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 use Friendica\Core\System;
21 function content_content(App $a, $update = 0) {
23 require_once('include/conversation.php');
26 // Currently security is based on the logged in user
32 $arr = array('query' => $a->query_string);
34 call_hooks('content_content_init', $arr);
37 $datequery = $datequery2 = '';
44 for($x = 1; $x < $a->argc; $x ++) {
45 if(is_a_date_arg($a->argv[$x])) {
47 $datequery2 = escape_tags($a->argv[$x]);
49 $datequery = escape_tags($a->argv[$x]);
50 $_GET['order'] = 'post';
53 elseif($a->argv[$x] === 'new') {
56 elseif(intval($a->argv[$x])) {
57 $group = intval($a->argv[$x]);
58 $def_acl = array('allow_gid' => '<' . $group . '>');
68 $contact_id = $a->cid;
70 require_once('include/acl_selectors.php');
72 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
73 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
74 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
75 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
76 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
77 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
78 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
79 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
80 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
81 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
82 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
86 if(x($_GET,'search') || x($_GET,'file'))
89 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
92 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
98 if (dbm::is_result($r))
100 $str .= '<' . $rr['id'] . '>';
102 $def_acl = array('allow_cid' => $str);
106 $sql_options = (($star) ? " and starred = 1 " : '');
107 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
109 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
111 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
114 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
116 intval($_SESSION['uid'])
118 if (! dbm::is_result($r)) {
121 notice( t('No such group') . EOL );
122 goaway(System::baseUrl(true) . '/network');
126 $contacts = expand_groups(array($group));
127 if((is_array($contacts)) && count($contacts)) {
128 $contact_str = implode(',',$contacts);
131 $contact_str = ' 0 ';
132 info( t('Group is empty'));
135 $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 ) ";
136 $o = replace_macros(get_markup_template("section_title.tpl"),array(
137 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
142 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
143 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
146 if (dbm::is_result($r)) {
147 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
159 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
162 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
165 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
166 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
167 $sql_table = "`item`";
169 if(x($_GET,'search')) {
170 $search = escape_tags($_GET['search']);
172 if(strpos($search,'#') === 0) {
174 $search = substr($search,1);
177 if (get_config('system','only_tag_search'))
181 //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
182 // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
183 //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
186 $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` ",
187 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
190 if (get_config('system','use_fulltext_engine'))
191 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
193 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
198 $sql_extra .= file_tag_file_query('item',unxmlify($file));
202 $myurl = System::baseUrl() . '/profile/'. $a->user['nickname'];
203 $myurl = substr($myurl,strpos($myurl,'://')+3);
204 $myurl = str_replace('www.','',$myurl);
205 $diasp_url = str_replace('/profile/','/u/',$myurl);
207 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
208 dbesc(protect_sprintf($myurl)),
209 dbesc(protect_sprintf($myurl))
213 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
217 // "New Item View" - show all items unthreaded in reverse created date order
219 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
220 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
221 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
222 `contact`.`id` AS `cid`
223 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
224 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
225 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
227 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
229 ORDER BY `item`.`id` DESC $pager_sql ",
230 intval($_SESSION['uid'])
236 // Normal conversation view
239 if($order === 'post')
240 $ordering = "`created`";
242 $ordering = "`commented`";
244 $start = dba_timer();
246 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
247 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
248 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
249 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
250 AND `item`.`parent` = `item`.`id`
251 $sql_extra3 $sql_extra $sql_nets
252 ORDER BY `item`.$ordering DESC $pager_sql ",
256 $first = dba_timer();
259 // Then fetch all the children of the parents that are on this page
261 $parents_arr = array();
264 if (dbm::is_result($r)) {
266 if(! in_array($rr['item_id'],$parents_arr))
267 $parents_arr[] = $rr['item_id'];
268 $parents_str = implode(', ', $parents_arr);
270 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
271 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
272 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
273 `contact`.`id` AS `cid`
274 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
275 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
276 AND `item`.`moderated` = 0
277 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
278 AND `item`.`parent` IN ( %s )
280 intval(local_user()),
284 $second = dba_timer();
286 $items = conv_sort($items,$ordering);
294 logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
295 logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
297 // Set this so that the conversation function can find out contact info for our wall-wall items
298 $a->page_contact = $a->contact;
300 $mode = (($nouveau) ? 'network-new' : 'network');
302 $o = render_content($a,$items,$mode,false);
305 header('Content-type: application/json');
306 echo json_encode($o);
312 function render_content(App $a, $items, $mode, $update, $preview = false) {
314 require_once('include/bbcode.php');
315 require_once('mod/proxy.php');
317 $ssl_state = ((local_user()) ? true : false);
320 $page_writeable = false;
322 $previewing = (($preview) ? ' preview ' : '');
325 if (strcmp($item['created'], $item['edited'])<>0) {
327 'label' => t('This entry was edited'),
328 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
329 'relative' => relative_date($item['edited'])
333 if($mode === 'network') {
334 $profile_owner = local_user();
335 $page_writeable = true;
338 if($mode === 'profile') {
339 $profile_owner = $a->profile['profile_uid'];
340 $page_writeable = can_write_wall($a,$profile_owner);
343 if($mode === 'notes') {
344 $profile_owner = local_user();
345 $page_writeable = true;
348 if($mode === 'display') {
349 $profile_owner = $a->profile['uid'];
350 $page_writeable = can_write_wall($a,$profile_owner);
353 if($mode === 'community') {
355 $page_writeable = false;
359 $return_url = $_SESSION['return_url'];
361 $return_url = $_SESSION['return_url'] = $a->query_string;
363 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
364 call_hooks('conversation_start',$cb);
366 $items = $cb['items'];
368 $cmnt_tpl = get_markup_template('comment_item.tpl');
369 $tpl = 'wall_item.tpl';
370 $wallwall = 'wallwall_item.tpl';
371 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
373 $conv_responses = array(
374 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
375 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
379 // array with html for each thread (parent+comments)
383 if($items && count($items)) {
385 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
387 // "New Item View" on network page or search page results
388 // - just loop through the items and format them minimally for display
390 //$tpl = get_markup_template('search_item.tpl');
391 $tpl = 'search_item.tpl';
393 foreach($items as $item) {
402 if($mode === 'search' || $mode === 'community') {
403 if(((activity_match($item['verb'],ACTIVITY_LIKE))
404 || (activity_match($item['verb'],ACTIVITY_DISLIKE))
405 || activity_match($item['verb'],ACTIVITY_ATTEND)
406 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
407 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE))
408 && ($item['id'] != $item['parent']))
410 $nickname = $item['nickname'];
413 $nickname = $a->user['nickname'];
415 // prevent private email from leaking.
416 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
419 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
420 if($item['author-link'] && (! $item['author-name']))
421 $profile_name = $item['author-link'];
426 $profile_link = best_link_url($item,$sp);
427 if($profile_link === 'mailbox')
430 $sparkle = ' sparkle';
432 $profile_link = zrl($profile_link);
434 // Don't rely on the author-avatar. It is better to use the data from the contact table
435 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
436 if ($author_contact["thumb"])
437 $profile_avatar = $author_contact["thumb"];
439 $profile_avatar = $item['author-avatar'];
441 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
442 call_hooks('render_location',$locate);
444 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
446 localize_item($item);
447 if($mode === 'network-new')
454 'dropping' => $dropping,
455 'select' => t('Select'),
456 'delete' => t('Delete'),
460 $isstarred = "unstarred";
463 $likebuttons = false;
466 $body = prepare_body($item,true);
468 if($a->theme['template_engine'] === 'internal') {
469 $name_e = template_escape($profile_name);
470 $title_e = template_escape($item['title']);
471 $body_e = template_escape($body);
472 $text_e = strip_tags(template_escape($body));
473 $location_e = template_escape($location);
474 $owner_name_e = template_escape($owner_name);
477 $name_e = $profile_name;
478 $title_e = $item['title'];
480 $text_e = strip_tags($body);
481 $location_e = $location;
482 $owner_name_e = $owner_name;
485 //$tmp_item = replace_macros($tpl,array(
488 'id' => (($preview) ? 'P0' : $item['item_id']),
489 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
490 'profile_url' => $profile_link,
491 'item_photo_menu' => item_photo_menu($item),
493 'sparkle' => $sparkle,
495 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
499 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
500 'location' => $location_e,
502 'owner_name' => $owner_name_e,
503 'owner_url' => $owner_url,
504 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
505 'plink' => get_plink($item),
507 'isstarred' => $isstarred,
510 'vote' => $likebuttons,
514 //'conv' => (($preview) ? '' : array('href'=> System::baseUrl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
515 'conv' => (($preview) ? '' : array('href'=> System::baseUrl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
516 'previewing' => $previewing,
517 'wait' => t('Please wait'),
520 $arr = array('item' => $item, 'output' => $tmp_item);
521 call_hooks('display_item', $arr);
523 $threads[$threadsid]['id'] = $item['item_id'];
524 $threads[$threadsid]['items'] = array($arr['output']);
534 // Figure out how many comments each parent has
535 // (Comments all have gravity of 6)
536 // Store the result in the $comments array
539 foreach($items as $item) {
540 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
541 if(! x($comments,$item['parent']))
542 $comments[$item['parent']] = 1;
544 $comments[$item['parent']] += 1;
545 } elseif(! x($comments,$item['parent']))
546 $comments[$item['parent']] = 0; // avoid notices later on
549 // map all the like/dislike/attendance activities for each parent item
550 // Store these in the $alike and $dlike arrays
552 foreach($items as $item) {
553 builtin_activity_puller($item, $conv_responses);
556 $comments_collapsed = false;
558 $comment_lastcollapsed = false;
559 $comment_firstcollapsed = false;
564 foreach($items as $item) {
570 $owner_url = $owner_photo = $owner_name = '';
572 // We've already parsed out like/dislike for special treatment. We can ignore them now
574 if(((activity_match($item['verb'],ACTIVITY_LIKE))
575 || (activity_match($item['verb'],ACTIVITY_DISLIKE)
576 || activity_match($item['verb'],ACTIVITY_ATTEND)
577 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
578 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)))
579 && ($item['id'] != $item['parent']))
582 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
585 // Take care of author collapsing and comment collapsing
586 // (author collapsing is currently disabled)
587 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
588 // If there are more than two comments, squash all but the last 2.
592 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
595 $comments_collapsed = false;
596 $comment_lastcollapsed = false;
597 $comment_firstcollapsed = false;
600 $threads[$threadsid]['id'] = $item['item_id'];
601 $threads[$threadsid]['private'] = $item['private'];
602 $threads[$threadsid]['items'] = array();
607 // prevent private email reply to public conversation from leaking.
608 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
612 $comment_lastcollapsed = false;
613 $comment_firstcollapsed = false;
616 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
617 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
620 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
622 if (!$comments_collapsed){
623 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
624 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
625 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
626 $threads[$threadsid]['hide_text'] = t('show more');
627 $comments_collapsed = true;
628 $comment_firstcollapsed = true;
631 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
633 $comment_lastcollapsed = true;
636 $redirect_url = 'redir/' . $item['cid'] ;
638 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
639 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
640 ? t('Private Message')
644 // Top-level wall post not written by the wall owner (wall-to-wall)
645 // First figure out who owns it.
649 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
653 // On the network page, I am the owner. On the display page it will be the profile owner.
654 // This will have been stored in $a->page_contact by our calling page.
655 // Put this person as the wall owner of the wall-to-wall notice.
657 $owner_url = zrl($a->page_contact['url']);
658 $owner_photo = $a->page_contact['thumb'];
659 $owner_name = $a->page_contact['name'];
660 $template = $wallwall;
664 if((! $item['wall']) && $item['owner-link']) {
666 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
667 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
668 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
669 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
671 // The author url doesn't match the owner (typically the contact)
672 // and also doesn't match the contact alias.
673 // The name match is a hack to catch several weird cases where URLs are
674 // all over the park. It can be tricked, but this prevents you from
675 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
676 // well that it's the same Bob Smith.
678 // But it could be somebody else with the same name. It just isn't highly likely.
681 $owner_url = $item['owner-link'];
682 $owner_photo = $item['owner-avatar'];
683 $owner_name = $item['owner-name'];
684 $template = $wallwall;
686 // If it is our contact, use a friendly redirect link
687 if((link_compare($item['owner-link'],$item['url']))
688 && ($item['network'] === NETWORK_DFRN)) {
689 $owner_url = $redirect_url;
690 $osparkle = ' sparkle';
693 $owner_url = zrl($owner_url);
699 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
701 if($page_writeable) {
702 /* if($toplevelpost) { */
703 $likebuttons = array(
704 'like' => array( t("I like this \x28toggle\x29"), t("like")),
705 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
707 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
710 $qc = $qcomment = null;
712 if(in_array('qcomment',$a->plugins)) {
713 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
714 $qcomment = (($qc) ? explode("\n",$qc) : null);
717 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
718 $comment = replace_macros($cmnt_tpl,array(
719 '$return_path' => '',
720 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
721 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
722 '$id' => $item['item_id'],
723 '$parent' => $item['parent'],
724 '$qcomment' => $qcomment,
725 '$profile_uid' => $profile_owner,
726 '$mylink' => $a->contact['url'],
727 '$mytitle' => t('This is you'),
728 '$myphoto' => $a->contact['thumb'],
729 '$comment' => t('Comment'),
730 '$submit' => t('Submit'),
731 '$edbold' => t('Bold'),
732 '$editalic' => t('Italic'),
733 '$eduline' => t('Underline'),
734 '$edquote' => t('Quote'),
735 '$edcode' => t('Code'),
736 '$edimg' => t('Image'),
737 '$edurl' => t('Link'),
738 '$edvideo' => t('Video'),
739 '$preview' => t('Preview'),
740 '$sourceapp' => t($a->sourcename),
741 '$ww' => (($mode === 'network') ? $commentww : ''),
742 '$rand_num' => random_digits(12)
747 if (local_user() && link_compare($a->contact['url'],$item['author-link'])) {
748 $edpost = array(System::baseUrl($ssl_state)."/editpost/".$item['id'], t("Edit"));
756 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
760 'dropping' => $dropping,
761 'select' => t('Select'),
762 'delete' => t('Delete'),
768 $isstarred = "unstarred";
769 if ($profile_owner == local_user()) {
771 $isstarred = (($item['starred']) ? "starred" : "unstarred");
774 'do' => t("add star"),
775 'undo' => t("remove star"),
776 'toggle' => t("toggle star status"),
777 'classdo' => (($item['starred']) ? "hidden" : ""),
778 'classundo' => (($item['starred']) ? "" : "hidden"),
779 'starred' => t('starred'),
780 'tagger' => t("add tag"),
784 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
785 intval($item['uid']),
789 if (dbm::is_result($r)) {
791 'do' => t("ignore thread"),
792 'undo' => t("unignore thread"),
793 'toggle' => t("toggle ignore status"),
794 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
795 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
796 'ignored' => t('ignored'),
800 if (feature_enabled($profile_owner,'commtag')) {
802 'add' => t("add tag"),
807 $filer = t("save to folder");
811 $photo = $item['photo'];
812 $thumb = $item['thumb'];
814 // Post was remotely authored.
816 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
818 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
820 if($item['author-link'] && (! $item['author-name']))
821 $profile_name = $item['author-link'];
824 $profile_link = best_link_url($item,$sp);
825 if ($profile_link === 'mailbox') {
829 $sparkle = ' sparkle';
831 $profile_link = zrl($profile_link);
834 // Don't rely on the author-avatar. It is better to use the data from the contact table
835 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
836 if ($author_contact["thumb"]) {
837 $profile_avatar = $author_contact["thumb"];
839 $profile_avatar = $item['author-avatar'];
842 $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
843 $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
845 // process action responses - e.g. like/dislike/attend/agree/whatever
846 $response_verbs = array('like');
847 if(feature_enabled($profile_owner,'dislike'))
848 $response_verbs[] = 'dislike';
849 if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
850 $response_verbs[] = 'attendyes';
851 $response_verbs[] = 'attendno';
852 $response_verbs[] = 'attendmaybe';
853 if($page_writeable) {
855 $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
858 $responses = get_responses($conv_responses,$response_verbs,'',$item);
860 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
861 call_hooks('render_location',$locate);
863 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
865 $indent = (($toplevelpost) ? '' : ' comment');
868 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
872 localize_item($item);
876 foreach(explode(',',$item['tag']) as $tag){
878 if ($tag!="") $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);
896 $text_e = strip_tags($body);
897 $name_e = $profile_name;
898 $title_e = $item['title'];
899 $location_e = $location;
900 $owner_name_e = $owner_name;
904 // collapse comments in template. I don't like this much...
905 'comment_firstcollapsed' => $comment_firstcollapsed,
906 'comment_lastcollapsed' => $comment_lastcollapsed,
907 // template to use to render item (wall, walltowall, search)
908 'template' => $template,
910 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
914 'id' => $item['item_id'],
915 'isevent' => $isevent,
917 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
918 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
920 'wall' => t('Wall-to-Wall'),
921 'vwall' => t('via Wall-To-Wall:'),
922 'profile_url' => $profile_link,
923 'item_photo_menu' => item_photo_menu($item),
925 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
926 'osparkle' => $osparkle,
927 'sparkle' => $sparkle,
929 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
930 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
931 'app' => $item['app'],
932 'created' => relative_date($item['created']),
934 'location' => $location_e,
937 'owner_url' => $owner_url,
938 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
939 'owner_name' => $owner_name_e,
940 'plink' => get_plink($item),
942 'isstarred' => $isstarred,
944 'ignore' => ((feature_enabled($profile_owner,'ignore_posts')) ? $ignore : ''),
946 'filer' => ((feature_enabled($profile_owner,'filing')) ? $filer : ''),
948 'vote' => $likebuttons,
949 'responses' => $responses,
951 'dislike' => $dislike,
952 'switchcomment' => t('Comment'),
953 'comment' => $comment,
954 'previewing' => $previewing,
955 'wait' => t('Please wait'),
957 'network' => $item["item_network"],
958 'network_name' => network_to_name($item['network'], $profile_link),
963 $arr = array('item' => $item, 'output' => $tmp_item);
964 call_hooks('display_item', $arr);
966 $threads[$threadsid]['items'][] = $arr['output'];