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 if (!empty($item['parent'])) {
426 $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
427 while ($parent = Item::fetch($parents)) {
428 if ($parent['gravity'] == GRAVITY_PARENT) {
429 $profile = APContact::getByURL($parent['owner-link'], false);
430 if (!empty($profile)) {
431 if ($item['gravity'] != GRAVITY_PARENT) {
432 // Comments to forums are directed to the forum
433 // But comments to forums aren't directed to the followers collection
434 if ($profile['type'] == 'Group') {
435 $data['to'][] = $profile['url'];
437 $data['cc'][] = $profile['url'];
438 if (!$item['private']) {
439 $data['cc'][] = $actor_profile['followers'];
443 // Public thread parent post always are directed to the followes
444 if (!$item['private'] && !$forum_mode) {
445 $data['cc'][] = $actor_profile['followers'];
451 // Don't include data from future posts
452 if ($parent['id'] >= $last_id) {
456 $profile = APContact::getByURL($parent['author-link'], false);
457 if (!empty($profile)) {
458 if (($profile['type'] == 'Group') || ($parent['uri'] == $item['thr-parent'])) {
459 $data['to'][] = $profile['url'];
461 $data['cc'][] = $profile['url'];
465 DBA::close($parents);
468 $data['to'] = array_unique($data['to']);
469 $data['cc'] = array_unique($data['cc']);
470 $data['bcc'] = array_unique($data['bcc']);
472 if (($key = array_search($item['author-link'], $data['to'])) !== false) {
473 unset($data['to'][$key]);
476 if (($key = array_search($item['author-link'], $data['cc'])) !== false) {
477 unset($data['cc'][$key]);
480 if (($key = array_search($item['author-link'], $data['bcc'])) !== false) {
481 unset($data['bcc'][$key]);
484 foreach ($data['to'] as $to) {
485 if (($key = array_search($to, $data['cc'])) !== false) {
486 unset($data['cc'][$key]);
489 if (($key = array_search($to, $data['bcc'])) !== false) {
490 unset($data['bcc'][$key]);
494 foreach ($data['cc'] as $cc) {
495 if (($key = array_search($cc, $data['bcc'])) !== false) {
496 unset($data['bcc'][$key]);
500 $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])];
503 unset($receivers['bcc']);
510 * Check if an inbox is archived
512 * @param string $url Inbox url
514 * @return boolean "true" if inbox is archived
516 private static function archivedInbox($url)
518 return DBA::exists('inbox-status', ['url' => $url, 'archive' => true]);
522 * Fetches a list of inboxes of followers of a given user
524 * @param integer $uid User ID
525 * @param boolean $personal fetch personal inboxes
527 * @return array of follower inboxes
528 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
529 * @throws \ImagickException
531 public static function fetchTargetInboxesforUser($uid, $personal = false)
535 if (Config::get('debug', 'total_ap_delivery')) {
536 // Will be activated in a later step
537 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
539 // For now only send to these contacts:
540 $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
543 $condition = ['uid' => $uid, 'archive' => false, 'pending' => false];
546 $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
549 $contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
550 while ($contact = DBA::fetch($contacts)) {
551 if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) {
555 if (Network::isUrlBlocked($contact['url'])) {
559 $profile = APContact::getByURL($contact['url'], false);
560 if (!empty($profile)) {
561 if (empty($profile['sharedinbox']) || $personal) {
562 $target = $profile['inbox'];
564 $target = $profile['sharedinbox'];
566 if (!self::archivedInbox($target)) {
567 $inboxes[$target] = $target;
571 DBA::close($contacts);
577 * Fetches an array of inboxes for the given item and user
579 * @param array $item Item array
580 * @param integer $uid User ID
581 * @param boolean $personal fetch personal inboxes
582 * @param integer $last_id Last item id for adding receivers
583 * @param boolean $forum_mode "true" means that we are sending content to a forum
584 * @return array with inboxes
585 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
586 * @throws \ImagickException
588 public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0, $forum_mode = false)
590 $permissions = self::createPermissionBlockForItem($item, true, $last_id, $forum_mode);
591 if (empty($permissions)) {
597 if ($item['gravity'] == GRAVITY_ACTIVITY) {
598 $item_profile = APContact::getByURL($item['author-link'], false);
600 $item_profile = APContact::getByURL($item['owner-link'], false);
603 foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
604 if (empty($permissions[$element])) {
608 $blindcopy = in_array($element, ['bto', 'bcc']);
610 foreach ($permissions[$element] as $receiver) {
611 if (Network::isUrlBlocked($receiver)) {
615 if ($receiver == $item_profile['followers']) {
616 $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
618 $profile = APContact::getByURL($receiver, false);
619 if (!empty($profile)) {
620 if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
621 $target = $profile['inbox'];
623 $target = $profile['sharedinbox'];
625 if (!self::archivedInbox($target)) {
626 $inboxes[$target] = $target;
637 * Creates an array in the structure of the item table for a given mail id
639 * @param integer $mail_id
644 public static function ItemArrayFromMail($mail_id)
646 $mail = DBA::selectFirst('mail', [], ['id' => $mail_id]);
648 $reply = DBA::selectFirst('mail', ['uri'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
650 $mail['author-link'] = $mail['owner-link'] = $mail['from-url'];
651 $mail['allow_cid'] = '<'.$mail['contact-id'].'>';
652 $mail['allow_gid'] = '';
653 $mail['deny_cid'] = '';
654 $mail['deny_gid'] = '';
655 $mail['private'] = true;
656 $mail['deleted'] = false;
657 $mail['edited'] = $mail['created'];
658 $mail['plink'] = $mail['uri'];
659 $mail['thr-parent'] = $reply['uri'];
660 $mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
662 $mail['event-type'] = '';
663 $mail['attach'] = '';
671 * Creates an activity array for a given mail id
673 * @param integer $mail_id
674 * @param boolean $object_mode Is the activity item is used inside another object?
676 * @return array of activity
679 public static function createActivityFromMail($mail_id, $object_mode = false)
681 $mail = self::ItemArrayFromMail($mail_id);
682 $object = self::createNote($mail);
684 $object['to'] = $object['cc'];
685 unset($object['cc']);
687 $object['tag'] = [['type' => 'Mention', 'href' => $object['to'][0], 'name' => 'test']];
690 $data = ['@context' => ActivityPub::CONTEXT];
695 $data['id'] = $mail['uri'] . '#Create';
696 $data['type'] = 'Create';
697 $data['actor'] = $mail['author-link'];
698 $data['published'] = DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM);
699 $data['instrument'] = self::getService();
700 $data = array_merge($data, self::createPermissionBlockForItem($mail, true));
702 if (empty($data['to']) && !empty($data['cc'])) {
703 $data['to'] = $data['cc'];
706 if (empty($data['to']) && !empty($data['bcc'])) {
707 $data['to'] = $data['bcc'];
713 $object['to'] = $data['to'];
714 unset($object['cc']);
715 unset($object['bcc']);
717 $data['directMessage'] = true;
719 $data['object'] = $object;
721 $owner = User::getOwnerDataById($mail['uid']);
723 if (!$object_mode && !empty($owner)) {
724 return LDSignature::sign($data, $owner);
731 * Returns the activity type of a given item
735 * @return string with activity type
736 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
737 * @throws \ImagickException
739 private static function getTypeOfItem($item)
743 // Only check for a reshare, if it is a real reshare and no quoted reshare
744 if (strpos($item['body'], "[share") === 0) {
745 $announce = api_share_as_retweet($item);
746 $reshared = !empty($announce['plink']);
751 } elseif ($item['verb'] == ACTIVITY_POST) {
752 if ($item['created'] == $item['edited']) {
757 } elseif ($item['verb'] == ACTIVITY_LIKE) {
759 } elseif ($item['verb'] == ACTIVITY_DISLIKE) {
761 } elseif ($item['verb'] == ACTIVITY_ATTEND) {
763 } elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
765 } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
766 $type = 'TentativeAccept';
767 } elseif ($item['verb'] == ACTIVITY_FOLLOW) {
777 * Creates the activity or fetches it from the cache
779 * @param integer $item_id
780 * @param boolean $force Force new cache entry
782 * @return array with the activity
785 public static function createCachedActivityFromItem($item_id, $force = false)
787 $cachekey = 'APDelivery:createActivity:' . $item_id;
790 $data = Cache::get($cachekey);
791 if (!is_null($data)) {
796 $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
798 Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
803 * Creates an activity array for a given item id
805 * @param integer $item_id
806 * @param boolean $object_mode Is the activity item is used inside another object?
808 * @return array of activity
811 public static function createActivityFromItem($item_id, $object_mode = false)
813 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
815 if (!DBA::isResult($item)) {
819 if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
820 $owner = User::getOwnerDataById($item['uid']);
821 if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
824 // Disguise forum posts as reshares. Will later be converted to a real announce
825 $item['body'] = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
826 $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]';
831 $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
832 $conversation = DBA::selectFirst('conversation', ['source'], $condition);
833 if (DBA::isResult($conversation)) {
834 $data = json_decode($conversation['source'], true);
840 $type = self::getTypeOfItem($item);
844 $data = ['@context' => ActivityPub::CONTEXT];
846 if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) {
848 } elseif ($item['deleted']) {
855 $data['id'] = $item['uri'] . '#' . $type;
856 $data['type'] = $type;
858 if (Item::isForumPost($item) && ($type != 'Announce')) {
859 $data['actor'] = $item['author-link'];
861 $data['actor'] = $item['owner-link'];
864 $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
866 $data['instrument'] = self::getService();
868 $data = array_merge($data, self::createPermissionBlockForItem($item, false));
870 if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
871 $data['object'] = self::createNote($item);
872 } elseif ($data['type'] == 'Announce') {
873 $data = self::createAnnounce($item, $data);
874 } elseif ($data['type'] == 'Follow') {
875 $data['object'] = $item['parent-uri'];
876 } elseif ($data['type'] == 'Undo') {
877 $data['object'] = self::createActivityFromItem($item_id, true);
879 $data['diaspora:guid'] = $item['guid'];
880 if (!empty($item['signed_text'])) {
881 $data['diaspora:like'] = $item['signed_text'];
883 $data['object'] = $item['thr-parent'];
886 if (!empty($item['contact-uid'])) {
887 $uid = $item['contact-uid'];
892 $owner = User::getOwnerDataById($uid);
894 if (!$object_mode && !empty($owner)) {
895 return LDSignature::sign($data, $owner);
900 /// @todo Create "conversation" entry
904 * Creates an object array for a given item id
906 * @param integer $item_id
908 * @return array with the object data
909 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
910 * @throws \ImagickException
912 public static function createObjectFromItemID($item_id)
914 $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
916 if (!DBA::isResult($item)) {
920 $data = ['@context' => ActivityPub::CONTEXT];
921 $data = array_merge($data, self::createNote($item));
927 * Creates a location entry for a given item array
931 * @return array with location array
933 private static function createLocation($item)
935 $location = ['type' => 'Place'];
937 if (!empty($item['location'])) {
938 $location['name'] = $item['location'];
943 if (empty($item['coord'])) {
944 $coord = Map::getCoordinates($item['location']);
946 $coords = explode(' ', $item['coord']);
947 if (count($coords) == 2) {
948 $coord = ['lat' => $coords[0], 'lon' => $coords[1]];
952 if (!empty($coord['lat']) && !empty($coord['lon'])) {
953 $location['latitude'] = $coord['lat'];
954 $location['longitude'] = $coord['lon'];
961 * Returns a tag array for a given item array
965 * @return array of tags
966 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
968 private static function createTagList($item)
972 $terms = Term::tagArrayFromItemId($item['id'], [Term::HASHTAG, Term::MENTION, Term::IMPLICIT_MENTION]);
973 foreach ($terms as $term) {
974 if ($term['type'] == Term::HASHTAG) {
975 $url = System::baseUrl() . '/search?tag=' . urlencode($term['term']);
976 $tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['term']];
977 } elseif ($term['type'] == Term::MENTION || $term['type'] == Term::IMPLICIT_MENTION) {
978 $contact = Contact::getDetailsByURL($term['url']);
979 if (!empty($contact['addr'])) {
980 $mention = '@' . $contact['addr'];
982 $mention = '@' . $term['url'];
985 $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention];
992 * Adds attachment data to the JSON document
994 * @param array $item Data of the item that is to be posted
995 * @param string $type Object type
997 * @return array with attachment data
998 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1000 private static function createAttachmentList($item, $type)
1004 $arr = explode('[/attach],', $item['attach']);
1006 foreach ($arr as $r) {
1008 $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
1010 $attributes = ['type' => 'Document',
1011 'mediaType' => $matches[3],
1012 'url' => $matches[1],
1015 if (trim($matches[4]) != '') {
1016 $attributes['name'] = trim($matches[4]);
1019 $attachments[] = $attributes;
1024 if ($type != 'Note') {
1025 return $attachments;
1028 // Simplify image codes
1029 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
1031 // Grab all pictures and create attachments out of them
1032 if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
1033 foreach ($pictures[1] as $picture) {
1034 $imgdata = Image::getInfoFromURL($picture);
1036 $attachments[] = ['type' => 'Document',
1037 'mediaType' => $imgdata['mime'],
1044 return $attachments;
1048 * @brief Callback function to replace a Friendica style mention in a mention that is used on AP
1050 * @param array $match Matching values for the callback
1051 * @return string Replaced mention
1052 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1054 private static function mentionCallback($match)
1056 if (empty($match[1])) {
1060 $data = Contact::getDetailsByURL($match[1]);
1061 if (empty($data['nick'])) {
1065 return '@[url=' . $data['url'] . ']' . $data['nick'] . '[/url]';
1069 * Remove image elements and replaces them with links to the image
1071 * @param string $body
1073 * @return string with replaced elements
1075 private static function removePictures($body)
1077 // Simplify image codes
1078 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
1080 $body = preg_replace("/\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]/Usi", '[url]$1[/url]', $body);
1081 $body = preg_replace("/\[img\]([^\[\]]*)\[\/img\]/Usi", '[url]$1[/url]', $body);
1087 * Fetches the "context" value for a givem item array from the "conversation" table
1089 * @param array $item
1091 * @return string with context url
1092 * @throws \Exception
1094 private static function fetchContextURLForItem($item)
1096 $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
1097 if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
1098 $context_uri = $conversation['conversation-href'];
1099 } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
1100 $context_uri = $conversation['conversation-uri'];
1102 $context_uri = $item['parent-uri'] . '#context';
1104 return $context_uri;
1108 * Returns if the post contains sensitive content ("nsfw")
1110 * @param integer $item_id
1113 * @throws \Exception
1115 private static function isSensitive($item_id)
1117 $condition = ['otype' => TERM_OBJ_POST, 'oid' => $item_id, 'type' => TERM_HASHTAG, 'term' => 'nsfw'];
1118 return DBA::exists('term', $condition);
1122 * Creates event data
1124 * @param array $item
1126 * @return array with the event data
1127 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1129 public static function createEvent($item)
1132 $event['name'] = $item['event-summary'];
1133 $event['content'] = BBCode::convert($item['event-desc'], false, 7);
1134 $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM);
1136 if (!$item['event-nofinish']) {
1137 $event['endTime'] = DateTimeFormat::utc($item['event-finish'] . '+00:00', DateTimeFormat::ATOM);
1140 if (!empty($item['event-location'])) {
1141 $item['location'] = $item['event-location'];
1142 $event['location'] = self::createLocation($item);
1149 * Creates a note/article object array
1151 * @param array $item
1153 * @return array with the object data
1154 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1155 * @throws \ImagickException
1157 public static function createNote($item)
1159 if ($item['event-type'] == 'event') {
1161 } elseif (!empty($item['title'])) {
1167 if ($item['deleted']) {
1168 $type = 'Tombstone';
1172 $data['id'] = $item['uri'];
1173 $data['type'] = $type;
1175 if ($item['deleted']) {
1179 $data['summary'] = BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
1181 if ($item['uri'] != $item['thr-parent']) {
1182 $data['inReplyTo'] = $item['thr-parent'];
1184 $data['inReplyTo'] = null;
1187 $data['diaspora:guid'] = $item['guid'];
1188 $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
1190 if ($item['created'] != $item['edited']) {
1191 $data['updated'] = DateTimeFormat::utc($item['edited'] . '+00:00', DateTimeFormat::ATOM);
1194 $data['url'] = $item['plink'];
1195 $data['attributedTo'] = $item['author-link'];
1196 $data['sensitive'] = self::isSensitive($item['id']);
1197 $data['context'] = self::fetchContextURLForItem($item);
1199 if (!empty($item['title'])) {
1200 $data['name'] = BBCode::toPlaintext($item['title'], false);
1203 $permission_block = self::createPermissionBlockForItem($item, false);
1205 $body = $item['body'];
1207 if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
1208 $body = self::prependMentions($body, $permission_block);
1211 if ($type == 'Note') {
1212 $body = self::removePictures($body);
1213 } elseif (($type == 'Article') && empty($data['summary'])) {
1214 $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
1217 if ($type == 'Event') {
1218 $data = array_merge($data, self::createEvent($item));
1220 $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
1221 $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
1223 $data['content'] = BBCode::convert($body, false, 7);
1226 $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];
1228 if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) {
1229 $data['diaspora:comment'] = $item['signed_text'];
1232 $data['attachment'] = self::createAttachmentList($item, $type);
1233 $data['tag'] = self::createTagList($item);
1235 if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
1236 $data['location'] = self::createLocation($item);
1239 if (!empty($item['app'])) {
1240 $data['generator'] = ['type' => 'Application', 'name' => $item['app']];
1243 $data = array_merge($data, $permission_block);
1249 * Creates an announce object entry
1251 * @param array $item
1252 * @param array $data activity data
1254 * @return array with activity data
1255 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1256 * @throws \ImagickException
1258 private static function createAnnounce($item, $data)
1260 $announce = api_share_as_retweet($item);
1261 if (empty($announce['plink'])) {
1262 $data['type'] = 'Create';
1263 $data['object'] = self::createNote($item);
1267 // Fetch the original id of the object
1268 $activity = ActivityPub::fetchContent($announce['plink'], $item['uid']);
1269 if (!empty($activity)) {
1270 $ldactivity = JsonLD::compact($activity);
1271 $id = JsonLD::fetchElement($ldactivity, '@id');
1273 $data['object'] = $id;
1278 $data['type'] = 'Create';
1279 $data['object'] = self::createNote($item);
1284 * Creates an activity id for a given contact id
1286 * @param integer $cid Contact ID of target
1288 * @return bool|string activity id
1290 public static function activityIDFromContact($cid)
1292 $contact = DBA::selectFirst('contact', ['uid', 'id', 'created'], ['id' => $cid]);
1293 if (!DBA::isResult($contact)) {
1297 $hash = hash('ripemd128', $contact['uid'].'-'.$contact['id'].'-'.$contact['created']);
1298 $uuid = substr($hash, 0, 8). '-' . substr($hash, 8, 4) . '-' . substr($hash, 12, 4) . '-' . substr($hash, 16, 4) . '-' . substr($hash, 20, 12);
1299 return System::baseUrl() . '/activity/' . $uuid;
1303 * Transmits a contact suggestion to a given inbox
1305 * @param integer $uid User ID
1306 * @param string $inbox Target inbox
1307 * @param integer $suggestion_id Suggestion ID
1309 * @return boolean was the transmission successful?
1310 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1312 public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
1314 $owner = User::getOwnerDataById($uid);
1316 $suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]);
1318 $data = ['@context' => ActivityPub::CONTEXT,
1319 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1320 'type' => 'Announce',
1321 'actor' => $owner['url'],
1322 'object' => $suggestion['url'],
1323 'content' => $suggestion['note'],
1324 'instrument' => self::getService(),
1325 'to' => [ActivityPub::PUBLIC_COLLECTION],
1328 $signed = LDSignature::sign($data, $owner);
1330 Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1331 return HTTPSignature::transmit($signed, $inbox, $uid);
1335 * Transmits a profile relocation to a given inbox
1337 * @param integer $uid User ID
1338 * @param string $inbox Target inbox
1340 * @return boolean was the transmission successful?
1341 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1343 public static function sendProfileRelocation($uid, $inbox)
1345 $owner = User::getOwnerDataById($uid);
1347 $data = ['@context' => ActivityPub::CONTEXT,
1348 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1349 'type' => 'dfrn:relocate',
1350 'actor' => $owner['url'],
1351 'object' => $owner['url'],
1352 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1353 'instrument' => self::getService(),
1354 'to' => [ActivityPub::PUBLIC_COLLECTION],
1357 $signed = LDSignature::sign($data, $owner);
1359 Logger::log('Deliver profile relocation for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1360 return HTTPSignature::transmit($signed, $inbox, $uid);
1364 * Transmits a profile deletion to a given inbox
1366 * @param integer $uid User ID
1367 * @param string $inbox Target inbox
1369 * @return boolean was the transmission successful?
1370 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1372 public static function sendProfileDeletion($uid, $inbox)
1374 $owner = User::getOwnerDataById($uid);
1376 if (empty($owner)) {
1377 Logger::error('No owner data found, the deletion message cannot be processed.', ['user' => $uid]);
1381 if (empty($owner['uprvkey'])) {
1382 Logger::error('No private key for owner found, the deletion message cannot be processed.', ['user' => $uid]);
1386 $data = ['@context' => ActivityPub::CONTEXT,
1387 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1389 'actor' => $owner['url'],
1390 'object' => $owner['url'],
1391 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1392 'instrument' => self::getService(),
1393 'to' => [ActivityPub::PUBLIC_COLLECTION],
1396 $signed = LDSignature::sign($data, $owner);
1398 Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1399 return HTTPSignature::transmit($signed, $inbox, $uid);
1403 * Transmits a profile change to a given inbox
1405 * @param integer $uid User ID
1406 * @param string $inbox Target inbox
1408 * @return boolean was the transmission successful?
1409 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1410 * @throws \ImagickException
1412 public static function sendProfileUpdate($uid, $inbox)
1414 $owner = User::getOwnerDataById($uid);
1415 $profile = APContact::getByURL($owner['url']);
1417 $data = ['@context' => ActivityPub::CONTEXT,
1418 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1420 'actor' => $owner['url'],
1421 'object' => self::getProfile($uid),
1422 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
1423 'instrument' => self::getService(),
1424 'to' => [$profile['followers']],
1427 $signed = LDSignature::sign($data, $owner);
1429 Logger::log('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
1430 return HTTPSignature::transmit($signed, $inbox, $uid);
1434 * Transmits a given activity to a target
1436 * @param string $activity Type name
1437 * @param string $target Target profile
1438 * @param integer $uid User ID
1440 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1441 * @throws \ImagickException
1442 * @throws \Exception
1444 public static function sendActivity($activity, $target, $uid, $id = '')
1446 $profile = APContact::getByURL($target);
1448 $owner = User::getOwnerDataById($uid);
1451 $id = System::baseUrl() . '/activity/' . System::createGUID();
1454 $data = ['@context' => ActivityPub::CONTEXT,
1456 'type' => $activity,
1457 'actor' => $owner['url'],
1458 'object' => $profile['url'],
1459 'instrument' => self::getService(),
1460 'to' => [$profile['url']]];
1462 Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
1464 $signed = LDSignature::sign($data, $owner);
1465 return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1469 * Transmits a "follow object" activity to a target
1470 * This is a preparation for sending automated "follow" requests when receiving "Announce" messages
1472 * @param string $object Object URL
1473 * @param string $target Target profile
1474 * @param integer $uid User ID
1476 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1477 * @throws \ImagickException
1478 * @throws \Exception
1480 public static function sendFollowObject($object, $target, $uid = 0)
1482 $profile = APContact::getByURL($target);
1485 // Fetch the list of administrators
1486 $admin_mail = explode(',', str_replace(' ', '', Config::get('config', 'admin_email')));
1488 // We need to use some user as a sender. It doesn't care who it will send. We will use an administrator account.
1489 $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'email' => $admin_mail];
1490 $first_user = DBA::selectFirst('user', ['uid'], $condition);
1491 $uid = $first_user['uid'];
1494 $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
1495 'author-id' => Contact::getPublicIdByUserId($uid)];
1496 if (Item::exists($condition)) {
1497 Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
1501 $owner = User::getOwnerDataById($uid);
1503 $data = ['@context' => ActivityPub::CONTEXT,
1504 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1506 'actor' => $owner['url'],
1507 'object' => $object,
1508 'instrument' => self::getService(),
1509 'to' => [$profile['url']]];
1511 Logger::log('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
1513 $signed = LDSignature::sign($data, $owner);
1514 return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1518 * Transmit a message that the contact request had been accepted
1520 * @param string $target Target profile
1522 * @param integer $uid User ID
1523 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1524 * @throws \ImagickException
1526 public static function sendContactAccept($target, $id, $uid)
1528 $profile = APContact::getByURL($target);
1530 $owner = User::getOwnerDataById($uid);
1531 $data = ['@context' => ActivityPub::CONTEXT,
1532 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1534 'actor' => $owner['url'],
1535 'object' => ['id' => $id, 'type' => 'Follow',
1536 'actor' => $profile['url'],
1537 'object' => $owner['url']],
1538 'instrument' => self::getService(),
1539 'to' => [$profile['url']]];
1541 Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1543 $signed = LDSignature::sign($data, $owner);
1544 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1548 * Reject a contact request or terminates the contact relation
1550 * @param string $target Target profile
1552 * @param integer $uid User ID
1553 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1554 * @throws \ImagickException
1556 public static function sendContactReject($target, $id, $uid)
1558 $profile = APContact::getByURL($target);
1560 $owner = User::getOwnerDataById($uid);
1561 $data = ['@context' => ActivityPub::CONTEXT,
1562 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
1564 'actor' => $owner['url'],
1565 'object' => ['id' => $id, 'type' => 'Follow',
1566 'actor' => $profile['url'],
1567 'object' => $owner['url']],
1568 'instrument' => self::getService(),
1569 'to' => [$profile['url']]];
1571 Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1573 $signed = LDSignature::sign($data, $owner);
1574 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1578 * Transmits a message that we don't want to follow this contact anymore
1580 * @param string $target Target profile
1581 * @param integer $uid User ID
1582 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1583 * @throws \ImagickException
1584 * @throws \Exception
1586 public static function sendContactUndo($target, $cid, $uid)
1588 $profile = APContact::getByURL($target);
1590 $object_id = self::activityIDFromContact($cid);
1591 if (empty($object_id)) {
1595 $id = System::baseUrl() . '/activity/' . System::createGUID();
1597 $owner = User::getOwnerDataById($uid);
1598 $data = ['@context' => ActivityPub::CONTEXT,
1601 'actor' => $owner['url'],
1602 'object' => ['id' => $object_id, 'type' => 'Follow',
1603 'actor' => $owner['url'],
1604 'object' => $profile['url']],
1605 'instrument' => self::getService(),
1606 'to' => [$profile['url']]];
1608 Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
1610 $signed = LDSignature::sign($data, $owner);
1611 HTTPSignature::transmit($signed, $profile['inbox'], $uid);
1614 private static function prependMentions($body, array $permission_block)
1616 if (Config::get('system', 'disable_implicit_mentions')) {
1622 foreach ($permission_block['to'] as $profile_url) {
1623 $profile = Contact::getDetailsByURL($profile_url);
1624 if (!empty($profile['addr'])
1625 && $profile['contact-type'] != Contact::TYPE_COMMUNITY
1626 && !strstr($body, $profile['addr'])
1627 && !strstr($body, $profile_url)
1629 $mentions[] = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url]';
1633 $mentions[] = $body;
1635 return implode(' ', $mentions);