3 * @copyright Copyright (C) 2020, Friendica
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/>.
23 use Friendica\Content\ContactSelector;
24 use Friendica\Content\Feature;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Hook;
28 use Friendica\Core\Logger;
29 use Friendica\Core\Protocol;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
32 use Friendica\Database\DBA;
34 use Friendica\Model\Contact;
35 use Friendica\Model\Item;
36 use Friendica\Model\Profile;
37 use Friendica\Model\Term;
38 use Friendica\Object\Post;
39 use Friendica\Object\Thread;
40 use Friendica\Protocol\Activity;
41 use Friendica\Util\Crypto;
42 use Friendica\Util\DateTimeFormat;
43 use Friendica\Util\Proxy as ProxyUtils;
44 use Friendica\Util\Strings;
45 use Friendica\Util\Temporal;
46 use Friendica\Util\XML;
48 function item_extract_images($body) {
55 $img_start = strpos($orig_body, '[img');
56 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
57 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
58 while (($img_st_close !== false) && ($img_end !== false)) {
60 $img_st_close++; // make it point to AFTER the closing bracket
61 $img_end += $img_start;
63 if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
64 // This is an embedded image
66 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
67 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
71 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
74 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
76 if ($orig_body === false) {
77 // in case the body ends on a closing image tag
81 $img_start = strpos($orig_body, '[img');
82 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
83 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
86 $new_body = $new_body . $orig_body;
88 return ['body' => $new_body, 'images' => $saved_image];
91 function item_redir_and_replace_images($body, $images, $cid) {
97 $pos = BBCode::getTagPosition($origbody, 'url', 0);
98 while ($pos !== false && $cnt < 1000) {
100 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
101 $replace = '[url=' . DI::baseUrl() . '/redir/' . $cid
102 . '?url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
104 $newbody .= substr($origbody, 0, $pos['start']['open']);
105 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
106 $origbody = substr($origbody, $pos['end']['close']);
107 if ($origbody === false) {
111 $subject = preg_replace($search, $replace, $subject);
112 $newbody .= $subject;
115 // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
116 $pos = BBCode::getTagPosition($origbody, 'url', 0);
118 $newbody .= $origbody;
121 foreach ($images as $image) {
123 * We're depending on the property of 'foreach' (specified on the PHP website) that
124 * it loops over the array starting from the first element and going sequentially
125 * to the last element.
127 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
134 * Render actions localized
137 * @throws ImagickException
138 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
140 function localize_item(&$item)
142 $extracted = item_extract_images($item['body']);
143 if ($extracted['images']) {
144 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
148 heluecht 2018-06-19: from my point of view this whole code part is useless.
149 It just renders the body message of technical posts (Like, dislike, ...).
150 But: The body isn't visible at all. So we do this stuff just because we can.
151 Even if these messages were visible, this would only mean that something went wrong.
152 During the further steps of the database restructuring I would like to address this issue.
155 $activity = DI::activity();
157 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
158 if ($activity->match($item['verb'], Activity::LIKE)
159 || $activity->match($item['verb'], Activity::DISLIKE)
160 || $activity->match($item['verb'], Activity::ATTEND)
161 || $activity->match($item['verb'], Activity::ATTENDNO)
162 || $activity->match($item['verb'], Activity::ATTENDMAYBE)) {
164 $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
165 $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
166 if (!DBA::isResult($obj)) {
170 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
171 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
173 switch ($obj['verb']) {
175 switch ($obj['object-type']) {
176 case Activity\ObjectType::EVENT:
177 $post_type = DI::l10n()->t('event');
180 $post_type = DI::l10n()->t('status');
184 if ($obj['resource-id']) {
185 $post_type = DI::l10n()->t('photo');
187 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
188 $rr['plink'] = $m[1];
190 $post_type = DI::l10n()->t('status');
194 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
197 if ($activity->match($item['verb'], Activity::LIKE)) {
198 $bodyverb = DI::l10n()->t('%1$s likes %2$s\'s %3$s');
199 } elseif ($activity->match($item['verb'], Activity::DISLIKE)) {
200 $bodyverb = DI::l10n()->t('%1$s doesn\'t like %2$s\'s %3$s');
201 } elseif ($activity->match($item['verb'], Activity::ATTEND)) {
202 $bodyverb = DI::l10n()->t('%1$s attends %2$s\'s %3$s');
203 } elseif ($activity->match($item['verb'], Activity::ATTENDNO)) {
204 $bodyverb = DI::l10n()->t('%1$s doesn\'t attend %2$s\'s %3$s');
205 } elseif ($activity->match($item['verb'], Activity::ATTENDMAYBE)) {
206 $bodyverb = DI::l10n()->t('%1$s attends maybe %2$s\'s %3$s');
209 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
212 if ($activity->match($item['verb'], Activity::FRIEND)) {
214 if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) return;
216 $Aname = $item['author-name'];
217 $Alink = $item['author-link'];
219 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
221 $obj = XML::parseString($xmlhead.$item['object']);
222 $links = XML::parseString($xmlhead."<links>".XML::unescape($obj->link)."</links>");
224 $Bname = $obj->title;
227 foreach ($links->link as $l) {
228 $atts = $l->attributes();
229 switch ($atts['rel']) {
230 case "alternate": $Blink = $atts['href']; break;
231 case "photo": $Bphoto = $atts['href']; break;
235 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
236 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
238 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img]' . $Bphoto . '[/img][/url]';
241 $item['body'] = DI::l10n()->t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
244 if (stristr($item['verb'], Activity::POKE)) {
245 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
249 if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) {
253 $Aname = $item['author-name'];
254 $Alink = $item['author-link'];
256 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
258 $obj = XML::parseString($xmlhead.$item['object']);
260 $Bname = $obj->title;
264 foreach ($obj->link as $l) {
265 $atts = $l->attributes();
266 switch ($atts['rel']) {
267 case "alternate": $Blink = $atts['href'];
268 case "photo": $Bphoto = $atts['href'];
272 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
273 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
275 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
279 * we can't have a translation string with three positions but no distinguishable text
280 * So here is the translate string.
282 $txt = DI::l10n()->t('%1$s poked %2$s');
284 // now translate the verb
285 $poked_t = trim(sprintf($txt, "", ""));
286 $txt = str_replace($poked_t, DI::l10n()->t($verb), $txt);
288 // then do the sprintf on the translation string
290 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
294 if ($activity->match($item['verb'], Activity::TAG)) {
295 $fields = ['author-id', 'author-link', 'author-name', 'author-network',
296 'verb', 'object-type', 'resource-id', 'body', 'plink'];
297 $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
298 if (!DBA::isResult($obj)) {
302 $author_arr = ['uid' => 0, 'id' => $item['author-id'],
303 'network' => $item['author-network'], 'url' => $item['author-link']];
304 $author = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $item['author-name'] . '[/url]';
306 $author_arr = ['uid' => 0, 'id' => $obj['author-id'],
307 'network' => $obj['author-network'], 'url' => $obj['author-link']];
308 $objauthor = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]';
310 switch ($obj['verb']) {
312 switch ($obj['object-type']) {
313 case Activity\ObjectType::EVENT:
314 $post_type = DI::l10n()->t('event');
317 $post_type = DI::l10n()->t('status');
321 if ($obj['resource-id']) {
322 $post_type = DI::l10n()->t('photo');
323 $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
324 $rr['plink'] = $m[1];
326 $post_type = DI::l10n()->t('status');
328 // Let's break everthing ... ;-)
331 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
333 $parsedobj = XML::parseString($xmlhead.$item['object']);
335 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
336 $item['body'] = DI::l10n()->t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag);
339 if ($activity->match($item['verb'], Activity::FAVORITE)) {
340 if ($item['object-type'] == "") {
344 $Aname = $item['author-name'];
345 $Alink = $item['author-link'];
347 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
349 $obj = XML::parseString($xmlhead.$item['object']);
350 if (strlen($obj->id)) {
351 $fields = ['author-link', 'author-name', 'plink'];
352 $target = Item::selectFirst($fields, ['uri' => $obj->id, 'uid' => $item['uid']]);
353 if (DBA::isResult($target) && $target['plink']) {
354 $Bname = $target['author-name'];
355 $Blink = $target['author-link'];
356 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
357 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
358 $P = '[url=' . $target['plink'] . ']' . DI::l10n()->t('post/item') . '[/url]';
359 $item['body'] = DI::l10n()->t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
364 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
365 foreach ($matches as $mtch) {
366 if (!strpos($mtch[1], 'zrl=')) {
367 $item['body'] = str_replace($mtch[0], '@[url=' . Contact::magicLink($mtch[1]) . ']', $item['body']);
372 // add zrl's to public images
373 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
374 if (preg_match($photo_pattern, $item['body'])) {
375 $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
376 $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
379 // add sparkle links to appropriate permalinks
380 $author = ['uid' => 0, 'id' => $item['author-id'],
381 'network' => $item['author-network'], 'url' => $item['author-link']];
383 // Only create a redirection to a magic link when logged in
384 if (!empty($item['plink']) && Session::isAuthenticated()) {
385 $item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
390 * Count the total of comments on this item and its desendants
391 * @TODO proper type-hint + doc-tag
395 function count_descendants($item) {
396 $total = count($item['children']);
399 foreach ($item['children'] as $child) {
400 if (!visible_activity($child)) {
403 $total += count_descendants($child);
410 function visible_activity($item) {
412 $activity = DI::activity();
414 if (empty($item['verb']) || $activity->isHidden($item['verb'])) {
418 // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
419 if ($activity->match($item['verb'], Activity::FOLLOW) &&
420 $item['object-type'] === Activity\ObjectType::NOTE &&
421 empty($item['self']) &&
422 $item['uid'] == local_user()) {
429 function conv_get_blocklist()
435 $str_blocked = DI::pConfig()->get(local_user(), 'system', 'blocked');
436 if (empty($str_blocked)) {
442 foreach (explode(',', $str_blocked) as $entry) {
443 // The 4th parameter guarantees that there always will be a public contact entry
444 $cid = Contact::getIdForURL(trim($entry), 0, true, ['url' => trim($entry)]);
454 * "Render" a conversation or list of items for HTML display.
455 * There are two major forms of display:
456 * - Sequential or unthreaded ("New Item View" or search results)
457 * - conversation view
458 * The $mode parameter decides between the various renderings and also
459 * figures out how to determine page owner and other contextual items
460 * that are based on unique features of the calling module.
462 * @param array $items
463 * @param Pager $pager
466 * @param bool $preview
467 * @param string $order
470 * @throws ImagickException
471 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
473 function conversation(App $a, array $items, Pager $pager, $mode, $update, $preview = false, $order = 'commented', $uid = 0)
475 $ssl_state = (local_user() ? true : false);
478 $live_update_div = '';
480 $blocklist = conv_get_blocklist();
482 $previewing = (($preview) ? ' preview ' : '');
484 if ($mode === 'network') {
485 $items = conversation_add_children($items, false, $order, $uid);
486 $profile_owner = local_user();
489 * The special div is needed for liveUpdate to kick in for this page.
490 * We only launch liveUpdate if you aren't filtering in some incompatible
491 * way and also you aren't writing a comment (discovered in javascript).
493 $live_update_div = '<div id="live-network"></div>' . "\r\n"
494 . "<script> var profile_uid = " . $_SESSION['uid']
495 . "; var netargs = '" . substr(DI::args()->getCommand(), 8)
497 . (!empty($_GET['cid']) ? '&cid=' . rawurlencode($_GET['cid']) : '')
498 . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
499 . (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
500 . (!empty($_GET['order']) ? '&order=' . rawurlencode($_GET['order']) : '')
501 . (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
502 . (!empty($_GET['liked']) ? '&liked=' . rawurlencode($_GET['liked']) : '')
503 . (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
504 . (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
505 . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
506 . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
507 . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
509 . "'; var profile_page = " . $pager->getPage() . "; </script>\r\n";
511 } elseif ($mode === 'profile') {
512 $items = conversation_add_children($items, false, $order, $uid);
513 $profile_owner = $a->profile['uid'];
517 if (!empty($_GET['tab'])) {
518 $tab = Strings::escapeTags(trim($_GET['tab']));
520 if ($tab === 'posts') {
522 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
523 * because browser prefetching might change it on us. We have to deliver it with the page.
526 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
527 . "<script> var profile_uid = " . $a->profile['uid']
528 . "; var netargs = '?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
531 } elseif ($mode === 'notes') {
532 $items = conversation_add_children($items, false, $order, local_user());
533 $profile_owner = local_user();
536 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
537 . "<script> var profile_uid = " . local_user()
538 . "; var netargs = '/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
540 } elseif ($mode === 'display') {
541 $items = conversation_add_children($items, false, $order, $uid);
542 $profile_owner = $a->profile['uid'];
545 $live_update_div = '<div id="live-display"></div>' . "\r\n"
546 . "<script> var profile_uid = " . Session::get('uid', 0) . ";"
547 . " var profile_page = 1; </script>";
549 } elseif ($mode === 'community') {
550 $items = conversation_add_children($items, true, $order, $uid);
554 $live_update_div = '<div id="live-community"></div>' . "\r\n"
555 . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 10)
556 ."/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
558 } elseif ($mode === 'contacts') {
559 $items = conversation_add_children($items, false, $order, $uid);
563 $live_update_div = '<div id="live-contacts"></div>' . "\r\n"
564 . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 9)
565 ."/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
567 } elseif ($mode === 'search') {
568 $live_update_div = '<div id="live-search"></div>' . "\r\n";
571 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
574 $_SESSION['return_path'] = DI::args()->getQueryString();
577 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
578 Hook::callAll('conversation_start',$cb);
580 $items = $cb['items'];
583 'like' => ['title' => DI::l10n()->t('Likes','title')],
584 'dislike' => ['title' => DI::l10n()->t('Dislikes','title')],
585 'attendyes' => ['title' => DI::l10n()->t('Attending','title')],
586 'attendno' => ['title' => DI::l10n()->t('Not attending','title')],
587 'attendmaybe' => ['title' => DI::l10n()->t('Might attend','title')],
588 'announce' => ['title' => DI::l10n()->t('Reshares','title')]
591 // array with html for each thread (parent+comments)
595 $page_template = Renderer::getMarkupTemplate("conversation.tpl");
597 if (!empty($items)) {
598 if (in_array($mode, ['community', 'contacts'])) {
601 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
608 if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
611 * "New Item View" on network page or search page results
612 * - just loop through the items and format them minimally for display
615 $tpl = 'search_item.tpl';
617 foreach ($items as $item) {
619 if (!visible_activity($item)) {
623 if (in_array($item['author-id'], $blocklist)) {
633 // prevent private email from leaking.
634 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
638 $profile_name = $item['author-name'];
639 if (!empty($item['author-link']) && empty($item['author-name'])) {
640 $profile_name = $item['author-link'];
643 $tags = Term::populateTagsFromItem($item);
645 $author = ['uid' => 0, 'id' => $item['author-id'],
646 'network' => $item['author-network'], 'url' => $item['author-link']];
647 $profile_link = Contact::magicLinkByContact($author);
649 if (strpos($profile_link, 'redir/') === 0) {
650 $sparkle = ' sparkle';
653 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
654 Hook::callAll('render_location',$locate);
656 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
658 localize_item($item);
659 if ($mode === 'network-new') {
666 'dropping' => $dropping,
667 'pagedrop' => $page_dropping,
668 'select' => DI::l10n()->t('Select'),
669 'delete' => DI::l10n()->t('Delete'),
673 $isstarred = "unstarred";
676 $likebuttons = false;
678 $body = Item::prepareBody($item, true, $preview);
680 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
682 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
683 $title = ucfirst($item['content-warning']);
685 $title = $item['title'];
690 'id' => ($preview ? 'P0' : $item['id']),
691 'guid' => ($preview ? 'Q0' : $item['guid']),
692 'network' => $item['network'],
693 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
694 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
695 'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
696 'profile_url' => $profile_link,
697 'item_photo_menu' => item_photo_menu($item),
698 'name' => $profile_name,
699 'sparkle' => $sparkle,
701 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
704 'tags' => $tags['tags'],
705 'hashtags' => $tags['hashtags'],
706 'mentions' => $tags['mentions'],
707 'implicit_mentions' => $tags['implicit_mentions'],
708 'txt_cats' => DI::l10n()->t('Categories:'),
709 'txt_folders' => DI::l10n()->t('Filed under:'),
710 'has_cats' => ((count($categories)) ? 'true' : ''),
711 'has_folders' => ((count($folders)) ? 'true' : ''),
712 'categories' => $categories,
713 'folders' => $folders,
714 'text' => strip_tags($body),
715 'localtime' => DateTimeFormat::local($item['created'], 'r'),
716 'ago' => (($item['app']) ? DI::l10n()->t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
717 'location' => $location,
719 'owner_name' => $owner_name,
720 'owner_url' => $owner_url,
721 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
722 'plink' => Item::getPlink($item),
724 'isstarred' => $isstarred,
727 'vote' => $likebuttons,
731 'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> DI::l10n()->t('View in context')]),
732 'previewing' => $previewing,
733 'wait' => DI::l10n()->t('Please wait'),
737 $arr = ['item' => $item, 'output' => $tmp_item];
738 Hook::callAll('display_item', $arr);
740 $threads[$threadsid]['id'] = $item['id'];
741 $threads[$threadsid]['network'] = $item['network'];
742 $threads[$threadsid]['items'] = [$arr['output']];
747 $page_template = Renderer::getMarkupTemplate("threaded_conversation.tpl");
749 $conv = new Thread($mode, $preview, $writable);
752 * get all the topmost parents
753 * this shouldn't be needed, as we should have only them in our array
754 * But for now, this array respects the old style, just in case
756 foreach ($items as $item) {
757 if (in_array($item['author-id'], $blocklist)) {
761 // Can we put this after the visibility check?
762 builtin_activity_puller($item, $conv_responses);
764 // Only add what is visible
765 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
769 if (!visible_activity($item)) {
773 /// @todo Check if this call is needed or not
774 $arr = ['item' => $item];
775 Hook::callAll('display_item', $arr);
777 $item['pagedrop'] = $page_dropping;
779 if ($item['id'] == $item['parent']) {
780 $item_object = new Post($item);
781 $conv->addParent($item_object);
785 $threads = $conv->getTemplateData($conv_responses);
787 Logger::log('[ERROR] conversation : Failed to get template data.', Logger::DEBUG);
793 $o = Renderer::replaceMacros($page_template, [
794 '$baseurl' => DI::baseUrl()->get($ssl_state),
795 '$return_path' => DI::args()->getQueryString(),
796 '$live_update' => $live_update_div,
797 '$remove' => DI::l10n()->t('remove'),
800 '$threads' => $threads,
801 '$dropping' => ($page_dropping ? DI::l10n()->t('Delete Selected Items') : False),
808 * Fetch all comments from a query. Additionally set the newest resharer as thread owner.
810 * @param mixed $thread_items Database statement with thread posts
811 * @param boolean $pinned Is the item pinned?
813 * @return array items with parents and comments
815 function conversation_fetch_comments($thread_items, $pinned) {
822 while ($row = Item::fetch($thread_items)) {
823 if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
824 $actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
825 $received = $row['received'];
828 if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
829 (empty($row['contact-uid']) || !in_array($row['network'], Protocol::NATIVE_SUPPORT))) {
830 $parentlines[] = $lineno;
833 if ($row['gravity'] == GRAVITY_PARENT) {
834 $row['pinned'] = $pinned;
841 DBA::close($thread_items);
843 if (!empty($actor)) {
844 foreach ($parentlines as $line) {
845 $comments[$line]['owner-link'] = $actor['link'];
846 $comments[$line]['owner-avatar'] = $actor['avatar'];
847 $comments[$line]['owner-name'] = $actor['name'];
854 * Add comments to top level entries that had been fetched before
856 * The system will fetch the comments for the local user whenever possible.
857 * This behaviour is currently needed to allow commenting on Friendica posts.
859 * @param array $parents Parent items
861 * @param $block_authors
864 * @return array items with parents and comments
865 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
867 function conversation_add_children(array $parents, $block_authors, $order, $uid) {
868 $max_comments = DI::config()->get('system', 'max_comments', 100);
870 $params = ['order' => ['uid', 'commented' => true]];
872 if ($max_comments > 0) {
873 $params['limit'] = $max_comments;
878 foreach ($parents AS $parent) {
879 $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ",
880 $parent['uri'], $uid];
881 if ($block_authors) {
882 $condition[0] .= "AND NOT `author`.`hidden`";
885 $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
887 $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
889 if (count($comments) != 0) {
890 $items = array_merge($items, $comments);
894 foreach ($items as $index => $item) {
895 if ($item['uid'] == 0) {
896 $items[$index]['writable'] = in_array($item['network'], Protocol::FEDERATED);
900 $items = conv_sort($items, $order);
905 function item_photo_menu($item) {
916 if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) {
917 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
920 $author = ['uid' => 0, 'id' => $item['author-id'],
921 'network' => $item['author-network'], 'url' => $item['author-link']];
922 $profile_link = Contact::magicLinkByContact($author, $item['author-link']);
923 $sparkle = (strpos($profile_link, 'redir/') === 0);
926 $pcid = Contact::getIdForURL($item['author-link'], 0, true);
929 $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
930 $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
931 if (DBA::isResult($contact)) {
932 $cid = $contact['id'];
933 $network = $contact['network'];
934 $rel = $contact['rel'];
938 $status_link = $profile_link . '/status';
939 $photos_link = str_replace('/profile/', '/photos/', $profile_link);
940 $profile_link = $profile_link . '/profile';
944 $contact_url = 'contact/' . $pcid;
945 $posts_link = 'contact/' . $pcid . '/posts';
946 $block_link = 'contact/' . $pcid . '/block';
947 $ignore_link = 'contact/' . $pcid . '/ignore';
950 if ($cid && !$item['self']) {
951 $poke_link = 'poke?c=' . $cid;
952 $contact_url = 'contact/' . $cid;
953 $posts_link = 'contact/' . $cid . '/posts';
955 if (in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
956 $pm_url = 'message/new/' . $cid;
962 DI::l10n()->t('Follow Thread') => $sub_link,
963 DI::l10n()->t('View Status') => $status_link,
964 DI::l10n()->t('View Profile') => $profile_link,
965 DI::l10n()->t('View Photos') => $photos_link,
966 DI::l10n()->t('Network Posts') => $posts_link,
967 DI::l10n()->t('View Contact') => $contact_url,
968 DI::l10n()->t('Send PM') => $pm_url,
969 DI::l10n()->t('Block') => $block_link,
970 DI::l10n()->t('Ignore') => $ignore_link
973 if ($network == Protocol::DFRN) {
974 $menu[DI::l10n()->t("Poke")] = $poke_link;
977 if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
978 in_array($item['network'], Protocol::FEDERATED)) {
979 $menu[DI::l10n()->t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
982 $menu = [DI::l10n()->t('View Profile') => $item['author-link']];
985 $args = ['item' => $item, 'menu' => $menu];
987 Hook::callAll('item_photo_menu', $args);
989 $menu = $args['menu'];
992 foreach ($menu as $k => $v) {
993 if (strpos($v, 'javascript:') === 0) {
995 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
997 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1004 * Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1006 * Increments the count of each matching activity and adds a link to the author as needed.
1008 * @param array $item
1009 * @param array &$conv_responses (already created with builtin activity structure)
1011 * @throws ImagickException
1012 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1014 function builtin_activity_puller($item, &$conv_responses) {
1015 foreach ($conv_responses as $mode => $v) {
1020 $verb = Activity::LIKE;
1023 $verb = Activity::DISLIKE;
1026 $verb = Activity::ATTEND;
1029 $verb = Activity::ATTENDNO;
1032 $verb = Activity::ATTENDMAYBE;
1035 $verb = Activity::ANNOUNCE;
1041 if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
1042 $author = ['uid' => 0, 'id' => $item['author-id'],
1043 'network' => $item['author-network'], 'url' => $item['author-link']];
1044 $url = Contact::magicLinkByContact($author);
1045 if (strpos($url, 'redir/') === 0) {
1046 $sparkle = ' class="sparkle" ';
1049 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1051 if (empty($item['thr-parent'])) {
1052 $item['thr-parent'] = $item['parent-uri'];
1055 if (!(isset($conv_responses[$mode][$item['thr-parent'] . '-l'])
1056 && is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))) {
1057 $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
1060 // only list each unique author once
1061 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1065 if (!isset($conv_responses[$mode][$item['thr-parent']])) {
1066 $conv_responses[$mode][$item['thr-parent']] = 1;
1068 $conv_responses[$mode][$item['thr-parent']] ++;
1071 if (public_contact() == $item['author-id']) {
1072 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1075 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1077 // there can only be one activity verb per item so if we found anything, we can stop looking
1084 * Format the vote text for a profile item
1086 * @param int $cnt = number of people who vote the item
1087 * @param array $arr = array of pre-linked names of likers/dislikers
1088 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1089 * @param int $id = item id
1090 * @return string formatted text
1091 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1093 function format_like($cnt, array $arr, $type, $id) {
1101 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1102 // list which show all likers
1105 $phrase = DI::l10n()->t('%s likes this.', $likers);
1108 $phrase = DI::l10n()->t('%s doesn\'t like this.', $likers);
1111 $phrase = DI::l10n()->t('%s attends.', $likers);
1114 $phrase = DI::l10n()->t('%s doesn\'t attend.', $likers);
1116 case 'attendmaybe' :
1117 $phrase = DI::l10n()->t('%s attends maybe.', $likers);
1120 $phrase = DI::l10n()->t('%s reshared this.', $likers);
1126 $total = count($arr);
1127 if ($total < MAX_LIKERS) {
1128 $last = DI::l10n()->t('and') . ' ' . $arr[count($arr)-1];
1129 $arr2 = array_slice($arr, 0, -1);
1130 $likers = implode(', ', $arr2) . ' ' . $last;
1132 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1133 $likers = implode(', ', $arr);
1134 $likers .= DI::l10n()->t('and %d other people', $total - MAX_LIKERS);
1137 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1142 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
1143 $explikers = DI::l10n()->t('%s like this.', $likers);
1146 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
1147 $explikers = DI::l10n()->t('%s don\'t like this.', $likers);
1150 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
1151 $explikers = DI::l10n()->t('%s attend.', $likers);
1154 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
1155 $explikers = DI::l10n()->t('%s don\'t attend.', $likers);
1158 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
1159 $explikers = DI::l10n()->t('%s attend maybe.', $likers);
1162 $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> reshared this', $spanatts, $cnt);
1163 $explikers = DI::l10n()->t('%s reshared this.', $likers);
1167 $expanded .= "\t" . '<p class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</p>';
1170 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
1171 '$phrase' => $phrase,
1180 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1184 $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
1186 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
1187 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
1188 '$newpost' => 'true',
1189 '$baseurl' => DI::baseUrl()->get(true),
1190 '$geotag' => $geotag,
1191 '$nickname' => $x['nickname'],
1192 '$ispublic' => DI::l10n()->t('Visible to <strong>everybody</strong>'),
1193 '$linkurl' => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
1194 '$term' => DI::l10n()->t('Tag term:'),
1195 '$fileas' => DI::l10n()->t('Save to Folder:'),
1196 '$whereareu' => DI::l10n()->t('Where are you right now?'),
1197 '$delitems' => DI::l10n()->t("Delete item\x28s\x29?")
1201 Hook::callAll('jot_tool', $jotplugins);
1203 // Private/public post links for the non-JS ACL form
1205 if (!empty($_REQUEST['public'])) {
1209 $query_str = DI::args()->getQueryString();
1210 if (strpos($query_str, 'public=1') !== false) {
1211 $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
1215 * I think $a->query_string may never have ? in it, but I could be wrong
1216 * It looks like it's from the index.php?q=[etc] rewrite that the web
1217 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1219 if (strpos($query_str, '?') === false) {
1220 $public_post_link = '?public=1';
1222 $public_post_link = '&public=1';
1225 // $tpl = Renderer::replaceMacros($tpl,array('$jotplugins' => $jotplugins));
1226 $tpl = Renderer::getMarkupTemplate("jot.tpl");
1228 $o .= Renderer::replaceMacros($tpl,[
1229 '$new_post' => DI::l10n()->t('New Post'),
1230 '$return_path' => $query_str,
1231 '$action' => 'item',
1232 '$share' => ($x['button'] ?? '') ?: DI::l10n()->t('Share'),
1233 '$loading' => DI::l10n()->t('Loading...'),
1234 '$upload' => DI::l10n()->t('Upload photo'),
1235 '$shortupload' => DI::l10n()->t('upload photo'),
1236 '$attach' => DI::l10n()->t('Attach file'),
1237 '$shortattach' => DI::l10n()->t('attach file'),
1238 '$edbold' => DI::l10n()->t('Bold'),
1239 '$editalic' => DI::l10n()->t('Italic'),
1240 '$eduline' => DI::l10n()->t('Underline'),
1241 '$edquote' => DI::l10n()->t('Quote'),
1242 '$edcode' => DI::l10n()->t('Code'),
1243 '$edimg' => DI::l10n()->t('Image'),
1244 '$edurl' => DI::l10n()->t('Link'),
1245 '$edattach' => DI::l10n()->t('Link or Media'),
1246 '$setloc' => DI::l10n()->t('Set your location'),
1247 '$shortsetloc' => DI::l10n()->t('set location'),
1248 '$noloc' => DI::l10n()->t('Clear browser location'),
1249 '$shortnoloc' => DI::l10n()->t('clear location'),
1250 '$title' => $x['title'] ?? '',
1251 '$placeholdertitle' => DI::l10n()->t('Set title'),
1252 '$category' => $x['category'] ?? '',
1253 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : '',
1254 '$wait' => DI::l10n()->t('Please wait'),
1255 '$permset' => DI::l10n()->t('Permission settings'),
1256 '$shortpermset' => DI::l10n()->t('permissions'),
1257 '$wall' => $notes_cid ? 0 : 1,
1258 '$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
1259 '$content' => $x['content'] ?? '',
1260 '$post_id' => $x['post_id'] ?? '',
1261 '$baseurl' => DI::baseUrl()->get(true),
1262 '$defloc' => $x['default_location'],
1263 '$visitor' => $x['visitor'],
1264 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1265 '$public' => DI::l10n()->t('Public post'),
1266 '$lockstate' => $x['lockstate'],
1267 '$bang' => $x['bang'],
1268 '$profile_uid' => $x['profile_uid'],
1269 '$preview' => DI::l10n()->t('Preview'),
1270 '$jotplugins' => $jotplugins,
1271 '$notes_cid' => $notes_cid,
1272 '$sourceapp' => DI::l10n()->t($a->sourcename),
1273 '$cancel' => DI::l10n()->t('Cancel'),
1274 '$rand_num' => Crypto::randomDigits(12),
1276 // ACL permissions box
1277 '$acl' => $x['acl'],
1278 '$group_perms' => DI::l10n()->t('Post to Groups'),
1279 '$contact_perms' => DI::l10n()->t('Post to Contacts'),
1280 '$private' => DI::l10n()->t('Private post'),
1281 '$is_private' => $private_post,
1282 '$public_link' => $public_post_link,
1284 //jot nav tab (used in some themes)
1285 '$message' => DI::l10n()->t('Message'),
1286 '$browser' => DI::l10n()->t('Browser'),
1290 if ($popup == true) {
1291 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1298 * Plucks the children of the given parent from a given item list.
1300 * @param array $item_list
1301 * @param array $parent
1302 * @param bool $recursive
1305 function get_item_children(array &$item_list, array $parent, $recursive = true)
1308 foreach ($item_list as $i => $item) {
1309 if ($item['id'] != $item['parent']) {
1311 // Fallback to parent-uri if thr-parent is not set
1312 $thr_parent = $item['thr-parent'];
1313 if ($thr_parent == '') {
1314 $thr_parent = $item['parent-uri'];
1317 if ($thr_parent == $parent['uri']) {
1318 $item['children'] = get_item_children($item_list, $item);
1319 $children[] = $item;
1320 unset($item_list[$i]);
1322 } elseif ($item['parent'] == $parent['id']) {
1323 $children[] = $item;
1324 unset($item_list[$i]);
1332 * Recursively sorts a tree-like item array
1334 * @param array $items
1337 function sort_item_children(array $items)
1340 usort($result, 'sort_thr_received_rev');
1341 foreach ($result as $k => $i) {
1342 if (isset($result[$k]['children'])) {
1343 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1350 * Recursively add all children items at the top level of a list
1352 * @param array $children List of items to append
1353 * @param array $item_list
1355 function add_children_to_list(array $children, array &$item_list)
1357 foreach ($children as $child) {
1358 $item_list[] = $child;
1359 if (isset($child['children'])) {
1360 add_children_to_list($child['children'], $item_list);
1366 * Selectively flattens a tree-like item structure to prevent threading stairs
1368 * This recursive function takes the item tree structure created by conv_sort() and
1369 * flatten the extraneous depth levels when people reply sequentially, removing the
1370 * stairs effect in threaded conversations limiting the available content width.
1372 * The basic principle is the following: if a post item has only one reply and is
1373 * the last reply of its parent, then the reply is moved to the parent.
1375 * This process is rendered somewhat more complicated because items can be either
1376 * replies or likes, and these don't factor at all in the reply count/last reply.
1378 * @param array $parent A tree-like array of items
1381 function smart_flatten_conversation(array $parent)
1383 if (!isset($parent['children']) || count($parent['children']) == 0) {
1387 // We use a for loop to ensure we process the newly-moved items
1388 for ($i = 0; $i < count($parent['children']); $i++) {
1389 $child = $parent['children'][$i];
1391 if (isset($child['children']) && count($child['children'])) {
1392 // This helps counting only the regular posts
1393 $count_post_closure = function($var) {
1394 return $var['verb'] === Activity::POST;
1397 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1399 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1401 // If there's only one child's children post and this is the last child post
1402 if ($child_post_count == 1 && $remaining_post_count == 1) {
1404 // Searches the post item in the children
1406 while($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
1410 $moved_item = $child['children'][$j];
1411 unset($parent['children'][$i]['children'][$j]);
1412 $parent['children'][] = $moved_item;
1414 $parent['children'][$i] = smart_flatten_conversation($child);
1424 * Expands a flat list of items into corresponding tree-like conversation structures.
1426 * sort the top-level posts either on "received" or "commented", and finally
1427 * append all the items at the top level (???)
1429 * @param array $item_list A list of items belonging to one or more conversations
1430 * @param string $order Either on "received" or "commented"
1432 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1434 function conv_sort(array $item_list, $order)
1438 if (!(is_array($item_list) && count($item_list))) {
1442 $blocklist = conv_get_blocklist();
1446 // Dedupes the item list on the uri to prevent infinite loops
1447 foreach ($item_list as $item) {
1448 if (in_array($item['author-id'], $blocklist)) {
1452 $item_array[$item['uri']] = $item;
1455 // Extract the top level items
1456 foreach ($item_array as $item) {
1457 if ($item['id'] == $item['parent']) {
1462 if (stristr($order, 'pinned_received')) {
1463 usort($parents, 'sort_thr_pinned_received');
1464 } elseif (stristr($order, 'received')) {
1465 usort($parents, 'sort_thr_received');
1466 } elseif (stristr($order, 'commented')) {
1467 usort($parents, 'sort_thr_commented');
1471 * Plucks children from the item_array, second pass collects eventual orphan
1472 * items and add them as children of their top-level post.
1474 foreach ($parents as $i => $parent) {
1475 $parents[$i]['children'] =
1476 array_merge(get_item_children($item_array, $parent, true),
1477 get_item_children($item_array, $parent, false));
1480 foreach ($parents as $i => $parent) {
1481 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1484 if (!DI::pConfig()->get(local_user(), 'system', 'no_smart_threading', 0)) {
1485 foreach ($parents as $i => $parent) {
1486 $parents[$i] = smart_flatten_conversation($parent);
1490 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1491 /// However, this apparently ensures responses (likes, attendance) display (?!)
1492 foreach ($parents as $parent) {
1493 if (count($parent['children'])) {
1494 add_children_to_list($parent['children'], $parents);
1502 * usort() callback to sort item arrays by pinned and the received key
1508 function sort_thr_pinned_received(array $a, array $b)
1510 if ($b['pinned'] && !$a['pinned']) {
1512 } elseif (!$b['pinned'] && $a['pinned']) {
1516 return strcmp($b['received'], $a['received']);
1520 * usort() callback to sort item arrays by the received key
1526 function sort_thr_received(array $a, array $b)
1528 return strcmp($b['received'], $a['received']);
1532 * usort() callback to reverse sort item arrays by the received key
1538 function sort_thr_received_rev(array $a, array $b)
1540 return strcmp($a['received'], $b['received']);
1544 * usort() callback to sort item arrays by the commented key
1550 function sort_thr_commented(array $a, array $b)
1552 return strcmp($b['commented'], $a['commented']);
1555 function render_location_dummy(array $item) {
1556 if (!empty($item['location']) && !empty($item['location'])) {
1557 return $item['location'];
1560 if (!empty($item['coord']) && !empty($item['coord'])) {
1561 return $item['coord'];
1565 function get_responses(array $conv_responses, array $response_verbs, array $item, Post $ob = null) {
1567 foreach ($response_verbs as $v) {
1569 $ret[$v]['count'] = $conv_responses[$v][$item['uri']] ?? 0;
1570 $ret[$v]['list'] = $conv_responses[$v][$item['uri'] . '-l'] ?? [];
1571 $ret[$v]['self'] = $conv_responses[$v][$item['uri'] . '-self'] ?? '0';
1572 if (count($ret[$v]['list']) > MAX_LIKERS) {
1573 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1574 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1575 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . DI::l10n()->t('View all') . '</b></a>');
1577 $ret[$v]['list_part'] = '';
1579 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1580 $ret[$v]['title'] = $conv_responses[$v]['title'];
1584 foreach ($ret as $key) {
1585 if ($key['count'] == true) {
1589 $ret['count'] = $count;
1594 function get_response_button_text($v, $count)
1599 $return = DI::l10n()->tt('Like', 'Likes', $count);
1602 $return = DI::l10n()->tt('Dislike', 'Dislikes', $count);
1605 $return = DI::l10n()->tt('Attending', 'Attending', $count);
1608 $return = DI::l10n()->tt('Not Attending', 'Not Attending', $count);
1611 $return = DI::l10n()->tt('Undecided', 'Undecided', $count);