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",
96 if (dbm::is_result($r))
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'])
116 if (! dbm::is_result($r)) {
119 notice( t('No such group') . EOL );
120 goaway(App::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",
144 if (dbm::is_result($r)) {
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 = App::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`
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`.`id` 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();
262 if (dbm::is_result($r)) {
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`
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 ' : '');
323 if (strcmp($item['created'], $item['edited'])<>0) {
325 'label' => t('This entry was edited'),
326 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
327 'relative' => relative_date($item['edited'])
331 if($mode === 'network') {
332 $profile_owner = local_user();
333 $page_writeable = true;
336 if($mode === 'profile') {
337 $profile_owner = $a->profile['profile_uid'];
338 $page_writeable = can_write_wall($a,$profile_owner);
341 if($mode === 'notes') {
342 $profile_owner = local_user();
343 $page_writeable = true;
346 if($mode === 'display') {
347 $profile_owner = $a->profile['uid'];
348 $page_writeable = can_write_wall($a,$profile_owner);
351 if($mode === 'community') {
353 $page_writeable = false;
357 $return_url = $_SESSION['return_url'];
359 $return_url = $_SESSION['return_url'] = $a->query_string;
361 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
362 call_hooks('conversation_start',$cb);
364 $items = $cb['items'];
366 $cmnt_tpl = get_markup_template('comment_item.tpl');
367 $tpl = 'wall_item.tpl';
368 $wallwall = 'wallwall_item.tpl';
369 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
371 $conv_responses = array(
372 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
373 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
377 // array with html for each thread (parent+comments)
381 if($items && count($items)) {
383 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
385 // "New Item View" on network page or search page results
386 // - just loop through the items and format them minimally for display
388 //$tpl = get_markup_template('search_item.tpl');
389 $tpl = 'search_item.tpl';
391 foreach($items as $item) {
400 if($mode === 'search' || $mode === 'community') {
401 if(((activity_match($item['verb'],ACTIVITY_LIKE))
402 || (activity_match($item['verb'],ACTIVITY_DISLIKE))
403 || activity_match($item['verb'],ACTIVITY_ATTEND)
404 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
405 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE))
406 && ($item['id'] != $item['parent']))
408 $nickname = $item['nickname'];
411 $nickname = $a->user['nickname'];
413 // prevent private email from leaking.
414 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
417 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
418 if($item['author-link'] && (! $item['author-name']))
419 $profile_name = $item['author-link'];
424 $profile_link = best_link_url($item,$sp);
425 if($profile_link === 'mailbox')
428 $sparkle = ' sparkle';
430 $profile_link = zrl($profile_link);
432 // Don't rely on the author-avatar. It is better to use the data from the contact table
433 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
434 if ($author_contact["thumb"])
435 $profile_avatar = $author_contact["thumb"];
437 $profile_avatar = $item['author-avatar'];
439 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
440 call_hooks('render_location',$locate);
442 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
444 localize_item($item);
445 if($mode === 'network-new')
452 'dropping' => $dropping,
453 'select' => t('Select'),
454 'delete' => t('Delete'),
458 $isstarred = "unstarred";
461 $likebuttons = false;
464 $body = prepare_body($item,true);
466 if($a->theme['template_engine'] === 'internal') {
467 $name_e = template_escape($profile_name);
468 $title_e = template_escape($item['title']);
469 $body_e = template_escape($body);
470 $text_e = strip_tags(template_escape($body));
471 $location_e = template_escape($location);
472 $owner_name_e = template_escape($owner_name);
475 $name_e = $profile_name;
476 $title_e = $item['title'];
478 $text_e = strip_tags($body);
479 $location_e = $location;
480 $owner_name_e = $owner_name;
483 //$tmp_item = replace_macros($tpl,array(
486 'id' => (($preview) ? 'P0' : $item['item_id']),
487 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
488 'profile_url' => $profile_link,
489 'item_photo_menu' => item_photo_menu($item),
491 'sparkle' => $sparkle,
493 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
497 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
498 'location' => $location_e,
500 'owner_name' => $owner_name_e,
501 'owner_url' => $owner_url,
502 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
503 'plink' => get_plink($item),
505 'isstarred' => $isstarred,
508 'vote' => $likebuttons,
512 //'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
513 'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
514 'previewing' => $previewing,
515 'wait' => t('Please wait'),
518 $arr = array('item' => $item, 'output' => $tmp_item);
519 call_hooks('display_item', $arr);
521 $threads[$threadsid]['id'] = $item['item_id'];
522 $threads[$threadsid]['items'] = array($arr['output']);
532 // Figure out how many comments each parent has
533 // (Comments all have gravity of 6)
534 // Store the result in the $comments array
537 foreach($items as $item) {
538 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
539 if(! x($comments,$item['parent']))
540 $comments[$item['parent']] = 1;
542 $comments[$item['parent']] += 1;
543 } elseif(! x($comments,$item['parent']))
544 $comments[$item['parent']] = 0; // avoid notices later on
547 // map all the like/dislike/attendance activities for each parent item
548 // Store these in the $alike and $dlike arrays
550 foreach($items as $item) {
551 builtin_activity_puller($item, $conv_responses);
554 $comments_collapsed = false;
556 $comment_lastcollapsed = false;
557 $comment_firstcollapsed = false;
562 foreach($items as $item) {
568 $owner_url = $owner_photo = $owner_name = '';
570 // We've already parsed out like/dislike for special treatment. We can ignore them now
572 if(((activity_match($item['verb'],ACTIVITY_LIKE))
573 || (activity_match($item['verb'],ACTIVITY_DISLIKE)
574 || activity_match($item['verb'],ACTIVITY_ATTEND)
575 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
576 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)))
577 && ($item['id'] != $item['parent']))
580 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
583 // Take care of author collapsing and comment collapsing
584 // (author collapsing is currently disabled)
585 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
586 // If there are more than two comments, squash all but the last 2.
590 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
593 $comments_collapsed = false;
594 $comment_lastcollapsed = false;
595 $comment_firstcollapsed = false;
598 $threads[$threadsid]['id'] = $item['item_id'];
599 $threads[$threadsid]['private'] = $item['private'];
600 $threads[$threadsid]['items'] = array();
605 // prevent private email reply to public conversation from leaking.
606 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
610 $comment_lastcollapsed = false;
611 $comment_firstcollapsed = false;
614 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
615 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
618 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
620 if (!$comments_collapsed){
621 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
622 $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
623 $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
624 $threads[$threadsid]['hide_text'] = t('show more');
625 $comments_collapsed = true;
626 $comment_firstcollapsed = true;
629 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
631 $comment_lastcollapsed = true;
634 $redirect_url = 'redir/' . $item['cid'] ;
636 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
637 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
638 ? t('Private Message')
642 // Top-level wall post not written by the wall owner (wall-to-wall)
643 // First figure out who owns it.
647 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
651 // On the network page, I am the owner. On the display page it will be the profile owner.
652 // This will have been stored in $a->page_contact by our calling page.
653 // Put this person as the wall owner of the wall-to-wall notice.
655 $owner_url = zrl($a->page_contact['url']);
656 $owner_photo = $a->page_contact['thumb'];
657 $owner_name = $a->page_contact['name'];
658 $template = $wallwall;
662 if((! $item['wall']) && $item['owner-link']) {
664 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
665 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
666 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
667 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
669 // The author url doesn't match the owner (typically the contact)
670 // and also doesn't match the contact alias.
671 // The name match is a hack to catch several weird cases where URLs are
672 // all over the park. It can be tricked, but this prevents you from
673 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
674 // well that it's the same Bob Smith.
676 // But it could be somebody else with the same name. It just isn't highly likely.
679 $owner_url = $item['owner-link'];
680 $owner_photo = $item['owner-avatar'];
681 $owner_name = $item['owner-name'];
682 $template = $wallwall;
684 // If it is our contact, use a friendly redirect link
685 if((link_compare($item['owner-link'],$item['url']))
686 && ($item['network'] === NETWORK_DFRN)) {
687 $owner_url = $redirect_url;
688 $osparkle = ' sparkle';
691 $owner_url = zrl($owner_url);
697 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
699 if($page_writeable) {
700 /* if($toplevelpost) { */
701 $likebuttons = array(
702 'like' => array( t("I like this \x28toggle\x29"), t("like")),
703 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
705 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
708 $qc = $qcomment = null;
710 if(in_array('qcomment',$a->plugins)) {
711 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
712 $qcomment = (($qc) ? explode("\n",$qc) : null);
715 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
716 $comment = replace_macros($cmnt_tpl,array(
717 '$return_path' => '',
718 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
719 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
720 '$id' => $item['item_id'],
721 '$parent' => $item['parent'],
722 '$qcomment' => $qcomment,
723 '$profile_uid' => $profile_owner,
724 '$mylink' => $a->contact['url'],
725 '$mytitle' => t('This is you'),
726 '$myphoto' => $a->contact['thumb'],
727 '$comment' => t('Comment'),
728 '$submit' => t('Submit'),
729 '$edbold' => t('Bold'),
730 '$editalic' => t('Italic'),
731 '$eduline' => t('Underline'),
732 '$edquote' => t('Quote'),
733 '$edcode' => t('Code'),
734 '$edimg' => t('Image'),
735 '$edurl' => t('Link'),
736 '$edvideo' => t('Video'),
737 '$preview' => t('Preview'),
738 '$sourceapp' => t($a->sourcename),
739 '$ww' => (($mode === 'network') ? $commentww : ''),
740 '$rand_num' => random_digits(12)
745 if (local_user() && link_compare($a->contact['url'],$item['author-link'])) {
746 $edpost = array(App::get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
754 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
758 'dropping' => $dropping,
759 'select' => t('Select'),
760 'delete' => t('Delete'),
766 $isstarred = "unstarred";
767 if ($profile_owner == local_user()) {
769 $isstarred = (($item['starred']) ? "starred" : "unstarred");
772 'do' => t("add star"),
773 'undo' => t("remove star"),
774 'toggle' => t("toggle star status"),
775 'classdo' => (($item['starred']) ? "hidden" : ""),
776 'classundo' => (($item['starred']) ? "" : "hidden"),
777 'starred' => t('starred'),
778 'tagger' => t("add tag"),
782 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
783 intval($item['uid']),
787 if (dbm::is_result($r)) {
789 'do' => t("ignore thread"),
790 'undo' => t("unignore thread"),
791 'toggle' => t("toggle ignore status"),
792 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
793 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
794 'ignored' => t('ignored'),
798 if (feature_enabled($profile_owner,'commtag')) {
800 'add' => t("add tag"),
805 $filer = t("save to folder");
809 $photo = $item['photo'];
810 $thumb = $item['thumb'];
812 // Post was remotely authored.
814 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
816 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
818 if($item['author-link'] && (! $item['author-name']))
819 $profile_name = $item['author-link'];
822 $profile_link = best_link_url($item,$sp);
823 if ($profile_link === 'mailbox') {
827 $sparkle = ' sparkle';
829 $profile_link = zrl($profile_link);
832 // Don't rely on the author-avatar. It is better to use the data from the contact table
833 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
834 if ($author_contact["thumb"]) {
835 $profile_avatar = $author_contact["thumb"];
837 $profile_avatar = $item['author-avatar'];
840 $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
841 $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
843 // process action responses - e.g. like/dislike/attend/agree/whatever
844 $response_verbs = array('like');
845 if(feature_enabled($profile_owner,'dislike'))
846 $response_verbs[] = 'dislike';
847 if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
848 $response_verbs[] = 'attendyes';
849 $response_verbs[] = 'attendno';
850 $response_verbs[] = 'attendmaybe';
851 if($page_writeable) {
853 $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
856 $responses = get_responses($conv_responses,$response_verbs,'',$item);
858 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
859 call_hooks('render_location',$locate);
861 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
863 $indent = (($toplevelpost) ? '' : ' comment');
866 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){
876 if ($tag!="") $tags[] = bbcode($tag);
881 $body = prepare_body($item,true);
882 //$tmp_item = replace_macros($template,
884 if($a->theme['template_engine'] === 'internal') {
885 $body_e = template_escape($body);
886 $text_e = strip_tags(template_escape($body));
887 $name_e = template_escape($profile_name);
888 $title_e = template_escape($item['title']);
889 $location_e = template_escape($location);
890 $owner_name_e = template_escape($owner_name);
894 $text_e = strip_tags($body);
895 $name_e = $profile_name;
896 $title_e = $item['title'];
897 $location_e = $location;
898 $owner_name_e = $owner_name;
902 // collapse comments in template. I don't like this much...
903 'comment_firstcollapsed' => $comment_firstcollapsed,
904 'comment_lastcollapsed' => $comment_lastcollapsed,
905 // template to use to render item (wall, walltowall, search)
906 'template' => $template,
908 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
912 'id' => $item['item_id'],
913 'isevent' => $isevent,
915 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
916 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
918 'wall' => t('Wall-to-Wall'),
919 'vwall' => t('via Wall-To-Wall:'),
920 'profile_url' => $profile_link,
921 'item_photo_menu' => item_photo_menu($item),
923 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
924 'osparkle' => $osparkle,
925 'sparkle' => $sparkle,
927 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
928 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
929 'app' => $item['app'],
930 'created' => relative_date($item['created']),
932 'location' => $location_e,
935 'owner_url' => $owner_url,
936 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
937 'owner_name' => $owner_name_e,
938 'plink' => get_plink($item),
940 'isstarred' => $isstarred,
942 'ignore' => ((feature_enabled($profile_owner,'ignore_posts')) ? $ignore : ''),
944 'filer' => ((feature_enabled($profile_owner,'filing')) ? $filer : ''),
946 'vote' => $likebuttons,
947 'responses' => $responses,
949 'dislike' => $dislike,
950 'switchcomment' => t('Comment'),
951 'comment' => $comment,
952 'previewing' => $previewing,
953 'wait' => t('Please wait'),
955 'network' => $item["item_network"],
956 'network_name' => network_to_name($item['network'], $profile_link),
961 $arr = array('item' => $item, 'output' => $tmp_item);
962 call_hooks('display_item', $arr);
964 $threads[$threadsid]['items'][] = $arr['output'];