]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
Merge pull request #12591 from MrPetovan/task/2023-licence
[friendica.git] / src / Object / Post.php
index fec3b3f2b3db7752015a74e0f7a4c47cde37a3dc..dfe5aba383a3621b45871f8726b88df331d61f36 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -28,7 +28,6 @@ use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
@@ -42,6 +41,7 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use InvalidArgumentException;
 
 /**
  * An item
@@ -86,7 +86,7 @@ class Post
                $this->setTemplate('wall');
                $this->toplevel = $this->getId() == $this->getDataValue('parent');
 
-               if (!empty(Session::getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
+               if (!empty(DI::userSession()->getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
                        $this->visiting = true;
                }
 
@@ -103,14 +103,14 @@ class Post
                if (!empty($data['children'])) {
                        foreach ($data['children'] as $item) {
                                // Only add will be displayed
-                               if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
+                               if ($item['network'] === Protocol::MAIL && DI::userSession()->getLocalUserId() != $item['uid']) {
                                        continue;
-                               } elseif (!DI::contentItem()->visibleActivity($item)) {
+                               } elseif (!DI::contentItem()->isVisibleActivity($item)) {
                                        continue;
                                }
 
                                // You can always comment on Diaspora and OStatus items
-                               if (in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA]) && (local_user() == $item['uid'])) {
+                               if (in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA]) && (DI::userSession()->getLocalUserId() == $item['uid'])) {
                                        $item['writable'] = true;
                                }
 
@@ -124,21 +124,27 @@ class Post
        /**
         * Fetch the privacy of the post
         *
-        * @param array $item
-        * @return string
+        * @param array $item Item record
+        * @return string Item privacy message
+        * @throws InvalidArgumentException If $item['private'] is unknown
         */
