X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fnotifier.php;h=db2542849d1d1d721171609dd1b11e385b92480d;hb=570a22de7425e2a486b02e3b43a4b4b1ece552af;hp=ca2304845ed276655aa009c8d7717e72b3b31e65;hpb=9838245c6c9b2e311650b53a1c3aa1ef778ef935;p=friendica.git diff --git a/include/notifier.php b/include/notifier.php index ca2304845e..db2542849d 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -20,6 +20,8 @@ function notifier_run($argv, $argc){ require_once('include/items.php'); require_once('include/bbcode.php'); + load_hooks(); + if($argc < 3) return; @@ -72,7 +74,7 @@ function notifier_run($argv, $argc){ else { // find ancestors - $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($item_id) ); @@ -80,6 +82,7 @@ function notifier_run($argv, $argc){ return; } + $parent_item = $r[0]; $parent_id = intval($r[0]['parent']); $uid = $r[0]['uid']; $updated = $r[0]['edited']; @@ -188,8 +191,8 @@ function notifier_run($argv, $argc){ $contacts = $r; } - $feed_template = load_view_file('view/atom_feed.tpl'); - $mail_template = load_view_file('view/atom_mail.tpl'); + $feed_template = get_markup_template('atom_feed.tpl'); + $mail_template = get_markup_template('atom_mail.tpl'); $atom = ''; $slaps = array(); @@ -267,12 +270,30 @@ function notifier_run($argv, $argc){ logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA); + // If this is a public message and pubmail is set on the parent, include all your email contacts + + $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); + + if(! $mail_disabled) { + if((! strlen($parent_item['allow_cid'])) && (! strlen($parent_item['allow_gid'])) + && (! strlen($parent_item['deny_cid'])) && (! strlen($parent_item['deny_gid'])) + && (intval($parent_item['pubmail']))) { + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'", + intval($uid), + dbesc(NETWORK_MAIL) + ); + if(count($r)) { + foreach($r as $rr) + $recipients[] = $rr['id']; + } + } + } + if($followup) $recip_str = $parent['contact-id']; else $recip_str = implode(', ', $recipients); - $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ", dbesc($recip_str) ); @@ -352,8 +373,82 @@ function notifier_run($argv, $argc){ } break; case 'mail': + + // WARNING: does not currently convert to RFC2047 header encodings, etc. + + $addr = $contact['addr']; + if(! strlen($addr)) + break; + + if($cmd === 'wall-new' || $cmd === 'comment-new') { + + $it = null; + if($cmd === 'wall-new') + $it = $items[0]; + else { + $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($argv[2]), + intval($uid) + ); + if(count($r)) + $it = $r[0]; + } + if(! $it) + break; + + + + $local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", + intval($uid) + ); + if(! count($local_user)) + break; + + $reply_to = ''; + $r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", + intval($uid) + ); + if($r1 && $r1[0]['reply_to']) + $reply_to = $r1[0]['reply_to']; + + $subject = (($it['title']) ? $it['title'] : t("\x28no subject\x29")) ; + $headers = 'From: ' . $local_user[0]['username'] . ' <' . $local_user[0]['email'] . '>' . "\n"; + + if($reply_to) + $headers .= 'Reply-to: ' . $reply_to . "\n"; + + $headers .= 'Message-id: <' . $it['uri'] . '>' . "\n"; + + if($it['uri'] !== $it['parent-uri']) { + $header .= 'References: <' . $it['parent-uri'] . '>' . "\n"; + if(! strlen($it['title'])) { + $r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1", + dbesc($it['parent-uri']) + ); + if(count($r)) { + $subtitle = $r[0]['title']; + if($subtitle) { + if(strncasecmp($subtitle,'RE:',3)) + $subject = $subtitle; + else + $subject = 'Re: ' . $subtitle; + } + } + } + } + + $headers .= 'MIME-Version: 1.0' . "\n"; + $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; + $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n"; + $html = prepare_body($it); + $message = '' . $html . ''; + logger('notifier: email delivery to ' . $addr); + mail($addr, $subject, $message, $headers); + } + break; case 'dspr': case 'feed': + case 'face': default: break; }