]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Conversation.php
Merge pull request #11671 from MrPetovan/bug/fatal-errors
[friendica.git] / src / Content / Conversation.php
index 89d9ca4c1b712e59de059595a3e8ce6b662bd30e..1088497983522f432dd008523efd3fede925ae27 100644 (file)
@@ -37,7 +37,6 @@ use Friendica\Core\Theme;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Item as ItemModel;
-use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
@@ -48,7 +47,6 @@ use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Profiler;
-use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 use Psr\Log\LoggerInterface;
@@ -156,7 +154,7 @@ class Conversation
                                }
 
                                // Skip when the causer of the parent is the same as the author of the announce
-                               if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id'] && ($thread_parent['causer-id'] == $activity['author-id']))) {
+                               if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id']) && ($thread_parent['causer-id'] == $activity['author-id'])) {
                                        continue;
                                }
 
@@ -191,7 +189,7 @@ class Conversation
         * @return string formatted text
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function formatActivity(array $links, $verb, $id)
+       public function formatActivity(array $links, string $verb, int $id): string
        {
                $this->profiler->startRecording('rendering');
                $o        = '';
@@ -277,7 +275,7 @@ class Conversation
                return $o;
        }
 
-       public function statusEditor(array $x = [], $notes_cid = 0, $popup = false)
+       public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string
        {
                $user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
                if (empty($user['uid'])) {
@@ -416,8 +414,8 @@ class Conversation
         * figures out how to determine page owner and other contextual items
         * that are based on unique features of the calling module.
         * @param array  $items
-        * @param        $mode
-        * @param        $update
+        * @param string $mode
+        * @param        $update @TODO Which type?
         * @param bool   $preview
         * @param string $order
         * @param int    $uid
@@ -425,7 +423,7 @@ class Conversation
         * @throws ImagickException
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function create(array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0)
+       public function create(array $items, string $mode, $update, bool $preview = false, string $order = 'commented', int $uid = 0): string
        {
                $this->profiler->startRecording('rendering');
 
@@ -443,7 +441,7 @@ class Conversation
                $previewing = (($preview) ? ' preview ' : '');
 
                if ($mode === 'network') {
-                       $items = $this->addChildren($items, false, $order, $uid);
+                       $items = $this->addChildren($items, false, $order, $uid, $mode);
                        if (!$update) {
                                /*
                                * The special div is needed for liveUpdate to kick in for this page.
@@ -469,7 +467,7 @@ class Conversation
                                        . "'; </script>\r\n";
                        }
                } elseif ($mode === 'profile') {
-                       $items = $this->addChildren($items, false, $order, $uid);
+                       $items = $this->addChildren($items, false, $order, $uid, $mode);
 
                        if (!$update) {
                                $tab = !empty($_GET['tab']) ? trim($_GET['tab']) : 'posts';
@@ -486,7 +484,7 @@ class Conversation
                                }
                        }
                } elseif ($mode === 'notes') {
-                       $items = $this->addChildren($items, false, $order, local_user());
+                       $items = $this->addChildren($items, false, $order, local_user(), $mode);
 
                        if (!$update) {
                                $live_update_div = '<div id="live-notes"></div>' . "\r\n"
@@ -494,7 +492,7 @@ class Conversation
                                        . "; var netargs = '/?f='; </script>\r\n";
                        }
                } elseif ($mode === 'display') {
-                       $items = $this->addChildren($items, false, $order, $uid);
+                       $items = $this->addChildren($items, false, $order, $uid, $mode);
 
                        if (!$update) {
                                $live_update_div = '<div id="live-display"></div>' . "\r\n"
@@ -502,17 +500,18 @@ class Conversation
                                        . "</script>";
                        }
                } elseif ($mode === 'community') {
-                       $items = $this->addChildren($items, true, $order, $uid);
+                       $items = $this->addChildren($items, true, $order, $uid, $mode);
 
                        if (!$update) {
                                $live_update_div = '<div id="live-community"></div>' . "\r\n"
                                        . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
                                        . '?f='
                                        . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
+                                       . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
                                        . "'; </script>\r\n";
                        }
                } elseif ($mode === 'contacts') {
-                       $items = $this->addChildren($items, false, $order, $uid);
+                       $items = $this->addChildren($items, false, $order, $uid, $mode);
 
                        if (!$update) {
                                $live_update_div = '<div id="live-contact"></div>' . "\r\n"
@@ -558,7 +557,7 @@ class Conversation
                        if (in_array($mode, ['community', 'contacts', 'profile'])) {
                                $writable = true;
                        } else {
-                               $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
+                               $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
                        }
 
                        if (!local_user()) {
@@ -660,27 +659,6 @@ class Conversation
                                                $pinned = '';
                                        }
 
-                                       if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
-                                               $owner_avatar  = $author_avatar  = $item['contact-id'];
-                                               $owner_updated = $author_updated = '';
-                                               $owner_thumb   = $author_thumb   = $item['contact-avatar'];
-                                       } else {
-                                               $owner_avatar   = $item['owner-id'];
-                                               $owner_updated  = $item['owner-updated'];
-                                               $owner_thumb    = $item['owner-avatar'];
-                                               $author_avatar  = $item['author-id'];
-                                               $author_updated = $item['author-updated'];
-                                               $author_thumb   = $item['author-avatar'];
-                                       }
-
-                                       if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
-                                               $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
-                                       }
-                       
-                                       if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
-                                               $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
-                                       }
-
                                        $tmp_item = [
                                                'template'             => $tpl,
                                                'id'                   => ($preview ? 'P0' : $item['id']),
@@ -698,7 +676,7 @@ class Conversation
                                                'name'                 => $profile_name,
                                                'sparkle'              => $sparkle,
                                                'lock'                 => false,
-                                               'thumb'                => $this->baseURL->remove($author_thumb),
+                                               'thumb'                => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
                                                'title'                => $title,
                                                'body_html'            => $body_html,
                                                'tags'                 => $tags['tags'],
@@ -719,7 +697,7 @@ class Conversation
                                                'indent'               => '',
                                                'owner_name'           => '',
                                                'owner_url'            => '',
-                                               'owner_photo'          => $this->baseURL->remove($owner_thumb),
+                                               'owner_photo'          => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
                                                'plink'                => ItemModel::getPlink($item),
                                                'edpost'               => false,
                                                'pinned'               => $pinned,
@@ -806,7 +784,7 @@ class Conversation
                return $o;
        }
 
-       private function getBlocklist()
+       private function getBlocklist(): array
        {
                if (!local_user()) {
                        return [];
@@ -838,11 +816,11 @@ class Conversation
         *
         * @return array items with parents and comments
         */
-       private function addRowInformation(array $row, array $activity, array $thr_parent)
+       private function addRowInformation(array $row, array $activity, array $thr_parent): array
        {
                $this->profiler->startRecording('rendering');
 
-               if ($row['uid'] == 0) {
+               if (!$row['writable']) {
                        $row['writable'] = in_array($row['network'], Protocol::FEDERATED);
                }
 
@@ -925,15 +903,15 @@ class Conversation
         * The system will fetch the comments for the local user whenever possible.
         * This behaviour is currently needed to allow commenting on Friendica posts.
         *
-        * @param array $parents Parent items
-        *
-        * @param       $block_authors
-        * @param       $order
-        * @param       $uid
+        * @param array  $parents       Parent items
+        * @param bool   $block_authors
+        * @param bool   $order
+        * @param int    $uid
+        * @param string $mode
         * @return array items with parents and comments
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private function addChildren(array $parents, $block_authors, $order, $uid)
+       private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode): array
        {
                $this->profiler->startRecording('rendering');
                if (count($parents) > 1) {
@@ -995,6 +973,10 @@ class Conversation
                                continue;
                        }
 
+                       if (($mode != 'contacts') && !$row['origin']) {
+                               $row['featured'] = false;
+                       }
+
                        if ($max_comments > 0) {
                                if (($row['gravity'] == GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
                                        continue;
@@ -1023,7 +1005,7 @@ class Conversation
         * @param bool  $recursive
         * @return array
         */
-       private function getItemChildren(array &$item_list, array $parent, $recursive = true)
+       private function getItemChildren(array &$item_list, array $parent, bool $recursive = true): array
        {
                $this->profiler->startRecording('rendering');
                $children = [];
@@ -1058,7 +1040,7 @@ class Conversation
         * @param array $items
         * @return array
         */
-       private function sortItemChildren(array $items)
+       private function sortItemChildren(array $items): array
        {
                $this->profiler->startRecording('rendering');
                $result = $items;
@@ -1104,7 +1086,7 @@ class Conversation
         * @param array $parent A tree-like array of items
         * @return array
         */
-       private function smartFlattenConversation(array $parent)
+       private function smartFlattenConversation(array $parent): array
        {
                $this->profiler->startRecording('rendering');
                if (!isset($parent['children']) || count($parent['children']) == 0) {
@@ -1160,7 +1142,7 @@ class Conversation
         * @return array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private function convSort(array $item_list, $order)
+       private function convSort(array $item_list, string $order): array
        {
                $this->profiler->startRecording('rendering');
                $parents = [];
@@ -1240,7 +1222,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrFeaturedReceived(array $a, array $b)
+       private function sortThrFeaturedReceived(array $a, array $b): int
        {
                if ($b['featured'] && !$a['featured']) {
                        return 1;
@@ -1258,7 +1240,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrFeaturedCommented(array $a, array $b)
+       private function sortThrFeaturedCommented(array $a, array $b): int
        {
                if ($b['featured'] && !$a['featured']) {
                        return 1;
@@ -1276,7 +1258,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrReceived(array $a, array $b)
+       private function sortThrReceived(array $a, array $b): int
        {
                return strcmp($b['received'], $a['received']);
        }
@@ -1288,7 +1270,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrReceivedRev(array $a, array $b)
+       private function sortThrReceivedRev(array $a, array $b): int
        {
                return strcmp($a['received'], $b['received']);
        }
@@ -1300,7 +1282,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrCommented(array $a, array $b)
+       private function sortThrCommented(array $a, array $b): int
        {
                return strcmp($b['commented'], $a['commented']);
        }
@@ -1312,7 +1294,7 @@ class Conversation
         * @param array $b
         * @return int
         */
-       private function sortThrCreated(array $a, array $b)
+       private function sortThrCreated(array $a, array $b): int
        {
                return strcmp($b['created'], $a['created']);
        }