-       private function fetchPrivacy(array $item):string
+       private function fetchPrivacy(array $item): string
        {
                switch ($item['private']) {
                        case Item::PRIVATE:
                                $output = DI::l10n()->t('Private Message');
                                break;
+
                        case Item::PUBLIC:
                                $output = DI::l10n()->t('Public Message');
                                break;
+
                        case Item::UNLISTED:
                                $output = DI::l10n()->t('Unlisted Message');
                                break;
+
+                       default:
+                               throw new InvalidArgumentException('Item privacy ' . $item['privacy'] . ' is unsupported');
                }
 
                return $output;
@@ -151,25 +157,27 @@ class Post
         * @param string $formSecurityToken A security Token to avoid CSF attacks
         * @param integer $thread_level   default = 1
         *
-        * @return mixed The data requested on success
-        *               false on failure
+        * @return mixed The data requested on success, false on failure
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public function getTemplateData(array $conv_responses, string $formSecurityToken, $thread_level = 1)
+       public function getTemplateData(array $conv_responses, string $formSecurityToken, int $thread_level = 1)
        {
                $item = $this->getData();
                $edited = false;
-               // If the time between "created" and "edited" differs we add
-               // a notice that the post was edited.
-               // Note: In some networks reshared items seem to have (sometimes) a difference
-               // between creation time and edit time of a second. Thats why we add the notice
-               // only if the difference is more than 1 second.
+
+               /*
+                * If the time between "created" and "edited" differs we add
+                * a notice that the post was edited.
+                * Note: In some networks reshared items seem to have (sometimes) a difference
+                * between creation time and edit time of a second. Thats why we add the notice
+                * only if the difference is more than 1 second.
+                */
                if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
                        $edited = [
                                'label'    => DI::l10n()->t('This entry was edited'),
                                'date'     => DateTimeFormat::local($item['edited'], 'r'),
-                               'relative' => Temporal::getRelativeDate($item['edited'])
+                               'relative' => Temporal::getRelativeDate($item['edited']),
                        ];
                }
                $sparkle = '';
@@ -184,8 +192,8 @@ class Post
                $pin = false;
                $star = false;
                $ignore = false;
-               $ispinned = "unpinned";
-               $isstarred = "unstarred";
+               $ispinned = 'unpinned';
+               $isstarred = 'unstarred';
                $indent = '';
                $shiny = '';
                $osparkle = '';
@@ -197,25 +205,25 @@ class Post
                $lock      = ($item['private'] == Item::PRIVATE) ? $privacy : false;
                $connector = !in_array($item['network'], Protocol::NATIVE_SUPPORT) ? DI::l10n()->t('Connector Message') : false;
 
-               $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
+               $shareable = in_array($conv->getProfileOwner(), [0, DI::userSession()->getLocalUserId()]) && $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)) {
+               if ($announceable && ($item['network'] == Protocol::DIASPORA) && ($item['gravity'] != Item::GRAVITY_PARENT)) {
                        $announceable = false;
                }
 
                $edpost = false;
 
-               if (local_user()) {
-                       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")];
+               if (DI::userSession()->getLocalUserId()) {
+                       if (Strings::compareLink(DI::session()->get('my_url'), $item['author-link'])) {
+                               if ($item['event-id'] != 0) {
+                                       $edpost = ['calendar/event/edit/' . $item['event-id'], DI::l10n()->t('Edit')];
                                } else {
-                                       $edpost = ["editpost/" . $item['id'], DI::l10n()->t("Edit")];
+                                       $edpost = [sprintf('post/%s/edit', $item['id']), DI::l10n()->t('Edit')];
                                }
                        }
-                       $dropping = in_array($item['uid'], [0, local_user()]);
+                       $dropping = in_array($item['uid'], [0, DI::userSession()->getLocalUserId()]);
                }
 
                // Editing on items of not subscribed users isn't currently possible
@@ -225,7 +233,7 @@ class Post
                        $edpost = false;
                }
 
-               if (($this->getDataValue('uid') == local_user()) || $this->isVisiting()) {
+               if (($this->getDataValue('uid') == DI::userSession()->getLocalUserId()) || $this->isVisiting()) {
                        $dropping = true;
                }
 
@@ -240,7 +248,7 @@ class Post
 
                $drop = false;
                $block = false;
-               if (local_user()) {
+               if (DI::userSession()->getLocalUserId()) {
                        $drop = [
                                'dropping' => $dropping,
                                'pagedrop' => $item['pagedrop'],
@@ -249,7 +257,7 @@ class Post
                        ];
                }
 
-               if (!$item['self'] && local_user()) {
+               if (!$item['self'] && DI::userSession()->getLocalUserId()) {
                        $block = [
                                'blocking' => true,
                                'block'   => DI::l10n()->t('Block %s', $item['author-name']),
@@ -257,14 +265,14 @@ class Post
                        ];
                }
 
-               $filer = local_user() ? DI::l10n()->t('Save to folder') : false;
+               $filer = DI::userSession()->getLocalUserId() ? 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'];
                }
 
-               if (Session::isAuthenticated()) {
+               if (DI::userSession()->isAuthenticated()) {
                        $author = ['uid' => 0, 'id' => $item['author-id'],
                                'network' => $item['author-network'], 'url' => $item['author-link']];
                        $profile_link = Contact::magicLinkByContact($author);
@@ -272,7 +280,7 @@ class Post
                        $profile_link = $item['author-link'];
                }
 
-               if (strpos($profile_link, 'redir/') === 0) {
+               if (strpos($profile_link, 'contact/redir/') === 0) {
                        $sparkle = ' sparkle';
                }
 
@@ -289,6 +297,7 @@ class Post
                        $response_verbs[] = 'attendyes';
                        $response_verbs[] = 'attendno';
                        $response_verbs[] = 'attendmaybe';
+
                        if ($conv->isWritable()) {
                                $isevent = true;
                                $attend = [DI::l10n()->t('I will attend'), DI::l10n()->t('I will not attend'), DI::l10n()->t('I might attend')];
@@ -317,31 +326,31 @@ class Post
                $tagger = '';
 
                if ($this->isToplevel()) {
-                       if (local_user()) {
-                               $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], local_user());
+                       if (DI::userSession()->getLocalUserId()) {
+                               $ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], DI::userSession()->getLocalUserId());
                                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'   => $ignored ? "hidden" : "",
-                                               'classundo' => $ignored ? "" : "hidden",
+                                               'classdo'   => $ignored ? 'hidden' : '',
+                                               'classundo' => $ignored ? '' : 'hidden',
                                                'ignored'   => DI::l10n()->t('Ignored'),
                                        ];
                                }
 
-                               $isstarred = (($item['starred']) ? "starred" : "unstarred");
+                               $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",
+                                       'classdo'   => $item['starred'] ? 'hidden' : '',
+                                       'classundo' => $item['starred'] ? '' : 'hidden',
                                        'starred'   => DI::l10n()->t('Starred'),
                                ];
 
-                               if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
+                               if ($conv->getProfileOwner() == DI::userSession()->getLocalUserId() && ($item['uid'] != 0)) {
                                        if ($origin && in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
                                                $ispinned = ($item['featured'] ? 'pinned' : 'unpinned');
 
@@ -357,7 +366,7 @@ class Post
 
                                        $tagger = [
                                                'add'   => DI::l10n()->t('Add tag'),
-                                               'class' => "",
+                                               'class' => '',
                                        ];
                                }
                        }
@@ -387,32 +396,32 @@ class Post
 
                $body_html = Item::prepareBody($item, true);
 
-               list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
+               list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, DI::userSession()->getLocalUserId());
 
                if (!empty($item['title'])) {
                        $title = $item['title'];
-               } elseif (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
+               } elseif (!empty($item['content-warning']) && DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'disable_cw', false)) {
                        $title = ucfirst($item['content-warning']);
                } else {
                        $title = '';
                }
 
