]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
[frio] Add a conditional browser share button
[friendica.git] / src / Object / Post.php
index f55dbde0d5791c7e37b59bbc8131095e6fb31c03..0561f5506c7a2680b245a34ede7bdd0e65e7a15e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -33,12 +33,13 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Model\Term;
+use Friendica\Model\Post as PostModel;
+use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
@@ -68,7 +69,6 @@ class Post
        private $thread = null;
        private $redirect_url = null;
        private $owner_url = '';
-       private $owner_photo = '';
        private $owner_name = '';
        private $wall_to_wall = false;
        private $threaded = false;
@@ -105,7 +105,7 @@ class Post
                                // Only add will be displayed
                                if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
                                        continue;
-                               } elseif (!visible_activity($item)) {
+                               } elseif (!DI::contentItem()->visibleActivity($item)) {
                                        continue;
                                }
 
@@ -125,6 +125,7 @@ class Post
         * Get data in a form usable by a conversation template
         *
         * @param array   $conv_responses conversation responses
+        * @param string $formSecurityToken A security Token to avoid CSF attacks
         * @param integer $thread_level   default = 1
         *
         * @return mixed The data requested on success
@@ -132,10 +133,8 @@ class Post
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public function getTemplateData(array $conv_responses, $thread_level = 1)
+       public function getTemplateData(array $conv_responses, string $formSecurityToken, $thread_level = 1)
        {
-               $a = DI::app();
-
                $item = $this->getData();
                $edited = false;
                // If the time between "created" and "edited" differs we add
@@ -151,7 +150,12 @@ class Post
                        ];
                }
                $sparkle = '';
-               $buttons = '';
+               $buttons = [
+                       'like'     => null,
+                       'dislike'  => null,
+                       'share'    => null,
+                       'announce' => null,
+               ];
                $dropping = false;
                $pinned = '';
                $pin = false;
@@ -166,17 +170,25 @@ class Post
 
                $conv = $this->getThread();
 
-               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
+               $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
                        || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
                        ? DI::l10n()->t('Private Message')
                        : false);
 
