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) {
494 require_once 'include/bbcode.php';
495 require_once 'mod/proxy.php';
497 $ssl_state = ((local_user()) ? true : false);
500 $live_update_div = '';
505 $str_blocked = PConfig::get(local_user(), 'system', 'blocked');
507 $arr_blocked = explode(',', $str_blocked);
508 for ($x = 0; $x < count($arr_blocked); $x ++) {
509 $arr_blocked[$x] = trim($arr_blocked[$x]);
515 $previewing = (($preview) ? ' preview ' : '');
517 if ($mode === 'network') {
518 $profile_owner = local_user();
521 * The special div is needed for liveUpdate to kick in for this page.
522 * We only launch liveUpdate if you aren't filtering in some incompatible
523 * way and also you aren't writing a comment (discovered in javascript).
525 $live_update_div = '<div id="live-network"></div>' . "\r\n"
526 . "<script> var profile_uid = " . $_SESSION['uid']
527 . "; var netargs = '" . substr($a->cmd, 8)
529 . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
530 . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
531 . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
532 . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
533 . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
534 . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
535 . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
536 . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
537 . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
538 . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
539 . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
540 . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
542 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
544 } elseif ($mode === 'profile') {
545 $profile_owner = $a->profile['profile_uid'];
548 $tab = notags(trim($_GET['tab']));
549 $tab = ( $tab ? $tab : 'posts' );
550 if ($tab === 'posts') {
552 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
553 * because browser prefetching might change it on us. We have to deliver it with the page.
556 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
557 . "<script> var profile_uid = " . $a->profile['profile_uid']
558 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
561 } elseif ($mode === 'notes') {
562 $profile_owner = local_user();
564 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
565 . "<script> var profile_uid = " . local_user()
566 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
568 } elseif ($mode === 'display') {
569 $profile_owner = $a->profile['uid'];
571 $live_update_div = '<div id="live-display"></div>' . "\r\n"
572 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
573 . " var profile_page = 1; </script>";
575 } elseif ($mode === 'community') {
578 // $live_update_div = '<div id="live-community"></div>' . "\r\n"
579 // . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
581 } elseif ($mode === 'search') {
582 $live_update_div = '<div id="live-search"></div>' . "\r\n";
585 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
589 $return_url = $_SESSION['return_url'];
591 $return_url = $_SESSION['return_url'] = $a->query_string;
594 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
595 call_hooks('conversation_start',$cb);
597 $items = $cb['items'];
599 $cmnt_tpl = get_markup_template('comment_item.tpl');
600 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
602 $conv_responses = array(
603 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
604 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
607 // array with html for each thread (parent+comments)
611 $page_template = get_markup_template("conversation.tpl");
613 if ($items && count($items)) {
614 // Currently behind a config value. This allows the commenting and sharing of every public item.
615 if (Config::get('system', 'comment_public') && local_user()) {
616 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA));
622 if ($mode === 'network-new' || $mode === 'search') {
623 // || $mode === 'community') {
626 * "New Item View" on network page or search page results
627 * - just loop through the items and format them minimally for display
630 /// @TODO old lost code?
631 // $tpl = get_markup_template('search_item.tpl');
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)) {
657 if ($mode === 'search' || $mode === 'community') {
658 if (((activity_match($item['verb'], ACTIVITY_LIKE)) || (activity_match($item['verb'], ACTIVITY_DISLIKE)))
659 && ($item['id'] != $item['parent']))
661 $nickname = $item['nickname'];
663 $nickname = $a->user['nickname'];
666 // prevent private email from leaking.
667 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
671 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
672 if ($item['author-link'] && (! $item['author-name'])) {
673 $profile_name = $item['author-link'];
680 $searchpath = System::baseUrl()."/search?tag=";
682 $taglist = dba::select('term', array('type', 'term', 'url'),
683 array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
684 array('order' => array('tid')));
686 while ($tag = dba::fetch($taglist)) {
687 if ($tag["url"] == "") {
688 $tag["url"] = $searchpath . strtolower($tag["term"]);
691 $tag["url"] = best_link_url($item, $sp, $tag["url"]);
693 if ($tag["type"] == TERM_HASHTAG) {
694 $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
696 } elseif ($tag["type"] == TERM_MENTION) {
697 $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
700 $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
702 dba::close($taglist);
705 $profile_link = best_link_url($item, $sp);
706 if ($profile_link === 'mailbox') {
711 $sparkle = ' sparkle';
713 $profile_link = zrl($profile_link);
716 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
717 $author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
718 if ($author_contact["thumb"]) {
719 $item['author-thumb'] = $author_contact["thumb"];
721 $item['author-thumb'] = $item['author-avatar'];
725 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
726 $owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
727 if ($owner_contact["thumb"]) {
728 $item['owner-thumb'] = $owner_contact["thumb"];
730 $item['owner-thumb'] = $item['owner-avatar'];
734 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
735 call_hooks('render_location',$locate);
737 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
739 localize_item($item);
740 if ($mode === 'network-new') {
747 'dropping' => $dropping,
748 'pagedrop' => $page_dropping,
749 'select' => t('Select'),
750 'delete' => t('Delete'),
754 $isstarred = "unstarred";
757 $likebuttons = false;
760 $body = prepare_body($item, true, $preview);
762 list($categories, $folders) = get_cats_and_terms($item);
764 $profile_name_e = $profile_name;
765 $item['title_e'] = $item['title'];
768 $hashtags_e = $hashtags;
769 $mentions_e = $mentions;
770 $location_e = $location;
771 $owner_name_e = $owner_name;
773 if ($item['item_network'] == "") {
774 $item['item_network'] = $item['network'];
779 'id' => (($preview) ? 'P0' : $item['item_id']),
780 'guid' => (($preview) ? 'Q0' : $item['guid']),
781 'network' => $item['item_network'],
782 'network_name' => network_to_name($item['item_network'], $profile_link),
783 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
784 'profile_url' => $profile_link,
785 'item_photo_menu' => item_photo_menu($item),
786 'name' => $profile_name_e,
787 'sparkle' => $sparkle,
789 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
790 'title' => $item['title_e'],
793 'hashtags' => $hashtags_e,
794 'mentions' => $mentions_e,
795 'txt_cats' => t('Categories:'),
796 'txt_folders' => t('Filed under:'),
797 'has_cats' => ((count($categories)) ? 'true' : ''),
798 'has_folders' => ((count($folders)) ? 'true' : ''),
799 'categories' => $categories,
800 'folders' => $folders,
801 'text' => strip_tags($body_e),
802 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
803 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
804 'location' => $location_e,
806 'owner_name' => $owner_name_e,
807 'owner_url' => $owner_url,
808 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
809 'plink' => get_plink($item),
811 'isstarred' => $isstarred,
814 'vote' => $likebuttons,
818 //'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
819 'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
820 'previewing' => $previewing,
821 'wait' => t('Please wait'),
825 $arr = array('item' => $item, 'output' => $tmp_item);
826 call_hooks('display_item', $arr);
828 $threads[$threadsid]['id'] = $item['item_id'];
829 $threads[$threadsid]['network'] = $item['item_network'];
830 $threads[$threadsid]['items'] = array($arr['output']);
835 $page_template = get_markup_template("threaded_conversation.tpl");
837 $conv = new Thread($mode, $preview, $writable);
840 * get all the topmost parents
841 * this shouldn't be needed, as we should have only them in our array
842 * But for now, this array respects the old style, just in case
845 foreach ($items as $item) {
849 foreach ($arr_blocked as $b) {
850 if ($b && link_compare($item['author-link'], $b)) {
860 // Can we put this after the visibility check?
861 builtin_activity_puller($item, $conv_responses);
863 // Only add what is visible
864 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
868 if (! visible_activity($item)) {
872 call_hooks('display_item', $arr);
874 $item['pagedrop'] = $page_dropping;
876 if ($item['id'] == $item['parent']) {
877 $item_object = new Post($item);
878 $conv->addParent($item_object);
882 $threads = $conv->getTemplateData($conv_responses);
885 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
891 $o = replace_macros($page_template, array(
892 '$baseurl' => System::baseUrl($ssl_state),
893 '$return_path' => $a->query_string,
894 '$live_update' => $live_update_div,
895 '$remove' => t('remove'),
898 '$threads' => $threads,
899 '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False),
905 function best_link_url($item, &$sparkle, $url = '') {
910 $clean_url = normalise_link($item['author-link']);
913 $r = dba::select('contact', array('id'),
914 array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
915 array('limit' => 1));
916 if (DBM::is_result($r)) {
917 $best_url = 'redir/' . $r['id'];
920 $hostname = get_app()->get_hostname();
921 if (!strstr($url, $hostname)) {
922 $best_url .= "?url=".$url;
932 } elseif (strlen($item['author-link'])) {
933 $best_url = $item['author-link'];
935 $best_url = $item['url'];
943 function item_photo_menu($item) {
953 if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
954 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
958 $profile_link = best_link_url($item, $sparkle);
959 if ($profile_link === 'mailbox') {
966 $r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
967 if (DBM::is_result($r)) {
969 $network = $r['network'];
974 $status_link = $profile_link . '?url=status';
975 $photos_link = $profile_link . '?url=photos';
976 $profile_link = $profile_link . '?url=profile';
979 $profile_link = zrl($profile_link);
982 if ($cid && !$item['self']) {
983 $poke_link = 'poke/?f=&c=' . $cid;
984 $contact_url = 'contacts/' . $cid;
985 $posts_link = 'contacts/' . $cid . '/posts';
987 if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA))) {
988 $pm_url = 'message/new/' . $cid;
994 t('Follow Thread') => $sub_link,
995 t('View Status') => $status_link,
996 t('View Profile') => $profile_link,
997 t('View Photos') => $photos_link,
998 t('Network Posts') => $posts_link,
999 t('View Contact') => $contact_url,
1000 t('Send PM') => $pm_url
1003 if ($network == NETWORK_DFRN) {
1004 $menu[t("Poke")] = $poke_link;
1007 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
1008 in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
1009 $menu[t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
1012 $menu = array(t('View Profile') => $item['author-link']);
1015 $args = array('item' => $item, 'menu' => $menu);
1017 call_hooks('item_photo_menu', $args);
1019 $menu = $args['menu'];
1022 foreach ($menu as $k => $v) {
1023 if (strpos($v, 'javascript:') === 0) {
1024 $v = substr($v, 11);
1025 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1027 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1034 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1035 * Increments the count of each matching activity and adds a link to the author as needed.
1037 * @param array $item
1038 * @param array &$conv_responses (already created with builtin activity structure)
1041 function builtin_activity_puller($item, &$conv_responses) {
1042 foreach ($conv_responses as $mode => $v) {
1048 $verb = ACTIVITY_LIKE;
1051 $verb = ACTIVITY_DISLIKE;
1054 $verb = ACTIVITY_ATTEND;
1057 $verb = ACTIVITY_ATTENDNO;
1060 $verb = ACTIVITY_ATTENDMAYBE;
1067 if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1068 $url = $item['author-link'];
1069 if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
1070 $url = 'redir/' . $item['contact-id'];
1071 $sparkle = ' class="sparkle" ';
1076 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1078 if (! $item['thr-parent']) {
1079 $item['thr-parent'] = $item['parent-uri'];
1082 if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1083 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
1084 $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
1087 // only list each unique author once
1088 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1092 if (! isset($conv_responses[$mode][$item['thr-parent']])) {
1093 $conv_responses[$mode][$item['thr-parent']] = 1;
1095 $conv_responses[$mode][$item['thr-parent']] ++;
1098 if (public_contact() == $item['author-id']) {
1099 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1102 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1104 // there can only be one activity verb per item so if we found anything, we can stop looking
1111 * Format the vote text for a profile item
1112 * @param int $cnt = number of people who vote the item
1113 * @param array $arr = array of pre-linked names of likers/dislikers
1114 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1115 * @param int $id = item id
1116 * @return formatted text
1118 function format_like($cnt, array $arr, $type, $id) {
1125 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1126 // list which show all likers
1129 $phrase = sprintf( t('%s likes this.'), $likers);
1132 $phrase = sprintf( t('%s doesn\'t like this.'), $likers);
1135 $phrase = sprintf( t('%s attends.'), $likers);
1138 $phrase = sprintf( t('%s doesn\'t attend.'), $likers);
1140 case 'attendmaybe' :
1141 $phrase = sprintf( t('%s attends maybe.'), $likers);
1147 $total = count($arr);
1148 if ($total >= MAX_LIKERS) {
1149 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1151 if ($total < MAX_LIKERS) {
1152 $last = t('and') . ' ' . $arr[count($arr)-1];
1153 $arr2 = array_slice($arr, 0, -1);
1154 $str = implode(', ', $arr2) . ' ' . $last;
1156 if ($total >= MAX_LIKERS) {
1157 $str = implode(', ', $arr);
1158 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1163 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1167 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
1168 $explikers = sprintf( t('%s like this.'), $likers);
1171 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
1172 $explikers = sprintf( t('%s don\'t like this.'), $likers);
1175 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend'), $spanatts, $cnt);
1176 $explikers = sprintf( t('%s attend.'), $likers);
1179 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
1180 $explikers = sprintf( t('%s don\'t attend.'), $likers);
1183 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend maybe'), $spanatts, $cnt);
1184 $explikers = sprintf( t('%s anttend maybe.'), $likers);
1188 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1192 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
1193 '$phrase' => $phrase,
1202 function status_editor(App $a, $x, $notes_cid = 0, $popup = false) {
1205 $geotag = (x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
1207 $tpl = get_markup_template('jot-header.tpl');
1208 $a->page['htmlhead'] .= replace_macros($tpl, array(
1209 '$newpost' => 'true',
1210 '$baseurl' => System::baseUrl(true),
1211 '$geotag' => $geotag,
1212 '$nickname' => $x['nickname'],
1213 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1214 '$linkurl' => t('Please enter a link URL:'),
1215 '$vidurl' => t("Please enter a video link/URL:"),
1216 '$audurl' => t("Please enter an audio link/URL:"),
1217 '$term' => t('Tag term:'),
1218 '$fileas' => t('Save to Folder:'),
1219 '$whereareu' => t('Where are you right now?'),
1220 '$delitems' => t('Delete item(s)?')
1223 $tpl = get_markup_template('jot-end.tpl');
1224 $a->page['end'] .= replace_macros($tpl, array(
1225 '$newpost' => 'true',
1226 '$baseurl' => System::baseUrl(true),
1227 '$geotag' => $geotag,
1228 '$nickname' => $x['nickname'],
1229 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1230 '$linkurl' => t('Please enter a link URL:'),
1231 '$vidurl' => t("Please enter a video link/URL:"),
1232 '$audurl' => t("Please enter an audio link/URL:"),
1233 '$term' => t('Tag term:'),
1234 '$fileas' => t('Save to Folder:'),
1235 '$whereareu' => t('Where are you right now?')
1239 call_hooks('jot_tool', $jotplugins);
1241 // Private/public post links for the non-JS ACL form
1243 if (x($_REQUEST, 'public')) {
1247 $query_str = $a->query_string;
1248 if (strpos($query_str, 'public=1') !== false) {
1249 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1253 * I think $a->query_string may never have ? in it, but I could be wrong
1254 * It looks like it's from the index.php?q=[etc] rewrite that the web
1255 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1257 if (strpos($query_str, '?') === false) {
1258 $public_post_link = '?public=1';
1260 $public_post_link = '&public=1';
1263 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1264 $tpl = get_markup_template("jot.tpl");
1266 $o .= replace_macros($tpl,array(
1267 '$return_path' => $query_str,
1268 '$action' => 'item',
1269 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1270 '$upload' => t('Upload photo'),
1271 '$shortupload' => t('upload photo'),
1272 '$attach' => t('Attach file'),
1273 '$shortattach' => t('attach file'),
1274 '$weblink' => t('Insert web link'),
1275 '$shortweblink' => t('web link'),
1276 '$video' => t('Insert video link'),
1277 '$shortvideo' => t('video link'),
1278 '$audio' => t('Insert audio link'),
1279 '$shortaudio' => t('audio link'),
1280 '$setloc' => t('Set your location'),
1281 '$shortsetloc' => t('set location'),
1282 '$noloc' => t('Clear browser location'),
1283 '$shortnoloc' => t('clear location'),
1284 '$title' => $x['title'],
1285 '$placeholdertitle' => t('Set title'),
1286 '$category' => $x['category'],
1287 '$placeholdercategory' => (Feature::isEnabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''),
1288 '$wait' => t('Please wait'),
1289 '$permset' => t('Permission settings'),
1290 '$shortpermset' => t('permissions'),
1291 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1292 '$content' => $x['content'],
1293 '$post_id' => $x['post_id'],
1294 '$baseurl' => System::baseUrl(true),
1295 '$defloc' => $x['default_location'],
1296 '$visitor' => $x['visitor'],
1297 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1298 '$public' => t('Public post'),
1299 '$jotnets' => $jotnets,
1300 '$lockstate' => $x['lockstate'],
1301 '$bang' => $x['bang'],
1302 '$profile_uid' => $x['profile_uid'],
1303 '$preview' => ((Feature::isEnabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1304 '$jotplugins' => $jotplugins,
1305 '$notes_cid' => $notes_cid,
1306 '$sourceapp' => t($a->sourcename),
1307 '$cancel' => t('Cancel'),
1308 '$rand_num' => random_digits(12),
1310 // ACL permissions box
1311 '$acl' => $x['acl'],
1312 '$acl_data' => $x['acl_data'],
1313 '$group_perms' => t('Post to Groups'),
1314 '$contact_perms' => t('Post to Contacts'),
1315 '$private' => t('Private post'),
1316 '$is_private' => $private_post,
1317 '$public_link' => $public_post_link,
1319 //jot nav tab (used in some themes)
1320 '$message' => t('Message'),
1321 '$browser' => t('Browser'),
1325 if ($popup == true) {
1326 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1333 * Plucks the children of the given parent from a given item list.
1335 * @brief Plucks all the children in the given item list of the given parent
1337 * @param array $item_list
1338 * @param array $parent
1339 * @param bool $recursive
1342 function get_item_children(array &$item_list, array $parent, $recursive = true)
1345 foreach ($item_list as $i => $item) {
1346 if ($item['id'] != $item['parent']) {
1348 // Fallback to parent-uri if thr-parent is not set
1349 $thr_parent = $item['thr-parent'];
1350 if ($thr_parent == '') {
1351 $thr_parent = $item['parent-uri'];
1354 if ($thr_parent == $parent['uri']) {
1355 $item['children'] = get_item_children($item_list, $item);
1356 $children[] = $item;
1357 unset($item_list[$i]);
1359 } elseif ($item['parent'] == $parent['id']) {
1360 $children[] = $item;
1361 unset($item_list[$i]);
1369 * @brief Recursively sorts a tree-like item array
1371 * @param array $items
1374 function sort_item_children(array $items)
1377 usort($result, 'sort_thr_created_rev');
1378 foreach ($result as $k => $i) {
1379 if (isset($result[$k]['children'])) {
1380 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1387 * @brief Recursively add all children items at the top level of a list
1389 * @param array $children List of items to append
1390 * @param array $item_list
1392 function add_children_to_list(array $children, array &$item_list)
1394 foreach ($children as $child) {
1395 $item_list[] = $child;
1396 if (isset($child['children'])) {
1397 add_children_to_list($child['children'], $item_list);
1403 * This recursive function takes the item tree structure created by conv_sort() and
1404 * flatten the extraneous depth levels when people reply sequentially, removing the
1405 * stairs effect in threaded conversations limiting the available content width.
1407 * The basic principle is the following: if a post item has only one reply and is
1408 * the last reply of its parent, then the reply is moved to the parent.
1410 * This process is rendered somewhat more complicated because items can be either
1411 * replies or likes, and these don't factor at all in the reply count/last reply.
1413 * @brief Selectively flattens a tree-like item structure to prevent threading stairs
1415 * @param array $parent A tree-like array of items
1418 function smart_flatten_conversation(array $parent)
1420 if (! isset($parent['children']) || count($parent['children']) == 0) {
1424 // We use a for loop to ensure we process the newly-moved items
1425 for ($i = 0; $i < count($parent['children']); $i++) {
1426 $child = $parent['children'][$i];
1428 if (isset($child['children']) && count($child['children'])) {
1429 // This helps counting only the regular posts
1430 $count_post_closure = function($var) {
1431 return $var['verb'] === ACTIVITY_POST;
1434 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1436 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1438 // If there's only one child's children post and this is the last child post
1439 if ($child_post_count == 1 && $remaining_post_count == 1) {
1441 // Searches the post item in the children
1443 while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
1447 $moved_item = $child['children'][$j];
1448 unset($parent['children'][$i]['children'][$j]);
1449 $parent['children'][] = $moved_item;
1451 $parent['children'][$i] = smart_flatten_conversation($child);
1461 * Expands a flat list of items into corresponding tree-like conversation structures,
1462 * sort the top-level posts either on "created" or "commented", and finally
1463 * append all the items at the top level (???)
1465 * @brief Expands a flat item list into a conversation array for display
1467 * @param array $item_list A list of items belonging to one or more conversations
1468 * @param string $order Either on "created" or "commented"
1471 function conv_sort(array $item_list, $order)
1475 if (!(is_array($item_list) && count($item_list))) {
1481 // Dedupes the item list on the uri to prevent infinite loops
1482 foreach ($item_list as $item) {
1483 $item_array[$item['uri']] = $item;
1486 // Extract the top level items
1487 foreach ($item_array as $item) {
1488 if ($item['id'] == $item['parent']) {
1493 if (stristr($order, 'created')) {
1494 usort($parents, 'sort_thr_created');
1495 } elseif (stristr($order, 'commented')) {
1496 usort($parents, 'sort_thr_commented');
1500 * Plucks children from the item_array, second pass collects eventual orphan
1501 * items and add them as children of their top-level post.
1503 foreach ($parents as $i => $parent) {
1504 $parents[$i]['children'] =
1505 array_merge(get_item_children($item_array, $parent, true),
1506 get_item_children($item_array, $parent, false));
1509 foreach ($parents as $i => $parent) {
1510 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1513 if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
1514 foreach ($parents as $i => $parent) {
1515 $parents[$i] = smart_flatten_conversation($parent);
1519 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1520 /// However, this apparently ensures responses (likes, attendance) display (?!)
1521 foreach ($parents as $parent) {
1522 if (count($parent['children'])) {
1523 add_children_to_list($parent['children'], $parents);
1531 * @brief usort() callback to sort item arrays by the created key
1537 function sort_thr_created(array $a, array $b)
1539 return strcmp($b['created'], $a['created']);
1543 * @brief usort() callback to reverse sort item arrays by the created key
1549 function sort_thr_created_rev(array $a, array $b)
1551 return strcmp($a['created'], $b['created']);
1555 * @brief usort() callback to sort item arrays by the commented key
1561 function sort_thr_commented(array $a, array $b)
1563 return strcmp($b['commented'], $a['commented']);
1566 /// @TODO Add type-hint
1567 function render_location_dummy($item) {
1568 if ($item['location'] != "") {
1569 return $item['location'];
1572 if ($item['coord'] != "") {
1573 return $item['coord'];
1577 /// @TODO Add type-hint
1578 function get_responses($conv_responses, $response_verbs, $ob, $item) {
1580 foreach ($response_verbs as $v) {
1582 $ret[$v]['count'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
1583 $ret[$v]['list'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
1584 $ret[$v]['self'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0');
1585 if (count($ret[$v]['list']) > MAX_LIKERS) {
1586 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1587 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1588 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
1590 $ret[$v]['list_part'] = '';
1592 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1593 $ret[$v]['title'] = $conv_responses[$v]['title'];
1597 foreach ($ret as $key) {
1598 if ($key['count'] == true) {
1602 $ret['count'] = $count;
1607 function get_response_button_text($v, $count) {
1610 return tt('Like', 'Likes', $count, 'noun');
1613 return tt('Dislike', 'Dislikes', $count, 'noun');
1616 return tt('Attending', 'Attending', $count, 'noun');
1619 return tt('Not Attending', 'Not Attending', $count, 'noun');
1622 return tt('Undecided', 'Undecided', $count, 'noun');