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 function item_extract_images($body) {
31 $img_start = strpos($orig_body, '[img');
32 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
33 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
34 while (($img_st_close !== false) && ($img_end !== false)) {
36 $img_st_close++; // make it point to AFTER the closing bracket
37 $img_end += $img_start;
39 if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
40 // This is an embedded image
42 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
43 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
47 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
50 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
52 if ($orig_body === false) {
53 // in case the body ends on a closing image tag
57 $img_start = strpos($orig_body, '[img');
58 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
59 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
62 $new_body = $new_body . $orig_body;
64 return ['body' => $new_body, 'images' => $saved_image];
67 function item_redir_and_replace_images($body, $images, $cid) {
73 $pos = BBCode::getTagPosition($origbody, 'url', 0);
74 while ($pos !== false && $cnt < 1000) {
76 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
77 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
78 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
80 $newbody .= substr($origbody, 0, $pos['start']['open']);
81 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
82 $origbody = substr($origbody, $pos['end']['close']);
83 if ($origbody === false) {
87 $subject = preg_replace($search, $replace, $subject);
91 // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
92 $pos = BBCode::getTagPosition($origbody, 'url', 0);
94 $newbody .= $origbody;
97 foreach ($images as $image) {
99 * We're depending on the property of 'foreach' (specified on the PHP website) that
100 * it loops over the array starting from the first element and going sequentially
101 * to the last element.
103 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
110 * Render actions localized
112 function localize_item(&$item) {
114 $extracted = item_extract_images($item['body']);
115 if ($extracted['images']) {
116 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
119 /// @TODO Separted ???
120 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
121 if (activity_match($item['verb'], ACTIVITY_LIKE)
122 || activity_match($item['verb'], ACTIVITY_DISLIKE)
123 || activity_match($item['verb'], ACTIVITY_ATTEND)
124 || activity_match($item['verb'], ACTIVITY_ATTENDNO)
125 || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
127 /// @TODO may hurt performance
128 $r = q("SELECT * FROM `item`, `contact`
129 WHERE `item`.`contact-id`=`contact`.`id`
130 AND `item`.`uri`='%s'",
131 dbesc($item['parent-uri']));
132 if (!DBM::is_result($r)) {
137 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
138 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
140 switch ($obj['verb']) {
142 switch ($obj['object-type']) {
143 case ACTIVITY_OBJ_EVENT:
144 $post_type = L10n::t('event');
147 $post_type = L10n::t('status');
151 if ($obj['resource-id']) {
152 $post_type = L10n::t('photo');
154 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
155 $rr['plink'] = $m[1];
157 $post_type = L10n::t('status');
161 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
163 if (activity_match($item['verb'], ACTIVITY_LIKE)) {
164 $bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
165 } elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
166 $bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
167 } elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
168 $bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
169 } elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
170 $bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
171 } elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
172 $bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
175 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
178 if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
180 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
182 $Aname = $item['author-name'];
183 $Alink = $item['author-link'];
185 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
187 $obj = XML::parseString($xmlhead.$item['object']);
188 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
190 $Bname = $obj->title;
191 $Blink = ""; $Bphoto = "";
192 foreach ($links->link as $l) {
193 $atts = $l->attributes();
194 switch ($atts['rel']) {
195 case "alternate": $Blink = $atts['href'];
196 case "photo": $Bphoto = $atts['href'];
200 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
201 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
203 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img]' . $Bphoto . '[/img][/url]';
206 $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
209 if (stristr($item['verb'], ACTIVITY_POKE)) {
210 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
214 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
218 $Aname = $item['author-name'];
219 $Alink = $item['author-link'];
221 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
223 $obj = XML::parseString($xmlhead.$item['object']);
224 $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
226 $Bname = $obj->title;
229 foreach ($links->link as $l) {
230 $atts = $l->attributes();
231 switch ($atts['rel']) {
232 case "alternate": $Blink = $atts['href'];
233 case "photo": $Bphoto = $atts['href'];
237 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
238 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
240 $Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
244 * we can't have a translation string with three positions but no distinguishable text
245 * So here is the translate string.
247 $txt = L10n::t('%1$s poked %2$s');
249 // now translate the verb
250 $poked_t = trim(sprintf($txt, "", ""));
251 $txt = str_replace( $poked_t, L10n::t($verb), $txt);
253 // then do the sprintf on the translation string
255 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
259 if (activity_match($item['verb'], ACTIVITY_TAG)) {
260 /// @TODO may hurt performance "joining" two tables + asterisk
261 $r = q("SELECT * FROM `item`, `contact`
262 WHERE `item`.`contact-id`=`contact`.`id`
263 AND `item`.`uri`='%s'",
264 dbesc($item['parent-uri']));
266 if (!DBM::is_result($r)) {
272 $author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
273 $objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
275 switch ($obj['verb']) {
277 switch ($obj['object-type']) {
278 case ACTIVITY_OBJ_EVENT:
279 $post_type = L10n::t('event');
282 $post_type = L10n::t('status');
286 if ($obj['resource-id']) {
287 $post_type = L10n::t('photo');
288 $m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
289 $rr['plink'] = $m[1];
291 $post_type = L10n::t('status');
293 // Let's break everthing ... ;-)
296 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
298 $parsedobj = XML::parseString($xmlhead.$item['object']);
300 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
301 $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
305 if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
306 if ($item['object-type'] == "") {
310 $Aname = $item['author-name'];
311 $Alink = $item['author-link'];
313 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
315 $obj = XML::parseString($xmlhead.$item['object']);
316 if (strlen($obj->id)) {
317 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
322 if (DBM::is_result($r) && $r[0]['plink']) {
324 $Bname = $target['author-name'];
325 $Blink = $target['author-link'];
326 $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
327 $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
328 $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
329 $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
334 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
335 foreach ($matches as $mtch) {
336 if (!strpos($mtch[1], 'zrl=')) {
337 $item['body'] = str_replace($mtch[0], '@[url=' . Contact::magicLink($mtch[1]) . ']', $item['body']);
342 // add zrl's to public images
343 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
344 if (preg_match($photo_pattern, $item['body'])) {
345 $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
346 $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
349 // add sparkle links to appropriate permalinks
350 $item['plink'] = Contact::magicLinkById($item['author-id'], $item['plink']);
354 * Count the total of comments on this item and its desendants
355 * @TODO proper type-hint + doc-tag
357 function count_descendants($item) {
358 $total = count($item['children']);
361 foreach ($item['children'] as $child) {
362 if (!visible_activity($child)) {
365 $total += count_descendants($child);
372 function visible_activity($item) {
375 * likes (etc.) can apply to other things besides posts. Check if they are post children,
376 * in which case we handle them specially
378 $hidden_activities = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
379 foreach ($hidden_activities as $act) {
380 if (activity_match($item['verb'], $act)) {
385 // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
386 if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
394 * @brief SQL query for items
396 * @param int $uid user id
398 function item_query($uid = 0) {
399 return "SELECT " . item_fieldlists() . " FROM `item` " .
400 item_joins($uid) . " WHERE " . item_condition();
404 * @brief List of all data fields that are needed for displaying items
406 function item_fieldlists() {
409 These Fields are not added below (yet). They are here to for bug search.
414 `item`.`target-type`,
416 `item`.`resource-id`,
431 return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
432 `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
433 `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
434 `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`,
435 `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
436 `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
437 `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, `item`.`origin`,
438 `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
439 `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
440 `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
441 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
442 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
444 `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
446 `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
447 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
449 `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
450 `event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
451 `event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
452 `event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
453 `event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
454 `event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
458 * @brief SQL join for contacts that are needed for displaying items
460 * @param int $uid user id
462 function item_joins($uid = 0) {
463 return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
464 AND NOT `contact`.`blocked`
465 AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
466 OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0)
467 INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
468 INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
469 LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
470 LEFT JOIN `event` ON `event-id` = `event`.`id`",
471 CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid)
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` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
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, $order = 'commented', $uid = 0) {
493 require_once 'mod/proxy.php';
495 $ssl_state = ((local_user()) ? true : false);
498 $live_update_div = '';
503 $str_blocked = PConfig::get(local_user(), 'system', 'blocked');
505 $arr_blocked = explode(',', $str_blocked);
506 for ($x = 0; $x < count($arr_blocked); $x ++) {
507 $arr_blocked[$x] = trim($arr_blocked[$x]);
513 $previewing = (($preview) ? ' preview ' : '');
515 if ($mode === 'network') {
516 $items = conversation_add_children($items, false, $order, $uid);
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 $items = conversation_add_children($items, true, $order, $uid);
580 $live_update_div = '<div id="live-community"></div>' . "\r\n"
581 . "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
582 ."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
584 } elseif ($mode === 'search') {
585 $live_update_div = '<div id="live-search"></div>' . "\r\n";
588 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
591 $_SESSION['return_url'] = $a->query_string;
594 $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
595 Addon::callHooks('conversation_start',$cb);
597 $items = $cb['items'];
600 'like' => ['title' => L10n::t('Likes','title')], 'dislike' => ['title' => L10n::t('Dislikes','title')],
601 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
604 // array with html for each thread (parent+comments)
608 $page_template = get_markup_template("conversation.tpl");
610 if ($items && count($items)) {
611 if ($mode === 'community') {
614 $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
621 if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
624 * "New Item View" on network page or search page results
625 * - just loop through the items and format them minimally for display
628 $tpl = 'search_item.tpl';
630 foreach ($items as $item) {
632 if (!visible_activity($item)) {
638 foreach ($arr_blocked as $b) {
639 if ($b && link_compare($item['author-link'], $b)) {
656 // prevent private email from leaking.
657 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
661 $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']);
662 if ($item['author-link'] && !$item['author-name']) {
663 $profile_name = $item['author-link'];
666 $tags = \Friendica\Model\Term::populateTagsFromItem($item);
668 $profile_link = Contact::magicLinkbyId($item['author-id']);
670 if (strpos($profile_link, 'redir/') === 0) {
671 $sparkle = ' sparkle';
674 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
675 $author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
676 if ($author_contact["thumb"]) {
677 $item['author-thumb'] = $author_contact["thumb"];
679 $item['author-thumb'] = $item['author-avatar'];
683 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
684 $owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
685 if ($owner_contact["thumb"]) {
686 $item['owner-thumb'] = $owner_contact["thumb"];
688 $item['owner-thumb'] = $item['owner-avatar'];
692 $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
693 Addon::callHooks('render_location',$locate);
695 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
697 localize_item($item);
698 if ($mode === 'network-new') {
705 'dropping' => $dropping,
706 'pagedrop' => $page_dropping,
707 'select' => L10n::t('Select'),
708 'delete' => L10n::t('Delete'),
712 $isstarred = "unstarred";
715 $likebuttons = false;
717 $body = prepare_body($item, true, $preview);
719 list($categories, $folders) = get_cats_and_terms($item);
721 $profile_name_e = $profile_name;
723 if (!empty($item['content-warning']) && PConfig::get(local_user(), 'system', 'disable_cw', false)) {
724 $title_e = ucfirst($item['content-warning']);
726 $title_e = $item['title'];
730 $tags_e = $tags['tags'];
731 $hashtags_e = $tags['hashtags'];
732 $mentions_e = $tags['mentions'];
733 $location_e = $location;
734 $owner_name_e = $owner_name;
736 if ($item['item_network'] == "") {
737 $item['item_network'] = $item['network'];
742 'id' => (($preview) ? 'P0' : $item['item_id']),
743 'guid' => (($preview) ? 'Q0' : $item['guid']),
744 'network' => $item['item_network'],
745 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
746 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
747 'profile_url' => $profile_link,
748 'item_photo_menu' => item_photo_menu($item),
749 'name' => $profile_name_e,
750 'sparkle' => $sparkle,
752 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
756 'hashtags' => $hashtags_e,
757 'mentions' => $mentions_e,
758 'txt_cats' => L10n::t('Categories:'),
759 'txt_folders' => L10n::t('Filed under:'),
760 'has_cats' => ((count($categories)) ? 'true' : ''),
761 'has_folders' => ((count($folders)) ? 'true' : ''),
762 'categories' => $categories,
763 'folders' => $folders,
764 'text' => strip_tags($body_e),
765 'localtime' => DateTimeFormat::local($item['created'], 'r'),
766 'ago' => (($item['app']) ? L10n::t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
767 'location' => $location_e,
769 'owner_name' => $owner_name_e,
770 'owner_url' => $owner_url,
771 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
772 'plink' => get_plink($item),
774 'isstarred' => $isstarred,
777 'vote' => $likebuttons,
781 'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> L10n::t('View in context')]),
782 'previewing' => $previewing,
783 'wait' => L10n::t('Please wait'),
787 $arr = ['item' => $item, 'output' => $tmp_item];
788 Addon::callHooks('display_item', $arr);
790 $threads[$threadsid]['id'] = $item['item_id'];
791 $threads[$threadsid]['network'] = $item['item_network'];
792 $threads[$threadsid]['items'] = [$arr['output']];
797 $page_template = get_markup_template("threaded_conversation.tpl");
799 $conv = new Thread($mode, $preview, $writable);
802 * get all the topmost parents
803 * this shouldn't be needed, as we should have only them in our array
804 * But for now, this array respects the old style, just in case
806 foreach ($items as $item) {
809 foreach ($arr_blocked as $b) {
810 if ($b && link_compare($item['author-link'], $b)) {
820 // Can we put this after the visibility check?
821 builtin_activity_puller($item, $conv_responses);
823 // Only add what is visible
824 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
828 if (!visible_activity($item)) {
832 Addon::callHooks('display_item', $arr);
834 $item['pagedrop'] = $page_dropping;
836 if ($item['id'] == $item['parent']) {
837 $item_object = new Post($item);
838 $conv->addParent($item_object);
842 $threads = $conv->getTemplateData($conv_responses);
844 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
850 $o = replace_macros($page_template, [
851 '$baseurl' => System::baseUrl($ssl_state),
852 '$return_path' => $a->query_string,
853 '$live_update' => $live_update_div,
854 '$remove' => L10n::t('remove'),
857 '$threads' => $threads,
858 '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? L10n::t('Delete Selected Items') : False),
865 * @brief Add comments to top level entries that had been fetched before
867 * The system will fetch the comments for the local user whenever possible.
868 * This behaviour is currently needed to allow commenting on Friendica posts.
870 * @param array $parents Parent items
872 * @return array items with parents and comments
874 function conversation_add_children($parents, $block_authors, $order, $uid) {
875 $max_comments = Config::get('system', 'max_comments', 100);
877 if ($max_comments > 0) {
878 $limit = ' LIMIT '.intval($max_comments + 1);
885 $block_sql = $block_authors ? "AND NOT `author`.`hidden` AND NOT `author`.`blocked`" : "";
887 foreach ($parents AS $parent) {
888 $thread_items = dba::p(item_query(local_user())."AND `item`.`parent-uri` = ?
889 AND `item`.`uid` IN (0, ?) $block_sql
890 ORDER BY `item`.`uid` ASC, `item`.`commented` DESC" . $limit,
891 $parent['uri'], local_user());
893 $comments = dba::inArray($thread_items);
895 if (count($comments) != 0) {
896 $items = array_merge($items, $comments);
900 foreach ($items as $index => $item) {
901 if ($item['uid'] == 0) {
902 $items[$index]['writable'] = in_array($item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
906 $items = conv_sort($items, $order);
911 function item_photo_menu($item) {
920 if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) {
921 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
924 $profile_link = Contact::magicLinkById($item['author-id']);
925 $sparkle = (strpos($profile_link, 'redir/') === 0);
930 $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
931 $contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
932 if (DBM::is_result($contact)) {
933 $cid = $contact['id'];
934 $network = $contact['network'];
935 $rel = $contact['rel'];
939 $status_link = $profile_link . '?url=status';
940 $photos_link = $profile_link . '?url=photos';
941 $profile_link = $profile_link . '?url=profile';
943 $profile_link = Contact::magicLink($profile_link);
946 if ($cid && !$item['self']) {
947 $poke_link = 'poke/?f=&c=' . $cid;
948 $contact_url = 'contacts/' . $cid;
949 $posts_link = 'contacts/' . $cid . '/posts';
951 if (in_array($network, [NETWORK_DFRN, NETWORK_DIASPORA])) {
952 $pm_url = 'message/new/' . $cid;
958 L10n::t('Follow Thread') => $sub_link,
959 L10n::t('View Status') => $status_link,
960 L10n::t('View Profile') => $profile_link,
961 L10n::t('View Photos') => $photos_link,
962 L10n::t('Network Posts') => $posts_link,
963 L10n::t('View Contact') => $contact_url,
964 L10n::t('Send PM') => $pm_url
967 if ($network == NETWORK_DFRN) {
968 $menu[L10n::t("Poke")] = $poke_link;
971 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
972 in_array($item['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])) {
973 $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
976 $menu = [L10n::t('View Profile') => $item['author-link']];
979 $args = ['item' => $item, 'menu' => $menu];
981 Addon::callHooks('item_photo_menu', $args);
983 $menu = $args['menu'];
986 foreach ($menu as $k => $v) {
987 if (strpos($v, 'javascript:') === 0) {
989 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
991 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
998 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
999 * Increments the count of each matching activity and adds a link to the author as needed.
1001 * @param array $item
1002 * @param array &$conv_responses (already created with builtin activity structure)
1005 function builtin_activity_puller($item, &$conv_responses) {
1006 foreach ($conv_responses as $mode => $v) {
1012 $verb = ACTIVITY_LIKE;
1015 $verb = ACTIVITY_DISLIKE;
1018 $verb = ACTIVITY_ATTEND;
1021 $verb = ACTIVITY_ATTENDNO;
1024 $verb = ACTIVITY_ATTENDMAYBE;
1030 if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
1031 $url = Contact::MagicLinkbyId($item['author-id']);
1032 if (strpos($url, 'redir/') === 0) {
1033 $sparkle = ' class="sparkle" ';
1036 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1038 if (!x($item, 'thr-parent')) {
1039 $item['thr-parent'] = $item['parent-uri'];
1042 if (!(isset($conv_responses[$mode][$item['thr-parent'] . '-l'])
1043 && is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))) {
1044 $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
1047 // only list each unique author once
1048 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1052 if (!isset($conv_responses[$mode][$item['thr-parent']])) {
1053 $conv_responses[$mode][$item['thr-parent']] = 1;
1055 $conv_responses[$mode][$item['thr-parent']] ++;
1058 if (public_contact() == $item['author-id']) {
1059 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1062 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1064 // there can only be one activity verb per item so if we found anything, we can stop looking
1071 * Format the vote text for a profile item
1072 * @param int $cnt = number of people who vote the item
1073 * @param array $arr = array of pre-linked names of likers/dislikers
1074 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1075 * @param int $id = item id
1076 * @return string formatted text
1078 function format_like($cnt, array $arr, $type, $id) {
1085 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1086 // list which show all likers
1089 $phrase = L10n::t('%s likes this.', $likers);
1092 $phrase = L10n::t('%s doesn\'t like this.', $likers);
1095 $phrase = L10n::t('%s attends.', $likers);
1098 $phrase = L10n::t('%s doesn\'t attend.', $likers);
1100 case 'attendmaybe' :
1101 $phrase = L10n::t('%s attends maybe.', $likers);
1107 $total = count($arr);
1108 if ($total >= MAX_LIKERS) {
1109 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1111 if ($total < MAX_LIKERS) {
1112 $last = L10n::t('and') . ' ' . $arr[count($arr)-1];
1113 $arr2 = array_slice($arr, 0, -1);
1114 $str = implode(', ', $arr2) . ' ' . $last;
1116 if ($total >= MAX_LIKERS) {
1117 $str = implode(', ', $arr);
1118 $str .= L10n::t('and %d other people', $total - MAX_LIKERS );
1123 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1127 $phrase = L10n::t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
1128 $explikers = L10n::t('%s like this.', $likers);
1131 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
1132 $explikers = L10n::t('%s don\'t like this.', $likers);
1135 $phrase = L10n::t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
1136 $explikers = L10n::t('%s attend.', $likers);
1139 $phrase = L10n::t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
1140 $explikers = L10n::t('%s don\'t attend.', $likers);
1143 $phrase = L10n::t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
1144 $explikers = L10n::t('%s attend maybe.', $likers);
1148 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1152 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), [
1153 '$phrase' => $phrase,
1162 function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
1166 $geotag = x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), []) : '';
1168 $tpl = get_markup_template('jot-header.tpl');
1169 $a->page['htmlhead'] .= replace_macros($tpl, [
1170 '$newpost' => 'true',
1171 '$baseurl' => System::baseUrl(true),
1172 '$geotag' => $geotag,
1173 '$nickname' => $x['nickname'],
1174 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1175 '$linkurl' => L10n::t('Please enter a link URL:'),
1176 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1177 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1178 '$term' => L10n::t('Tag term:'),
1179 '$fileas' => L10n::t('Save to Folder:'),
1180 '$whereareu' => L10n::t('Where are you right now?'),
1181 '$delitems' => L10n::t("Delete item\x28s\x29?")
1184 $tpl = get_markup_template('jot-end.tpl');
1185 $a->page['end'] .= replace_macros($tpl, [
1186 '$newpost' => 'true',
1187 '$baseurl' => System::baseUrl(true),
1188 '$geotag' => $geotag,
1189 '$nickname' => $x['nickname'],
1190 '$ispublic' => L10n::t('Visible to <strong>everybody</strong>'),
1191 '$linkurl' => L10n::t('Please enter a link URL:'),
1192 '$vidurl' => L10n::t("Please enter a video link/URL:"),
1193 '$audurl' => L10n::t("Please enter an audio link/URL:"),
1194 '$term' => L10n::t('Tag term:'),
1195 '$fileas' => L10n::t('Save to Folder:'),
1196 '$whereareu' => L10n::t('Where are you right now?')
1200 Addon::callHooks('jot_tool', $jotplugins);
1202 // Private/public post links for the non-JS ACL form
1204 if (x($_REQUEST, 'public')) {
1208 $query_str = $a->query_string;
1209 if (strpos($query_str, 'public=1') !== false) {
1210 $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
1214 * I think $a->query_string may never have ? in it, but I could be wrong
1215 * It looks like it's from the index.php?q=[etc] rewrite that the web
1216 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1218 if (strpos($query_str, '?') === false) {
1219 $public_post_link = '?public=1';
1221 $public_post_link = '&public=1';
1224 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1225 $tpl = get_markup_template("jot.tpl");
1227 $o .= replace_macros($tpl,[
1228 '$new_post' => L10n::t('New Post'),
1229 '$return_path' => $query_str,
1230 '$action' => 'item',
1231 '$share' => defaults($x, 'button', L10n::t('Share')),
1232 '$upload' => L10n::t('Upload photo'),
1233 '$shortupload' => L10n::t('upload photo'),
1234 '$attach' => L10n::t('Attach file'),
1235 '$shortattach' => L10n::t('attach file'),
1236 '$weblink' => L10n::t('Insert web link'),
1237 '$shortweblink' => L10n::t('web link'),
1238 '$video' => L10n::t('Insert video link'),
1239 '$shortvideo' => L10n::t('video link'),
1240 '$audio' => L10n::t('Insert audio link'),
1241 '$shortaudio' => L10n::t('audio link'),
1242 '$setloc' => L10n::t('Set your location'),
1243 '$shortsetloc' => L10n::t('set location'),
1244 '$noloc' => L10n::t('Clear browser location'),
1245 '$shortnoloc' => L10n::t('clear location'),
1246 '$title' => defaults($x, 'title', ''),
1247 '$placeholdertitle' => L10n::t('Set title'),
1248 '$category' => defaults($x, 'category', ''),
1249 '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '',
1250 '$wait' => L10n::t('Please wait'),
1251 '$permset' => L10n::t('Permission settings'),
1252 '$shortpermset' => L10n::t('permissions'),
1253 '$ptyp' => $notes_cid ? 'note' : 'wall',
1254 '$content' => defaults($x, 'content', ''),
1255 '$post_id' => defaults($x, 'post_id', ''),
1256 '$baseurl' => System::baseUrl(true),
1257 '$defloc' => $x['default_location'],
1258 '$visitor' => $x['visitor'],
1259 '$pvisit' => $notes_cid ? 'none' : $x['visitor'],
1260 '$public' => L10n::t('Public post'),
1261 '$lockstate' => $x['lockstate'],
1262 '$bang' => $x['bang'],
1263 '$profile_uid' => $x['profile_uid'],
1264 '$preview' => Feature::isEnabled($x['profile_uid'], 'preview') ? L10n::t('Preview') : '',
1265 '$jotplugins' => $jotplugins,
1266 '$notes_cid' => $notes_cid,
1267 '$sourceapp' => L10n::t($a->sourcename),
1268 '$cancel' => L10n::t('Cancel'),
1269 '$rand_num' => random_digits(12),
1271 // ACL permissions box
1272 '$acl' => $x['acl'],
1273 '$group_perms' => L10n::t('Post to Groups'),
1274 '$contact_perms' => L10n::t('Post to Contacts'),
1275 '$private' => L10n::t('Private post'),
1276 '$is_private' => $private_post,
1277 '$public_link' => $public_post_link,
1279 //jot nav tab (used in some themes)
1280 '$message' => L10n::t('Message'),
1281 '$browser' => L10n::t('Browser'),
1285 if ($popup == true) {
1286 $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
1293 * Plucks the children of the given parent from a given item list.
1295 * @brief Plucks all the children in the given item list of the given parent
1297 * @param array $item_list
1298 * @param array $parent
1299 * @param bool $recursive
1302 function get_item_children(array &$item_list, array $parent, $recursive = true)
1305 foreach ($item_list as $i => $item) {
1306 if ($item['id'] != $item['parent']) {
1308 // Fallback to parent-uri if thr-parent is not set
1309 $thr_parent = $item['thr-parent'];
1310 if ($thr_parent == '') {
1311 $thr_parent = $item['parent-uri'];
1314 if ($thr_parent == $parent['uri']) {
1315 $item['children'] = get_item_children($item_list, $item);
1316 $children[] = $item;
1317 unset($item_list[$i]);
1319 } elseif ($item['parent'] == $parent['id']) {
1320 $children[] = $item;
1321 unset($item_list[$i]);
1329 * @brief Recursively sorts a tree-like item array
1331 * @param array $items
1334 function sort_item_children(array $items)
1337 usort($result, 'sort_thr_created_rev');
1338 foreach ($result as $k => $i) {
1339 if (isset($result[$k]['children'])) {
1340 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1347 * @brief Recursively add all children items at the top level of a list
1349 * @param array $children List of items to append
1350 * @param array $item_list
1352 function add_children_to_list(array $children, array &$item_list)
1354 foreach ($children as $child) {
1355 $item_list[] = $child;
1356 if (isset($child['children'])) {
1357 add_children_to_list($child['children'], $item_list);
1363 * This recursive function takes the item tree structure created by conv_sort() and
1364 * flatten the extraneous depth levels when people reply sequentially, removing the
1365 * stairs effect in threaded conversations limiting the available content width.
1367 * The basic principle is the following: if a post item has only one reply and is
1368 * the last reply of its parent, then the reply is moved to the parent.
1370 * This process is rendered somewhat more complicated because items can be either
1371 * replies or likes, and these don't factor at all in the reply count/last reply.
1373 * @brief Selectively flattens a tree-like item structure to prevent threading stairs
1375 * @param array $parent A tree-like array of items
1378 function smart_flatten_conversation(array $parent)
1380 if (!isset($parent['children']) || count($parent['children']) == 0) {
1384 // We use a for loop to ensure we process the newly-moved items
1385 for ($i = 0; $i < count($parent['children']); $i++) {
1386 $child = $parent['children'][$i];
1388 if (isset($child['children']) && count($child['children'])) {
1389 // This helps counting only the regular posts
1390 $count_post_closure = function($var) {
1391 return $var['verb'] === ACTIVITY_POST;
1394 $child_post_count = count(array_filter($child['children'], $count_post_closure));
1396 $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure));
1398 // If there's only one child's children post and this is the last child post
1399 if ($child_post_count == 1 && $remaining_post_count == 1) {
1401 // Searches the post item in the children
1403 while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
1407 $moved_item = $child['children'][$j];
1408 unset($parent['children'][$i]['children'][$j]);
1409 $parent['children'][] = $moved_item;
1411 $parent['children'][$i] = smart_flatten_conversation($child);
1421 * Expands a flat list of items into corresponding tree-like conversation structures,
1422 * sort the top-level posts either on "created" or "commented", and finally
1423 * append all the items at the top level (???)
1425 * @brief Expands a flat item list into a conversation array for display
1427 * @param array $item_list A list of items belonging to one or more conversations
1428 * @param string $order Either on "created" or "commented"
1431 function conv_sort(array $item_list, $order)
1435 if (!(is_array($item_list) && count($item_list))) {
1441 // Dedupes the item list on the uri to prevent infinite loops
1442 foreach ($item_list as $item) {
1443 $item_array[$item['uri']] = $item;
1446 // Extract the top level items
1447 foreach ($item_array as $item) {
1448 if ($item['id'] == $item['parent']) {
1453 if (stristr($order, 'created')) {
1454 usort($parents, 'sort_thr_created');
1455 } elseif (stristr($order, 'commented')) {
1456 usort($parents, 'sort_thr_commented');
1460 * Plucks children from the item_array, second pass collects eventual orphan
1461 * items and add them as children of their top-level post.
1463 foreach ($parents as $i => $parent) {
1464 $parents[$i]['children'] =
1465 array_merge(get_item_children($item_array, $parent, true),
1466 get_item_children($item_array, $parent, false));
1469 foreach ($parents as $i => $parent) {
1470 $parents[$i]['children'] = sort_item_children($parents[$i]['children']);
1473 if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
1474 foreach ($parents as $i => $parent) {
1475 $parents[$i] = smart_flatten_conversation($parent);
1479 /// @TODO: Stop recusrsively adding all children back to the top level (!!!)
1480 /// However, this apparently ensures responses (likes, attendance) display (?!)
1481 foreach ($parents as $parent) {
1482 if (count($parent['children'])) {
1483 add_children_to_list($parent['children'], $parents);
1491 * @brief usort() callback to sort item arrays by the created key
1497 function sort_thr_created(array $a, array $b)
1499 return strcmp($b['created'], $a['created']);
1503 * @brief usort() callback to reverse sort item arrays by the created key
1509 function sort_thr_created_rev(array $a, array $b)
1511 return strcmp($a['created'], $b['created']);
1515 * @brief usort() callback to sort item arrays by the commented key
1521 function sort_thr_commented(array $a, array $b)
1523 return strcmp($b['commented'], $a['commented']);
1526 function render_location_dummy(array $item) {
1527 if (x($item, 'location') && !empty($item['location'])) {
1528 return $item['location'];
1531 if (x($item, 'coord') && !empty($item['coord'])) {
1532 return $item['coord'];
1536 function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) {
1538 foreach ($response_verbs as $v) {
1540 $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], '');
1541 $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', []);
1542 $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0');
1543 if (count($ret[$v]['list']) > MAX_LIKERS) {
1544 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1545 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1546 . (($ob) ? $ob->getId() : $item['id']) . '"><b>' . L10n::t('View all') . '</b></a>');
1548 $ret[$v]['list_part'] = '';
1550 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1551 $ret[$v]['title'] = $conv_responses[$v]['title'];
1555 foreach ($ret as $key) {
1556 if ($key['count'] == true) {
1560 $ret['count'] = $count;
1565 function get_response_button_text($v, $count)
1569 $return = L10n::tt('Like', 'Likes', $count);
1572 $return = L10n::tt('Dislike', 'Dislikes', $count);
1575 $return = L10n::tt('Attending', 'Attending', $count);
1578 $return = L10n::tt('Not Attending', 'Not Attending', $count);
1581 $return = L10n::tt('Undecided', 'Undecided', $count);