-               $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1;
+               $connector = !$item['global'] ? DI::l10n()->t('Connector Message') : false;
+
+               $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
+               $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
+
+               // On Diaspora only toplevel posts can be reshared
+               if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != GRAVITY_PARENT)) {
+                       $announceable = false;
+               }
 
                $edpost = false;
 
                if (local_user()) {
-                       if (Strings::compareLink($a->contact['url'], $item['author-link'])) {
+                       if (Strings::compareLink(Session::get('my_url'), $item['author-link'])) {
                                if ($item["event-id"] != 0) {
                                        $edpost = ["events/event/" . $item['event-id'], DI::l10n()->t("Edit")];
                                } else {
@@ -197,49 +209,44 @@ class Post
                        $dropping = true;
                }
 
-               $origin = $item['origin'];
+               $origin = $item['origin'] || $item['parent-origin'];
 
-               if (!$origin) {
-                       /// @todo This shouldn't be done as query here, but better during the data creation.
-                       // it is now done here, since during the RC phase we shouldn't make to intense changes.
-                       $parent = Item::selectFirst(['origin'], ['id' => $item['parent']]);
-                       if (DBA::isResult($parent)) {
-                               $origin = $parent['origin'];
-                       }
-               } elseif ($item['pinned']) {
-                       $pinned = DI::l10n()->t('pinned item');
+               if ($item['pinned']) {
+                       $pinned = DI::l10n()->t('Pinned item');
                }
 
-               if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
-                       // ActivityPub doesn't allow removal of remote comments
-                       $delete = DI::l10n()->t('Delete locally');
-               } else {
-                       // Showing the one or the other text, depending upon if we can only hide it or really delete it.
-                       $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
-               }
+               // Showing the one or the other text, depending upon if we can only hide it or really delete it.
+               $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
 
-               $drop = [
-                       'dropping' => $dropping,
-                       'pagedrop' => $item['pagedrop'],
-                       'select'   => DI::l10n()->t('Select'),
-                       'delete'   => $delete,
-               ];
+               $drop = false;
+               $block = false;
+               if (local_user()) {
+                       $drop = [
+                               'dropping' => $dropping,
+                               'pagedrop' => $item['pagedrop'],
+                               'select' => DI::l10n()->t('Select'),
+                               'delete' => $delete,
+                       ];
+               }
 
-               if (!local_user()) {
-                       $drop = false;
+               if (!$item['self']) {
+                       $block = [
+                               'blocking' => true,
+                               'block'   => DI::l10n()->t('Block %s', $item['author-name']),
+                               'author_id'   => $item['author-id'],
+                       ];
                }
 
-               $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? DI::l10n()->t("save to folder") : false);
+               $filer = local_user() ? DI::l10n()->t('Save to folder') : false;
 
                $profile_name = $item['author-name'];
                if (!empty($item['author-link']) && empty($item['author-name'])) {
                        $profile_name = $item['author-link'];
                }
 
-               $author = ['uid' => 0, 'id' => $item['author-id'],
-                       'network' => $item['author-network'], 'url' => $item['author-link']];
-
                if (Session::isAuthenticated()) {
+                       $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
                        $profile_link = Contact::magicLinkByContact($author);
                } else {
                        $profile_link = $item['author-link'];
@@ -251,7 +258,7 @@ class Post
 
                $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
                Hook::callAll('render_location', $locate);
-               $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
+               $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
 
                // process action responses - e.g. like/dislike/attend/agree/whatever
                $response_verbs = ['like', 'dislike', 'announce'];
@@ -268,10 +275,12 @@ class Post
                        }
                }
 
-               $responses = get_responses($conv_responses, $response_verbs, $item, $this);
-
-               foreach ($response_verbs as $value => $verbs) {
-                       $responses[$verbs]['output'] = !empty($conv_responses[$verbs][$item['uri']]) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : '';
+               $responses = [];
+               foreach ($response_verbs as $value => $verb) {
+                       $responses[$verb] = [
+                               'self'   => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
+                               'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? DI::conversation()->formatActivity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
+                       ];
                }
 
                /*
@@ -288,46 +297,46 @@ class Post
                $tagger = '';
 
                if ($this->isToplevel()) {
-                       if(local_user()) {
-                               $thread = Item::selectFirstThreadForUser(local_user(), ['ignored'], ['iid' => $item['id']]);
-                               if (DBA::isResult($thread)) {
+                       if (local_user()) {
+                               $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user());
+                               if ($item['mention'] || $ignored) {
                                        $ignore = [
-                                               'do'        => DI::l10n()->t("ignore thread"),
-                                               'undo'      => DI::l10n()->t("unignore thread"),
-                                               'toggle'    => DI::l10n()->t("toggle ignore status"),
-                                               'classdo'   => $thread['ignored'] ? "hidden" : "",
-                                               'classundo' => $thread['ignored'] ? "" : "hidden",
-                                               'ignored'   => DI::l10n()->t('ignored'),
+                                               'do'        => DI::l10n()->t('Ignore thread'),
+                                               'undo'      => DI::l10n()->t('Unignore thread'),
+                                               'toggle'    => DI::l10n()->t('Toggle ignore status'),
+                                               'classdo'   => $ignored ? "hidden" : "",
+                                               'classundo' => $ignored ? "" : "hidden",
+                                               'ignored'   => DI::l10n()->t('Ignored'),
                                        ];
                                }
 
+                               $isstarred = (($item['starred']) ? "starred" : "unstarred");
+
+                               $star = [
+                                       'do'        => DI::l10n()->t('Add star'),
+                                       'undo'      => DI::l10n()->t('Remove star'),
+                                       'toggle'    => DI::l10n()->t('Toggle star status'),
+                                       'classdo'   => $item['starred'] ? "hidden" : "",
+                                       'classundo' => $item['starred'] ? "" : "hidden",
+                                       'starred'   => DI::l10n()->t('Starred'),
+                               ];
+
                                if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
                                        if ($origin) {
                                                $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
 
                                                $pin = [
-                                                       'do'        => DI::l10n()->t('pin'),
-                                                       'undo'      => DI::l10n()->t('unpin'),
-                                                       'toggle'    => DI::l10n()->t('toggle pin status'),
+                                                       'do'        => DI::l10n()->t('Pin'),
+                                                       'undo'      => DI::l10n()->t('Unpin'),
+                                                       'toggle'    => DI::l10n()->t('Toggle pin status'),
                                                        'classdo'   => $item['pinned'] ? 'hidden' : '',
                                                        'classundo' => $item['pinned'] ? '' : 'hidden',
-                                                       'pinned'   => DI::l10n()->t('pinned'),
+                                                       'pinned'   => DI::l10n()->t('Pinned'),
                                                ];
                                        }
 
-                                       $isstarred = (($item['starred']) ? "starred" : "unstarred");
-
-                                       $star = [
-                                               'do'        => DI::l10n()->t("add star"),
-                                               'undo'      => DI::l10n()->t("remove star"),
-                                               'toggle'    => DI::l10n()->t("toggle star status"),
-                                               'classdo'   => $item['starred'] ? "hidden" : "",
-                                               'classundo' => $item['starred'] ? "" : "hidden",
-                                               'starred'   => DI::l10n()->t('starred'),
-                                       ];
-
                                        $tagger = [
-                                               'add'   => DI::l10n()->t("add tag"),
+                                               'add'   => DI::l10n()->t('Add tag'),
                                                'class' => "",
                                        ];
                                }
@@ -337,56 +346,54 @@ class Post
                }
 
                if ($conv->isWritable()) {
-                       $buttons = [
-                               'like'    => [DI::l10n()->t("I like this \x28toggle\x29"), DI::l10n()->t("like")],
-                               'dislike' => [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")],
-                       ];
+                       $buttons['like']    = [DI::l10n()->t("I like this \x28toggle\x29")      , DI::l10n()->t('Like')];
+                       $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t('Dislike')];
                        if ($shareable) {
-                               $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('share')];
+                               $buttons['share'] = [DI::l10n()->t('Quote share this'), DI::l10n()->t('Quote Share')];
+                       }
+                       if ($announceable) {
+                               $buttons['announce'] = [DI::l10n()->t('Reshare this'), DI::l10n()->t('Reshare')];
+                               $buttons['unannounce'] = [DI::l10n()->t('Cancel your Reshare'), DI::l10n()->t('Unshare')];
                        }
                }
 
-               $comment = $this->getCommentBox($indent);
+               $comment_html = $this->getCommentBox($indent);
 
                if (strcmp(DateTimeFormat::utc($item['created']), DateTimeFormat::utc('now - 12 hours')) > 0) {
                        $shiny = 'shiny';
                }
 
-               localize_item($item);
+               DI::contentItem()->localize($item);
 
-               $body = Item::prepareBody($item, true);
+               $body_html = Item::prepareBody($item, true);
 
-               list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
-
-               $body_e       = $body;
-               $text_e       = strip_tags($body);
-               $name_e       = $profile_name;
+               list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
 
                if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
-                       $title_e = ucfirst($item['content-warning']);
+                       $title = ucfirst($item['content-warning']);
                } else {
-                       $title_e = $item['title'];
+                       $title = $item['title'];
                }
 
-               $location_e   = $location;
-               $owner_name_e = $this->getOwnerName();
+               if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
+                       $buttons['dislike'] = false;
+               }
 
                // Disable features that aren't available in several networks
-               if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) {
-                       unset($buttons["dislike"]);
+               if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
+                       if ($buttons["dislike"]) {
+                               $buttons["dislike"] = false;
+                       }
+
                        $isevent = false;
                        $tagger = '';
                }
 
-               if (($item["network"] == Protocol::FEED) && isset($buttons["like"])) {
-                       unset($buttons["like"]);
-               }
-
-               if (($item["network"] == Protocol::MAIL) && isset($buttons["like"])) {
-                       unset($buttons["like"]);
+               if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
+                       $buttons["like"] = false;
                }
 
-               $tags = Term::populateTagsFromItem($item);
+               $tags = Tag::populateFromItem($item);
 
                $ago = Temporal::getRelativeDate($item['created']);
                $ago_received = Temporal::getRelativeDate($item['received']);
@@ -394,9 +401,39 @@ class Post
                        $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
                }
 
+               // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
+               if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(Session::get('remote_comment'))) {
+                       $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('Remote comment'),
+                               str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
+
+                       // Ensure to either display the remote comment or the local activities
+                       $buttons = [];
+                       $comment_html = '';
+               } else {
+                       $remote_comment = '';
+               }
+
+               $direction = [];
+               if (!empty($item['direction'])) {
+                       $direction = $item['direction'];
+               } elseif (DI::config()->get('debug', 'show_direction')) {
+                       $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
+                       if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
+                               $direction_title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
+                               $direction = ['direction' => $conversation['direction'], 'title' => $direction_title[$conversation['direction']]];
+                       }
+               }
+
+               $languages = [];
+               if (!empty($item['language'])) {
+                       $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)];
+               }
+
                $tmp_item = [
                        'template'        => $this->getTemplate(),
                        'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
+                       'comment_firstcollapsed' => false,
+                       'comment_lastcollapsed' => false,
                        'suppress_tags'   => DI::config()->get('system', 'suppress_tags'),
                        'tags'            => $tags['tags'],
                        'hashtags'        => $tags['hashtags'],
@@ -408,8 +445,8 @@ class Post
                        'has_folders'     => ((count($folders)) ? 'true' : ''),
                        'categories'      => $categories,
                        'folders'         => $folders,
-                       'body'            => $body_e,
-                       'text'            => $text_e,
+                       'body_html'       => $body_html,
+                       'text'            => strip_tags($body_html),
                        'id'              => $this->getId(),
                        'guid'            => urlencode($item['guid']),
                        'isevent'         => $isevent,
@@ -421,25 +458,27 @@ class Post
                        'wall'            => DI::l10n()->t('Wall-to-Wall'),
                        'vwall'           => DI::l10n()->t('via Wall-To-Wall:'),
                        'profile_url'     => $profile_link,
-                       'item_photo_menu' => item_photo_menu($item),
-                       'name'            => $name_e,
-                       'thumb'           => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
+                       'name'            => $profile_name,
+                       'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken),
+                       'thumb'           => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
                        'osparkle'        => $osparkle,
                        'sparkle'         => $sparkle,
-                       'title'           => $title_e,
+                       'title'           => $title,
                        'localtime'       => DateTimeFormat::local($item['created'], 'r'),
                        'ago'             => $item['app'] ? DI::l10n()->t('%s from %s', $ago, $item['app']) : $ago,
                        'app'             => $item['app'],
                        'created'         => $ago,
                        'lock'            => $lock,
-                       'location'        => $location_e,
+                       'connector'       => $connector,
+                       'location_html'   => $location_html,
                        'indent'          => $indent,
                        'shiny'           => $shiny,
                        'owner_self'      => $item['author-link'] == Session::get('my_url'),
                        'owner_url'       => $this->getOwnerUrl(),
-                       'owner_photo'     => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
-                       'owner_name'      => $owner_name_e,
+                       'owner_photo'     => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
+                       'owner_name'      => $this->getOwnerName(),
                        'plink'           => Item::getPlink($item),
+                       'browsershare'    => DI::l10n()->t('Share'),
                        'edpost'          => $edpost,
                        'ispinned'        => $ispinned,
                        'pin'             => $pin,
@@ -449,14 +488,17 @@ class Post
                        'ignore'          => $ignore,
                        'tagger'          => $tagger,
                        'filer'           => $filer,
+                       'language'        => $languages,
                        'drop'            => $drop,
+                       'block'           => $block,
                        'vote'            => $buttons,
-                       'like'            => $responses['like']['output'],
-                       'dislike'         => $responses['dislike']['output'],
+                       'like_html'       => $responses['like']['output'],
+                       'dislike_html'    => $responses['dislike']['output'],
                        'responses'       => $responses,
                        'switchcomment'   => DI::l10n()->t('Comment'),
-                       'reply_label'     => DI::l10n()->t('Reply to %s', $name_e),
-                       'comment'         => $comment,
+                       'reply_label'     => DI::l10n()->t('Reply to %s', $profile_name),
+                       'comment_html'    => $comment_html,
+                       'remote_comment'  => $remote_comment,
                        'menu'            => DI::l10n()->t('More'),
                        'previewing'      => $conv->isPreview() ? ' preview ' : '',
                        'wait'            => DI::l10n()->t('Please wait'),
@@ -468,7 +510,10 @@ class Post
                        'received'        => $item['received'],
                        'commented'       => $item['commented'],
                        'created_date'    => $item['created'],
+                       'uriid'           => $item['uri-id'],
                        'return'          => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
+                       'direction'       => $direction,
+                       'reshared'        => $item['reshared'] ?? '',
                        'delivery'        => [
                                'queue_count'       => $item['delivery_queue_count'],
                                'queue_done'        => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
@@ -490,7 +535,7 @@ class Post
                $nb_children = count($children);
                if ($nb_children > 0) {
                        foreach ($children as $child) {
-                               $result['children'][] = $child->getTemplateData($conv_responses, $thread_level + 1);
+                               $result['children'][] = $child->getTemplateData($conv_responses, $formSecurityToken, $thread_level + 1);
                        }
 
                        // Collapse
@@ -507,10 +552,7 @@ class Post
                        }
                }
 
-               if ($this->isToplevel()) {
-                       $result['total_comments_num'] = "$total_children";
-                       $result['total_comments_text'] = DI::l10n()->tt('comment', 'comments', $total_children);
-               }
+               $result['total_comments_num'] = $this->isToplevel() ? $total_children : 0;
 
                $result['private'] = $item['private'];
                $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
@@ -554,10 +596,10 @@ class Post
        {
                $item_id = $item->getId();
                if (!$item_id) {
-                       Logger::log('[ERROR] Post::addChild : Item has no ID!!', Logger::DEBUG);
+                       Logger::info('[ERROR] Post::addChild : Item has no ID!!');
                        return false;
                } elseif ($this->getChild($item->getId())) {
-                       Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
+                       Logger::info('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').');
                        return false;
                }
 
@@ -656,7 +698,7 @@ class Post
                                return true;
                        }
                }
-               Logger::log('[WARN] Item::removeChild : Item is not a child (' . $id . ').', Logger::DEBUG);
+               Logger::info('[WARN] Item::removeChild : Item is not a child (' . $id . ').');
                return false;
        }
 
@@ -720,7 +762,7 @@ class Post
        public function getDataValue($name)
        {
                if (!isset($this->data[$name])) {
-                       // Logger::log('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".', Logger::DEBUG);
+                       // Logger::info('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".');
                        return false;
                }
 
@@ -737,7 +779,7 @@ class Post
        private function setTemplate($name)
        {
                if (empty($this->available_templates[$name])) {
-                       Logger::log('[ERROR] Item::setTemplate : Template not available ("' . $name . '").', Logger::DEBUG);
+                       Logger::info('[ERROR] Item::setTemplate : Template not available ("' . $name . '").');
                        return false;
                }
 
@@ -831,28 +873,33 @@ class Post
                        return '';
                }
 
-               $owner = User::getOwnerDataById($a->user['uid']);
+               $owner = User::getOwnerDataById($a->getLoggedInUserId());
 
                if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
                        return '';
                }
 
-               $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]);
+               $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity'], ['id' => $this->getId()]);
                if (!DBA::isResult($item) || empty($item['author-addr'])) {
                        // Should not happen
                        return '';
                }
 
-               if ($item['author-addr'] != $owner['addr']) {
+               if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
                        $text = '@' . $item['author-addr'] . ' ';
                } else {
                        $text = '';
                }
 
-               $terms = Term::tagArrayFromItemId($this->getId(), [Term::MENTION, Term::IMPLICIT_MENTION]);
+               $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
                foreach ($terms as $term) {
-                       $profile = Contact::getDetailsByURL($term['url']);
-                       if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
+                       if (!$term['url']) {
+                               DI::logger()->warning('Mention term with no URL', ['term' => $term]);
+                               continue;
+                       }
+
+                       $profile = Contact::getByURL($term['url'], false, ['addr', 'contact-type']);
+                       if (!empty($profile['addr']) && (($profile['contact-type'] ?? Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
                                ($profile['addr'] != $owner['addr']) && !strstr($text, $profile['addr'])) {
                                $text .= '@' . $profile['addr'] . ' ';
                        }
@@ -876,27 +923,24 @@ class Post
 
                $comment_box = '';
                $conv = $this->getThread();
-               $ww = '';
-               if (($conv->getMode() === 'network') && $this->isWallToWall()) {
-                       $ww = 'ww';
-               }
 
                if ($conv->isWritable() && $this->isWritable()) {
-                       $qcomment = null;
-
                        /*
                         * Hmmm, code depending on the presence of a particular addon?
                         * This should be better if done by a hook
                         */
+                       $qcomment = null;
                        if (Addon::isEnabled('qcomment')) {
-                               $qc = ((local_user()) ? DI::pConfig()->get(local_user(), 'qcomment', 'words') : null);
-                               $qcomment = (($qc) ? explode("\n", $qc) : null);
+                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                               $qcomment = $words ? explode("\n", $words) : [];
                        }
 
                        // Fetch the user id from the parent when the owner user is empty
                        $uid = $conv->getProfileOwner();
                        $parent_uid = $this->getDataValue('uid');
 
+                       $contact = Contact::getById($a->getContactId());
+
                        $default_text = $this->getDefaultText();
 
                        if (!is_null($parent_uid) && ($uid != $parent_uid)) {
@@ -914,11 +958,12 @@ class Post
                                '$qcomment'    => $qcomment,
                                '$default'     => $default_text,
                                '$profile_uid' => $uid,
-                               '$mylink'      => DI::baseUrl()->remove($a->contact['url']),
+                               '$mylink'      => DI::baseUrl()->remove($contact['url'] ?? ''),
                                '$mytitle'     => DI::l10n()->t('This is you'),
-                               '$myphoto'     => DI::baseUrl()->remove($a->contact['thumb']),
+                               '$myphoto'     => DI::baseUrl()->remove($contact['thumb'] ?? ''),
                                '$comment'     => DI::l10n()->t('Comment'),
                                '$submit'      => DI::l10n()->t('Submit'),
+                               '$loading'     => DI::l10n()->t('Loading...'),
                                '$edbold'      => DI::l10n()->t('Bold'),
                                '$editalic'    => DI::l10n()->t('Italic'),
                                '$eduline'     => DI::l10n()->t('Underline'),
@@ -930,8 +975,6 @@ class Post
                                '$prompttext'  => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
                                '$preview'     => DI::l10n()->t('Preview'),
                                '$indent'      => $indent,
-                               '$sourceapp'   => DI::l10n()->t($a->sourcename),
-                               '$ww'          => $conv->getMode() === 'network' ? $ww : '',
                                '$rand_num'    => Crypto::randomDigits(12)
                        ]);
                }
@@ -961,16 +1004,7 @@ class Post
 
                if ($this->isToplevel()) {
                        if ($conv->getMode() !== 'profile') {
-                               if ($this->getDataValue('wall') && !$this->getDataValue('self')) {
-                                       // On the network page, I am the owner. On the display page it will be the profile owner.
-                                       // This will have been stored in $a->page_contact by our calling page.
-                                       // Put this person as the wall owner of the wall-to-wall notice.
-
-                                       $this->owner_url = Contact::magicLink($a->page_contact['url']);
-                                       $this->owner_photo = $a->page_contact['thumb'];
-                                       $this->owner_name = $a->page_contact['name'];
-                                       $this->wall_to_wall = true;
-                               } elseif ($this->getDataValue('owner-link')) {
+                               if ($this->getDataValue('owner-link')) {
                                        $owner_linkmatch = (($this->getDataValue('owner-link')) && Strings::compareLink($this->getDataValue('owner-link'), $this->getDataValue('author-link')));
                                        $alias_linkmatch = (($this->getDataValue('alias')) && Strings::compareLink($this->getDataValue('alias'), $this->getDataValue('author-link')));
                                        $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
@@ -985,7 +1019,6 @@ class Post
                                                // But it could be somebody else with the same name. It just isn't highly likely.
 
 
-                                               $this->owner_photo = $this->getDataValue('owner-avatar');
                                                $this->owner_name = $this->getDataValue('owner-name');
                                                $this->wall_to_wall = true;
 
@@ -1001,7 +1034,6 @@ class Post
                if (!$this->wall_to_wall) {
                        $this->setTemplate('wall');
                        $this->owner_url = '';
-                       $this->owner_photo = '';
                        $this->owner_name = '';
                }
        }