-               if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
+               if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), '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])) {
-                       if ($buttons["dislike"]) {
-                               $buttons["dislike"] = false;
+               if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
+                       if ($buttons['dislike']) {
+                               $buttons['dislike'] = false;
                        }
 
                        $isevent = false;
                        $tagger = '';
                }
 
-               if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
-                       $buttons["like"] = false;
+               if ($buttons['like'] && in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
+                       $buttons['like'] = false;
                }
 
                $tags = Tag::populateFromItem($item);
@@ -424,9 +433,9 @@ class Post
                }
 
                // 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'))) {
+               if (!DI::userSession()->getLocalUserId() && ($item['network'] != Protocol::DIASPORA) && !empty(DI::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'))];
+                               str_replace('{uri}', urlencode($item['uri']), DI::session()->get('remote_comment'))];
 
                        // Ensure to either display the remote comment or the local activities
                        $buttons = [];
@@ -453,7 +462,7 @@ class Post
 
                $tmp_item = [
                        'template'        => $this->getTemplate(),
-                       'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
+                       'type'            => implode('', array_slice(explode('/', $item['verb']), -1)),
                        'comment_firstcollapsed' => false,
                        'comment_lastcollapsed' => false,
                        'suppress_tags'   => DI::config()->get('system', 'suppress_tags'),
@@ -497,7 +506,7 @@ class Post
                        'location_html'   => $location_html,
                        'indent'          => $indent,
                        'shiny'           => $shiny,
-                       'owner_self'      => $item['author-link'] == Session::get('my_url'),
+                       'owner_self'      => $item['author-link'] == DI::session()->get('my_url'),
                        'owner_url'       => $this->getOwnerUrl(),
                        'owner_photo'     => DI::baseUrl()->remove(DI::contentItem()->getOwnerAvatar($item)),
                        'owner_name'      => $this->getOwnerName(),
@@ -528,7 +537,7 @@ class Post
                        'wait'            => DI::l10n()->t('Please wait'),
                        'thread_level'    => $thread_level,
                        'edited'          => $edited,
-                       'network'         => $item["network"],
+                       'network'         => $item['network'],
                        'network_name'    => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
                        'network_icon'    => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
                        'received'        => $item['received'],
@@ -576,18 +585,12 @@ class Post
                        }
                }
 
+               // Copy values/set defaults
                $result['total_comments_num'] = $this->isToplevel() ? $total_children : 0;
-
-               $result['private'] = $item['private'];
-               $result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
-
-               if ($this->isThreaded()) {
-                       $result['flatten'] = false;
-                       $result['threaded'] = true;
-               } else {
-                       $result['flatten'] = true;
-                       $result['threaded'] = false;
-               }
+               $result['private']            = $item['private'];
+               $result['toplevel']           = ($this->isToplevel() ? 'toplevel_item' : '');
+               $result['flatten']            = !$this->isThreaded();
+               $result['threaded']           = $this->isThreaded();
 
                return $result;
        }
@@ -595,7 +598,7 @@ class Post
        /**
         * @return integer
         */
-       public function getId()
+       public function getId(): int
        {
                return $this->getDataValue('id');
        }
@@ -603,39 +606,38 @@ class Post
        /**
         * @return boolean
         */
