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\Network\HTTPException\InternalServerErrorException;
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'],
158 'alias' => $activity['author-alias'],
160 $url = Contact::magicLinkByContact($author);
161 if (strpos($url, 'contact/redir/') === 0) {
162 $sparkle = ' class="sparkle" ';
165 $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
167 if (empty($activity['thr-parent-id'])) {
168 $activity['thr-parent-id'] = $activity['parent-uri-id'];
171 // Skip when the causer of the parent is the same as the author of the announce
172 if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id']) && ($thread_parent['causer-id'] == $activity['author-id'])) {
176 if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
177 $conv_responses[$mode][$activity['thr-parent-id']] = [
181 } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
182 // only list each unique author once
186 if ($this->session->getPublicContactId() == $activity['author-id']) {
187 $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
190 $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
192 // there can only be one activity verb per item so if we found anything, we can stop looking
199 * Returns the liker phrase based on a list of likers
201 * @param string $verb the activity verb
202 * @param array $likers a list of likers
204 * @return string the liker phrase
206 * @throws InternalServerErrorException in case either the verb is invalid or the list of likers is empty
208 private function getLikerPhrase(string $verb, array $likers): string
210 $total = count($likers);
213 throw new InternalServerErrorException(sprintf('There has to be at least one Liker for verb "%s"', $verb));
214 } else if ($total === 1) {
215 $likerString = $likers[0];
217 if ($total < $this->config->get('system', 'max_likers')) {
218 $likerString = implode(', ', array_slice($likers, 0, -1));
219 $likerString .= ' ' . $this->l10n->t('and') . ' ' . $likers[count($likers) - 1];
221 $likerString = implode(', ', array_slice($likers, 0, $this->config->get('system', 'max_likers') - 1));
222 $likerString .= ' ' . $this->l10n->t('and %d other people', $total - $this->config->get('system', 'max_likers'));
228 return $this->l10n->tt('%2$s likes this.', '%2$s like this.', $total, $likerString);
230 return $this->l10n->tt('%2$s doesn\'t like this.', '%2$s don\'t like this.', $total, $likerString);
232 return $this->l10n->tt('%2$s attends.', '%2$s attend.', $total, $likerString);
234 return $this->l10n->tt('%2$s doesn\'t attend.', '%2$s don\'t attend.', $total, $likerString);
236 return $this->l10n->tt('%2$s attends maybe.', '%2$s attend maybe.', $total, $likerString);
238 return $this->l10n->tt('%2$s reshared this.', '%2$s reshared this.', $total, $likerString);
240 throw new InternalServerErrorException(sprintf('Unknown verb "%s"', $verb));
245 * Format the activity text for an item/photo/video
247 * @param array $links = array of pre-linked names of actors
248 * @param string $verb = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
249 * @param int $id = item id
250 * @return string formatted text
251 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
253 public function formatActivity(array $links, string $verb, int $id): string
255 $this->profiler->startRecording('rendering');
258 $phrase = $this->getLikerPhrase($verb, $links);
259 $total = count($links);
262 $spanatts = "class=\"btn btn-link fakelink\" onclick=\"openClose('{$verb}list-$id');\"";
263 $explikers = $phrase;
267 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> likes this', '<button type="button" %2$s>%1$d people</button> like this', $total, $spanatts);
270 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> doesn\'t like this', '<button type="button" %2$s>%1$d peiple</button> don\'t like this', $total, $spanatts);
273 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> attends', '<button type="button" %2$s>%1$d people</button> attend', $total, $spanatts);
276 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> doesn\'t attend', '<button type="button" %2$s>%1$d people</button> don\'t attend', $total, $spanatts);
279 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> attends maybe', '<button type="button" %2$s>%1$d people</button> attend maybe', $total, $spanatts);
282 $phrase = $this->l10n->tt('<button type="button" %2$s>%1$d person</button> reshared this', '<button type="button" %2$s>%1$d people</button> reshared this', $total, $spanatts);
286 $expanded .= "\t" . '<p class="wall-item-' . $verb . '-expanded" id="' . $verb . 'list-' . $id . '" style="display: none;" >' . $explikers . '</p>';
289 $output = Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
290 '$phrase' => $phrase,
294 $output .= $expanded;
296 $this->profiler->stopRecording();
300 public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string
302 $user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
303 if (empty($user['uid'])) {
307 $this->profiler->startRecording('rendering');
310 $x['allow_location'] = $x['allow_location'] ?? $user['allow_location'];
311 $x['default_location'] = $x['default_location'] ?? $user['default-location'];
312 $x['nickname'] = $x['nickname'] ?? $user['nickname'];
313 $x['lockstate'] = $x['lockstate'] ?? ACL::getLockstateForUserId($user['uid']) ? 'lock' : 'unlock';
314 $x['acl'] = $x['acl'] ?? ACL::getFullSelectorHTML($this->page, $user['uid'], true);
315 $x['bang'] = $x['bang'] ?? '';
316 $x['visitor'] = $x['visitor'] ?? 'block';
317 $x['is_owner'] = $x['is_owner'] ?? true;
318 $x['profile_uid'] = $x['profile_uid'] ?? $this->session->getLocalUserId();
321 $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
323 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
324 $this->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
325 '$newpost' => 'true',
326 '$baseurl' => $this->baseURL,
327 '$geotag' => $geotag,
328 '$nickname' => $x['nickname'],
329 '$ispublic' => $this->l10n->t('Visible to <strong>everybody</strong>'),
330 '$linkurl' => $this->l10n->t('Please enter a image/video/audio/webpage URL:'),
331 '$term' => $this->l10n->t('Tag term:'),
332 '$fileas' => $this->l10n->t('Save to Folder:'),
333 '$whereareu' => $this->l10n->t('Where are you right now?'),
334 '$delitems' => $this->l10n->t("Delete item\x28s\x29?"),
335 '$is_mobile' => $this->mode->isMobile(),
339 Hook::callAll('jot_tool', $jotplugins);
341 if ($this->config->get('system', 'set_creation_date')) {
342 $created_at = Temporal::getDateTimeField(
343 new \DateTime(DBA::NULL_DATETIME),
344 new \DateTime('now'),
346 $this->l10n->t('Created at'),
353 $tpl = Renderer::getMarkupTemplate('jot.tpl');
355 $o .= Renderer::replaceMacros($tpl, [
356 '$new_post' => $this->l10n->t('New Post'),
357 '$return_path' => $this->args->getQueryString(),
359 '$share' => ($x['button'] ?? '') ?: $this->l10n->t('Share'),
360 '$loading' => $this->l10n->t('Loading...'),
361 '$upload' => $this->l10n->t('Upload photo'),
362 '$shortupload' => $this->l10n->t('upload photo'),
363 '$attach' => $this->l10n->t('Attach file'),
364 '$shortattach' => $this->l10n->t('attach file'),
365 '$edbold' => $this->l10n->t('Bold'),
366 '$editalic' => $this->l10n->t('Italic'),
367 '$eduline' => $this->l10n->t('Underline'),
368 '$edquote' => $this->l10n->t('Quote'),
369 '$edemojis' => $this->l10n->t('Add emojis'),
370 '$contentwarn' => $this->l10n->t('Content Warning'),
371 '$edcode' => $this->l10n->t('Code'),
372 '$edimg' => $this->l10n->t('Image'),
373 '$edurl' => $this->l10n->t('Link'),
374 '$edattach' => $this->l10n->t('Link or Media'),
375 '$edvideo' => $this->l10n->t('Video'),
376 '$setloc' => $this->l10n->t('Set your location'),
377 '$shortsetloc' => $this->l10n->t('set location'),
378 '$noloc' => $this->l10n->t('Clear browser location'),
379 '$shortnoloc' => $this->l10n->t('clear location'),
380 '$title' => $x['title'] ?? '',
381 '$placeholdertitle' => $this->l10n->t('Set title'),
382 '$category' => $x['category'] ?? '',
383 '$placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), 'categories') ? $this->l10n->t("Categories \x28comma-separated list\x29") : '',
384 '$scheduled_at' => Temporal::getDateTimeField(
386 new \DateTime('now + 6 months'),
388 $this->l10n->t('Scheduled at'),
391 '$created_at' => $created_at,
392 '$wait' => $this->l10n->t('Please wait'),
393 '$permset' => $this->l10n->t('Permission settings'),
394 '$shortpermset' => $this->l10n->t('Permissions'),
395 '$wall' => $notes_cid ? 0 : 1,
396 '$posttype' => $notes_cid ? ItemModel::PT_PERSONAL_NOTE : ItemModel::PT_ARTICLE,
397 '$content' => $x['content'] ?? '',
398 '$post_id' => $x['post_id'] ?? '',
399 '$baseurl' => $this->baseURL,
400 '$defloc' => $x['default_location'],
401 '$visitor' => $x['visitor'],
402 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
403 '$public' => $this->l10n->t('Public post'),
404 '$lockstate' => $x['lockstate'],
405 '$bang' => $x['bang'],
406 '$profile_uid' => $x['profile_uid'],
407 '$preview' => $this->l10n->t('Preview'),
408 '$jotplugins' => $jotplugins,
409 '$notes_cid' => $notes_cid,
410 '$cancel' => $this->l10n->t('Cancel'),
411 '$rand_num' => Crypto::randomDigits(12),
413 // ACL permissions box
416 //jot nav tab (used in some themes)
417 '$message' => $this->l10n->t('Message'),
418 '$browser' => $this->l10n->t('Browser'),
420 '$compose_link_title' => $this->l10n->t('Open Compose page'),
421 '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
425 if ($popup == true) {
426 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
429 $this->profiler->stopRecording();
434 * "Render" a conversation or list of items for HTML display.
435 * There are two major forms of display:
436 * - Sequential or unthreaded ("New Item View" or search results)
437 * - conversation view
438 * The $mode parameter decides between the various renderings and also
439 * figures out how to determine page owner and other contextual items
440 * that are based on unique features of the calling module.
441 * @param array $items An array of Posts
442 * @param string $mode One of self::MODE_*
443 * @param bool $update Asynchronous update rendering
444 * @param bool $preview Post preview (no actual database record)
445 * @param string $order Either "received" or "commented"
448 * @throws ImagickException
449 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
451 public function render(array $items, string $mode, bool $update = false, bool $preview = false, string $order = 'commented', int $uid = 0): string
453 $this->profiler->startRecording('rendering');
455 $this->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
456 $this->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
457 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
458 $this->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
460 $live_update_div = '';
462 if ($mode === self::MODE_NETWORK) {
463 $items = $this->addChildren($items, false, $order, $uid, $mode);
466 * The special div is needed for liveUpdate to kick in for this page.
467 * We only launch liveUpdate if you aren't filtering in some incompatible
468 * way and also you aren't writing a comment (discovered in javascript).
470 $live_update_div = '<div id="live-network"></div>' . "\r\n"
471 . "<script> var profile_uid = " . $_SESSION['uid']
472 . "; var netargs = '" . substr($this->args->getCommand(), 8)
474 . (!empty($_GET['contactid']) ? '&contactid=' . rawurlencode($_GET['contactid']) : '')
475 . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
476 . (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
477 . (!empty($_GET['order']) ? '&order=' . rawurlencode($_GET['order']) : '')
478 . (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
479 . (!empty($_GET['liked']) ? '&liked=' . rawurlencode($_GET['liked']) : '')
480 . (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
481 . (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
482 . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
483 . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
484 . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
486 . "'; </script>\r\n";
488 } elseif ($mode === self::MODE_PROFILE) {
489 $items = $this->addChildren($items, false, $order, $uid, $mode);
492 $tab = !empty($_GET['tab']) ? trim($_GET['tab']) : 'posts';
494 if ($tab === 'posts') {
496 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
497 * because browser prefetching might change it on us. We have to deliver it with the page.
500 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
501 . "<script> var profile_uid = " . $uid
502 . "; var netargs = '?f='; </script>\r\n";
505 } elseif ($mode === self::MODE_NOTES) {
506 $items = $this->addChildren($items, false, $order, $this->session->getLocalUserId(), $mode);
509 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
510 . "<script> var profile_uid = " . $this->session->getLocalUserId()
511 . "; var netargs = '?f='; </script>\r\n";
513 } elseif ($mode === self::MODE_DISPLAY) {
514 $items = $this->addChildren($items, false, $order, $uid, $mode);
517 $live_update_div = '<div id="live-display"></div>' . "\r\n"
518 . "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
521 } elseif ($mode === self::MODE_COMMUNITY) {
522 $items = $this->addChildren($items, true, $order, $uid, $mode);
525 $live_update_div = '<div id="live-community"></div>' . "\r\n"
526 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
528 . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
529 . (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
530 . "'; </script>\r\n";
532 } elseif ($mode === self::MODE_CONTACTS) {
533 $items = $this->addChildren($items, false, $order, $uid, $mode);
536 $live_update_div = '<div id="live-contact"></div>' . "\r\n"
537 . "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 8)
538 . "?f='; </script>\r\n";
540 } elseif ($mode === self::MODE_SEARCH) {
541 $live_update_div = '<div id="live-search"></div>' . "\r\n";
544 $page_dropping = $this->session->getLocalUserId() && $this->session->getLocalUserId() == $uid && $mode != self::MODE_SEARCH;
547 $_SESSION['return_path'] = $this->args->getQueryString();
550 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
551 Hook::callAll('conversation_start', $cb);
553 $items = $cb['items'];
555 $formSecurityToken = BaseModule::getFormSecurityToken('contact_action');
557 $threads = $this->getThreadList($items, $mode, $preview, $page_dropping, $formSecurityToken);
559 if (in_array($mode, [self::MODE_FILED, self::MODE_SEARCH, self::MODE_CONTACT_POSTS])) {
560 $page_template = Renderer::getMarkupTemplate('conversation.tpl');
562 $page_template = Renderer::getMarkupTemplate('threaded_conversation.tpl');
565 $o = Renderer::replaceMacros($page_template, [
566 '$baseurl' => $this->baseURL,
567 '$return_path' => $this->args->getQueryString(),
568 '$live_update' => $live_update_div,
569 '$remove' => $this->l10n->t('remove'),
571 '$update' => $update,
572 '$threads' => $threads,
573 '$dropping' => ($page_dropping ? $this->l10n->t('Delete Selected Items') : false),
576 $this->profiler->stopRecording();
581 * @param array $items
582 * @param string $mode One of self::MODE_*
583 * @param bool $preview
584 * @param bool $pagedrop Whether to enable the user to select the thread for deletion
585 * @param string $formSecurityToken A 'contact_action' form security token
587 * @throws InternalServerErrorException
588 * @throws \ImagickException
590 public function getThreadList(array $items, string $mode, bool $preview, bool $pagedrop, string $formSecurityToken): array
592 if (in_array($mode, [self::MODE_FILED, self::MODE_SEARCH, self::MODE_CONTACT_POSTS])) {
593 $threads = $this->getContextLessThreadList($items, $mode, $preview, $pagedrop, $formSecurityToken);
604 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
605 unset($conv_responses['dislike']);
608 if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
611 $writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
614 if (!$this->session->getLocalUserId()) {
619 $conv = new Thread($mode, $preview, $writable);
622 * get all the topmost parents
623 * this shouldn't be needed, as we should have only them in our array
624 * But for now, this array respects the old style, just in case
626 foreach ($items as $item) {
627 if (in_array($item['author-id'], $this->getBlocklist())) {
631 // Can we put this after the visibility check?
632 $this->builtinActivityPuller($item, $conv_responses);
634 // Only add what is visible
635 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
639 if (!$this->item->isVisibleActivity($item)) {
643 /// @todo Check if this call is needed or not
644 $arr = ['item' => $item];
645 Hook::callAll('display_item', $arr);
647 $item['pagedrop'] = $pagedrop;
649 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
650 $item_object = new PostObject($item);
651 $conv->addParent($item_object);
655 $threads = $conv->getTemplateData($conv_responses, $formSecurityToken);
657 $this->logger->info('[ERROR] conversation : Failed to get template data.');
665 private function getBlocklist(): array
667 if (!$this->session->getLocalUserId()) {
671 $str_blocked = str_replace(["\n", "\r"], ",", $this->pConfig->get($this->session->getLocalUserId(), 'system', 'blocked') ?? '');
672 if (empty($str_blocked)) {
678 foreach (explode(',', $str_blocked) as $entry) {
679 $cid = Contact::getIdForURL(trim($entry), 0, false);
689 * Adds some information (Causer, post reason, direction) to the fetched post row.
691 * @param array $row Post row
692 * @param array $activity Contact data of the resharer
693 * @param array $thr_parent Thread parent row
695 * @return array items with parents and comments
697 private function addRowInformation(array $row, array $activity, array $thr_parent): array
699 $this->profiler->startRecording('rendering');
701 if (!$row['writable']) {
702 $row['writable'] = in_array($row['network'], Protocol::FEDERATED);
705 if (!empty($activity)) {
706 if (($row['gravity'] == ItemModel::GRAVITY_PARENT)) {
707 $row['post-reason'] = ItemModel::PR_ANNOUNCEMENT;
709 $row = array_merge($row, $activity);
710 $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
712 $row['causer-link'] = $contact['url'];
713 $row['causer-avatar'] = $contact['thumb'];
714 $row['causer-name'] = $contact['name'];
715 } elseif (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
716 ($row['author-id'] == $activity['causer-id'])
722 switch ($row['post-reason']) {
723 case ItemModel::PR_TO:
724 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'to')];
726 case ItemModel::PR_CC:
727 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'cc')];
729 case ItemModel::PR_BTO:
730 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bto')];
732 case ItemModel::PR_BCC:
733 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'bcc')];
735 case ItemModel::PR_AUDIENCE:
736 $row['direction'] = ['direction' => 7, 'title' => $this->l10n->t('You had been addressed (%s).', 'audience')];
738 case ItemModel::PR_FOLLOWER:
739 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['causer-name'] ?: $row['author-name'])];
741 case ItemModel::PR_TAG:
742 $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')];
744 case ItemModel::PR_ANNOUNCEMENT:
745 if (!empty($row['causer-id']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'display_resharer')) {
746 $row['owner-id'] = $row['causer-id'];
747 $row['owner-link'] = $row['causer-link'];
748 $row['owner-avatar'] = $row['causer-avatar'];
749 $row['owner-name'] = $row['causer-name'];
752 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT]) && !empty($row['causer-id'])) {
755 'id' => $row['causer-id'],
756 'network' => $row['causer-network'],
757 'url' => $row['causer-link'],
758 'alias' => $row['causer-alias'],
761 $row['reshared'] = $this->l10n->t('%s reshared this.', '<a href="' . htmlentities(Contact::magicLinkByContact($causer)) . '">' . htmlentities($row['causer-name']) . '</a>');
763 $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']))];
765 case ItemModel::PR_COMMENT:
766 $row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])];
768 case ItemModel::PR_STORED:
769 $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')];
771 case ItemModel::PR_GLOBAL:
772 $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')];
774 case ItemModel::PR_RELAY:
775 $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']))];
777 case ItemModel::PR_FETCHED:
778 $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']))];
780 case ItemModel::PR_COMPLETION:
781 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')];
783 case ItemModel::PR_DIRECT:
784 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')];
786 case ItemModel::PR_ACTIVITY:
787 $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')];
789 case ItemModel::PR_DISTRIBUTE:
790 $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')];
792 case ItemModel::PR_PUSHED:
793 $row['direction'] = ['direction' => 1, 'title' => $this->l10n->t('Pushed to us')];
797 $row['thr-parent-row'] = $thr_parent;
799 $this->profiler->stopRecording();
804 * Add comments to top level entries that had been fetched before
806 * The system will fetch the comments for the local user whenever possible.
807 * This behaviour is currently needed to allow commenting on Friendica posts.
809 * @param array $parents Parent items
810 * @param bool $block_authors
813 * @param string $mode
814 * @return array items with parents and comments
815 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
817 private function addChildren(array $parents, bool $block_authors, string $order, int $uid, string $mode): array
819 $this->profiler->startRecording('rendering');
820 if (count($parents) > 1) {
821 $max_comments = $this->config->get('system', 'max_comments', 100);
823 $max_comments = $this->config->get('system', 'max_display_comments', 1000);
828 $commentcounter = [];
829 $activitycounter = [];
831 foreach ($parents as $parent) {
832 if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == ItemModel::GRAVITY_ACTIVITY)) {
833 $uriid = $parent['thr-parent-id'];
834 if (!empty($parent['author-id'])) {
835 $activities[$uriid] = ['causer-id' => $parent['author-id']];
836 foreach (['commented', 'received', 'created'] as $orderfields) {
837 if (!empty($parent[$orderfields])) {
838 $activities[$uriid][$orderfields] = $parent[$orderfields];
843 $uriid = $parent['uri-id'];
847 $commentcounter[$uriid] = 0;
848 $activitycounter[$uriid] = 0;
851 $condition = ['parent-uri-id' => $uriids];
852 if ($block_authors) {
853 $condition['author-hidden'] = false;
856 if ($this->config->get('system', 'emoji_activities')) {
857 $emojis = $this->getEmojis($uriids);
858 $condition = DBA::mergeConditions($condition, ["(`gravity` != ? OR `origin`)", ItemModel::GRAVITY_ACTIVITY]);
861 $condition = DBA::mergeConditions(
863 ["`uid` IN (0, ?) AND (NOT `vid` IN (?, ?, ?) OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)]
866 $condition = DBA::mergeConditions($condition, ["(`uid` != ? OR `private` != ?)", 0, ItemModel::PRIVATE]);
868 $condition = DBA::mergeConditions(
871 "`visible` AND NOT `deleted` AND NOT `author-blocked` AND NOT `owner-blocked`
872 AND ((NOT `contact-pending` AND (`contact-rel` IN (?, ?))) OR `self` OR `contact-uid` = ?)",
873 Contact::SHARING, Contact::FRIEND, 0
877 $thread_parents = Post::select(['uri-id', 'causer-id'], $condition, ['order' => ['uri-id' => false, 'uid']]);
881 while ($row = Post::fetch($thread_parents)) {
882 $thr_parent[$row['uri-id']] = $row;
884 DBA::close($thread_parents);
886 $params = ['order' => ['uri-id' => true, 'uid' => true]];
888 $thread_items = Post::select(array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
894 while ($row = Post::fetch($thread_items)) {
895 if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
899 if (($mode != self::MODE_CONTACTS) && !$row['origin']) {
900 $row['featured'] = false;
903 if ($max_comments > 0) {
904 if (($row['gravity'] == ItemModel::GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
907 if (($row['gravity'] == ItemModel::GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) {
912 $authors[] = $row['author-id'];
913 $authors[] = $row['owner-id'];
915 if (in_array($row['gravity'], [ItemModel::GRAVITY_PARENT, ItemModel::GRAVITY_COMMENT])) {
916 $quote_uri_ids[$row['uri-id']] = [
917 'uri-id' => $row['uri-id'],
918 'uri' => $row['uri'],
919 'parent-uri-id' => $row['parent-uri-id'],
920 'parent-uri' => $row['parent-uri'],
924 $items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? [], $thr_parent[$row['thr-parent-id']] ?? []);
927 DBA::close($thread_items);
929 $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]);
930 while ($quote = Post::fetch($quotes)) {
934 $row['verb'] = $row['body'] = $row['raw-body'] = Activity::ANNOUNCE;
935 $row['gravity'] = ItemModel::GRAVITY_ACTIVITY;
936 $row['object-type'] = Activity\ObjectType::NOTE;
937 $row['parent-uri'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri'];
938 $row['parent-uri-id'] = $quote_uri_ids[$quote['quote-uri-id']]['parent-uri-id'];
939 $row['thr-parent'] = $quote_uri_ids[$quote['quote-uri-id']]['uri'];
940 $row['thr-parent-id'] = $quote_uri_ids[$quote['quote-uri-id']]['uri-id'];
942 $authors[] = $row['author-id'];
943 $authors[] = $row['owner-id'];
945 $items[$row['uri-id']] = $this->addRowInformation($row, [], []);
949 $authors = array_unique($authors);
954 if (!empty($authors)) {
955 $usercontacts = DBA::select('user-contact', ['cid', 'blocked', 'ignored', 'collapsed'], ['uid' => $uid, 'cid' => $authors]);
956 while ($usercontact = DBA::fetch($usercontacts)) {
957 if ($usercontact['blocked']) {
958 $blocks[] = $usercontact['cid'];
960 if ($usercontact['ignored']) {
961 $ignores[] = $usercontact['cid'];
963 if ($usercontact['collapsed']) {
964 $collapses[] = $usercontact['cid'];
967 DBA::close($usercontacts);
970 foreach ($items as $key => $row) {
971 $items[$key]['emojis'] = $emojis[$key] ?? [];
973 $always_display = in_array($mode, [self::MODE_CONTACTS, self::MODE_CONTACT_POSTS]);
975 $items[$key]['user-blocked-author'] = !$always_display && in_array($row['author-id'], $blocks);
976 $items[$key]['user-ignored-author'] = !$always_display && in_array($row['author-id'], $ignores);
977 $items[$key]['user-blocked-owner'] = !$always_display && in_array($row['owner-id'], $blocks);
978 $items[$key]['user-ignored-owner'] = !$always_display && in_array($row['owner-id'], $ignores);
979 $items[$key]['user-collapsed-author'] = !$always_display && in_array($row['author-id'], $collapses);
980 $items[$key]['user-collapsed-owner'] = !$always_display && in_array($row['owner-id'], $collapses);
983 in_array($mode, [self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
984 (in_array($row['author-id'], $blocks) || in_array($row['owner-id'], $blocks) || in_array($row['author-id'], $ignores) || in_array($row['owner-id'], $ignores))
990 $items = $this->convSort($items, $order);
992 $this->profiler->stopRecording();
997 * Fetch emoji reaction from the conversation
999 * @param array $uriids
1002 private function getEmojis(array $uriids): array
1005 Activity::LIKE => '👍',
1006 Activity::DISLIKE => '👎',
1007 Activity::ATTEND => '✔️',
1008 Activity::ATTENDMAYBE => '❓',
1009 Activity::ATTENDNO => '❌',
1010 Activity::ANNOUNCE => '♻',
1011 Activity::VIEW => '📺',
1014 $index_list = array_values($activity_emoji);
1015 $verbs = array_merge(array_keys($activity_emoji), [Activity::EMOJIREACT]);
1017 $condition = DBA::mergeConditions(['parent-uri-id' => $uriids, 'gravity' => ItemModel::GRAVITY_ACTIVITY, 'verb' => $verbs], ["NOT `deleted`"]);
1018 $separator = chr(255) . chr(255) . chr(255);
1020 $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`";
1024 $rows = DBA::p($sql, $condition);
1025 while ($row = DBA::fetch($rows)) {
1026 $row['verb'] = $row['body'] ? Activity::EMOJIREACT : $row['verb'];
1027 $emoji = $row['body'] ?: $activity_emoji[$row['verb']];
1028 if (!isset($index_list[$emoji])) {
1029 $index_list[] = $emoji;
1031 $index = array_search($emoji, $index_list);
1033 $emojis[$row['thr-parent-id']][$index]['emoji'] = $emoji;
1034 $emojis[$row['thr-parent-id']][$index]['verb'] = $row['verb'];
1035 $emojis[$row['thr-parent-id']][$index]['total'] = ($emojis[$row['thr-parent-id']][$index]['total'] ?? 0) + $row['total'];
1036 $emojis[$row['thr-parent-id']][$index]['title'] = array_unique(array_merge($emojis[$row['thr-parent-id']][$index]['title'] ?? [], explode($separator, $row['title'])));
1044 * Plucks the children of the given parent from a given item list.
1046 * @param array $item_list
1047 * @param array $parent
1048 * @param bool $recursive
1051 private function getItemChildren(array &$item_list, array $parent, bool $recursive = true): array
1053 $this->profiler->startRecording('rendering');
1055 foreach ($item_list as $i => $item) {
1056 if ($item['gravity'] != ItemModel::GRAVITY_PARENT) {
1058 // Fallback to parent-uri if thr-parent is not set
1059 $thr_parent = $item['thr-parent-id'];
1060 if ($thr_parent == '') {
1061 $thr_parent = $item['parent-uri-id'];
1064 if ($thr_parent == $parent['uri-id']) {
1065 $item['children'] = $this->getItemChildren($item_list, $item);
1067 $children[] = $item;
1068 unset($item_list[$i]);
1070 } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
1071 $children[] = $item;
1072 unset($item_list[$i]);
1076 $this->profiler->stopRecording();
1081 * Recursively sorts a tree-like item array
1083 * @param array $items
1086 private function sortItemChildren(array $items): array
1088 $this->profiler->startRecording('rendering');
1090 usort($result, [$this, 'sortThrReceivedRev']);
1091 foreach ($result as $k => $i) {
1092 if (isset($result[$k]['children'])) {
1093 $result[$k]['children'] = $this->sortItemChildren($result[$k]['children']);
1096 $this->profiler->stopRecording();
1101 * Recursively add all children items at the top level of a list
1103 * @param array $children List of items to append
1104 * @param array $item_list
1106 private function addChildrenToList(array $children, array &$item_list)
1108 foreach ($children as $child) {
1109 $item_list[] = $child;
1110 if (isset($child['children'])) {
1111 $this->addChildrenToList($child['children'], $item_list);
1117 * Selectively flattens a tree-like item structure to prevent threading stairs
1119 * This recursive function takes the item tree structure created by conv_sort() and
1120 * flatten the extraneous depth levels when people reply sequentially, removing the
1121 * stairs effect in threaded conversations limiting the available content width.
1123 * The basic principle is the following: if a post item has only one reply and is
1124 * the last reply of its parent, then the reply is moved to the parent.
1126 * This process is rendered somewhat more complicated because items can be either
1127 * replies or likes, and these don't factor at all in the reply count/last reply.
1129 * @param array $parent A tree-like array of items
1132 private function smartFlattenConversation(array $parent): array
1134 $this->profiler->startRecording('rendering');
1135 if (!isset($parent['children']) || count($parent['children']) == 0) {
1136 $this->profiler->stopRecording();
1140 // We use a for loop to ensure we process the newly-moved items
1141 for ($i = 0; $i < count($parent['children']); $i++) {
1142 $child = $parent['children'][$i];
1144 if (isset($child['children']) && count($child['children'])) {
1145 // This helps counting only the regular posts
1146 $count_post_closure = function ($var) {
1147 $this->profiler->stopRecording();
1148 return $var['verb'] === Activity::POST;
1151 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1153 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1155 // If there's only one child's children post and this is the last child post
1156 if ($child_post_count == 1 && $remaining_post_count == 1) {
1158 // Searches the post item in the children
1160 while ($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
1164 $moved_item = $child['children'][$j];
1165 unset($parent['children'][$i]['children'][$j]);
1166 $parent['children'][] = $moved_item;
1168 $parent['children'][$i] = $this->smartFlattenConversation($child);
1173 $this->profiler->stopRecording();
1178 * Expands a flat list of items into corresponding tree-like conversation structures.
1180 * sort the top-level posts either on "received" or "commented", and finally
1181 * append all the items at the top level (???)
1183 * @param array $item_list A list of items belonging to one or more conversations
1184 * @param string $order Either on "received" or "commented"
1186 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1188 private function convSort(array $item_list, string $order): array
1190 $this->profiler->startRecording('rendering');
1193 if (!(is_array($item_list) && count($item_list))) {
1194 $this->profiler->stopRecording();
1198 $blocklist = $this->getBlocklist();
1202 // Dedupes the item list on the uri to prevent infinite loops
1203 foreach ($item_list as $item) {
1204 if (in_array($item['author-id'], $blocklist)) {
1208 $item_array[$item['uri-id']] = $item;
1211 // Extract the top level items
1212 foreach ($item_array as $item) {
1213 if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
1218 if (stristr($order, 'pinned_received')) {
1219 usort($parents, [$this, 'sortThrFeaturedReceived']);
1220 } elseif (stristr($order, 'pinned_commented')) {
1221 usort($parents, [$this, 'sortThrFeaturedCommented']);
1222 } elseif (stristr($order, 'received')) {
1223 usort($parents, [$this, 'sortThrReceived']);
1224 } elseif (stristr($order, 'commented')) {
1225 usort($parents, [$this, 'sortThrCommented']);
1226 } elseif (stristr($order, 'created')) {
1227 usort($parents, [$this, 'sortThrCreated']);
1231 * Plucks children from the item_array, second pass collects eventual orphan
1232 * items and add them as children of their top-level post.
1234 foreach ($parents as $i => $parent) {
1235 $parents[$i]['children'] = array_merge(
1236 $this->getItemChildren($item_array, $parent, true),
1237 $this->getItemChildren($item_array, $parent, false)
1241 foreach ($parents as $i => $parent) {
1242 $parents[$i]['children'] = $this->sortItemChildren($parents[$i]['children']);
1245 if (!$this->pConfig->get($this->session->getLocalUserId(), 'system', 'no_smart_threading', 0)) {
1246 foreach ($parents as $i => $parent) {
1247 $parents[$i] = $this->smartFlattenConversation($parent);
1251 /// @TODO: Stop recursively adding all children back to the top level (!!!)
1252 /// However, this apparently ensures responses (likes, attendance) display (?!)
1253 foreach ($parents as $parent) {
1254 if (count($parent['children'])) {
1255 $this->addChildrenToList($parent['children'], $parents);
1259 $this->profiler->stopRecording();
1264 * usort() callback to sort item arrays by featured and the received key
1270 private function sortThrFeaturedReceived(array $a, array $b): int
1272 if ($b['featured'] && !$a['featured']) {
1274 } elseif (!$b['featured'] && $a['featured']) {
1278 return strcmp($b['received'], $a['received']);
1282 * usort() callback to sort item arrays by featured and the received key
1288 private function sortThrFeaturedCommented(array $a, array $b): int
1290 if ($b['featured'] && !$a['featured']) {
1292 } elseif (!$b['featured'] && $a['featured']) {
1296 return strcmp($b['commented'], $a['commented']);
1300 * usort() callback to sort item arrays by the received key
1306 private function sortThrReceived(array $a, array $b): int
1308 return strcmp($b['received'], $a['received']);
1312 * usort() callback to reverse sort item arrays by the received key
1318 private function sortThrReceivedRev(array $a, array $b): int
1320 return strcmp($a['received'], $b['received']);
1324 * usort() callback to sort item arrays by the commented key
1330 private function sortThrCommented(array $a, array $b): int
1332 return strcmp($b['commented'], $a['commented']);
1336 * usort() callback to sort item arrays by the created key
1342 private function sortThrCreated(array $a, array $b): int
1344 return strcmp($b['created'], $a['created']);
1348 * "New Item View" on network page or search page results
1349 * - just loop through the items and format them minimally for display
1351 * @param array $items
1352 * @param string $mode One of self::MODE_*
1353 * @param bool $preview Whether the display is a preview
1354 * @param bool $pagedrop Whether the user can select the threads for deletion
1355 * @param string $formSecurityToken A 'contact_action' form security token
1357 * @throws InternalServerErrorException
1358 * @throws \ImagickException
1360 public function getContextLessThreadList(array $items, string $mode, bool $preview, bool $pagedrop, string $formSecurityToken): array
1365 foreach ($items as $item) {
1366 if (in_array($item['uri-id'], $uriids)) {
1370 $uriids[] = $item['uri-id'];
1372 if (!$this->item->isVisibleActivity($item)) {
1376 if (in_array($item['author-id'], $this->getBlocklist())) {
1382 // prevent private email from leaking.
1383 if ($item['network'] === Protocol::MAIL && $this->session->getLocalUserId() != $item['uid']) {
1387 $profile_name = $item['author-name'];
1388 if (!empty($item['author-link']) && empty($item['author-name'])) {
1389 $profile_name = $item['author-link'];
1392 $tags = Tag::populateFromItem($item);
1396 'id' => $item['author-id'],
1397 'network' => $item['author-network'],
1398 'url' => $item['author-link'],
1399 'alias' => $item['author-alias'],
1401 $profile_link = Contact::magicLinkByContact($author);
1404 if (strpos($profile_link, 'contact/redir/') === 0) {
1405 $sparkle = ' sparkle';
1408 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
1409 Hook::callAll('render_location', $locate);
1410 $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
1412 $this->item->localize($item);
1413 if ($mode === self::MODE_FILED) {
1420 'dropping' => $dropping,
1421 'pagedrop' => $pagedrop,
1422 'select' => $this->l10n->t('Select'),
1423 'delete' => $this->l10n->t('Delete'),
1433 if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'hide_dislike')) {
1434 unset($likebuttons['dislike']);
1437 $body_html = ItemModel::prepareBody($item, true, $preview);
1439 [$categories, $folders] = $this->item->determineCategoriesTerms($item, $this->session->getLocalUserId());
1441 if (!empty($item['title'])) {
1442 $title = $item['title'];
1443 } elseif (!empty($item['content-warning']) && $this->pConfig->get($this->session->getLocalUserId(), 'system', 'disable_cw', false)) {
1444 $title = ucfirst($item['content-warning']);
1449 if (!empty($item['featured'])) {
1450 $pinned = $this->l10n->t('Pinned item');
1456 'template' => 'search_item.tpl',
1457 'id' => ($preview ? 'P0' : $item['id']),
1458 'guid' => ($preview ? 'Q0' : $item['guid']),
1459 'commented' => $item['commented'],
1460 'received' => $item['received'],
1461 'created_date' => $item['created'],
1462 'uriid' => $item['uri-id'],
1463 'network' => $item['network'],
1464 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
1465 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
1466 'linktitle' => $this->l10n->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
1467 'profile_url' => $profile_link,
1468 'item_photo_menu_html' => $this->item->photoMenu($item, $formSecurityToken),
1469 'name' => $profile_name,
1470 'sparkle' => $sparkle,
1472 'thumb' => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
1474 'body_html' => $body_html,
1475 'tags' => $tags['tags'],
1476 'hashtags' => $tags['hashtags'],
1477 'mentions' => $tags['mentions'],
1478 'implicit_mentions' => $tags['implicit_mentions'],
1479 'txt_cats' => $this->l10n->t('Categories:'),
1480 'txt_folders' => $this->l10n->t('Filed under:'),
1481 'has_cats' => ((count($categories)) ? 'true' : ''),
1482 'has_folders' => ((count($folders)) ? 'true' : ''),
1483 'categories' => $categories,
1484 'folders' => $folders,
1485 'text' => strip_tags($body_html),
1486 'localtime' => DateTimeFormat::local($item['created'], 'r'),
1487 'utc' => DateTimeFormat::utc($item['created'], 'c'),
1488 'ago' => (($item['app']) ? $this->l10n->t('%s from %s', Temporal::getRelativeDate($item['created']), $item['app']) : Temporal::getRelativeDate($item['created'])),
1489 'location_html' => $location_html,
1493 'owner_photo' => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
1494 'plink' => ItemModel::getPlink($item),
1496 'pinned' => $pinned,
1497 'isstarred' => 'unstarred',
1500 'vote' => $likebuttons,
1502 'dislike_html ' => '',
1503 'comment_html' => '',
1504 'conv' => $preview ? '' : ['href' => 'display/' . $item['guid'], 'title' => $this->l10n->t('View in context')],
1505 'previewing' => $preview ? ' preview ' : '',
1506 'wait' => $this->l10n->t('Please wait'),
1507 'thread_level' => 1,
1510 $arr = ['item' => $item, 'output' => $tmp_item];
1511 Hook::callAll('display_item', $arr);
1514 'id' => $item['id'],
1515 'network' => $item['network'],
1516 'items' => [$arr['output']],