]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Add cache for PHP 7.3 test
[friendica.git] / include / conversation.php
index 3261311012b4eba8c6da9f09cdc88488e1ce8979..57d368e927b9723ff16ca4191e26b2fe8db72837 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -145,7 +145,7 @@ function localize_item(&$item)
                $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
        }
 
-       /// @todo The following functionality needs to be cleaned up. 
+       /// @todo The following functionality needs to be cleaned up.
        if (!empty($item['verb'])) {
                $activity = DI::activity();
 
@@ -160,9 +160,6 @@ function localize_item(&$item)
                                return;
                        }
 
-                       $Aname = $item['author-name'];
-                       $Alink = $item['author-link'];
-
                        $obj = XML::parseString($xmlhead . $item['object']);
 
                        $Bname = $obj->title;
@@ -177,9 +174,17 @@ function localize_item(&$item)
                                }
                        }
 
-                       $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
-                       $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
-                       if ($Bphoto != "") {
+                       $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
+                       $A = '[url=' . Contact::magicLinkByContact($author) . ']' . $item['author-name'] . '[/url]';
+
+                       if (!empty($Blink)) {
+                               $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
+                       } else {
+                               $B = '';
+                       }
+
+                       if ($Bphoto != "" && !empty($Blink)) {
                                $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
                        }
 
@@ -262,11 +267,10 @@ function localize_item(&$item)
        }
 
        // add sparkle links to appropriate permalinks
-       $author = ['uid' => 0, 'id' => $item['author-id'],
-               'network' => $item['author-network'], 'url' => $item['author-link']];
-
        // Only create a redirection to a magic link when logged in
        if (!empty($item['plink']) && Session::isAuthenticated()) {
+               $author = ['uid' => 0, 'id' => $item['author-id'],
+                       'network' => $item['author-network'], 'url' => $item['author-link']];
                $item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
        }
 }
@@ -477,7 +481,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                'attendyes'   => [],
                'attendno'    => [],
                'attendmaybe' => [],
-               'announce'    => [],    
+               'announce'    => [],
        ];
 
        if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
@@ -718,10 +722,10 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
 function conversation_fetch_comments($thread_items, bool $pinned, array $activity) {
        $comments = [];
 
-       while ($row = Item::fetch($thread_items)) {
+       while ($row = Post::fetch($thread_items)) {
                if (!empty($activity)) {
                        if (($row['gravity'] == GRAVITY_PARENT)) {
-                               $row['post-type'] = Item::PT_ANNOUNCEMENT;
+                               $row['post-reason'] = Item::PR_ANNOUNCEMENT;
                                $row = array_merge($row, $activity);
                                $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
                                $row['causer-link'] = $contact['url'];
@@ -735,26 +739,26 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
 
                $name = $row['causer-contact-type'] == Contact::TYPE_RELAY ? $row['causer-link'] : $row['causer-name'];
 
-               switch ($row['post-type']) {
-                       case Item::PT_TO:
+               switch ($row['post-reason']) {
+                       case Item::PR_TO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
                                break;
-                       case Item::PT_CC:
+                       case Item::PR_CC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
                                break;
-                       case Item::PT_BTO:
+                       case Item::PR_BTO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
                                break;
-                       case Item::PT_BCC:
+                       case Item::PR_BCC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
                                break;
-                       case Item::PT_FOLLOWER:
+                       case Item::PR_FOLLOWER:
                                $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
                                break;
-                       case Item::PT_TAG:
+                       case Item::PR_TAG:
                                $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
                                break;
-                       case Item::PT_ANNOUNCEMENT:
+                       case Item::PR_ANNOUNCEMENT:
                                if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) {
                                        $row['owner-id'] = $row['causer-id'];
                                        $row['owner-link'] = $row['causer-link'];
@@ -763,23 +767,25 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
                                }
 
                                if (($row['gravity'] == GRAVITY_PARENT) && !empty($row['causer-id'])) {
-                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkById($row['causer-id'])) .'">' . htmlentities($name) . '</a>');
+                                       $causer = ['uid' => 0, 'id' => $row['causer-id'],
+                                               'network' => $row['causer-network'], 'url' => $row['causer-link']];
+                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($name) . '</a>');
                                }
                                $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s', $name))];
                                break;
-                       case Item::PT_COMMENT:
+                       case Item::PR_COMMENT:
                                $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
                                break;
-                       case Item::PT_STORED:
+                       case Item::PR_STORED:
                                $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
                                break;
-                       case Item::PT_GLOBAL:
+                       case Item::PR_GLOBAL:
                                $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
                                break;
-                       case Item::PT_RELAY:
+                       case Item::PR_RELAY:
                                $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Relayed') : DI::l10n()->t('Relayed by %s.', $name))];
                                break;
-                       case Item::PT_FETCHED:
+                       case Item::PR_FETCHED:
                                $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Fetched') : DI::l10n()->t('Fetched because of %s', $name))];
                                break;
                        }
@@ -827,19 +833,19 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
 
        foreach ($parents AS $parent) {
                if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) {
-                       $condition = ["`item`.`parent-uri-id` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
+                       $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
                                $parent['thr-parent-id'], $uid, Verb::getID(Activity::FOLLOW)];
                        if (!empty($parent['author-id'])) {
                                $activity = ['causer-id' => $parent['author-id']];
                                foreach (['commented', 'received', 'created'] as $orderfields) {
                                        if (!empty($parent[$orderfields])) {
-                                               $activity[$orderfields] = $parent[$orderfields];        
-                                       }       
+                                               $activity[$orderfields] = $parent[$orderfields];
+                                       }
                                }
                        }
                } else {
-                       $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
-                               $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)];
+                       $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
+                               $parent['uri-id'], $uid, Verb::getID(Activity::FOLLOW)];
                        $activity = [];
                }
                $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params, $activity);
