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(App $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';
50 } elseif ($a->argv[$x] === 'new') {
52 } elseif (intval($a->argv[$x])) {
53 $group = intval($a->argv[$x]);
54 $def_acl = array('allow_gid' => '<' . $group . '>');
64 $contact_id = $a->cid;
66 require_once('include/acl_selectors.php');
68 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
69 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
70 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
71 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
72 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
73 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
74 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
75 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
76 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
77 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
78 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
82 if (x($_GET,'search') || x($_GET,'file'))
85 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
88 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
94 if (dbm::is_result($r))
96 $str .= '<' . $rr['id'] . '>';
98 $def_acl = array('allow_cid' => $str);
102 $sql_options = (($star) ? " and starred = 1 " : '');
103 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
105 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
107 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
110 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
112 intval($_SESSION['uid'])
114 if (! dbm::is_result($r)) {
117 notice( t('No such group') . EOL );
118 goaway(App::get_baseurl(true) . '/network');
122 $contacts = expand_groups(array($group));
123 if ((is_array($contacts)) && count($contacts)) {
124 $contact_str = implode(',',$contacts);
127 $contact_str = ' 0 ';
128 info( t('Group is empty'));
131 $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 ) ";
132 $o = replace_macros(get_markup_template("section_title.tpl"),array(
133 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
138 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
139 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
142 if (dbm::is_result($r)) {
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'))
177 //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
178 // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
179 //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
182 $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` ",
183 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
186 if (get_config('system','use_fulltext_engine'))
187 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
189 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
194 $sql_extra .= file_tag_file_query('item',unxmlify($file));
198 $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
199 $myurl = substr($myurl,strpos($myurl,'://')+3);
200 $myurl = str_replace('www.','',$myurl);
201 $diasp_url = str_replace('/profile/','/u/',$myurl);
203 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
204 dbesc(protect_sprintf($myurl)),
205 dbesc(protect_sprintf($myurl))
209 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
213 // "New Item View" - show all items unthreaded in reverse created date order
215 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
216 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
217 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
218 `contact`.`id` AS `cid`
219 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
220 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
221 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
223 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
225 ORDER BY `item`.`id` DESC $pager_sql ",
226 intval($_SESSION['uid'])
232 // Normal conversation view
235 if ($order === 'post')
236 $ordering = "`created`";
238 $ordering = "`commented`";
240 $start = dba_timer();
242 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
243 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
244 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
245 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
246 AND `item`.`parent` = `item`.`id`
247 $sql_extra3 $sql_extra $sql_nets
248 ORDER BY `item`.$ordering DESC $pager_sql ",
252 $first = dba_timer();
255 // Then fetch all the children of the parents that are on this page
257 $parents_arr = array();
260 if (dbm::is_result($r)) {
262 if (! in_array($rr['item_id'],$parents_arr))
263 $parents_arr[] = $rr['item_id'];
264 $parents_str = implode(', ', $parents_arr);
266 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
267 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
268 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
269 `contact`.`id` AS `cid`
270 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
271 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
272 AND `item`.`moderated` = 0
273 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
274 AND `item`.`parent` IN ( %s )
276 intval(local_user()),
280 $second = dba_timer();
282 $items = conv_sort($items,$ordering);
290 logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
291 logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
293 // Set this so that the conversation function can find out contact info for our wall-wall items
294 $a->page_contact = $a->contact;
296 $mode = (($nouveau) ? 'network-new' : 'network');
298 $o = render_content($a,$items,$mode,false);
301 header('Content-type: application/json');
302 echo json_encode($o);
308 function render_content(App $a, $items, $mode, $update, $preview = false) {
310 require_once('include/bbcode.php');
311 require_once('mod/proxy.php');
313 $ssl_state = ((local_user()) ? true : false);
316 $page_writeable = false;
318 $previewing = (($preview) ? ' preview ' : '');
321 if (strcmp($item['created'], $item['edited'])<>0) {
323 'label' => t('This entry was edited'),
324 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
325 'relative' => relative_date($item['edited'])
329 if ($mode === 'network') {
330 $profile_owner = local_user();
331 $page_writeable = true;
334 if ($mode === 'profile') {
335 $profile_owner = $a->profile['profile_uid'];
336 $page_writeable = can_write_wall($a,$profile_owner);
339 if ($mode === 'notes') {
340 $profile_owner = local_user();
341 $page_writeable = true;
344 if ($mode === 'display') {
345 $profile_owner = $a->profile['uid'];
346 $page_writeable = can_write_wall($a,$profile_owner);
349 if ($mode === 'community') {
351 $page_writeable = false;
355 $return_url = $_SESSION['return_url'];
357 $return_url = $_SESSION['return_url'] = $a->query_string;
359 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
360 call_hooks('conversation_start',$cb);
362 $items = $cb['items'];
364 $cmnt_tpl = get_markup_template('comment_item.tpl');
365 $tpl = 'wall_item.tpl';
366 $wallwall = 'wallwall_item.tpl';
367 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
369 $conv_responses = array(
370 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
371 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
375 // array with html for each thread (parent+comments)
379 if ($items && count($items)) {
381 if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
383 // "New Item View" on network page or search page results
384 // - just loop through the items and format them minimally for display
386 //$tpl = get_markup_template('search_item.tpl');
387 $tpl = 'search_item.tpl';
389 foreach ($items as $item) {
398 if ($mode === 'search' || $mode === 'community') {
399 if (((activity_match($item['verb'],ACTIVITY_LIKE))
400 || (activity_match($item['verb'],ACTIVITY_DISLIKE))
401 || activity_match($item['verb'],ACTIVITY_ATTEND)
402 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
403 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE))
404 && ($item['id'] != $item['parent']))
406 $nickname = $item['nickname'];
409 $nickname = $a->user['nickname'];
411 // prevent private email from leaking.
412 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
415 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
416 if ($item['author-link'] && (! $item['author-name']))
417 $profile_name = $item['author-link'];
422 $profile_link = best_link_url($item,$sp);
423 if ($profile_link === 'mailbox')
426 $sparkle = ' sparkle';
428 $profile_link = zrl($profile_link);
430 // Don't rely on the author-avatar. It is better to use the data from the contact table
431 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
432 if ($author_contact["thumb"])
433 $profile_avatar = $author_contact["thumb"];
435 $profile_avatar = $item['author-avatar'];
437 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
438 call_hooks('render_location',$locate);
440 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
442 localize_item($item);
443 if ($mode === 'network-new')
450 'dropping' => $dropping,
451 'select' => t('Select'),
452 'delete' => t('Delete'),
456 $isstarred = "unstarred";
459 $likebuttons = false;
462 $body = prepare_body($item,true);
464 if ($a->theme['template_engine'] === 'internal') {
465 $name_e = template_escape($profile_name);
466 $title_e = template_escape($item['title']);
467 $body_e = template_escape($body);
468 $text_e = strip_tags(template_escape($body));
469 $location_e = template_escape($location);
470 $owner_name_e = template_escape($owner_name);
473 $name_e = $profile_name;
474 $title_e = $item['title'];
476 $text_e = strip_tags($body);
477 $location_e = $location;
478 $owner_name_e = $owner_name;
481 //$tmp_item = replace_macros($tpl,array(
484 'id' => (($preview) ? 'P0' : $item['item_id']),
485 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
486 'profile_url' => $profile_link,
487 'item_photo_menu' => item_photo_menu($item),
489 'sparkle' => $sparkle,
491 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
495 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
496 'location' => $location_e,
498 'owner_name' => $owner_name_e,
499 'owner_url' => $owner_url,
500 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
501 'plink' => get_plink($item),
503 'isstarred' => $isstarred,
506 'vote' => $likebuttons,
510 //'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
511 'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
512 'previewing' => $previewing,
513 'wait' => t('Please wait'),
516 $arr = array('item' => $item, 'output' => $tmp_item);
517 call_hooks('display_item', $arr);
519 $threads[$threadsid]['id'] = $item['item_id'];
520 $threads[$threadsid]['items'] = array($arr['output']);
530 // Figure out how many comments each parent has
531 // (Comments all have gravity of 6)
532 // Store the result in the $comments array
535 foreach ($items as $item) {
536 if ((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
537 if (! x($comments,$item['parent']))
538 $comments[$item['parent']] = 1;
540 $comments[$item['parent']] += 1;
541 } elseif (! x($comments,$item['parent']))
542 $comments[$item['parent']] = 0; // avoid notices later on
545 // map all the like/dislike/attendance activities for each parent item
546 // Store these in the $alike and $dlike arrays
548 foreach ($items as $item) {
549 builtin_activity_puller($item, $conv_responses);
552 $comments_collapsed = false;
554 $comment_lastcollapsed = false;
555 $comment_firstcollapsed = false;
560 foreach ($items as $item) {
566 $owner_url = $owner_photo = $owner_name = '';
568 // We've already parsed out like/dislike for special treatment. We can ignore them now
570 if (((activity_match($item['verb'],ACTIVITY_LIKE))
571 || (activity_match($item['verb'],ACTIVITY_DISLIKE)
572 || activity_match($item['verb'],ACTIVITY_ATTEND)
573 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
574 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)))
575 && ($item['id'] != $item['parent']))
578 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
581 // Take care of author collapsing and comment collapsing
582 // (author collapsing is currently disabled)
583 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
584 // If there are more than two comments, squash all but the last 2.
588 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
591 $comments_collapsed = false;
592 $comment_lastcollapsed = false;
593 $comment_firstcollapsed = false;
596 $threads[$threadsid]['id'] = $item['item_id'];
597 $threads[$threadsid]['private'] = $item['private'];
598 $threads[$threadsid]['items'] = array();
603 // prevent private email reply to public conversation from leaking.
604 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
608 $comment_lastcollapsed = false;
609 $comment_firstcollapsed = false;
612 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
613 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
616 if (($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
618 if (!$comments_collapsed){
619 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
620 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
621 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
622 $threads[$threadsid]['hide_text'] = t('show more');
623 $comments_collapsed = true;
624 $comment_firstcollapsed = true;
627 if (($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
629 $comment_lastcollapsed = true;
632 $redirect_url = 'redir/' . $item['cid'] ;
634 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
635 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
636 ? t('Private Message')
640 // Top-level wall post not written by the wall owner (wall-to-wall)
641 // First figure out who owns it.
645 if (($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
649 // On the network page, I am the owner. On the display page it will be the profile owner.
650 // This will have been stored in $a->page_contact by our calling page.
651 // Put this person as the wall owner of the wall-to-wall notice.
653 $owner_url = zrl($a->page_contact['url']);
654 $owner_photo = $a->page_contact['thumb'];
655 $owner_name = $a->page_contact['name'];
656 $template = $wallwall;
660 if ((! $item['wall']) && $item['owner-link']) {
662 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
663 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
664 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
665 if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
667 // The author url doesn't match the owner (typically the contact)
668 // and also doesn't match the contact alias.
669 // The name match is a hack to catch several weird cases where URLs are
670 // all over the park. It can be tricked, but this prevents you from
671 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
672 // well that it's the same Bob Smith.
674 // But it could be somebody else with the same name. It just isn't highly likely.
677 $owner_url = $item['owner-link'];
678 $owner_photo = $item['owner-avatar'];
679 $owner_name = $item['owner-name'];
680 $template = $wallwall;
682 // If it is our contact, use a friendly redirect link
683 if ((link_compare($item['owner-link'],$item['url']))
684 && ($item['network'] === NETWORK_DFRN)) {
685 $owner_url = $redirect_url;
686 $osparkle = ' sparkle';
689 $owner_url = zrl($owner_url);
695 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
697 if ($page_writeable) {
698 /* if ($toplevelpost) { */
699 $likebuttons = array(
700 'like' => array( t("I like this \x28toggle\x29"), t("like")),
701 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
703 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
706 $qc = $qcomment = null;
708 if (in_array('qcomment',$a->plugins)) {
709 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
710 $qcomment = (($qc) ? explode("\n",$qc) : null);
713 if (($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
714 $comment = replace_macros($cmnt_tpl,array(
715 '$return_path' => '',
716 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
717 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
718 '$id' => $item['item_id'],
719 '$parent' => $item['parent'],
720 '$qcomment' => $qcomment,
721 '$profile_uid' => $profile_owner,
722 '$mylink' => $a->contact['url'],
723 '$mytitle' => t('This is you'),
724 '$myphoto' => $a->contact['thumb'],
725 '$comment' => t('Comment'),
726 '$submit' => t('Submit'),
727 '$edbold' => t('Bold'),
728 '$editalic' => t('Italic'),
729 '$eduline' => t('Underline'),
730 '$edquote' => t('Quote'),
731 '$edcode' => t('Code'),
732 '$edimg' => t('Image'),
733 '$edurl' => t('Link'),
734 '$edvideo' => t('Video'),
735 '$preview' => t('Preview'),
736 '$sourceapp' => t($a->sourcename),
737 '$ww' => (($mode === 'network') ? $commentww : ''),
738 '$rand_num' => random_digits(12)
743 if (local_user() && link_compare($a->contact['url'],$item['author-link'])) {
744 $edpost = array(App::get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
752 if ((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
756 'dropping' => $dropping,
757 'select' => t('Select'),
758 'delete' => t('Delete'),
764 $isstarred = "unstarred";
765 if ($profile_owner == local_user()) {
767 $isstarred = (($item['starred']) ? "starred" : "unstarred");
770 'do' => t("add star"),
771 'undo' => t("remove star"),
772 'toggle' => t("toggle star status"),
773 'classdo' => (($item['starred']) ? "hidden" : ""),
774 'classundo' => (($item['starred']) ? "" : "hidden"),
775 'starred' => t('starred'),
776 'tagger' => t("add tag"),
780 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
781 intval($item['uid']),
785 if (dbm::is_result($r)) {
787 'do' => t("ignore thread"),
788 'undo' => t("unignore thread"),
789 'toggle' => t("toggle ignore status"),
790 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
791 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
792 'ignored' => t('ignored'),
796 if (feature_enabled($profile_owner,'commtag')) {
798 'add' => t("add tag"),
803 $filer = t("save to folder");
807 $photo = $item['photo'];
808 $thumb = $item['thumb'];
810 // Post was remotely authored.
812 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
814 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
816 if ($item['author-link'] && (! $item['author-name']))
817 $profile_name = $item['author-link'];
820 $profile_link = best_link_url($item,$sp);
821 if ($profile_link === 'mailbox') {
825 $sparkle = ' sparkle';
827 $profile_link = zrl($profile_link);
830 // Don't rely on the author-avatar. It is better to use the data from the contact table
831 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
832 if ($author_contact["thumb"]) {
833 $profile_avatar = $author_contact["thumb"];
835 $profile_avatar = $item['author-avatar'];
838 $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
839 $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
841 // process action responses - e.g. like/dislike/attend/agree/whatever
842 $response_verbs = array('like');
843 if (feature_enabled($profile_owner,'dislike')) {
844 $response_verbs[] = 'dislike';
846 if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
847 $response_verbs[] = 'attendyes';
848 $response_verbs[] = 'attendno';
849 $response_verbs[] = 'attendmaybe';
850 if ($page_writeable) {
852 $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
855 $responses = get_responses($conv_responses,$response_verbs,'',$item);
857 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
858 call_hooks('render_location',$locate);
860 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
862 $indent = (($toplevelpost) ? '' : ' comment');
865 if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) {
870 localize_item($item);
874 foreach (explode(',',$item['tag']) as $tag){
877 $tags[] = bbcode($tag);
883 $body = prepare_body($item,true);
884 //$tmp_item = replace_macros($template,
886 if ($a->theme['template_engine'] === 'internal') {
887 $body_e = template_escape($body);
888 $text_e = strip_tags(template_escape($body));
889 $name_e = template_escape($profile_name);
890 $title_e = template_escape($item['title']);
891 $location_e = template_escape($location);
892 $owner_name_e = template_escape($owner_name);
895 $text_e = strip_tags($body);
896 $name_e = $profile_name;
897 $title_e = $item['title'];
898 $location_e = $location;
899 $owner_name_e = $owner_name;
903 // collapse comments in template. I don't like this much...
904 'comment_firstcollapsed' => $comment_firstcollapsed,
905 'comment_lastcollapsed' => $comment_lastcollapsed,
906 // template to use to render item (wall, walltowall, search)
907 'template' => $template,
909 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
913 'id' => $item['item_id'],
914 'isevent' => $isevent,
916 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
917 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
919 'wall' => t('Wall-to-Wall'),
920 'vwall' => t('via Wall-To-Wall:'),
921 'profile_url' => $profile_link,
922 'item_photo_menu' => item_photo_menu($item),
924 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
925 'osparkle' => $osparkle,
926 'sparkle' => $sparkle,
928 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
929 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
930 'app' => $item['app'],
931 'created' => relative_date($item['created']),
933 'location' => $location_e,
936 'owner_url' => $owner_url,
937 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
938 'owner_name' => $owner_name_e,
939 'plink' => get_plink($item),
941 'isstarred' => $isstarred,
943 'ignore' => ((feature_enabled($profile_owner,'ignore_posts')) ? $ignore : ''),
945 'filer' => ((feature_enabled($profile_owner,'filing')) ? $filer : ''),
947 'vote' => $likebuttons,
948 'responses' => $responses,
950 'dislike' => $dislike,
951 'switchcomment' => t('Comment'),
952 'comment' => $comment,
953 'previewing' => $previewing,
954 'wait' => t('Please wait'),
956 'network' => $item["item_network"],
957 'network_name' => network_to_name($item['network'], $profile_link),
962 $arr = array('item' => $item, 'output' => $tmp_item);
963 call_hooks('display_item', $arr);
965 $threads[$threadsid]['items'][] = $arr['output'];