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;
38 use Friendica\Model\Contact;
39 use Friendica\Model\Item as ItemModel;
40 use Friendica\Model\Post;
41 use Friendica\Model\Tag;
42 use Friendica\Model\User;
43 use Friendica\Model\Verb;
44 use Friendica\Object\Post as PostObject;
45 use Friendica\Object\Thread;
46 use Friendica\Protocol\Activity;
47 use Friendica\Util\Crypto;
48 use Friendica\Util\DateTimeFormat;
49 use Friendica\Util\Profiler;
50 use Friendica\Util\Strings;
51 use Friendica\Util\Temporal;
52 use Psr\Log\LoggerInterface;
56 const MODE_COMMUNITY = 'community';
57 const MODE_CONTACTS = 'contacts';
58 const MODE_CONTACT_POSTS = 'contact-posts';
59 const MODE_DISPLAY = 'display';
60 const MODE_FILED = 'filed';
61 const MODE_NETWORK = 'network';
62 const MODE_NOTES = 'notes';
63 const MODE_SEARCH = 'search';
64 const MODE_PROFILE = 'profile';
72 /** @var LoggerInterface */
76 /** @var App\Arguments */
78 /** @var IManagePersonalConfigValues */
82 /** @var IManageConfigValues */
90 /** @var IHandleUserSessions */
93 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)
95 $this->activity = $activity;
97 $this->config = $config;
99 $this->baseURL = $baseURL;
100 $this->profiler = $profiler;
101 $this->logger = $logger;
104 $this->pConfig = $pConfig;
107 $this->session = $session;
111 * Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
113 * Increments the count of each matching activity and adds a link to the author as needed.
115 * @param array $activity
116 * @param array &$conv_responses (already created with builtin activity structure)
118 * @throws ImagickException
119 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
121 public function builtinActivityPuller(array $activity, array &$conv_responses)
123 $thread_parent = $activity['thr-parent-row'] ?? [];
125 foreach ($conv_responses as $mode => $v) {
130 $verb = Activity::LIKE;
133 $verb = Activity::DISLIKE;
136 $verb = Activity::ATTEND;
139 $verb = Activity::ATTENDNO;
142 $verb = Activity::ATTENDMAYBE;
145 $verb = Activity::ANNOUNCE;
151 if (!empty($activity['verb']) && $this->activity->match($activity['verb'], $verb) && ($activity['gravity'] != ItemModel::GRAVITY_PARENT)) {
154 'id' => $activity['author-id'],
155 'network' => $activity['author-network'],
156 'url' => $activity['author-link']
158 $url = Contact::magicLinkByContact($author);
159 if (strpos($url, 'contact/redir/') === 0) {
160 $sparkle = ' class="sparkle" ';
163 $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
165 if (empty($activity['thr-parent-id'])) {
166 $activity['thr-parent-id'] = $activity['parent-uri-id'];
169 // Skip when the causer of the parent is the same as the author of the announce
170 if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id']) && ($thread_parent['causer-id'] == $activity['author-id'])) {
174 if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
175 $conv_responses[$mode][$activity['thr-parent-id']] = [
179 } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
180 // only list each unique author once
184 if ($this->session->getPublicContactId() == $activity['author-id']) {
185 $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
188 $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
190 // there can only be one activity verb per item so if we found anything, we can stop looking
197 * Format the activity text for an item/photo/video
199 * @param array $links = array of pre-linked names of actors
200 * @param string $verb = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
201 * @param int $id = item id
202 * @return string formatted text
203 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
205 public function formatActivity(array $links, string $verb, int $id): string
207 $this->profiler->startRecording('rendering');
212 $total = count($links);
216 // Phrase if there is only one liker. In other cases it will be uses for the expanded
217 // list which show all likers
220 $phrase = $this->l10n->t('%s likes this.', $likers);
223 $phrase = $this->l10n->t('%s doesn\'t like this.', $likers);
226 $phrase = $this->l10n->t('%s attends.', $likers);
229 $phrase = $this->l10n->t('%s doesn\'t attend.', $likers);
232 $phrase = $this->l10n->t('%s attends maybe.', $likers);
235 $phrase = $this->l10n->t('%s reshared this.', $likers);
238 } elseif ($total > 1) {
239 if ($total < $this->config->get('system', 'max_likers')) {
240 $likers = implode(', ', array_slice($links, 0, -1));
241 $likers .= ' ' . $this->l10n->t('and') . ' ' . $links[count($links) - 1];
243 $likers = implode(', ', array_slice($links, 0, $this->config->get('system', 'max_likers') - 1));
244 $likers .= ' ' . $this->l10n->t('and %d other people', $total - $this->config->get('system', 'max_likers'));
247 $spanatts = "class=\"btn btn-link fakelink\" onclick=\"openClose('{$verb}list-$id');\"";
252 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> like this', $spanatts, $total);
253 $explikers = $this->l10n->t('%s like this.', $likers);
256 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> don\'t like this', $spanatts, $total);
257 $explikers = $this->l10n->t('%s don\'t like this.', $likers);
260 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> attend', $spanatts, $total);
261 $explikers = $this->l10n->t('%s attend.', $likers);
264 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> don\'t attend', $spanatts, $total);
265 $explikers = $this->l10n->t('%s don\'t attend.', $likers);
268 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> attend maybe', $spanatts, $total);
269 $explikers = $this->l10n->t('%s attend maybe.', $likers);
272 $phrase = $this->l10n->t('<button type="button" %1$s>%2$d people</button> reshared this', $spanatts, $total);
273 $explikers = $this->l10n->t('%s reshared this.', $likers);
277 $expanded .= "\t" . '<p class="wall-item-' . $verb . '-expanded" id="' . $verb . 'list-' . $id . '" style="display: none;" >' . $explikers . '</p>';
280 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
281 '$phrase' => $phrase,
287 $this->profiler->stopRecording();
291 public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string
293 $user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
294 if (empty($user['uid'])) {
298 $this->profiler->startRecording('rendering');
301 $x['allow_location'] = $x['allow_location'] ?? $user['allow_location'];
302 $x['default_location'] = $x['default_location'] ?? $user['default-location'];
303 $x['nickname'] = $x['nickname'] ?? $user['nickname'];
304 $x['lockstate'] = $x['lockstate'] ?? ACL::getLockstateForUserId($user['uid']) ? 'lock' : 'unlock';
305 $x['acl'] = $x['acl'] ?? ACL::getFullSelectorHTML($this->page, $user['uid'], true);
306 $x['bang'] = $x['bang'] ?? '';
307 $x['visitor'] = $x['visitor'] ?? 'block';
308 $x['is_owner'] = $x['is_owner'] ?? true;
309 $x['profile_uid'] = $x['profile_uid'] ?? $this->session->getLocalUserId();
312 $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
314 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
315 $this->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
316 '$newpost' => 'true',
317 '$baseurl' => $this->baseURL,
318 '$geotag' => $geotag,
319 '$nickname' => $x['nickname'],
320 '$ispublic' => $this->l10n->t('Visible to <strong>everybody</strong>'),
321 '$linkurl' => $this->l10n->t('Please enter a image/video/audio/webpage URL:'),
322 '$term' => $this->l10n->t('Tag term:'),
323 '$fileas' => $this->l10n->t('Save to Folder:'),
324 '$whereareu' => $this->l10n->t('Where are you right now?'),
325 '$delitems' => $this->l10n->t("Delete item\x28s\x29?"),
326 '$is_mobile' => $this->mode->isMobile(),
330 Hook::callAll('jot_tool', $jotplugins);
332 if ($this->config->get('system', 'set_creation_date')) {
333 $created_at = Temporal::getDateTimeField(
334 new \DateTime(DBA::NULL_DATETIME),
335 new \DateTime('now'),
337 $this->l10n->t('Created at'),
344 $tpl = Renderer::getMarkupTemplate('jot.tpl');
346 $o .= Renderer::replaceMacros($tpl, [
347 '$new_post' => $this->l10n->t('New Post'),
348 '$return_path' => $this->args->getQueryString(),
350 '$share' => ($x['button'] ?? '') ?: $this->l10n->t('Share'),
351 '$loading' => $this->l10n->t('Loading...'),
352 '$upload' => $this->l10n->t('Upload photo'),
353 '$shortupload' => $this->l10n->t('upload photo'),
354 '$attach' => $this->l10n->t('Attach file'),
355 '$shortattach' => $this->l10n->t('attach file'),
356 '$edbold' => $this->l10n->t('Bold'),
357 '$editalic' => $this->l10n->t('Italic'),
358 '$eduline' => $this->l10n->t('Underline'),
359 '$edquote' => $this->l10n->t('Quote'),
360 '$edcode' => $this->l10n->t('Code'),
361 '$edimg' => $this->l10n->t('Image'),
362 '$edurl' => $this->l10n->t('Link'),
363 '$edattach' => $this->l10n->t('Link or Media'),
364 '$edvideo' => $this->l10n->t('Video'),
365 '$setloc' => $this->l10n->t('Set your location'),
366 '$shortsetloc' => $this->l10n->t('set location'),
367 '$noloc' => $this->l10n->t('Clear browser location'),
368 '$shortnoloc' => $this->l10n->t('clear location'),
369 '$title' => $x['title'] ?? '',
370 '$placeholdertitle' => $this->l10n->t('Set title'),
371 '$category' => $x['category'] ?? '',
372 '$placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
373 '$scheduled_at' => Temporal::getDateTimeField(
375 new \DateTime('now + 6 months'),
377 $this->l10n->t('Scheduled at'),
380 '$created_at' => $created_at,
381 '$wait' => $this->l10n->t('Please wait'),
382 '$permset' => $this->l10n->t('Permission settings'),
383 '$shortpermset' => $this->l10n->t('Permissions'),
384 '$wall' => $notes_cid ? 0 : 1,
385 '$posttype' => $notes_cid ? ItemModel::PT_PERSONAL_NOTE : ItemModel::PT_ARTICLE,
386 '$content' => $x['content'] ?? '',
387 '$post_id' => $x['post_id'] ?? '',
388 '$baseurl' => $this->baseURL,
389 '$defloc' => $x['default_location'],
390 '$visitor' => $x['visitor'],
391 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
392 '$public' => $this->l10n->t('Public post'),
393 '$lockstate' => $x['lockstate'],
394 '$bang' => $x['bang'],
395 '$profile_uid' => $x['profile_uid'],
396 '$preview' => $this->l10n->t('Preview'),
397 '$jotplugins' => $jotplugins,
398 '$notes_cid' => $notes_cid,
399 '$cancel' => $this->l10n->t('Cancel'),
400 '$rand_num' => Crypto::randomDigits(12),
402 // ACL permissions box
405 //jot nav tab (used in some themes)
406 '$message' => $this->l10n->t('Message'),
407 '$browser' => $this->l10n->t('Browser'),
409 '$compose_link_title' => $this->l10n->t('Open Compose page'),
410 '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
414 if ($popup == true) {
415 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
418 $this->profiler->stopRecording();
423 * "Render" a conversation or list of items for HTML display.
424 * There are two major forms of display:
425 * - Sequential or unthreaded ("New Item View" or search results)
426 * - conversation view
427 * The $mode parameter decides between the various renderings and also
428 * figures out how to determine page owner and other contextual items
429 * that are based on unique features of the calling module.
430 * @param array $items
431 * @param string $mode
432 * @param $update @TODO Which type?
433 * @param bool $preview
434 * @param string $order
437 * @throws ImagickException
438 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
440 public function create(array $items, string $mode, $update, bool $preview = false, string $order = 'commented', int $uid = 0): string
442 $this->profiler->startRecording('rendering');
444 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
445 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
446 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
447 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
448 $this->page->registerStylesheet(Theme::getPathForFile('vendor/enyo/dropzone/dist/min/dropzone.min.css'));
450 $live_update_div = '';
452 $blocklist = $this->getBlocklist();
454 $previewing = (($preview) ? ' preview ' : '');
456 if ($mode === self::MODE_NETWORK) {
457 $items = $this->addChildren($items, false, $order, $uid, $mode);
460 * The special div is needed for liveUpdate to kick in for this page.
461 * We only launch liveUpdate if you aren't filtering in some incompatible
462 * way and also you aren't writing a comment (discovered in javascript).
464 $live_update_div = '<div id="live-network"></div>' . "\r\n"
465 . "<script> var profile_uid = " . $_SESSION['uid']
466 . "; var netargs = '" . substr($this->args->getCommand(), 8)
468 . (!empty($_GET['contactid']) ? '&contactid=' . rawurlencode($_GET['contactid']) : '')
469 . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
470 . (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
471 . (!empty($_GET['order']) ? '&order=' . rawurlencode($_GET['order']) : '')
472 . (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
473 . (!empty($_GET['liked']) ? '&liked=' . rawurlencode($_GET['liked']) : '')
474 . (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
475 . (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
476 . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
477 . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
478 . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
480 . "'; </script>\r\n";
482 } elseif ($mode === self::MODE_PROFILE) {
483 $items = $this->addChildren($items, false, $order, $uid, $mode);
486 $tab = !empty($_GET['tab']) ? trim($_GET['tab']) : 'posts';
488 if ($tab === 'posts') {
490 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
491 * because browser prefetching might change it on us. We have to deliver it with the page.
494 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
495 . "<script> var profile_uid = " . $uid
496 . "; var netargs = '?f='; </script>\r\n";
499 } elseif ($mode === self::MODE_NOTES) {
500 $items = $this->addChildren($items, false, $order, $this->session->getLocalUserId(), $mode);
503 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
504 . "<script> var profile_uid = " . $this->session->getLocalUserId()
505 . "; var netargs = '?f='; </script>\r\n";
507 } elseif ($mode === self::MODE_DISPLAY) {
508 $items = $this->addChildren($items, false, $order, $uid, $mode);
511 $live_update_div = '<div id="live-display"></div>' . "\r\n"
512 . "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
515 } elseif ($mode === self::MODE_COMMUNITY) {
516 $items = $this->addChildren($items, true, $order, $uid, $mode);
519 $live_update_div = '<div id="live-community"></div>' . "\r\n"
520 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
522 . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
523 . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
524 . "'; </script>\r\n";
526 } elseif ($mode === self::MODE_CONTACTS) {
527 $items = $this->addChildren($items, false, $order, $uid, $mode);
530 $live_update_div = '<div id="live-contact"></div>' . "\r\n"
531 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
532 ."?f='; </script>\r\n";
534 } elseif ($mode === self::MODE_SEARCH) {
535 $live_update_div = '<div id="live-search"></div>' . "\r\n";
538 $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH;
541 $_SESSION['return_path'] = $this->args->getQueryString();
544 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
545 Hook::callAll('conversation_start', $cb);
547 $items = $cb['items'];
558 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
559 unset($conv_responses['dislike']);
562 // array with html for each thread (parent+comments)
566 $page_template = Renderer::getMarkupTemplate("conversation.tpl");
567 $formSecurityToken = BaseModule::getFormSecurityToken('contact_action');
569 if (!empty($items)) {
570 if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
573 $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
576 if (!$this->session->getLocalUserId()) {
580 if (in_array($mode, [self::MODE_FILED, self::MODE_SEARCH, self::MODE_CONTACT_POSTS])) {
583 * "New Item View" on network page or search page results
584 * - just loop through the items and format them minimally for display
587 $tpl = 'search_item.tpl';
591 foreach ($items as $item) {
592 if (in_array($item['uri-id'], $uriids)) {
596 $uriids[] = $item['uri-id'];
598 if (!$this->item->isVisibleActivity($item)) {
602 if (in_array($item['author-id'], $blocklist)) {
608 // prevent private email from leaking.
609 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
613 $profile_name = $item['author-name'];
614 if (!empty($item['author-link']) && empty($item['author-name'])) {
615 $profile_name = $item['author-link'];
618 $tags = Tag::populateFromItem($item);
620 $author = ['uid' => 0, 'id' => $item['author-id'], 'network' => $item['author-network'], 'url' => $item['author-link']];
621 $profile_link = Contact::magicLinkByContact($author);
624 if (strpos($profile_link, 'contact/redir/') === 0) {
625 $sparkle = ' sparkle';
628 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
629 Hook::callAll('render_location', $locate);
630 $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
632 $this->item->localize($item);
633 if ($mode === self::MODE_FILED) {
640 'dropping' => $dropping,
641 'pagedrop' => $page_dropping,
642 'select' => $this->l10n->t('Select'),
643 'delete' => $this->l10n->t('Delete'),
653 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
654 unset($likebuttons['dislike']);
657 $body_html = ItemModel::prepareBody($item, true, $preview);
659 [$categories, $folders] = $this->item->determineCategoriesTerms($item, $this->session->getLocalUserId());
661 if (!empty($item['title'])) {
662 $title = $item['title'];
663 } elseif (!empty($item['content-warning']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'disable_cw', false)) {
664 $title = ucfirst($item['content-warning']);
669 if (!empty($item['featured'])) {
670 $pinned = $this->l10n->t('Pinned item');
677 'id' => ($preview ? 'P0' : $item['id']),
678 'guid' => ($preview ? 'Q0' : $item['guid']),
679 'commented' => $item['commented'],
680 'received' => $item['received'],
681 'created_date' => $item['created'],
682 'uriid' => $item['uri-id'],
683 'network' => $item['network'],
684 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
685 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
686 'linktitle' => $this->l10n->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
687 'profile_url' => $profile_link,
688 'item_photo_menu_html' => $this->item->photoMenu($item, $formSecurityToken),
689 'name' => $profile_name,
690 'sparkle' => $sparkle,
692 'thumb' => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
694 'body_html' => $body_html,
695 'tags' => $tags['tags'],
696 'hashtags' => $tags['hashtags'],
697 'mentions' => $tags['mentions'],
698 'implicit_mentions' => $tags['implicit_mentions'],
699 'txt_cats' => $this->l10n->t('Categories:'),
700 'txt_folders' => $this->l10n->t('Filed under:'),
701 'has_cats' => ((count($categories)) ? 'true' : ''),
702 'has_folders' => ((count($folders)) ? 'true' : ''),
703 'categories' => $categories,
704 'folders' => $folders,
705 'text' => strip_tags($body_html),
706 'localtime' => DateTimeFormat::local($item['created'], 'r'),
707 'utc' => DateTimeFormat::utc($item['created'], 'c'),
708 'ago' => (($item['app']) ? $this->l10n->t('%s from %s', Temporal::getRelativeDate($item['created']), $item['app']) : Temporal::getRelativeDate($item['created'])),
709 'location_html' => $location_html,
713 'owner_photo' => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
714 'plink' => ItemModel::getPlink($item),
717 'isstarred' => 'unstarred',
720 'vote' => $likebuttons,
722 'dislike_html ' => '',
723 'comment_html' => '',
724 'conv' => ($preview ? '' : ['href' => 'display/' . $item['guid'], 'title' => $this->l10n->t('View in context')]),
725 'previewing' => $previewing,
726 'wait' => $this->l10n->t('Please wait'),
730 $arr = ['item' => $item, 'output' => $tmp_item];
731 Hook::callAll('display_item', $arr);
733 $threads[$threadsid]['id'] = $item['id'];
734 $threads[$threadsid]['network'] = $item['network'];
735 $threads[$threadsid]['items'] = [$arr['output']];
739 $page_template = Renderer::getMarkupTemplate("threaded_conversation.tpl");
741 $conv = new Thread($mode, $preview, $writable);
744 * get all the topmost parents
745 * this shouldn't be needed, as we should have only them in our array
746 * But for now, this array respects the old style, just in case
748 foreach ($items as $item) {
749 if (in_array($item['author-id'], $blocklist)) {
753 // Can we put this after the visibility check?
754 $this->builtinActivityPuller($item, $conv_responses);
756 // Only add what is visible
757 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
761 if (!$this->item->isVisibleActivity($item)) {
765 /// @todo Check if this call is needed or not
766 $arr = ['item' => $item];
767 Hook::callAll('display_item', $arr);
769 $item['pagedrop'] = $page_dropping;
771 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
772 $item_object = new PostObject($item);
773 $conv->addParent($item_object);
777 $threads = $conv->getTemplateData($conv_responses, $formSecurityToken);
779 $this->logger->info('[ERROR] conversation : Failed to get template data.');
785 $o = Renderer::replaceMacros($page_template, [
786 '$baseurl' => $this->baseURL,
787 '$return_path' => $this->args->getQueryString(),
788 '$live_update' => $live_update_div,
789 '$remove' => $this->l10n->t('remove'),
791 '$update' => $update,
792 '$threads' => $threads,
793 '$dropping' => ($page_dropping ? $this->l10n->t('Delete Selected Items') : false),
796 $this->profiler->stopRecording();
800 private function getBlocklist(): array
802 if (!$this->session->getLocalUserId()) {
806 $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get($this->session->getLocalUserId(), 'system', 'blocked') ?? '');
807 if (empty($str_blocked)) {
813 foreach (explode(',', $str_blocked) as $entry) {
814 $cid = Contact::getIdForURL(trim($entry), 0, false);
824 * Adds some information (Causer, post reason, direction) to the fetched post row.
826 * @param array $row Post row
827 * @param array $activity Contact data of the resharer
828 * @param array $thr_parent Thread parent row
830 * @return array items with parents and comments
832 private function addRowInformation(array $row, array $activity, array $thr_parent): array
834 $this->profiler->startRecording('rendering');
836 if (!$row['writable']) {
837 $row['writable'] = in_array($row['network'], Protocol::FEDERATED);
840 if (!empty($activity)) {
841 if (($row['gravity'] == ItemModel::GRAVITY_PARENT)) {
842 $row['post-reason'] = ItemModel::PR_ANNOUNCEMENT;
844 $row = array_merge($row, $activity);
845 $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
847 $row['causer-link'] = $contact['url'];
848 $row['causer-avatar'] = $contact['thumb'];
849 $row['causer-name'] = $contact['name'];
850 } elseif (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
851 ($row['author-id'] == $activity['causer-id'])) {
856 switch ($row['post-reason']) {
857 case ItemModel::PR_TO:
858 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'to')];
860 case ItemModel::PR_CC:
861 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'cc')];
863 case ItemModel::PR_BTO:
864 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bto')];
866 case ItemModel::PR_BCC:
867 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bcc')];
869 case ItemModel::PR_FOLLOWER:
870 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])];
872 case ItemModel::PR_TAG:
873 $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')];
875 case ItemModel::PR_ANNOUNCEMENT:
876 if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) {
877 $row['owner-id'] = $row['causer-id'];
878 $row['owner-link'] = $row['causer-link'];
879 $row['owner-avatar'] = $row['causer-avatar'];
880 $row['owner-name'] = $row['causer-name'];
883 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT]) && !empty($row['causer-id'])) {
884 $causer = ['uid' => 0, 'id' => $row['causer-id'], 'network' => $row['causer-network'], 'url' => $row['causer-link']];
886 $row['reshared'] = $this->l10n->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>');
888 $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']))];
890 case ItemModel::PR_COMMENT:
891 $row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])];
893 case ItemModel::PR_STORED:
894 $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')];
896 case ItemModel::PR_GLOBAL:
897 $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')];
899 case ItemModel::PR_RELAY:
900 $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']))];
902 case ItemModel::PR_FETCHED:
903 $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']))];
905 case ItemModel::PR_COMPLETION:
906 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')];
908 case ItemModel::PR_DIRECT:
909 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')];
911 case ItemModel::PR_ACTIVITY:
912 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')];
914 case ItemModel::PR_DISTRIBUTE:
915 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')];
917 case ItemModel::PR_PUSHED:
918 $row['direction'] = ['direction' => 1, 'title' => $this->l10n->t('Pushed to us')];
922 $row['thr-parent-row'] = $thr_parent;
924 $this->profiler->stopRecording();
929 * Add comments to top level entries that had been fetched before
931 * The system will fetch the comments for the local user whenever possible.
932 * This behaviour is currently needed to allow commenting on Friendica posts.
934 * @param array $parents Parent items
935 * @param bool $block_authors
938 * @param string $mode
939 * @return array items with parents and comments
940 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
942 private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode): array
944 $this->profiler->startRecording('rendering');
945 if (count($parents) > 1) {
946 $max_comments = $this->config->get('system', 'max_comments', 100);
948 $max_comments = $this->config->get('system', 'max_display_comments', 1000);
953 $commentcounter = [];
954 $activitycounter = [];
956 foreach ($parents as $parent) {
957 if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == ItemModel::GRAVITY_ACTIVITY)) {
958 $uriid = $parent['thr-parent-id'];
959 if (!empty($parent['author-id'])) {
960 $activities[$uriid] = ['causer-id' => $parent['author-id']];
961 foreach (['commented', 'received', 'created'] as $orderfields) {
962 if (!empty($parent[$orderfields])) {
963 $activities[$uriid][$orderfields] = $parent[$orderfields];
968 $uriid = $parent['uri-id'];
972 $commentcounter[$uriid] = 0;
973 $activitycounter[$uriid] = 0;
976 $condition = ['parent-uri-id' => $uriids];
977 if ($block_authors) {
978 $condition['author-hidden'] = false;
981 if ($this->config->get('system', 'emoji_activities')) {
982 $emojis = $this->getEmojis($uriids);
983 $condition = DBA::mergeConditions($condition, ["(`gravity` != ? OR `origin`)", ItemModel::GRAVITY_ACTIVITY]);
986 $condition = DBA::mergeConditions($condition,
987 ["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]);
989 $condition = DBA::mergeConditions($condition,
990 ["`visible` AND NOT `deleted` AND NOT `author-blocked` AND NOT `owner-blocked`
991 AND ((NOT `contact-pending` AND (`contact-rel` IN (?, ?))) OR `self` OR `contact-uid` = ?)",
992 Contact::SHARING, Contact::FRIEND, 0]);
994 $thread_parents = Post::select(['uri-id', 'causer-id'], $condition, ['order' => ['uri-id' => false, 'uid']]);
998 while ($row = Post::fetch($thread_parents)) {
999 $thr_parent[$row['uri-id']] = $row;
1001 DBA::close($thread_parents);
1003 $params = ['order' => ['uri-id' => true, 'uid' => true]];
1005 $thread_items = Post::select(array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
1008 $quote_uri_ids = [];
1011 while ($row = Post::fetch($thread_items)) {
1012 if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
1016 if (($mode != self::MODE_CONTACTS) && !$row['origin']) {
1017 $row['featured'] = false;
1020 if ($max_comments > 0) {
1021 if (($row['gravity'] == ItemModel::GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
1024 if (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) {
1029 $authors[] = $row['author-id'];
1030 $authors[] = $row['owner-id'];
1032 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT])) {
1033 $quote_uri_ids[$row['uri-id']] = [
1034 'uri-id' => $row['uri-id'],
1035 'uri' => $row['uri'],
1036 'parent-uri-id' => $row['parent-uri-id'],
1037 'parent-uri' => $row['parent-uri'],
1041 $items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? [], $thr_parent[$row['thr-parent-id']] ?? []);
1044 DBA::close($thread_items);
1046 $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]);
1047 while ($quote = Post::fetch($quotes)) {
1051 $row['verb'] = $row['body'] = $row['raw-body'] = Activity::ANNOUNCE;
1052 $row['gravity'] = ItemModel::GRAVITY_ACTIVITY;
1053 $row['object-type'] = Activity\ObjectType::NOTE;
1054 $row['parent-uri'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri'];
1055 $row['parent-uri-id'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri-id'];
1056 $row['thr-parent'] = $quote_uri_ids[$quote['quote-uri-id']]['uri'];
1057 $row['thr-parent-id'] = $quote_uri_ids[$quote['quote-uri-id']]['uri-id'];
1059 $authors[] = $row['author-id'];
1060 $authors[] = $row['owner-id'];
1062 $items[$row['uri-id']] = $this->addRowInformation($row, [], []);
1064 DBA::close($quotes);
1066 $authors = array_unique($authors);
1071 if (!empty($authors)) {
1072 $usercontacts = DBA::select('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $uid, 'cid' => $authors]);
1073 while ($usercontact = DBA::fetch($usercontacts)) {
1074 if ($usercontact['blocked']) {
1075 $blocks[] = $usercontact['cid'];
1077 if ($usercontact['ignored']) {
1078 $ignores[] = $usercontact['cid'];
1080 if ($usercontact['collapsed']) {
1081 $collapses[] = $usercontact['cid'];
1084 DBA::close($usercontacts);
1087 foreach ($items as $key => $row) {
1088 $items[$key]['emojis'] = $emojis[$key] ?? [];
1090 $always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]);
1092 $items[$key]['user-blocked-author'] = !$always_display && in_array($row['author-id'], $blocks);
1093 $items[$key]['user-ignored-author'] = !$always_display && in_array($row['author-id'], $ignores);
1094 $items[$key]['user-blocked-owner'] = !$always_display && in_array($row['owner-id'], $blocks);
1095 $items[$key]['user-ignored-owner'] = !$always_display && in_array($row['owner-id'], $ignores);
1096 $items[$key]['user-collapsed-author'] = !$always_display && in_array($row['author-id'], $collapses);
1097 $items[$key]['user-collapsed-owner'] = !$always_display && in_array($row['owner-id'], $collapses);
1099 if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
1100 (in_array($row['author-id'], $blocks) || in_array($row['owner-id'], $blocks) || in_array($row['author-id'], $ignores) || in_array($row['owner-id'], $ignores))) {
1101 unset($items[$key]);
1105 $items = $this->convSort($items, $order);
1107 $this->profiler->stopRecording();
1112 * Fetch emoji reaction from the conversation
1114 * @param array $uriids
1117 private function getEmojis(array $uriids): array
1120 Activity::LIKE => '👍',
1121 Activity::DISLIKE => '👎',
1122 Activity::ATTEND => '✔️',
1123 Activity::ATTENDMAYBE => '❓',
1124 Activity::ATTENDNO => '❌',
1125 Activity::ANNOUNCE => '♻',
1126 Activity::VIEW => '📺',
1129 $index_list = array_values($activity_emoji);
1130 $verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT]);
1132 $condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => ItemModel::GRAVITY_ACTIVITY, 'verb' => $verbs], ["NOT `deleted`"]);
1133 $separator = chr(255) . chr(255) . chr(255);
1135 $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`";
1139 $rows = DBA::p($sql, $condition);
1140 while ($row = DBA::fetch($rows)) {
1141 $row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb'];
1142 $emoji = $row['body'] ?: $activity_emoji[$row['verb']];
1143 if (!isset($index_list[$emoji])) {
1144 $index_list[] = $emoji;
1146 $index = array_search($emoji, $index_list);
1148 $emojis[$row['thr-parent-id']][$index]['emoji'] = $emoji;
1149 $emojis[$row['thr-parent-id']][$index]['verb'] = $row['verb'];
1150 $emojis[$row['thr-parent-id']][$index]['total'] = ($emojis[$row['thr-parent-id']][$index]['total'] ?? 0) + $row['total'];
1151 $emojis[$row['thr-parent-id']][$index]['title'] = array_unique(array_merge($emojis[$row['thr-parent-id']][$index]['title'] ?? [], explode($separator, $row['title'])));
1159 * Plucks the children of the given parent from a given item list.
1161 * @param array $item_list
1162 * @param array $parent
1163 * @param bool $recursive
1166 private function getItemChildren(array &$item_list, array $parent, bool $recursive = true): array
1168 $this->profiler->startRecording('rendering');
1170 foreach ($item_list as $i => $item) {
1171 if ($item['gravity'] != ItemModel::GRAVITY_PARENT) {
1173 // Fallback to parent-uri if thr-parent is not set
1174 $thr_parent = $item['thr-parent-id'];
1175 if ($thr_parent == '') {
1176 $thr_parent = $item['parent-uri-id'];
1179 if ($thr_parent == $parent['uri-id']) {
1180 $item['children'] = $this->getItemChildren($item_list, $item);
1182 $children[] = $item;
1183 unset($item_list[$i]);
1185 } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
1186 $children[] = $item;
1187 unset($item_list[$i]);
1191 $this->profiler->stopRecording();
1196 * Recursively sorts a tree-like item array
1198 * @param array $items
1201 private function sortItemChildren(array $items): array
1203 $this->profiler->startRecording('rendering');
1205 usort($result, [$this, 'sortThrReceivedRev']);
1206 foreach ($result as $k => $i) {
1207 if (isset($result[$k]['children'])) {
1208 $result[$k]['children'] = $this->sortItemChildren($result[$k]['children']);
1211 $this->profiler->stopRecording();
1216 * Recursively add all children items at the top level of a list
1218 * @param array $children List of items to append
1219 * @param array $item_list
1221 private function addChildrenToList(array $children, array &$item_list)
1223 foreach ($children as $child) {
1224 $item_list[] = $child;
1225 if (isset($child['children'])) {
1226 $this->addChildrenToList($child['children'], $item_list);
1232 * Selectively flattens a tree-like item structure to prevent threading stairs
1234 * This recursive function takes the item tree structure created by conv_sort() and
1235 * flatten the extraneous depth levels when people reply sequentially, removing the
1236 * stairs effect in threaded conversations limiting the available content width.
1238 * The basic principle is the following: if a post item has only one reply and is
1239 * the last reply of its parent, then the reply is moved to the parent.
1241 * This process is rendered somewhat more complicated because items can be either
1242 * replies or likes, and these don't factor at all in the reply count/last reply.
1244 * @param array $parent A tree-like array of items
1247 private function smartFlattenConversation(array $parent): array
1249 $this->profiler->startRecording('rendering');
1250 if (!isset($parent['children']) || count($parent['children']) == 0) {
1251 $this->profiler->stopRecording();
1255 // We use a for loop to ensure we process the newly-moved items
1256 for ($i = 0; $i < count($parent['children']); $i++) {
1257 $child = $parent['children'][$i];
1259 if (isset($child['children']) && count($child['children'])) {
1260 // This helps counting only the regular posts
1261 $count_post_closure = function ($var) {
1262 $this->profiler->stopRecording();
1263 return $var['verb'] === Activity::POST;
1266 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1268 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1270 // If there's only one child's children post and this is the last child post
1271 if ($child_post_count == 1 && $remaining_post_count == 1) {
1273 // Searches the post item in the children
1275 while ($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
1279 $moved_item = $child['children'][$j];
1280 unset($parent['children'][$i]['children'][$j]);
1281 $parent['children'][] = $moved_item;
1283 $parent['children'][$i] = $this->smartFlattenConversation($child);
1288 $this->profiler->stopRecording();
1293 * Expands a flat list of items into corresponding tree-like conversation structures.
1295 * sort the top-level posts either on "received" or "commented", and finally
1296 * append all the items at the top level (???)
1298 * @param array $item_list A list of items belonging to one or more conversations
1299 * @param string $order Either on "received" or "commented"
1301 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1303 private function convSort(array $item_list, string $order): array
1305 $this->profiler->startRecording('rendering');
1308 if (!(is_array($item_list) && count($item_list))) {
1309 $this->profiler->stopRecording();
1313 $blocklist = $this->getBlocklist();
1317 // Dedupes the item list on the uri to prevent infinite loops
1318 foreach ($item_list as $item) {
1319 if (in_array($item['author-id'], $blocklist)) {
1323 $item_array[$item['uri-id']] = $item;
1326 // Extract the top level items
1327 foreach ($item_array as $item) {
1328 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
1333 if (stristr($order, 'pinned_received')) {
1334 usort($parents, [$this, 'sortThrFeaturedReceived']);
1335 } elseif (stristr($order, 'pinned_commented')) {
1336 usort($parents, [$this, 'sortThrFeaturedCommented']);
1337 } elseif (stristr($order, 'received')) {
1338 usort($parents, [$this, 'sortThrReceived']);
1339 } elseif (stristr($order, 'commented')) {
1340 usort($parents, [$this, 'sortThrCommented']);
1341 } elseif (stristr($order, 'created')) {
1342 usort($parents, [$this, 'sortThrCreated']);
1346 * Plucks children from the item_array, second pass collects eventual orphan
1347 * items and add them as children of their top-level post.
1349 foreach ($parents as $i => $parent) {
1350 $parents[$i]['children'] = array_merge($this->getItemChildren($item_array, $parent, true),
1351 $this->getItemChildren($item_array, $parent, false));
1354 foreach ($parents as $i => $parent) {
1355 $parents[$i]['children'] = $this->sortItemChildren($parents[$i]['children']);
1358 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'no_smart_threading', 0)) {
1359 foreach ($parents as $i => $parent) {
1360 $parents[$i] = $this->smartFlattenConversation($parent);
1364 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1365 /// However, this apparently ensures responses (likes, attendance) display (?!)
1366 foreach ($parents as $parent) {
1367 if (count($parent['children'])) {
1368 $this->addChildrenToList($parent['children'], $parents);
1372 $this->profiler->stopRecording();
1377 * usort() callback to sort item arrays by featured and the received key
1383 private function sortThrFeaturedReceived(array $a, array $b): int
1385 if ($b['featured'] && !$a['featured']) {
1387 } elseif (!$b['featured'] && $a['featured']) {
1391 return strcmp($b['received'], $a['received']);
1395 * usort() callback to sort item arrays by featured and the received key
1401 private function sortThrFeaturedCommented(array $a, array $b): int
1403 if ($b['featured'] && !$a['featured']) {
1405 } elseif (!$b['featured'] && $a['featured']) {
1409 return strcmp($b['commented'], $a['commented']);
1413 * usort() callback to sort item arrays by the received key
1419 private function sortThrReceived(array $a, array $b): int
1421 return strcmp($b['received'], $a['received']);
1425 * usort() callback to reverse sort item arrays by the received key
1431 private function sortThrReceivedRev(array $a, array $b): int
1433 return strcmp($a['received'], $b['received']);
1437 * usort() callback to sort item arrays by the commented key
1443 private function sortThrCommented(array $a, array $b): int
1445 return strcmp($b['commented'], $a['commented']);
1449 * usort() callback to sort item arrays by the created key
1455 private function sortThrCreated(array $a, array $b): int
1457 return strcmp($b['created'], $a['created']);