X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=86af3b69d496902c71aab1c4a6c414056c1a9ded;hb=53810a9e42a82caf5eb351a8f2eb310f2a9961d1;hp=1a93d119f4ed464e37ab129a7e7acb7b75bbf486;hpb=afc87838628994edd839cc5f3b8b9236adb129d3;p=friendica.git diff --git a/include/conversation.php b/include/conversation.php index 1a93d119f4..86af3b69d4 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -22,7 +22,6 @@ use Friendica\App; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; -use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; @@ -34,13 +33,13 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Profile; -use Friendica\Model\Term; +use Friendica\Model\Tag; +use Friendica\Model\Verb; use Friendica\Object\Post; use Friendica\Object\Thread; use Friendica\Protocol\Activity; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; use Friendica\Util\Temporal; use Friendica\Util\XML; @@ -148,6 +147,8 @@ function localize_item(&$item) if (!empty($item['verb'])) { $activity = DI::activity(); + $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; + if (stristr($item['verb'], Activity::POKE)) { $verb = urldecode(substr($item['verb'], strpos($item['verb'],'#') + 1)); if (!$verb) { @@ -160,8 +161,6 @@ function localize_item(&$item) $Aname = $item['author-name']; $Alink = $item['author-link']; - $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = XML::parseString($xmlhead . $item['object']); $Bname = $obj->title; @@ -189,12 +188,12 @@ function localize_item(&$item) $txt = DI::l10n()->t('%1$s poked %2$s'); // now translate the verb - $poked_t = trim(sprintf($txt, "", "")); + $poked_t = trim(sprintf($txt, '', '')); $txt = str_replace($poked_t, DI::l10n()->t($verb), $txt); // then do the sprintf on the translation string - $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto; + $item['body'] = sprintf($txt, $A, $B) . "\n\n\n" . $Bphoto; } @@ -237,7 +236,7 @@ function localize_item(&$item) } $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; - $parsedobj = XML::parseString($xmlhead.$item['object']); + $parsedobj = XML::parseString($xmlhead . $item['object']); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $item['body'] = DI::l10n()->t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag); @@ -316,7 +315,7 @@ function conv_get_blocklist() return []; } - $str_blocked = DI::pConfig()->get(local_user(), 'system', 'blocked'); + $str_blocked = str_replace(["\n", "\r"], ",", DI::pConfig()->get(local_user(), 'system', 'blocked')); if (empty($str_blocked)) { return []; } @@ -325,7 +324,7 @@ function conv_get_blocklist() foreach (explode(',', $str_blocked) as $entry) { // The 4th parameter guarantees that there always will be a public contact entry - $cid = Contact::getIdForURL(trim($entry), 0, true, ['url' => trim($entry)]); + $cid = Contact::getIdForURL(trim($entry), 0, false, ['url' => trim($entry)]); if (!empty($cid)) { $blocklist[] = $cid; } @@ -377,17 +376,17 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o . "\r\n"; } @@ -527,7 +526,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o $profile_name = $item['author-link']; } - $tags = Term::populateTagsFromItem($item); + $tags = Tag::populateFromItem($item); $author = ['uid' => 0, 'id' => $item['author-id'], 'network' => $item['author-network'], 'url' => $item['author-link']]; @@ -593,7 +592,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o 'name' => $profile_name, 'sparkle' => $sparkle, 'lock' => $lock, - 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)), + 'thumb' => DI::baseUrl()->remove($item['author-avatar']), 'title' => $title, 'body' => $body, 'tags' => $tags['tags'], @@ -613,7 +612,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o 'indent' => '', 'owner_name' => $owner_name, 'owner_url' => $owner_url, - 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)), + 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']), 'plink' => Item::getPlink($item), 'edpost' => false, 'isstarred' => $isstarred, @@ -671,7 +670,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o $item['pagedrop'] = $page_dropping; - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { $item_object = new Post($item); $conv->addParent($item_object); } @@ -760,7 +759,11 @@ function conversation_fetch_comments($thread_items, $pinned) { * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ function conversation_add_children(array $parents, $block_authors, $order, $uid) { - $max_comments = DI::config()->get('system', 'max_comments', 100); + if (count($parents) > 1) { + $max_comments = DI::config()->get('system', 'max_comments', 100); + } else { + $max_comments = DI::config()->get('system', 'max_display_comments', 1000); + } $params = ['order' => ['uid', 'commented' => true]]; @@ -771,19 +774,9 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid) $items = []; foreach ($parents AS $parent) { - $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ", - $parent['uri'], $uid]; - if ($block_authors) { - $condition[0] .= "AND NOT `author`.`hidden`"; - } - - $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params); - - $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false); - - if (count($comments) != 0) { - $items = array_merge($items, $comments); - } + $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", + $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)]; + $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params); } foreach ($items as $index => $item) { @@ -797,6 +790,31 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid) return $items; } +/** + * Fetch conversation items + * + * @param array $parent + * @param array $items + * @param array $condition + * @param boolean $block_authors + * @param array $params + * @return array + */ +function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params) { + if ($block_authors) { + $condition[0] .= " AND NOT `author`.`hidden`"; + } + + $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params); + + $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false); + + if (count($comments) != 0) { + $items = array_merge($items, $comments); + } + return $items; +} + function item_photo_menu($item) { $sub_link = ''; $poke_link = ''; @@ -808,7 +826,7 @@ function item_photo_menu($item) { $block_link = ''; $ignore_link = ''; - if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) { + if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) { $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; } @@ -818,7 +836,7 @@ function item_photo_menu($item) { $sparkle = (strpos($profile_link, 'redir/') === 0); $cid = 0; - $pcid = Contact::getIdForURL($item['author-link'], 0, true); + $pcid = Contact::getIdForURL($item['author-link'], 0, false); $network = ''; $rel = 0; $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])]; @@ -837,15 +855,15 @@ function item_photo_menu($item) { if (!empty($pcid)) { $contact_url = 'contact/' . $pcid; - $posts_link = 'contact/' . $pcid . '/posts'; - $block_link = 'contact/' . $pcid . '/block'; - $ignore_link = 'contact/' . $pcid . '/ignore'; + $posts_link = $contact_url . '/posts'; + $block_link = $contact_url . '/block'; + $ignore_link = $contact_url . '/ignore'; } if ($cid && !$item['self']) { - $poke_link = 'poke?c=' . $cid; $contact_url = 'contact/' . $cid; - $posts_link = 'contact/' . $cid . '/posts'; + $poke_link = $contact_url . '/poke'; + $posts_link = $contact_url . '/posts'; if (in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) { $pm_url = 'message/new/' . $cid; @@ -933,7 +951,7 @@ function builtin_activity_puller($item, &$conv_responses) { return; } - if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { + if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['gravity'] != GRAVITY_PARENT)) { $author = ['uid' => 0, 'id' => $item['author-id'], 'network' => $item['author-network'], 'url' => $item['author-link']]; $url = Contact::magicLinkByContact($author); @@ -1203,7 +1221,7 @@ function get_item_children(array &$item_list, array $parent, $recursive = true) { $children = []; foreach ($item_list as $i => $item) { - if ($item['id'] != $item['parent']) { + if ($item['gravity'] != GRAVITY_PARENT) { if ($recursive) { // Fallback to parent-uri if thr-parent is not set $thr_parent = $item['thr-parent']; @@ -1351,7 +1369,7 @@ function conv_sort(array $item_list, $order) // Extract the top level items foreach ($item_array as $item) { - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { $parents[] = $item; } }