+
+ if((! count($r)) || (! intval($r[0]['parent']))) {
+ return;
+ }
+
+ $target_item = $r[0];
+ $parent_id = intval($r[0]['parent']);
+ $uid = $r[0]['uid'];
+ $updated = $r[0]['edited'];
+
+ $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
+ FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d ORDER BY `id` ASC",
+ intval($parent_id)
+ );
+
+ if(! count($items)) {
+ return;
+ }
+
+ // avoid race condition with deleting entries
+
+ if($items[0]['deleted']) {
+ foreach($items as $item)
+ $item['deleted'] = 1;
+ }
+
+ if((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
+ logger('notifier: top level post');
+ $top_level = true;
+ }
+
+ }
+
+ $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
+ `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
+ `user`.`page-flags`, `user`.`prvnets`
+ FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
+ WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
+ intval($uid)
+ );
+
+ if(! count($r))
+ return;
+
+ $owner = $r[0];
+
+ $walltowall = ((($top_level) && ($owner['id'] != $items[0]['contact-id'])) ? true : false);
+
+ $hub = get_config('system','huburl');
+
+ // If this is a public conversation, notify the feed hub
+ $public_message = true;
+
+ // fill this in with a single salmon slap if applicable
+ $slap = '';
+
+ if(! ($mail || $fsuggest)) {
+
+ require_once('include/group.php');
+
+ $parent = $items[0];
+
+ // This is IMPORTANT!!!!
+
+ // We will only send a "notify owner to relay" or followup message if the referenced post
+ // originated on our system by virtue of having our hostname somewhere
+ // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
+ // if $parent['wall'] == 1 we will already have the parent message in our array
+ // and we will relay the whole lot.
+
+ // expire sends an entire group of expire messages and cannot be forwarded.
+ // However the conversation owner will be a part of the conversation and will
+ // be notified during this run.
+ // Other DFRN conversation members will be alerted during polled updates.
+
+ // Diaspora members currently are not notified of expirations, and other networks have
+ // either limited or no ability to process deletions. We should at least fix Diaspora
+ // by stringing togther an array of retractions and sending them onward.
+
+
+ $localhost = $a->get_hostname();
+ if(strpos($localhost,':'))
+ $localhost = substr($localhost,0,strpos($localhost,':'));
+
+ /**
+ *
+ * Be VERY CAREFUL if you make any changes to the following line. Seemingly innocuous changes
+ * have been known to cause runaway conditions which affected several servers, along with
+ * permissions issues.
+ *
+ */
+
+ if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
+ // local followup to remote post
+ $followup = true;
+ $public_message = false; // not public
+ $conversant_str = dbesc($parent['contact-id']);
+ }
+ else {
+ $followup = false;
+
+ if((strlen($parent['allow_cid']))
+ || (strlen($parent['allow_gid']))
+ || (strlen($parent['deny_cid']))
+ || (strlen($parent['deny_gid']))) {
+ $public_message = false; // private recipients, not public
+ }
+
+ $allow_people = expand_acl($parent['allow_cid']);
+ $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
+ $deny_people = expand_acl($parent['deny_cid']);
+ $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
+
+ $conversants = array();
+
+ foreach($items as $item) {
+ $recipients[] = $item['contact-id'];
+ $conversants[] = $item['contact-id'];
+ // pull out additional tagged people to notify (if public message)
+ if($public_message && strlen($item['inform'])) {
+ $people = explode(',',$item['inform']);
+ foreach($people as $person) {
+ if(substr($person,0,4) === 'cid:') {
+ $recipients[] = intval(substr($person,4));
+ $conversants[] = intval(substr($person,4));
+ }
+ else {
+ $url_recipients[] = substr($person,4);
+ }
+ }
+ }
+ }
+
+ logger('notifier: url_recipients' . print_r($url_recipients,true));
+
+ $conversants = array_unique($conversants);
+
+
+ $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups));
+ $deny = array_unique(array_merge($deny_people,$deny_groups));
+ $recipients = array_diff($recipients,$deny);
+
+ $conversant_str = dbesc(implode(', ',$conversants));
+ }
+
+ $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
+