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 = replace_macros(get_markup_template("section_title.tpl"),array(
135 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
140 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
141 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
145 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
157 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
160 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
163 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
164 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
165 $sql_table = "`item`";
167 if(x($_GET,'search')) {
168 $search = escape_tags($_GET['search']);
170 if(strpos($search,'#') === 0) {
172 $search = substr($search,1);
175 if (get_config('system','only_tag_search'))
179 //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
180 // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
181 //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
184 $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
185 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
188 if (get_config('system','use_fulltext_engine'))
189 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
191 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
196 $sql_extra .= file_tag_file_query('item',unxmlify($file));
200 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
201 $myurl = substr($myurl,strpos($myurl,'://')+3);
202 $myurl = str_replace('www.','',$myurl);
203 $diasp_url = str_replace('/profile/','/u/',$myurl);
205 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
206 dbesc(protect_sprintf($myurl)),
207 dbesc(protect_sprintf($myurl))
211 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
215 // "New Item View" - show all items unthreaded in reverse created date order
217 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
218 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
219 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
220 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
221 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
222 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
223 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
225 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
227 ORDER BY `item`.`received` DESC $pager_sql ",
228 intval($_SESSION['uid'])
234 // Normal conversation view
237 if($order === 'post')
238 $ordering = "`created`";
240 $ordering = "`commented`";
242 $start = dba_timer();
244 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
245 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
246 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
247 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
248 AND `item`.`parent` = `item`.`id`
249 $sql_extra3 $sql_extra $sql_nets
250 ORDER BY `item`.$ordering DESC $pager_sql ",
254 $first = dba_timer();
257 // Then fetch all the children of the parents that are on this page
259 $parents_arr = array();
264 if(! in_array($rr['item_id'],$parents_arr))
265 $parents_arr[] = $rr['item_id'];
266 $parents_str = implode(', ', $parents_arr);
268 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
269 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
270 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
271 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
272 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
273 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
274 AND `item`.`moderated` = 0
275 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
276 AND `item`.`parent` IN ( %s )
278 intval(local_user()),
282 $second = dba_timer();
284 $items = conv_sort($items,$ordering);
292 logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
293 logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
295 // Set this so that the conversation function can find out contact info for our wall-wall items
296 $a->page_contact = $a->contact;
298 $mode = (($nouveau) ? 'network-new' : 'network');
300 $o = render_content($a,$items,$mode,false);
303 header('Content-type: application/json');
304 echo json_encode($o);
310 function render_content(&$a, $items, $mode, $update, $preview = false) {
312 require_once('include/bbcode.php');
313 require_once('mod/proxy.php');
315 $ssl_state = ((local_user()) ? true : false);
318 $page_writeable = false;
320 $previewing = (($preview) ? ' preview ' : '');
322 if($mode === 'network') {
323 $profile_owner = local_user();
324 $page_writeable = true;
327 if($mode === 'profile') {
328 $profile_owner = $a->profile['profile_uid'];
329 $page_writeable = can_write_wall($a,$profile_owner);
332 if($mode === 'notes') {
333 $profile_owner = local_user();
334 $page_writeable = true;
337 if($mode === 'display') {
338 $profile_owner = $a->profile['uid'];
339 $page_writeable = can_write_wall($a,$profile_owner);
342 if($mode === 'community') {
344 $page_writeable = false;
348 $return_url = $_SESSION['return_url'];
350 $return_url = $_SESSION['return_url'] = $a->query_string;
352 load_contact_links(local_user());
354 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
355 call_hooks('conversation_start',$cb);
357 $items = $cb['items'];
359 $cmnt_tpl = get_markup_template('comment_item.tpl');
360 $tpl = 'wall_item.tpl';
361 $wallwall = 'wallwall_item.tpl';
362 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
368 // array with html for each thread (parent+comments)
372 if($items && count($items)) {
374 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
376 // "New Item View" on network page or search page results
377 // - just loop through the items and format them minimally for display
379 //$tpl = get_markup_template('search_item.tpl');
380 $tpl = 'search_item.tpl';
382 foreach($items as $item) {
391 if($mode === 'search' || $mode === 'community') {
392 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
393 && ($item['id'] != $item['parent']))
395 $nickname = $item['nickname'];
398 $nickname = $a->user['nickname'];
400 // prevent private email from leaking.
401 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
404 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
405 if($item['author-link'] && (! $item['author-name']))
406 $profile_name = $item['author-link'];
411 $profile_link = best_link_url($item,$sp);
412 if($profile_link === 'mailbox')
415 $sparkle = ' sparkle';
417 $profile_link = zrl($profile_link);
419 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
420 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
421 $profile_avatar = $a->contacts[$normalised]['thumb'];
423 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
425 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
426 call_hooks('render_location',$locate);
428 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
430 localize_item($item);
431 if($mode === 'network-new')
438 'dropping' => $dropping,
439 'select' => t('Select'),
440 'delete' => t('Delete'),
444 $isstarred = "unstarred";
447 $likebuttons = false;
450 $body = prepare_body($item,true);
452 if($a->theme['template_engine'] === 'internal') {
453 $name_e = template_escape($profile_name);
454 $title_e = template_escape($item['title']);
455 $body_e = template_escape($body);
456 $text_e = strip_tags(template_escape($body));
457 $location_e = template_escape($location);
458 $owner_name_e = template_escape($owner_name);
461 $name_e = $profile_name;
462 $title_e = $item['title'];
464 $text_e = strip_tags($body);
465 $location_e = $location;
466 $owner_name_e = $owner_name;
469 //$tmp_item = replace_macros($tpl,array(
472 'id' => (($preview) ? 'P0' : $item['item_id']),
473 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
474 'profile_url' => $profile_link,
475 'item_photo_menu' => item_photo_menu($item),
477 'sparkle' => $sparkle,
479 'thumb' => proxy_url($profile_avatar),
483 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
484 'location' => $location_e,
486 'owner_name' => $owner_name_e,
487 'owner_url' => $owner_url,
488 'owner_photo' => proxy_url($owner_photo),
489 'plink' => get_plink($item),
491 'isstarred' => $isstarred,
494 'vote' => $likebuttons,
498 //'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
499 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
500 'previewing' => $previewing,
501 'wait' => t('Please wait'),
504 $arr = array('item' => $item, 'output' => $tmp_item);
505 call_hooks('display_item', $arr);
507 $threads[$threadsid]['id'] = $item['item_id'];
508 $threads[$threadsid]['items'] = array($arr['output']);
518 // Figure out how many comments each parent has
519 // (Comments all have gravity of 6)
520 // Store the result in the $comments array
523 foreach($items as $item) {
524 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
525 if(! x($comments,$item['parent']))
526 $comments[$item['parent']] = 1;
528 $comments[$item['parent']] += 1;
529 } elseif(! x($comments,$item['parent']))
530 $comments[$item['parent']] = 0; // avoid notices later on
533 // map all the like/dislike activities for each parent item
534 // Store these in the $alike and $dlike arrays
536 foreach($items as $item) {
537 like_puller($a,$item,$alike,'like');
538 like_puller($a,$item,$dlike,'dislike');
541 $comments_collapsed = false;
543 $comment_lastcollapsed = false;
544 $comment_firstcollapsed = false;
549 foreach($items as $item) {
555 $owner_url = $owner_photo = $owner_name = '';
557 // We've already parsed out like/dislike for special treatment. We can ignore them now
559 if(((activity_match($item['verb'],ACTIVITY_LIKE))
560 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
561 && ($item['id'] != $item['parent']))
564 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
567 // Take care of author collapsing and comment collapsing
568 // (author collapsing is currently disabled)
569 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
570 // If there are more than two comments, squash all but the last 2.
574 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
577 $comments_collapsed = false;
578 $comment_lastcollapsed = false;
579 $comment_firstcollapsed = false;
582 $threads[$threadsid]['id'] = $item['item_id'];
583 $threads[$threadsid]['private'] = $item['private'];
584 $threads[$threadsid]['items'] = array();
589 // prevent private email reply to public conversation from leaking.
590 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
594 $comment_lastcollapsed = false;
595 $comment_firstcollapsed = false;
598 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
599 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
602 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
604 if (!$comments_collapsed){
605 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
606 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
607 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
608 $threads[$threadsid]['hide_text'] = t('show more');
609 $comments_collapsed = true;
610 $comment_firstcollapsed = true;
613 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
615 $comment_lastcollapsed = true;
618 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
620 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
621 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
622 ? t('Private Message')
626 // Top-level wall post not written by the wall owner (wall-to-wall)
627 // First figure out who owns it.
631 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
635 // On the network page, I am the owner. On the display page it will be the profile owner.
636 // This will have been stored in $a->page_contact by our calling page.
637 // Put this person as the wall owner of the wall-to-wall notice.
639 $owner_url = zrl($a->page_contact['url']);
640 $owner_photo = $a->page_contact['thumb'];
641 $owner_name = $a->page_contact['name'];
642 $template = $wallwall;
646 if((! $item['wall']) && $item['owner-link']) {
648 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
649 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
650 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
651 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
653 // The author url doesn't match the owner (typically the contact)
654 // and also doesn't match the contact alias.
655 // The name match is a hack to catch several weird cases where URLs are
656 // all over the park. It can be tricked, but this prevents you from
657 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
658 // well that it's the same Bob Smith.
660 // But it could be somebody else with the same name. It just isn't highly likely.
663 $owner_url = $item['owner-link'];
664 $owner_photo = $item['owner-avatar'];
665 $owner_name = $item['owner-name'];
666 $template = $wallwall;
668 // If it is our contact, use a friendly redirect link
669 if((link_compare($item['owner-link'],$item['url']))
670 && ($item['network'] === NETWORK_DFRN)) {
671 $owner_url = $redirect_url;
672 $osparkle = ' sparkle';
675 $owner_url = zrl($owner_url);
681 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
683 if($page_writeable) {
684 /* if($toplevelpost) { */
685 $likebuttons = array(
686 'like' => array( t("I like this \x28toggle\x29"), t("like")),
687 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
689 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
692 $qc = $qcomment = null;
694 if(in_array('qcomment',$a->plugins)) {
695 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
696 $qcomment = (($qc) ? explode("\n",$qc) : null);
699 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
700 $comment = replace_macros($cmnt_tpl,array(
701 '$return_path' => '',
702 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
703 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
704 '$id' => $item['item_id'],
705 '$parent' => $item['parent'],
706 '$qcomment' => $qcomment,
707 '$profile_uid' => $profile_owner,
708 '$mylink' => $a->contact['url'],
709 '$mytitle' => t('This is you'),
710 '$myphoto' => $a->contact['thumb'],
711 '$comment' => t('Comment'),
712 '$submit' => t('Submit'),
713 '$edbold' => t('Bold'),
714 '$editalic' => t('Italic'),
715 '$eduline' => t('Underline'),
716 '$edquote' => t('Quote'),
717 '$edcode' => t('Code'),
718 '$edimg' => t('Image'),
719 '$edurl' => t('Link'),
720 '$edvideo' => t('Video'),
721 '$preview' => t('Preview'),
722 '$sourceapp' => t($a->sourcename),
723 '$ww' => (($mode === 'network') ? $commentww : ''),
724 '$rand_num' => random_digits(12)
729 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
730 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
737 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
741 'dropping' => $dropping,
742 'select' => t('Select'),
743 'delete' => t('Delete'),
749 $isstarred = "unstarred";
750 if ($profile_owner == local_user()) {
752 $isstarred = (($item['starred']) ? "starred" : "unstarred");
755 'do' => t("add star"),
756 'undo' => t("remove star"),
757 'toggle' => t("toggle star status"),
758 'classdo' => (($item['starred']) ? "hidden" : ""),
759 'classundo' => (($item['starred']) ? "" : "hidden"),
760 'starred' => t('starred'),
761 'tagger' => t("add tag"),
765 $filer = t("save to folder");
769 $photo = $item['photo'];
770 $thumb = $item['thumb'];
772 // Post was remotely authored.
774 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
776 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
778 if($item['author-link'] && (! $item['author-name']))
779 $profile_name = $item['author-link'];
782 $profile_link = best_link_url($item,$sp);
783 if($profile_link === 'mailbox')
786 $sparkle = ' sparkle';
788 $profile_link = zrl($profile_link);
790 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
791 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
792 $profile_avatar = $a->contacts[$normalised]['thumb'];
794 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
796 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
797 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
799 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
800 call_hooks('render_location',$locate);
802 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
804 $indent = (($toplevelpost) ? '' : ' comment');
807 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
811 localize_item($item);
815 foreach(explode(',',$item['tag']) as $tag){
817 if ($tag!="") $tags[] = bbcode($tag);
822 $body = prepare_body($item,true);
823 //$tmp_item = replace_macros($template,
825 if($a->theme['template_engine'] === 'internal') {
826 $body_e = template_escape($body);
827 $text_e = strip_tags(template_escape($body));
828 $name_e = template_escape($profile_name);
829 $title_e = template_escape($item['title']);
830 $location_e = template_escape($location);
831 $owner_name_e = template_escape($owner_name);
835 $text_e = strip_tags($body);
836 $name_e = $profile_name;
837 $title_e = $item['title'];
838 $location_e = $location;
839 $owner_name_e = $owner_name;
843 // collapse comments in template. I don't like this much...
844 'comment_firstcollapsed' => $comment_firstcollapsed,
845 'comment_lastcollapsed' => $comment_lastcollapsed,
846 // template to use to render item (wall, walltowall, search)
847 'template' => $template,
849 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
853 'id' => $item['item_id'],
854 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
855 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
857 'wall' => t('Wall-to-Wall'),
858 'vwall' => t('via Wall-To-Wall:'),
859 'profile_url' => $profile_link,
860 'item_photo_menu' => item_photo_menu($item),
862 'thumb' => proxy_url($profile_avatar),
863 'osparkle' => $osparkle,
864 'sparkle' => $sparkle,
866 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
868 'location' => $location_e,
871 'owner_url' => $owner_url,
872 'owner_photo' => proxy_url($owner_photo),
873 'owner_name' => $owner_name_e,
874 'plink' => get_plink($item),
876 'isstarred' => $isstarred,
880 'vote' => $likebuttons,
882 'dislike' => $dislike,
883 'comment' => $comment,
884 'previewing' => $previewing,
885 'wait' => t('Please wait'),
890 $arr = array('item' => $item, 'output' => $tmp_item);
891 call_hooks('display_item', $arr);
893 $threads[$threadsid]['items'][] = $arr['output'];