- // Convert mentions in the body to a unified format
- $body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network, &$inform) {
- $tags = BBCode::getTags($body);
-
- $tagged = [];
-
- foreach ($tags as $tag) {
- $tag_type = substr($tag, 0, 1);
-
- if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
- continue;
- }
-
- // If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
- // Robert Johnson should be first in the $tags array
- foreach ($tagged as $nextTag) {
- if (stristr($nextTag, $tag . ' ')) {
- continue 2;
- }
- }
-
- ItemHelper::replaceTag($body, $inform, local_user() ? local_user() : $profile_uid, $tag, $network);
- }
-
- return $body;
- });
-
- // Search for forum mentions
- if (!$toplevel_item_id) {
- foreach (Tag::getFromBody($body) as $tag) {
- $contact = Contact::getByURL($tag[2], false, [], $profile_uid);
- if ($contact['contact-type'] != Contact::TYPE_COMMUNITY) {
- continue;
- }
-
- if (!empty($contact['prv']) || ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION])) {
- $private_forum = $contact['prv'];
- $only_to_forum = ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]);
- $private_id = $contact['id'];
- $forum_contact = $contact;
- Logger::info('Private forum or exclusive mention', ['url' => $tag[2], 'mention' => $tag[1]]);
- } elseif ($str_contact_allow == '<' . $contact['id'] . '>') {
- $private_forum = false;
- $only_to_forum = true;
- $private_id = $contact['id'];
- $forum_contact = $contact;
- Logger::info('Public forum', ['url' => $tag[2], 'mention' => $tag[1]]);
- } else {
- Logger::info('Post with forum mention will not be converted to a forum post', ['url' => $tag[2], 'mention' => $tag[1]]);
- }
- }
- }
- }
-
- $original_contact_id = $contact_id;
-
- if (!$toplevel_item_id && !empty($forum_contact) && ($private_forum || $only_to_forum)) {
- // we tagged a forum in a top level post. Now we change the post
- $private = $private_forum ? Item::PRIVATE : Item::UNLISTED;
-
- if ($only_to_forum) {
- $postopts = '';
- }
-
- if (!$private_forum) {
- $str_contact_allow = '';
- $str_group_allow = '';
- $str_contact_deny = '';
- $str_group_deny = '';
- }
-
- if ($private_forum || !APContact::getByURL($forum_contact['url'])) {
- $str_group_allow = '';
- $str_contact_deny = '';
- $str_group_deny = '';
- if ($private_forum) {
- $str_contact_allow = '<' . $private_id . '>';
- } else {
- $str_contact_allow = '';
- }
- $contact_id = $private_id;
- $contact_record = $forum_contact;
- $_REQUEST['origin'] = false;
- $wall = 0;
- }
+ // Look for any tags and linkify them
+ $item = [
+ 'uid' => local_user() ? local_user() : $profile_uid,
+ 'gravity' => $toplevel_item_id ? GRAVITY_COMMENT : GRAVITY_PARENT,
+ 'network' => $network,
+ 'body' => $body,
+ 'postopts' => $postopts,
+ 'private' => $private,
+ 'allow_cid' => $str_contact_allow,
+ 'allow_gid' => $str_group_allow,
+ 'deny_cid' => $str_contact_deny,
+ 'deny_gid' => $str_group_deny,
+ ];
+
+ $item = DI::contentItem()->expandTags($item);
+
+ $body = $item['body'];
+ $inform = $item['inform'];
+ $postopts = $item['postopts'];
+ $private = $item['private'];
+ $str_contact_allow = $item['allow_cid'];
+ $str_group_allow = $item['allow_gid'];
+ $str_contact_deny = $item['deny_cid'];
+ $str_group_deny = $item['deny_gid'];
+ } else {
+ $inform = '';