3 * @file include/conversation.php
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Content\Pager;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\Config;
12 use Friendica\Core\Hook;
13 use Friendica\Core\L10n;
14 use Friendica\Core\Logger;
15 use Friendica\Core\Protocol;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\Session;
18 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Item;
22 use Friendica\Model\Profile;
23 use Friendica\Model\Term;
24 use Friendica\Object\Post;
25 use Friendica\Object\Thread;
26 use Friendica\Protocol\Activity;
27 use Friendica\Util\Crypto;
28 use Friendica\Util\DateTimeFormat;
29 use Friendica\Util\Proxy as ProxyUtils;
30 use Friendica\Util\Strings;
31 use Friendica\Util\Temporal;
32 use Friendica\Util\XML;
34 function item_extract_images($body) {
41 $img_start = strpos($orig_body, '[img');
42 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
43 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
44 while (($img_st_close !== false) && ($img_end !== false)) {
46 $img_st_close++; // make it point to AFTER the closing bracket
47 $img_end += $img_start;
49 if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
50 // This is an embedded image
52 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
53 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
57 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
60 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
62 if ($orig_body === false) {
63 // in case the body ends on a closing image tag
67 $img_start = strpos($orig_body, '[img');
68 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
69 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
72 $new_body = $new_body . $orig_body;
74 return ['body' => $new_body, 'images' => $saved_image];
77 function item_redir_and_replace_images($body, $images, $cid) {
83 $pos = BBCode::getTagPosition($origbody, 'url', 0);
84 while ($pos !== false && $cnt < 1000) {
86 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
87 $replace = '[url=' . DI::baseUrl() . '/redir/' . $cid
88 . '?url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
90 $newbody .= substr($origbody, 0, $pos['start']['open']);
91 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
92 $origbody = substr($origbody, $pos['end']['close']);
93 if ($origbody === false) {
97 $subject = preg_replace($search, $replace, $subject);
101 // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
102 $pos = BBCode::getTagPosition($origbody, 'url', 0);
104 $newbody .= $origbody;
107 foreach ($images as $image) {
109 * We're depending on the property of 'foreach' (specified on the PHP website) that
110 * it loops over the array starting from the first element and going sequentially
111 * to the last element.
113 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
120 * Render actions localized
123 * @throws ImagickException
124 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
126 function localize_item(&$item)
128 $extracted = item_extract_images($item['body']);
129 if ($extracted['images']) {
130 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
134 heluecht 2018-06-19: from my point of view this whole code part is useless.
135 It just renders the body message of technical posts (Like, dislike, ...).
136 But: The body isn't visible at all. So we do this stuff just because we can.
137 Even if these messages were visible, this would only mean that something went wrong.
138 During the further steps of the database restructuring I would like to address this issue.
141 $activity = DI::activity();
143 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
144 if ($activity->match($item['verb'], Activity::LIKE)
145 || $activity->match($item['verb'], Activity::DISLIKE)
146 || $activity->match($item['verb'], Activity::ATTEND)
147 || $activity->match($item['verb'], Activity::ATTENDNO)
148 || $activity->match($item['verb'], Activity::ATTENDMAYBE)) {
150 $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
151 $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
152 if (!DBA::isResult($obj)) {
156 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
157 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
159 switch ($obj['verb']) {
161 switch ($obj['object-type']) {
162 case Activity\ObjectType::EVENT:
163 $post_type = L10n::t('event');
166 $post_type = L10n::t('status');
170 if ($obj['resource-id']) {
171 $post_type = L10n::t('photo');
173 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
174 $rr['plink'] = $m[1];
176 $post_type = L10n::t('status');
180 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
183 if ($activity->match($item['verb'], Activity::LIKE)) {
184 $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
185 } elseif ($activity->match($item['verb'], Activity::DISLIKE)) {
186 $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
187 } elseif ($activity->match($item['verb'], Activity::ATTEND)) {
188 $bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
189 } elseif ($activity->match($item['verb'], Activity::ATTENDNO)) {
190 $bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
191 } elseif ($activity->match($item['verb'], Activity::ATTENDMAYBE)) {
192 $bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
195 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
198 if ($activity->match($item['verb'], Activity::FRIEND)) {
200 if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) return;
202 $Aname = $item['author-name'];
203 $Alink = $item['author-link'];
205 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
207 $obj = XML::parseString($xmlhead.$item['object']);
208 $links = XML::parseString($xmlhead."<links>".XML::unescape($obj->link)."</links>");
210 $Bname = $obj->title;
213 foreach ($links->link as $l) {
214 $atts = $l->attributes();
215 switch ($atts['rel']) {
216 case "alternate": $Blink = $atts['href']; break;
217 case "photo": $Bphoto = $atts['href']; break;
221 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
222 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
224 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img]' . $Bphoto . '[/img][/url]';
227 $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
230 if (stristr($item['verb'], Activity::POKE)) {
231 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
235 if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) {
239 $Aname = $item['author-name'];
240 $Alink = $item['author-link'];
242 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
244 $obj = XML::parseString($xmlhead.$item['object']);
246 $Bname = $obj->title;
250 foreach ($obj->link as $l) {
251 $atts = $l->attributes();
252 switch ($atts['rel']) {
253 case "alternate": $Blink = $atts['href'];
254 case "photo": $Bphoto = $atts['href'];
258 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
259 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
261 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
265 * we can't have a translation string with three positions but no distinguishable text
266 * So here is the translate string.
268 $txt = L10n::t('%1$s poked %2$s');
270 // now translate the verb
271 $poked_t = trim(sprintf($txt, "", ""));
272 $txt = str_replace($poked_t, L10n::t($verb), $txt);
274 // then do the sprintf on the translation string
276 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
280 if ($activity->match($item['verb'], Activity::TAG)) {
281 $fields = ['author-id', 'author-link', 'author-name', 'author-network',
282 'verb', 'object-type', 'resource-id', 'body', 'plink'];
283 $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
284 if (!DBA::isResult($obj)) {
288 $author_arr = ['uid' => 0, 'id' => $item['author-id'],
289 'network' => $item['author-network'], 'url' => $item['author-link']];
290 $author = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $item['author-name'] . '[/url]';
292 $author_arr = ['uid' => 0, 'id' => $obj['author-id'],
293 'network' => $obj['author-network'], 'url' => $obj['author-link']];
294 $objauthor = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]';
296 switch ($obj['verb']) {
298 switch ($obj['object-type']) {
299 case Activity\ObjectType::EVENT:
300 $post_type = L10n::t('event');
303 $post_type = L10n::t('status');
307 if ($obj['resource-id']) {
308 $post_type = L10n::t('photo');
309 $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
310 $rr['plink'] = $m[1];
312 $post_type = L10n::t('status');
314 // Let's break everthing ... ;-)
317 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
319 $parsedobj = XML::parseString($xmlhead.$item['object']);
321 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
322 $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag);
325 if ($activity->match($item['verb'], Activity::FAVORITE)) {
326 if ($item['object-type'] == "") {
330 $Aname = $item['author-name'];
331 $Alink = $item['author-link'];
333 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
335 $obj = XML::parseString($xmlhead.$item['object']);
336 if (strlen($obj->id)) {
337 $fields = ['author-link', 'author-name', 'plink'];
338 $target = Item::selectFirst($fields, ['uri' => $obj->id, 'uid' => $item['uid']]);
339 if (DBA::isResult($target) && $target['plink']) {
340 $Bname = $target['author-name'];
341 $Blink = $target['author-link'];
342 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
343 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
344 $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
345 $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
350 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
351 foreach ($matches as $mtch) {
352 if (!strpos($mtch[1], 'zrl=')) {
353 $item['body'] = str_replace($mtch[0], '@[url=' . Contact::magicLink($mtch[1]) . ']', $item['body']);
358 // add zrl's to public images
359 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
360 if (preg_match($photo_pattern, $item['body'])) {
361 $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
362 $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
365 // add sparkle links to appropriate permalinks
366 $author = ['uid' => 0, 'id' => $item['author-id'],
367 'network' => $item['author-network'], 'url' => $item['author-link']];
369 // Only create a redirection to a magic link when logged in
370 if (!empty($item['plink']) && Session::isAuthenticated()) {
371 $item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
376 * Count the total of comments on this item and its desendants
377 * @TODO proper type-hint + doc-tag
381 function count_descendants($item) {
382 $total = count($item['children']);
385 foreach ($item['children'] as $child) {
386 if (!visible_activity($child)) {
389 $total += count_descendants($child);
396 function visible_activity($item) {
398 $activity = DI::activity();
400 if (empty($item['verb']) || $activity->isHidden($item['verb'])) {
404 // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
405 if ($activity->match($item['verb'], Activity::FOLLOW) &&
406 $item['object-type'] === Activity\ObjectType::NOTE &&
407 empty($item['self']) &&
408 $item['uid'] == local_user()) {
415 function conv_get_blocklist()
421 $str_blocked = DI::pConfig()->get(local_user(), 'system', 'blocked');
422 if (empty($str_blocked)) {
428 foreach (explode(',', $str_blocked) as $entry) {
429 // The 4th parameter guarantees that there always will be a public contact entry
430 $cid = Contact::getIdForURL(trim($entry), 0, true, ['url' => trim($entry)]);
440 * "Render" a conversation or list of items for HTML display.
441 * There are two major forms of display:
442 * - Sequential or unthreaded ("New Item View" or search results)
443 * - conversation view
444 * The $mode parameter decides between the various renderings and also
445 * figures out how to determine page owner and other contextual items
446 * that are based on unique features of the calling module.
448 * @param array $items
449 * @param Pager $pager
452 * @param bool $preview
453 * @param string $order
456 * @throws ImagickException
457 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
459 function conversation(App $a, array $items, Pager $pager, $mode, $update, $preview = false, $order = 'commented', $uid = 0)
461 $ssl_state = (local_user() ? true : false);
464 $live_update_div = '';
466 $blocklist = conv_get_blocklist();
468 $previewing = (($preview) ? ' preview ' : '');
470 if ($mode === 'network') {
471 $items = conversation_add_children($items, false, $order, $uid);
472 $profile_owner = local_user();
475 * The special div is needed for liveUpdate to kick in for this page.
476 * We only launch liveUpdate if you aren't filtering in some incompatible
477 * way and also you aren't writing a comment (discovered in javascript).
479 $live_update_div = '<div id="live-network"></div>' . "\r\n"
480 . "<script> var profile_uid = " . $_SESSION['uid']
481 . "; var netargs = '" . substr(DI::args()->getCommand(), 8)
483 . (!empty($_GET['cid']) ? '&cid=' . rawurlencode($_GET['cid']) : '')
484 . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
485 . (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
486 . (!empty($_GET['order']) ? '&order=' . rawurlencode($_GET['order']) : '')
487 . (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
488 . (!empty($_GET['liked']) ? '&liked=' . rawurlencode($_GET['liked']) : '')
489 . (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
490 . (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
491 . (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
492 . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
493 . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '')
495 . "'; var profile_page = " . $pager->getPage() . "; </script>\r\n";
497 } elseif ($mode === 'profile') {
498 $items = conversation_add_children($items, false, $order, $uid);
499 $profile_owner = $a->profile['profile_uid'];
503 if (!empty($_GET['tab'])) {
504 $tab = Strings::escapeTags(trim($_GET['tab']));
506 if ($tab === 'posts') {
508 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
509 * because browser prefetching might change it on us. We have to deliver it with the page.
512 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
513 . "<script> var profile_uid = " . $a->profile['profile_uid']
514 . "; var netargs = '?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
517 } elseif ($mode === 'notes') {
518 $items = conversation_add_children($items, false, $order, local_user());
519 $profile_owner = local_user();
522 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
523 . "<script> var profile_uid = " . local_user()
524 . "; var netargs = '/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
526 } elseif ($mode === 'display') {
527 $items = conversation_add_children($items, false, $order, $uid);
528 $profile_owner = $a->profile['uid'];
531 $live_update_div = '<div id="live-display"></div>' . "\r\n"
532 . "<script> var profile_uid = " . Session::get('uid', 0) . ";"
533 . " var profile_page = 1; </script>";
535 } elseif ($mode === 'community') {
536 $items = conversation_add_children($items, true, $order, $uid);
540 $live_update_div = '<div id="live-community"></div>' . "\r\n"
541 . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 10)
542 ."/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
544 } elseif ($mode === 'contacts') {
545 $items = conversation_add_children($items, false, $order, $uid);
549 $live_update_div = '<div id="live-contacts"></div>' . "\r\n"
550 . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 9)
551 ."/?f='; var profile_page = " . $pager->getPage() . "; </script>\r\n";
553 } elseif ($mode === 'search') {
554 $live_update_div = '<div id="live-search"></div>' . "\r\n";
557 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
560 $_SESSION['return_path'] = DI::args()->getQueryString();
563 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
564 Hook::callAll('conversation_start',$cb);
566 $items = $cb['items'];
569 'like' => ['title' => L10n::t('Likes','title')],
570 'dislike' => ['title' => L10n::t('Dislikes','title')],
571 'attendyes' => ['title' => L10n::t('Attending','title')],
572 'attendno' => ['title' => L10n::t('Not attending','title')],
573 'attendmaybe' => ['title' => L10n::t('Might attend','title')],
574 'announce' => ['title' => L10n::t('Reshares','title')]
577 // array with html for each thread (parent+comments)
581 $page_template = Renderer::getMarkupTemplate("conversation.tpl");
583 if (!empty($items)) {
584 if (in_array($mode, ['community', 'contacts'])) {
587 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
594 if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
597 * "New Item View" on network page or search page results
598 * - just loop through the items and format them minimally for display
601 $tpl = 'search_item.tpl';
603 foreach ($items as $item) {
605 if (!visible_activity($item)) {
609 if (in_array($item['author-id'], $blocklist)) {
619 // prevent private email from leaking.
620 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
624 $profile_name = $item['author-name'];
625 if (!empty($item['author-link']) && empty($item['author-name'])) {
626 $profile_name = $item['author-link'];
629 $tags = Term::populateTagsFromItem($item);
631 $author = ['uid' => 0, 'id' => $item['author-id'],
632 'network' => $item['author-network'], 'url' => $item['author-link']];
633 $profile_link = Contact::magicLinkByContact($author);
635 if (strpos($profile_link, 'redir/') === 0) {
636 $sparkle = ' sparkle';
639 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
640 Hook::callAll('render_location',$locate);
642 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
644 localize_item($item);
645 if ($mode === 'network-new') {
652 'dropping' => $dropping,
653 'pagedrop' => $page_dropping,
654 'select' => L10n::t('Select'),
655 'delete' => L10n::t('Delete'),
659 $isstarred = "unstarred";
662 $likebuttons = false;
664 $body = Item::prepareBody($item, true, $preview);
666 list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
668 if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
669 $title = ucfirst($item['content-warning']);
671 $title = $item['title'];
676 'id' => ($preview ? 'P0' : $item['id']),
677 'guid' => ($preview ? 'Q0' : $item['guid']),
678 'network' => $item['network'],
679 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
680 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
681 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
682 'profile_url' => $profile_link,
683 'item_photo_menu' => item_photo_menu($item),
684 'name' => $profile_name,
685 'sparkle' => $sparkle,
687 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
690 'tags' => $tags['tags'],
691 'hashtags' => $tags['hashtags'],
692 'mentions' => $tags['mentions'],
693 'implicit_mentions' => $tags['implicit_mentions'],
694 'txt_cats' => L10n::t('Categories:'),
695 'txt_folders' => L10n::t('Filed under:'),
696 'has_cats' => ((count($categories)) ? 'true' : ''),
697 'has_folders' => ((count($folders)) ? 'true' : ''),
698 'categories' => $categories,
699 'folders' => $folders,
700 'text' => strip_tags($body),
701 'localtime' => DateTimeFormat::local($item['created'], 'r'),
702 'ago' => (($item['app']) ? L10n::t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
703 'location' => $location,
705 'owner_name' => $owner_name,
706 'owner_url' => $owner_url,
707 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
708 'plink' => Item::getPlink($item),
710 'isstarred' => $isstarred,
713 'vote' => $likebuttons,
717 'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> L10n::t('View in context')]),
718 'previewing' => $previewing,
719 'wait' => L10n::t('Please wait'),
723 $arr = ['item' => $item, 'output' => $tmp_item];
724 Hook::callAll('display_item', $arr);
726 $threads[$threadsid]['id'] = $item['id'];
727 $threads[$threadsid]['network'] = $item['network'];
728 $threads[$threadsid]['items'] = [$arr['output']];
733 $page_template = Renderer::getMarkupTemplate("threaded_conversation.tpl");
735 $conv = new Thread($mode, $preview, $writable);
738 * get all the topmost parents
739 * this shouldn't be needed, as we should have only them in our array
740 * But for now, this array respects the old style, just in case
742 foreach ($items as $item) {
743 if (in_array($item['author-id'], $blocklist)) {
747 // Can we put this after the visibility check?
748 builtin_activity_puller($item, $conv_responses);
750 // Only add what is visible
751 if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
755 if (!visible_activity($item)) {
759 /// @todo Check if this call is needed or not
760 $arr = ['item' => $item];
761 Hook::callAll('display_item', $arr);
763 $item['pagedrop'] = $page_dropping;
765 if ($item['id'] == $item['parent']) {
766 $item_object = new Post($item);
767 $conv->addParent($item_object);
771 $threads = $conv->getTemplateData($conv_responses);
773 Logger::log('[ERROR] conversation : Failed to get template data.', Logger::DEBUG);
779 $o = Renderer::replaceMacros($page_template, [
780 '$baseurl' => DI::baseUrl()->get($ssl_state),
781 '$return_path' => DI::args()->getQueryString(),
782 '$live_update' => $live_update_div,
783 '$remove' => L10n::t('remove'),
786 '$threads' => $threads,
787 '$dropping' => ($page_dropping ? L10n::t('Delete Selected Items') : False),
794 * Fetch all comments from a query. Additionally set the newest resharer as thread owner.
796 * @param array $thread_items Database statement with thread posts
797 * @param boolean $pinned Is the item pinned?
799 * @return array items with parents and comments
801 function conversation_fetch_comments($thread_items, $pinned) {
808 while ($row = Item::fetch($thread_items)) {
809 if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
810 $actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
811 $received = $row['received'];
814 if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
815 (empty($row['contact-uid']) || !in_array($row['network'], Protocol::NATIVE_SUPPORT))) {
816 $parentlines[] = $lineno;
819 if ($row['gravity'] == GRAVITY_PARENT) {
820 $row['pinned'] = $pinned;
827 DBA::close($thread_items);
829 if (!empty($actor)) {
830 foreach ($parentlines as $line) {
831 $comments[$line]['owner-link'] = $actor['link'];
832 $comments[$line]['owner-avatar'] = $actor['avatar'];
833 $comments[$line]['owner-name'] = $actor['name'];
840 * Add comments to top level entries that had been fetched before
842 * The system will fetch the comments for the local user whenever possible.
843 * This behaviour is currently needed to allow commenting on Friendica posts.
845 * @param array $parents Parent items
847 * @param $block_authors
850 * @return array items with parents and comments
851 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
853 function conversation_add_children(array $parents, $block_authors, $order, $uid) {
854 $max_comments = Config::get('system', 'max_comments', 100);
856 $params = ['order' => ['uid', 'commented' => true]];
858 if ($max_comments > 0) {
859 $params['limit'] = $max_comments;
864 foreach ($parents AS $parent) {
865 $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ",
866 $parent['uri'], $uid];
867 if ($block_authors) {
868 $condition[0] .= "AND NOT `author`.`hidden`";
871 $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
873 $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
875 if (count($comments) != 0) {
876 $items = array_merge($items, $comments);
880 foreach ($items as $index => $item) {
881 if ($item['uid'] == 0) {
882 $items[$index]['writable'] = in_array($item['network'], Protocol::FEDERATED);
886 $items = conv_sort($items, $order);
891 function item_photo_menu($item) {
902 if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) {
903 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
906 $author = ['uid' => 0, 'id' => $item['author-id'],
907 'network' => $item['author-network'], 'url' => $item['author-link']];
908 $profile_link = Contact::magicLinkByContact($author, $item['author-link']);
909 $sparkle = (strpos($profile_link, 'redir/') === 0);
912 $pcid = Contact::getIdForURL($item['author-link'], 0, true);
915 $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
916 $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
917 if (DBA::isResult($contact)) {
918 $cid = $contact['id'];
919 $network = $contact['network'];
920 $rel = $contact['rel'];
924 $status_link = $profile_link . '?tab=status';
925 $photos_link = str_replace('/profile/', '/photos/', $profile_link);
926 $profile_link = $profile_link . '?=profile';
930 $contact_url = 'contact/' . $pcid;
931 $posts_link = 'contact/' . $pcid . '/posts';
932 $block_link = 'contact/' . $pcid . '/block';
933 $ignore_link = 'contact/' . $pcid . '/ignore';
936 if ($cid && !$item['self']) {
937 $poke_link = 'poke?c=' . $cid;
938 $contact_url = 'contact/' . $cid;
939 $posts_link = 'contact/' . $cid . '/posts';
941 if (in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
942 $pm_url = 'message/new/' . $cid;
948 L10n::t('Follow Thread') => $sub_link,
949 L10n::t('View Status') => $status_link,
950 L10n::t('View Profile') => $profile_link,
951 L10n::t('View Photos') => $photos_link,
952 L10n::t('Network Posts') => $posts_link,
953 L10n::t('View Contact') => $contact_url,
954 L10n::t('Send PM') => $pm_url,
955 L10n::t('Block') => $block_link,
956 L10n::t('Ignore') => $ignore_link
959 if ($network == Protocol::DFRN) {
960 $menu[L10n::t("Poke")] = $poke_link;
963 if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
964 in_array($item['network'], Protocol::FEDERATED)) {
965 $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
968 $menu = [L10n::t('View Profile') => $item['author-link']];
971 $args = ['item' => $item, 'menu' => $menu];
973 Hook::callAll('item_photo_menu', $args);
975 $menu = $args['menu'];
978 foreach ($menu as $k => $v) {
979 if (strpos($v, 'javascript:') === 0) {
981 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
983 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
990 * Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
992 * Increments the count of each matching activity and adds a link to the author as needed.
995 * @param array &$conv_responses (already created with builtin activity structure)
997 * @throws ImagickException
998 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1000 function builtin_activity_puller($item, &$conv_responses) {
1001 foreach ($conv_responses as $mode => $v) {
1006 $verb = Activity::LIKE;
1009 $verb = Activity::DISLIKE;
1012 $verb = Activity::ATTEND;
1015 $verb = Activity::ATTENDNO;
1018 $verb = Activity::ATTENDMAYBE;
1021 $verb = Activity::ANNOUNCE;
1027 if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
1028 $author = ['uid' => 0, 'id' => $item['author-id'],
1029 'network' => $item['author-network'], 'url' => $item['author-link']];
1030 $url = Contact::magicLinkByContact($author);
1031 if (strpos($url, 'redir/') === 0) {
1032 $sparkle = ' class="sparkle" ';
1035 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1037 if (empty($item['thr-parent'])) {
1038 $item['thr-parent'] = $item['parent-uri'];
1041 if (!(isset($conv_responses[$mode][$item['thr-parent'] . '-l'])
1042 && is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))) {
1043 $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
1046 // only list each unique author once
1047 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1051 if (!isset($conv_responses[$mode][$item['thr-parent']])) {
1052 $conv_responses[$mode][$item['thr-parent']] = 1;
1054 $conv_responses[$mode][$item['thr-parent']] ++;
1057 if (public_contact() == $item['author-id']) {
1058 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1061 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1063 // there can only be one activity verb per item so if we found anything, we can stop looking
1070 * Format the vote text for a profile item
1072 * @param int $cnt = number of people who vote the item
1073 * @param array $arr = array of pre-linked names of likers/dislikers
1074 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1075 * @param int $id = item id
1076 * @return string formatted text
1077 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1079 function format_like($cnt, array $arr, $type, $id) {
1087 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1088 // list which show all likers
1091 $phrase = L10n::t('%s likes this.', $likers);
1094 $phrase = L10n::t('%s doesn\'t like this.', $likers);
1097 $phrase = L10n::t('%s attends.', $likers);
1100 $phrase = L10n::t('%s doesn\'t attend.', $likers);
1102 case 'attendmaybe' :
1103 $phrase = L10n::t('%s attends maybe.', $likers);
1106 $phrase = L10n::t('%s reshared this.', $likers);
1112 $total = count($arr);
1113 if ($total < MAX_LIKERS) {
1114 $last = L10n::t('and') . ' ' . $arr[count($arr)-1];
1115 $arr2 = array_slice($arr, 0, -1);
1116 $likers = implode(', ', $arr2) . ' ' . $last;
1118 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1119 $likers = implode(', ', $arr);
1120 $likers .= L10n::t('and %d other people', $total - MAX_LIKERS);
1123 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1128 $phrase = L10n::t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
1129 $explikers = L10n::t('%s like this.', $likers);
1132 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
1133 $explikers = L10n::t('%s don\'t like this.', $likers);
1136 $phrase = L10n::t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
1137 $explikers = L10n::t('%s attend.', $likers);
1140 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
1141 $explikers = L10n::t('%s don\'t attend.', $likers);
1144 $phrase = L10n::t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
1145 $explikers = L10n::t('%s attend maybe.', $likers);
1148 $phrase = L10n::t('<span %1$s>%2$d people</span> reshared this', $spanatts, $cnt);
1149 $explikers = L10n::t('%s reshared this.', $likers);
1153 $expanded .= "\t" . '<p class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</p>';
1156 $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
1157 '$phrase' => $phrase,
1166 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1170 $geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
1172 $tpl = Renderer::getMarkupTemplate('jot-header.tpl');
1173 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
1174 '$newpost' => 'true',
1175 '$baseurl' => DI::baseUrl()->get(true),
1176 '$geotag' => $geotag,
1177 '$nickname' => $x['nickname'],
1178 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1179 '$linkurl' => L10n::t('Please enter a image/video/audio/webpage URL:'),
1180 '$term' => L10n::t('Tag term:'),
1181 '$fileas' => L10n::t('Save to Folder:'),
1182 '$whereareu' => L10n::t('Where are you right now?'),
1183 '$delitems' => L10n::t("Delete item\x28s\x29?")
1187 Hook::callAll('jot_tool', $jotplugins);
1189 // Private/public post links for the non-JS ACL form
1191 if (!empty($_REQUEST['public'])) {
1195 $query_str = DI::args()->getQueryString();
1196 if (strpos($query_str, 'public=1') !== false) {
1197 $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
1201 * I think $a->query_string may never have ? in it, but I could be wrong
1202 * It looks like it's from the index.php?q=[etc] rewrite that the web
1203 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1205 if (strpos($query_str, '?') === false) {
1206 $public_post_link = '?public=1';
1208 $public_post_link = '&public=1';
1211 // $tpl = Renderer::replaceMacros($tpl,array('$jotplugins' => $jotplugins));
1212 $tpl = Renderer::getMarkupTemplate("jot.tpl");
1214 $o .= Renderer::replaceMacros($tpl,[
1215 '$new_post' => L10n::t('New Post'),
1216 '$return_path' => $query_str,
1217 '$action' => 'item',
1218 '$share' => ($x['button'] ?? '') ?: L10n::t('Share'),
1219 '$upload' => L10n::t('Upload photo'),
1220 '$shortupload' => L10n::t('upload photo'),
1221 '$attach' => L10n::t('Attach file'),
1222 '$shortattach' => L10n::t('attach file'),
1223 '$edbold' => L10n::t('Bold'),
1224 '$editalic' => L10n::t('Italic'),
1225 '$eduline' => L10n::t('Underline'),
1226 '$edquote' => L10n::t('Quote'),
1227 '$edcode' => L10n::t('Code'),
1228 '$edimg' => L10n::t('Image'),
1229 '$edurl' => L10n::t('Link'),
1230 '$edattach' => L10n::t('Link or Media'),
1231 '$setloc' => L10n::t('Set your location'),
1232 '$shortsetloc' => L10n::t('set location'),
1233 '$noloc' => L10n::t('Clear browser location'),
1234 '$shortnoloc' => L10n::t('clear location'),
1235 '$title' => $x['title'] ?? '',
1236 '$placeholdertitle' => L10n::t('Set title'),
1237 '$category' => $x['category'] ?? '',
1238 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '',
1239 '$wait' => L10n::t('Please wait'),
1240 '$permset' => L10n::t('Permission settings'),
1241 '$shortpermset' => L10n::t('permissions'),
1242 '$wall' => $notes_cid ? 0 : 1,
1243 '$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
1244 '$content' => $x['content'] ?? '',
1245 '$post_id' => $x['post_id'] ?? '',
1246 '$baseurl' => DI::baseUrl()->get(true),
1247 '$defloc' => $x['default_location'],
1248 '$visitor' => $x['visitor'],
1249 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1250 '$public' => L10n::t('Public post'),
1251 '$lockstate' => $x['lockstate'],
1252 '$bang' => $x['bang'],
1253 '$profile_uid' => $x['profile_uid'],
1254 '$preview' => L10n::t('Preview'),
1255 '$jotplugins' => $jotplugins,
1256 '$notes_cid' => $notes_cid,
1257 '$sourceapp' => L10n::t($a->sourcename),
1258 '$cancel' => L10n::t('Cancel'),
1259 '$rand_num' => Crypto::randomDigits(12),
1261 // ACL permissions box
1262 '$acl' => $x['acl'],
1263 '$group_perms' => L10n::t('Post to Groups'),
1264 '$contact_perms' => L10n::t('Post to Contacts'),
1265 '$private' => L10n::t('Private post'),
1266 '$is_private' => $private_post,
1267 '$public_link' => $public_post_link,
1269 //jot nav tab (used in some themes)
1270 '$message' => L10n::t('Message'),
1271 '$browser' => L10n::t('Browser'),
1275 if ($popup == true) {
1276 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1283 * Plucks the children of the given parent from a given item list.
1285 * @param array $item_list
1286 * @param array $parent
1287 * @param bool $recursive
1290 function get_item_children(array &$item_list, array $parent, $recursive = true)
1293 foreach ($item_list as $i => $item) {
1294 if ($item['id'] != $item['parent']) {
1296 // Fallback to parent-uri if thr-parent is not set
1297 $thr_parent = $item['thr-parent'];
1298 if ($thr_parent == '') {
1299 $thr_parent = $item['parent-uri'];
1302 if ($thr_parent == $parent['uri']) {
1303 $item['children'] = get_item_children($item_list, $item);
1304 $children[] = $item;
1305 unset($item_list[$i]);
1307 } elseif ($item['parent'] == $parent['id']) {
1308 $children[] = $item;
1309 unset($item_list[$i]);
1317 * Recursively sorts a tree-like item array
1319 * @param array $items
1322 function sort_item_children(array $items)
1325 usort($result, 'sort_thr_received_rev');
1326 foreach ($result as $k => $i) {
1327 if (isset($result[$k]['children'])) {
1328 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1335 * Recursively add all children items at the top level of a list
1337 * @param array $children List of items to append
1338 * @param array $item_list
1340 function add_children_to_list(array $children, array &$item_list)
1342 foreach ($children as $child) {
1343 $item_list[] = $child;
1344 if (isset($child['children'])) {
1345 add_children_to_list($child['children'], $item_list);
1351 * Selectively flattens a tree-like item structure to prevent threading stairs
1353 * This recursive function takes the item tree structure created by conv_sort() and
1354 * flatten the extraneous depth levels when people reply sequentially, removing the
1355 * stairs effect in threaded conversations limiting the available content width.
1357 * The basic principle is the following: if a post item has only one reply and is
1358 * the last reply of its parent, then the reply is moved to the parent.
1360 * This process is rendered somewhat more complicated because items can be either
1361 * replies or likes, and these don't factor at all in the reply count/last reply.
1363 * @param array $parent A tree-like array of items
1366 function smart_flatten_conversation(array $parent)
1368 if (!isset($parent['children']) || count($parent['children']) == 0) {
1372 // We use a for loop to ensure we process the newly-moved items
1373 for ($i = 0; $i < count($parent['children']); $i++) {
1374 $child = $parent['children'][$i];
1376 if (isset($child['children']) && count($child['children'])) {
1377 // This helps counting only the regular posts
1378 $count_post_closure = function($var) {
1379 return $var['verb'] === Activity::POST;
1382 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1384 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1386 // If there's only one child's children post and this is the last child post
1387 if ($child_post_count == 1 && $remaining_post_count == 1) {
1389 // Searches the post item in the children
1391 while($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
1395 $moved_item = $child['children'][$j];
1396 unset($parent['children'][$i]['children'][$j]);
1397 $parent['children'][] = $moved_item;
1399 $parent['children'][$i] = smart_flatten_conversation($child);
1409 * Expands a flat list of items into corresponding tree-like conversation structures.
1411 * sort the top-level posts either on "received" or "commented", and finally
1412 * append all the items at the top level (???)
1414 * @param array $item_list A list of items belonging to one or more conversations
1415 * @param string $order Either on "received" or "commented"
1417 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1419 function conv_sort(array $item_list, $order)
1423 if (!(is_array($item_list) && count($item_list))) {
1427 $blocklist = conv_get_blocklist();
1431 // Dedupes the item list on the uri to prevent infinite loops
1432 foreach ($item_list as $item) {
1433 if (in_array($item['author-id'], $blocklist)) {
1437 $item_array[$item['uri']] = $item;
1440 // Extract the top level items
1441 foreach ($item_array as $item) {
1442 if ($item['id'] == $item['parent']) {
1447 if (stristr($order, 'pinned_received')) {
1448 usort($parents, 'sort_thr_pinned_received');
1449 } elseif (stristr($order, 'received')) {
1450 usort($parents, 'sort_thr_received');
1451 } elseif (stristr($order, 'commented')) {
1452 usort($parents, 'sort_thr_commented');
1456 * Plucks children from the item_array, second pass collects eventual orphan
1457 * items and add them as children of their top-level post.
1459 foreach ($parents as $i => $parent) {
1460 $parents[$i]['children'] =
1461 array_merge(get_item_children($item_array, $parent, true),
1462 get_item_children($item_array, $parent, false));
1465 foreach ($parents as $i => $parent) {
1466 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1469 if (!DI::pConfig()->get(local_user(), 'system', 'no_smart_threading', 0)) {
1470 foreach ($parents as $i => $parent) {
1471 $parents[$i] = smart_flatten_conversation($parent);
1475 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1476 /// However, this apparently ensures responses (likes, attendance) display (?!)
1477 foreach ($parents as $parent) {
1478 if (count($parent['children'])) {
1479 add_children_to_list($parent['children'], $parents);
1487 * usort() callback to sort item arrays by pinned and the received key
1493 function sort_thr_pinned_received(array $a, array $b)
1495 if ($b['pinned'] && !$a['pinned']) {
1497 } elseif (!$b['pinned'] && $a['pinned']) {
1501 return strcmp($b['received'], $a['received']);
1505 * usort() callback to sort item arrays by the received key
1511 function sort_thr_received(array $a, array $b)
1513 return strcmp($b['received'], $a['received']);
1517 * usort() callback to reverse sort item arrays by the received key
1523 function sort_thr_received_rev(array $a, array $b)
1525 return strcmp($a['received'], $b['received']);
1529 * usort() callback to sort item arrays by the commented key
1535 function sort_thr_commented(array $a, array $b)
1537 return strcmp($b['commented'], $a['commented']);
1540 function render_location_dummy(array $item) {
1541 if (!empty($item['location']) && !empty($item['location'])) {
1542 return $item['location'];
1545 if (!empty($item['coord']) && !empty($item['coord'])) {
1546 return $item['coord'];
1550 function get_responses(array $conv_responses, array $response_verbs, array $item, Post $ob = null) {
1552 foreach ($response_verbs as $v) {
1554 $ret[$v]['count'] = $conv_responses[$v][$item['uri']] ?? 0;
1555 $ret[$v]['list'] = $conv_responses[$v][$item['uri'] . '-l'] ?? [];
1556 $ret[$v]['self'] = $conv_responses[$v][$item['uri'] . '-self'] ?? '0';
1557 if (count($ret[$v]['list']) > MAX_LIKERS) {
1558 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1559 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1560 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . L10n::t('View all') . '</b></a>');
1562 $ret[$v]['list_part'] = '';
1564 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1565 $ret[$v]['title'] = $conv_responses[$v]['title'];
1569 foreach ($ret as $key) {
1570 if ($key['count'] == true) {
1574 $ret['count'] = $count;
1579 function get_response_button_text($v, $count)
1584 $return = L10n::tt('Like', 'Likes', $count);
1587 $return = L10n::tt('Dislike', 'Dislikes', $count);
1590 $return = L10n::tt('Attending', 'Attending', $count);
1593 $return = L10n::tt('Not Attending', 'Not Attending', $count);
1596 $return = L10n::tt('Undecided', 'Undecided', $count);