@@ -869,10 +875,10 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
  */
 function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params, array $activity) {
        if ($block_authors) {
-               $condition[0] .= " AND NOT `author`.`hidden`";
+               $condition[0] .= " AND NOT `author-hidden`";
        }
 
-       $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params);
+       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
 
        $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity);
 
@@ -882,7 +888,8 @@ function conversation_fetch_items(array $parent, array $items, array $condition,
        return $items;
 }
 
-function item_photo_menu($item) {
+function item_photo_menu($item)
+{
        $sub_link = '';
        $poke_link = '';
        $contact_url = '';
@@ -893,8 +900,8 @@ function item_photo_menu($item) {
        $block_link = '';
        $ignore_link = '';
 
-       if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) {
-               $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
+       if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
+               $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
        }
 
        $author = ['uid' => 0, 'id' => $item['author-id'],
@@ -903,7 +910,7 @@ function item_photo_menu($item) {
        $sparkle = (strpos($profile_link, 'redir/') === 0);
 
        $cid = 0;
-       $pcid = Contact::getIdForURL($item['author-link'], 0, false);
+       $pcid = $item['author-id'];
        $network = '';
        $rel = 0;
        $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
@@ -923,8 +930,8 @@ function item_photo_menu($item) {
        if (!empty($pcid)) {
                $contact_url = 'contact/' . $pcid;
                $posts_link  = $contact_url . '/posts';
-               $block_link  = $contact_url . '/block';
-               $ignore_link = $contact_url . '/ignore';
+               $block_link  = $item['self'] ? '' : $contact_url . '/block';
+               $ignore_link = $item['self'] ? '' : $contact_url . '/ignore';
        }
 
        if ($cid && !$item['self']) {
@@ -977,7 +984,7 @@ function item_photo_menu($item) {
                if (strpos($v, 'javascript:') === 0) {
                        $v = substr($v, 11);
                        $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
-               } elseif ($v!='') {
+               } elseif ($v) {
                        $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
                }
        }
@@ -1037,31 +1044,31 @@ function builtin_activity_puller(array $activity, array &$conv_responses)
 
                        $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
 
-                       if (empty($activity['thr-parent'])) {
-                               $activity['thr-parent'] = $activity['parent-uri'];
+                       if (empty($activity['thr-parent-id'])) {
+                               $activity['thr-parent-id'] = $activity['parent-uri-id'];
                        }
 
                        // Skip when the causer of the parent is the same than the author of the announce
-                       if (($verb == Activity::ANNOUNCE) && Post::exists(['uri' => $activity['thr-parent'],
+                       if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
                                'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) {
                                continue;
                        }
 
-                       if (!isset($conv_responses[$mode][$activity['thr-parent']])) {
-                               $conv_responses[$mode][$activity['thr-parent']] = [
+                       if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
+                               $conv_responses[$mode][$activity['thr-parent-id']] = [
                                        'links' => [],
                                        'self' => 0,
                                ];
-                       } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent']]['links'])) {
+                       } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
                                // only list each unique author once
                                continue;
                        }
 
                        if (public_contact() == $activity['author-id']) {
-                               $conv_responses[$mode][$activity['thr-parent']]['self'] = 1;
+                               $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
                        }
 
-                       $conv_responses[$mode][$activity['thr-parent']]['links'][] = $link;
+                       $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
 
                        // there can only be one activity verb per item so if we found anything, we can stop looking
                        return;
@@ -1205,6 +1212,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$edimg'        => DI::l10n()->t('Image'),
                '$edurl'        => DI::l10n()->t('Link'),
                '$edattach'     => DI::l10n()->t('Link or Media'),
+               '$edvideo'      => DI::l10n()->t('Video'),
                '$setloc'       => DI::l10n()->t('Set your location'),
                '$shortsetloc'  => DI::l10n()->t('set location'),
                '$noloc'        => DI::l10n()->t('Clear browser location'),
@@ -1268,17 +1276,17 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
                if ($item['gravity'] != GRAVITY_PARENT) {
                        if ($recursive) {
                                // Fallback to parent-uri if thr-parent is not set
-                               $thr_parent = $item['thr-parent'];
+                               $thr_parent = $item['thr-parent-id'];
                                if ($thr_parent == '') {
-                                       $thr_parent = $item['parent-uri'];
+                                       $thr_parent = $item['parent-uri-id'];
                                }
 
-                               if ($thr_parent == $parent['uri']) {
+                               if ($thr_parent == $parent['uri-id']) {
                                        $item['children'] = get_item_children($item_list, $item);
                                        $children[] = $item;
                                        unset($item_list[$i]);
                                }
-                       } elseif ($item['parent'] == $parent['id']) {
+                       } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
                                $children[] = $item;
                                unset($item_list[$i]);
                        }
@@ -1408,7 +1416,7 @@ function conv_sort(array $item_list, $order)
                        continue;
                }
 
-               $item_array[$item['uri']] = $item;
+               $item_array[$item['uri-id']] = $item;
        }
 
        // Extract the top level items