]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
Merge pull request #12214 from Schnoop/bugfix/DivisionByZero
[friendica.git] / src / Object / Post.php
index 7c73be7796086f05490c73afc7bd8e82fa847f97..8b8463f8587fe5417e1ac17ed13b610cfb0ef5c5 100644 (file)
@@ -218,9 +218,9 @@ class Post
                if (DI::userSession()->getLocalUserId()) {
                        if (Strings::compareLink(DI::session()->get('my_url'), $item['author-link'])) {
                                if ($item['event-id'] != 0) {
-                                       $edpost = ['events/event/' . $item['event-id'], DI::l10n()->t('Edit')];
+                                       $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, DI::userSession()->getLocalUserId()]);
@@ -280,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';
                }
 
@@ -585,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;
        }
@@ -618,33 +612,32 @@ class Post
        }
 
        /**
-        * 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::fatal('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 && DI::userSession()->getLocalUserId() != $item->getDataValue('uid')) {
+                       Logger::warning('Post object does not belong to local user', ['post' => $item, 'local_user' => $local_user]);
                        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;
                }
 
@@ -658,7 +651,7 @@ 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(int $id)
        {
@@ -747,6 +740,7 @@ class Post
         * Set conversation thread
         *
         * @param Thread|null $thread
+        *
         * @return void
         */
        public function setThread(Thread $thread = null)
@@ -785,6 +779,7 @@ class Post
         * Get a data value
         *
         * @param string $name key
+        *
         * @return mixed value on success, false on failure
         */
        public function getDataValue(string $name)
@@ -798,13 +793,14 @@ class Post
        }
 
        /**
-        * Set template
+        * Set template by name
         *
         * @param string $name Template name
-        * @return bool If template was set
+        *
+        * @return void
         * @throws InvalidArgumentException
         */
-       private function setTemplate(string $name): bool
+       private function setTemplate(string $name)
        {
                if (empty($this->available_templates[$name])) {
                        // Throw exception
@@ -812,8 +808,6 @@ class Post
                }
 
                $this->template = $this->available_templates[$name];
-
-               return true;
        }
 
        /**
@@ -939,6 +933,7 @@ class Post
         * Get the comment box
         *
         * @param string $indent Indent value
+        *
         * @return mixed The comment box string (empty if no comment box), false on failure
         * @throws \Exception
         * @todo return false is nowhere in this method?
@@ -1049,10 +1044,10 @@ class Post
                                                $this->wall_to_wall = true;
 
                                                $owner = [
-                                                       'uid' => 0,
-                                                       'id' => $this->getDataValue('owner-id'),
+                                                       '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);
                                        }