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.
20 function content_content(App $a, $update = 0) {
22 require_once('include/conversation.php');
25 // Currently security is based on the logged in user
31 $arr = array('query' => $a->query_string);
33 call_hooks('content_content_init', $arr);
36 $datequery = $datequery2 = '';
43 for($x = 1; $x < $a->argc; $x ++) {
44 if(is_a_date_arg($a->argv[$x])) {
46 $datequery2 = escape_tags($a->argv[$x]);
48 $datequery = escape_tags($a->argv[$x]);
49 $_GET['order'] = 'post';
52 elseif($a->argv[$x] === 'new') {
55 elseif(intval($a->argv[$x])) {
56 $group = intval($a->argv[$x]);
57 $def_acl = array('allow_gid' => '<' . $group . '>');
67 $contact_id = $a->cid;
69 require_once('include/acl_selectors.php');
71 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
72 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
73 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
74 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
75 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
76 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
77 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
78 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
79 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
80 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
81 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
85 if(x($_GET,'search') || x($_GET,'file'))
88 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
91 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
97 if (dbm::is_result($r))
99 $str .= '<' . $rr['id'] . '>';
101 $def_acl = array('allow_cid' => $str);
105 $sql_options = (($star) ? " and starred = 1 " : '');
106 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
108 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
110 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
113 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
115 intval($_SESSION['uid'])
117 if (! dbm::is_result($r)) {
120 notice( t('No such group') . EOL );
121 goaway(App::get_baseurl(true) . '/network');
125 $contacts = expand_groups(array($group));
126 if((is_array($contacts)) && count($contacts)) {
127 $contact_str = implode(',',$contacts);
130 $contact_str = ' 0 ';
131 info( t('Group is empty'));
134 $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 ) ";
135 $o = replace_macros(get_markup_template("section_title.tpl"),array(
136 '$title' => sprintf( t('Group: %s'), $r[0]['name'])
141 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
142 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
145 if (dbm::is_result($r)) {
146 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
158 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
161 $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
164 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
165 $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
166 $sql_table = "`item`";
168 if(x($_GET,'search')) {
169 $search = escape_tags($_GET['search']);
171 if(strpos($search,'#') === 0) {
173 $search = substr($search,1);
176 if (get_config('system','only_tag_search'))
180 //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
181 // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
182 //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
185 $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` ",
186 dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
189 if (get_config('system','use_fulltext_engine'))
190 $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
192 $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
197 $sql_extra .= file_tag_file_query('item',unxmlify($file));
201 $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
202 $myurl = substr($myurl,strpos($myurl,'://')+3);
203 $myurl = str_replace('www.','',$myurl);
204 $diasp_url = str_replace('/profile/','/u/',$myurl);
206 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
207 dbesc(protect_sprintf($myurl)),
208 dbesc(protect_sprintf($myurl))
212 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
216 // "New Item View" - show all items unthreaded in reverse created date order
218 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
219 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
220 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
221 `contact`.`id` AS `cid`
222 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
223 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
224 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
226 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
228 ORDER BY `item`.`id` DESC $pager_sql ",
229 intval($_SESSION['uid'])
235 // Normal conversation view
238 if($order === 'post')
239 $ordering = "`created`";
241 $ordering = "`commented`";
243 $start = dba_timer();
245 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
246 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
247 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
248 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
249 AND `item`.`parent` = `item`.`id`
250 $sql_extra3 $sql_extra $sql_nets
251 ORDER BY `item`.$ordering DESC $pager_sql ",
255 $first = dba_timer();
258 // Then fetch all the children of the parents that are on this page
260 $parents_arr = array();
263 if (dbm::is_result($r)) {
265 if(! in_array($rr['item_id'],$parents_arr))
266 $parents_arr[] = $rr['item_id'];
267 $parents_str = implode(', ', $parents_arr);
269 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
270 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
271 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
272 `contact`.`id` AS `cid`
273 FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
274 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
275 AND `item`.`moderated` = 0
276 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
277 AND `item`.`parent` IN ( %s )
279 intval(local_user()),
283 $second = dba_timer();
285 $items = conv_sort($items,$ordering);
293 logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
294 logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
296 // Set this so that the conversation function can find out contact info for our wall-wall items
297 $a->page_contact = $a->contact;
299 $mode = (($nouveau) ? 'network-new' : 'network');
301 $o = render_content($a,$items,$mode,false);
304 header('Content-type: application/json');
305 echo json_encode($o);
311 function render_content(App $a, $items, $mode, $update, $preview = false) {
313 require_once('include/bbcode.php');
314 require_once('mod/proxy.php');
316 $ssl_state = ((local_user()) ? true : false);
319 $page_writeable = false;
321 $previewing = (($preview) ? ' preview ' : '');
324 if (strcmp($item['created'], $item['edited'])<>0) {
326 'label' => t('This entry was edited'),
327 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
328 'relative' => relative_date($item['edited'])
332 if($mode === 'network') {
333 $profile_owner = local_user();
334 $page_writeable = true;
337 if($mode === 'profile') {
338 $profile_owner = $a->profile['profile_uid'];
339 $page_writeable = can_write_wall($a,$profile_owner);
342 if($mode === 'notes') {
343 $profile_owner = local_user();
344 $page_writeable = true;
347 if($mode === 'display') {
348 $profile_owner = $a->profile['uid'];
349 $page_writeable = can_write_wall($a,$profile_owner);
352 if($mode === 'community') {
354 $page_writeable = false;
358 $return_url = $_SESSION['return_url'];
360 $return_url = $_SESSION['return_url'] = $a->query_string;
362 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
363 call_hooks('conversation_start',$cb);
365 $items = $cb['items'];
367 $cmnt_tpl = get_markup_template('comment_item.tpl');
368 $tpl = 'wall_item.tpl';
369 $wallwall = 'wallwall_item.tpl';
370 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
372 $conv_responses = array(
373 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
374 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
378 // array with html for each thread (parent+comments)
382 if($items && count($items)) {
384 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
386 // "New Item View" on network page or search page results
387 // - just loop through the items and format them minimally for display
389 //$tpl = get_markup_template('search_item.tpl');
390 $tpl = 'search_item.tpl';
392 foreach($items as $item) {
401 if($mode === 'search' || $mode === 'community') {
402 if(((activity_match($item['verb'],ACTIVITY_LIKE))
403 || (activity_match($item['verb'],ACTIVITY_DISLIKE))
404 || activity_match($item['verb'],ACTIVITY_ATTEND)
405 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
406 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE))
407 && ($item['id'] != $item['parent']))
409 $nickname = $item['nickname'];
412 $nickname = $a->user['nickname'];
414 // prevent private email from leaking.
415 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
418 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
419 if($item['author-link'] && (! $item['author-name']))
420 $profile_name = $item['author-link'];
425 $profile_link = best_link_url($item,$sp);
426 if($profile_link === 'mailbox')
429 $sparkle = ' sparkle';
431 $profile_link = zrl($profile_link);
433 // Don't rely on the author-avatar. It is better to use the data from the contact table
434 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
435 if ($author_contact["thumb"])
436 $profile_avatar = $author_contact["thumb"];
438 $profile_avatar = $item['author-avatar'];
440 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
441 call_hooks('render_location',$locate);
443 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
445 localize_item($item);
446 if($mode === 'network-new')
453 'dropping' => $dropping,
454 'select' => t('Select'),
455 'delete' => t('Delete'),
459 $isstarred = "unstarred";
462 $likebuttons = false;
465 $body = prepare_body($item,true);
467 if($a->theme['template_engine'] === 'internal') {
468 $name_e = template_escape($profile_name);
469 $title_e = template_escape($item['title']);
470 $body_e = template_escape($body);
471 $text_e = strip_tags(template_escape($body));
472 $location_e = template_escape($location);
473 $owner_name_e = template_escape($owner_name);
476 $name_e = $profile_name;
477 $title_e = $item['title'];
479 $text_e = strip_tags($body);
480 $location_e = $location;
481 $owner_name_e = $owner_name;
484 //$tmp_item = replace_macros($tpl,array(
487 'id' => (($preview) ? 'P0' : $item['item_id']),
488 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
489 'profile_url' => $profile_link,
490 'item_photo_menu' => item_photo_menu($item),
492 'sparkle' => $sparkle,
494 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
498 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
499 'location' => $location_e,
501 'owner_name' => $owner_name_e,
502 'owner_url' => $owner_url,
503 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
504 'plink' => get_plink($item),
506 'isstarred' => $isstarred,
509 'vote' => $likebuttons,
513 //'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
514 'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
515 'previewing' => $previewing,
516 'wait' => t('Please wait'),
519 $arr = array('item' => $item, 'output' => $tmp_item);
520 call_hooks('display_item', $arr);
522 $threads[$threadsid]['id'] = $item['item_id'];
523 $threads[$threadsid]['items'] = array($arr['output']);
533 // Figure out how many comments each parent has
534 // (Comments all have gravity of 6)
535 // Store the result in the $comments array
538 foreach($items as $item) {
539 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
540 if(! x($comments,$item['parent']))
541 $comments[$item['parent']] = 1;
543 $comments[$item['parent']] += 1;
544 } elseif(! x($comments,$item['parent']))
545 $comments[$item['parent']] = 0; // avoid notices later on
548 // map all the like/dislike/attendance activities for each parent item
549 // Store these in the $alike and $dlike arrays
551 foreach($items as $item) {
552 builtin_activity_puller($item, $conv_responses);
555 $comments_collapsed = false;
557 $comment_lastcollapsed = false;
558 $comment_firstcollapsed = false;
563 foreach($items as $item) {
569 $owner_url = $owner_photo = $owner_name = '';
571 // We've already parsed out like/dislike for special treatment. We can ignore them now
573 if(((activity_match($item['verb'],ACTIVITY_LIKE))
574 || (activity_match($item['verb'],ACTIVITY_DISLIKE)
575 || activity_match($item['verb'],ACTIVITY_ATTEND)
576 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
577 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)))
578 && ($item['id'] != $item['parent']))
581 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
584 // Take care of author collapsing and comment collapsing
585 // (author collapsing is currently disabled)
586 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
587 // If there are more than two comments, squash all but the last 2.
591 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
594 $comments_collapsed = false;
595 $comment_lastcollapsed = false;
596 $comment_firstcollapsed = false;
599 $threads[$threadsid]['id'] = $item['item_id'];
600 $threads[$threadsid]['private'] = $item['private'];
601 $threads[$threadsid]['items'] = array();
606 // prevent private email reply to public conversation from leaking.
607 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
611 $comment_lastcollapsed = false;
612 $comment_firstcollapsed = false;
615 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
616 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
619 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
621 if (!$comments_collapsed){
622 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
623 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
624 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
625 $threads[$threadsid]['hide_text'] = t('show more');
626 $comments_collapsed = true;
627 $comment_firstcollapsed = true;
630 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
632 $comment_lastcollapsed = true;
635 $redirect_url = 'redir/' . $item['cid'] ;
637 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
638 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
639 ? t('Private Message')
643 // Top-level wall post not written by the wall owner (wall-to-wall)
644 // First figure out who owns it.
648 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
652 // On the network page, I am the owner. On the display page it will be the profile owner.
653 // This will have been stored in $a->page_contact by our calling page.
654 // Put this person as the wall owner of the wall-to-wall notice.
656 $owner_url = zrl($a->page_contact['url']);
657 $owner_photo = $a->page_contact['thumb'];
658 $owner_name = $a->page_contact['name'];
659 $template = $wallwall;
663 if((! $item['wall']) && $item['owner-link']) {
665 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
666 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
667 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
668 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
670 // The author url doesn't match the owner (typically the contact)
671 // and also doesn't match the contact alias.
672 // The name match is a hack to catch several weird cases where URLs are
673 // all over the park. It can be tricked, but this prevents you from
674 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
675 // well that it's the same Bob Smith.
677 // But it could be somebody else with the same name. It just isn't highly likely.
680 $owner_url = $item['owner-link'];
681 $owner_photo = $item['owner-avatar'];
682 $owner_name = $item['owner-name'];
683 $template = $wallwall;
685 // If it is our contact, use a friendly redirect link
686 if((link_compare($item['owner-link'],$item['url']))
687 && ($item['network'] === NETWORK_DFRN)) {
688 $owner_url = $redirect_url;
689 $osparkle = ' sparkle';
692 $owner_url = zrl($owner_url);
698 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
700 if($page_writeable) {
701 /* if($toplevelpost) { */
702 $likebuttons = array(
703 'like' => array( t("I like this \x28toggle\x29"), t("like")),
704 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
706 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
709 $qc = $qcomment = null;
711 if(in_array('qcomment',$a->plugins)) {
712 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
713 $qcomment = (($qc) ? explode("\n",$qc) : null);
716 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
717 $comment = replace_macros($cmnt_tpl,array(
718 '$return_path' => '',
719 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
720 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
721 '$id' => $item['item_id'],
722 '$parent' => $item['parent'],
723 '$qcomment' => $qcomment,
724 '$profile_uid' => $profile_owner,
725 '$mylink' => $a->contact['url'],
726 '$mytitle' => t('This is you'),
727 '$myphoto' => $a->contact['thumb'],
728 '$comment' => t('Comment'),
729 '$submit' => t('Submit'),
730 '$edbold' => t('Bold'),
731 '$editalic' => t('Italic'),
732 '$eduline' => t('Underline'),
733 '$edquote' => t('Quote'),
734 '$edcode' => t('Code'),
735 '$edimg' => t('Image'),
736 '$edurl' => t('Link'),
737 '$edvideo' => t('Video'),
738 '$preview' => t('Preview'),
739 '$sourceapp' => t($a->sourcename),
740 '$ww' => (($mode === 'network') ? $commentww : ''),
741 '$rand_num' => random_digits(12)
746 if (local_user() && link_compare($a->contact['url'],$item['author-link'])) {
747 $edpost = array(App::get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
755 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
759 'dropping' => $dropping,
760 'select' => t('Select'),
761 'delete' => t('Delete'),
767 $isstarred = "unstarred";
768 if ($profile_owner == local_user()) {
770 $isstarred = (($item['starred']) ? "starred" : "unstarred");
773 'do' => t("add star"),
774 'undo' => t("remove star"),
775 'toggle' => t("toggle star status"),
776 'classdo' => (($item['starred']) ? "hidden" : ""),
777 'classundo' => (($item['starred']) ? "" : "hidden"),
778 'starred' => t('starred'),
779 'tagger' => t("add tag"),
783 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
784 intval($item['uid']),
788 if (dbm::is_result($r)) {
790 'do' => t("ignore thread"),
791 'undo' => t("unignore thread"),
792 'toggle' => t("toggle ignore status"),
793 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
794 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
795 'ignored' => t('ignored'),
799 if (feature_enabled($profile_owner,'commtag')) {
801 'add' => t("add tag"),
806 $filer = t("save to folder");
810 $photo = $item['photo'];
811 $thumb = $item['thumb'];
813 // Post was remotely authored.
815 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
817 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
819 if($item['author-link'] && (! $item['author-name']))
820 $profile_name = $item['author-link'];
823 $profile_link = best_link_url($item,$sp);
824 if ($profile_link === 'mailbox') {
828 $sparkle = ' sparkle';
830 $profile_link = zrl($profile_link);
833 // Don't rely on the author-avatar. It is better to use the data from the contact table
834 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
835 if ($author_contact["thumb"]) {
836 $profile_avatar = $author_contact["thumb"];
838 $profile_avatar = $item['author-avatar'];
841 $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
842 $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
844 // process action responses - e.g. like/dislike/attend/agree/whatever
845 $response_verbs = array('like');
846 if(feature_enabled($profile_owner,'dislike'))
847 $response_verbs[] = 'dislike';
848 if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
849 $response_verbs[] = 'attendyes';
850 $response_verbs[] = 'attendno';
851 $response_verbs[] = 'attendmaybe';
852 if($page_writeable) {
854 $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
857 $responses = get_responses($conv_responses,$response_verbs,'',$item);
859 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
860 call_hooks('render_location',$locate);
862 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
864 $indent = (($toplevelpost) ? '' : ' comment');
867 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
871 localize_item($item);
875 foreach(explode(',',$item['tag']) as $tag){
877 if ($tag!="") $tags[] = bbcode($tag);
882 $body = prepare_body($item,true);
883 //$tmp_item = replace_macros($template,
885 if($a->theme['template_engine'] === 'internal') {
886 $body_e = template_escape($body);
887 $text_e = strip_tags(template_escape($body));
888 $name_e = template_escape($profile_name);
889 $title_e = template_escape($item['title']);
890 $location_e = template_escape($location);
891 $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'];