3 * @file include/conversation.php
6 use Friendica\Content\Feature;
7 use Friendica\Core\Config;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Contact;
12 use Friendica\Object\Thread;
13 use Friendica\Object\Post;
15 require_once "include/bbcode.php";
16 require_once "include/acl_selectors.php";
18 function item_extract_images($body) {
20 $saved_image = array();
25 $img_start = strpos($orig_body, '[img');
26 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
27 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
28 while (($img_st_close !== false) && ($img_end !== false)) {
30 $img_st_close++; // make it point to AFTER the closing bracket
31 $img_end += $img_start;
33 if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
34 // This is an embedded image
36 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
37 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
41 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
44 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
46 if ($orig_body === false) {
47 // in case the body ends on a closing image tag
51 $img_start = strpos($orig_body, '[img');
52 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
53 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
56 $new_body = $new_body . $orig_body;
58 return array('body' => $new_body, 'images' => $saved_image);
61 function item_redir_and_replace_images($body, $images, $cid) {
67 $pos = get_bb_tag_pos($origbody, 'url', 1);
68 while ($pos !== false && $cnt < 1000) {
70 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
71 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
72 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
74 $newbody .= substr($origbody, 0, $pos['start']['open']);
75 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
76 $origbody = substr($origbody, $pos['end']['close']);
77 if ($origbody === false) {
81 $subject = preg_replace($search, $replace, $subject);
85 $pos = get_bb_tag_pos($origbody, 'url', 1);
87 $newbody .= $origbody;
90 foreach ($images as $image) {
92 * We're depending on the property of 'foreach' (specified on the PHP website) that
93 * it loops over the array starting from the first element and going sequentially
94 * to the last element.
96 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
103 * Render actions localized
105 function localize_item(&$item) {
107 $extracted = item_extract_images($item['body']);
108 if ($extracted['images']) {
109 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
113 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
114 if (activity_match($item['verb'], ACTIVITY_LIKE)
115 || activity_match($item['verb'], ACTIVITY_DISLIKE)
116 || activity_match($item['verb'], ACTIVITY_ATTEND)
117 || activity_match($item['verb'], ACTIVITY_ATTENDNO)
118 || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
120 /// @TODO may hurt performance
121 $r = q("SELECT * FROM `item`, `contact`
122 WHERE `item`.`contact-id`=`contact`.`id`
123 AND `item`.`uri`='%s'",
124 dbesc($item['parent-uri']));
125 if (!DBM::is_result($r)) {
130 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
131 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
133 switch ($obj['verb']) {
135 switch ($obj['object-type']) {
136 case ACTIVITY_OBJ_EVENT:
137 $post_type = t('event');
140 $post_type = t('status');
144 if ($obj['resource-id']) {
145 $post_type = t('photo');
147 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
148 $rr['plink'] = $m[1];
150 $post_type = t('status');
154 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
156 if (activity_match($item['verb'], ACTIVITY_LIKE)) {
157 $bodyverb = t('%1$s likes %2$s\'s %3$s');
159 elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
160 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
162 elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
163 $bodyverb = t('%1$s attends %2$s\'s %3$s');
165 elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
166 $bodyverb = t('%1$s doesn\'t attend %2$s\'s %3$s');
168 elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
169 $bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
171 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
174 if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
176 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
178 $Aname = $item['author-name'];
179 $Alink = $item['author-link'];
181 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
183 $obj = parse_xml_string($xmlhead.$item['object']);
184 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
186 $Bname = $obj->title;
187 $Blink = ""; $Bphoto = "";
188 foreach ($links->link as $l) {
189 $atts = $l->attributes();
190 switch ($atts['rel']) {
191 case "alternate": $Blink = $atts['href'];
192 case "photo": $Bphoto = $atts['href'];
196 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
197 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
199 $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
202 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
205 if (stristr($item['verb'], ACTIVITY_POKE)) {
206 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
210 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
214 $Aname = $item['author-name'];
215 $Alink = $item['author-link'];
217 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
219 $obj = parse_xml_string($xmlhead.$item['object']);
220 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
222 $Bname = $obj->title;
225 foreach ($links->link as $l) {
226 $atts = $l->attributes();
227 switch ($atts['rel']) {
228 case "alternate": $Blink = $atts['href'];
229 case "photo": $Bphoto = $atts['href'];
233 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
234 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
236 $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
240 * we can't have a translation string with three positions but no distinguishable text
241 * So here is the translate string.
243 $txt = t('%1$s poked %2$s');
245 // now translate the verb
246 $poked_t = trim(sprintf($txt, "", ""));
247 $txt = str_replace( $poked_t, t($verb), $txt);
249 // then do the sprintf on the translation string
251 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
255 if (activity_match($item['verb'], ACTIVITY_TAG)) {
256 /// @TODO may hurt performance "joining" two tables + asterisk
257 $r = q("SELECT * FROM `item`, `contact`
258 WHERE `item`.`contact-id`=`contact`.`id`
259 AND `item`.`uri`='%s'",
260 dbesc($item['parent-uri']));
262 if (!DBM::is_result($r)) {
268 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
269 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
271 switch ($obj['verb']) {
273 switch ($obj['object-type']) {
274 case ACTIVITY_OBJ_EVENT:
275 $post_type = t('event');
278 $post_type = t('status');
282 if ($obj['resource-id']) {
283 $post_type = t('photo');
284 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
285 $rr['plink'] = $m[1];
287 $post_type = t('status');
289 // Let's break everthing ... ;-)
292 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
294 $parsedobj = parse_xml_string($xmlhead.$item['object']);
296 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
297 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
300 if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
302 if ($item['object-type'] == "") {
306 $Aname = $item['author-name'];
307 $Alink = $item['author-link'];
309 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
311 $obj = parse_xml_string($xmlhead.$item['object']);
312 if (strlen($obj->id)) {
313 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
318 if (DBM::is_result($r) && $r[0]['plink']) {
320 $Bname = $target['author-name'];
321 $Blink = $target['author-link'];
322 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
323 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
324 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
325 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
330 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
331 foreach ($matches as $mtch) {
332 if (! strpos($mtch[1], 'zrl=')) {
333 $item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']);
338 // add zrl's to public images
339 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
340 if (preg_match($photo_pattern, $item['body'])) {
341 $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
342 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
345 // add sparkle links to appropriate permalinks
347 $x = stristr($item['plink'],'/display/');
350 $y = best_link_url($item, $sparkle);
352 if (strstr($y, '/redir/')) {
353 $item['plink'] = $y . '?f=&url=' . $item['plink'];
359 * Count the total of comments on this item and its desendants
360 * @TODO proper type-hint + doc-tag
362 function count_descendants($item) {
363 $total = count($item['children']);
366 foreach ($item['children'] as $child) {
367 if (! visible_activity($child)) {
370 $total += count_descendants($child);
377 function visible_activity($item) {
380 * likes (etc.) can apply to other things besides posts. Check if they are post children,
381 * in which case we handle them specially
383 $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
384 foreach ($hidden_activities as $act) {
385 if (activity_match($item['verb'], $act)) {
390 if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
391 if (! (($item['self']) && ($item['uid'] == local_user()))) {
400 * @brief SQL query for items
402 function item_query() {
403 return "SELECT " . item_fieldlists() . " FROM `item` " .
404 item_joins() . " WHERE " . item_condition();
408 * @brief List of all data fields that are needed for displaying items
410 function item_fieldlists() {
413 These Fields are not added below (yet). They are here to for bug search.
418 `item`.`target-type`,
420 `item`.`resource-id`,
434 `item`.`gcontact-id`,
438 return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
439 `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
440 `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
441 `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
442 `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
443 `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
444 `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
445 `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
446 `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
447 `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
448 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
449 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
451 `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
453 `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
454 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
456 `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
457 `event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
458 `event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
459 `event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
460 `event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
461 `event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
465 * @brief SQL join for contacts that are needed for displaying items
467 function item_joins() {
468 return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
469 (NOT `contact`.`blocked` OR `contact`.`pending`)
470 LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
471 LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`
472 LEFT JOIN `event` ON `event-id` = `event`.`id`";
476 * @brief SQL condition for items that are needed for displaying items
478 function item_condition() {
479 return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
483 * "Render" a conversation or list of items for HTML display.
484 * There are two major forms of display:
485 * - Sequential or unthreaded ("New Item View" or search results)
486 * - conversation view
487 * The $mode parameter decides between the various renderings and also
488 * figures out how to determine page owner and other contextual items
489 * that are based on unique features of the calling module.
492 function conversation(App $a, $items, $mode, $update, $preview = false) {
493 require_once 'include/bbcode.php';
494 require_once 'mod/proxy.php';
496 $ssl_state = ((local_user()) ? true : false);
499 $live_update_div = '';
504 $str_blocked = PConfig::get(local_user(), 'system', 'blocked');
506 $arr_blocked = explode(',', $str_blocked);
507 for ($x = 0; $x < count($arr_blocked); $x ++) {
508 $arr_blocked[$x] = trim($arr_blocked[$x]);
514 $previewing = (($preview) ? ' preview ' : '');
516 if ($mode === 'network') {
517 $profile_owner = local_user();
520 * The special div is needed for liveUpdate to kick in for this page.
521 * We only launch liveUpdate if you aren't filtering in some incompatible
522 * way and also you aren't writing a comment (discovered in javascript).
524 $live_update_div = '<div id="live-network"></div>' . "\r\n"
525 . "<script> var profile_uid = " . $_SESSION['uid']
526 . "; var netargs = '" . substr($a->cmd, 8)
528 . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
529 . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
530 . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
531 . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
532 . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
533 . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
534 . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
535 . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
536 . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
537 . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
538 . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
539 . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
541 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
543 } elseif ($mode === 'profile') {
544 $profile_owner = $a->profile['profile_uid'];
548 if (x($_GET, 'tab')) {
549 $tab = notags(trim($_GET['tab']));
551 if ($tab === 'posts') {
553 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
554 * because browser prefetching might change it on us. We have to deliver it with the page.
557 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
558 . "<script> var profile_uid = " . $a->profile['profile_uid']
559 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
562 } elseif ($mode === 'notes') {
563 $profile_owner = local_user();
565 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
566 . "<script> var profile_uid = " . local_user()
567 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
569 } elseif ($mode === 'display') {
570 $profile_owner = $a->profile['uid'];
572 $live_update_div = '<div id="live-display"></div>' . "\r\n"
573 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
574 . " var profile_page = 1; </script>";
576 } elseif ($mode === 'community') {
577 if (!$community_readonly) {
578 $items = community_add_items($items);
582 $live_update_div = '<div id="live-community"></div>' . "\r\n"
583 . "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
584 ."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
586 } elseif ($mode === 'search') {
587 $live_update_div = '<div id="live-search"></div>' . "\r\n";
590 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
593 $_SESSION['return_url'] = $a->query_string;
596 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
597 call_hooks('conversation_start',$cb);
599 $items = $cb['items'];
601 $conv_responses = array(
602 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
603 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
606 // array with html for each thread (parent+comments)
610 $page_template = get_markup_template("conversation.tpl");
612 if ($items && count($items)) {
613 $community_readonly = ($mode === 'community');
615 // Currently behind a config value. This allows the commenting and sharing of every public item.
616 if (Config::get('system', 'comment_public')) {
617 if ($mode === 'community') {
618 $community_readonly = false;
621 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN));
631 if ($mode === 'network-new' || $mode === 'search' || $community_readonly) {
634 * "New Item View" on network page or search page results
635 * - just loop through the items and format them minimally for display
638 /// @TODO old lost code?
639 // $tpl = get_markup_template('search_item.tpl');
640 $tpl = 'search_item.tpl';
642 foreach ($items as $item) {
646 foreach ($arr_blocked as $b) {
647 if ($b && link_compare($item['author-link'], $b)) {
664 // prevent private email from leaking.
665 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
669 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
670 if ($item['author-link'] && (! $item['author-name'])) {
671 $profile_name = $item['author-link'];
678 $searchpath = System::baseUrl()."/search?tag=";
680 $taglist = dba::select('term', array('type', 'term', 'url'),
681 array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
682 array('order' => array('tid')));
684 while ($tag = dba::fetch($taglist)) {
685 if ($tag["url"] == "") {
686 $tag["url"] = $searchpath . strtolower($tag["term"]);
689 $tag["url"] = best_link_url($item, $sp, $tag["url"]);
691 if ($tag["type"] == TERM_HASHTAG) {
692 $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
694 } elseif ($tag["type"] == TERM_MENTION) {
695 $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
698 $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
700 dba::close($taglist);
703 $profile_link = best_link_url($item, $sp);
704 if ($profile_link === 'mailbox') {
709 $sparkle = ' sparkle';
711 $profile_link = zrl($profile_link);
714 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
715 $author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
716 if ($author_contact["thumb"]) {
717 $item['author-thumb'] = $author_contact["thumb"];
719 $item['author-thumb'] = $item['author-avatar'];
723 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
724 $owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
725 if ($owner_contact["thumb"]) {
726 $item['owner-thumb'] = $owner_contact["thumb"];
728 $item['owner-thumb'] = $item['owner-avatar'];
732 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
733 call_hooks('render_location',$locate);
735 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
737 localize_item($item);
738 if ($mode === 'network-new') {
745 'dropping' => $dropping,
746 'pagedrop' => $page_dropping,
747 'select' => t('Select'),
748 'delete' => t('Delete'),
752 $isstarred = "unstarred";
755 $likebuttons = false;
757 $body = prepare_body($item, true, $preview);
759 list($categories, $folders) = get_cats_and_terms($item);
761 $profile_name_e = $profile_name;
762 $item['title_e'] = $item['title'];
765 $hashtags_e = $hashtags;
766 $mentions_e = $mentions;
767 $location_e = $location;
768 $owner_name_e = $owner_name;
770 if ($item['item_network'] == "") {
771 $item['item_network'] = $item['network'];
776 'id' => (($preview) ? 'P0' : $item['item_id']),
777 'guid' => (($preview) ? 'Q0' : $item['guid']),
778 'network' => $item['item_network'],
779 'network_name' => network_to_name($item['item_network'], $profile_link),
780 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
781 'profile_url' => $profile_link,
782 'item_photo_menu' => item_photo_menu($item),
783 'name' => $profile_name_e,
784 'sparkle' => $sparkle,
786 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
787 'title' => $item['title_e'],
790 'hashtags' => $hashtags_e,
791 'mentions' => $mentions_e,
792 'txt_cats' => t('Categories:'),
793 'txt_folders' => t('Filed under:'),
794 'has_cats' => ((count($categories)) ? 'true' : ''),
795 'has_folders' => ((count($folders)) ? 'true' : ''),
796 'categories' => $categories,
797 'folders' => $folders,
798 'text' => strip_tags($body_e),
799 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
800 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
801 'location' => $location_e,
803 'owner_name' => $owner_name_e,
804 'owner_url' => $owner_url,
805 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
806 'plink' => get_plink($item),
808 'isstarred' => $isstarred,
811 'vote' => $likebuttons,
815 'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
816 'previewing' => $previewing,
817 'wait' => t('Please wait'),
821 $arr = array('item' => $item, 'output' => $tmp_item);
822 call_hooks('display_item', $arr);
824 $threads[$threadsid]['id'] = $item['item_id'];
825 $threads[$threadsid]['network'] = $item['item_network'];
826 $threads[$threadsid]['items'] = array($arr['output']);
831 $page_template = get_markup_template("threaded_conversation.tpl");
833 $conv = new Thread($mode, $preview, $writable);
836 * get all the topmost parents
837 * this shouldn't be needed, as we should have only them in our array
838 * But for now, this array respects the old style, just in case
840 foreach ($items as $item) {
843 foreach ($arr_blocked as $b) {
844 if ($b && link_compare($item['author-link'], $b)) {
854 // Can we put this after the visibility check?
855 builtin_activity_puller($item, $conv_responses);
857 // Only add what is visible
858 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
862 if (! visible_activity($item)) {
866 call_hooks('display_item', $arr);
868 $item['pagedrop'] = $page_dropping;
870 if ($item['id'] == $item['parent']) {
871 $item_object = new Post($item);
872 $conv->addParent($item_object);
876 $threads = $conv->getTemplateData($conv_responses);
878 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
884 $o = replace_macros($page_template, array(
885 '$baseurl' => System::baseUrl($ssl_state),
886 '$return_path' => $a->query_string,
887 '$live_update' => $live_update_div,
888 '$remove' => t('remove'),
891 '$threads' => $threads,
892 '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False),
899 * @brief Add comments to top level entries that had been fetched before
901 * The system will fetch the comments for the local user whenever possible.
902 * This behaviour is currently needed to allow commenting on Friendica posts.
904 * @param array $parents Parent items
906 * @return array items with parents and comments
908 function community_add_items($parents) {
909 $max_comments = Config::get("system", "max_comments", 100);
913 foreach ($parents AS $parent) {
914 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
915 AND `item`.`parent-uri` = ?
916 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
920 $comments = dba::inArray($thread_items);
922 // Check if the original item is in the result.
923 // When commenting from the community page there can be incomplete threads
924 if (count($comments) > 0) {
925 $parent_found = false;
926 foreach ($comments as $comment) {
927 if ($comment['uri'] == $comment['parent-uri']) {
928 $parent_found = true;
932 if (!$parent_found) {
937 if (count($comments) == 0) {
938 $thread_items = dba::p(item_query()." AND `item`.`uid` = 0
939 AND `item`.`parent-uri` = ?
940 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
943 $comments = dba::inArray($thread_items);
946 if (count($comments) != 0) {
947 $items = array_merge($items, $comments);
951 foreach ($items as $index => $item) {
952 if ($item['uid'] == 0) {
953 $items[$index]['writable'] = in_array($item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
957 $items = conv_sort($items, "`commented`");
962 function best_link_url($item, &$sparkle, $url = '') {
967 $clean_url = normalise_link($item['author-link']);
970 $r = dba::select('contact', array('id'),
971 array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
972 array('limit' => 1));
973 if (DBM::is_result($r)) {
974 $best_url = 'redir/' . $r['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 $r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
1023 if (DBM::is_result($r)) {
1025 $network = $r['network'];
1030 $status_link = $profile_link . '?url=status';
1031 $photos_link = $profile_link . '?url=photos';
1032 $profile_link = $profile_link . '?url=profile';
1034 $profile_link = zrl($profile_link);
1037 if ($cid && !$item['self']) {
1038 $poke_link = 'poke/?f=&c=' . $cid;
1039 $contact_url = 'contacts/' . $cid;
1040 $posts_link = 'contacts/' . $cid . '/posts';
1042 if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA))) {
1043 $pm_url = 'message/new/' . $cid;
1049 t('Follow Thread') => $sub_link,
1050 t('View Status') => $status_link,
1051 t('View Profile') => $profile_link,
1052 t('View Photos') => $photos_link,
1053 t('Network Posts') => $posts_link,
1054 t('View Contact') => $contact_url,
1055 t('Send PM') => $pm_url
1058 if ($network == NETWORK_DFRN) {
1059 $menu[t("Poke")] = $poke_link;
1062 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
1063 in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
1064 $menu[t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
1067 $menu = array(t('View Profile') => $item['author-link']);
1070 $args = array('item' => $item, 'menu' => $menu);
1072 call_hooks('item_photo_menu', $args);
1074 $menu = $args['menu'];
1077 foreach ($menu as $k => $v) {
1078 if (strpos($v, 'javascript:') === 0) {
1079 $v = substr($v, 11);
1080 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1082 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1089 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1090 * Increments the count of each matching activity and adds a link to the author as needed.
1092 * @param array $item
1093 * @param array &$conv_responses (already created with builtin activity structure)
1096 function builtin_activity_puller($item, &$conv_responses) {
1097 foreach ($conv_responses as $mode => $v) {
1103 $verb = ACTIVITY_LIKE;
1106 $verb = ACTIVITY_DISLIKE;
1109 $verb = ACTIVITY_ATTEND;
1112 $verb = ACTIVITY_ATTENDNO;
1115 $verb = ACTIVITY_ATTENDMAYBE;
1121 if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1122 $url = $item['author-link'];
1123 if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
1124 $url = 'redir/' . $item['contact-id'];
1125 $sparkle = ' class="sparkle" ';
1130 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1132 if (! $item['thr-parent']) {
1133 $item['thr-parent'] = $item['parent-uri'];
1136 if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1137 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
1138 $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
1141 // only list each unique author once
1142 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1146 if (! isset($conv_responses[$mode][$item['thr-parent']])) {
1147 $conv_responses[$mode][$item['thr-parent']] = 1;
1149 $conv_responses[$mode][$item['thr-parent']] ++;
1152 if (public_contact() == $item['author-id']) {
1153 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1156 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1158 // there can only be one activity verb per item so if we found anything, we can stop looking
1165 * Format the vote text for a profile item
1166 * @param int $cnt = number of people who vote the item
1167 * @param array $arr = array of pre-linked names of likers/dislikers
1168 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1169 * @param int $id = item id
1170 * @return formatted text
1172 function format_like($cnt, array $arr, $type, $id) {
1179 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1180 // list which show all likers
1183 $phrase = sprintf( t('%s likes this.'), $likers);
1186 $phrase = sprintf( t('%s doesn\'t like this.'), $likers);
1189 $phrase = sprintf( t('%s attends.'), $likers);
1192 $phrase = sprintf( t('%s doesn\'t attend.'), $likers);
1194 case 'attendmaybe' :
1195 $phrase = sprintf( t('%s attends maybe.'), $likers);
1201 $total = count($arr);
1202 if ($total >= MAX_LIKERS) {
1203 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1205 if ($total < MAX_LIKERS) {
1206 $last = t('and') . ' ' . $arr[count($arr)-1];
1207 $arr2 = array_slice($arr, 0, -1);
1208 $str = implode(', ', $arr2) . ' ' . $last;
1210 if ($total >= MAX_LIKERS) {
1211 $str = implode(', ', $arr);
1212 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1217 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1221 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
1222 $explikers = sprintf( t('%s like this.'), $likers);
1225 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
1226 $explikers = sprintf( t('%s don\'t like this.'), $likers);
1229 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend'), $spanatts, $cnt);
1230 $explikers = sprintf( t('%s attend.'), $likers);
1233 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
1234 $explikers = sprintf( t('%s don\'t attend.'), $likers);
1237 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend maybe'), $spanatts, $cnt);
1238 $explikers = sprintf( t('%s anttend maybe.'), $likers);
1242 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1246 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
1247 '$phrase' => $phrase,
1256 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1260 $geotag = x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '';
1262 $tpl = get_markup_template('jot-header.tpl');
1263 $a->page['htmlhead'] .= replace_macros($tpl, array(
1264 '$newpost' => 'true',
1265 '$baseurl' => System::baseUrl(true),
1266 '$geotag' => $geotag,
1267 '$nickname' => $x['nickname'],
1268 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1269 '$linkurl' => t('Please enter a link URL:'),
1270 '$vidurl' => t("Please enter a video link/URL:"),
1271 '$audurl' => t("Please enter an audio link/URL:"),
1272 '$term' => t('Tag term:'),
1273 '$fileas' => t('Save to Folder:'),
1274 '$whereareu' => t('Where are you right now?'),
1275 '$delitems' => t('Delete item(s)?')
1278 $tpl = get_markup_template('jot-end.tpl');
1279 $a->page['end'] .= replace_macros($tpl, array(
1280 '$newpost' => 'true',
1281 '$baseurl' => System::baseUrl(true),
1282 '$geotag' => $geotag,
1283 '$nickname' => $x['nickname'],
1284 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1285 '$linkurl' => t('Please enter a link URL:'),
1286 '$vidurl' => t("Please enter a video link/URL:"),
1287 '$audurl' => t("Please enter an audio link/URL:"),
1288 '$term' => t('Tag term:'),
1289 '$fileas' => t('Save to Folder:'),
1290 '$whereareu' => t('Where are you right now?')
1294 call_hooks('jot_tool', $jotplugins);
1296 // Private/public post links for the non-JS ACL form
1298 if (x($_REQUEST, 'public')) {
1302 $query_str = $a->query_string;
1303 if (strpos($query_str, 'public=1') !== false) {
1304 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1308 * I think $a->query_string may never have ? in it, but I could be wrong
1309 * It looks like it's from the index.php?q=[etc] rewrite that the web
1310 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1312 if (strpos($query_str, '?') === false) {
1313 $public_post_link = '?public=1';
1315 $public_post_link = '&public=1';
1318 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1319 $tpl = get_markup_template("jot.tpl");
1321 $o .= replace_macros($tpl,array(
1322 '$return_path' => $query_str,
1323 '$action' => 'item',
1324 '$share' => defaults($x, 'button', t('Share')),
1325 '$upload' => t('Upload photo'),
1326 '$shortupload' => t('upload photo'),
1327 '$attach' => t('Attach file'),
1328 '$shortattach' => t('attach file'),
1329 '$weblink' => t('Insert web link'),
1330 '$shortweblink' => t('web link'),
1331 '$video' => t('Insert video link'),
1332 '$shortvideo' => t('video link'),
1333 '$audio' => t('Insert audio link'),
1334 '$shortaudio' => t('audio link'),
1335 '$setloc' => t('Set your location'),
1336 '$shortsetloc' => t('set location'),
1337 '$noloc' => t('Clear browser location'),
1338 '$shortnoloc' => t('clear location'),
1339 '$title' => defaults($x, 'title', ''),
1340 '$placeholdertitle' => t('Set title'),
1341 '$category' => defaults($x, 'category', ''),
1342 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : '',
1343 '$wait' => t('Please wait'),
1344 '$permset' => t('Permission settings'),
1345 '$shortpermset' => t('permissions'),
1346 '$ptyp' => $notes_cid ? 'note' : 'wall',
1347 '$content' => defaults($x, 'content', ''),
1348 '$post_id' => defaults($x, 'post_id', ''),
1349 '$baseurl' => System::baseUrl(true),
1350 '$defloc' => $x['default_location'],
1351 '$visitor' => $x['visitor'],
1352 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1353 '$public' => t('Public post'),
1354 '$lockstate' => $x['lockstate'],
1355 '$bang' => $x['bang'],
1356 '$profile_uid' => $x['profile_uid'],
1357 '$preview' => Feature::isEnabled($x['profile_uid'], 'preview') ? t('Preview') : '',
1358 '$jotplugins' => $jotplugins,
1359 '$notes_cid' => $notes_cid,
1360 '$sourceapp' => t($a->sourcename),
1361 '$cancel' => t('Cancel'),
1362 '$rand_num' => random_digits(12),
1364 // ACL permissions box
1365 '$acl' => $x['acl'],
1366 '$group_perms' => t('Post to Groups'),
1367 '$contact_perms' => t('Post to Contacts'),
1368 '$private' => t('Private post'),
1369 '$is_private' => $private_post,
1370 '$public_link' => $public_post_link,
1372 //jot nav tab (used in some themes)
1373 '$message' => t('Message'),
1374 '$browser' => t('Browser'),
1378 if ($popup == true) {
1379 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1386 * Plucks the children of the given parent from a given item list.
1388 * @brief Plucks all the children in the given item list of the given parent
1390 * @param array $item_list
1391 * @param array $parent
1392 * @param bool $recursive
1395 function get_item_children(array &$item_list, array $parent, $recursive = true)
1398 foreach ($item_list as $i => $item) {
1399 if ($item['id'] != $item['parent']) {
1401 // Fallback to parent-uri if thr-parent is not set
1402 $thr_parent = $item['thr-parent'];
1403 if ($thr_parent == '') {
1404 $thr_parent = $item['parent-uri'];
1407 if ($thr_parent == $parent['uri']) {
1408 $item['children'] = get_item_children($item_list, $item);
1409 $children[] = $item;
1410 unset($item_list[$i]);
1412 } elseif ($item['parent'] == $parent['id']) {
1413 $children[] = $item;
1414 unset($item_list[$i]);
1422 * @brief Recursively sorts a tree-like item array
1424 * @param array $items
1427 function sort_item_children(array $items)
1430 usort($result, 'sort_thr_created_rev');
1431 foreach ($result as $k => $i) {
1432 if (isset($result[$k]['children'])) {
1433 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1440 * @brief Recursively add all children items at the top level of a list
1442 * @param array $children List of items to append
1443 * @param array $item_list
1445 function add_children_to_list(array $children, array &$item_list)
1447 foreach ($children as $child) {
1448 $item_list[] = $child;
1449 if (isset($child['children'])) {
1450 add_children_to_list($child['children'], $item_list);
1456 * This recursive function takes the item tree structure created by conv_sort() and
1457 * flatten the extraneous depth levels when people reply sequentially, removing the
1458 * stairs effect in threaded conversations limiting the available content width.
1460 * The basic principle is the following: if a post item has only one reply and is
1461 * the last reply of its parent, then the reply is moved to the parent.
1463 * This process is rendered somewhat more complicated because items can be either
1464 * replies or likes, and these don't factor at all in the reply count/last reply.
1466 * @brief Selectively flattens a tree-like item structure to prevent threading stairs
1468 * @param array $parent A tree-like array of items
1471 function smart_flatten_conversation(array $parent)
1473 if (! isset($parent['children']) || count($parent['children']) == 0) {
1477 // We use a for loop to ensure we process the newly-moved items
1478 for ($i = 0; $i < count($parent['children']); $i++) {
1479 $child = $parent['children'][$i];
1481 if (isset($child['children']) && count($child['children'])) {
1482 // This helps counting only the regular posts
1483 $count_post_closure = function($var) {
1484 return $var['verb'] === ACTIVITY_POST;
1487 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1489 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1491 // If there's only one child's children post and this is the last child post
1492 if ($child_post_count == 1 && $remaining_post_count == 1) {
1494 // Searches the post item in the children
1496 while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
1500 $moved_item = $child['children'][$j];
1501 unset($parent['children'][$i]['children'][$j]);
1502 $parent['children'][] = $moved_item;
1504 $parent['children'][$i] = smart_flatten_conversation($child);
1514 * Expands a flat list of items into corresponding tree-like conversation structures,
1515 * sort the top-level posts either on "created" or "commented", and finally
1516 * append all the items at the top level (???)
1518 * @brief Expands a flat item list into a conversation array for display
1520 * @param array $item_list A list of items belonging to one or more conversations
1521 * @param string $order Either on "created" or "commented"
1524 function conv_sort(array $item_list, $order)
1528 if (!(is_array($item_list) && count($item_list))) {
1534 // Dedupes the item list on the uri to prevent infinite loops
1535 foreach ($item_list as $item) {
1536 $item_array[$item['uri']] = $item;
1539 // Extract the top level items
1540 foreach ($item_array as $item) {
1541 if ($item['id'] == $item['parent']) {
1546 if (stristr($order, 'created')) {
1547 usort($parents, 'sort_thr_created');
1548 } elseif (stristr($order, 'commented')) {
1549 usort($parents, 'sort_thr_commented');
1553 * Plucks children from the item_array, second pass collects eventual orphan
1554 * items and add them as children of their top-level post.
1556 foreach ($parents as $i => $parent) {
1557 $parents[$i]['children'] =
1558 array_merge(get_item_children($item_array, $parent, true),
1559 get_item_children($item_array, $parent, false));
1562 foreach ($parents as $i => $parent) {
1563 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1566 if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
1567 foreach ($parents as $i => $parent) {
1568 $parents[$i] = smart_flatten_conversation($parent);
1572 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1573 /// However, this apparently ensures responses (likes, attendance) display (?!)
1574 foreach ($parents as $parent) {
1575 if (count($parent['children'])) {
1576 add_children_to_list($parent['children'], $parents);
1584 * @brief usort() callback to sort item arrays by the created key
1590 function sort_thr_created(array $a, array $b)
1592 return strcmp($b['created'], $a['created']);
1596 * @brief usort() callback to reverse sort item arrays by the created key
1602 function sort_thr_created_rev(array $a, array $b)
1604 return strcmp($a['created'], $b['created']);
1608 * @brief usort() callback to sort item arrays by the commented key
1614 function sort_thr_commented(array $a, array $b)
1616 return strcmp($b['commented'], $a['commented']);
1619 /// @TODO Add type-hint
1620 function render_location_dummy($item) {
1621 if ($item['location'] != "") {
1622 return $item['location'];
1625 if ($item['coord'] != "") {
1626 return $item['coord'];
1630 /// @TODO Add type-hint
1631 function get_responses($conv_responses, $response_verbs, $ob, $item) {
1633 foreach ($response_verbs as $v) {
1635 $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], '');
1636 $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', '');
1637 $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0');
1638 if (count($ret[$v]['list']) > MAX_LIKERS) {
1639 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1640 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1641 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
1643 $ret[$v]['list_part'] = '';
1645 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1646 $ret[$v]['title'] = $conv_responses[$v]['title'];
1650 foreach ($ret as $key) {
1651 if ($key['count'] == true) {
1655 $ret['count'] = $count;
1660 function get_response_button_text($v, $count)
1664 $return = tt('Like', 'Likes', $count);
1667 $return = tt('Dislike', 'Dislikes', $count);
1670 $return = tt('Attending', 'Attending', $count);
1673 $return = tt('Not Attending', 'Not Attending', $count);
1676 $return = tt('Undecided', 'Undecided', $count);