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