3 // This is a purely experimental module and is not yet generally useful.
5 // The eventual goal is to provide a json backend to fetch content and fill the current page.
6 // The page will be filled in on the frontend using javascript.
7 // At the present time this page is based on "network", but the hope is to extend to serving
8 // any content (wall, community, search, etc.).
9 // All search parameters, etc. will be managed in javascript and sent as request params.
10 // Security will be managed on the backend.
11 // There is no "pagination query", but we will manage the "current page" on the client
12 // and provide a link to fetch the next page - until there are no pages left to fetch.
14 // With the exception of complex tag and text searches, this prototype is incredibly
15 // fast - e.g. one or two milliseconds to fetch parent items for the current content,
16 // and 10-20 milliseconds to fetch all the child items.
19 function content_content(&$a, $update = 0) {
21 require_once('include/conversation.php');
24 // Currently security is based on the logged in user
30 $arr = array('query' => $a->query_string);
32 call_hooks('content_content_init', $arr);
35 $datequery = $datequery2 = '';
42 for($x = 1; $x < $a->argc; $x ++) {
43 if(is_a_date_arg($a->argv[$x])) {
45 $datequery2 = escape_tags($a->argv[$x]);
47 $datequery = escape_tags($a->argv[$x]);
48 $_GET['order'] = 'post';
51 elseif($a->argv[$x] === 'new') {
54 elseif(intval($a->argv[$x])) {
55 $group = intval($a->argv[$x]);
56 $def_acl = array('allow_gid' => '<' . $group . '>');
66 $contact_id = $a->cid;
68 require_once('include/acl_selectors.php');
70 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
71 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
72 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
73 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
74 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
75 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
76 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
77 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
78 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
79 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
80 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
84 if(x($_GET,'search') || x($_GET,'file'))
87 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
90 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
98 $str .= '<' . $rr['id'] . '>';
100 $def_acl = array('allow_cid' => $str);
104 $sql_options = (($star) ? " and starred = 1 " : '');
105 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
107 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
109 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
112 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
114 intval($_SESSION['uid'])
119 notice( t('No such group') . EOL );
120 goaway($a->get_baseurl(true) . '/network');
124 $contacts = expand_groups(array($group));
125 if((is_array($contacts)) && count($contacts)) {
126 $contact_str = implode(',',$contacts);
129 $contact_str = ' 0 ';
130 info( t('Group is empty'));
133 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) ";
134 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
138 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
139 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
143 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
155 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
158 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
161 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
162 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
163 $sql_table = "`item`";
165 if(x($_GET,'search')) {
166 $search = escape_tags($_GET['search']);
168 if(strpos($search,'#') === 0) {
170 $search = substr($search,1);
173 if (get_config('system','only_tag_search'))
176 /*if (get_config('system','use_fulltext_engine')) {
177 if(strpos($search,'#') === 0)
178 $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('%s' in boolean mode)) ",
179 dbesc(protect_sprintf($search))
182 $sql_extra .= sprintf(" AND (MATCH(`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode)) ",
183 dbesc(protect_sprintf($search)),
184 dbesc(protect_sprintf($search))
187 $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ",
188 dbesc(protect_sprintf('%' . $search . '%')),
189 dbesc(protect_sprintf('%]' . $search . '[%'))
194 $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
195 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
196 $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
198 if (get_config('system','use_fulltext_engine'))
199 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
201 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
206 $sql_extra .= file_tag_file_query('item',unxmlify($file));
210 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
211 $myurl = substr($myurl,strpos($myurl,'://')+3);
212 $myurl = str_replace('www.','',$myurl);
213 $diasp_url = str_replace('/profile/','/u/',$myurl);
214 /*if (get_config('system','use_fulltext_engine'))
215 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where (MATCH(`author-link`, `tag`) AGAINST ('%s' in boolean mode) or MATCH(tag) AGAINST ('%s' in boolean mode))) ",
216 dbesc(protect_sprintf($myurl)),
217 dbesc(protect_sprintf($myurl)),
218 dbesc(protect_sprintf($diasp_url))
221 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ",
222 dbesc(protect_sprintf('%' . $myurl)),
223 dbesc(protect_sprintf('%' . $myurl . ']%')),
224 dbesc(protect_sprintf('%' . $diasp_url . ']%'))
227 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
228 dbesc(protect_sprintf($myurl)),
229 dbesc(protect_sprintf($myurl))
233 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
237 // "New Item View" - show all items unthreaded in reverse created date order
239 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
240 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
241 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
242 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
243 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
244 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
245 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
247 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
249 ORDER BY `item`.`received` DESC $pager_sql ",
250 intval($_SESSION['uid'])
256 // Normal conversation view
259 if($order === 'post')
260 $ordering = "`created`";
262 $ordering = "`commented`";
264 $start = dba_timer();
266 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
267 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
268 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
269 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
270 AND `item`.`parent` = `item`.`id`
271 $sql_extra3 $sql_extra $sql_nets
272 ORDER BY `item`.$ordering DESC $pager_sql ",
276 $first = dba_timer();
279 // Then fetch all the children of the parents that are on this page
281 $parents_arr = array();
286 if(! in_array($rr['item_id'],$parents_arr))
287 $parents_arr[] = $rr['item_id'];
288 $parents_str = implode(', ', $parents_arr);
290 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
291 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
292 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
293 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
294 FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
295 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
296 AND `item`.`moderated` = 0
297 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
298 AND `item`.`parent` IN ( %s )
300 intval(local_user()),
304 $second = dba_timer();
306 $items = conv_sort($items,$ordering);
314 logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
315 logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
317 // Set this so that the conversation function can find out contact info for our wall-wall items
318 $a->page_contact = $a->contact;
320 $mode = (($nouveau) ? 'network-new' : 'network');
322 $o = render_content($a,$items,$mode,false);
325 header('Content-type: application/json');
326 echo json_encode($o);
332 function render_content(&$a, $items, $mode, $update, $preview = false) {
335 require_once('include/bbcode.php');
337 $ssl_state = ((local_user()) ? true : false);
340 $page_writeable = false;
342 $previewing = (($preview) ? ' preview ' : '');
344 if($mode === 'network') {
345 $profile_owner = local_user();
346 $page_writeable = true;
349 if($mode === 'profile') {
350 $profile_owner = $a->profile['profile_uid'];
351 $page_writeable = can_write_wall($a,$profile_owner);
354 if($mode === 'notes') {
355 $profile_owner = local_user();
356 $page_writeable = true;
359 if($mode === 'display') {
360 $profile_owner = $a->profile['uid'];
361 $page_writeable = can_write_wall($a,$profile_owner);
364 if($mode === 'community') {
366 $page_writeable = false;
370 $return_url = $_SESSION['return_url'];
372 $return_url = $_SESSION['return_url'] = $a->query_string;
374 load_contact_links(local_user());
376 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
377 call_hooks('conversation_start',$cb);
379 $items = $cb['items'];
381 $cmnt_tpl = get_markup_template('comment_item.tpl');
382 $tpl = 'wall_item.tpl';
383 $wallwall = 'wallwall_item.tpl';
384 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
390 // array with html for each thread (parent+comments)
394 if($items && count($items)) {
396 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
398 // "New Item View" on network page or search page results
399 // - just loop through the items and format them minimally for display
401 //$tpl = get_markup_template('search_item.tpl');
402 $tpl = 'search_item.tpl';
404 foreach($items as $item) {
413 if($mode === 'search' || $mode === 'community') {
414 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
415 && ($item['id'] != $item['parent']))
417 $nickname = $item['nickname'];
420 $nickname = $a->user['nickname'];
422 // prevent private email from leaking.
423 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
426 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
427 if($item['author-link'] && (! $item['author-name']))
428 $profile_name = $item['author-link'];
433 $profile_link = best_link_url($item,$sp);
434 if($profile_link === 'mailbox')
437 $sparkle = ' sparkle';
439 $profile_link = zrl($profile_link);
441 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
442 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
443 $profile_avatar = $a->contacts[$normalised]['thumb'];
445 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
447 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
448 call_hooks('render_location',$locate);
450 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
452 localize_item($item);
453 if($mode === 'network-new')
460 'dropping' => $dropping,
461 'select' => t('Select'),
462 'delete' => t('Delete'),
466 $isstarred = "unstarred";
469 $likebuttons = false;
472 $body = prepare_body($item,true);
474 if($a->theme['template_engine'] === 'internal') {
475 $name_e = template_escape($profile_name);
476 $title_e = template_escape($item['title']);
477 $body_e = template_escape($body);
478 $text_e = strip_tags(template_escape($body));
479 $location_e = template_escape($location);
480 $owner_name_e = template_escape($owner_name);
483 $name_e = $profile_name;
484 $title_e = $item['title'];
486 $text_e = strip_tags($body);
487 $location_e = $location;
488 $owner_name_e = $owner_name;
491 //$tmp_item = replace_macros($tpl,array(
494 'id' => (($preview) ? 'P0' : $item['item_id']),
495 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
496 'profile_url' => $profile_link,
497 'item_photo_menu' => item_photo_menu($item),
499 'sparkle' => $sparkle,
501 'thumb' => $profile_avatar,
505 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
506 'location' => $location_e,
508 'owner_name' => $owner_name_e,
509 'owner_url' => $owner_url,
510 'owner_photo' => $owner_photo,
511 'plink' => get_plink($item),
513 'isstarred' => $isstarred,
516 'vote' => $likebuttons,
520 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
521 'previewing' => $previewing,
522 'wait' => t('Please wait'),
525 $arr = array('item' => $item, 'output' => $tmp_item);
526 call_hooks('display_item', $arr);
528 $threads[$threadsid]['id'] = $item['item_id'];
529 $threads[$threadsid]['items'] = array($arr['output']);
539 // Figure out how many comments each parent has
540 // (Comments all have gravity of 6)
541 // Store the result in the $comments array
544 foreach($items as $item) {
545 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
546 if(! x($comments,$item['parent']))
547 $comments[$item['parent']] = 1;
549 $comments[$item['parent']] += 1;
550 } elseif(! x($comments,$item['parent']))
551 $comments[$item['parent']] = 0; // avoid notices later on
554 // map all the like/dislike activities for each parent item
555 // Store these in the $alike and $dlike arrays
557 foreach($items as $item) {
558 like_puller($a,$item,$alike,'like');
559 like_puller($a,$item,$dlike,'dislike');
562 $comments_collapsed = false;
564 $comment_lastcollapsed = false;
565 $comment_firstcollapsed = false;
570 foreach($items as $item) {
576 $owner_url = $owner_photo = $owner_name = '';
578 // We've already parsed out like/dislike for special treatment. We can ignore them now
580 if(((activity_match($item['verb'],ACTIVITY_LIKE))
581 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
582 && ($item['id'] != $item['parent']))
585 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
588 // Take care of author collapsing and comment collapsing
589 // (author collapsing is currently disabled)
590 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
591 // If there are more than two comments, squash all but the last 2.
595 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
598 $comments_collapsed = false;
599 $comment_lastcollapsed = false;
600 $comment_firstcollapsed = false;
603 $threads[$threadsid]['id'] = $item['item_id'];
604 $threads[$threadsid]['private'] = $item['private'];
605 $threads[$threadsid]['items'] = array();
610 // prevent private email reply to public conversation from leaking.
611 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
615 $comment_lastcollapsed = false;
616 $comment_firstcollapsed = false;
619 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
620 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
623 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
625 if (!$comments_collapsed){
626 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
627 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
628 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
629 $threads[$threadsid]['hide_text'] = t('show more');
630 $comments_collapsed = true;
631 $comment_firstcollapsed = true;
634 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
636 $comment_lastcollapsed = true;
639 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
641 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
642 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
643 ? t('Private Message')
647 // Top-level wall post not written by the wall owner (wall-to-wall)
648 // First figure out who owns it.
652 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
656 // On the network page, I am the owner. On the display page it will be the profile owner.
657 // This will have been stored in $a->page_contact by our calling page.
658 // Put this person as the wall owner of the wall-to-wall notice.
660 $owner_url = zrl($a->page_contact['url']);
661 $owner_photo = $a->page_contact['thumb'];
662 $owner_name = $a->page_contact['name'];
663 $template = $wallwall;
667 if((! $item['wall']) && $item['owner-link']) {
669 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
670 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
671 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
672 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
674 // The author url doesn't match the owner (typically the contact)
675 // and also doesn't match the contact alias.
676 // The name match is a hack to catch several weird cases where URLs are
677 // all over the park. It can be tricked, but this prevents you from
678 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
679 // well that it's the same Bob Smith.
681 // But it could be somebody else with the same name. It just isn't highly likely.
684 $owner_url = $item['owner-link'];
685 $owner_photo = $item['owner-avatar'];
686 $owner_name = $item['owner-name'];
687 $template = $wallwall;
689 // If it is our contact, use a friendly redirect link
690 if((link_compare($item['owner-link'],$item['url']))
691 && ($item['network'] === NETWORK_DFRN)) {
692 $owner_url = $redirect_url;
693 $osparkle = ' sparkle';
696 $owner_url = zrl($owner_url);
702 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
704 if($page_writeable) {
705 /* if($toplevelpost) { */
706 $likebuttons = array(
707 'like' => array( t("I like this \x28toggle\x29"), t("like")),
708 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
710 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
713 $qc = $qcomment = null;
715 if(in_array('qcomment',$a->plugins)) {
716 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
717 $qcomment = (($qc) ? explode("\n",$qc) : null);
720 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
721 $comment = replace_macros($cmnt_tpl,array(
722 '$return_path' => '',
723 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
724 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
725 '$id' => $item['item_id'],
726 '$parent' => $item['parent'],
727 '$qcomment' => $qcomment,
728 '$profile_uid' => $profile_owner,
729 '$mylink' => $a->contact['url'],
730 '$mytitle' => t('This is you'),
731 '$myphoto' => $a->contact['thumb'],
732 '$comment' => t('Comment'),
733 '$submit' => t('Submit'),
734 '$edbold' => t('Bold'),
735 '$editalic' => t('Italic'),
736 '$eduline' => t('Underline'),
737 '$edquote' => t('Quote'),
738 '$edcode' => t('Code'),
739 '$edimg' => t('Image'),
740 '$edurl' => t('Link'),
741 '$edvideo' => t('Video'),
742 '$preview' => t('Preview'),
743 '$sourceapp' => t($a->sourcename),
744 '$ww' => (($mode === 'network') ? $commentww : ''),
745 '$rand_num' => random_digits(12)
750 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
751 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
758 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
762 'dropping' => $dropping,
763 'select' => t('Select'),
764 'delete' => t('Delete'),
770 $isstarred = "unstarred";
771 if ($profile_owner == local_user()) {
773 $isstarred = (($item['starred']) ? "starred" : "unstarred");
776 'do' => t("add star"),
777 'undo' => t("remove star"),
778 'toggle' => t("toggle star status"),
779 'classdo' => (($item['starred']) ? "hidden" : ""),
780 'classundo' => (($item['starred']) ? "" : "hidden"),
781 'starred' => t('starred'),
782 'tagger' => t("add tag"),
786 $filer = t("save to folder");
790 $photo = $item['photo'];
791 $thumb = $item['thumb'];
793 // Post was remotely authored.
795 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
797 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
799 if($item['author-link'] && (! $item['author-name']))
800 $profile_name = $item['author-link'];
803 $profile_link = best_link_url($item,$sp);
804 if($profile_link === 'mailbox')
807 $sparkle = ' sparkle';
809 $profile_link = zrl($profile_link);
811 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
812 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
813 $profile_avatar = $a->contacts[$normalised]['thumb'];
815 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
817 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
818 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
820 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
821 call_hooks('render_location',$locate);
823 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
825 $indent = (($toplevelpost) ? '' : ' comment');
828 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
832 localize_item($item);
836 foreach(explode(',',$item['tag']) as $tag){
838 if ($tag!="") $tags[] = bbcode($tag);
843 $body = prepare_body($item,true);
844 //$tmp_item = replace_macros($template,
846 if($a->theme['template_engine'] === 'internal') {
847 $body_e = template_escape($body);
848 $text_e = strip_tags(template_escape($body));
849 $name_e = template_escape($profile_name);
850 $title_e = template_escape($item['title']);
851 $location_e = template_escape($location);
852 $owner_name_e = template_escape($owner_name);
856 $text_e = strip_tags($body);
857 $name_e = $profile_name;
858 $title_e = $item['title'];
859 $location_e = $location;
860 $owner_name_e = $owner_name;
864 // collapse comments in template. I don't like this much...
865 'comment_firstcollapsed' => $comment_firstcollapsed,
866 'comment_lastcollapsed' => $comment_lastcollapsed,
867 // template to use to render item (wall, walltowall, search)
868 'template' => $template,
870 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
874 'id' => $item['item_id'],
875 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
876 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
878 'wall' => t('Wall-to-Wall'),
879 'vwall' => t('via Wall-To-Wall:'),
880 'profile_url' => $profile_link,
881 'item_photo_menu' => item_photo_menu($item),
883 'thumb' => $profile_avatar,
884 'osparkle' => $osparkle,
885 'sparkle' => $sparkle,
887 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
889 'location' => $location_e,
892 'owner_url' => $owner_url,
893 'owner_photo' => $owner_photo,
894 'owner_name' => $owner_name_e,
895 'plink' => get_plink($item),
897 'isstarred' => $isstarred,
901 'vote' => $likebuttons,
903 'dislike' => $dislike,
904 'comment' => $comment,
905 'previewing' => $previewing,
906 'wait' => t('Please wait'),
911 $arr = array('item' => $item, 'output' => $tmp_item);
912 call_hooks('display_item', $arr);
914 $threads[$threadsid]['items'][] = $arr['output'];