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