Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

610 lines
23 KiB

  1. <?php
  2. require_once('include/Emailer.php');
  3. require_once('include/email.php');
  4. require_once('include/bbcode.php');
  5. require_once('include/html2bbcode.php');
  6. function notification($params) {
  7. #logger('notification()', LOGGER_DEBUG);
  8. $a = get_app();
  9. // from here on everything is in the recipients language
  10. push_lang($params['language']);
  11. $banner = t('Friendica Notification');
  12. $product = FRIENDICA_PLATFORM;
  13. $siteurl = $a->get_baseurl(true);
  14. $thanks = t('Thank You,');
  15. $sitename = $a->config['sitename'];
  16. $site_admin = sprintf( t('%s Administrator'), $sitename);
  17. $sender_name = $product;
  18. $hostname = $a->get_hostname();
  19. if(strpos($hostname,':'))
  20. $hostname = substr($hostname,0,strpos($hostname,':'));
  21. $sender_email = t('noreply') . '@' . $hostname;
  22. // with $params['show_in_notification_page'] == false, the notification isn't inserted into
  23. // the database, and an email is sent if applicable.
  24. // default, if not specified: true
  25. $show_in_notification_page = ((x($params,'show_in_notification_page')) ? $params['show_in_notification_page']:True);
  26. $additional_mail_header = "";
  27. $additional_mail_header .= "Precedence: list\n";
  28. $additional_mail_header .= "X-Friendica-Host: ".$hostname."\n";
  29. $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n";
  30. $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n";
  31. $additional_mail_header .= "List-ID: <notification.".$hostname.">\n";
  32. $additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n";
  33. if(array_key_exists('item',$params)) {
  34. $title = $params['item']['title'];
  35. $body = $params['item']['body'];
  36. }
  37. else {
  38. $title = $body = '';
  39. }
  40. // e.g. "your post", "David's photo", etc.
  41. $possess_desc = t('%s <!item_type!>');
  42. if($params['type'] == NOTIFY_MAIL) {
  43. $subject = sprintf( t('[Friendica:Notify] New mail received at %s'),$sitename);
  44. $preamble = sprintf( t('%1$s sent you a new private message at %2$s.'),$params['source_name'],$sitename);
  45. $epreamble = sprintf( t('%1$s sent you %2$s.'),'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]', '[url=$itemlink]' . t('a private message') . '[/url]');
  46. $sitelink = t('Please visit %s to view and/or reply to your private messages.');
  47. $tsitelink = sprintf( $sitelink, $siteurl . '/message/' . $params['item']['id'] );
  48. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message/' . $params['item']['id'] . '">' . $sitename . '</a>');
  49. $itemlink = $siteurl . '/message/' . $params['item']['id'];
  50. }
  51. if($params['type'] == NOTIFY_COMMENT) {
  52. // logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
  53. $parent_id = $params['parent'];
  54. $p = q("SELECT `ignored` FROM `thread` WHERE `iid` = %d AND `uid` = %d LIMIT 1",
  55. intval($parent_id),
  56. intval($params['uid'])
  57. );
  58. if ($p AND count($p) AND ($p[0]["ignored"])) {
  59. logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
  60. return;
  61. }
  62. // Check to see if there was already a tag notify or comment notify for this post.
  63. // If so don't create a second notification
  64. $p = null;
  65. $p = q("select id from notify where (type = %d or type = %d or type = %d) and link = '%s' and uid = %d limit 1",
  66. intval(NOTIFY_TAGSELF),
  67. intval(NOTIFY_COMMENT),
  68. intval(NOTIFY_SHARE),
  69. dbesc($params['link']),
  70. intval($params['uid'])
  71. );
  72. if($p and count($p)) {
  73. pop_lang();
  74. return;
  75. }
  76. // if it's a post figure out who's post it is.
  77. $p = null;
  78. if($params['otype'] === 'item' && $parent_id) {
  79. $p = q("select * from item where id = %d and uid = %d limit 1",
  80. intval($parent_id),
  81. intval($params['uid'])
  82. );
  83. }
  84. $item_post_type = item_post_type($p[0]);
  85. //$possess_desc = str_replace('<!item_type!>',$possess_desc);
  86. // "a post"
  87. $dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
  88. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  89. $itemlink,
  90. $item_post_type);
  91. // "George Bull's post"
  92. if($p)
  93. $dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
  94. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  95. $itemlink,
  96. $p[0]['author-name'],
  97. $item_post_type);
  98. // "your post"
  99. if($p[0]['owner-name'] == $p[0]['author-name'] && $p[0]['wall'])
  100. $dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
  101. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  102. $itemlink,
  103. $item_post_type);
  104. // Some mail softwares relies on subject field for threading.
  105. // So, we cannot have different subjects for notifications of the same thread.
  106. // Before this we have the name of the replier on the subject rendering
  107. // differents subjects for messages on the same thread.
  108. $subject = sprintf( t('[Friendica:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $params['source_name']);
  109. $preamble = sprintf( t('%s commented on an item/conversation you have been following.'), $params['source_name']);
  110. $epreamble = $dest_str;
  111. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  112. $tsitelink = sprintf( $sitelink, $siteurl );
  113. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  114. $itemlink = $params['link'];
  115. }
  116. if($params['type'] == NOTIFY_WALL) {
  117. $subject = sprintf( t('[Friendica:Notify] %s posted to your profile wall') , $params['source_name']);
  118. $preamble = sprintf( t('%1$s posted to your profile wall at %2$s') , $params['source_name'], $sitename);
  119. $epreamble = sprintf( t('%1$s posted to [url=%2$s]your wall[/url]') ,
  120. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  121. $params['link']);
  122. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  123. $tsitelink = sprintf( $sitelink, $siteurl );
  124. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  125. $itemlink = $params['link'];
  126. }
  127. if($params['type'] == NOTIFY_TAGSELF) {
  128. $subject = sprintf( t('[Friendica:Notify] %s tagged you') , $params['source_name']);
  129. $preamble = sprintf( t('%1$s tagged you at %2$s') , $params['source_name'], $sitename);
  130. $epreamble = sprintf( t('%1$s [url=%2$s]tagged you[/url].') ,
  131. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  132. $params['link']);
  133. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  134. $tsitelink = sprintf( $sitelink, $siteurl );
  135. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  136. $itemlink = $params['link'];
  137. }
  138. if($params['type'] == NOTIFY_SHARE) {
  139. $subject = sprintf( t('[Friendica:Notify] %s shared a new post') , $params['source_name']);
  140. $preamble = sprintf( t('%1$s shared a new post at %2$s') , $params['source_name'], $sitename);
  141. $epreamble = sprintf( t('%1$s [url=%2$s]shared a post[/url].') ,
  142. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  143. $params['link']);
  144. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  145. $tsitelink = sprintf( $sitelink, $siteurl );
  146. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  147. $itemlink = $params['link'];
  148. }
  149. if($params['type'] == NOTIFY_POKE) {
  150. $subject = sprintf( t('[Friendica:Notify] %1$s poked you') , $params['source_name']);
  151. $preamble = sprintf( t('%1$s poked you at %2$s') , $params['source_name'], $sitename);
  152. $epreamble = sprintf( t('%1$s [url=%2$s]poked you[/url].') ,
  153. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  154. $params['link']);
  155. $subject = str_replace('poked', t($params['activity']), $subject);
  156. $preamble = str_replace('poked', t($params['activity']), $preamble);
  157. $epreamble = str_replace('poked', t($params['activity']), $epreamble);
  158. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  159. $tsitelink = sprintf( $sitelink, $siteurl );
  160. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  161. $itemlink = $params['link'];
  162. }
  163. if($params['type'] == NOTIFY_TAGSHARE) {
  164. $subject = sprintf( t('[Friendica:Notify] %s tagged your post') , $params['source_name']);
  165. $preamble = sprintf( t('%1$s tagged your post at %2$s') , $params['source_name'], $sitename);
  166. $epreamble = sprintf( t('%1$s tagged [url=%2$s]your post[/url]') ,
  167. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  168. $itemlink);
  169. $sitelink = t('Please visit %s to view and/or reply to the conversation.');
  170. $tsitelink = sprintf( $sitelink, $siteurl );
  171. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  172. $itemlink = $params['link'];
  173. }
  174. if($params['type'] == NOTIFY_INTRO) {
  175. $subject = sprintf( t('[Friendica:Notify] Introduction received'));
  176. $preamble = sprintf( t('You\'ve received an introduction from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
  177. $epreamble = sprintf( t('You\'ve received [url=%1$s]an introduction[/url] from %2$s.'),
  178. $itemlink,
  179. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
  180. $body = sprintf( t('You may visit their profile at %s'),$params['source_link']);
  181. $sitelink = t('Please visit %s to approve or reject the introduction.');
  182. $tsitelink = sprintf( $sitelink, $siteurl );
  183. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  184. $itemlink = $params['link'];
  185. switch ($params['verb']) {
  186. case ACTIVITY_FRIEND:
  187. // someone started to share with user (mostly OStatus)
  188. $subject = sprintf( t('[Friendica:Notify] A new person is sharing with you'));
  189. $preamble = sprintf( t('%1$s is sharing with you at %2$s'), $params['source_name'], $sitename);
  190. $epreamble = sprintf( t('%1$s is sharing with you at %2$s'),
  191. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  192. $sitename);
  193. break;
  194. case ACTIVITY_FOLLOW:
  195. // someone started to follow the user (mostly OStatus)
  196. $subject = sprintf( t('[Friendica:Notify] You have a new follower'));
  197. $preamble = sprintf( t('You have a new follower at %2$s : %1$s'), $params['source_name'], $sitename);
  198. $epreamble = sprintf( t('You have a new follower at %2$s : %1$s'),
  199. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
  200. $sitename);
  201. break;
  202. default:
  203. // ACTIVITY_REQ_FRIEND is default activity for notifications
  204. break;
  205. }
  206. }
  207. if($params['type'] == NOTIFY_SUGGEST) {
  208. $subject = sprintf( t('[Friendica:Notify] Friend suggestion received'));
  209. $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
  210. $epreamble = sprintf( t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.'),
  211. $itemlink,
  212. '[url=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/url]',
  213. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
  214. $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
  215. $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
  216. $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
  217. $sitelink = t('Please visit %s to approve or reject the suggestion.');
  218. $tsitelink = sprintf( $sitelink, $siteurl );
  219. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  220. $itemlink = $params['link'];
  221. }
  222. if($params['type'] == NOTIFY_CONFIRM) {
  223. if ($params['verb'] == ACTIVITY_FRIEND ){ // mutual connection
  224. $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
  225. $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
  226. $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
  227. $itemlink,
  228. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
  229. $body = t('You are now mutual friends and may exchange status updates, photos, and email
  230. without restriction.');
  231. $sitelink = t('Please visit %s if you wish to make any changes to this relationship.');
  232. $tsitelink = sprintf( $sitelink, $siteurl );
  233. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  234. $itemlink = $params['link'];
  235. } else { // ACTIVITY_FOLLOW
  236. $subject = sprintf( t('[Friendica:Notify] Connection accepted'));
  237. $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename);
  238. $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'),
  239. $itemlink,
  240. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
  241. $body = sprintf(t('\'%1$s\' has chosen to accept you a "fan", which restricts some forms of communication - such as private messaging and some profile interactions. If this is a celebrity or community page, these settings were applied automatically.'), $params['source_name']);
  242. $body .= "\n\n";
  243. $body .= sprintf(t('\'%1$s\' may choose to extend this into a two-way or more permissive relationship in the future. '), $params['source_name']);
  244. $sitelink = t('Please visit %s if you wish to make any changes to this relationship.');
  245. $tsitelink = sprintf( $sitelink, $siteurl );
  246. $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
  247. $itemlink = $params['link'];
  248. }
  249. }
  250. if($params['type'] == NOTIFY_SYSTEM) {
  251. switch($params['event']) {
  252. case "SYSTEM_REGISTER_REQUEST":
  253. $subject = sprintf( t('[Friendica System:Notify] registration request'));
  254. $preamble = sprintf( t('You\'ve received a registration request from \'%1$s\' at %2$s'), $params['source_name'], $sitename);
  255. $epreamble = sprintf( t('You\'ve received a [url=%1$s]registration request[/url] from %2$s.'),
  256. $itemlink,
  257. '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]');
  258. $body = sprintf( t('Full Name: %1$s\nSite Location: %2$s\nLogin Name: %3$s (%4$s)'),
  259. $params['source_name'], $siteurl, $params['source_mail'], $params['source_nick']);
  260. $sitelink = t('Please visit %s to approve or reject the request.');
  261. $tsitelink = sprintf( $sitelink, $params['link'] );
  262. $hsitelink = sprintf( $sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>');
  263. $itemlink = $params['link'];
  264. break;
  265. case "SYSTEM_DB_UPDATE_FAIL":
  266. break;
  267. }
  268. }
  269. if ($params['type'] == "SYSTEM_EMAIL"){
  270. // not part of the notifications.
  271. // it just send a mail to the user.
  272. // It will be used by the system to send emails to users (like
  273. // password reset, invitations and so) using one look (but without
  274. // add a notification to the user, with could be inexistent)
  275. $subject = $params['subject'];
  276. $preamble = $params['preamble'];
  277. $body = $params['body'];
  278. $sitelink = "";
  279. $tsitelink = "";
  280. $hsitelink = "";
  281. $itemlink = "";
  282. $show_in_notification_page = false;
  283. }
  284. $h = array(
  285. 'params' => $params,
  286. 'subject' => $subject,
  287. 'preamble' => $preamble,
  288. 'epreamble' => $epreamble,
  289. 'body' => $body,
  290. 'sitelink' => $sitelink,
  291. 'tsitelink' => $tsitelink,
  292. 'hsitelink' => $hsitelink,
  293. 'itemlink' => $itemlink
  294. );
  295. call_hooks('enotify',$h);
  296. $subject = $h['subject'];
  297. $preamble = $h['preamble'];
  298. $epreamble = $h['epreamble'];
  299. $body = $h['body'];
  300. $sitelink = $h['sitelink'];
  301. $tsitelink = $h['tsitelink'];
  302. $hsitelink = $h['hsitelink'];
  303. $itemlink = $h['itemlink'];
  304. if ($show_in_notification_page) {
  305. logger("adding notification entry", LOGGER_DEBUG);
  306. do {
  307. $dups = false;
  308. $hash = random_string();
  309. $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
  310. dbesc($hash));
  311. if(count($r))
  312. $dups = true;
  313. } while($dups == true);
  314. $datarray = array();
  315. $datarray['hash'] = $hash;
  316. $datarray['name'] = $params['source_name'];
  317. $datarray['url'] = $params['source_link'];
  318. $datarray['photo'] = $params['source_photo'];
  319. $datarray['date'] = datetime_convert();
  320. $datarray['uid'] = $params['uid'];
  321. $datarray['link'] = $itemlink;
  322. $datarray['parent'] = $parent_id;
  323. $datarray['type'] = $params['type'];
  324. $datarray['verb'] = $params['verb'];
  325. $datarray['otype'] = $params['otype'];
  326. $datarray['abort'] = false;
  327. call_hooks('enotify_store', $datarray);
  328. if($datarray['abort']) {
  329. pop_lang();
  330. return False;
  331. }
  332. // create notification entry in DB
  333. $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
  334. values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
  335. dbesc($datarray['hash']),
  336. dbesc($datarray['name']),
  337. dbesc($datarray['url']),
  338. dbesc($datarray['photo']),
  339. dbesc($datarray['date']),
  340. intval($datarray['uid']),
  341. dbesc($datarray['link']),
  342. intval($datarray['parent']),
  343. intval($datarray['type']),
  344. dbesc($datarray['verb']),
  345. dbesc($datarray['otype'])
  346. );
  347. $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
  348. dbesc($hash),
  349. intval($params['uid'])
  350. );
  351. if($r)
  352. $notify_id = $r[0]['id'];
  353. else {
  354. pop_lang();
  355. return False;
  356. }
  357. // we seem to have a lot of duplicate comment notifications due to race conditions, mostly from forums
  358. // After we've stored everything, look again to see if there are any duplicates and if so remove them
  359. $p = null;
  360. $p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d order by id",
  361. intval(NOTIFY_TAGSELF),
  362. intval(NOTIFY_COMMENT),
  363. dbesc($params['link']),
  364. intval($params['uid'])
  365. );
  366. if($p && (count($p) > 1)) {
  367. for ($d = 1; $d < count($p); $d ++) {
  368. q("delete from notify where id = %d",
  369. intval($p[$d]['id'])
  370. );
  371. }
  372. // only continue on if we stored the first one
  373. if($notify_id != $p[0]['id']) {
  374. pop_lang();
  375. return False;
  376. }
  377. }
  378. $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
  379. $msg = replace_macros($epreamble,array('$itemlink' => $itemlink));
  380. $r = q("update notify set msg = '%s' where id = %d and uid = %d",
  381. dbesc($msg),
  382. intval($notify_id),
  383. intval($params['uid'])
  384. );
  385. }
  386. // send email notification if notification preferences permit
  387. if((intval($params['notify_flags']) & intval($params['type']))
  388. || $params['type'] == NOTIFY_SYSTEM
  389. || $params['type'] == "SYSTEM_EMAIL") {
  390. logger('sending notification email');
  391. if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
  392. $id_for_parent = $params['parent']."@".$hostname;
  393. // Is this the first email notification for this parent item and user?
  394. $r = q("select `id` from `notify-threads` where `master-parent-item` = %d and `receiver-uid` = %d limit 1",
  395. intval($params['parent']),
  396. intval($params['uid']) );
  397. // If so, create the record of it and use a message-id smtp header.
  398. if(!$r) {
  399. logger("notify_id:".intval($notify_id).", parent: ".intval($params['parent'])."uid: ".intval($params['uid']), LOGGER_DEBUG);
  400. $r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
  401. values(%d,%d,%d,%d)",
  402. intval($notify_id),
  403. intval($params['parent']),
  404. intval($params['uid']),
  405. 0 );
  406. $additional_mail_header .= "Message-ID: <${id_for_parent}>\n";
  407. $log_msg = "include/enotify: No previous notification found for this parent:\n" .
  408. " parent: ${params['parent']}\n" . " uid : ${params['uid']}\n";
  409. logger($log_msg, LOGGER_DEBUG);
  410. } else {
  411. // If not, just "follow" the thread.
  412. $additional_mail_header .= "References: <${id_for_parent}>\nIn-Reply-To: <${id_for_parent}>\n";
  413. logger("There's already a notification for this parent:\n" . print_r($r, true), LOGGER_DEBUG);
  414. }
  415. }
  416. // textversion keeps linebreaks
  417. $textversion = strip_tags(str_replace("<br>","\n",html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
  418. $body))),ENT_QUOTES,'UTF-8')));
  419. $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
  420. "<br />\n",$body))),ENT_QUOTES,'UTF-8');
  421. $datarray = array();
  422. $datarray['banner'] = $banner;
  423. $datarray['product'] = $product;
  424. $datarray['preamble'] = $preamble;
  425. $datarray['sitename'] = $sitename;
  426. $datarray['siteurl'] = $siteurl;
  427. $datarray['type'] = $params['type'];
  428. $datarray['parent'] = $params['parent'];
  429. $datarray['source_name'] = $params['source_name'];
  430. $datarray['source_link'] = $params['source_link'];
  431. $datarray['source_photo'] = $params['source_photo'];
  432. $datarray['uid'] = $params['uid'];
  433. $datarray['username'] = $params['to_name'];
  434. $datarray['hsitelink'] = $hsitelink;
  435. $datarray['tsitelink'] = $tsitelink;
  436. $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
  437. $datarray['titemlink'] = $itemlink;
  438. $datarray['thanks'] = $thanks;
  439. $datarray['site_admin'] = $site_admin;
  440. $datarray['title'] = stripslashes($title);
  441. $datarray['htmlversion'] = $htmlversion;
  442. $datarray['textversion'] = $textversion;
  443. $datarray['subject'] = $subject;
  444. $datarray['headers'] = $additional_mail_header;
  445. call_hooks('enotify_mail', $datarray);
  446. // check whether sending post content in email notifications is allowed
  447. $content_allowed = !get_config('system','enotify_no_content');
  448. // load the template for private message notifications
  449. $tpl = get_markup_template('email_notify_html.tpl');
  450. $email_html_body = replace_macros($tpl,array(
  451. '$banner' => $datarray['banner'],
  452. '$product' => $datarray['product'],
  453. '$preamble' => str_replace("\n","<br>\n",$datarray['preamble']),
  454. '$sitename' => $datarray['sitename'],
  455. '$siteurl' => $datarray['siteurl'],
  456. '$source_name' => $datarray['source_name'],
  457. '$source_link' => $datarray['source_link'],
  458. '$source_photo' => $datarray['source_photo'],
  459. '$username' => $datarray['to_name'],
  460. '$hsitelink' => $datarray['hsitelink'],
  461. '$hitemlink' => $datarray['hitemlink'],
  462. '$thanks' => $datarray['thanks'],
  463. '$site_admin' => $datarray['site_admin'],
  464. '$title' => $datarray['title'],
  465. '$htmlversion' => $datarray['htmlversion'],
  466. '$content_allowed' => $content_allowed,
  467. ));
  468. // load the template for private message notifications
  469. $tpl = get_markup_template('email_notify_text.tpl');
  470. $email_text_body = replace_macros($tpl,array(
  471. '$banner' => $datarray['banner'],
  472. '$product' => $datarray['product'],
  473. '$preamble' => $datarray['preamble'],
  474. '$sitename' => $datarray['sitename'],
  475. '$siteurl' => $datarray['siteurl'],
  476. '$source_name' => $datarray['source_name'],
  477. '$source_link' => $datarray['source_link'],
  478. '$source_photo' => $datarray['source_photo'],
  479. '$username' => $datarray['to_name'],
  480. '$tsitelink' => $datarray['tsitelink'],
  481. '$titemlink' => $datarray['titemlink'],
  482. '$thanks' => $datarray['thanks'],
  483. '$site_admin' => $datarray['site_admin'],
  484. '$title' => $datarray['title'],
  485. '$textversion' => $datarray['textversion'],
  486. '$content_allowed' => $content_allowed,
  487. ));
  488. // logger('text: ' . $email_text_body);
  489. // use the Emailer class to send the message
  490. return Emailer::send(array(
  491. 'fromName' => $sender_name,
  492. 'fromEmail' => $sender_email,
  493. 'replyTo' => $sender_email,
  494. 'toEmail' => $params['to_email'],
  495. 'messageSubject' => $datarray['subject'],
  496. 'htmlVersion' => $email_html_body,
  497. 'textVersion' => $email_text_body,
  498. 'additionalMailHeader' => $datarray['headers'],
  499. ));
  500. }
  501. return False;
  502. }
  503. ?>