]> git.mxchange.org Git - friendica.git/blob - src/Worker/Notifier.php
Merge pull request #5997 from annando/notice-relocation
[friendica.git] / src / Worker / Notifier.php
1 <?php
2 /**
3  * @file src/Worker/Notifier.php
4  */
5 namespace Friendica\Worker;
6
7 use Friendica\BaseObject;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\Hook;
11 use Friendica\Core\Protocol;
12 use Friendica\Core\Worker;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Conversation;
16 use Friendica\Model\Group;
17 use Friendica\Model\Item;
18 use Friendica\Model\PushSubscriber;
19 use Friendica\Model\User;
20 use Friendica\Network\Probe;
21 use Friendica\Protocol\ActivityPub;
22 use Friendica\Protocol\Diaspora;
23 use Friendica\Protocol\OStatus;
24 use Friendica\Protocol\Salmon;
25
26 require_once 'include/dba.php';
27 require_once 'include/items.php';
28
29 /*
30  * The notifier is typically called with:
31  *
32  *              Worker::add(PRIORITY_HIGH, "Notifier", COMMAND, ITEM_ID);
33  *
34  * where COMMAND is one of the following:
35  *
36  *              activity                                (in diaspora.php, dfrn_confirm.php, profiles.php)
37  *              comment-import                  (in diaspora.php, items.php)
38  *              comment-new                             (in item.php)
39  *              drop                                    (in diaspora.php, items.php, photos.php)
40  *              edit_post                               (in item.php)
41  *              event                                   (in events.php)
42  *              like                                    (in like.php, poke.php)
43  *              mail                                    (in message.php)
44  *              suggest                                 (in fsuggest.php)
45  *              tag                                             (in photos.php, poke.php, tagger.php)
46  *              tgroup                                  (in items.php)
47  *              wall-new                                (in photos.php, item.php)
48  *              removeme                                (in Contact.php)
49  *              relocate                                (in uimport.php)
50  *
51  * and ITEM_ID is the id of the item in the database that needs to be sent to others.
52  */
53
54 class Notifier
55 {
56         public static function execute($cmd, $item_id)
57         {
58                 $a = BaseObject::getApp();
59
60                 logger('notifier: invoked: '.$cmd.': '.$item_id, LOGGER_DEBUG);
61
62                 $top_level = false;
63                 $recipients = [];
64                 $url_recipients = [];
65
66                 $normal_mode = true;
67                 $recipients_relocate = [];
68
69                 if ($cmd == Delivery::MAIL) {
70                         $normal_mode = false;
71                         $message = DBA::selectFirst('mail', ['uid', 'contact-id'], ['id' => $item_id]);
72                         if (!DBA::isResult($message)) {
73                                 return;
74                         }
75                         $uid = $message['uid'];
76                         $recipients[] = $message['contact-id'];
77                 } elseif ($cmd == Delivery::SUGGESTION) {
78                         $normal_mode = false;
79                         $suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $item_id]);
80                         if (!DBA::isResult($suggest)) {
81                                 return;
82                         }
83                         $uid = $suggest['uid'];
84                         $recipients[] = $suggest['cid'];
85                 } elseif ($cmd == Delivery::REMOVAL) {
86                         $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`,
87                                         `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
88                                         `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid`
89                                 FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
90                                         WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1",
91                                         intval($item_id));
92                         if (!$r) {
93                                 return;
94                         }
95                         $user = $r[0];
96
97                         $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
98                         if (!$r) {
99                                 return;
100                         }
101                         foreach ($r as $contact) {
102                                 Contact::terminateFriendship($user, $contact, true);
103                         }
104
105                         $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
106                         foreach ($inboxes as $inbox) {
107                                 logger('Account removal for user ' . $item_id . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
108                                 Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
109                                         'APDelivery', Delivery::REMOVAL, '', $inbox, $item_id);
110                         }
111
112                         return;
113                 } elseif ($cmd == Delivery::RELOCATION) {
114                         $normal_mode = false;
115                         $uid = $item_id;
116
117                         $recipients_relocate = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND `network` IN ('%s', '%s')",
118                                                 intval($uid), Protocol::DFRN, Protocol::DIASPORA);
119                 } else {
120                         // find ancestors
121                         $condition = ['id' => $item_id, 'visible' => true, 'moderated' => false];
122                         $target_item = Item::selectFirst([], $condition);
123
124                         if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
125                                 return;
126                         }
127
128                         $parent_id = intval($target_item['parent']);
129                         $uid = $target_item['contact-uid'];
130                         $updated = $target_item['edited'];
131
132                         $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false];
133                         $params = ['order' => ['id']];
134                         $ret = Item::select([], $condition, $params);
135
136                         if (!DBA::isResult($ret)) {
137                                 return;
138                         }
139
140                         $items = Item::inArray($ret);
141
142                         // avoid race condition with deleting entries
143                         if ($items[0]['deleted']) {
144                                 foreach ($items as $item) {
145                                         $item['deleted'] = 1;
146                                 }
147                         }
148
149                         if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
150                                 logger('notifier: top level post');
151                                 $top_level = true;
152                         }
153                 }
154
155                 $owner = User::getOwnerDataById($uid);
156                 if (!$owner) {
157                         return;
158                 }
159
160                 $walltowall = ($top_level && ($owner['id'] != $items[0]['contact-id']) ? true : false);
161
162                 // Should the post be transmitted to Diaspora?
163                 $diaspora_delivery = true;
164
165                 // If this is a public conversation, notify the feed hub
166                 $public_message = true;
167
168                 // Do a PuSH
169                 $push_notify = false;
170
171                 // Deliver directly to a forum, don't PuSH
172                 $direct_forum_delivery = false;
173
174                 $followup = false;
175                 $recipients_followup = [];
176                 $conversants = [];
177
178                 if (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::RELOCATION])) {
179                         $parent = $items[0];
180
181                         self::activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent);
182
183                         $fields = ['network', 'author-id', 'owner-id'];
184                         $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]];
185                         $thr_parent = Item::selectFirst($fields, $condition);
186
187                         logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent['network'], LOGGER_DEBUG);
188
189                         // This is IMPORTANT!!!!
190
191                         // We will only send a "notify owner to relay" or followup message if the referenced post
192                         // originated on our system by virtue of having our hostname somewhere
193                         // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere.
194
195                         // if $parent['wall'] == 1 we will already have the parent message in our array
196                         // and we will relay the whole lot.
197
198                         $localhost = str_replace('www.','',$a->getHostName());
199                         if (strpos($localhost,':')) {
200                                 $localhost = substr($localhost,0,strpos($localhost,':'));
201                         }
202                         /**
203                          *
204                          * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
205                          * have been known to cause runaway conditions which affected several servers, along with
206                          * permissions issues.
207                          *
208                          */
209
210                         $relay_to_owner = false;
211
212                         if (!$top_level && ($parent['wall'] == 0) && (stristr($target_item['uri'],$localhost))) {
213                                 $relay_to_owner = true;
214                         }
215
216
217                         if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) {
218                                 $relay_to_owner = true;
219                         }
220
221                         // until the 'origin' flag has been in use for several months
222                         // we will just use it as a fallback test
223                         // later we will be able to use it as the primary test of whether or not to relay.
224
225                         if (!$target_item['origin']) {
226                                 $relay_to_owner = false;
227                         }
228                         if ($parent['origin']) {
229                                 $relay_to_owner = false;
230                         }
231
232                         // Special treatment for forum posts
233                         if (self::isForumPost($target_item, $owner)) {
234                                 $relay_to_owner = true;
235                                 $direct_forum_delivery = true;
236                         }
237
238                         // Avoid that comments in a forum thread are sent to OStatus
239                         if (self::isForumPost($parent, $owner)) {
240                                 $direct_forum_delivery = true;
241                         }
242
243                         if ($relay_to_owner) {
244                                 // local followup to remote post
245                                 $followup = true;
246                                 $public_message = false; // not public
247                                 $conversant_str = DBA::escape($parent['contact-id']);
248                                 $recipients = [$parent['contact-id']];
249                                 $recipients_followup  = [$parent['contact-id']];
250
251                                 logger('notifier: followup '.$target_item["guid"].' to '.$conversant_str, LOGGER_DEBUG);
252
253                                 //if (!$target_item['private'] && $target_item['wall'] &&
254                                 if (!$target_item['private'] &&
255                                         (strlen($target_item['allow_cid'].$target_item['allow_gid'].
256                                                 $target_item['deny_cid'].$target_item['deny_gid']) == 0))
257                                         $push_notify = true;
258
259                                 if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
260                                         $push_notify = true;
261
262                                         if ($parent["network"] == Protocol::OSTATUS) {
263                                                 // Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
264                                                 // Currently it is work at progress
265                                                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
266                                                         intval($uid),
267                                                         DBA::escape(Protocol::DFRN)
268                                                 );
269                                                 if (DBA::isResult($r)) {
270                                                         foreach ($r as $rr) {
271                                                                 $recipients_followup[] = $rr['id'];
272                                                         }
273                                                 }
274                                         }
275                                 }
276
277                                 if ($direct_forum_delivery) {
278                                         $push_notify = false;
279                                 }
280
281                                 logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
282                         } else {
283                                 $followup = false;
284
285                                 logger('Distributing directly '.$target_item["guid"], LOGGER_DEBUG);
286
287                                 // don't send deletions onward for other people's stuff
288
289                                 if ($target_item['deleted'] && !intval($target_item['wall'])) {
290                                         logger('notifier: ignoring delete notification for non-wall item');
291                                         return;
292                                 }
293
294                                 if (strlen($parent['allow_cid'])
295                                         || strlen($parent['allow_gid'])
296                                         || strlen($parent['deny_cid'])
297                                         || strlen($parent['deny_gid'])) {
298                                         $public_message = false; // private recipients, not public
299                                 }
300
301                                 $allow_people = expand_acl($parent['allow_cid']);
302                                 $allow_groups = Group::expand(expand_acl($parent['allow_gid']),true);
303                                 $deny_people  = expand_acl($parent['deny_cid']);
304                                 $deny_groups  = Group::expand(expand_acl($parent['deny_gid']));
305
306                                 // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
307                                 // a delivery fork. private groups (forum_mode == 2) do not uplink
308
309                                 if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== 'uplink')) {
310                                         Worker::add($a->queue['priority'], 'Notifier', 'uplink', $item_id);
311                                 }
312
313                                 foreach ($items as $item) {
314                                         $recipients[] = $item['contact-id'];
315                                         $conversants[] = $item['contact-id'];
316                                         // pull out additional tagged people to notify (if public message)
317                                         if ($public_message && strlen($item['inform'])) {
318                                                 $people = explode(',',$item['inform']);
319                                                 foreach ($people as $person) {
320                                                         if (substr($person,0,4) === 'cid:') {
321                                                                 $recipients[] = intval(substr($person,4));
322                                                                 $conversants[] = intval(substr($person,4));
323                                                         } else {
324                                                                 $url_recipients[] = substr($person,4);
325                                                         }
326                                                 }
327                                         }
328                                 }
329
330                                 if (count($url_recipients)) {
331                                         logger('notifier: '.$target_item["guid"].' url_recipients ' . print_r($url_recipients,true));
332                                 }
333
334                                 $conversants = array_unique($conversants);
335
336                                 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups));
337                                 $deny = array_unique(array_merge($deny_people,$deny_groups));
338                                 $recipients = array_diff($recipients,$deny);
339
340                                 $conversant_str = DBA::escape(implode(', ',$conversants));
341                         }
342
343                         // If the thread parent is OStatus then do some magic to distribute the messages.
344                         // We have not only to look at the parent, since it could be a Friendica thread.
345                         if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
346                                 $diaspora_delivery = false;
347
348                                 logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent['author-id']." - Owner: ".$thr_parent['owner-id'], LOGGER_DEBUG);
349
350                                 // Send a salmon to the parent author
351                                 $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
352                                 if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
353                                         logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
354                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
355                                 }
356
357                                 // Send a salmon to the parent owner
358                                 $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
359                                 if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
360                                         logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
361                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
362                                 }
363
364                                 // Send a salmon notification to every person we mentioned in the post
365                                 $arr = explode(',',$target_item['tag']);
366                                 foreach ($arr as $x) {
367                                         //logger('Checking tag '.$x, LOGGER_DEBUG);
368                                         $matches = null;
369                                         if (preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
370                                                         $probed_contact = Probe::uri($matches[1]);
371                                                 if ($probed_contact["notify"] != "") {
372                                                         logger('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]);
373                                                         $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
374                                                 }
375                                         }
376                                 }
377
378                                 // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora
379                                 $networks = [Protocol::OSTATUS, Protocol::DFRN];
380                         } else {
381                                 $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL];
382                         }
383                 } else {
384                         $public_message = false;
385                 }
386
387                 // If this is a public message and pubmail is set on the parent, include all your email contacts
388                 if (!empty($target_item) && function_exists('imap_open') && !Config::get('system','imap_disabled')) {
389                         if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
390                                 && !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
391                                 && intval($target_item['pubmail'])) {
392                                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
393                                         intval($uid),
394                                         DBA::escape(Protocol::MAIL)
395                                 );
396                                 if (DBA::isResult($r)) {
397                                         foreach ($r as $rr) {
398                                                 $recipients[] = $rr['id'];
399                                         }
400                                 }
401                         }
402                 }
403
404                 if (($cmd == Delivery::RELOCATION)) {
405                         $r = $recipients_relocate;
406                 } else {
407                         if ($followup) {
408                                 $recipients = $recipients_followup;
409                         }
410                         $condition = ['id' => $recipients, 'self' => false,
411                                 'blocked' => false, 'pending' => false, 'archive' => false];
412                         if (!empty($networks)) {
413                                 $condition['network'] = $networks;
414                         }
415                         $contacts = DBA::select('contact', ['id', 'url', 'network'], $condition);
416                         $r = DBA::toArray($contacts);
417                 }
418
419                 // delivery loop
420                 if (DBA::isResult($r)) {
421                         foreach ($r as $contact) {
422                                 logger("Deliver ".$item_id." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
423
424                                 Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
425                                                 'Delivery', $cmd, $item_id, (int)$contact['id']);
426                         }
427                 }
428
429                 // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
430                 // They are especially used for notifications to OStatus users that don't follow us.
431                 if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
432                         $slap = OStatus::salmon($target_item, $owner);
433                         foreach ($url_recipients as $url) {
434                                 if ($url) {
435                                         logger('notifier: urldelivery: ' . $url);
436                                         $deliver_status = Salmon::slapper($owner, $url, $slap);
437                                         /// @TODO Redeliver/queue these items on failure, though there is no contact record
438                                 }
439                         }
440                 }
441
442                 if ($public_message) {
443                         $r1 = [];
444
445                         if ($diaspora_delivery) {
446                                 $r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
447                                         FROM `contact` WHERE `network` = '%s' AND `batch` != ''
448                                         AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
449                                         DBA::escape(Protocol::DIASPORA),
450                                         intval($owner['uid']),
451                                         intval(Contact::SHARING)
452                                 );
453
454                                 // Fetch the participation list
455                                 // The function will ensure that there are no duplicates
456                                 $r1 = Diaspora::participantsForThread($item_id, $r1);
457
458                                 // Add the relay to the list, avoid duplicates
459                                 if (!$followup) {
460                                         $r1 = Diaspora::relayList($item_id, $r1);
461                                 }
462                         }
463
464                         $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
465                                 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
466
467                         $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition));
468
469                         $r = array_merge($r2, $r1);
470
471                         if (DBA::isResult($r)) {
472                                 logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);
473
474                                 foreach ($r as $rr) {
475                                         // except for Diaspora batch jobs
476                                         // Don't deliver to folks who have already been delivered to
477
478                                         if (($rr['network'] !== Protocol::DIASPORA) && (in_array($rr['id'], $conversants))) {
479                                                 logger('notifier: already delivered id=' . $rr['id']);
480                                                 continue;
481                                         }
482
483                                         if (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION]) && !$followup) {
484                                                 logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
485                                                 Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
486                                                                 'Delivery', $cmd, $item_id, (int)$rr['id']);
487                                         }
488                                 }
489                         }
490
491                         $push_notify = true;
492                 }
493
494                 // Notify PuSH subscribers (Used for OStatus distribution of regular posts)
495                 if ($push_notify) {
496                         logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG);
497
498                         // Handling the pubsubhubbub requests
499                         PushSubscriber::publishFeed($owner['uid'], $a->queue['priority']);
500                 }
501
502                 logger('notifier: calling hooks for ' . $cmd . ' ' . $item_id, LOGGER_DEBUG);
503
504                 if ($normal_mode) {
505                         Hook::fork($a->queue['priority'], 'notifier_normal', $target_item);
506                 }
507
508                 Addon::callHooks('notifier_end',$target_item);
509
510                 return;
511         }
512
513         private static function activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent)
514         {
515                 $inboxes = [];
516                 $personal = false;
517
518                 if ($target_item['origin']) {
519                         $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
520                         logger('Origin item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG);
521                 } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
522                         logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', LOGGER_DEBUG);
523                         return;
524                 } else {
525                         // Remote items are transmitted via the personal inboxes.
526                         // Doing so ensures that the dedicated receiver will get the message.
527                         $personal = true;
528                         logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG);
529                 }
530
531                 if ($parent['origin']) {
532                         $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, $personal);
533                         $inboxes = array_merge($inboxes, $parent_inboxes);
534                 }
535
536                 if (empty($inboxes)) {
537                         logger('No inboxes found for item ' . $item_id . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', LOGGER_DEBUG);
538                         return;
539                 }
540
541                 // Fill the item cache
542                 ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
543
544                 foreach ($inboxes as $inbox) {
545                         logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
546
547                         Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
548                                         'APDelivery', $cmd, $item_id, $inbox, $uid);
549                 }
550         }
551
552         private static function isForumPost($item, $owner) {
553                 if (($item['author-id'] == $item['owner-id']) ||
554                         ($owner['id'] == $item['contact-id']) ||
555                         ($item['uri'] != $item['parent-uri'])) {
556                         return false;
557                 }
558
559                 $fields = ['forum', 'prv'];
560                 $condition = ['id' => $item['contact-id']];
561                 $contact = DBA::selectFirst('contact', $fields, $condition);
562                 if (!DBA::isResult($contact)) {
563                         // Should never happen
564                         return false;
565                 }
566
567                 // Is the post from a forum?
568                 return ($contact['forum'] || $contact['prv']);
569         }
570 }