3 * @file include/conversation.php
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\System;
15 use Friendica\Database\DBM;
16 use Friendica\Model\Contact;
17 use Friendica\Model\Profile;
18 use Friendica\Object\Post;
19 use Friendica\Object\Thread;
20 use Friendica\Util\DateTimeFormat;
21 use Friendica\Util\Temporal;
22 use Friendica\Util\XML;
24 require_once "include/acl_selectors.php";
26 function item_extract_images($body) {
33 $img_start = strpos($orig_body, '[img');
34 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
35 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
36 while (($img_st_close !== false) && ($img_end !== false)) {
38 $img_st_close++; // make it point to AFTER the closing bracket
39 $img_end += $img_start;
41 if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
42 // This is an embedded image
44 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
45 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
49 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
52 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
54 if ($orig_body === false) {
55 // in case the body ends on a closing image tag
59 $img_start = strpos($orig_body, '[img');
60 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
61 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
64 $new_body = $new_body . $orig_body;
66 return ['body' => $new_body, 'images' => $saved_image];
69 function item_redir_and_replace_images($body, $images, $cid) {
75 $pos = BBCode::getTagPosition($origbody, 'url', 0);
76 while ($pos !== false && $cnt < 1000) {
78 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
79 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
80 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
82 $newbody .= substr($origbody, 0, $pos['start']['open']);
83 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
84 $origbody = substr($origbody, $pos['end']['close']);
85 if ($origbody === false) {
89 $subject = preg_replace($search, $replace, $subject);
93 // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
94 $pos = BBCode::getTagPosition($origbody, 'url', 0);
96 $newbody .= $origbody;
99 foreach ($images as $image) {
101 * We're depending on the property of 'foreach' (specified on the PHP website) that
102 * it loops over the array starting from the first element and going sequentially
103 * to the last element.
105 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
112 * Render actions localized
114 function localize_item(&$item) {
116 $extracted = item_extract_images($item['body']);
117 if ($extracted['images']) {
118 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
122 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
123 if (activity_match($item['verb'], ACTIVITY_LIKE)
124 || activity_match($item['verb'], ACTIVITY_DISLIKE)
125 || activity_match($item['verb'], ACTIVITY_ATTEND)
126 || activity_match($item['verb'], ACTIVITY_ATTENDNO)
127 || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
129 /// @TODO may hurt performance
130 $r = q("SELECT * FROM `item`, `contact`
131 WHERE `item`.`contact-id`=`contact`.`id`
132 AND `item`.`uri`='%s'",
133 dbesc($item['parent-uri']));
134 if (!DBM::is_result($r)) {
139 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
140 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
142 switch ($obj['verb']) {
144 switch ($obj['object-type']) {
145 case ACTIVITY_OBJ_EVENT:
146 $post_type = L10n::t('event');
149 $post_type = L10n::t('status');
153 if ($obj['resource-id']) {
154 $post_type = L10n::t('photo');
156 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
157 $rr['plink'] = $m[1];
159 $post_type = L10n::t('status');
163 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
165 if (activity_match($item['verb'], ACTIVITY_LIKE)) {
166 $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
168 elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
169 $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
171 elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
172 $bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
174 elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
175 $bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
177 elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
178 $bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
180 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
183 if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
185 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
187 $Aname = $item['author-name'];
188 $Alink = $item['author-link'];
190 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
192 $obj = XML::parseString($xmlhead.$item['object']);
193 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
195 $Bname = $obj->title;
196 $Blink = ""; $Bphoto = "";
197 foreach ($links->link as $l) {
198 $atts = $l->attributes();
199 switch ($atts['rel']) {
200 case "alternate": $Blink = $atts['href'];
201 case "photo": $Bphoto = $atts['href'];
205 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
206 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
208 $Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
211 $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
214 if (stristr($item['verb'], ACTIVITY_POKE)) {
215 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
219 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
223 $Aname = $item['author-name'];
224 $Alink = $item['author-link'];
226 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
228 $obj = XML::parseString($xmlhead.$item['object']);
229 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
231 $Bname = $obj->title;
234 foreach ($links->link as $l) {
235 $atts = $l->attributes();
236 switch ($atts['rel']) {
237 case "alternate": $Blink = $atts['href'];
238 case "photo": $Bphoto = $atts['href'];
242 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
243 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
245 $Bphoto = '[url=' . Profile::zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
249 * we can't have a translation string with three positions but no distinguishable text
250 * So here is the translate string.
252 $txt = L10n::t('%1$s poked %2$s');
254 // now translate the verb
255 $poked_t = trim(sprintf($txt, "", ""));
256 $txt = str_replace( $poked_t, L10n::t($verb), $txt);
258 // then do the sprintf on the translation string
260 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
264 if (activity_match($item['verb'], ACTIVITY_TAG)) {
265 /// @TODO may hurt performance "joining" two tables + asterisk
266 $r = q("SELECT * FROM `item`, `contact`
267 WHERE `item`.`contact-id`=`contact`.`id`
268 AND `item`.`uri`='%s'",
269 dbesc($item['parent-uri']));
271 if (!DBM::is_result($r)) {
277 $author = '[url=' . Profile::zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
278 $objauthor = '[url=' . Profile::zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
280 switch ($obj['verb']) {
282 switch ($obj['object-type']) {
283 case ACTIVITY_OBJ_EVENT:
284 $post_type = L10n::t('event');
287 $post_type = L10n::t('status');
291 if ($obj['resource-id']) {
292 $post_type = L10n::t('photo');
293 $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
294 $rr['plink'] = $m[1];
296 $post_type = L10n::t('status');
298 // Let's break everthing ... ;-)
301 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
303 $parsedobj = XML::parseString($xmlhead.$item['object']);
305 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
306 $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
309 if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
311 if ($item['object-type'] == "") {
315 $Aname = $item['author-name'];
316 $Alink = $item['author-link'];
318 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
320 $obj = XML::parseString($xmlhead.$item['object']);
321 if (strlen($obj->id)) {
322 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
327 if (DBM::is_result($r) && $r[0]['plink']) {
329 $Bname = $target['author-name'];
330 $Blink = $target['author-link'];
331 $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
332 $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
333 $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
334 $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
339 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
340 foreach ($matches as $mtch) {
341 if (! strpos($mtch[1], 'zrl=')) {
342 $item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']);
347 // add zrl's to public images
348 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
349 if (preg_match($photo_pattern, $item['body'])) {
350 $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
351 $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
354 // add sparkle links to appropriate permalinks
356 $x = stristr($item['plink'],'/display/');
359 $y = best_link_url($item, $sparkle);
361 if (strstr($y, '/redir/')) {
362 $item['plink'] = $y . '?f=&url=' . $item['plink'];
368 * Count the total of comments on this item and its desendants
369 * @TODO proper type-hint + doc-tag
371 function count_descendants($item) {
372 $total = count($item['children']);
375 foreach ($item['children'] as $child) {
376 if (! visible_activity($child)) {
379 $total += count_descendants($child);
386 function visible_activity($item) {
389 * likes (etc.) can apply to other things besides posts. Check if they are post children,
390 * in which case we handle them specially
392 $hidden_activities = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
393 foreach ($hidden_activities as $act) {
394 if (activity_match($item['verb'], $act)) {
399 if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
400 if (! (($item['self']) && ($item['uid'] == local_user()))) {
409 * @brief SQL query for items
411 function item_query() {
412 return "SELECT " . item_fieldlists() . " FROM `item` " .
413 item_joins() . " WHERE " . item_condition();
417 * @brief List of all data fields that are needed for displaying items
419 function item_fieldlists() {
422 These Fields are not added below (yet). They are here to for bug search.
427 `item`.`target-type`,
429 `item`.`resource-id`,
442 `item`.`gcontact-id`,
446 return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
447 `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
448 `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
449 `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
450 `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
451 `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
452 `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
453 `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
454 `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
455 `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
456 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
457 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
459 `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
461 `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
462 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
464 `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
465 `event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
466 `event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
467 `event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
468 `event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
469 `event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
473 * @brief SQL join for contacts that are needed for displaying items
475 function item_joins() {
476 return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
477 (NOT `contact`.`blocked` OR `contact`.`pending`)
478 LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
479 LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`
480 LEFT JOIN `event` ON `event-id` = `event`.`id`";
484 * @brief SQL condition for items that are needed for displaying items
486 function item_condition() {
487 return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
491 * "Render" a conversation or list of items for HTML display.
492 * There are two major forms of display:
493 * - Sequential or unthreaded ("New Item View" or search results)
494 * - conversation view
495 * The $mode parameter decides between the various renderings and also
496 * figures out how to determine page owner and other contextual items
497 * that are based on unique features of the calling module.
500 function conversation(App $a, $items, $mode, $update, $preview = false) {
501 require_once 'mod/proxy.php';
503 $ssl_state = ((local_user()) ? true : false);
506 $live_update_div = '';
511 $str_blocked = PConfig::get(local_user(), 'system', 'blocked');
513 $arr_blocked = explode(',', $str_blocked);
514 for ($x = 0; $x < count($arr_blocked); $x ++) {
515 $arr_blocked[$x] = trim($arr_blocked[$x]);
521 $previewing = (($preview) ? ' preview ' : '');
523 if ($mode === 'network') {
524 $profile_owner = local_user();
527 * The special div is needed for liveUpdate to kick in for this page.
528 * We only launch liveUpdate if you aren't filtering in some incompatible
529 * way and also you aren't writing a comment (discovered in javascript).
531 $live_update_div = '<div id="live-network"></div>' . "\r\n"
532 . "<script> var profile_uid = " . $_SESSION['uid']
533 . "; var netargs = '" . substr($a->cmd, 8)
535 . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
536 . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
537 . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
538 . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
539 . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
540 . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
541 . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
542 . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
543 . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
544 . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
545 . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
546 . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
548 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
550 } elseif ($mode === 'profile') {
551 $profile_owner = $a->profile['profile_uid'];
555 if (x($_GET, 'tab')) {
556 $tab = notags(trim($_GET['tab']));
558 if ($tab === 'posts') {
560 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
561 * because browser prefetching might change it on us. We have to deliver it with the page.
564 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
565 . "<script> var profile_uid = " . $a->profile['profile_uid']
566 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
569 } elseif ($mode === 'notes') {
570 $profile_owner = local_user();
572 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
573 . "<script> var profile_uid = " . local_user()
574 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
576 } elseif ($mode === 'display') {
577 $profile_owner = $a->profile['uid'];
579 $live_update_div = '<div id="live-display"></div>' . "\r\n"
580 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
581 . " var profile_page = 1; </script>";
583 } elseif ($mode === 'community') {
584 $items = community_add_items($items);
587 $live_update_div = '<div id="live-community"></div>' . "\r\n"
588 . "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
589 ."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
591 } elseif ($mode === 'search') {
592 $live_update_div = '<div id="live-search"></div>' . "\r\n";
595 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
598 $_SESSION['return_url'] = $a->query_string;
601 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
602 Addon::callHooks('conversation_start',$cb);
604 $items = $cb['items'];
607 'like' => ['title' => L10n::t('Likes','title')], 'dislike' => ['title' => L10n::t('Dislikes','title')],
608 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
611 // array with html for each thread (parent+comments)
615 $page_template = get_markup_template("conversation.tpl");
617 if ($items && count($items)) {
618 if ($mode === 'community') {
621 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
628 if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
631 * "New Item View" on network page or search page results
632 * - just loop through the items and format them minimally for display
635 $tpl = 'search_item.tpl';
637 foreach ($items as $item) {
641 foreach ($arr_blocked as $b) {
642 if ($b && link_compare($item['author-link'], $b)) {
659 // prevent private email from leaking.
660 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
664 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
665 if ($item['author-link'] && (! $item['author-name'])) {
666 $profile_name = $item['author-link'];
673 $searchpath = System::baseUrl()."/search?tag=";
675 $taglist = dba::select('term', ['type', 'term', 'url'],
676 ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
677 ['order' => ['tid']]);
679 while ($tag = dba::fetch($taglist)) {
680 if ($tag["url"] == "") {
681 $tag["url"] = $searchpath . strtolower($tag["term"]);
684 $tag["url"] = best_link_url($item, $sp, $tag["url"]);
686 if ($tag["type"] == TERM_HASHTAG) {
687 $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
689 } elseif ($tag["type"] == TERM_MENTION) {
690 $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
693 $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
695 dba::close($taglist);
698 $profile_link = best_link_url($item, $sp);
699 if ($profile_link === 'mailbox') {
704 $sparkle = ' sparkle';
706 $profile_link = Profile::zrl($profile_link);
709 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
710 $author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
711 if ($author_contact["thumb"]) {
712 $item['author-thumb'] = $author_contact["thumb"];
714 $item['author-thumb'] = $item['author-avatar'];
718 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
719 $owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
720 if ($owner_contact["thumb"]) {
721 $item['owner-thumb'] = $owner_contact["thumb"];
723 $item['owner-thumb'] = $item['owner-avatar'];
727 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
728 Addon::callHooks('render_location',$locate);
730 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
732 localize_item($item);
733 if ($mode === 'network-new') {
740 'dropping' => $dropping,
741 'pagedrop' => $page_dropping,
742 'select' => L10n::t('Select'),
743 'delete' => L10n::t('Delete'),
747 $isstarred = "unstarred";
750 $likebuttons = false;
752 $body = prepare_body($item, true, $preview);
754 list($categories, $folders) = get_cats_and_terms($item);
756 $profile_name_e = $profile_name;
757 $item['title_e'] = $item['title'];
760 $hashtags_e = $hashtags;
761 $mentions_e = $mentions;
762 $location_e = $location;
763 $owner_name_e = $owner_name;
765 if ($item['item_network'] == "") {
766 $item['item_network'] = $item['network'];
771 'id' => (($preview) ? 'P0' : $item['item_id']),
772 'guid' => (($preview) ? 'Q0' : $item['guid']),
773 'network' => $item['item_network'],
774 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
775 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
776 'profile_url' => $profile_link,
777 'item_photo_menu' => item_photo_menu($item),
778 'name' => $profile_name_e,
779 'sparkle' => $sparkle,
781 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
782 'title' => $item['title_e'],
785 'hashtags' => $hashtags_e,
786 'mentions' => $mentions_e,
787 'txt_cats' => L10n::t('Categories:'),
788 'txt_folders' => L10n::t('Filed under:'),
789 'has_cats' => ((count($categories)) ? 'true' : ''),
790 'has_folders' => ((count($folders)) ? 'true' : ''),
791 'categories' => $categories,
792 'folders' => $folders,
793 'text' => strip_tags($body_e),
794 'localtime' => DateTimeFormat::local($item['created'], 'r'),
795 'ago' => (($item['app']) ? L10n::t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
796 'location' => $location_e,
798 'owner_name' => $owner_name_e,
799 'owner_url' => $owner_url,
800 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
801 'plink' => get_plink($item),
803 'isstarred' => $isstarred,
806 'vote' => $likebuttons,
810 'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> L10n::t('View in context')]),
811 'previewing' => $previewing,
812 'wait' => L10n::t('Please wait'),
816 $arr = ['item' => $item, 'output' => $tmp_item];
817 Addon::callHooks('display_item', $arr);
819 $threads[$threadsid]['id'] = $item['item_id'];
820 $threads[$threadsid]['network'] = $item['item_network'];
821 $threads[$threadsid]['items'] = [$arr['output']];
826 $page_template = get_markup_template("threaded_conversation.tpl");
828 $conv = new Thread($mode, $preview, $writable);
831 * get all the topmost parents
832 * this shouldn't be needed, as we should have only them in our array
833 * But for now, this array respects the old style, just in case
835 foreach ($items as $item) {
838 foreach ($arr_blocked as $b) {
839 if ($b && link_compare($item['author-link'], $b)) {
849 // Can we put this after the visibility check?
850 builtin_activity_puller($item, $conv_responses);
852 // Only add what is visible
853 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
857 if (! visible_activity($item)) {
861 Addon::callHooks('display_item', $arr);
863 $item['pagedrop'] = $page_dropping;
865 if ($item['id'] == $item['parent']) {
866 $item_object = new Post($item);
867 $conv->addParent($item_object);
871 $threads = $conv->getTemplateData($conv_responses);
873 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
879 $o = replace_macros($page_template, [
880 '$baseurl' => System::baseUrl($ssl_state),
881 '$return_path' => $a->query_string,
882 '$live_update' => $live_update_div,
883 '$remove' => L10n::t('remove'),
886 '$threads' => $threads,
887 '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? L10n::t('Delete Selected Items') : False),
894 * @brief Add comments to top level entries that had been fetched before
896 * The system will fetch the comments for the local user whenever possible.
897 * This behaviour is currently needed to allow commenting on Friendica posts.
899 * @param array $parents Parent items
901 * @return array items with parents and comments
903 function community_add_items($parents) {
904 $max_comments = Config::get("system", "max_comments", 100);
908 foreach ($parents AS $parent) {
909 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
910 AND `item`.`parent-uri` = ?
911 AND NOT `author`.`hidden` AND NOT `author`.`blocked`
912 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
916 $comments = dba::inArray($thread_items);
918 // Check if the original item is in the result.
919 // When commenting from the community page there can be incomplete threads
920 if (count($comments) > 0) {
921 $parent_found = false;
922 foreach ($comments as $comment) {
923 if ($comment['uri'] == $comment['parent-uri']) {
924 $parent_found = true;
928 if (!$parent_found) {
933 if (count($comments) == 0) {
934 $thread_items = dba::p(item_query()." AND `item`.`uid` = 0
935 AND `item`.`parent-uri` = ?
936 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
939 $comments = dba::inArray($thread_items);
942 if (count($comments) != 0) {
943 $items = array_merge($items, $comments);
947 foreach ($items as $index => $item) {
948 if ($item['uid'] == 0) {
949 $items[$index]['writable'] = in_array($item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
953 $items = conv_sort($items, "`commented`");
958 function best_link_url($item, &$sparkle, $url = '') {
963 $clean_url = normalise_link($item['author-link']);
967 'network' => NETWORK_DFRN,
968 'uid' => local_user(),
969 'nurl' => normalise_link($clean_url),
972 $contact = dba::selectFirst('contact', ['id'], $condition);
973 if (DBM::is_result($contact)) {
974 $best_url = 'redir/' . $contact['id'];
977 $hostname = get_app()->get_hostname();
978 if (!strstr($url, $hostname)) {
979 $best_url .= "?url=".$url;
989 } elseif (strlen($item['author-link'])) {
990 $best_url = $item['author-link'];
992 $best_url = $item['url'];
1000 function item_photo_menu($item) {
1009 if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
1010 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
1014 $profile_link = best_link_url($item, $sparkle);
1015 if ($profile_link === 'mailbox') {
1022 $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
1023 $contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
1024 if (DBM::is_result($contact)) {
1025 $cid = $contact['id'];
1026 $network = $contact['network'];
1027 $rel = $contact['rel'];
1031 $status_link = $profile_link . '?url=status';
1032 $photos_link = $profile_link . '?url=photos';
1033 $profile_link = $profile_link . '?url=profile';
1035 $profile_link = Profile::zrl($profile_link);
1038 if ($cid && !$item['self']) {
1039 $poke_link = 'poke/?f=&c=' . $cid;
1040 $contact_url = 'contacts/' . $cid;
1041 $posts_link = 'contacts/' . $cid . '/posts';
1043 if (in_array($network, [NETWORK_DFRN, NETWORK_DIASPORA])) {
1044 $pm_url = 'message/new/' . $cid;
1050 L10n::t('Follow Thread') => $sub_link,
1051 L10n::t('View Status') => $status_link,
1052 L10n::t('View Profile') => $profile_link,
1053 L10n::t('View Photos') => $photos_link,
1054 L10n::t('Network Posts') => $posts_link,
1055 L10n::t('View Contact') => $contact_url,
1056 L10n::t('Send PM') => $pm_url
1059 if ($network == NETWORK_DFRN) {
1060 $menu[L10n::t("Poke")] = $poke_link;
1063 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
1064 in_array($item['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])) {
1065 $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
1068 $menu = [L10n::t('View Profile') => $item['author-link']];
1071 $args = ['item' => $item, 'menu' => $menu];
1073 Addon::callHooks('item_photo_menu', $args);
1075 $menu = $args['menu'];
1078 foreach ($menu as $k => $v) {
1079 if (strpos($v, 'javascript:') === 0) {
1080 $v = substr($v, 11);
1081 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1083 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1090 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1091 * Increments the count of each matching activity and adds a link to the author as needed.
1093 * @param array $item
1094 * @param array &$conv_responses (already created with builtin activity structure)
1097 function builtin_activity_puller($item, &$conv_responses) {
1098 foreach ($conv_responses as $mode => $v) {
1104 $verb = ACTIVITY_LIKE;
1107 $verb = ACTIVITY_DISLIKE;
1110 $verb = ACTIVITY_ATTEND;
1113 $verb = ACTIVITY_ATTENDNO;
1116 $verb = ACTIVITY_ATTENDMAYBE;
1122 if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1123 $url = $item['author-link'];
1124 if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
1125 $url = 'redir/' . $item['contact-id'];
1126 $sparkle = ' class="sparkle" ';
1128 $url = Profile::zrl($url);
1131 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1133 if (! $item['thr-parent']) {
1134 $item['thr-parent'] = $item['parent-uri'];
1137 if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1138 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
1139 $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
1142 // only list each unique author once
1143 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1147 if (! isset($conv_responses[$mode][$item['thr-parent']])) {
1148 $conv_responses[$mode][$item['thr-parent']] = 1;
1150 $conv_responses[$mode][$item['thr-parent']] ++;
1153 if (public_contact() == $item['author-id']) {
1154 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1157 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1159 // there can only be one activity verb per item so if we found anything, we can stop looking
1166 * Format the vote text for a profile item
1167 * @param int $cnt = number of people who vote the item
1168 * @param array $arr = array of pre-linked names of likers/dislikers
1169 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1170 * @param int $id = item id
1171 * @return string formatted text
1173 function format_like($cnt, array $arr, $type, $id) {
1180 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1181 // list which show all likers
1184 $phrase = L10n::t('%s likes this.', $likers);
1187 $phrase = L10n::t('%s doesn\'t like this.', $likers);
1190 $phrase = L10n::t('%s attends.', $likers);
1193 $phrase = L10n::t('%s doesn\'t attend.', $likers);
1195 case 'attendmaybe' :
1196 $phrase = L10n::t('%s attends maybe.', $likers);
1202 $total = count($arr);
1203 if ($total >= MAX_LIKERS) {
1204 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1206 if ($total < MAX_LIKERS) {
1207 $last = L10n::t('and') . ' ' . $arr[count($arr)-1];
1208 $arr2 = array_slice($arr, 0, -1);
1209 $str = implode(', ', $arr2) . ' ' . $last;
1211 if ($total >= MAX_LIKERS) {
1212 $str = implode(', ', $arr);
1213 $str .= L10n::t('and %d other people', $total - MAX_LIKERS );
1218 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1222 $phrase = L10n::t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
1223 $explikers = L10n::t('%s like this.', $likers);
1226 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
1227 $explikers = L10n::t('%s don\'t like this.', $likers);
1230 $phrase = L10n::t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
1231 $explikers = L10n::t('%s attend.', $likers);
1234 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
1235 $explikers = L10n::t('%s don\'t attend.', $likers);
1238 $phrase = L10n::t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
1239 $explikers = L10n::t('%s anttend maybe.', $likers);
1243 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1247 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), [
1248 '$phrase' => $phrase,
1257 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1261 $geotag = x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), []) : '';
1263 $tpl = get_markup_template('jot-header.tpl');
1264 $a->page['htmlhead'] .= replace_macros($tpl, [
1265 '$newpost' => 'true',
1266 '$baseurl' => System::baseUrl(true),
1267 '$geotag' => $geotag,
1268 '$nickname' => $x['nickname'],
1269 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1270 '$linkurl' => L10n::t('Please enter a link URL:'),
1271 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1272 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1273 '$term' => L10n::t('Tag term:'),
1274 '$fileas' => L10n::t('Save to Folder:'),
1275 '$whereareu' => L10n::t('Where are you right now?'),
1276 '$delitems' => L10n::t("Delete item\x28s\x29?")
1279 $tpl = get_markup_template('jot-end.tpl');
1280 $a->page['end'] .= replace_macros($tpl, [
1281 '$newpost' => 'true',
1282 '$baseurl' => System::baseUrl(true),
1283 '$geotag' => $geotag,
1284 '$nickname' => $x['nickname'],
1285 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1286 '$linkurl' => L10n::t('Please enter a link URL:'),
1287 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1288 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1289 '$term' => L10n::t('Tag term:'),
1290 '$fileas' => L10n::t('Save to Folder:'),
1291 '$whereareu' => L10n::t('Where are you right now?')
1295 Addon::callHooks('jot_tool', $jotplugins);
1297 // Private/public post links for the non-JS ACL form
1299 if (x($_REQUEST, 'public')) {
1303 $query_str = $a->query_string;
1304 if (strpos($query_str, 'public=1') !== false) {
1305 $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
1309 * I think $a->query_string may never have ? in it, but I could be wrong
1310 * It looks like it's from the index.php?q=[etc] rewrite that the web
1311 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1313 if (strpos($query_str, '?') === false) {
1314 $public_post_link = '?public=1';
1316 $public_post_link = '&public=1';
1319 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1320 $tpl = get_markup_template("jot.tpl");
1322 $o .= replace_macros($tpl,[
1323 '$return_path' => $query_str,
1324 '$action' => 'item',
1325 '$share' => defaults($x, 'button', L10n::t('Share')),
1326 '$upload' => L10n::t('Upload photo'),
1327 '$shortupload' => L10n::t('upload photo'),
1328 '$attach' => L10n::t('Attach file'),
1329 '$shortattach' => L10n::t('attach file'),
1330 '$weblink' => L10n::t('Insert web link'),
1331 '$shortweblink' => L10n::t('web link'),
1332 '$video' => L10n::t('Insert video link'),
1333 '$shortvideo' => L10n::t('video link'),
1334 '$audio' => L10n::t('Insert audio link'),
1335 '$shortaudio' => L10n::t('audio link'),
1336 '$setloc' => L10n::t('Set your location'),
1337 '$shortsetloc' => L10n::t('set location'),
1338 '$noloc' => L10n::t('Clear browser location'),
1339 '$shortnoloc' => L10n::t('clear location'),
1340 '$title' => defaults($x, 'title', ''),
1341 '$placeholdertitle' => L10n::t('Set title'),
1342 '$category' => defaults($x, 'category', ''),
1343 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '',
1344 '$wait' => L10n::t('Please wait'),
1345 '$permset' => L10n::t('Permission settings'),
1346 '$shortpermset' => L10n::t('permissions'),
1347 '$ptyp' => $notes_cid ? 'note' : 'wall',
1348 '$content' => defaults($x, 'content', ''),
1349 '$post_id' => defaults($x, 'post_id', ''),
1350 '$baseurl' => System::baseUrl(true),
1351 '$defloc' => $x['default_location'],
1352 '$visitor' => $x['visitor'],
1353 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1354 '$public' => L10n::t('Public post'),
1355 '$lockstate' => $x['lockstate'],
1356 '$bang' => $x['bang'],
1357 '$profile_uid' => $x['profile_uid'],
1358 '$preview' => Feature::isEnabled($x['profile_uid'], 'preview') ? L10n::t('Preview') : '',
1359 '$jotplugins' => $jotplugins,
1360 '$notes_cid' => $notes_cid,
1361 '$sourceapp' => L10n::t($a->sourcename),
1362 '$cancel' => L10n::t('Cancel'),
1363 '$rand_num' => random_digits(12),
1365 // ACL permissions box
1366 '$acl' => $x['acl'],
1367 '$group_perms' => L10n::t('Post to Groups'),
1368 '$contact_perms' => L10n::t('Post to Contacts'),
1369 '$private' => L10n::t('Private post'),
1370 '$is_private' => $private_post,
1371 '$public_link' => $public_post_link,
1373 //jot nav tab (used in some themes)
1374 '$message' => L10n::t('Message'),
1375 '$browser' => L10n::t('Browser'),
1379 if ($popup == true) {
1380 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1387 * Plucks the children of the given parent from a given item list.
1389 * @brief Plucks all the children in the given item list of the given parent
1391 * @param array $item_list
1392 * @param array $parent
1393 * @param bool $recursive
1396 function get_item_children(array &$item_list, array $parent, $recursive = true)
1399 foreach ($item_list as $i => $item) {
1400 if ($item['id'] != $item['parent']) {
1402 // Fallback to parent-uri if thr-parent is not set
1403 $thr_parent = $item['thr-parent'];
1404 if ($thr_parent == '') {
1405 $thr_parent = $item['parent-uri'];
1408 if ($thr_parent == $parent['uri']) {
1409 $item['children'] = get_item_children($item_list, $item);
1410 $children[] = $item;
1411 unset($item_list[$i]);
1413 } elseif ($item['parent'] == $parent['id']) {
1414 $children[] = $item;
1415 unset($item_list[$i]);
1423 * @brief Recursively sorts a tree-like item array
1425 * @param array $items
1428 function sort_item_children(array $items)
1431 usort($result, 'sort_thr_created_rev');
1432 foreach ($result as $k => $i) {
1433 if (isset($result[$k]['children'])) {
1434 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1441 * @brief Recursively add all children items at the top level of a list
1443 * @param array $children List of items to append
1444 * @param array $item_list
1446 function add_children_to_list(array $children, array &$item_list)
1448 foreach ($children as $child) {
1449 $item_list[] = $child;
1450 if (isset($child['children'])) {
1451 add_children_to_list($child['children'], $item_list);
1457 * This recursive function takes the item tree structure created by conv_sort() and
1458 * flatten the extraneous depth levels when people reply sequentially, removing the
1459 * stairs effect in threaded conversations limiting the available content width.
1461 * The basic principle is the following: if a post item has only one reply and is
1462 * the last reply of its parent, then the reply is moved to the parent.
1464 * This process is rendered somewhat more complicated because items can be either
1465 * replies or likes, and these don't factor at all in the reply count/last reply.
1467 * @brief Selectively flattens a tree-like item structure to prevent threading stairs
1469 * @param array $parent A tree-like array of items
1472 function smart_flatten_conversation(array $parent)
1474 if (! isset($parent['children']) || count($parent['children']) == 0) {
1478 // We use a for loop to ensure we process the newly-moved items
1479 for ($i = 0; $i < count($parent['children']); $i++) {
1480 $child = $parent['children'][$i];
1482 if (isset($child['children']) && count($child['children'])) {
1483 // This helps counting only the regular posts
1484 $count_post_closure = function($var) {
1485 return $var['verb'] === ACTIVITY_POST;
1488 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1490 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1492 // If there's only one child's children post and this is the last child post
1493 if ($child_post_count == 1 && $remaining_post_count == 1) {
1495 // Searches the post item in the children
1497 while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
1501 $moved_item = $child['children'][$j];
1502 unset($parent['children'][$i]['children'][$j]);
1503 $parent['children'][] = $moved_item;
1505 $parent['children'][$i] = smart_flatten_conversation($child);
1515 * Expands a flat list of items into corresponding tree-like conversation structures,
1516 * sort the top-level posts either on "created" or "commented", and finally
1517 * append all the items at the top level (???)
1519 * @brief Expands a flat item list into a conversation array for display
1521 * @param array $item_list A list of items belonging to one or more conversations
1522 * @param string $order Either on "created" or "commented"
1525 function conv_sort(array $item_list, $order)
1529 if (!(is_array($item_list) && count($item_list))) {
1535 // Dedupes the item list on the uri to prevent infinite loops
1536 foreach ($item_list as $item) {
1537 $item_array[$item['uri']] = $item;
1540 // Extract the top level items
1541 foreach ($item_array as $item) {
1542 if ($item['id'] == $item['parent']) {
1547 if (stristr($order, 'created')) {
1548 usort($parents, 'sort_thr_created');
1549 } elseif (stristr($order, 'commented')) {
1550 usort($parents, 'sort_thr_commented');
1554 * Plucks children from the item_array, second pass collects eventual orphan
1555 * items and add them as children of their top-level post.
1557 foreach ($parents as $i => $parent) {
1558 $parents[$i]['children'] =
1559 array_merge(get_item_children($item_array, $parent, true),
1560 get_item_children($item_array, $parent, false));
1563 foreach ($parents as $i => $parent) {
1564 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1567 if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
1568 foreach ($parents as $i => $parent) {
1569 $parents[$i] = smart_flatten_conversation($parent);
1573 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1574 /// However, this apparently ensures responses (likes, attendance) display (?!)
1575 foreach ($parents as $parent) {
1576 if (count($parent['children'])) {
1577 add_children_to_list($parent['children'], $parents);
1585 * @brief usort() callback to sort item arrays by the created key
1591 function sort_thr_created(array $a, array $b)
1593 return strcmp($b['created'], $a['created']);
1597 * @brief usort() callback to reverse sort item arrays by the created key
1603 function sort_thr_created_rev(array $a, array $b)
1605 return strcmp($a['created'], $b['created']);
1609 * @brief usort() callback to sort item arrays by the commented key
1615 function sort_thr_commented(array $a, array $b)
1617 return strcmp($b['commented'], $a['commented']);
1620 /// @TODO Add type-hint
1621 function render_location_dummy($item) {
1622 if ($item['location'] != "") {
1623 return $item['location'];
1626 if ($item['coord'] != "") {
1627 return $item['coord'];
1631 /// @TODO Add type-hint
1632 function get_responses($conv_responses, $response_verbs, $ob, $item) {
1634 foreach ($response_verbs as $v) {
1636 $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], '');
1637 $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', '');
1638 $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0');
1639 if (count($ret[$v]['list']) > MAX_LIKERS) {
1640 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1641 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1642 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . L10n::t('View all') . '</b></a>');
1644 $ret[$v]['list_part'] = '';
1646 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1647 $ret[$v]['title'] = $conv_responses[$v]['title'];
1651 foreach ($ret as $key) {
1652 if ($key['count'] == true) {
1656 $ret['count'] = $count;
1661 function get_response_button_text($v, $count)
1665 $return = L10n::tt('Like', 'Likes', $count);
1668 $return = L10n::tt('Dislike', 'Dislikes', $count);
1671 $return = L10n::tt('Attending', 'Attending', $count);
1674 $return = L10n::tt('Not Attending', 'Not Attending', $count);
1677 $return = L10n::tt('Undecided', 'Undecided', $count);