3 * @file include/conversation.php
6 use Friendica\Content\ContactSelector;
7 use Friendica\Content\Feature;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\System;
13 use Friendica\Database\DBM;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Profile;
16 use Friendica\Object\Thread;
17 use Friendica\Object\Post;
18 use Friendica\Util\XML;
20 require_once "include/bbcode.php";
21 require_once "include/acl_selectors.php";
23 function item_extract_images($body) {
30 $img_start = strpos($orig_body, '[img');
31 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
32 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
33 while (($img_st_close !== false) && ($img_end !== false)) {
35 $img_st_close++; // make it point to AFTER the closing bracket
36 $img_end += $img_start;
38 if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
39 // This is an embedded image
41 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
42 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
46 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
49 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
51 if ($orig_body === false) {
52 // in case the body ends on a closing image tag
56 $img_start = strpos($orig_body, '[img');
57 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
58 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
61 $new_body = $new_body . $orig_body;
63 return ['body' => $new_body, 'images' => $saved_image];
66 function item_redir_and_replace_images($body, $images, $cid) {
72 $pos = get_bb_tag_pos($origbody, 'url', 1);
73 while ($pos !== false && $cnt < 1000) {
75 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
76 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
77 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
79 $newbody .= substr($origbody, 0, $pos['start']['open']);
80 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
81 $origbody = substr($origbody, $pos['end']['close']);
82 if ($origbody === false) {
86 $subject = preg_replace($search, $replace, $subject);
90 $pos = get_bb_tag_pos($origbody, 'url', 1);
92 $newbody .= $origbody;
95 foreach ($images as $image) {
97 * We're depending on the property of 'foreach' (specified on the PHP website) that
98 * it loops over the array starting from the first element and going sequentially
99 * to the last element.
101 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
108 * Render actions localized
110 function localize_item(&$item) {
112 $extracted = item_extract_images($item['body']);
113 if ($extracted['images']) {
114 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
118 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
119 if (activity_match($item['verb'], ACTIVITY_LIKE)
120 || activity_match($item['verb'], ACTIVITY_DISLIKE)
121 || activity_match($item['verb'], ACTIVITY_ATTEND)
122 || activity_match($item['verb'], ACTIVITY_ATTENDNO)
123 || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
125 /// @TODO may hurt performance
126 $r = q("SELECT * FROM `item`, `contact`
127 WHERE `item`.`contact-id`=`contact`.`id`
128 AND `item`.`uri`='%s'",
129 dbesc($item['parent-uri']));
130 if (!DBM::is_result($r)) {
135 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
136 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
138 switch ($obj['verb']) {
140 switch ($obj['object-type']) {
141 case ACTIVITY_OBJ_EVENT:
142 $post_type = L10n::t('event');
145 $post_type = L10n::t('status');
149 if ($obj['resource-id']) {
150 $post_type = L10n::t('photo');
152 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
153 $rr['plink'] = $m[1];
155 $post_type = L10n::t('status');
159 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
161 if (activity_match($item['verb'], ACTIVITY_LIKE)) {
162 $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
164 elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
165 $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
167 elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
168 $bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
170 elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
171 $bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
173 elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
174 $bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
176 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
179 if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
181 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
183 $Aname = $item['author-name'];
184 $Alink = $item['author-link'];
186 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
188 $obj = XML::parseString($xmlhead.$item['object']);
189 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
191 $Bname = $obj->title;
192 $Blink = ""; $Bphoto = "";
193 foreach ($links->link as $l) {
194 $atts = $l->attributes();
195 switch ($atts['rel']) {
196 case "alternate": $Blink = $atts['href'];
197 case "photo": $Bphoto = $atts['href'];
201 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
202 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
204 $Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
207 $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
210 if (stristr($item['verb'], ACTIVITY_POKE)) {
211 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
215 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
219 $Aname = $item['author-name'];
220 $Alink = $item['author-link'];
222 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
224 $obj = XML::parseString($xmlhead.$item['object']);
225 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
227 $Bname = $obj->title;
230 foreach ($links->link as $l) {
231 $atts = $l->attributes();
232 switch ($atts['rel']) {
233 case "alternate": $Blink = $atts['href'];
234 case "photo": $Bphoto = $atts['href'];
238 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
239 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
241 $Bphoto = '[url=' . Profile::zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
245 * we can't have a translation string with three positions but no distinguishable text
246 * So here is the translate string.
248 $txt = L10n::t('%1$s poked %2$s');
250 // now translate the verb
251 $poked_t = trim(sprintf($txt, "", ""));
252 $txt = str_replace( $poked_t, L10n::t($verb), $txt);
254 // then do the sprintf on the translation string
256 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
260 if (activity_match($item['verb'], ACTIVITY_TAG)) {
261 /// @TODO may hurt performance "joining" two tables + asterisk
262 $r = q("SELECT * FROM `item`, `contact`
263 WHERE `item`.`contact-id`=`contact`.`id`
264 AND `item`.`uri`='%s'",
265 dbesc($item['parent-uri']));
267 if (!DBM::is_result($r)) {
273 $author = '[url=' . Profile::zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
274 $objauthor = '[url=' . Profile::zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
276 switch ($obj['verb']) {
278 switch ($obj['object-type']) {
279 case ACTIVITY_OBJ_EVENT:
280 $post_type = L10n::t('event');
283 $post_type = L10n::t('status');
287 if ($obj['resource-id']) {
288 $post_type = L10n::t('photo');
289 $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
290 $rr['plink'] = $m[1];
292 $post_type = L10n::t('status');
294 // Let's break everthing ... ;-)
297 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
299 $parsedobj = XML::parseString($xmlhead.$item['object']);
301 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
302 $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
305 if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
307 if ($item['object-type'] == "") {
311 $Aname = $item['author-name'];
312 $Alink = $item['author-link'];
314 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
316 $obj = XML::parseString($xmlhead.$item['object']);
317 if (strlen($obj->id)) {
318 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
323 if (DBM::is_result($r) && $r[0]['plink']) {
325 $Bname = $target['author-name'];
326 $Blink = $target['author-link'];
327 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
328 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
329 $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
330 $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
335 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
336 foreach ($matches as $mtch) {
337 if (! strpos($mtch[1], 'zrl=')) {
338 $item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']);
343 // add zrl's to public images
344 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
345 if (preg_match($photo_pattern, $item['body'])) {
346 $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
347 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
350 // add sparkle links to appropriate permalinks
352 $x = stristr($item['plink'],'/display/');
355 $y = best_link_url($item, $sparkle);
357 if (strstr($y, '/redir/')) {
358 $item['plink'] = $y . '?f=&url=' . $item['plink'];
364 * Count the total of comments on this item and its desendants
365 * @TODO proper type-hint + doc-tag
367 function count_descendants($item) {
368 $total = count($item['children']);
371 foreach ($item['children'] as $child) {
372 if (! visible_activity($child)) {
375 $total += count_descendants($child);
382 function visible_activity($item) {
385 * likes (etc.) can apply to other things besides posts. Check if they are post children,
386 * in which case we handle them specially
388 $hidden_activities = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
389 foreach ($hidden_activities as $act) {
390 if (activity_match($item['verb'], $act)) {
395 if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
396 if (! (($item['self']) && ($item['uid'] == local_user()))) {
405 * @brief SQL query for items
407 function item_query() {
408 return "SELECT " . item_fieldlists() . " FROM `item` " .
409 item_joins() . " WHERE " . item_condition();
413 * @brief List of all data fields that are needed for displaying items
415 function item_fieldlists() {
418 These Fields are not added below (yet). They are here to for bug search.
423 `item`.`target-type`,
425 `item`.`resource-id`,
438 `item`.`gcontact-id`,
442 return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
443 `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
444 `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
445 `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
446 `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
447 `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
448 `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
449 `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
450 `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
451 `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
452 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
453 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
455 `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
457 `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
458 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
460 `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
461 `event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
462 `event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
463 `event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
464 `event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
465 `event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
469 * @brief SQL join for contacts that are needed for displaying items
471 function item_joins() {
472 return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
473 (NOT `contact`.`blocked` OR `contact`.`pending`)
474 LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
475 LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`
476 LEFT JOIN `event` ON `event-id` = `event`.`id`";
480 * @brief SQL condition for items that are needed for displaying items
482 function item_condition() {
483 return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
487 * "Render" a conversation or list of items for HTML display.
488 * There are two major forms of display:
489 * - Sequential or unthreaded ("New Item View" or search results)
490 * - conversation view
491 * The $mode parameter decides between the various renderings and also
492 * figures out how to determine page owner and other contextual items
493 * that are based on unique features of the calling module.
496 function conversation(App $a, $items, $mode, $update, $preview = false) {
497 require_once 'include/bbcode.php';
498 require_once 'mod/proxy.php';
500 $ssl_state = ((local_user()) ? true : false);
503 $live_update_div = '';
508 $str_blocked = PConfig::get(local_user(), 'system', 'blocked');
510 $arr_blocked = explode(',', $str_blocked);
511 for ($x = 0; $x < count($arr_blocked); $x ++) {
512 $arr_blocked[$x] = trim($arr_blocked[$x]);
518 $previewing = (($preview) ? ' preview ' : '');
520 if ($mode === 'network') {
521 $profile_owner = local_user();
524 * The special div is needed for liveUpdate to kick in for this page.
525 * We only launch liveUpdate if you aren't filtering in some incompatible
526 * way and also you aren't writing a comment (discovered in javascript).
528 $live_update_div = '<div id="live-network"></div>' . "\r\n"
529 . "<script> var profile_uid = " . $_SESSION['uid']
530 . "; var netargs = '" . substr($a->cmd, 8)
532 . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
533 . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
534 . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
535 . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
536 . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
537 . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
538 . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
539 . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
540 . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
541 . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
542 . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
543 . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
545 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
547 } elseif ($mode === 'profile') {
548 $profile_owner = $a->profile['profile_uid'];
552 if (x($_GET, 'tab')) {
553 $tab = notags(trim($_GET['tab']));
555 if ($tab === 'posts') {
557 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
558 * because browser prefetching might change it on us. We have to deliver it with the page.
561 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
562 . "<script> var profile_uid = " . $a->profile['profile_uid']
563 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
566 } elseif ($mode === 'notes') {
567 $profile_owner = local_user();
569 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
570 . "<script> var profile_uid = " . local_user()
571 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
573 } elseif ($mode === 'display') {
574 $profile_owner = $a->profile['uid'];
576 $live_update_div = '<div id="live-display"></div>' . "\r\n"
577 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
578 . " var profile_page = 1; </script>";
580 } elseif ($mode === 'community') {
581 $items = community_add_items($items);
584 $live_update_div = '<div id="live-community"></div>' . "\r\n"
585 . "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
586 ."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
588 } elseif ($mode === 'search') {
589 $live_update_div = '<div id="live-search"></div>' . "\r\n";
592 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
595 $_SESSION['return_url'] = $a->query_string;
598 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
599 Addon::callHooks('conversation_start',$cb);
601 $items = $cb['items'];
604 'like' => ['title' => L10n::t('Likes','title')], 'dislike' => ['title' => L10n::t('Dislikes','title')],
605 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
608 // array with html for each thread (parent+comments)
612 $page_template = get_markup_template("conversation.tpl");
614 if ($items && count($items)) {
615 if ($mode === 'community') {
618 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
625 if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
628 * "New Item View" on network page or search page results
629 * - just loop through the items and format them minimally for display
632 $tpl = 'search_item.tpl';
634 foreach ($items as $item) {
638 foreach ($arr_blocked as $b) {
639 if ($b && link_compare($item['author-link'], $b)) {
656 // prevent private email from leaking.
657 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
661 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
662 if ($item['author-link'] && (! $item['author-name'])) {
663 $profile_name = $item['author-link'];
670 $searchpath = System::baseUrl()."/search?tag=";
672 $taglist = dba::select('term', ['type', 'term', 'url'],
673 ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
674 ['order' => ['tid']]);
676 while ($tag = dba::fetch($taglist)) {
677 if ($tag["url"] == "") {
678 $tag["url"] = $searchpath . strtolower($tag["term"]);
681 $tag["url"] = best_link_url($item, $sp, $tag["url"]);
683 if ($tag["type"] == TERM_HASHTAG) {
684 $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
686 } elseif ($tag["type"] == TERM_MENTION) {
687 $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
690 $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
692 dba::close($taglist);
695 $profile_link = best_link_url($item, $sp);
696 if ($profile_link === 'mailbox') {
701 $sparkle = ' sparkle';
703 $profile_link = Profile::zrl($profile_link);
706 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
707 $author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
708 if ($author_contact["thumb"]) {
709 $item['author-thumb'] = $author_contact["thumb"];
711 $item['author-thumb'] = $item['author-avatar'];
715 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
716 $owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
717 if ($owner_contact["thumb"]) {
718 $item['owner-thumb'] = $owner_contact["thumb"];
720 $item['owner-thumb'] = $item['owner-avatar'];
724 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
725 Addon::callHooks('render_location',$locate);
727 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
729 localize_item($item);
730 if ($mode === 'network-new') {
737 'dropping' => $dropping,
738 'pagedrop' => $page_dropping,
739 'select' => L10n::t('Select'),
740 'delete' => L10n::t('Delete'),
744 $isstarred = "unstarred";
747 $likebuttons = false;
749 $body = prepare_body($item, true, $preview);
751 list($categories, $folders) = get_cats_and_terms($item);
753 $profile_name_e = $profile_name;
754 $item['title_e'] = $item['title'];
757 $hashtags_e = $hashtags;
758 $mentions_e = $mentions;
759 $location_e = $location;
760 $owner_name_e = $owner_name;
762 if ($item['item_network'] == "") {
763 $item['item_network'] = $item['network'];
768 'id' => (($preview) ? 'P0' : $item['item_id']),
769 'guid' => (($preview) ? 'Q0' : $item['guid']),
770 'network' => $item['item_network'],
771 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
772 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
773 'profile_url' => $profile_link,
774 'item_photo_menu' => item_photo_menu($item),
775 'name' => $profile_name_e,
776 'sparkle' => $sparkle,
778 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
779 'title' => $item['title_e'],
782 'hashtags' => $hashtags_e,
783 'mentions' => $mentions_e,
784 'txt_cats' => L10n::t('Categories:'),
785 'txt_folders' => L10n::t('Filed under:'),
786 'has_cats' => ((count($categories)) ? 'true' : ''),
787 'has_folders' => ((count($folders)) ? 'true' : ''),
788 'categories' => $categories,
789 'folders' => $folders,
790 'text' => strip_tags($body_e),
791 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
792 'ago' => (($item['app']) ? L10n::t('%s from %s', relative_date($item['created']),$item['app']) : relative_date($item['created'])),
793 'location' => $location_e,
795 'owner_name' => $owner_name_e,
796 'owner_url' => $owner_url,
797 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
798 'plink' => get_plink($item),
800 'isstarred' => $isstarred,
803 'vote' => $likebuttons,
807 'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> L10n::t('View in context')]),
808 'previewing' => $previewing,
809 'wait' => L10n::t('Please wait'),
813 $arr = ['item' => $item, 'output' => $tmp_item];
814 Addon::callHooks('display_item', $arr);
816 $threads[$threadsid]['id'] = $item['item_id'];
817 $threads[$threadsid]['network'] = $item['item_network'];
818 $threads[$threadsid]['items'] = [$arr['output']];
823 $page_template = get_markup_template("threaded_conversation.tpl");
825 $conv = new Thread($mode, $preview, $writable);
828 * get all the topmost parents
829 * this shouldn't be needed, as we should have only them in our array
830 * But for now, this array respects the old style, just in case
832 foreach ($items as $item) {
835 foreach ($arr_blocked as $b) {
836 if ($b && link_compare($item['author-link'], $b)) {
846 // Can we put this after the visibility check?
847 builtin_activity_puller($item, $conv_responses);
849 // Only add what is visible
850 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
854 if (! visible_activity($item)) {
858 Addon::callHooks('display_item', $arr);
860 $item['pagedrop'] = $page_dropping;
862 if ($item['id'] == $item['parent']) {
863 $item_object = new Post($item);
864 $conv->addParent($item_object);
868 $threads = $conv->getTemplateData($conv_responses);
870 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
876 $o = replace_macros($page_template, [
877 '$baseurl' => System::baseUrl($ssl_state),
878 '$return_path' => $a->query_string,
879 '$live_update' => $live_update_div,
880 '$remove' => L10n::t('remove'),
883 '$threads' => $threads,
884 '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? L10n::t('Delete Selected Items') : False),
891 * @brief Add comments to top level entries that had been fetched before
893 * The system will fetch the comments for the local user whenever possible.
894 * This behaviour is currently needed to allow commenting on Friendica posts.
896 * @param array $parents Parent items
898 * @return array items with parents and comments
900 function community_add_items($parents) {
901 $max_comments = Config::get("system", "max_comments", 100);
905 foreach ($parents AS $parent) {
906 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
907 AND `item`.`parent-uri` = ?
908 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
912 $comments = dba::inArray($thread_items);
914 // Check if the original item is in the result.
915 // When commenting from the community page there can be incomplete threads
916 if (count($comments) > 0) {
917 $parent_found = false;
918 foreach ($comments as $comment) {
919 if ($comment['uri'] == $comment['parent-uri']) {
920 $parent_found = true;
924 if (!$parent_found) {
929 if (count($comments) == 0) {
930 $thread_items = dba::p(item_query()." AND `item`.`uid` = 0
931 AND `item`.`parent-uri` = ?
932 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
935 $comments = dba::inArray($thread_items);
938 if (count($comments) != 0) {
939 $items = array_merge($items, $comments);
943 foreach ($items as $index => $item) {
944 if ($item['uid'] == 0) {
945 $items[$index]['writable'] = in_array($item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
949 $items = conv_sort($items, "`commented`");
954 function best_link_url($item, &$sparkle, $url = '') {
959 $clean_url = normalise_link($item['author-link']);
963 'network' => NETWORK_DFRN,
964 'uid' => local_user(),
965 'nurl' => normalise_link($clean_url),
968 $contact = dba::selectFirst('contact', ['id'], $condition);
969 if (DBM::is_result($contact)) {
970 $best_url = 'redir/' . $contact['id'];
973 $hostname = get_app()->get_hostname();
974 if (!strstr($url, $hostname)) {
975 $best_url .= "?url=".$url;
985 } elseif (strlen($item['author-link'])) {
986 $best_url = $item['author-link'];
988 $best_url = $item['url'];
996 function item_photo_menu($item) {
1005 if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
1006 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
1010 $profile_link = best_link_url($item, $sparkle);
1011 if ($profile_link === 'mailbox') {
1018 $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
1019 $contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
1020 if (DBM::is_result($contact)) {
1021 $cid = $contact['id'];
1022 $network = $contact['network'];
1023 $rel = $contact['rel'];
1027 $status_link = $profile_link . '?url=status';
1028 $photos_link = $profile_link . '?url=photos';
1029 $profile_link = $profile_link . '?url=profile';
1031 $profile_link = Profile::zrl($profile_link);
1034 if ($cid && !$item['self']) {
1035 $poke_link = 'poke/?f=&c=' . $cid;
1036 $contact_url = 'contacts/' . $cid;
1037 $posts_link = 'contacts/' . $cid . '/posts';
1039 if (in_array($network, [NETWORK_DFRN, NETWORK_DIASPORA])) {
1040 $pm_url = 'message/new/' . $cid;
1046 L10n::t('Follow Thread') => $sub_link,
1047 L10n::t('View Status') => $status_link,
1048 L10n::t('View Profile') => $profile_link,
1049 L10n::t('View Photos') => $photos_link,
1050 L10n::t('Network Posts') => $posts_link,
1051 L10n::t('View Contact') => $contact_url,
1052 L10n::t('Send PM') => $pm_url
1055 if ($network == NETWORK_DFRN) {
1056 $menu[L10n::t("Poke")] = $poke_link;
1059 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
1060 in_array($item['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])) {
1061 $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
1064 $menu = [L10n::t('View Profile') => $item['author-link']];
1067 $args = ['item' => $item, 'menu' => $menu];
1069 Addon::callHooks('item_photo_menu', $args);
1071 $menu = $args['menu'];
1074 foreach ($menu as $k => $v) {
1075 if (strpos($v, 'javascript:') === 0) {
1076 $v = substr($v, 11);
1077 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1079 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1086 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1087 * Increments the count of each matching activity and adds a link to the author as needed.
1089 * @param array $item
1090 * @param array &$conv_responses (already created with builtin activity structure)
1093 function builtin_activity_puller($item, &$conv_responses) {
1094 foreach ($conv_responses as $mode => $v) {
1100 $verb = ACTIVITY_LIKE;
1103 $verb = ACTIVITY_DISLIKE;
1106 $verb = ACTIVITY_ATTEND;
1109 $verb = ACTIVITY_ATTENDNO;
1112 $verb = ACTIVITY_ATTENDMAYBE;
1118 if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1119 $url = $item['author-link'];
1120 if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
1121 $url = 'redir/' . $item['contact-id'];
1122 $sparkle = ' class="sparkle" ';
1124 $url = Profile::zrl($url);
1127 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1129 if (! $item['thr-parent']) {
1130 $item['thr-parent'] = $item['parent-uri'];
1133 if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1134 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
1135 $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
1138 // only list each unique author once
1139 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1143 if (! isset($conv_responses[$mode][$item['thr-parent']])) {
1144 $conv_responses[$mode][$item['thr-parent']] = 1;
1146 $conv_responses[$mode][$item['thr-parent']] ++;
1149 if (public_contact() == $item['author-id']) {
1150 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1153 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1155 // there can only be one activity verb per item so if we found anything, we can stop looking
1162 * Format the vote text for a profile item
1163 * @param int $cnt = number of people who vote the item
1164 * @param array $arr = array of pre-linked names of likers/dislikers
1165 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1166 * @param int $id = item id
1167 * @return formatted text
1169 function format_like($cnt, array $arr, $type, $id) {
1176 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1177 // list which show all likers
1180 $phrase = L10n::t('%s likes this.', $likers);
1183 $phrase = L10n::t('%s doesn\'t like this.', $likers);
1186 $phrase = L10n::t('%s attends.', $likers);
1189 $phrase = L10n::t('%s doesn\'t attend.', $likers);
1191 case 'attendmaybe' :
1192 $phrase = L10n::t('%s attends maybe.', $likers);
1198 $total = count($arr);
1199 if ($total >= MAX_LIKERS) {
1200 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1202 if ($total < MAX_LIKERS) {
1203 $last = L10n::t('and') . ' ' . $arr[count($arr)-1];
1204 $arr2 = array_slice($arr, 0, -1);
1205 $str = implode(', ', $arr2) . ' ' . $last;
1207 if ($total >= MAX_LIKERS) {
1208 $str = implode(', ', $arr);
1209 $str .= L10n::t('and %d other people', $total - MAX_LIKERS );
1214 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1218 $phrase = L10n::t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
1219 $explikers = L10n::t('%s like this.', $likers);
1222 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
1223 $explikers = L10n::t('%s don\'t like this.', $likers);
1226 $phrase = L10n::t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
1227 $explikers = L10n::t('%s attend.', $likers);
1230 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
1231 $explikers = L10n::t('%s don\'t attend.', $likers);
1234 $phrase = L10n::t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
1235 $explikers = L10n::t('%s anttend maybe.', $likers);
1239 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1243 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), [
1244 '$phrase' => $phrase,
1253 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1257 $geotag = x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), []) : '';
1259 $tpl = get_markup_template('jot-header.tpl');
1260 $a->page['htmlhead'] .= replace_macros($tpl, [
1261 '$newpost' => 'true',
1262 '$baseurl' => System::baseUrl(true),
1263 '$geotag' => $geotag,
1264 '$nickname' => $x['nickname'],
1265 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1266 '$linkurl' => L10n::t('Please enter a link URL:'),
1267 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1268 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1269 '$term' => L10n::t('Tag term:'),
1270 '$fileas' => L10n::t('Save to Folder:'),
1271 '$whereareu' => L10n::t('Where are you right now?'),
1272 '$delitems' => L10n::t("Delete item\x28s\x29?")
1275 $tpl = get_markup_template('jot-end.tpl');
1276 $a->page['end'] .= replace_macros($tpl, [
1277 '$newpost' => 'true',
1278 '$baseurl' => System::baseUrl(true),
1279 '$geotag' => $geotag,
1280 '$nickname' => $x['nickname'],
1281 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1282 '$linkurl' => L10n::t('Please enter a link URL:'),
1283 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1284 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1285 '$term' => L10n::t('Tag term:'),
1286 '$fileas' => L10n::t('Save to Folder:'),
1287 '$whereareu' => L10n::t('Where are you right now?')
1291 Addon::callHooks('jot_tool', $jotplugins);
1293 // Private/public post links for the non-JS ACL form
1295 if (x($_REQUEST, 'public')) {
1299 $query_str = $a->query_string;
1300 if (strpos($query_str, 'public=1') !== false) {
1301 $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
1305 * I think $a->query_string may never have ? in it, but I could be wrong
1306 * It looks like it's from the index.php?q=[etc] rewrite that the web
1307 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1309 if (strpos($query_str, '?') === false) {
1310 $public_post_link = '?public=1';
1312 $public_post_link = '&public=1';
1315 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1316 $tpl = get_markup_template("jot.tpl");
1318 $o .= replace_macros($tpl,[
1319 '$return_path' => $query_str,
1320 '$action' => 'item',
1321 '$share' => defaults($x, 'button', L10n::t('Share')),
1322 '$upload' => L10n::t('Upload photo'),
1323 '$shortupload' => L10n::t('upload photo'),
1324 '$attach' => L10n::t('Attach file'),
1325 '$shortattach' => L10n::t('attach file'),
1326 '$weblink' => L10n::t('Insert web link'),
1327 '$shortweblink' => L10n::t('web link'),
1328 '$video' => L10n::t('Insert video link'),
1329 '$shortvideo' => L10n::t('video link'),
1330 '$audio' => L10n::t('Insert audio link'),
1331 '$shortaudio' => L10n::t('audio link'),
1332 '$setloc' => L10n::t('Set your location'),
1333 '$shortsetloc' => L10n::t('set location'),
1334 '$noloc' => L10n::t('Clear browser location'),
1335 '$shortnoloc' => L10n::t('clear location'),
1336 '$title' => defaults($x, 'title', ''),
1337 '$placeholdertitle' => L10n::t('Set title'),
1338 '$category' => defaults($x, 'category', ''),
1339 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '',
1340 '$wait' => L10n::t('Please wait'),
1341 '$permset' => L10n::t('Permission settings'),
1342 '$shortpermset' => L10n::t('permissions'),
1343 '$ptyp' => $notes_cid ? 'note' : 'wall',
1344 '$content' => defaults($x, 'content', ''),
1345 '$post_id' => defaults($x, 'post_id', ''),
1346 '$baseurl' => System::baseUrl(true),
1347 '$defloc' => $x['default_location'],
1348 '$visitor' => $x['visitor'],
1349 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1350 '$public' => L10n::t('Public post'),
1351 '$lockstate' => $x['lockstate'],
1352 '$bang' => $x['bang'],
1353 '$profile_uid' => $x['profile_uid'],
1354 '$preview' => Feature::isEnabled($x['profile_uid'], 'preview') ? L10n::t('Preview') : '',
1355 '$jotplugins' => $jotplugins,
1356 '$notes_cid' => $notes_cid,
1357 '$sourceapp' => L10n::t($a->sourcename),
1358 '$cancel' => L10n::t('Cancel'),
1359 '$rand_num' => random_digits(12),
1361 // ACL permissions box
1362 '$acl' => $x['acl'],
1363 '$group_perms' => L10n::t('Post to Groups'),
1364 '$contact_perms' => L10n::t('Post to Contacts'),
1365 '$private' => L10n::t('Private post'),
1366 '$is_private' => $private_post,
1367 '$public_link' => $public_post_link,
1369 //jot nav tab (used in some themes)
1370 '$message' => L10n::t('Message'),
1371 '$browser' => L10n::t('Browser'),
1375 if ($popup == true) {
1376 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1383 * Plucks the children of the given parent from a given item list.
1385 * @brief Plucks all the children in the given item list of the given parent
1387 * @param array $item_list
1388 * @param array $parent
1389 * @param bool $recursive
1392 function get_item_children(array &$item_list, array $parent, $recursive = true)
1395 foreach ($item_list as $i => $item) {
1396 if ($item['id'] != $item['parent']) {
1398 // Fallback to parent-uri if thr-parent is not set
1399 $thr_parent = $item['thr-parent'];
1400 if ($thr_parent == '') {
1401 $thr_parent = $item['parent-uri'];
1404 if ($thr_parent == $parent['uri']) {
1405 $item['children'] = get_item_children($item_list, $item);
1406 $children[] = $item;
1407 unset($item_list[$i]);
1409 } elseif ($item['parent'] == $parent['id']) {
1410 $children[] = $item;
1411 unset($item_list[$i]);
1419 * @brief Recursively sorts a tree-like item array
1421 * @param array $items
1424 function sort_item_children(array $items)
1427 usort($result, 'sort_thr_created_rev');
1428 foreach ($result as $k => $i) {
1429 if (isset($result[$k]['children'])) {
1430 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1437 * @brief Recursively add all children items at the top level of a list
1439 * @param array $children List of items to append
1440 * @param array $item_list
1442 function add_children_to_list(array $children, array &$item_list)
1444 foreach ($children as $child) {
1445 $item_list[] = $child;
1446 if (isset($child['children'])) {
1447 add_children_to_list($child['children'], $item_list);
1453 * This recursive function takes the item tree structure created by conv_sort() and
1454 * flatten the extraneous depth levels when people reply sequentially, removing the
1455 * stairs effect in threaded conversations limiting the available content width.
1457 * The basic principle is the following: if a post item has only one reply and is
1458 * the last reply of its parent, then the reply is moved to the parent.
1460 * This process is rendered somewhat more complicated because items can be either
1461 * replies or likes, and these don't factor at all in the reply count/last reply.
1463 * @brief Selectively flattens a tree-like item structure to prevent threading stairs
1465 * @param array $parent A tree-like array of items
1468 function smart_flatten_conversation(array $parent)
1470 if (! isset($parent['children']) || count($parent['children']) == 0) {
1474 // We use a for loop to ensure we process the newly-moved items
1475 for ($i = 0; $i < count($parent['children']); $i++) {
1476 $child = $parent['children'][$i];
1478 if (isset($child['children']) && count($child['children'])) {
1479 // This helps counting only the regular posts
1480 $count_post_closure = function($var) {
1481 return $var['verb'] === ACTIVITY_POST;
1484 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1486 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1488 // If there's only one child's children post and this is the last child post
1489 if ($child_post_count == 1 && $remaining_post_count == 1) {
1491 // Searches the post item in the children
1493 while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
1497 $moved_item = $child['children'][$j];
1498 unset($parent['children'][$i]['children'][$j]);
1499 $parent['children'][] = $moved_item;
1501 $parent['children'][$i] = smart_flatten_conversation($child);
1511 * Expands a flat list of items into corresponding tree-like conversation structures,
1512 * sort the top-level posts either on "created" or "commented", and finally
1513 * append all the items at the top level (???)
1515 * @brief Expands a flat item list into a conversation array for display
1517 * @param array $item_list A list of items belonging to one or more conversations
1518 * @param string $order Either on "created" or "commented"
1521 function conv_sort(array $item_list, $order)
1525 if (!(is_array($item_list) && count($item_list))) {
1531 // Dedupes the item list on the uri to prevent infinite loops
1532 foreach ($item_list as $item) {
1533 $item_array[$item['uri']] = $item;
1536 // Extract the top level items
1537 foreach ($item_array as $item) {
1538 if ($item['id'] == $item['parent']) {
1543 if (stristr($order, 'created')) {
1544 usort($parents, 'sort_thr_created');
1545 } elseif (stristr($order, 'commented')) {
1546 usort($parents, 'sort_thr_commented');
1550 * Plucks children from the item_array, second pass collects eventual orphan
1551 * items and add them as children of their top-level post.
1553 foreach ($parents as $i => $parent) {
1554 $parents[$i]['children'] =
1555 array_merge(get_item_children($item_array, $parent, true),
1556 get_item_children($item_array, $parent, false));
1559 foreach ($parents as $i => $parent) {
1560 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1563 if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
1564 foreach ($parents as $i => $parent) {
1565 $parents[$i] = smart_flatten_conversation($parent);
1569 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1570 /// However, this apparently ensures responses (likes, attendance) display (?!)
1571 foreach ($parents as $parent) {
1572 if (count($parent['children'])) {
1573 add_children_to_list($parent['children'], $parents);
1581 * @brief usort() callback to sort item arrays by the created key
1587 function sort_thr_created(array $a, array $b)
1589 return strcmp($b['created'], $a['created']);
1593 * @brief usort() callback to reverse sort item arrays by the created key
1599 function sort_thr_created_rev(array $a, array $b)
1601 return strcmp($a['created'], $b['created']);
1605 * @brief usort() callback to sort item arrays by the commented key
1611 function sort_thr_commented(array $a, array $b)
1613 return strcmp($b['commented'], $a['commented']);
1616 /// @TODO Add type-hint
1617 function render_location_dummy($item) {
1618 if ($item['location'] != "") {
1619 return $item['location'];
1622 if ($item['coord'] != "") {
1623 return $item['coord'];
1627 /// @TODO Add type-hint
1628 function get_responses($conv_responses, $response_verbs, $ob, $item) {
1630 foreach ($response_verbs as $v) {
1632 $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], '');
1633 $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', '');
1634 $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0');
1635 if (count($ret[$v]['list']) > MAX_LIKERS) {
1636 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1637 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1638 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . L10n::t('View all') . '</b></a>');
1640 $ret[$v]['list_part'] = '';
1642 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1643 $ret[$v]['title'] = $conv_responses[$v]['title'];
1647 foreach ($ret as $key) {
1648 if ($key['count'] == true) {
1652 $ret['count'] = $count;
1657 function get_response_button_text($v, $count)
1661 $return = L10n::tt('Like', 'Likes', $count);
1664 $return = L10n::tt('Dislike', 'Dislikes', $count);
1667 $return = L10n::tt('Attending', 'Attending', $count);
1670 $return = L10n::tt('Not Attending', 'Not Attending', $count);
1673 $return = L10n::tt('Undecided', 'Undecided', $count);