3 * @file src/Protocol/ActivityPub/Transmitter.php
5 namespace Friendica\Protocol\ActivityPub;
7 use Friendica\BaseObject;
8 use Friendica\Content\Feature;
9 use Friendica\Database\DBA;
10 use Friendica\Core\Config;
11 use Friendica\Core\Logger;
12 use Friendica\Core\System;
13 use Friendica\Util\HTTPSignature;
14 use Friendica\Core\Protocol;
15 use Friendica\Model\Conversation;
16 use Friendica\Model\Contact;
17 use Friendica\Model\APContact;
18 use Friendica\Model\Item;
19 use Friendica\Model\Term;
20 use Friendica\Model\User;
21 use Friendica\Util\DateTimeFormat;
22 use Friendica\Content\Text\BBCode;
23 use Friendica\Content\Text\Plaintext;
24 use Friendica\Util\JsonLD;
25 use Friendica\Util\LDSignature;
26 use Friendica\Model\Profile;
27 use Friendica\Object\Image;
28 use Friendica\Protocol\ActivityPub;
29 use Friendica\Core\Cache;
30 use Friendica\Util\Map;
31 use Friendica\Util\Network;
33 require_once 'include/api.php';
34 require_once 'mod/share.php';
37 * @brief ActivityPub Transmitter Protocol class
45 * collects the lost of followers of the given owner
47 * @param array $owner Owner array
48 * @param integer $page Page number
50 * @return array of owners
51 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
53 public static function getFollowers($owner, $page = null)
55 $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
56 'self' => false, 'deleted' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
57 $count = DBA::count('contact', $condition);
59 $data = ['@context' => ActivityPub::CONTEXT];
60 $data['id'] = System::baseUrl() . '/followers/' . $owner['nickname'];
61 $data['type'] = 'OrderedCollection';
62 $data['totalItems'] = $count;
64 // When we hide our friends we will only show the pure number but don't allow more.
65 $profile = Profile::getByUID($owner['uid']);
66 if (!empty($profile['hide-friends'])) {
71 $data['first'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=1';
75 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
76 while ($contact = DBA::fetch($contacts)) {
77 $list[] = $contact['url'];
81 $data['next'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1);
84 $data['partOf'] = System::baseUrl() . '/followers/' . $owner['nickname'];
86 $data['orderedItems'] = $list;
93 * Create list of following contacts
95 * @param array $owner Owner array
96 * @param integer $page Page numbe
98 * @return array of following contacts
99 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
101 public static function getFollowing($owner, $page = null)
103 $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
104 'self' => false, 'deleted' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
105 $count = DBA::count('contact', $condition);
107 $data = ['@context' => ActivityPub::CONTEXT];
108 $data['id'] = System::baseUrl() . '/following/' . $owner['nickname'];
109 $data['type'] = 'OrderedCollection';
110 $data['totalItems'] = $count;
112 // When we hide our friends we will only show the pure number but don't allow more.
113 $profile = Profile::getByUID($owner['uid']);
114 if (!empty($profile['hide-friends'])) {
119 $data['first'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=1';
123 $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
124 while ($contact = DBA::fetch($contacts)) {
125 $list[] = $contact['url'];
129 $data['next'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1);
132 $data['partOf'] = System::baseUrl() . '/following/' . $owner['nickname'];
134 $data['orderedItems'] = $list;
141 * Public posts for the given owner
143 * @param array $owner Owner array
144 * @param integer $page Page numbe
146 * @return array of posts
147 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
148 * @throws \ImagickException
150 public static function getOutbox($owner, $page = null)
152 $public_contact = Contact::getIdForURL($owner['url'], 0, true);
154 $condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
155 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
156 'deleted' => false, 'visible' => true, 'moderated' => false];
157 $count = DBA::count('item', $condition);
159 $data = ['@context' => ActivityPub::CONTEXT];
160 $data['id'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
161 $data['type'] = 'OrderedCollection';
162 $data['totalItems'] = $count;
165 $data['first'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1';
169 $condition['parent-network'] = Protocol::NATIVE_SUPPORT;
171 $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
172 while ($item = Item::fetch($items)) {
173 $object = self::createObjectFromItemID($item['id']);
174 unset($object['@context']);
179 $data['next'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
182 $data['partOf'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
184 $data['orderedItems'] = $list;
191 * Return the service array containing information the used software and it's url
193 * @return array with service data
195 private static function getService()
197 return ['type' => 'Service',
198 'name' => FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
199 'url' => BaseObject::getApp()->getBaseURL()];
203 * Return the ActivityPub profile of the given user
205 * @param integer $uid User ID
206 * @return array with profile data
207 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
209 public static function getProfile($uid)
211 $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
212 'account_removed' => false, 'verified' => true];
213 $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags'];
214 $user = DBA::selectFirst('user', $fields, $condition);
215 if (!DBA::isResult($user)) {
219 $fields = ['locality', 'region', 'country-name'];
220 $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
221 if (!DBA::isResult($profile)) {
225 $fields = ['name', 'url', 'location', 'about', 'avatar', 'photo'];
226 $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
227 if (!DBA::isResult($contact)) {
231 // On old installations and never changed contacts this might not be filled
232 if (empty($contact['avatar'])) {
233 $contact['avatar'] = $contact['photo'];
236 $data = ['@context' => ActivityPub::CONTEXT];
237 $data['id'] = $contact['url'];
238 $data['diaspora:guid'] = $user['guid'];
239 $data['type'] = ActivityPub::ACCOUNT_TYPES[$user['account-type']];
240 $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
241 $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
242 $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname'];
243 $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname'];
244 $data['preferredUsername'] = $user['nickname'];
245 $data['name'] = $contact['name'];
246 $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'],
247 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
248 $data['summary'] = $contact['about'];
249 $data['url'] = $contact['url'];
250 $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
251 $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
252 'owner' => $contact['url'],
253 'publicKeyPem' => $user['pubkey']];
254 $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
255 $data['icon'] = ['type' => 'Image',
256 'url' => $contact['avatar']];
258 $data['generator'] = self::getService();
260 // tags: https://kitty.town/@inmysocks/100656097926961126.json
265 * @param string $username
267 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
269 public static function getDeletedUser($username)
272 '@context' => ActivityPub::CONTEXT,
273 'id' => System::baseUrl() . '/profile/' . $username,
274 'type' => 'Tombstone',
275 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
276 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
277 'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
282 * Returns an array with permissions of a given item array
286 * @return array with permissions
287 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
288 * @throws \ImagickException
290 private static function fetchPermissionBlockFromConversation($item)
292 if (empty($item['thr-parent'])) {
296 $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
297 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
298 if (!DBA::isResult($conversation)) {
302 $activity = json_decode($conversation['source'], true);
304 $actor = JsonLD::fetchElement($activity, 'actor', 'id');
305 $profile = APContact::getByURL($actor);
307 $item_profile = APContact::getByURL($item['author-link']);
308 $exclude[] = $item['author-link'];
310 if ($item['gravity'] == GRAVITY_PARENT) {
311 $exclude[] = $item['owner-link'];
314 $permissions['to'][] = $actor;
316 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
317 if (empty($activity[$element])) {
320 if (is_string($activity[$element])) {
321 $activity[$element] = [$activity[$element]];
324 foreach ($activity[$element] as $receiver) {
325 if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
326 $permissions[$element][] = $item_profile['followers'];
327 } elseif (!in_array($receiver, $exclude)) {
328 $permissions[$element][] = $receiver;
336 * Creates an array of permissions from an item thread
338 * @param array $item Item array
339 * @param boolean $blindcopy addressing via "bcc" or "cc"?
340 * @param integer $last_id Last item id for adding receivers
341 * @param boolean $forum_mode "true" means that we are sending content to a forum
343 * @return array with permission data
344 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
345 * @throws \ImagickException
347 private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0, $forum_mode = false)
350 $last_id = $item['id'];
355 // Check if we should always deliver our stuff via BCC
356 if (!empty($item['uid'])) {
357 $profile = Profile::getByUID($item['uid']);
358 if (!empty($profile)) {
359 $always_bcc = $profile['hide-friends'];
363 if (Config::get('debug', 'total_ap_delivery')) {
364 // Will be activated in a later step
365 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
367 // For now only send to these contacts:
368 $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
371 $data = ['to' => [], 'cc' => [], 'bcc' => []];
373 if ($item['gravity'] == GRAVITY_PARENT) {
374 $actor_profile = APContact::getByURL($item['owner-link']);
376 $actor_profile = APContact::getByURL($item['author-link']);
379 $terms = Term::tagArrayFromItemId($item['id'], [Term::MENTION, Term::IMPLICIT_MENTION]);
381 if (!$item['private']) {
382 $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
384 $data['to'][] = ActivityPub::PUBLIC_COLLECTION;
386 foreach ($terms as $term) {
387 $profile = APContact::getByURL($term['url'], false);
388 if (!empty($profile)) {
389 $data['to'][] = $profile['url'];
393 $receiver_list = Item::enumeratePermissions($item);
395 foreach ($terms as $term) {
396 $cid = Contact::getIdForURL($term['url'], $item['uid']);
397 if (!empty($cid) && in_array($cid, $receiver_list)) {
398 $contact = DBA::selectFirst('contact', ['url', 'network', 'protocol'], ['id' => $cid]);
399 if (!DBA::isResult($contact) || (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB))) {
403 if (!empty($profile = APContact::getByURL($contact['url'], false))) {
404 $data['to'][] = $profile['url'];
409 foreach ($receiver_list as $receiver) {
410 $contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol'], ['id' => $receiver]);
411 if (!DBA::isResult($contact) || (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB))) {
415 if (!empty($profile = APContact::getByURL($contact['url'], false))) {
416 if ($contact['hidden'] || $always_bcc) {
417 $data['bcc'][] = $profile['url'];
419 $data['cc'][] = $profile['url'];
425 $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
426 while ($parent = Item::fetch($parents)) {
427 if ($parent['gravity'] == GRAVITY_PARENT) {
428 $profile = APContact::getByURL($parent['owner-link'], false);
429 if (!empty($profile)) {
430 if ($item['gravity'] != GRAVITY_PARENT) {
431 // Comments to forums are directed to the forum
432 // But comments to forums aren't directed to the followers collection
433 if ($profile['type'] == 'Group') {
434 $data['to'][] = $profile['url'];
436 $data['cc'][] = $profile['url'];
437 if (!$item['private']) {
438 $data['cc'][] = $actor_profile['followers'];
442 // Public thread parent post always are directed to the followes
443 if (!$item['private'] && !$forum_mode) {
444 $data['cc'][] = $actor_profile['followers'];
450 // Don't include data from future posts
451 if ($parent['id'] >= $last_id) {
455 $profile = APContact::getByURL($parent['author-link'], false);
456 if (!empty($profile)) {
457 if (($profile['type'] == 'Group') || ($parent['uri'] == $item['thr-parent'])) {
458 $data['to'][] = $profile['url'];
460 $data['cc'][] = $profile['url'];
464 DBA::close($parents);
466 $data['to'] = array_unique($data['to']);
467 $data['cc'] = array_unique($data['cc']);
468 $data['bcc'] = array_unique($data['bcc']);
470 if (($key = array_search($item['author-link'], $data['to'])) !== false) {
471 unset($data['to'][$key]);
474 if (($key = array_search($item['author-link'], $data['cc'])) !== false) {
475 unset($data['cc'][$key]);
478 if (($key = array_search($item['author-link'], $data['bcc'])) !== false) {
479 unset($data['bcc'][$key]);
482 foreach ($data['to'] as $to) {
483 if (($key = array_search($to, $data['cc'])) !== false) {
484 unset($data['cc'][$key]);
487 if (($key = array_search($to, $data['bcc'])) !== false) {
488 unset($data['bcc'][$key]);
492 foreach ($data['cc'] as $cc) {
493 if (($key = array_search($cc, $data['bcc'])) !== false) {
494 unset($data['bcc'][$key]);
498 $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])];
501 unset($receivers['bcc']);
508 * Check if an inbox is archived
510 * @param string $url Inbox url
512 * @return boolean "true" if inbox is archived
514 private static function archivedInbox($url)
516 return DBA::exists('inbox-status', ['url' => $url, 'archive' => true]);
520 * Fetches a list of inboxes of followers of a given user
522 * @param integer $uid User ID
523 * @param boolean $personal fetch personal inboxes
525 * @return array of follower inboxes
526 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
527 * @throws \ImagickException
529 public static function fetchTargetInboxesforUser($uid, $personal = false)
533 if (Config::get('debug', 'total_ap_delivery')) {
534 // Will be activated in a later step
535 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
537 // For now only send to these contacts:
538 $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
541 $condition = ['uid' => $uid, 'archive' => false, 'pending' => false];
544 $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
547 $contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
548 while ($contact = DBA::fetch($contacts)) {
549 if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) {
553 if (Network::isUrlBlocked($contact['url'])) {
557 $profile = APContact::getByURL($contact['url'], false);
558 if (!empty($profile)) {
559 if (empty($profile['sharedinbox']) || $personal) {
560 $target = $profile['inbox'];
562 $target = $profile['sharedinbox'];
564 if (!self::archivedInbox($target)) {
565 $inboxes[$target] = $target;
569 DBA::close($contacts);
575 * Fetches an array of inboxes for the given item and user
577 * @param array $item Item array
578 * @param integer $uid User ID
579 * @param boolean $personal fetch personal inboxes
580 * @param integer $last_id Last item id for adding receivers
581 * @param boolean $forum_mode "true" means that we are sending content to a forum
582 * @return array with inboxes
583 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
584 * @throws \ImagickException
586 public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0, $forum_mode = false)
588 $permissions = self::createPermissionBlockForItem($item, true, $last_id, $forum_mode);
589 if (empty($permissions)) {
595 if ($item['gravity'] == GRAVITY_ACTIVITY) {
596 $item_profile = APContact::getByURL($item['author-link'], false);
598 $item_profile = APContact::getByURL($item['owner-link'], false);
601 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
602 if (empty($permissions[$element])) {
606 $blindcopy = in_array($element, ['bto', 'bcc']);
608 foreach ($permissions[$element] as $receiver) {
609 if (Network::isUrlBlocked($receiver)) {
613 if ($receiver == $item_profile['followers']) {
614 $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
616 $profile = APContact::getByURL($receiver, false);
617 if (!empty($profile)) {
618 if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
619 $target = $profile['inbox'];
621 $target = $profile['sharedinbox'];
623 if (!self::archivedInbox($target)) {
624 $inboxes[$target] = $target;
635 * Creates an array in the structure of the item table for a given mail id
637 * @param integer $mail_id
642 public static function ItemArrayFromMail($mail_id)
644 $mail = DBA::selectFirst('mail', [], ['id' => $mail_id]);
646 $reply = DBA::selectFirst('mail', ['uri'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
648 $mail['author-link'] = $mail['owner-link'] = $mail['from-url'];
649 $mail['allow_cid'] = '<'.$mail['contact-id'].'>';
650 $mail['allow_gid'] = '';
651 $mail['deny_cid'] = '';
652 $mail['deny_gid'] = '';
653 $mail['private'] = true;
654 $mail['deleted'] = false;
655 $mail['edited'] = $mail['created'];
656 $mail['plink'] = $mail['uri'];
657 $mail['thr-parent'] = $reply['uri'];
658 $mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
660 $mail['event-type'] = '';
661 $mail['attach'] = '';
669 * Creates an activity array for a given mail id
671 * @param integer $mail_id
672 * @param boolean $object_mode Is the activity item is used inside another object?
674 * @return array of activity
677 public static function createActivityFromMail($mail_id, $object_mode = false)
679 $mail = self::ItemArrayFromMail($mail_id);
680 $object = self::createNote($mail);
682 $object['to'] = $object['cc'];
683 unset($object['cc']);
685 $object['tag'] = [['type' => 'Mention', 'href' => $object['to'][0], 'name' => 'test']];
688 $data = ['@context' => ActivityPub::CONTEXT];
693 $data['id'] = $mail['uri'] . '#Create';
694 $data['type'] = 'Create';
695 $data['actor'] = $mail['author-link'];
696 $data['published'] = DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM);
697 $data['instrument'] = self::getService();
698 $data = array_merge($data, self::createPermissionBlockForItem($mail, true));
700 if (empty($data['to']) && !empty($data['cc'])) {
701 $data['to'] = $data['cc'];
704 if (empty($data['to']) && !empty($data['bcc'])) {
705 $data['to'] = $data['bcc'];
711 $object['to'] = $data['to'];
712 unset($object['cc']);
713 unset($object['bcc']);
715 $data['directMessage'] = true;
717 $data['object'] = $object;
719 $owner = User::getOwnerDataById($mail['uid']);
721 if (!$object_mode && !empty($owner)) {
722 return LDSignature::sign($data, $owner);
729 * Returns the activity type of a given item
733 * @return string with activity type
734 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
735 * @throws \ImagickException
737 private static function getTypeOfItem($item)
741 // Only check for a reshare, if it is a real reshare and no quoted reshare
742 if (strpos($item['body'], "[share") === 0) {
743 $announce = api_share_as_retweet($item);
744 $reshared = !empty($announce['plink']);
749 } elseif ($item['verb'] == ACTIVITY_POST) {
750 if ($item['created'] == $item['edited']) {
755 } elseif ($item['verb'] == ACTIVITY_LIKE) {
757 } elseif ($item['verb'] == ACTIVITY_DISLIKE) {
759 } elseif ($item['verb'] == ACTIVITY_ATTEND) {
761 } elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
763 } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
764 $type = 'TentativeAccept';
765 } elseif ($item['verb'] == ACTIVITY_FOLLOW) {
775 * Creates the activity or fetches it from the cache
777 * @param integer $item_id
778 * @param boolean $force Force new cache entry
780 * @return array with the activity
783 public static function createCachedActivityFromItem($item_id, $force = false)
785 $cachekey = 'APDelivery:createActivity:' . $item_id;
788 $data = Cache::get($cachekey);
789 if (!is_null($data)) {
794 $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
796 Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
801 * Creates an activity array for a given item id
803 * @param integer $item_id
804 * @param boolean $object_mode Is the activity item is used inside another object?
806 * @return array of activity
809 public static function createActivityFromItem($item_id, $object_mode = false)
811 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
813 if (!DBA::isResult($item)) {
817 if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
818 $owner = User::getOwnerDataById($item['uid']);
819 if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
822 // Disguise forum posts as reshares. Will later be converted to a real announce
823 $item['body'] = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
824 $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]';
829 $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
830 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
831 if (DBA::isResult($conversation)) {
832 $data = json_decode($conversation['source'], true);
838 $type = self::getTypeOfItem($item);
842 $data = ['@context' => ActivityPub::CONTEXT];
844 if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
846 } elseif ($item['deleted']) {
853 $data['id'] = $item['uri'] . '#' . $type;
854 $data['type'] = $type;
856 if (Item::isForumPost($item) && ($type != 'Announce')) {
857 $data['actor'] = $item['author-link'];
859 $data['actor'] = $item['owner-link'];
862 $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
864 $data['instrument'] = self::getService();
866 $data = array_merge($data, self::createPermissionBlockForItem($item, false));
868 if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
869 $data['object'] = self::createNote($item);
870 } elseif ($data['type'] == 'Announce') {
871 $data = self::createAnnounce($item, $data);
872 } elseif ($data['type'] == 'Follow') {
873 $data['object'] = $item['parent-uri'];
874 } elseif ($data['type'] == 'Undo') {
875 $data['object'] = self::createActivityFromItem($item_id, true);
877 $data['diaspora:guid'] = $item['guid'];
878 if (!empty($item['signed_text'])) {
879 $data['diaspora:like'] = $item['signed_text'];
881 $data['object'] = $item['thr-parent'];
884 if (!empty($item['contact-uid'])) {
885 $uid = $item['contact-uid'];
890 $owner = User::getOwnerDataById($uid);
892 if (!$object_mode && !empty($owner)) {
893 return LDSignature::sign($data, $owner);
898 /// @todo Create "conversation" entry
902 * Creates an object array for a given item id
904 * @param integer $item_id
906 * @return array with the object data
907 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
908 * @throws \ImagickException
910 public static function createObjectFromItemID($item_id)
912 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
914 if (!DBA::isResult($item)) {
918 $data = ['@context' => ActivityPub::CONTEXT];
919 $data = array_merge($data, self::createNote($item));
925 * Creates a location entry for a given item array
929 * @return array with location array
931 private static function createLocation($item)
933 $location = ['type' => 'Place'];
935 if (!empty($item['location'])) {
936 $location['name'] = $item['location'];
941 if (empty($item['coord'])) {
942 $coord = Map::getCoordinates($item['location']);
944 $coords = explode(' ', $item['coord']);
945 if (count($coords) == 2) {
946 $coord = ['lat' => $coords[0], 'lon' => $coords[1]];
950 if (!empty($coord['lat']) && !empty($coord['lon'])) {
951 $location['latitude'] = $coord['lat'];
952 $location['longitude'] = $coord['lon'];
959 * Returns a tag array for a given item array
963 * @return array of tags
964 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
966 private static function createTagList($item)
970 $terms = Term::tagArrayFromItemId($item['id'], [Term::HASHTAG, Term::MENTION, Term::IMPLICIT_MENTION]);
971 foreach ($terms as $term) {
972 if ($term['type'] == Term::HASHTAG) {
973 $url = System::baseUrl() . '/search?tag=' . urlencode($term['term']);
974 $tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['term']];
975 } elseif ($term['type'] == Term::MENTION || $term['type'] == Term::IMPLICIT_MENTION) {
976 $contact = Contact::getDetailsByURL($term['url']);
977 if (!empty($contact['addr'])) {
978 $mention = '@' . $contact['addr'];
980 $mention = '@' . $term['url'];
983 $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention];
990 * Adds attachment data to the JSON document
992 * @param array $item Data of the item that is to be posted
993 * @param string $type Object type
995 * @return array with attachment data
996 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
998 private static function createAttachmentList($item, $type)
1002 $arr = explode('[/attach],', $item['attach']);
1004 foreach ($arr as $r) {
1006 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
1008 $attributes = ['type' => 'Document',
1009 'mediaType' => $matches[3],
1010 'url' => $matches[1],
1013 if (trim($matches[4]) != '') {
1014 $attributes['name'] = trim($matches[4]);
1017 $attachments[] = $attributes;
1022 if ($type != 'Note') {
1023 return $attachments;
1026 // Simplify image codes
1027 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
1029 // Grab all pictures and create attachments out of them
1030 if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
1031 foreach ($pictures[1] as $picture) {
1032 $imgdata = Image::getInfoFromURL($picture);
1034 $attachments[] = ['type' => 'Document',
1035 'mediaType' => $imgdata['mime'],
1042 return $attachments;
1046 * @brief Callback function to replace a Friendica style mention in a mention that is used on AP
1048 * @param array $match Matching values for the callback
1049 * @return string Replaced mention
1050 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1052 private static function mentionCallback($match)
1054 if (empty($match[1])) {
1058 $data = Contact::getDetailsByURL($match[1]);
1059 if (empty($data['nick'])) {
1063 return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
1067 * Remove image elements and replaces them with links to the image
1069 * @param string $body
1071 * @return string with replaced elements
1073 private static function removePictures($body)
1075 // Simplify image codes
1076 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
1078 $body = preg_replace("/\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]/Usi", '[url]$1[/url]', $body);
1079 $body = preg_replace("/\[img\]([^\[\]]*)\[\/img\]/Usi", '[url]$1[/url]', $body);
1085 * Fetches the "context" value for a givem item array from the "conversation" table
1087 * @param array $item
1089 * @return string with context url
1090 * @throws \Exception
1092 private static function fetchContextURLForItem($item)
1094 $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
1095 if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
1096 $context_uri = $conversation['conversation-href'];
1097 } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
1098 $context_uri = $conversation['conversation-uri'];
1100 $context_uri = $item['parent-uri'] . '#context';
1102 return $context_uri;
1106 * Returns if the post contains sensitive content ("nsfw")
1108 * @param integer $item_id
1111 * @throws \Exception
1113 private static function isSensitive($item_id)
1115 $condition = ['otype' => TERM_OBJ_POST, 'oid' => $item_id, 'type' => TERM_HASHTAG, 'term' => 'nsfw'];
1116 return DBA::exists('term', $condition);
1120 * Creates event data
1122 * @param array $item
1124 * @return array with the event data
1125 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1127 public static function createEvent($item)
1130 $event['name'] = $item['event-summary'];
1131 $event['content'] = BBCode::convert($item['event-desc'], false, 7);
1132 $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM);
1134 if (!$item['event-nofinish']) {
1135 $event['endTime'] = DateTimeFormat::utc($item['event-finish'] . '+00:00', DateTimeFormat::ATOM);
1138 if (!empty($item['event-location'])) {
1139 $item['location'] = $item['event-location'];
1140 $event['location'] = self::createLocation($item);
1147 * Creates a note/article object array
1149 * @param array $item
1151 * @return array with the object data
1152 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1153 * @throws \ImagickException
1155 public static function createNote($item)
1157 if ($item['event-type'] == 'event') {
1159 } elseif (!empty($item['title'])) {
1165 if ($item['deleted']) {
1166 $type = 'Tombstone';
1170 $data['id'] = $item['uri'];
1171 $data['type'] = $type;
1173 if ($item['deleted']) {
1177 $data['summary'] = BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
1179 if ($item['uri'] != $item['thr-parent']) {
1180 $data['inReplyTo'] = $item['thr-parent'];
1182 $data['inReplyTo'] = null;
1185 $data['diaspora:guid'] = $item['guid'];
1186 $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
1188 if ($item['created'] != $item['edited']) {
1189 $data['updated'] = DateTimeFormat::utc($item['edited'] . '+00:00', DateTimeFormat::ATOM);
1192 $data['url'] = $item['plink'];
1193 $data['attributedTo'] = $item['author-link'];
1194 $data['sensitive'] = self::isSensitive($item['id']);
1195 $data['context'] = self::fetchContextURLForItem($item);
1197 if (!empty($item['title'])) {
1198 $data['name'] = BBCode::toPlaintext($item['title'], false);
1201 $permission_block = self::createPermissionBlockForItem($item, false);
1203 $body = $item['body'];
1205 if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
1206 $body = self::prependMentions($body, $permission_block);
1209 if ($type == 'Note') {
1210 $body = self::removePictures($body);
1211 } elseif (($type == 'Article') && empty($data['summary'])) {
1212 $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
1215 if ($type == 'Event') {
1216 $data = array_merge($data, self::createEvent($item));
1218 $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
1219 $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
1221 $data['content'] = BBCode::convert($body, false, 7);
1224 $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
1226 if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) {
1227 $data['diaspora:comment'] = $item['signed_text'];
1230 $data['attachment'] = self::createAttachmentList($item, $type);
1231 $data['tag'] = self::createTagList($item);
1233 if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
1234 $data['location'] = self::createLocation($item);
1237 if (!empty($item['app'])) {
1238 $data['generator'] = ['type' => 'Application', 'name' => $item['app']];
1241 $data = array_merge($data, $permission_block);
1247 * Creates an announce object entry
1249 * @param array $item
1250 * @param array $data activity data
1252 * @return array with activity data
1253 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1254 * @throws \ImagickException
1256 private static function createAnnounce($item, $data)
1258 $announce = api_share_as_retweet($item);
1259 if (empty($announce['plink'])) {
1260 $data['type'] = 'Create';
1261 $data['object'] = self::createNote($item);
1265 // Fetch the original id of the object
1266 $activity = ActivityPub::fetchContent($announce['plink'], $item['uid']);
1267 if (!empty($activity)) {
1268 $ldactivity = JsonLD::compact($activity);
1269 $id = JsonLD::fetchElement($ldactivity, '@id');
1271 $data['object'] = $id;
1276 $data['type'] = 'Create';
1277 $data['object'] = self::createNote($item);
1282 * Creates an activity id for a given contact id
1284 * @param integer $cid Contact ID of target
1286 * @return bool|string activity id
1288 public static function activityIDFromContact($cid)
1290 $contact = DBA::selectFirst('contact', ['uid', 'id', 'created'], ['id' => $cid]);
1291 if (!DBA::isResult($contact)) {
1295 $hash = hash('ripemd128', $contact['uid'].'-'.$contact['id'].'-'.$contact['created']);
1296 $uuid = substr($hash, 0, 8). '-' . substr($hash, 8, 4) . '-' . substr($hash, 12, 4) . '-' . substr($hash, 16, 4) . '-' . substr($hash, 20, 12);
1297 return System::baseUrl() . '/activity/' . $uuid;
1301 * Transmits a contact suggestion to a given inbox
1303 * @param integer $uid User ID
1304 * @param string $inbox Target inbox
1305 * @param integer $suggestion_id Suggestion ID
1307 * @return boolean was the transmission successful?
1308 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1310 public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
1312 $owner = User::getOwnerDataById($uid);
1314 $suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]);
1316 $data = ['@context' => ActivityPub::CONTEXT,
1317 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1318 'type' => 'Announce',
1319 'actor' => $owner['url'],
1320 'object' => $suggestion['url'],
1321 'content' => $suggestion['note'],
1322 'instrument' => self::getService(),
1323 'to' => [ActivityPub::PUBLIC_COLLECTION],
1326 $signed = LDSignature::sign($data, $owner);
1328 Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1329 return HTTPSignature::transmit($signed, $inbox, $uid);
1333 * Transmits a profile relocation to a given inbox
1335 * @param integer $uid User ID
1336 * @param string $inbox Target inbox
1338 * @return boolean was the transmission successful?
1339 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1341 public static function sendProfileRelocation($uid, $inbox)
1343 $owner = User::getOwnerDataById($uid);
1345 $data = ['@context' => ActivityPub::CONTEXT,
1346 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1347 'type' => 'dfrn:relocate',
1348 'actor' => $owner['url'],
1349 'object' => $owner['url'],
1350 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1351 'instrument' => self::getService(),
1352 'to' => [ActivityPub::PUBLIC_COLLECTION],
1355 $signed = LDSignature::sign($data, $owner);
1357 Logger::log('Deliver profile relocation for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1358 return HTTPSignature::transmit($signed, $inbox, $uid);
1362 * Transmits a profile deletion to a given inbox
1364 * @param integer $uid User ID
1365 * @param string $inbox Target inbox
1367 * @return boolean was the transmission successful?
1368 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1370 public static function sendProfileDeletion($uid, $inbox)
1372 $owner = User::getOwnerDataById($uid);
1374 if (empty($owner)) {
1375 Logger::error('No owner data found, the deletion message cannot be processed.', ['user' => $uid]);
1379 if (empty($owner['uprvkey'])) {
1380 Logger::error('No private key for owner found, the deletion message cannot be processed.', ['user' => $uid]);
1384 $data = ['@context' => ActivityPub::CONTEXT,
1385 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1387 'actor' => $owner['url'],
1388 'object' => $owner['url'],
1389 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1390 'instrument' => self::getService(),
1391 'to' => [ActivityPub::PUBLIC_COLLECTION],
1394 $signed = LDSignature::sign($data, $owner);
1396 Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1397 return HTTPSignature::transmit($signed, $inbox, $uid);
1401 * Transmits a profile change to a given inbox
1403 * @param integer $uid User ID
1404 * @param string $inbox Target inbox
1406 * @return boolean was the transmission successful?
1407 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1408 * @throws \ImagickException
1410 public static function sendProfileUpdate($uid, $inbox)
1412 $owner = User::getOwnerDataById($uid);
1413 $profile = APContact::getByURL($owner['url']);
1415 $data = ['@context' => ActivityPub::CONTEXT,
1416 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1418 'actor' => $owner['url'],
1419 'object' => self::getProfile($uid),
1420 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1421 'instrument' => self::getService(),
1422 'to' => [$profile['followers']],
1425 $signed = LDSignature::sign($data, $owner);
1427 Logger::log('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1428 return HTTPSignature::transmit($signed, $inbox, $uid);
1432 * Transmits a given activity to a target
1434 * @param string $activity Type name
1435 * @param string $target Target profile
1436 * @param integer $uid User ID
1438 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1439 * @throws \ImagickException
1440 * @throws \Exception
1442 public static function sendActivity($activity, $target, $uid, $id = '')
1444 $profile = APContact::getByURL($target);
1446 $owner = User::getOwnerDataById($uid);
1449 $id = System::baseUrl() . '/activity/' . System::createGUID();
1452 $data = ['@context' => ActivityPub::CONTEXT,
1454 'type' => $activity,
1455 'actor' => $owner['url'],
1456 'object' => $profile['url'],
1457 'instrument' => self::getService(),
1458 'to' => [$profile['url']]];
1460 Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
1462 $signed = LDSignature::sign($data, $owner);
1463 return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1467 * Transmits a "follow object" activity to a target
1468 * This is a preparation for sending automated "follow" requests when receiving "Announce" messages
1470 * @param string $object Object URL
1471 * @param string $target Target profile
1472 * @param integer $uid User ID
1474 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1475 * @throws \ImagickException
1476 * @throws \Exception
1478 public static function sendFollowObject($object, $target, $uid = 0)
1480 $profile = APContact::getByURL($target);
1483 // Fetch the list of administrators
1484 $admin_mail = explode(',', str_replace(' ', '', Config::get('config', 'admin_email')));
1486 // We need to use some user as a sender. It doesn't care who it will send. We will use an administrator account.
1487 $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'email' => $admin_mail];
1488 $first_user = DBA::selectFirst('user', ['uid'], $condition);
1489 $uid = $first_user['uid'];
1492 $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
1493 'author-id' => Contact::getPublicIdByUserId($uid)];
1494 if (Item::exists($condition)) {
1495 Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
1499 $owner = User::getOwnerDataById($uid);
1501 $data = ['@context' => ActivityPub::CONTEXT,
1502 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1504 'actor' => $owner['url'],
1505 'object' => $object,
1506 'instrument' => self::getService(),
1507 'to' => [$profile['url']]];
1509 Logger::log('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
1511 $signed = LDSignature::sign($data, $owner);
1512 return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1516 * Transmit a message that the contact request had been accepted
1518 * @param string $target Target profile
1520 * @param integer $uid User ID
1521 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1522 * @throws \ImagickException
1524 public static function sendContactAccept($target, $id, $uid)
1526 $profile = APContact::getByURL($target);
1528 $owner = User::getOwnerDataById($uid);
1529 $data = ['@context' => ActivityPub::CONTEXT,
1530 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1532 'actor' => $owner['url'],
1533 'object' => ['id' => $id, 'type' => 'Follow',
1534 'actor' => $profile['url'],
1535 'object' => $owner['url']],
1536 'instrument' => self::getService(),
1537 'to' => [$profile['url']]];
1539 Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1541 $signed = LDSignature::sign($data, $owner);
1542 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1546 * Reject a contact request or terminates the contact relation
1548 * @param string $target Target profile
1550 * @param integer $uid User ID
1551 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1552 * @throws \ImagickException
1554 public static function sendContactReject($target, $id, $uid)
1556 $profile = APContact::getByURL($target);
1558 $owner = User::getOwnerDataById($uid);
1559 $data = ['@context' => ActivityPub::CONTEXT,
1560 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1562 'actor' => $owner['url'],
1563 'object' => ['id' => $id, 'type' => 'Follow',
1564 'actor' => $profile['url'],
1565 'object' => $owner['url']],
1566 'instrument' => self::getService(),
1567 'to' => [$profile['url']]];
1569 Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1571 $signed = LDSignature::sign($data, $owner);
1572 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1576 * Transmits a message that we don't want to follow this contact anymore
1578 * @param string $target Target profile
1579 * @param integer $uid User ID
1580 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1581 * @throws \ImagickException
1582 * @throws \Exception
1584 public static function sendContactUndo($target, $cid, $uid)
1586 $profile = APContact::getByURL($target);
1588 $object_id = self::activityIDFromContact($cid);
1589 if (empty($object_id)) {
1593 $id = System::baseUrl() . '/activity/' . System::createGUID();
1595 $owner = User::getOwnerDataById($uid);
1596 $data = ['@context' => ActivityPub::CONTEXT,
1599 'actor' => $owner['url'],
1600 'object' => ['id' => $object_id, 'type' => 'Follow',
1601 'actor' => $owner['url'],
1602 'object' => $profile['url']],
1603 'instrument' => self::getService(),
1604 'to' => [$profile['url']]];
1606 Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1608 $signed = LDSignature::sign($data, $owner);
1609 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1612 private static function prependMentions($body, array $permission_block)
1614 if (Config::get('system', 'disable_implicit_mentions')) {
1620 foreach ($permission_block['to'] as $profile_url) {
1621 $profile = Contact::getDetailsByURL($profile_url);
1622 if (!empty($profile['addr'])
1623 && $profile['contact-type'] != Contact::TYPE_COMMUNITY
1624 && !strstr($body, $profile['addr'])
1625 && !strstr($body, $profile_url)
1627 $mentions[] = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url]';
1631 $mentions[] = $body;
1633 return implode(' ', $mentions);