2 require_once("boot.php");
3 require_once('include/queue_fn.php');
4 require_once('include/html2plain.php');
7 * This file was at one time responsible for doing all deliveries, but this caused
8 * big problems on shared hosting systems, where the process might get killed by the
9 * hosting provider and nothing would get delivered.
10 * It now only delivers one message under certain cases, and invokes a queued
11 * delivery mechanism (include/deliver.php) to deliver individual contacts at
12 * controlled intervals.
13 * This has a much better chance of surviving random processes getting killed
14 * by the hosting provider.
15 * A lot of this code is duplicated in include/deliver.php until we have time to go back
16 * and re-structure the delivery procedure based on the obstacles that have been thrown at
17 * us by hosting providers.
21 * The notifier is typically called with:
23 * proc_run('php', "include/notifier.php", COMMAND, ITEM_ID);
25 * where COMMAND is one of the following:
27 * activity (in diaspora.php, dfrn_confirm.php, profiles.php)
28 * comment-import (in diaspora.php, items.php)
29 * comment-new (in item.php)
30 * drop (in diaspora.php, items.php, photos.php)
31 * edit_post (in item.php)
32 * event (in events.php)
33 * expire (in items.php)
34 * like (in like.php, poke.php)
35 * mail (in message.php)
36 * suggest (in fsuggest.php)
37 * tag (in photos.php, poke.php, tagger.php)
38 * tgroup (in items.php)
39 * wall-new (in photos.php, item.php)
41 * and ITEM_ID is the id of the item in the database that needs to be sent to others.
45 function notifier_run(&$argv, &$argc){
53 @include(".htconfig.php");
54 require_once("dba.php");
55 $db = new dba($db_host, $db_user, $db_pass, $db_data);
56 unset($db_host, $db_user, $db_pass, $db_data);
59 require_once("session.php");
60 require_once("datetime.php");
61 require_once('include/items.php');
62 require_once('include/bbcode.php');
63 require_once('include/email.php');
64 load_config('config');
65 load_config('system');
72 $a->set_baseurl(get_config('system','url'));
74 logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
81 $item_id = intval($argv[2]);
93 $recipients = array();
94 $url_recipients = array();
101 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
104 if(! count($message)){
107 $uid = $message[0]['uid'];
108 $recipients[] = $message[0]['contact-id'];
112 elseif($cmd === 'expire') {
113 $normal_mode = false;
115 $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
116 AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE",
124 elseif($cmd === 'suggest') {
125 $normal_mode = false;
128 $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
131 if(! count($suggest))
133 $uid = $suggest[0]['uid'];
134 $recipients[] = $suggest[0]['cid'];
137 elseif($cmd === 'removeme') {
138 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
142 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
146 $r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
149 require_once('include/Contact.php');
150 foreach($r as $contact) {
151 terminate_friendship($user, $self, $contact);
155 elseif($cmd === 'relocate') {
156 $normal_mode = false;
162 $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
166 if((! count($r)) || (! intval($r[0]['parent']))) {
170 $target_item = $r[0];
171 $parent_id = intval($r[0]['parent']);
173 $updated = $r[0]['edited'];
175 // POSSIBLE CLEANUP --> The following seems superfluous. We've already checked for "if (! intval($r[0]['parent']))" a few lines up
179 $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
180 FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC",
184 if(! count($items)) {
188 // avoid race condition with deleting entries
190 if($items[0]['deleted']) {
191 foreach($items as $item)
192 $item['deleted'] = 1;
195 if((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
196 logger('notifier: top level post');
202 $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
203 `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
204 `user`.`page-flags`, `user`.`prvnets`
205 FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
206 WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
215 $walltowall = ((($top_level) && ($owner['id'] != $items[0]['contact-id'])) ? true : false);
217 $hub = get_config('system','huburl');
219 // If this is a public conversation, notify the feed hub
220 $public_message = true;
222 // fill this in with a single salmon slap if applicable
225 if(! ($mail || $fsuggest || $relocate)) {
227 require_once('include/group.php');
231 // This is IMPORTANT!!!!
233 // We will only send a "notify owner to relay" or followup message if the referenced post
234 // originated on our system by virtue of having our hostname somewhere
235 // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
237 // if $parent['wall'] == 1 we will already have the parent message in our array
238 // and we will relay the whole lot.
240 // expire sends an entire group of expire messages and cannot be forwarded.
241 // However the conversation owner will be a part of the conversation and will
242 // be notified during this run.
243 // Other DFRN conversation members will be alerted during polled updates.
247 // Diaspora members currently are not notified of expirations, and other networks have
248 // either limited or no ability to process deletions. We should at least fix Diaspora
249 // by stringing togther an array of retractions and sending them onward.
252 $localhost = str_replace('www.','',$a->get_hostname());
253 if(strpos($localhost,':'))
254 $localhost = substr($localhost,0,strpos($localhost,':'));
258 * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
259 * have been known to cause runaway conditions which affected several servers, along with
260 * permissions issues.
264 $relay_to_owner = false;
266 if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
267 $relay_to_owner = true;
271 if(($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && (! $top_level)) {
272 $relay_to_owner = true;
275 // until the 'origin' flag has been in use for several months
276 // we will just use it as a fallback test
277 // later we will be able to use it as the primary test of whether or not to relay.
279 if(! $target_item['origin'])
280 $relay_to_owner = false;
282 if($parent['origin'])
283 $relay_to_owner = false;
287 if($relay_to_owner) {
288 logger('notifier: followup', LOGGER_DEBUG);
289 // local followup to remote post
291 $public_message = false; // not public
292 $conversant_str = dbesc($parent['contact-id']);
297 // don't send deletions onward for other people's stuff
299 if($target_item['deleted'] && (! intval($target_item['wall']))) {
300 logger('notifier: ignoring delete notification for non-wall item');
304 if((strlen($parent['allow_cid']))
305 || (strlen($parent['allow_gid']))
306 || (strlen($parent['deny_cid']))
307 || (strlen($parent['deny_gid']))) {
308 $public_message = false; // private recipients, not public
311 $allow_people = expand_acl($parent['allow_cid']);
312 $allow_groups = expand_groups(expand_acl($parent['allow_gid']),true);
313 $deny_people = expand_acl($parent['deny_cid']);
314 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
316 // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
317 // a delivery fork. private groups (forum_mode == 2) do not uplink
319 if((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) {
320 proc_run('php','include/notifier.php','uplink',$item_id);
323 $conversants = array();
325 foreach($items as $item) {
326 $recipients[] = $item['contact-id'];
327 $conversants[] = $item['contact-id'];
328 // pull out additional tagged people to notify (if public message)
329 if($public_message && strlen($item['inform'])) {
330 $people = explode(',',$item['inform']);
331 foreach($people as $person) {
332 if(substr($person,0,4) === 'cid:') {
333 $recipients[] = intval(substr($person,4));
334 $conversants[] = intval(substr($person,4));
337 $url_recipients[] = substr($person,4);
343 logger('notifier: url_recipients' . print_r($url_recipients,true));
345 $conversants = array_unique($conversants);
348 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups));
349 $deny = array_unique(array_merge($deny_people,$deny_groups));
350 $recipients = array_diff($recipients,$deny);
352 $conversant_str = dbesc(implode(', ',$conversants));
355 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0");
361 $feed_template = get_markup_template('atom_feed.tpl');
362 $mail_template = get_markup_template('atom_mail.tpl');
367 $hubxml = feed_hublinks();
369 $birthday = feed_birthday($owner['uid'],$owner['timezone']);
371 if(strlen($birthday))
372 $birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
374 $atom .= replace_macros($feed_template, array(
375 '$version' => xmlify(FRIENDICA_VERSION),
376 '$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
377 '$feed_title' => xmlify($owner['name']),
378 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
380 '$salmon' => '', // private feed, we don't use salmon here
381 '$name' => xmlify($owner['name']),
382 '$profile_page' => xmlify($owner['url']),
383 '$photo' => xmlify($owner['photo']),
384 '$thumb' => xmlify($owner['thumb']),
385 '$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
386 '$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
387 '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
388 '$birthday' => $birthday,
389 '$community' => (($owner['page-flags'] == PAGE_COMMUNITY) ? '<dfrn:community>1</dfrn:community>' : '')
394 $public_message = false; // mail is not public
396 $body = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
398 $atom .= replace_macros($mail_template, array(
399 '$name' => xmlify($owner['name']),
400 '$profile_page' => xmlify($owner['url']),
401 '$thumb' => xmlify($owner['thumb']),
402 '$item_id' => xmlify($item['uri']),
403 '$subject' => xmlify($item['title']),
404 '$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
405 '$content' => xmlify($body),
406 '$parent_id' => xmlify($item['parent-uri'])
410 $public_message = false; // suggestions are not public
412 $sugg_template = get_markup_template('atom_suggest.tpl');
414 $atom .= replace_macros($sugg_template, array(
415 '$name' => xmlify($item['name']),
416 '$url' => xmlify($item['url']),
417 '$photo' => xmlify($item['photo']),
418 '$request' => xmlify($item['request']),
419 '$note' => xmlify($item['note'])
422 // We don't need this any more
424 q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1",
430 $public_message = false; // suggestions are not public
432 $sugg_template = get_markup_template('atom_relocate.tpl');
434 /* get site pubkey. this could be a new installation with no site keys*/
435 $pubkey = get_config('system','site_pubkey');
437 $res = new_keypair(1024);
438 set_config('system','site_prvkey', $res['prvkey']);
439 set_config('system','site_pubkey', $res['pubkey']);
442 $rp = q("SELECT `resource-id` , `scale`, type FROM `photo`
443 WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
445 $ext = Photo::supportedTypes();
447 $photos[$p['scale']] = $a->get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
451 $atom .= replace_macros($sugg_template, array(
452 '$name' => xmlify($owner['name']),
453 '$photo' => xmlify($photos[4]),
454 '$thumb' => xmlify($photos[5]),
455 '$micro' => xmlify($photos[6]),
456 '$url' => xmlify($owner['url']),
457 '$request' => xmlify($owner['request']),
458 '$confirm' => xmlify($owner['confirm']),
459 '$notify' => xmlify($owner['notify']),
460 '$poll' => xmlify($owner['poll']),
461 '$sitepubkey' => xmlify(get_config('system','site_pubkey')),
462 //'$pubkey' => xmlify($owner['pubkey']),
463 //'$prvkey' => xmlify($owner['prvkey']),
465 $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
470 foreach($items as $item) { // there is only one item
471 if(! $item['parent'])
473 if($item['id'] == $item_id) {
474 logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
475 $slap = atom_entry($item,'html',null,$owner,false);
476 $atom .= atom_entry($item,'text',null,$owner,false);
481 foreach($items as $item) {
483 if(! $item['parent'])
486 // private emails may be in included in public conversations. Filter them.
488 if(($public_message) && $item['private'] == 1)
492 $contact = get_item_contact($item,$contacts);
499 // we only need the current item, but include the parent because without it
500 // older sites without a corresponding dfrn_notify change may do the wrong thing.
502 if($item_id == $item['id'] || $item['id'] == $item['parent'])
503 $atom .= atom_entry($item,'text',null,$owner,true);
506 $atom .= atom_entry($item,'text',null,$owner,true);
508 if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire))
509 $slaps[] = atom_entry($item,'html',null,$owner,true);
513 $atom .= '</feed>' . "\r\n";
515 logger('notifier: ' . $atom, LOGGER_DATA);
517 logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
519 // If this is a public message and pubmail is set on the parent, include all your email contacts
521 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
523 if(! $mail_disabled) {
524 if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid']))
525 && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid']))
526 && (intval($target_item['pubmail']))) {
527 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
533 $recipients[] = $rr['id'];
539 $recip_str = $parent['contact-id'];
541 $recip_str = implode(', ', $recipients);
544 $r = $recipients_relocate;
546 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
551 require_once('include/salmon.php');
553 $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
559 foreach($r as $contact) {
560 if((! $mail) && (! $fsuggest) && (! $followup) && (!$relocate) && (! $contact['self'])) {
561 if(($contact['network'] === NETWORK_DIASPORA) && ($public_message))
563 q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
566 intval($contact['id'])
572 // This controls the number of deliveries to execute with each separate delivery process.
573 // By default we'll perform one delivery per process. Assuming a hostile shared hosting
574 // provider, this provides the greatest chance of deliveries if processes start getting
575 // killed. We can also space them out with the delivery_interval to also help avoid them
578 // If $deliveries_per_process > 1, we will chain this number of multiple deliveries
579 // together into a single process. This will reduce the overall number of processes
580 // spawned for each delivery, but they will run longer.
582 $deliveries_per_process = intval(get_config('system','delivery_batch_count'));
583 if($deliveries_per_process <= 0)
584 $deliveries_per_process = 1;
586 $this_batch = array();
588 for($x = 0; $x < count($r); $x ++) {
594 // potentially more than one recipient. Start a new process and space them out a bit.
595 // we will deliver single recipient types of message and email recipients here.
597 if((! $mail) && (! $fsuggest) && (!$relocate) && (! $followup)) {
599 $this_batch[] = $contact['id'];
601 if(count($this_batch) == $deliveries_per_process) {
602 proc_run('php','include/delivery.php',$cmd,$item_id,$this_batch);
603 $this_batch = array();
605 @time_sleep_until(microtime(true) + (float) $interval);
609 // be sure to pick up any stragglers
610 if(count($this_batch))
611 proc_run('php','include/delivery.php',$cmd,$item_id,$this_batch);
616 logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest relocate=$relocate");
618 switch($contact['network']) {
621 // perform local delivery if we are on the same site
623 $basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
625 if(link_compare($basepath,$a->get_baseurl())) {
627 $nickname = basename($contact['url']);
628 if($contact['issued-id'])
629 $sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
631 $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
633 $x = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
634 `contact`.`pubkey` AS `cpubkey`,
635 `contact`.`prvkey` AS `cprvkey`,
636 `contact`.`thumb` AS `thumb`,
637 `contact`.`url` as `url`,
638 `contact`.`name` as `senderName`,
641 LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
642 WHERE `contact`.`blocked` = 0 AND `contact`.`archive` = 0
643 AND `contact`.`pending` = 0
644 AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'
646 AND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1",
651 if($x && count($x)) {
652 $write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
653 if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
654 q("update contact set writable = 1 where id = %d limit 1",
657 $x[0]['writable'] = 1;
660 // if contact's ssl policy changed, which we just determined
661 // is on our own server, update our contact links
663 $ssl_policy = get_config('system','ssl_policy');
664 fix_contact_ssl_policy($x[0],$ssl_policy);
666 // If we are setup as a soapbox we aren't accepting input from this person
668 if($x[0]['page-flags'] == PAGE_SOAPBOX)
671 require_once('library/simplepie/simplepie.inc');
672 logger('mod-delivery: local delivery');
673 local_delivery($x[0],$atom);
680 logger('notifier: dfrndelivery: ' . $contact['name']);
681 $deliver_status = dfrn_deliver($owner,$contact,$atom);
683 logger('notifier: dfrn_delivery returns ' . $deliver_status);
685 if($deliver_status == (-1)) {
686 logger('notifier: delivery failed: queuing message');
687 // queue message for redelivery
688 add_to_queue($contact['id'],NETWORK_DFRN,$atom);
691 case NETWORK_OSTATUS:
693 // Do not send to ostatus if we are not configured to send to public networks
694 if($owner['prvnets'])
696 if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
699 if($followup && $contact['notify']) {
700 logger('notifier: slapdelivery: ' . $contact['name']);
701 $deliver_status = slapper($owner,$contact['notify'],$slap);
703 if($deliver_status == (-1)) {
704 // queue message for redelivery
705 add_to_queue($contact['id'],NETWORK_OSTATUS,$slap);
710 // only send salmon if public - e.g. if it's ok to notify
711 // a public hub, it's ok to send a salmon
713 if((count($slaps)) && ($public_message) && (! $expire)) {
714 logger('notifier: slapdelivery: ' . $contact['name']);
715 foreach($slaps as $slappy) {
716 if($contact['notify']) {
717 $deliver_status = slapper($owner,$contact['notify'],$slappy);
718 if($deliver_status == (-1)) {
719 // queue message for redelivery
720 add_to_queue($contact['id'],NETWORK_OSTATUS,$slappy);
731 if(get_config('system','dfrn_only'))
734 // WARNING: does not currently convert to RFC2047 header encodings, etc.
736 $addr = $contact['addr'];
740 if($cmd === 'wall-new' || $cmd === 'comment-new') {
743 if($cmd === 'wall-new')
746 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
758 $local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
761 if(! count($local_user))
765 $r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
768 if($r1 && $r1[0]['reply_to'])
769 $reply_to = $r1[0]['reply_to'];
771 $subject = (($it['title']) ? email_header_encode($it['title'],'UTF-8') : t("\x28no subject\x29")) ;
773 // only expose our real email address to true friends
775 if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked']))
776 $headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . $local_user[0]['email'] . '>' . "\n";
778 $headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . t('noreply') . '@' . $a->get_hostname() . '>' . "\n";
781 $headers .= 'Reply-to: ' . $reply_to . "\n";
783 // for testing purposes: Collect exported mails
784 //$file = tempnam("/tmp/friendica/", "mail-out2-");
785 //file_put_contents($file, json_encode($it));
787 $headers .= 'Message-Id: <' . iri2msgid($it['uri']) . '>' . "\n";
789 if($it['uri'] !== $it['parent-uri']) {
790 $headers .= 'References: <' . iri2msgid($it['parent-uri']) . '>' . "\n";
791 if(!strlen($it['title'])) {
792 $r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
793 dbesc($it['parent-uri']));
795 if(count($r) AND ($r[0]['title'] != ''))
796 $subject = $r[0]['title'];
798 if(strncasecmp($subject,'RE:',3))
799 $subject = 'Re: '.$subject;
801 email_send($addr, $subject, $headers, $it);
804 case NETWORK_DIASPORA:
805 require_once('include/diaspora.php');
807 if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')))
811 diaspora_send_mail($item,$owner,$contact);
818 // special handling for followup to public post
819 // all other public posts processed as public batches further below
821 if($public_message) {
823 diaspora_send_followup($target_item,$owner,$contact, true);
827 if(! $contact['pubkey'])
830 if($target_item['verb'] === ACTIVITY_DISLIKE) {
834 elseif(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
835 // send both top-level retractions and relayable retractions for owner to relay
836 diaspora_send_retraction($target_item,$owner,$contact);
840 // send comments and likes to owner to relay
841 diaspora_send_followup($target_item,$owner,$contact);
844 elseif($target_item['uri'] !== $target_item['parent-uri']) {
845 // we are the relay - send comments, likes and relayable_retractions
846 // (of comments and likes) to our conversants
847 diaspora_send_relay($target_item,$owner,$contact);
850 elseif(($top_level) && (! $walltowall)) {
851 // currently no workable solution for sending walltowall
852 diaspora_send_status($target_item,$owner,$contact);
859 case NETWORK_FACEBOOK:
860 if(get_config('system','dfrn_only'))
868 // send additional slaps to mentioned remote tags (@foo@example.com)
870 if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) {
871 if(! get_config('system','dfrn_only')) {
872 foreach($url_recipients as $url) {
874 logger('notifier: urldelivery: ' . $url);
875 $deliver_status = slapper($owner,$url,$slap);
876 // TODO: redeliver/queue these items on failure, though there is no contact record
883 if($public_message) {
885 $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
886 AND `uid` = %d AND `rel` != %d group by `batch` ORDER BY rand() ",
887 dbesc(NETWORK_DIASPORA),
888 intval($owner['uid']),
889 intval(CONTACT_IS_SHARING)
892 $r2 = q("SELECT `id`, `name`,`network` FROM `contact`
893 WHERE `network` in ( '%s', '%s') AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
894 AND `rel` != %d order by rand() ",
896 dbesc(NETWORK_MAIL2),
897 intval($owner['uid']),
898 intval(CONTACT_IS_SHARING)
901 $r = array_merge($r2,$r1);
904 logger('pubdeliver: ' . print_r($r,true), LOGGER_DEBUG);
906 // throw everything into the queue in case we get killed
909 if((! $mail) && (! $fsuggest) && (! $followup)) {
910 q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
920 // except for Diaspora batch jobs
921 // Don't deliver to folks who have already been delivered to
923 if(($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'],$conversants))) {
924 logger('notifier: already delivered id=' . $rr['id']);
928 if((! $mail) && (! $fsuggest) && (! $followup)) {
929 logger('notifier: delivery agent: ' . $rr['name'] . ' ' . $rr['id']);
930 proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']);
932 @time_sleep_until(microtime(true) + (float) $interval);
939 $hubs = explode(',', $hub);
941 foreach($hubs as $h) {
945 $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
946 post_url($h,$params);
947 logger('pubsub: publish: ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code());
949 sleep(7); // try and avoid multiple hubs responding at precisely the same time
956 // If the item was deleted, clean up the `sign` table
957 if($target_item['deleted']) {
958 $r = q("DELETE FROM sign where `retract_iid` = %d",
959 intval($target_item['id'])
963 logger('notifier: calling hooks', LOGGER_DEBUG);
966 call_hooks('notifier_normal',$target_item);
968 call_hooks('notifier_end',$target_item);
974 if (array_search(__file__,get_included_files())===0){
975 notifier_run($argv,$argc);