-       public function isThreaded()
+       public function isThreaded(): bool
        {
                return $this->threaded;
        }
 
        /**
-        * Add a child item
+        * Add a child post
         *
-        * @param Post $item The child item to add
+        * @param Post $item The child post to add
         *
-        * @return mixed
+        * @return Post|bool Last Post object or bool on any error
         * @throws \Exception
         */
        public function addChild(Post $item)
        {
-               $item_id = $item->getId();
-               if (!$item_id) {
-                       Logger::info('[ERROR] Post::addChild : Item has no ID!!');
+               if (!$item->getId()) {
+                       Logger::error('Post object has no id', ['post' => $item]);
                        return false;
                } elseif ($this->getChild($item->getId())) {
-                       Logger::info('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').');
+                       Logger::warning('Post object already exists', ['post' => $item]);
                        return false;
                }
 
-               $activity = DI::activity();
-
                /*
                 * Only add what will be displayed
                 */
-               if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
+               if ($item->getDataValue('network') === Protocol::MAIL && DI::userSession()->getLocalUserId() != $item->getDataValue('uid')) {
+                       Logger::warning('Post object does not belong to local user', ['post' => $item, 'local_user' => DI::userSession()->getLocalUserId()]);
                        return false;
-               } elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
-                         $activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
+               } elseif (DI::activity()->match($item->getDataValue('verb'), Activity::LIKE) ||
+                         DI::activity()->match($item->getDataValue('verb'), Activity::DISLIKE)) {
+                       Logger::warning('Post objects is a like/dislike', ['post' => $item]);
                        return false;
                }
 
@@ -649,10 +651,9 @@ class Post
         * Get a child by its ID
         *
         * @param integer $id The child id
-        *
-        * @return mixed
+        * @return Thread|null Thread or NULL if not found
         */
-       public function getChild($id)
+       public function getChild(int $id)
        {
                foreach ($this->getChildren() as $child) {
                        if ($child->getId() == $id) {
@@ -668,7 +669,7 @@ class Post
         *
         * @return Post[]
         */
-       public function getChildren()
+       public function getChildren(): array
        {
                return $this->children;
        }
@@ -677,7 +678,6 @@ class Post
         * Set our parent
         *
         * @param Post $item The item to set as parent
-        *
         * @return void
         */
        protected function setParent(Post $item)
@@ -706,11 +706,10 @@ class Post
         * Remove a child
         *
         * @param Post $item The child to be removed
-        *
         * @return boolean Success or failure
         * @throws \Exception
         */
-       public function removeChild(Post $item)
+       public function removeChild(Post $item): bool
        {
                $id = $item->getId();
                foreach ($this->getChildren() as $key => $child) {
@@ -722,6 +721,7 @@ class Post
                                return true;
                        }
                }
+
                Logger::info('[WARN] Item::removeChild : Item is not a child (' . $id . ').');
                return false;
        }
@@ -739,7 +739,7 @@ class Post
        /**
         * Set conversation thread
         *
-        * @param Thread $thread
+        * @param Thread|null $thread
         *
         * @return void
         */
@@ -756,7 +756,7 @@ class Post
        /**
         * Get conversation
         *
-        * @return Thread
+        * @return Thread|null
         */
        public function getThread()
        {
@@ -770,7 +770,7 @@ class Post
         *
         * @return array
         */
-       public function getData()
+       public function getData(): array
        {
                return $this->data;
        }
@@ -780,10 +780,9 @@ class Post
         *
         * @param string $name key
         *
-        * @return mixed value on success
-        *               false on failure
+        * @return mixed value on success, false on failure
         */
-       public function getDataValue($name)
+       public function getDataValue(string $name)
        {
                if (!isset($this->data[$name])) {
                        // Logger::info('[ERROR] Item::getDataValue : Item has no value name "'. $name .'".');
@@ -794,22 +793,21 @@ class Post
        }
 
        /**
-        * Set template
+        * Set template by name
         *
-        * @param string $name template name
-        * @return bool
-        * @throws \Exception
+        * @param string $name Template name
+        *
+        * @return void
+        * @throws InvalidArgumentException
         */
-       private function setTemplate($name)
+       private function setTemplate(string $name)
        {
                if (empty($this->available_templates[$name])) {
-                       Logger::info('[ERROR] Item::setTemplate : Template not available ("' . $name . '").');
-                       return false;
+                       // Throw exception
+                       throw new InvalidArgumentException('[ERROR] Item::setTemplate : Template not available ("' . $name . '").');
                }
 
                $this->template = $this->available_templates[$name];
-
-               return true;
        }
 
        /**
@@ -827,7 +825,7 @@ class Post
         *
         * @return boolean
         */
-       private function isToplevel()
+       private function isToplevel(): bool
        {
                return $this->toplevel;
        }
@@ -837,7 +835,7 @@ class Post
         *
         * @return boolean
         */
-       private function isWritable()
+       private function isWritable(): bool
        {
                $conv = $this->getThread();
 
@@ -845,7 +843,7 @@ class Post
                        // This will allow us to comment on wall-to-wall items owned by our friends
                        // and community forums even if somebody else wrote the post.
                        // bug #517 - this fixes for conversation owner
-                       if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) {
+                       if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == DI::userSession()->getLocalUserId()) {
                                return true;
                        }
 
@@ -860,7 +858,7 @@ class Post
         *
         * @return integer
         */
-       private function countDescendants()
+       private function countDescendants(): int
        {
                $children = $this->getChildren();
                $total = count($children);
@@ -878,7 +876,7 @@ class Post
         *
         * @return string
         */
-       private function getCommentBoxTemplate()
+       private function getCommentBoxTemplate(): string
        {
                return $this->comment_box_template;
        }
@@ -889,28 +887,28 @@ class Post
         * @return string
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private function getDefaultText()
+       private function getDefaultText(): string
        {
                $a = DI::app();
 
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        return '';
                }
 
                $owner = User::getOwnerDataById($a->getLoggedInUserId());
                $item = $this->getData();
 
-               if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
+               if (!empty($item['content-warning']) && Feature::isEnabled(DI::userSession()->getLocalUserId(), 'add_abstract')) {
                        $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
                } else {
                        $text = '';
                }
 
-               if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
+               if (!Feature::isEnabled(DI::userSession()->getLocalUserId(), 'explicit_mentions')) {
                        return $text;
                }
 
-               if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
+               if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != Item::GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
                        $text .= '@' . $item['author-addr'] . ' ';
                }
 
@@ -936,11 +934,11 @@ class Post
         *
         * @param string $indent Indent value
         *
-        * @return mixed The comment box string (empty if no comment box)
-        *               false on failure
+        * @return mixed The comment box string (empty if no comment box), false on failure
         * @throws \Exception
+        * @todo return false is nowhere in this method?
         */
-       private function getCommentBox($indent)
+       private function getCommentBox(string $indent)
        {
                $a = DI::app();
 
@@ -954,7 +952,7 @@ class Post
                         */
                        $qcomment = null;
                        if (Addon::isEnabled('qcomment')) {
-                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                               $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words');
                                $qcomment = $words ? explode("\n", $words) : [];
                        }
 
@@ -1008,7 +1006,7 @@ class Post
        /**
         * @return string
         */
-       private function getRedirectUrl()
+       private function getRedirectUrl(): string
        {
                return $this->redirect_url;
        }
@@ -1033,21 +1031,24 @@ class Post
                                        $owner_namematch = (($this->getDataValue('owner-name')) && $this->getDataValue('owner-name') == $this->getDataValue('author-name'));
 
                                        if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
-                                               // The author url doesn't match the owner (typically the contact)
-                                               // and also doesn't match the contact alias.
-                                               // The name match is a hack to catch several weird cases where URLs are
-                                               // all over the park. It can be tricked, but this prevents you from
-                                               // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
-                                               // well that it's the same Bob Smith.
-                                               // But it could be somebody else with the same name. It just isn't highly likely.
-
-
+                                               /*
+                                                * The author url doesn't match the owner (typically the contact)
+                                                * and also doesn't match the contact alias.
+                                                * The name match is a hack to catch several weird cases where URLs are
+                                                * all over the park. It can be tricked, but this prevents you from
+                                                * seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
+                                                * well that it's the same Bob Smith.
+                                                * But it could be somebody else with the same name. It just isn't highly likely.
+                                                */
                                                $this->owner_name = $this->getDataValue('owner-name');
                                                $this->wall_to_wall = true;
 
-                                               $owner = ['uid' => 0, 'id' => $this->getDataValue('owner-id'),
+                                               $owner = [
+                                                       'uid'     => 0,
+                                                       'id'      => $this->getDataValue('owner-id'),
                                                        'network' => $this->getDataValue('owner-network'),
-                                                       'url' => $this->getDataValue('owner-link')];
+                                                       'url'     => $this->getDataValue('owner-link'),
+                                               ];
                                                $this->owner_url = Contact::magicLinkByContact($owner);
                                        }
                                }
@@ -1064,7 +1065,7 @@ class Post
        /**
         * @return boolean
         */
-       private function isWallToWall()
+       private function isWallToWall(): bool
        {
                return $this->wall_to_wall;
        }
@@ -1072,7 +1073,7 @@ class Post
        /**
         * @return string
         */
-       private function getOwnerUrl()
+       private function getOwnerUrl(): string
        {
                return $this->owner_url;
        }
@@ -1080,7 +1081,7 @@ class Post
        /**
         * @return string
         */
-       private function getOwnerName()
+       private function getOwnerName(): string
        {
                return $this->owner_name;
        }
@@ -1088,7 +1089,7 @@ class Post
        /**
         * @return boolean
         */
-       private function isVisiting()
+       private function isVisiting(): bool
        {
                return $this->visiting;
        }