3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Content;
25 use Friendica\App\Arguments;
26 use Friendica\App\BaseURL;
27 use Friendica\BaseModule;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Config\Capability\IManageConfigValues;
30 use Friendica\Core\Hook;
31 use Friendica\Core\L10n;
32 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
33 use Friendica\Core\Protocol;
34 use Friendica\Core\Renderer;
35 use Friendica\Core\Session\Capability\IHandleUserSessions;
36 use Friendica\Core\Theme;
37 use Friendica\Database\DBA;
39 use Friendica\Model\Contact;
40 use Friendica\Model\Item as ItemModel;
41 use Friendica\Model\Post;
42 use Friendica\Model\Tag;
43 use Friendica\Model\User;
44 use Friendica\Model\Verb;
45 use Friendica\Object\Post as PostObject;
46 use Friendica\Object\Thread;
47 use Friendica\Protocol\Activity;
48 use Friendica\Util\Crypto;
49 use Friendica\Util\DateTimeFormat;
50 use Friendica\Util\Profiler;
51 use Friendica\Util\Strings;
52 use Friendica\Util\Temporal;
53 use Psr\Log\LoggerInterface;
57 const MODE_COMMUNITY = 'community';
58 const MODE_CONTACTS = 'contacts';
59 const MODE_CONTACT_POSTS = 'contact-posts';
60 const MODE_DISPLAY = 'display';
61 const MODE_FILED = 'filed';
62 const MODE_NETWORK = 'network';
63 const MODE_NOTES = 'notes';
64 const MODE_SEARCH = 'search';
65 const MODE_PROFILE = 'profile';
73 /** @var LoggerInterface */
77 /** @var App\Arguments */
79 /** @var IManagePersonalConfigValues */
83 /** @var IManageConfigValues */
91 /** @var IHandleUserSessions */
94 public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, IHandleUserSessions $session)
96 $this->activity = $activity;
98 $this->config = $config;
100 $this->baseURL = $baseURL;
101 $this->profiler = $profiler;
102 $this->logger = $logger;
105 $this->pConfig = $pConfig;
108 $this->session = $session;
112 * Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
114 * Increments the count of each matching activity and adds a link to the author as needed.
116 * @param array $activity
117 * @param array &$conv_responses (already created with builtin activity structure)
119 * @throws ImagickException
120 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
122 public function builtinActivityPuller(array $activity, array &$conv_responses)
124 $thread_parent = $activity['thr-parent-row'] ?? [];
126 foreach ($conv_responses as $mode => $v) {
131 $verb = Activity::LIKE;
134 $verb = Activity::DISLIKE;
137 $verb = Activity::ATTEND;
140 $verb = Activity::ATTENDNO;
143 $verb = Activity::ATTENDMAYBE;
146 $verb = Activity::ANNOUNCE;
152 if (!empty($activity['verb']) && $this->activity->match($activity['verb'], $verb) && ($activity['gravity'] != ItemModel::GRAVITY_PARENT)) {
155 'id' => $activity['author-id'],
156 'network' => $activity['author-network'],
157 'url' => $activity['author-link']
159 $url = Contact::magicLinkByContact($author);
160 if (strpos($url, 'contact/redir/') === 0) {
161 $sparkle = ' class="sparkle" ';
164 $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
166 if (empty($activity['thr-parent-id'])) {
167 $activity['thr-parent-id'] = $activity['parent-uri-id'];
170 // Skip when the causer of the parent is the same as the author of the announce
171 if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id']) && ($thread_parent['causer-id'] == $activity['author-id'])) {
175 if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
176 $conv_responses[$mode][$activity['thr-parent-id']] = [
180 } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
181 // only list each unique author once
185 if ($this->session->getPublicContactId() == $activity['author-id']) {
186 $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
189 $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
191 // there can only be one activity verb per item so if we found anything, we can stop looking
198 * Format the activity text for an item/photo/video
200 * @param array $links = array of pre-linked names of actors
201 * @param string $verb = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
202 * @param int $id = item id
203 * @return string formatted text
204 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
206 public function formatActivity(array $links, string $verb, int $id): string
208 $this->profiler->startRecording('rendering');
213 $total = count($links);
217 // Phrase if there is only one liker. In other cases it will be uses for the expanded
218 // list which show all likers
221 $phrase = $this->l10n->t('%s likes this.', $likers);
224 $phrase = $this->l10n->t('%s doesn\'t like this.', $likers);
227 $phrase = $this->l10n->t('%s attends.', $likers);
230 $phrase = $this->l10n->t('%s doesn\'t attend.', $likers);
233 $phrase = $this->l10n->t('%s attends maybe.', $likers);
236 $phrase = $this->l10n->t('%s reshared this.', $likers);
239 } elseif ($total > 1) {
240 if ($total < $this->config->get('system', 'max_likers')) {
241 $likers = implode(', ', array_slice($links, 0, -1));
242 $likers .= ' ' . $this->l10n->t('and') . ' ' . $links[count($links) - 1];
244 $likers = implode(', ', array_slice($links, 0, $this->config->get('system', 'max_likers') - 1));
245 $likers .= ' ' . $this->l10n->t('and %d other people', $total - $this->config->get('system', 'max_likers'));
248 $spanatts = "class=\"btn btn-link fakelink\" onclick=\"openClose('{$verb}list-$id');\"";
253 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> like this', $spanatts, $total);
254 $explikers = $this->l10n->t('%s like this.', $likers);
257 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> don\'t like this', $spanatts, $total);
258 $explikers = $this->l10n->t('%s don\'t like this.', $likers);
261 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> attend', $spanatts, $total);
262 $explikers = $this->l10n->t('%s attend.', $likers);
265 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> don\'t attend', $spanatts, $total);
266 $explikers = $this->l10n->t('%s don\'t attend.', $likers);
269 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> attend maybe', $spanatts, $total);
270 $explikers = $this->l10n->t('%s attend maybe.', $likers);
273 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> reshared this', $spanatts, $total);
274 $explikers = $this->l10n->t('%s reshared this.', $likers);
278 $expanded .= "\t" . '<p class="wall-item-' . $verb . '-expanded" id="' . $verb . 'list-' . $id . '" style="display: none;" >' . $explikers . '</p>';
281 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
282 '$phrase' => $phrase,
288 $this->profiler->stopRecording();
292 public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string
294 $user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
295 if (empty($user['uid'])) {
299 $this->profiler->startRecording('rendering');
302 $x['allow_location'] = $x['allow_location'] ?? $user['allow_location'];
303 $x['default_location'] = $x['default_location'] ?? $user['default-location'];
304 $x['nickname'] = $x['nickname'] ?? $user['nickname'];
305 $x['lockstate'] = $x['lockstate'] ?? ACL::getLockstateForUserId($user['uid']) ? 'lock' : 'unlock';
306 $x['acl'] = $x['acl'] ?? ACL::getFullSelectorHTML($this->page, $user['uid'], true);
307 $x['bang'] = $x['bang'] ?? '';
308 $x['visitor'] = $x['visitor'] ?? 'block';
309 $x['is_owner'] = $x['is_owner'] ?? true;
310 $x['profile_uid'] = $x['profile_uid'] ?? $this->session->getLocalUserId();
313 $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
315 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
316 $this->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
317 '$newpost' => 'true',
318 '$baseurl' => $this->baseURL,
319 '$geotag' => $geotag,
320 '$nickname' => $x['nickname'],
321 '$ispublic' => $this->l10n->t('Visible to <strong>everybody</strong>'),
322 '$linkurl' => $this->l10n->t('Please enter a image/video/audio/webpage URL:'),
323 '$term' => $this->l10n->t('Tag term:'),
324 '$fileas' => $this->l10n->t('Save to Folder:'),
325 '$whereareu' => $this->l10n->t('Where are you right now?'),
326 '$delitems' => $this->l10n->t("Delete item\x28s\x29?"),
327 '$is_mobile' => $this->mode->isMobile(),
331 Hook::callAll('jot_tool', $jotplugins);
333 if ($this->config->get('system', 'set_creation_date')) {
334 $created_at = Temporal::getDateTimeField(
335 new \DateTime(DBA::NULL_DATETIME),
336 new \DateTime('now'),
338 $this->l10n->t('Created at'),
345 $tpl = Renderer::getMarkupTemplate('jot.tpl');
347 $o .= Renderer::replaceMacros($tpl, [
348 '$new_post' => $this->l10n->t('New Post'),
349 '$return_path' => $this->args->getQueryString(),
351 '$share' => ($x['button'] ?? '') ?: $this->l10n->t('Share'),
352 '$loading' => $this->l10n->t('Loading...'),
353 '$upload' => $this->l10n->t('Upload photo'),
354 '$shortupload' => $this->l10n->t('upload photo'),
355 '$attach' => $this->l10n->t('Attach file'),
356 '$shortattach' => $this->l10n->t('attach file'),
357 '$edbold' => $this->l10n->t('Bold'),
358 '$editalic' => $this->l10n->t('Italic'),
359 '$eduline' => $this->l10n->t('Underline'),
360 '$edquote' => $this->l10n->t('Quote'),
361 '$edcode' => $this->l10n->t('Code'),
362 '$edimg' => $this->l10n->t('Image'),
363 '$edurl' => $this->l10n->t('Link'),
364 '$edattach' => $this->l10n->t('Link or Media'),
365 '$edvideo' => $this->l10n->t('Video'),
366 '$setloc' => $this->l10n->t('Set your location'),
367 '$shortsetloc' => $this->l10n->t('set location'),
368 '$noloc' => $this->l10n->t('Clear browser location'),
369 '$shortnoloc' => $this->l10n->t('clear location'),
370 '$title' => $x['title'] ?? '',
371 '$placeholdertitle' => $this->l10n->t('Set title'),
372 '$category' => $x['category'] ?? '',
373 '$placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
374 '$scheduled_at' => Temporal::getDateTimeField(
376 new \DateTime('now + 6 months'),
378 $this->l10n->t('Scheduled at'),
381 '$created_at' => $created_at,
382 '$wait' => $this->l10n->t('Please wait'),
383 '$permset' => $this->l10n->t('Permission settings'),
384 '$shortpermset' => $this->l10n->t('Permissions'),
385 '$wall' => $notes_cid ? 0 : 1,
386 '$posttype' => $notes_cid ? ItemModel::PT_PERSONAL_NOTE : ItemModel::PT_ARTICLE,
387 '$content' => $x['content'] ?? '',
388 '$post_id' => $x['post_id'] ?? '',
389 '$baseurl' => $this->baseURL,
390 '$defloc' => $x['default_location'],
391 '$visitor' => $x['visitor'],
392 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
393 '$public' => $this->l10n->t('Public post'),
394 '$lockstate' => $x['lockstate'],
395 '$bang' => $x['bang'],
396 '$profile_uid' => $x['profile_uid'],
397 '$preview' => $this->l10n->t('Preview'),
398 '$jotplugins' => $jotplugins,
399 '$notes_cid' => $notes_cid,
400 '$cancel' => $this->l10n->t('Cancel'),
401 '$rand_num' => Crypto::randomDigits(12),
403 // ACL permissions box
406 //jot nav tab (used in some themes)
407 '$message' => $this->l10n->t('Message'),
408 '$browser' => $this->l10n->t('Browser'),
410 '$compose_link_title' => $this->l10n->t('Open Compose page'),
411 '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
414 '$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000,1),
419 if ($popup == true) {
420 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
423 $this->profiler->stopRecording();
428 * "Render" a conversation or list of items for HTML display.
429 * There are two major forms of display:
430 * - Sequential or unthreaded ("New Item View" or search results)
431 * - conversation view
432 * The $mode parameter decides between the various renderings and also
433 * figures out how to determine page owner and other contextual items
434 * that are based on unique features of the calling module.
435 * @param array $items
436 * @param string $mode
437 * @param $update @TODO Which type?
438 * @param bool $preview
439 * @param string $order
442 * @throws ImagickException
443 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
445 public function create(array $items, string $mode, $update, bool $preview = false, string $order = 'commented', int $uid = 0): string
447 $this->profiler->startRecording('rendering');
449 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
450 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
451 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
452 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
454 $live_update_div = '';
456 $blocklist = $this->getBlocklist();
458 $previewing = (($preview) ? ' preview ' : '');
460 if ($mode === self::MODE_NETWORK) {
461 $items = $this->addChildren($items, false, $order, $uid, $mode);
464 * The special div is needed for liveUpdate to kick in for this page.
465 * We only launch liveUpdate if you aren't filtering in some incompatible
466 * way and also you aren't writing a comment (discovered in javascript).
468 $live_update_div = '<div id="live-network"></div>' . "\r\n"
469 . "<script> var profile_uid = " . $_SESSION['uid']
470 . "; var netargs = '" . substr($this->args->getCommand(), 8)
472 . (!empty($_GET['contactid']) ? '&contactid=' . rawurlencode($_GET['contactid']) : '')
473 . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
474 . (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
475 . (!empty($_GET['order']) ? '&order=' . rawurlencode($_GET['order']) : '')
476 . (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
477 . (!empty($_GET['liked']) ? '&liked=' . rawurlencode($_GET['liked']) : '')
478 . (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
479 . (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
480 . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
481 . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
482 . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
484 . "'; </script>\r\n";
486 } elseif ($mode === self::MODE_PROFILE) {
487 $items = $this->addChildren($items, false, $order, $uid, $mode);
490 $tab = !empty($_GET['tab']) ? trim($_GET['tab']) : 'posts';
492 if ($tab === 'posts') {
494 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
495 * because browser prefetching might change it on us. We have to deliver it with the page.
498 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
499 . "<script> var profile_uid = " . $uid
500 . "; var netargs = '?f='; </script>\r\n";
503 } elseif ($mode === self::MODE_NOTES) {
504 $items = $this->addChildren($items, false, $order, $this->session->getLocalUserId(), $mode);
507 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
508 . "<script> var profile_uid = " . $this->session->getLocalUserId()
509 . "; var netargs = '?f='; </script>\r\n";
511 } elseif ($mode === self::MODE_DISPLAY) {
512 $items = $this->addChildren($items, false, $order, $uid, $mode);
515 $live_update_div = '<div id="live-display"></div>' . "\r\n"
516 . "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
519 } elseif ($mode === self::MODE_COMMUNITY) {
520 $items = $this->addChildren($items, true, $order, $uid, $mode);
523 $live_update_div = '<div id="live-community"></div>' . "\r\n"
524 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
526 . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
527 . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
528 . "'; </script>\r\n";
530 } elseif ($mode === self::MODE_CONTACTS) {
531 $items = $this->addChildren($items, false, $order, $uid, $mode);
534 $live_update_div = '<div id="live-contact"></div>' . "\r\n"
535 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
536 ."?f='; </script>\r\n";
538 } elseif ($mode === self::MODE_SEARCH) {
539 $live_update_div = '<div id="live-search"></div>' . "\r\n";
542 $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH;
545 $_SESSION['return_path'] = $this->args->getQueryString();
548 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
549 Hook::callAll('conversation_start', $cb);
551 $items = $cb['items'];
562 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
563 unset($conv_responses['dislike']);
566 // array with html for each thread (parent+comments)
570 $page_template = Renderer::getMarkupTemplate("conversation.tpl");
571 $formSecurityToken = BaseModule::getFormSecurityToken('contact_action');
573 if (!empty($items)) {
574 if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
577 $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
580 if (!$this->session->getLocalUserId()) {
584 if (in_array($mode, [self::MODE_FILED, self::MODE_SEARCH, self::MODE_CONTACT_POSTS])) {
587 * "New Item View" on network page or search page results
588 * - just loop through the items and format them minimally for display
591 $tpl = 'search_item.tpl';
595 foreach ($items as $item) {
596 if (in_array($item['uri-id'], $uriids)) {
600 $uriids[] = $item['uri-id'];
602 if (!$this->item->isVisibleActivity($item)) {
606 if (in_array($item['author-id'], $blocklist)) {
612 // prevent private email from leaking.
613 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
617 $profile_name = $item['author-name'];
618 if (!empty($item['author-link']) && empty($item['author-name'])) {
619 $profile_name = $item['author-link'];
622 $tags = Tag::populateFromItem($item);
624 $author = ['uid' => 0, 'id' => $item['author-id'], 'network' => $item['author-network'], 'url' => $item['author-link']];
625 $profile_link = Contact::magicLinkByContact($author);
628 if (strpos($profile_link, 'contact/redir/') === 0) {
629 $sparkle = ' sparkle';
632 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
633 Hook::callAll('render_location', $locate);
634 $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
636 $this->item->localize($item);
637 if ($mode === self::MODE_FILED) {
644 'dropping' => $dropping,
645 'pagedrop' => $page_dropping,
646 'select' => $this->l10n->t('Select'),
647 'delete' => $this->l10n->t('Delete'),
657 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
658 unset($likebuttons['dislike']);
661 $body_html = ItemModel::prepareBody($item, true, $preview);
663 [$categories, $folders] = $this->item->determineCategoriesTerms($item, $this->session->getLocalUserId());
665 if (!empty($item['title'])) {
666 $title = $item['title'];
667 } elseif (!empty($item['content-warning']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'disable_cw', false)) {
668 $title = ucfirst($item['content-warning']);
673 if (!empty($item['featured'])) {
674 $pinned = $this->l10n->t('Pinned item');
681 'id' => ($preview ? 'P0' : $item['id']),
682 'guid' => ($preview ? 'Q0' : $item['guid']),
683 'commented' => $item['commented'],
684 'received' => $item['received'],
685 'created_date' => $item['created'],
686 'uriid' => $item['uri-id'],
687 'network' => $item['network'],
688 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
689 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
690 'linktitle' => $this->l10n->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
691 'profile_url' => $profile_link,
692 'item_photo_menu_html' => $this->item->photoMenu($item, $formSecurityToken),
693 'name' => $profile_name,
694 'sparkle' => $sparkle,
696 'thumb' => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
698 'body_html' => $body_html,
699 'tags' => $tags['tags'],
700 'hashtags' => $tags['hashtags'],
701 'mentions' => $tags['mentions'],
702 'implicit_mentions' => $tags['implicit_mentions'],
703 'txt_cats' => $this->l10n->t('Categories:'),
704 'txt_folders' => $this->l10n->t('Filed under:'),
705 'has_cats' => ((count($categories)) ? 'true' : ''),
706 'has_folders' => ((count($folders)) ? 'true' : ''),
707 'categories' => $categories,
708 'folders' => $folders,
709 'text' => strip_tags($body_html),
710 'localtime' => DateTimeFormat::local($item['created'], 'r'),
711 'utc' => DateTimeFormat::utc($item['created'], 'c'),
712 'ago' => (($item['app']) ? $this->l10n->t('%s from %s', Temporal::getRelativeDate($item['created']), $item['app']) : Temporal::getRelativeDate($item['created'])),
713 'location_html' => $location_html,
717 'owner_photo' => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
718 'plink' => ItemModel::getPlink($item),
721 'isstarred' => 'unstarred',
724 'vote' => $likebuttons,
726 'dislike_html ' => '',
727 'comment_html' => '',
728 'conv' => ($preview ? '' : ['href' => 'display/' . $item['guid'], 'title' => $this->l10n->t('View in context')]),
729 'previewing' => $previewing,
730 'wait' => $this->l10n->t('Please wait'),
734 $arr = ['item' => $item, 'output' => $tmp_item];
735 Hook::callAll('display_item', $arr);
737 $threads[$threadsid]['id'] = $item['id'];
738 $threads[$threadsid]['network'] = $item['network'];
739 $threads[$threadsid]['items'] = [$arr['output']];
743 $page_template = Renderer::getMarkupTemplate("threaded_conversation.tpl");
745 $conv = new Thread($mode, $preview, $writable);
748 * get all the topmost parents
749 * this shouldn't be needed, as we should have only them in our array
750 * But for now, this array respects the old style, just in case
752 foreach ($items as $item) {
753 if (in_array($item['author-id'], $blocklist)) {
757 // Can we put this after the visibility check?
758 $this->builtinActivityPuller($item, $conv_responses);
760 // Only add what is visible
761 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
765 if (!$this->item->isVisibleActivity($item)) {
769 /// @todo Check if this call is needed or not
770 $arr = ['item' => $item];
771 Hook::callAll('display_item', $arr);
773 $item['pagedrop'] = $page_dropping;
775 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
776 $item_object = new PostObject($item);
777 $conv->addParent($item_object);
781 $threads = $conv->getTemplateData($conv_responses, $formSecurityToken);
783 $this->logger->info('[ERROR] conversation : Failed to get template data.');
789 $o = Renderer::replaceMacros($page_template, [
790 '$baseurl' => $this->baseURL,
791 '$return_path' => $this->args->getQueryString(),
792 '$live_update' => $live_update_div,
793 '$remove' => $this->l10n->t('remove'),
795 '$update' => $update,
796 '$threads' => $threads,
797 '$dropping' => ($page_dropping ? $this->l10n->t('Delete Selected Items') : false),
800 $this->profiler->stopRecording();
804 private function getBlocklist(): array
806 if (!$this->session->getLocalUserId()) {
810 $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get($this->session->getLocalUserId(), 'system', 'blocked') ?? '');
811 if (empty($str_blocked)) {
817 foreach (explode(',', $str_blocked) as $entry) {
818 $cid = Contact::getIdForURL(trim($entry), 0, false);
828 * Adds some information (Causer, post reason, direction) to the fetched post row.
830 * @param array $row Post row
831 * @param array $activity Contact data of the resharer
832 * @param array $thr_parent Thread parent row
834 * @return array items with parents and comments
836 private function addRowInformation(array $row, array $activity, array $thr_parent): array
838 $this->profiler->startRecording('rendering');
840 if (!$row['writable']) {
841 $row['writable'] = in_array($row['network'], Protocol::FEDERATED);
844 if (!empty($activity)) {
845 if (($row['gravity'] == ItemModel::GRAVITY_PARENT)) {
846 $row['post-reason'] = ItemModel::PR_ANNOUNCEMENT;
848 $row = array_merge($row, $activity);
849 $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
851 $row['causer-link'] = $contact['url'];
852 $row['causer-avatar'] = $contact['thumb'];
853 $row['causer-name'] = $contact['name'];
854 } elseif (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
855 ($row['author-id'] == $activity['causer-id'])) {
860 switch ($row['post-reason']) {
861 case ItemModel::PR_TO:
862 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'to')];
864 case ItemModel::PR_CC:
865 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'cc')];
867 case ItemModel::PR_BTO:
868 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bto')];
870 case ItemModel::PR_BCC:
871 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bcc')];
873 case ItemModel::PR_FOLLOWER:
874 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])];
876 case ItemModel::PR_TAG:
877 $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')];
879 case ItemModel::PR_ANNOUNCEMENT:
880 if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) {
881 $row['owner-id'] = $row['causer-id'];
882 $row['owner-link'] = $row['causer-link'];
883 $row['owner-avatar'] = $row['causer-avatar'];
884 $row['owner-name'] = $row['causer-name'];
887 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT]) && !empty($row['causer-id'])) {
888 $causer = ['uid' => 0, 'id' => $row['causer-id'], 'network' => $row['causer-network'], 'url' => $row['causer-link']];
890 $row['reshared'] = $this->l10n->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>');
892 $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Reshared') : $this->l10n->t('Reshared by %s <%s>', $row['causer-name'], $row['causer-link']))];
894 case ItemModel::PR_COMMENT:
895 $row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])];
897 case ItemModel::PR_STORED:
898 $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')];
900 case ItemModel::PR_GLOBAL:
901 $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')];
903 case ItemModel::PR_RELAY:
904 $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Sent via an relay server') : $this->l10n->t('Sent via the relay server %s <%s>', $row['causer-name'], $row['causer-link']))];
906 case ItemModel::PR_FETCHED:
907 $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Fetched') : $this->l10n->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))];
909 case ItemModel::PR_COMPLETION:
910 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')];
912 case ItemModel::PR_DIRECT:
913 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')];
915 case ItemModel::PR_ACTIVITY:
916 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')];
918 case ItemModel::PR_DISTRIBUTE:
919 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')];
921 case ItemModel::PR_PUSHED:
922 $row['direction'] = ['direction' => 1, 'title' => $this->l10n->t('Pushed to us')];
926 $row['thr-parent-row'] = $thr_parent;
928 $this->profiler->stopRecording();
933 * Add comments to top level entries that had been fetched before
935 * The system will fetch the comments for the local user whenever possible.
936 * This behaviour is currently needed to allow commenting on Friendica posts.
938 * @param array $parents Parent items
939 * @param bool $block_authors
942 * @param string $mode
943 * @return array items with parents and comments
944 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
946 private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode): array
948 $this->profiler->startRecording('rendering');
949 if (count($parents) > 1) {
950 $max_comments = $this->config->get('system', 'max_comments', 100);
952 $max_comments = $this->config->get('system', 'max_display_comments', 1000);
957 $commentcounter = [];
958 $activitycounter = [];
960 foreach ($parents as $parent) {
961 if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == ItemModel::GRAVITY_ACTIVITY)) {
962 $uriid = $parent['thr-parent-id'];
963 if (!empty($parent['author-id'])) {
964 $activities[$uriid] = ['causer-id' => $parent['author-id']];
965 foreach (['commented', 'received', 'created'] as $orderfields) {
966 if (!empty($parent[$orderfields])) {
967 $activities[$uriid][$orderfields] = $parent[$orderfields];
972 $uriid = $parent['uri-id'];
976 $commentcounter[$uriid] = 0;
977 $activitycounter[$uriid] = 0;
980 $condition = ['parent-uri-id' => $uriids];
981 if ($block_authors) {
982 $condition['author-hidden'] = false;
985 if ($this->config->get('system', 'emoji_activities')) {
986 $emojis = $this->getEmojis($uriids);
987 $condition = DBA::mergeConditions($condition, ["(`gravity` != ? OR `origin`)", ItemModel::GRAVITY_ACTIVITY]);
990 $condition = DBA::mergeConditions($condition,
991 ["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]);
993 $condition = DBA::mergeConditions($condition,
994 ["`visible` AND NOT `deleted` AND NOT `author-blocked` AND NOT `owner-blocked`
995 AND ((NOT `contact-pending` AND (`contact-rel` IN (?, ?))) OR `self` OR `contact-uid` = ?)",
996 Contact::SHARING, Contact::FRIEND, 0]);
998 $thread_parents = Post::select(['uri-id', 'causer-id'], $condition, ['order' => ['uri-id' => false, 'uid']]);
1002 while ($row = Post::fetch($thread_parents)) {
1003 $thr_parent[$row['uri-id']] = $row;
1005 DBA::close($thread_parents);
1007 $params = ['order' => ['uri-id' => true, 'uid' => true]];
1009 $thread_items = Post::select(array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
1012 $quote_uri_ids = [];
1015 while ($row = Post::fetch($thread_items)) {
1016 if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
1020 if (($mode != self::MODE_CONTACTS) && !$row['origin']) {
1021 $row['featured'] = false;
1024 if ($max_comments > 0) {
1025 if (($row['gravity'] == ItemModel::GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
1028 if (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) {
1033 $authors[] = $row['author-id'];
1034 $authors[] = $row['owner-id'];
1036 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT])) {
1037 $quote_uri_ids[$row['uri-id']] = [
1038 'uri-id' => $row['uri-id'],
1039 'uri' => $row['uri'],
1040 'parent-uri-id' => $row['parent-uri-id'],
1041 'parent-uri' => $row['parent-uri'],
1045 $items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? [], $thr_parent[$row['thr-parent-id']] ?? []);
1048 DBA::close($thread_items);
1050 $quotes = Post::select(array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), ['quote-uri-id' => array_column($quote_uri_ids, 'uri-id'), 'body' => '', 'uid' => 0]);
1051 while ($quote = Post::fetch($quotes)) {
1055 $row['verb'] = $row['body'] = $row['raw-body'] = Activity::ANNOUNCE;
1056 $row['gravity'] = ItemModel::GRAVITY_ACTIVITY;
1057 $row['object-type'] = Activity\ObjectType::NOTE;
1058 $row['parent-uri'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri'];
1059 $row['parent-uri-id'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri-id'];
1060 $row['thr-parent'] = $quote_uri_ids[$quote['quote-uri-id']]['uri'];
1061 $row['thr-parent-id'] = $quote_uri_ids[$quote['quote-uri-id']]['uri-id'];
1063 $authors[] = $row['author-id'];
1064 $authors[] = $row['owner-id'];
1066 $items[$row['uri-id']] = $this->addRowInformation($row, [], []);
1068 DBA::close($quotes);
1070 $authors = array_unique($authors);
1075 if (!empty($authors)) {
1076 $usercontacts = DBA::select('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $uid, 'cid' => $authors]);
1077 while ($usercontact = DBA::fetch($usercontacts)) {
1078 if ($usercontact['blocked']) {
1079 $blocks[] = $usercontact['cid'];
1081 if ($usercontact['ignored']) {
1082 $ignores[] = $usercontact['cid'];
1084 if ($usercontact['collapsed']) {
1085 $collapses[] = $usercontact['cid'];
1088 DBA::close($usercontacts);
1091 foreach ($items as $key => $row) {
1092 $items[$key]['emojis'] = $emojis[$key] ?? [];
1094 $always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]);
1096 $items[$key]['user-blocked-author'] = !$always_display && in_array($row['author-id'], $blocks);
1097 $items[$key]['user-ignored-author'] = !$always_display && in_array($row['author-id'], $ignores);
1098 $items[$key]['user-blocked-owner'] = !$always_display && in_array($row['owner-id'], $blocks);
1099 $items[$key]['user-ignored-owner'] = !$always_display && in_array($row['owner-id'], $ignores);
1100 $items[$key]['user-collapsed-author'] = !$always_display && in_array($row['author-id'], $collapses);
1101 $items[$key]['user-collapsed-owner'] = !$always_display && in_array($row['owner-id'], $collapses);
1103 if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
1104 (in_array($row['author-id'], $blocks) || in_array($row['owner-id'], $blocks) || in_array($row['author-id'], $ignores) || in_array($row['owner-id'], $ignores))) {
1105 unset($items[$key]);
1109 $items = $this->convSort($items, $order);
1111 $this->profiler->stopRecording();
1116 * Fetch emoji reaction from the conversation
1118 * @param array $uriids
1121 private function getEmojis(array $uriids): array
1124 Activity::LIKE => '👍',
1125 Activity::DISLIKE => '👎',
1126 Activity::ATTEND => '✔️',
1127 Activity::ATTENDMAYBE => '❓',
1128 Activity::ATTENDNO => '❌',
1129 Activity::ANNOUNCE => '♻',
1130 Activity::VIEW => '📺',
1133 $index_list = array_values($activity_emoji);
1134 $verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT]);
1136 $condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => ItemModel::GRAVITY_ACTIVITY, 'verb' => $verbs], ["NOT `deleted`"]);
1137 $separator = chr(255) . chr(255) . chr(255);
1139 $sql = "SELECT `thr-parent-id`, `body`, `verb`, COUNT(*) AS `total`, GROUP_CONCAT(REPLACE(`author-name`, '" . $separator . "', ' ') SEPARATOR '". $separator ."' LIMIT 50) AS `title` FROM `post-view` WHERE " . array_shift($condition) . " GROUP BY `thr-parent-id`, `verb`, `body`";
1143 $rows = DBA::p($sql, $condition);
1144 while ($row = DBA::fetch($rows)) {
1145 $row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb'];
1146 $emoji = $row['body'] ?: $activity_emoji[$row['verb']];
1147 if (!isset($index_list[$emoji])) {
1148 $index_list[] = $emoji;
1150 $index = array_search($emoji, $index_list);
1152 $emojis[$row['thr-parent-id']][$index]['emoji'] = $emoji;
1153 $emojis[$row['thr-parent-id']][$index]['verb'] = $row['verb'];
1154 $emojis[$row['thr-parent-id']][$index]['total'] = ($emojis[$row['thr-parent-id']][$index]['total'] ?? 0) + $row['total'];
1155 $emojis[$row['thr-parent-id']][$index]['title'] = array_unique(array_merge($emojis[$row['thr-parent-id']][$index]['title'] ?? [], explode($separator, $row['title'])));
1163 * Plucks the children of the given parent from a given item list.
1165 * @param array $item_list
1166 * @param array $parent
1167 * @param bool $recursive
1170 private function getItemChildren(array &$item_list, array $parent, bool $recursive = true): array
1172 $this->profiler->startRecording('rendering');
1174 foreach ($item_list as $i => $item) {
1175 if ($item['gravity'] != ItemModel::GRAVITY_PARENT) {
1177 // Fallback to parent-uri if thr-parent is not set
1178 $thr_parent = $item['thr-parent-id'];
1179 if ($thr_parent == '') {
1180 $thr_parent = $item['parent-uri-id'];
1183 if ($thr_parent == $parent['uri-id']) {
1184 $item['children'] = $this->getItemChildren($item_list, $item);
1186 $children[] = $item;
1187 unset($item_list[$i]);
1189 } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
1190 $children[] = $item;
1191 unset($item_list[$i]);
1195 $this->profiler->stopRecording();
1200 * Recursively sorts a tree-like item array
1202 * @param array $items
1205 private function sortItemChildren(array $items): array
1207 $this->profiler->startRecording('rendering');
1209 usort($result, [$this, 'sortThrReceivedRev']);
1210 foreach ($result as $k => $i) {
1211 if (isset($result[$k]['children'])) {
1212 $result[$k]['children'] = $this->sortItemChildren($result[$k]['children']);
1215 $this->profiler->stopRecording();
1220 * Recursively add all children items at the top level of a list
1222 * @param array $children List of items to append
1223 * @param array $item_list
1225 private function addChildrenToList(array $children, array &$item_list)
1227 foreach ($children as $child) {
1228 $item_list[] = $child;
1229 if (isset($child['children'])) {
1230 $this->addChildrenToList($child['children'], $item_list);
1236 * Selectively flattens a tree-like item structure to prevent threading stairs
1238 * This recursive function takes the item tree structure created by conv_sort() and
1239 * flatten the extraneous depth levels when people reply sequentially, removing the
1240 * stairs effect in threaded conversations limiting the available content width.
1242 * The basic principle is the following: if a post item has only one reply and is
1243 * the last reply of its parent, then the reply is moved to the parent.
1245 * This process is rendered somewhat more complicated because items can be either
1246 * replies or likes, and these don't factor at all in the reply count/last reply.
1248 * @param array $parent A tree-like array of items
1251 private function smartFlattenConversation(array $parent): array
1253 $this->profiler->startRecording('rendering');
1254 if (!isset($parent['children']) || count($parent['children']) == 0) {
1255 $this->profiler->stopRecording();
1259 // We use a for loop to ensure we process the newly-moved items
1260 for ($i = 0; $i < count($parent['children']); $i++) {
1261 $child = $parent['children'][$i];
1263 if (isset($child['children']) && count($child['children'])) {
1264 // This helps counting only the regular posts
1265 $count_post_closure = function ($var) {
1266 $this->profiler->stopRecording();
1267 return $var['verb'] === Activity::POST;
1270 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1272 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1274 // If there's only one child's children post and this is the last child post
1275 if ($child_post_count == 1 && $remaining_post_count == 1) {
1277 // Searches the post item in the children
1279 while ($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
1283 $moved_item = $child['children'][$j];
1284 unset($parent['children'][$i]['children'][$j]);
1285 $parent['children'][] = $moved_item;
1287 $parent['children'][$i] = $this->smartFlattenConversation($child);
1292 $this->profiler->stopRecording();
1297 * Expands a flat list of items into corresponding tree-like conversation structures.
1299 * sort the top-level posts either on "received" or "commented", and finally
1300 * append all the items at the top level (???)
1302 * @param array $item_list A list of items belonging to one or more conversations
1303 * @param string $order Either on "received" or "commented"
1305 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1307 private function convSort(array $item_list, string $order): array
1309 $this->profiler->startRecording('rendering');
1312 if (!(is_array($item_list) && count($item_list))) {
1313 $this->profiler->stopRecording();
1317 $blocklist = $this->getBlocklist();
1321 // Dedupes the item list on the uri to prevent infinite loops
1322 foreach ($item_list as $item) {
1323 if (in_array($item['author-id'], $blocklist)) {
1327 $item_array[$item['uri-id']] = $item;
1330 // Extract the top level items
1331 foreach ($item_array as $item) {
1332 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
1337 if (stristr($order, 'pinned_received')) {
1338 usort($parents, [$this, 'sortThrFeaturedReceived']);
1339 } elseif (stristr($order, 'pinned_commented')) {
1340 usort($parents, [$this, 'sortThrFeaturedCommented']);
1341 } elseif (stristr($order, 'received')) {
1342 usort($parents, [$this, 'sortThrReceived']);
1343 } elseif (stristr($order, 'commented')) {
1344 usort($parents, [$this, 'sortThrCommented']);
1345 } elseif (stristr($order, 'created')) {
1346 usort($parents, [$this, 'sortThrCreated']);
1350 * Plucks children from the item_array, second pass collects eventual orphan
1351 * items and add them as children of their top-level post.
1353 foreach ($parents as $i => $parent) {
1354 $parents[$i]['children'] = array_merge($this->getItemChildren($item_array, $parent, true),
1355 $this->getItemChildren($item_array, $parent, false));
1358 foreach ($parents as $i => $parent) {
1359 $parents[$i]['children'] = $this->sortItemChildren($parents[$i]['children']);
1362 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'no_smart_threading', 0)) {
1363 foreach ($parents as $i => $parent) {
1364 $parents[$i] = $this->smartFlattenConversation($parent);
1368 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1369 /// However, this apparently ensures responses (likes, attendance) display (?!)
1370 foreach ($parents as $parent) {
1371 if (count($parent['children'])) {
1372 $this->addChildrenToList($parent['children'], $parents);
1376 $this->profiler->stopRecording();
1381 * usort() callback to sort item arrays by featured and the received key
1387 private function sortThrFeaturedReceived(array $a, array $b): int
1389 if ($b['featured'] && !$a['featured']) {
1391 } elseif (!$b['featured'] && $a['featured']) {
1395 return strcmp($b['received'], $a['received']);
1399 * usort() callback to sort item arrays by featured and the received key
1405 private function sortThrFeaturedCommented(array $a, array $b): int
1407 if ($b['featured'] && !$a['featured']) {
1409 } elseif (!$b['featured'] && $a['featured']) {
1413 return strcmp($b['commented'], $a['commented']);
1417 * usort() callback to sort item arrays by the received key
1423 private function sortThrReceived(array $a, array $b): int
1425 return strcmp($b['received'], $a['received']);
1429 * usort() callback to reverse sort item arrays by the received key
1435 private function sortThrReceivedRev(array $a, array $b): int
1437 return strcmp($a['received'], $b['received']);
1441 * usort() callback to sort item arrays by the commented key
1447 private function sortThrCommented(array $a, array $b): int
1449 return strcmp($b['commented'], $a['commented']);
1453 * usort() callback to sort item arrays by the created key
1459 private function sortThrCreated(array $a, array $b): int
1461 return strcmp($b['created'], $a['created']);