]> git.mxchange.org Git - friendica.git/blob - include/notifier.php
0bb82b7bf802015401567c74d5faae102cd035bd
[friendica.git] / include / notifier.php
1 <?php
2
3 require_once("boot.php");
4
5 function notifier_run($argv, $argc){
6         global $a, $db;
7
8         if(is_null($a)){
9                 $a = new App;
10         }
11   
12         if(is_null($db)) {
13                 @include(".htconfig.php");
14                 require_once("dba.php");
15                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
16                         unset($db_host, $db_user, $db_pass, $db_data);
17         }
18
19         require_once("session.php");
20         require_once("datetime.php");
21         require_once('include/items.php');
22         require_once('include/bbcode.php');
23
24         load_config('config');
25         load_config('system');
26
27         load_hooks();
28
29         if($argc < 3)
30                 return;
31
32         $a->set_baseurl(get_config('system','url'));
33
34         logger('notifier: invoked: ' . print_r($argv,true));
35
36         $cmd = $argv[1];
37
38         switch($cmd) {
39                 case 'mail':
40                 default:
41                         $item_id = intval($argv[2]);
42                         if(! $item_id){
43                                 return;
44                         }
45                         break;
46         }
47
48         $expire = false;
49         $mail = false;
50         $fsuggest = false;
51         $top_level = false;
52         $recipients = array();
53         $url_recipients = array();
54
55         $normal_mode = true;
56
57         if($cmd === 'mail') {
58                 $normal_mode = false;
59                 $mail = true;
60                 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
61                                 intval($item_id)
62                 );
63                 if(! count($message)){
64                         return;
65                 }
66                 $uid = $message[0]['uid'];
67                 $recipients[] = $message[0]['contact-id'];
68                 $item = $message[0];
69
70         }
71         elseif($cmd === 'expire') {
72                 $normal_mode = false;
73                 $expire = true;
74                 $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 
75                         AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 10 MINUTE",
76                         intval($item_id)
77                 );
78                 $uid = $item_id;
79                 $item_id = 0;
80                 if(! count($items))
81                         return;
82         }
83         elseif($cmd === 'suggest') {
84                 $normal_mode = false;
85                 $fsuggest = true;
86
87                 $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
88                         intval($item_id)
89                 );
90                 if(! count($suggest))
91                         return;
92                 $uid = $suggest[0]['uid'];
93                 $recipients[] = $suggest[0]['cid'];
94                 $item = $suggest[0];
95         }
96         else {
97
98                 // find ancestors
99                 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
100                         intval($item_id)
101                 );
102
103                 if((! count($r)) || (! intval($r[0]['parent']))) {
104                         return;
105                 }
106
107                 $target_item = $r[0];
108                 $parent_id = intval($r[0]['parent']);
109                 $uid = $r[0]['uid'];
110                 $updated = $r[0]['edited'];
111
112                 $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` 
113                         FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d ORDER BY `id` ASC",
114                         intval($parent_id)
115                 );
116
117                 if(! count($items)) {
118                         return;
119                 }
120
121                 // avoid race condition with deleting entries
122
123                 if($items[0]['deleted']) {
124                         foreach($items as $item)
125                                 $item['deleted'] = 1;
126                 }
127
128                 if((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
129                         logger('notifier: top level post');
130                         $top_level = true;
131                 }
132
133         }
134
135         $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, 
136                 `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, 
137                 `user`.`page-flags`, `user`.`prvnets`
138                 FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
139                 WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
140                 intval($uid)
141         );
142
143         if(! count($r))
144                 return;
145
146         $owner = $r[0];
147
148         $walltowall = ((($top_level) && ($owner['id'] != $items[0]['contact-id'])) ? true : false);
149
150         $hub = get_config('system','huburl');
151
152         // If this is a public conversation, notify the feed hub
153         $public_message = true;
154
155         // fill this in with a single salmon slap if applicable
156         $slap = '';
157
158         if(! ($mail || $fsuggest)) {
159
160                 require_once('include/group.php');
161
162                 $parent = $items[0];
163
164                 // This is IMPORTANT!!!!
165
166                 // We will only send a "notify owner to relay" or followup message if the referenced post
167                 // originated on our system by virtue of having our hostname somewhere
168                 // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
169                 // if $parent['wall'] == 1 we will already have the parent message in our array
170                 // and we will relay the whole lot.
171  
172                 // expire sends an entire group of expire messages and cannot be forwarded.
173                 // However the conversation owner will be a part of the conversation and will 
174                 // be notified during this run.
175                 // Other DFRN conversation members will be alerted during polled updates.
176
177                 // Diaspora members currently are not notified of expirations, and other networks have
178                 // either limited or no ability to process deletions. We should at least fix Diaspora 
179                 // by stringing togther an array of retractions and sending them onward.
180                  
181         
182                 $localhost = $a->get_hostname();
183                 if(strpos($localhost,':'))
184                         $localhost = substr($localhost,0,strpos($localhost,':'));
185
186                 /**
187                  *
188                  * Be VERY CAREFUL if you make any changes to the following line. Seemingly innocuous changes 
189                  * have been known to cause runaway conditions which affected several servers, along with 
190                  * permissions issues. 
191                  *
192                  */
193  
194                 if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
195                         // local followup to remote post
196                         $followup = true;
197                         $public_message = false; // not public
198                         $conversant_str = dbesc($parent['contact-id']);
199                 }
200                 else {
201                         $followup = false;
202
203                         if((strlen($parent['allow_cid'])) 
204                                 || (strlen($parent['allow_gid'])) 
205                                 || (strlen($parent['deny_cid'])) 
206                                 || (strlen($parent['deny_gid']))) {
207                                 $public_message = false; // private recipients, not public
208                         }
209
210                         $allow_people = expand_acl($parent['allow_cid']);
211                         $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
212                         $deny_people  = expand_acl($parent['deny_cid']);
213                         $deny_groups  = expand_groups(expand_acl($parent['deny_gid']));
214
215                         $conversants = array();
216
217                         foreach($items as $item) {
218                                 $recipients[] = $item['contact-id'];
219                                 $conversants[] = $item['contact-id'];
220                                 // pull out additional tagged people to notify (if public message)
221                                 if($public_message && strlen($item['inform'])) {
222                                         $people = explode(',',$item['inform']);
223                                         foreach($people as $person) {
224                                                 if(substr($person,0,4) === 'cid:') {
225                                                         $recipients[] = intval(substr($person,4));
226                                                         $conversants[] = intval(substr($person,4));
227                                                 }
228                                                 else {
229                                                         $url_recipients[] = substr($person,4);
230                                                 }
231                                         }
232                                 }
233                         }
234
235                         logger('notifier: url_recipients' . print_r($url_recipients,true));
236
237                         $conversants = array_unique($conversants);
238
239
240                         $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups));
241                         $deny = array_unique(array_merge($deny_people,$deny_groups));
242                         $recipients = array_diff($recipients,$deny);
243
244                         $conversant_str = dbesc(implode(', ',$conversants));
245                 }
246
247                 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
248
249                 if(count($r))
250                         $contacts = $r;
251         }
252
253         $feed_template = get_markup_template('atom_feed.tpl');
254         $mail_template = get_markup_template('atom_mail.tpl');
255
256         $atom = '';
257         $slaps = array();
258
259         $hubxml = feed_hublinks();
260
261         $birthday = feed_birthday($owner['uid'],$owner['timezone']);
262
263         if(strlen($birthday))
264                 $birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
265
266         $atom .= replace_macros($feed_template, array(
267                         '$version'      => xmlify(FRIENDIKA_VERSION),
268                         '$feed_id'      => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
269                         '$feed_title'   => xmlify($owner['name']),
270                         '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
271                         '$hub'          => $hubxml,
272                         '$salmon'       => '',  // private feed, we don't use salmon here
273                         '$name'         => xmlify($owner['name']),
274                         '$profile_page' => xmlify($owner['url']),
275                         '$photo'        => xmlify($owner['photo']),
276                         '$thumb'        => xmlify($owner['thumb']),
277                         '$picdate'      => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
278                         '$uridate'      => xmlify(datetime_convert('UTC','UTC',$owner['uri-date']    . '+00:00' , ATOM_TIME)) ,
279                         '$namdate'      => xmlify(datetime_convert('UTC','UTC',$owner['name-date']   . '+00:00' , ATOM_TIME)) ,
280                         '$birthday'     => $birthday
281         ));
282
283         if($mail) {
284                 $public_message = false;  // mail is  not public
285
286                 $body = fix_private_photos($item['body'],$owner['uid']);
287
288                 $atom .= replace_macros($mail_template, array(
289                         '$name'         => xmlify($owner['name']),
290                         '$profile_page' => xmlify($owner['url']),
291                         '$thumb'        => xmlify($owner['thumb']),
292                         '$item_id'      => xmlify($item['uri']),
293                         '$subject'      => xmlify($item['title']),
294                         '$created'      => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
295                         '$content'      => xmlify($body),
296                         '$parent_id'    => xmlify($item['parent-uri'])
297                 ));
298         }
299         elseif($fsuggest) {
300                 $public_message = false;  // suggestions are not public
301
302                 $sugg_template = get_markup_template('atom_suggest.tpl');
303
304                 $atom .= replace_macros($sugg_template, array(
305                         '$name'         => xmlify($item['name']),
306                         '$url'          => xmlify($item['url']),
307                         '$photo'        => xmlify($item['photo']),
308                         '$request'      => xmlify($item['request']),
309                         '$note'         => xmlify($item['note'])
310                 ));
311
312                 // We don't need this any more
313
314                 q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1",
315                         intval($item['id'])
316                 );
317
318         }
319         else {
320                 if($followup) {
321                         foreach($items as $item) {  // there is only one item
322                                 if(! $item['parent'])
323                                         continue;
324                                 if($item['id'] == $item_id) {
325                                         logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
326                                         $slap  = atom_entry($item,'html',$owner,$owner,false);
327                                         $atom .= atom_entry($item,'text',$owner,$owner,false);
328                                 }
329                         }
330                 }
331                 else {
332                         foreach($items as $item) {
333
334                                 if(! $item['parent'])
335                                         continue;
336
337                                 // private emails may be in included in public conversations. Filter them.
338
339                                 if(($public_message) && $item['private'])
340                                         continue;
341
342                                 $contact = get_item_contact($item,$contacts);
343                                 if(! $contact)
344                                         continue;
345
346                                 $atom .= atom_entry($item,'text',$contact,$owner,true);
347
348                                 if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) 
349                                         $slaps[] = atom_entry($item,'html',$contact,$owner,true);
350                         }
351                 }
352         }
353         $atom .= '</feed>' . "\r\n";
354
355         logger('notifier: ' . $atom, LOGGER_DATA);
356
357         logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
358
359         // If this is a public message and pubmail is set on the parent, include all your email contacts
360
361         $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
362
363         if(! $mail_disabled) {
364                 if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) 
365                         && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid'])) 
366                         && (intval($target_item['pubmail']))) {
367                         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
368                                 intval($uid),
369                                 dbesc(NETWORK_MAIL)
370                         );
371                         if(count($r)) {
372                                 foreach($r as $rr)
373                                         $recipients[] = $rr['id'];
374                         }
375                 }
376         }
377
378         if($followup)
379                 $recip_str = $parent['contact-id'];
380         else
381                 $recip_str = implode(', ', $recipients);
382
383         $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
384                 dbesc($recip_str)
385         );
386
387
388         require_once('include/salmon.php');
389
390         $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
391
392         // delivery loop
393
394         if(count($r)) {
395
396                 foreach($r as $contact) {
397                         if((! $mail) && (! $fsuggest) && (! $followup) && (! $contact['self'])) {
398                                 q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
399                                         dbesc($cmd),
400                                         intval($item_id),
401                                         intval($contact['id'])
402                                 );
403                         }
404                 }
405
406                 foreach($r as $contact) {
407                         if($contact['self'])
408                                 continue;
409
410                         // potentially more than one recipient. Start a new process and space them out a bit.
411                         // we will deliver single recipient types of message and email receipients here. 
412
413                         if((! $mail) && (! $fsuggest) && (! $followup)) {
414                                 proc_run('php','include/delivery.php',$cmd,$item_id,$contact['id']);
415                                 if($interval)
416                                         @time_sleep_until(microtime(true) + (float) $interval);
417                                 continue;
418                         }
419
420                         $deliver_status = 0;
421
422                         logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest");
423
424                         switch($contact['network']) {
425                                 case NETWORK_DFRN:
426                                         logger('notifier: dfrndelivery: ' . $contact['name']);
427                                         $deliver_status = dfrn_deliver($owner,$contact,$atom);
428
429                                         logger('notifier: dfrn_delivery returns ' . $deliver_status);
430         
431                                         if($deliver_status == (-1)) {
432                                                 logger('notifier: delivery failed: queuing message');
433                                                 // queue message for redelivery
434                                                 q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
435                                                         VALUES ( %d, '%s', '%s', '%s') ",
436                                                         intval($contact['id']),
437                                                         dbesc(datetime_convert()),
438                                                         dbesc(datetime_convert()),
439                                                         dbesc($atom)
440                                                 );
441                                         }
442                                         break;
443                                 case NETWORK_OSTATUS:
444
445                                         // Do not send to otatus if we are not configured to send to public networks
446                                         if($owner['prvnets'])
447                                                 break;
448                                         if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
449                                                 break;
450
451                                         if($followup && $contact['notify']) {
452                                                 logger('notifier: slapdelivery: ' . $contact['name']);
453                                                 $deliver_status = slapper($owner,$contact['notify'],$slap);
454
455                                                 if($deliver_status == (-1)) {
456                                                         // queue message for redelivery
457                                                         q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
458                                                                 VALUES ( %d, '%s', '%s', '%s') ",
459                                                                 intval($contact['id']),
460                                                                 dbesc(datetime_convert()),
461                                                                 dbesc(datetime_convert()),
462                                                                 dbesc($slap)
463                                                         );
464
465                                                 }
466                                         }
467                                         else {
468
469                                                 // only send salmon if public - e.g. if it's ok to notify
470                                                 // a public hub, it's ok to send a salmon
471
472                                                 if((count($slaps)) && ($public_message) && (! $expire)) {
473                                                         logger('notifier: slapdelivery: ' . $contact['name']);
474                                                         foreach($slaps as $slappy) {
475                                                                 if($contact['notify']) {
476                                                                         $deliver_status = slapper($owner,$contact['notify'],$slappy);
477                                                                         if($deliver_status == (-1)) {
478                                                                                 // queue message for redelivery
479                                                                                 q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
480                                                                                         VALUES ( %d, '%s', '%s', '%s') ",
481                                                                                         intval($contact['id']),
482                                                                                         dbesc(datetime_convert()),
483                                                                                         dbesc(datetime_convert()),
484                                                                                         dbesc($slappy)
485                                                                                 );                                                              
486                                                                         }
487                                                                 }
488                                                         }
489                                                 }
490                                         }
491                                         break;
492
493                                 case NETWORK_MAIL:
494                                                 
495                                         if(get_config('system','dfrn_only'))
496                                                 break;
497
498                                         // WARNING: does not currently convert to RFC2047 header encodings, etc.
499
500                                         $addr = $contact['addr'];
501                                         if(! strlen($addr))
502                                                 break;
503
504                                         if($cmd === 'wall-new' || $cmd === 'comment-new') {
505
506                                                 $it = null;
507                                                 if($cmd === 'wall-new') 
508                                                         $it = $items[0];
509                                                 else {
510                                                         $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", 
511                                                                 intval($argv[2]),
512                                                                 intval($uid)
513                                                         );
514                                                         if(count($r))
515                                                                 $it = $r[0];
516                                                 }
517                                                 if(! $it)
518                                                         break;
519                                                 
520
521
522                                                 $local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
523                                                         intval($uid)
524                                                 );
525                                                 if(! count($local_user))
526                                                         break;
527                                                 
528                                                 $reply_to = '';
529                                                 $r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
530                                                         intval($uid)
531                                                 );
532                                                 if($r1 && $r1[0]['reply_to'])
533                                                         $reply_to = $r1[0]['reply_to'];
534         
535                                                 $subject  = (($it['title']) ? $it['title'] : t("\x28no subject\x29")) ;
536                                                 $headers  = 'From: ' . $local_user[0]['username'] . ' <' . $local_user[0]['email'] . '>' . "\n";
537
538                                                 if($reply_to)
539                                                         $headers .= 'Reply-to: ' . $reply_to . "\n";
540
541                                                 $headers .= 'Message-id: <' . $it['uri'] . '>' . "\n";
542
543                                                 if($it['uri'] !== $it['parent-uri']) {
544                                                         $header .= 'References: <' . $it['parent-uri'] . '>' . "\n";
545                                                         if(! strlen($it['title'])) {
546                                                                 $r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
547                                                                         dbesc($it['parent-uri'])
548                                                                 );
549                                                                 if(count($r)) {
550                                                                         $subtitle = $r[0]['title'];
551                                                                         if($subtitle) {
552                                                                                 if(strncasecmp($subtitle,'RE:',3))
553                                                                                         $subject = $subtitle;
554                                                                                 else
555                                                                                         $subject = 'Re: ' . $subtitle;
556                                                                         }
557                                                                 }
558                                                         }
559                                                 }
560
561                                                 $headers .= 'MIME-Version: 1.0' . "\n";
562                                                 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
563                                                 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
564                                                 $html    = prepare_body($it);
565                                                 $message = '<html><body>' . $html . '</body></html>';
566                                                 logger('notifier: email delivery to ' . $addr);
567                                                 mail($addr, $subject, $message, $headers);
568                                         }
569                                         break;
570                                 case NETWORK_DIASPORA:
571                                         require_once('include/diaspora.php');
572                                         if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode))
573                                                 break;
574
575                                         if(! $contact['pubkey'])
576                                                 break;
577                                         
578                                         if($target_item['verb'] === ACTIVITY_DISLIKE) {
579                                                 // unsupported
580                                                 break;
581                                         }
582                                         elseif(($target_item['deleted']) && ($target_item['verb'] !== ACTIVITY_LIKE)) {
583                                                 // diaspora delete, 
584                                                 diaspora_send_retraction($target_item,$owner,$contact);
585                                                 break;
586                                         }
587                                         elseif($followup) {
588                                                 // send comments, likes and retractions of likes to owner to relay
589                                                 diaspora_send_followup($target_item,$owner,$contact);
590                                                 break;
591                                         }
592                                         elseif($target_item['parent'] != $target_item['id']) {
593                                                 // we are the relay - send comments, likes and unlikes to our conversants
594                                                 diaspora_send_relay($target_item,$owner,$contact);
595                                                 break;
596                                         }               
597                                         elseif($top_level) {
598                                                 diaspora_send_status($target_item,$owner,$contact);
599                                                 break;
600                                         }
601
602                                         break;
603
604                                 case NETWORK_FEED:
605                                 case NETWORK_FACEBOOK:
606                                         if(get_config('system','dfrn_only'))
607                                                 break;
608                                 default:
609                                         break;
610                         }
611                 }
612         }
613                 
614         // send additional slaps to mentioned remote tags (@foo@example.com)
615
616         if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) {
617                 if(! get_config('system','dfrn_only')) {
618                         foreach($url_recipients as $url) {
619                                 if($url) {
620                                         logger('notifier: urldelivery: ' . $url);
621                                         $deliver_status = slapper($owner,$url,$slap);
622                                         // TODO: redeliver/queue these items on failure, though there is no contact record
623                                 }
624                         }
625                 }
626         }
627
628
629         if($public_message) {
630
631                 $r = q("SELECT `id`, `name` FROM `contact` 
632                         WHERE `network` in ('%s','%s') AND `uid` = %d AND `blocked` = 0 AND `pending` = 0
633                         AND `rel` != %d order by rand() ",
634                         dbesc(NETWORK_DFRN),
635                         dbesc(NETWORK_DIASPORA),
636                         intval($owner['uid']),
637                         intval(CONTACT_IS_SHARING)
638                 );
639
640                 if(count($r)) {
641                         logger('pubdeliver: ' . print_r($r,true));
642
643                         // throw everything into the queue in case we get killed
644
645                         foreach($r as $rr) {
646                                 if((! $mail) && (! $fsuggest) && (! $followup)) {
647                                         q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
648                                                 dbesc($cmd),
649                                                 intval($item_id),
650                                                 intval($rr['id'])
651                                         );
652                                 }
653                         }
654
655                         foreach($r as $rr) {
656
657                                 /* Don't deliver to folks who have already been delivered to */
658
659                                 if(in_array($rr['id'],$conversants)) {
660                                         logger('notifier: already delivered id=' . $rr['id']);
661                                         continue;
662                                 }
663
664                                 if((! $mail) && (! $fsuggest) && (! $followup)) {
665                                         logger('notifier: delivery agent: ' . $rr['name'] . ' ' . $rr['id']); 
666                                         proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']);
667                                         if($interval)
668                                                 @time_sleep_until(microtime(true) + (float) $interval);
669                                 }
670                         }
671                 }
672
673
674                 if(strlen($hub)) {
675                         $hubs = explode(',', $hub);
676                         if(count($hubs)) {
677                                 foreach($hubs as $h) {
678                                         $h = trim($h);
679                                         if(! strlen($h))
680                                                 continue;
681                                         $params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
682                                         post_url($h,$params);
683                                         logger('pubsub: publish: ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code());
684                                         if(count($hubs) > 1)
685                                                 sleep(7);                               // try and avoid multiple hubs responding at precisely the same time
686                                 }
687                         }
688                 }
689
690         }
691
692         return;
693 }
694
695 if (array_search(__file__,get_included_files())===0){
696   notifier_run($argv,$argc);
697   killme();
698 }