4 use Friendica\Core\System;
6 require_once "include/bbcode.php";
7 require_once "include/acl_selectors.php";
10 * Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
11 * is identical to the code in mod/message.php for 'item_extract_images' and
12 * 'item_redir_and_replace_images'
14 if (! function_exists('item_extract_images')) {
15 function item_extract_images($body) {
17 $saved_image = array();
22 $img_start = strpos($orig_body, '[img');
23 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
24 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
25 while (($img_st_close !== false) && ($img_end !== false)) {
27 $img_st_close++; // make it point to AFTER the closing bracket
28 $img_end += $img_start;
30 if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
31 // This is an embedded image
33 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
34 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
38 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
41 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
43 if ($orig_body === false) {
44 // in case the body ends on a closing image tag
48 $img_start = strpos($orig_body, '[img');
49 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
50 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
53 $new_body = $new_body . $orig_body;
55 return array('body' => $new_body, 'images' => $saved_image);
58 if (! function_exists('item_redir_and_replace_images')) {
59 function item_redir_and_replace_images($body, $images, $cid) {
65 $pos = get_bb_tag_pos($origbody, 'url', 1);
66 while ($pos !== false && $cnt < 1000) {
68 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
69 $replace = '[url=' . System::baseUrl() . '/redir/' . $cid
70 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
72 $newbody .= substr($origbody, 0, $pos['start']['open']);
73 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
74 $origbody = substr($origbody, $pos['end']['close']);
75 if ($origbody === false) {
79 $subject = preg_replace($search, $replace, $subject);
83 $pos = get_bb_tag_pos($origbody, 'url', 1);
85 $newbody .= $origbody;
88 foreach ($images as $image) {
90 * We're depending on the property of 'foreach' (specified on the PHP website) that
91 * it loops over the array starting from the first element and going sequentially
92 * to the last element.
94 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
101 * Render actions localized
103 function localize_item(&$item) {
105 $extracted = item_extract_images($item['body']);
106 if ($extracted['images']) {
107 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
111 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
112 if (activity_match($item['verb'], ACTIVITY_LIKE)
113 || activity_match($item['verb'], ACTIVITY_DISLIKE)
114 || activity_match($item['verb'], ACTIVITY_ATTEND)
115 || activity_match($item['verb'], ACTIVITY_ATTENDNO)
116 || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
118 /// @TODO may hurt performance
119 $r = q("SELECT * FROM `item`, `contact`
120 WHERE `item`.`contact-id`=`contact`.`id`
121 AND `item`.`uri`='%s'",
122 dbesc($item['parent-uri']));
123 if (!dbm::is_result($r)) {
128 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
129 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
131 switch ($obj['verb']) {
133 switch ($obj['object-type']) {
134 case ACTIVITY_OBJ_EVENT:
135 $post_type = t('event');
138 $post_type = t('status');
142 if ($obj['resource-id']) {
143 $post_type = t('photo');
145 preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
146 $rr['plink'] = $m[1];
148 $post_type = t('status');
152 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
154 if (activity_match($item['verb'], ACTIVITY_LIKE)) {
155 $bodyverb = t('%1$s likes %2$s\'s %3$s');
157 elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
158 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
160 elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
161 $bodyverb = t('%1$s attends %2$s\'s %3$s');
163 elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
164 $bodyverb = t('%1$s doesn\'t attend %2$s\'s %3$s');
166 elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
167 $bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
169 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
172 if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
174 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
176 $Aname = $item['author-name'];
177 $Alink = $item['author-link'];
179 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
181 $obj = parse_xml_string($xmlhead.$item['object']);
182 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
184 $Bname = $obj->title;
185 $Blink = ""; $Bphoto = "";
186 foreach ($links->link as $l) {
187 $atts = $l->attributes();
188 switch ($atts['rel']) {
189 case "alternate": $Blink = $atts['href'];
190 case "photo": $Bphoto = $atts['href'];
194 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
195 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
197 $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
200 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
203 if (stristr($item['verb'], ACTIVITY_POKE)) {
204 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
208 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
212 $Aname = $item['author-name'];
213 $Alink = $item['author-link'];
215 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
217 $obj = parse_xml_string($xmlhead.$item['object']);
218 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
220 $Bname = $obj->title;
223 foreach ($links->link as $l) {
224 $atts = $l->attributes();
225 switch ($atts['rel']) {
226 case "alternate": $Blink = $atts['href'];
227 case "photo": $Bphoto = $atts['href'];
231 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
232 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
234 $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
238 * we can't have a translation string with three positions but no distinguishable text
239 * So here is the translate string.
241 $txt = t('%1$s poked %2$s');
243 // now translate the verb
244 $poked_t = trim(sprintf($txt, "", ""));
245 $txt = str_replace( $poked_t, t($verb), $txt);
247 // then do the sprintf on the translation string
249 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
252 if (stristr($item['verb'], ACTIVITY_MOOD)) {
253 $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
258 $Aname = $item['author-name'];
259 $Alink = $item['author-link'];
260 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
262 $txt = t('%1$s is currently %2$s');
264 $item['body'] = sprintf($txt, $A, t($verb));
267 if (activity_match($item['verb'], ACTIVITY_TAG)) {
268 /// @TODO may hurt performance "joining" two tables + asterisk
269 $r = q("SELECT * FROM `item`, `contact`
270 WHERE `item`.`contact-id`=`contact`.`id`
271 AND `item`.`uri`='%s'",
272 dbesc($item['parent-uri']));
274 if (!dbm::is_result($r)) {
280 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
281 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
283 switch ($obj['verb']) {
285 switch ($obj['object-type']) {
286 case ACTIVITY_OBJ_EVENT:
287 $post_type = t('event');
290 $post_type = t('status');
294 if ($obj['resource-id']) {
295 $post_type = t('photo');
296 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
297 $rr['plink'] = $m[1];
299 $post_type = t('status');
301 // Let's break everthing ... ;-)
304 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
306 $parsedobj = parse_xml_string($xmlhead.$item['object']);
308 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
309 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
312 if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
314 if ($item['object-type'] == "") {
318 $Aname = $item['author-name'];
319 $Alink = $item['author-link'];
321 $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
323 $obj = parse_xml_string($xmlhead.$item['object']);
324 if (strlen($obj->id)) {
325 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
330 if (dbm::is_result($r) && $r[0]['plink']) {
332 $Bname = $target['author-name'];
333 $Blink = $target['author-link'];
334 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
335 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
336 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
337 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
342 if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
343 foreach ($matches as $mtch) {
344 if (! strpos($mtch[1], 'zrl=')) {
345 $item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']);
350 // add zrl's to public images
351 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
352 if (preg_match($photo_pattern, $item['body'])) {
353 $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
354 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
357 // add sparkle links to appropriate permalinks
359 $x = stristr($item['plink'],'/display/');
362 $y = best_link_url($item, $sparkle);
364 if (strstr($y, '/redir/')) {
365 $item['plink'] = $y . '?f=&url=' . $item['plink'];
371 * Count the total of comments on this item and its desendants
372 * @TODO proper type-hint + doc-tag
374 function count_descendants($item) {
375 $total = count($item['children']);
378 foreach ($item['children'] as $child) {
379 if (! visible_activity($child)) {
382 $total += count_descendants($child);
389 function visible_activity($item) {
392 * likes (etc.) can apply to other things besides posts. Check if they are post children,
393 * in which case we handle them specially
395 $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
396 foreach ($hidden_activities as $act) {
397 if (activity_match($item['verb'], $act)) {
402 if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
403 if (! (($item['self']) && ($item['uid'] == local_user()))) {
412 * @brief SQL query for items
414 function item_query() {
415 return "SELECT " . item_fieldlists() . " FROM `item` " .
416 item_joins() . " WHERE " . item_condition();
420 * @brief List of all data fields that are needed for displaying items
422 function item_fieldlists() {
425 These Fields are not added below (yet). They are here to for bug search.
430 `item`.`target-type`,
432 `item`.`resource-id`,
446 `item`.`gcontact-id`,
450 return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
451 `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
452 `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
453 `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
454 `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
455 `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
456 `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
457 `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
458 `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
459 `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
460 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
461 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
463 `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
465 `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
466 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
468 `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
469 `event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
470 `event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
471 `event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
472 `event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
473 `event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
477 * @brief SQL join for contacts that are needed for displaying items
479 function item_joins() {
480 return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
481 (NOT `contact`.`blocked` OR `contact`.`pending`)
482 LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
483 LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`
484 LEFT JOIN `event` ON `event-id` = `event`.`id`";
488 * @brief SQL condition for items that are needed for displaying items
490 function item_condition() {
491 return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
494 if (!function_exists('conversation')) {
496 * "Render" a conversation or list of items for HTML display.
497 * There are two major forms of display:
498 * - Sequential or unthreaded ("New Item View" or search results)
499 * - conversation view
500 * The $mode parameter decides between the various renderings and also
501 * figures out how to determine page owner and other contextual items
502 * that are based on unique features of the calling module.
505 function conversation(App $a, $items, $mode, $update, $preview = false) {
507 require_once 'include/bbcode.php';
508 require_once 'include/Contact.php';
509 require_once 'mod/proxy.php';
511 $ssl_state = ((local_user()) ? true : false);
514 $page_writeable = false;
515 $live_update_div = '';
520 $str_blocked = get_pconfig(local_user(), 'system', 'blocked');
522 $arr_blocked = explode(',', $str_blocked);
523 for ($x = 0; $x < count($arr_blocked); $x ++) {
524 $arr_blocked[$x] = trim($arr_blocked[$x]);
530 $previewing = (($preview) ? ' preview ' : '');
532 if ($mode === 'network') {
533 $profile_owner = local_user();
534 $page_writeable = true;
537 * The special div is needed for liveUpdate to kick in for this page.
538 * We only launch liveUpdate if you aren't filtering in some incompatible
539 * way and also you aren't writing a comment (discovered in javascript).
541 $live_update_div = '<div id="live-network"></div>' . "\r\n"
542 . "<script> var profile_uid = " . $_SESSION['uid']
543 . "; var netargs = '" . substr($a->cmd, 8)
545 . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
546 . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
547 . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
548 . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
549 . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
550 . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
551 . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
552 . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
553 . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
554 . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
555 . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
556 . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
558 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
560 } elseif ($mode === 'profile') {
561 $profile_owner = $a->profile['profile_uid'];
562 $page_writeable = can_write_wall($a,$profile_owner);
565 $tab = notags(trim($_GET['tab']));
566 $tab = ( $tab ? $tab : 'posts' );
567 if ($tab === 'posts') {
569 * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
570 * because browser prefetching might change it on us. We have to deliver it with the page.
573 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
574 . "<script> var profile_uid = " . $a->profile['profile_uid']
575 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
578 } elseif ($mode === 'notes') {
579 $profile_owner = local_user();
580 $page_writeable = true;
582 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
583 . "<script> var profile_uid = " . local_user()
584 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
586 } elseif ($mode === 'display') {
587 $profile_owner = $a->profile['uid'];
588 $page_writeable = can_write_wall($a,$profile_owner);
590 $live_update_div = '<div id="live-display"></div>' . "\r\n"
591 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
592 . " var profile_page = 1; </script>";
594 } elseif ($mode === 'community') {
596 $page_writeable = false;
598 $live_update_div = '<div id="live-community"></div>' . "\r\n"
599 . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
601 } elseif ($mode === 'search') {
602 $live_update_div = '<div id="live-search"></div>' . "\r\n";
605 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
609 $return_url = $_SESSION['return_url'];
611 $return_url = $_SESSION['return_url'] = $a->query_string;
614 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
615 call_hooks('conversation_start',$cb);
617 $items = $cb['items'];
619 $cmnt_tpl = get_markup_template('comment_item.tpl');
620 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
622 $conv_responses = array(
623 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
624 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
627 // array with html for each thread (parent+comments)
631 $page_template = get_markup_template("conversation.tpl");
633 if ($items && count($items)) {
635 if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
638 * "New Item View" on network page or search page results
639 * - just loop through the items and format them minimally for display
642 /// @TODO old lost code?
643 // $tpl = get_markup_template('search_item.tpl');
644 $tpl = 'search_item.tpl';
646 foreach ($items as $item) {
650 foreach ($arr_blocked as $b) {
651 if ($b && link_compare($item['author-link'], $b)) {
669 if ($mode === 'search' || $mode === 'community') {
670 if (((activity_match($item['verb'], ACTIVITY_LIKE)) || (activity_match($item['verb'], ACTIVITY_DISLIKE)))
671 && ($item['id'] != $item['parent']))
673 $nickname = $item['nickname'];
675 $nickname = $a->user['nickname'];
678 // prevent private email from leaking.
679 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
683 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
684 if ($item['author-link'] && (! $item['author-name'])) {
685 $profile_name = $item['author-link'];
692 $searchpath = System::baseUrl()."/search?tag=";
694 $taglist = dba::select('term', array('type', 'term', 'url'),
695 array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
696 array('order' => array('tid')));
698 while ($tag = dba::fetch($taglist)) {
699 if ($tag["url"] == "") {
700 $tag["url"] = $searchpath . strtolower($tag["term"]);
703 $tag["url"] = best_link_url($item, $sp, $tag["url"]);
705 if ($tag["type"] == TERM_HASHTAG) {
706 $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
708 } elseif ($tag["type"] == TERM_MENTION) {
709 $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
712 $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
714 dba::close($taglist);
717 $profile_link = best_link_url($item, $sp);
718 if ($profile_link === 'mailbox') {
723 $sparkle = ' sparkle';
725 $profile_link = zrl($profile_link);
728 if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
729 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
730 if ($author_contact["thumb"]) {
731 $item['author-thumb'] = $author_contact["thumb"];
733 $item['author-thumb'] = $item['author-avatar'];
737 if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
738 $owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner);
739 if ($owner_contact["thumb"]) {
740 $item['owner-thumb'] = $owner_contact["thumb"];
742 $item['owner-thumb'] = $item['owner-avatar'];
746 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
747 call_hooks('render_location',$locate);
749 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
751 localize_item($item);
752 if ($mode === 'network-new') {
759 'dropping' => $dropping,
760 'pagedrop' => $page_dropping,
761 'select' => t('Select'),
762 'delete' => t('Delete'),
766 $isstarred = "unstarred";
769 $likebuttons = false;
772 $body = prepare_body($item, true, $preview);
774 list($categories, $folders) = get_cats_and_terms($item);
776 if ($a->theme['template_engine'] === 'internal') {
777 $profile_name_e = template_escape($profile_name);
778 $item['title_e'] = template_escape($item['title']);
779 $body_e = template_escape($body);
780 $tags_e = template_escape($tags);
781 $hashtags_e = template_escape($hashtags);
782 $mentions_e = template_escape($mentions);
783 $location_e = template_escape($location);
784 $owner_name_e = template_escape($owner_name);
786 $profile_name_e = $profile_name;
787 $item['title_e'] = $item['title'];
790 $hashtags_e = $hashtags;
791 $mentions_e = $mentions;
792 $location_e = $location;
793 $owner_name_e = $owner_name;
796 if ($item['item_network'] == "") {
797 $item['item_network'] = $item['network'];
802 'id' => (($preview) ? 'P0' : $item['item_id']),
803 'network' => $item['item_network'],
804 'network_name' => network_to_name($item['item_network'], $profile_link),
805 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
806 'profile_url' => $profile_link,
807 'item_photo_menu' => item_photo_menu($item),
808 'name' => $profile_name_e,
809 'sparkle' => $sparkle,
811 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
812 'title' => $item['title_e'],
815 'hashtags' => $hashtags_e,
816 'mentions' => $mentions_e,
817 'txt_cats' => t('Categories:'),
818 'txt_folders' => t('Filed under:'),
819 'has_cats' => ((count($categories)) ? 'true' : ''),
820 'has_folders' => ((count($folders)) ? 'true' : ''),
821 'categories' => $categories,
822 'folders' => $folders,
823 'text' => strip_tags($body_e),
824 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
825 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
826 'location' => $location_e,
828 'owner_name' => $owner_name_e,
829 'owner_url' => $owner_url,
830 'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
831 'plink' => get_plink($item),
833 'isstarred' => $isstarred,
836 'vote' => $likebuttons,
840 //'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
841 'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
842 'previewing' => $previewing,
843 'wait' => t('Please wait'),
847 $arr = array('item' => $item, 'output' => $tmp_item);
848 call_hooks('display_item', $arr);
850 $threads[$threadsid]['id'] = $item['item_id'];
851 $threads[$threadsid]['network'] = $item['item_network'];
852 $threads[$threadsid]['items'] = array($arr['output']);
857 $page_template = get_markup_template("threaded_conversation.tpl");
859 require_once 'object/Conversation.php';
860 require_once 'object/Item.php';
862 $conv = new Conversation($mode, $preview);
865 * get all the topmost parents
866 * this shouldn't be needed, as we should have only them in our array
867 * But for now, this array respects the old style, just in case
870 foreach ($items as $item) {
874 foreach ($arr_blocked as $b) {
875 if ($b && link_compare($item['author-link'], $b)) {
885 // Can we put this after the visibility check?
886 builtin_activity_puller($item, $conv_responses);
888 // Only add what is visible
889 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
893 if (! visible_activity($item)) {
897 call_hooks('display_item', $arr);
899 $item['pagedrop'] = $page_dropping;
901 if ($item['id'] == $item['parent']) {
902 $item_object = new Item($item);
903 $conv->add_thread($item_object);
907 $threads = $conv->get_template_data($conv_responses);
910 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
916 $o = replace_macros($page_template, array(
917 '$baseurl' => System::baseUrl($ssl_state),
918 '$return_path' => $a->query_string,
919 '$live_update' => $live_update_div,
920 '$remove' => t('remove'),
923 '$threads' => $threads,
924 '$dropping' => ($page_dropping && feature_enabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False),
930 function best_link_url($item, &$sparkle, $url = '') {
935 $clean_url = normalise_link($item['author-link']);
938 $r = dba::select('contact', array('id'),
939 array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
940 array('limit' => 1));
941 if (dbm::is_result($r)) {
942 $best_url = 'redir/' . $r['id'];
945 $hostname = get_app()->get_hostname();
946 if (!strstr($url, $hostname)) {
947 $best_url .= "?url=".$url;
957 } elseif (strlen($item['author-link'])) {
958 $best_url = $item['author-link'];
960 $best_url = $item['url'];
968 function item_photo_menu($item) {
978 if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
979 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
983 $profile_link = best_link_url($item, $sparkle);
984 if ($profile_link === 'mailbox') {
991 $r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
992 if (dbm::is_result($r)) {
994 $network = $r['network'];
999 $status_link = $profile_link . '?url=status';
1000 $photos_link = $profile_link . '?url=photos';
1001 $profile_link = $profile_link . '?url=profile';
1004 $profile_link = zrl($profile_link);
1007 if ($cid && !$item['self']) {
1008 $poke_link = 'poke/?f=&c=' . $cid;
1009 $contact_url = 'contacts/' . $cid;
1010 $posts_link = 'contacts/' . $cid . '/posts';
1012 if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA))) {
1013 $pm_url = 'message/new/' . $cid;
1019 t('Follow Thread') => $sub_link,
1020 t('View Status') => $status_link,
1021 t('View Profile') => $profile_link,
1022 t('View Photos') => $photos_link,
1023 t('Network Posts') => $posts_link,
1024 t('View Contact') => $contact_url,
1025 t('Send PM') => $pm_url
1028 if ($network == NETWORK_DFRN) {
1029 $menu[t("Poke")] = $poke_link;
1032 if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
1033 in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
1034 $menu[t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
1037 $menu = array(t('View Profile') => $item['author-link']);
1040 $args = array('item' => $item, 'menu' => $menu);
1042 call_hooks('item_photo_menu', $args);
1044 $menu = $args['menu'];
1047 foreach ($menu as $k => $v) {
1048 if (strpos($v, 'javascript:') === 0) {
1049 $v = substr($v, 11);
1050 $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1052 $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
1058 if (! function_exists('builtin_activity_puller')) {
1060 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
1061 * Increments the count of each matching activity and adds a link to the author as needed.
1063 * @param array $item
1064 * @param array &$conv_responses (already created with builtin activity structure)
1067 function builtin_activity_puller($item, &$conv_responses) {
1068 foreach ($conv_responses as $mode => $v) {
1074 $verb = ACTIVITY_LIKE;
1077 $verb = ACTIVITY_DISLIKE;
1080 $verb = ACTIVITY_ATTEND;
1083 $verb = ACTIVITY_ATTENDNO;
1086 $verb = ACTIVITY_ATTENDMAYBE;
1093 if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1094 $url = $item['author-link'];
1095 if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
1096 $url = 'redir/' . $item['contact-id'];
1097 $sparkle = ' class="sparkle" ';
1102 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1104 if (! $item['thr-parent']) {
1105 $item['thr-parent'] = $item['parent-uri'];
1108 if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1109 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
1110 $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
1113 // only list each unique author once
1114 if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
1118 if (! isset($conv_responses[$mode][$item['thr-parent']])) {
1119 $conv_responses[$mode][$item['thr-parent']] = 1;
1121 $conv_responses[$mode][$item['thr-parent']] ++;
1124 if (public_contact() == $item['author-id']) {
1125 $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
1128 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1130 // there can only be one activity verb per item so if we found anything, we can stop looking
1136 if (! function_exists('format_like')) {
1138 * Format the vote text for a profile item
1139 * @param int $cnt = number of people who vote the item
1140 * @param array $arr = array of pre-linked names of likers/dislikers
1141 * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1142 * @param int $id = item id
1143 * @return formatted text
1145 function format_like($cnt, array $arr, $type, $id) {
1152 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1153 // list which show all likers
1156 $phrase = sprintf( t('%s likes this.'), $likers);
1159 $phrase = sprintf( t('%s doesn\'t like this.'), $likers);
1162 $phrase = sprintf( t('%s attends.'), $likers);
1165 $phrase = sprintf( t('%s doesn\'t attend.'), $likers);
1167 case 'attendmaybe' :
1168 $phrase = sprintf( t('%s attends maybe.'), $likers);
1174 $total = count($arr);
1175 if ($total >= MAX_LIKERS) {
1176 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1178 if ($total < MAX_LIKERS) {
1179 $last = t('and') . ' ' . $arr[count($arr)-1];
1180 $arr2 = array_slice($arr, 0, -1);
1181 $str = implode(', ', $arr2) . ' ' . $last;
1183 if ($total >= MAX_LIKERS) {
1184 $str = implode(', ', $arr);
1185 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1190 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1194 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
1195 $explikers = sprintf( t('%s like this.'), $likers);
1198 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
1199 $explikers = sprintf( t('%s don\'t like this.'), $likers);
1202 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend'), $spanatts, $cnt);
1203 $explikers = sprintf( t('%s attend.'), $likers);
1206 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
1207 $explikers = sprintf( t('%s don\'t attend.'), $likers);
1210 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend maybe'), $spanatts, $cnt);
1211 $explikers = sprintf( t('%s anttend maybe.'), $likers);
1215 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1219 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
1220 '$phrase' => $phrase,
1229 function status_editor(App $a, $x, $notes_cid = 0, $popup = false) {
1232 $geotag = (x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
1234 $tpl = get_markup_template('jot-header.tpl');
1235 $a->page['htmlhead'] .= replace_macros($tpl, array(
1236 '$newpost' => 'true',
1237 '$baseurl' => System::baseUrl(true),
1238 '$geotag' => $geotag,
1239 '$nickname' => $x['nickname'],
1240 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1241 '$linkurl' => t('Please enter a link URL:'),
1242 '$vidurl' => t("Please enter a video link/URL:"),
1243 '$audurl' => t("Please enter an audio link/URL:"),
1244 '$term' => t('Tag term:'),
1245 '$fileas' => t('Save to Folder:'),
1246 '$whereareu' => t('Where are you right now?'),
1247 '$delitems' => t('Delete item(s)?')
1250 $tpl = get_markup_template('jot-end.tpl');
1251 $a->page['end'] .= replace_macros($tpl, array(
1252 '$newpost' => 'true',
1253 '$baseurl' => System::baseUrl(true),
1254 '$geotag' => $geotag,
1255 '$nickname' => $x['nickname'],
1256 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1257 '$linkurl' => t('Please enter a link URL:'),
1258 '$vidurl' => t("Please enter a video link/URL:"),
1259 '$audurl' => t("Please enter an audio link/URL:"),
1260 '$term' => t('Tag term:'),
1261 '$fileas' => t('Save to Folder:'),
1262 '$whereareu' => t('Where are you right now?')
1266 call_hooks('jot_tool', $jotplugins);
1268 // Private/public post links for the non-JS ACL form
1270 if (x($_REQUEST, 'public')) {
1274 $query_str = $a->query_string;
1275 if (strpos($query_str, 'public=1') !== false) {
1276 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1280 * I think $a->query_string may never have ? in it, but I could be wrong
1281 * It looks like it's from the index.php?q=[etc] rewrite that the web
1282 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1284 if (strpos($query_str, '?') === false) {
1285 $public_post_link = '?public=1';
1287 $public_post_link = '&public=1';
1290 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1291 $tpl = get_markup_template("jot.tpl");
1293 $o .= replace_macros($tpl,array(
1294 '$return_path' => $query_str,
1295 '$action' => 'item',
1296 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1297 '$upload' => t('Upload photo'),
1298 '$shortupload' => t('upload photo'),
1299 '$attach' => t('Attach file'),
1300 '$shortattach' => t('attach file'),
1301 '$weblink' => t('Insert web link'),
1302 '$shortweblink' => t('web link'),
1303 '$video' => t('Insert video link'),
1304 '$shortvideo' => t('video link'),
1305 '$audio' => t('Insert audio link'),
1306 '$shortaudio' => t('audio link'),
1307 '$setloc' => t('Set your location'),
1308 '$shortsetloc' => t('set location'),
1309 '$noloc' => t('Clear browser location'),
1310 '$shortnoloc' => t('clear location'),
1311 '$title' => $x['title'],
1312 '$placeholdertitle' => t('Set title'),
1313 '$category' => $x['category'],
1314 '$placeholdercategory' => (feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''),
1315 '$wait' => t('Please wait'),
1316 '$permset' => t('Permission settings'),
1317 '$shortpermset' => t('permissions'),
1318 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1319 '$content' => $x['content'],
1320 '$post_id' => $x['post_id'],
1321 '$baseurl' => System::baseUrl(true),
1322 '$defloc' => $x['default_location'],
1323 '$visitor' => $x['visitor'],
1324 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1325 '$public' => t('Public post'),
1326 '$jotnets' => $jotnets,
1327 '$lockstate' => $x['lockstate'],
1328 '$bang' => $x['bang'],
1329 '$profile_uid' => $x['profile_uid'],
1330 '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1331 '$jotplugins' => $jotplugins,
1332 '$notes_cid' => $notes_cid,
1333 '$sourceapp' => t($a->sourcename),
1334 '$cancel' => t('Cancel'),
1335 '$rand_num' => random_digits(12),
1337 // ACL permissions box
1338 '$acl' => $x['acl'],
1339 '$acl_data' => $x['acl_data'],
1340 '$group_perms' => t('Post to Groups'),
1341 '$contact_perms' => t('Post to Contacts'),
1342 '$private' => t('Private post'),
1343 '$is_private' => $private_post,
1344 '$public_link' => $public_post_link,
1346 //jot nav tab (used in some themes)
1347 '$message' => t('Message'),
1348 '$browser' => t('Browser'),
1352 if ($popup == true) {
1353 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1360 function get_item_children($arr, $parent) {
1361 $children = array();
1363 foreach ($arr as $item) {
1364 if ($item['id'] != $item['parent']) {
1365 if (get_config('system', 'thread_allow') && $a->theme_thread_allow) {
1366 // Fallback to parent-uri if thr-parent is not set
1367 $thr_parent = $item['thr-parent'];
1368 if ($thr_parent == '') {
1369 $thr_parent = $item['parent-uri'];
1372 if ($thr_parent == $parent['uri']) {
1373 $item['children'] = get_item_children($arr, $item);
1374 $children[] = $item;
1376 } elseif ($item['parent'] == $parent['id']) {
1377 $children[] = $item;
1384 /// @TODO Add type-hint
1385 function sort_item_children($items) {
1387 usort($result, 'sort_thr_created_rev');
1388 foreach ($result as $k => $i) {
1389 if (count($result[$k]['children'])) {
1390 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1396 /// @TODO Add type-hint
1397 function add_children_to_list($children, &$arr) {
1398 foreach ($children as $y) {
1400 if (count($y['children'])) {
1401 add_children_to_list($y['children'], $arr);
1406 /// @TODO Add type-hint
1407 function conv_sort($arr, $order) {
1409 if ((!(is_array($arr) && count($arr)))) {
1414 $children = array();
1418 * This is a preparation for having two different items with the same uri in one thread
1419 * This will otherwise lead to an endless loop.
1421 foreach ($arr as $x) {
1422 if (!isset($newarr[$x['uri']])) {
1423 $newarr[$x['uri']] = $x;
1429 foreach ($arr as $x) {
1430 if ($x['id'] == $x['parent']) {
1435 if (stristr($order, 'created')) {
1436 usort($parents, 'sort_thr_created');
1437 } elseif (stristr($order, 'commented')) {
1438 usort($parents, 'sort_thr_commented');
1441 if (count($parents)) {
1442 foreach ($parents as $i => $_x) {
1443 $parents[$i]['children'] = get_item_children($arr, $_x);
1447 /// @TODO Old-lost code?
1448 /*foreach ($arr as $x) {
1449 if ($x['id'] != $x['parent']) {
1450 $p = find_thread_parent_index($parents,$x);
1452 $parents[$p]['children'][] = $x;
1455 if (count($parents)) {
1456 foreach ($parents as $k => $v) {
1457 if (count($parents[$k]['children'])) {
1458 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1459 /// @TODO Old-lost code?
1460 /*$y = $parents[$k]['children'];
1461 usort($y,'sort_thr_created_rev');
1462 $parents[$k]['children'] = $y;*/
1468 if (count($parents)) {
1469 foreach ($parents as $x) {
1471 if (count($x['children'])) {
1472 add_children_to_list($x['children'], $ret);
1473 /// @TODO Old-lost code?
1474 /*foreach ($x['children'] as $y)
1483 /// @TODO Add type-hint
1484 function sort_thr_created($a, $b) {
1485 return strcmp($b['created'], $a['created']);
1488 /// @TODO Add type-hint
1489 function sort_thr_created_rev($a, $b) {
1490 return strcmp($a['created'], $b['created']);
1493 /// @TODO Add type-hint
1494 function sort_thr_commented($a, $b) {
1495 return strcmp($b['commented'], $a['commented']);
1498 /// @TODO Add type-hint
1499 function find_thread_parent_index($arr, $x) {
1500 foreach ($arr as $k => $v) {
1501 if ($v['id'] == $x['parent']) {
1508 /// @TODO Add type-hint
1509 function render_location_dummy($item) {
1510 if ($item['location'] != "") {
1511 return $item['location'];
1514 if ($item['coord'] != "") {
1515 return $item['coord'];
1519 /// @TODO Add type-hint
1520 function get_responses($conv_responses, $response_verbs, $ob, $item) {
1522 foreach ($response_verbs as $v) {
1524 $ret[$v]['count'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
1525 $ret[$v]['list'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
1526 $ret[$v]['self'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0');
1527 if (count($ret[$v]['list']) > MAX_LIKERS) {
1528 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1529 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1530 . (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
1532 $ret[$v]['list_part'] = '';
1534 $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
1535 $ret[$v]['title'] = $conv_responses[$v]['title'];
1539 foreach ($ret as $key) {
1540 if ($key['count'] == true) {
1544 $ret['count'] = $count;
1549 function get_response_button_text($v, $count) {
1552 return tt('Like', 'Likes', $count, 'noun');
1555 return tt('Dislike', 'Dislikes', $count, 'noun');
1558 return tt('Attending', 'Attending', $count, 'noun');
1561 return tt('Not Attending', 'Not Attending', $count, 'noun');
1564 return tt('Undecided', 'Undecided', $count, 'noun');