3 require_once("include/bbcode.php");
4 require_once("include/acl_selectors.php");
7 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
8 // is identical to the code in mod/message.php for 'item_extract_images' and
9 // 'item_redir_and_replace_images'
10 if(! function_exists('item_extract_images')) {
11 function item_extract_images($body) {
13 $saved_image = array();
18 $img_start = strpos($orig_body, '[img');
19 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
20 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
21 while(($img_st_close !== false) && ($img_end !== false)) {
23 $img_st_close++; // make it point to AFTER the closing bracket
24 $img_end += $img_start;
26 if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
27 // This is an embedded image
29 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
30 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
35 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
37 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
39 if($orig_body === false) // in case the body ends on a closing image tag
42 $img_start = strpos($orig_body, '[img');
43 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
44 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
47 $new_body = $new_body . $orig_body;
49 return array('body' => $new_body, 'images' => $saved_image);
52 if(! function_exists('item_redir_and_replace_images')) {
53 function item_redir_and_replace_images($body, $images, $cid) {
59 $pos = get_bb_tag_pos($origbody, 'url', 1);
60 while($pos !== false && $cnt < 1000) {
62 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
63 $replace = '[url=' . z_path() . '/redir/' . $cid
64 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
66 $newbody .= substr($origbody, 0, $pos['start']['open']);
67 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
68 $origbody = substr($origbody, $pos['end']['close']);
69 if($origbody === false)
72 $subject = preg_replace($search, $replace, $subject);
76 $pos = get_bb_tag_pos($origbody, 'url', 1);
78 $newbody .= $origbody;
81 foreach($images as $image) {
82 // We're depending on the property of 'foreach' (specified on the PHP website) that
83 // it loops over the array starting from the first element and going sequentially
84 // to the last element
85 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
94 * Render actions localized
96 function localize_item(&$item){
98 $extracted = item_extract_images($item['body']);
99 if($extracted['images'])
100 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
102 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
103 if (activity_match($item['verb'],ACTIVITY_LIKE)
104 || activity_match($item['verb'],ACTIVITY_DISLIKE)
105 || activity_match($item['verb'],ACTIVITY_ATTEND)
106 || activity_match($item['verb'],ACTIVITY_ATTENDNO)
107 || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)){
109 $r = q("SELECT * from `item`,`contact` WHERE
110 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
111 dbesc($item['parent-uri']));
112 if(count($r)==0) return;
115 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
116 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
118 switch($obj['verb']){
120 switch ($obj['object-type']){
121 case ACTIVITY_OBJ_EVENT:
122 $post_type = t('event');
125 $post_type = t('status');
129 if($obj['resource-id']){
130 $post_type = t('photo');
131 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
132 $rr['plink'] = $m[1];
134 $post_type = t('status');
138 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
140 if(activity_match($item['verb'],ACTIVITY_LIKE)) {
141 $bodyverb = t('%1$s likes %2$s\'s %3$s');
143 elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) {
144 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
146 elseif(activity_match($item['verb'],ACTIVITY_ATTEND)) {
147 $bodyverb = t('%1$s attends %2$s\'s %3$s');
149 elseif(activity_match($item['verb'],ACTIVITY_ATTENDNO)) {
150 $bodyverb = t('%1$s doesn\'t attend %2$s\'s %3$s');
152 elseif(activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)) {
153 $bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
155 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
158 if (activity_match($item['verb'],ACTIVITY_FRIEND)) {
160 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
162 $Aname = $item['author-name'];
163 $Alink = $item['author-link'];
165 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
167 $obj = parse_xml_string($xmlhead.$item['object']);
168 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
170 $Bname = $obj->title;
171 $Blink = ""; $Bphoto = "";
172 foreach ($links->link as $l){
173 $atts = $l->attributes();
174 switch($atts['rel']){
175 case "alternate": $Blink = $atts['href'];
176 case "photo": $Bphoto = $atts['href'];
181 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
182 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
183 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
185 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
188 if (stristr($item['verb'],ACTIVITY_POKE)) {
189 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
192 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
194 $Aname = $item['author-name'];
195 $Alink = $item['author-link'];
197 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
199 $obj = parse_xml_string($xmlhead.$item['object']);
200 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
202 $Bname = $obj->title;
203 $Blink = ""; $Bphoto = "";
204 foreach ($links->link as $l){
205 $atts = $l->attributes();
206 switch($atts['rel']){
207 case "alternate": $Blink = $atts['href'];
208 case "photo": $Bphoto = $atts['href'];
213 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
214 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
215 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
217 // we can't have a translation string with three positions but no distinguishable text
218 // So here is the translate string.
219 $txt = t('%1$s poked %2$s');
221 // now translate the verb
222 $poked_t = trim(sprintf($txt, "",""));
223 $txt = str_replace( $poked_t, t($verb), $txt);
225 // then do the sprintf on the translation string
227 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
230 if (stristr($item['verb'],ACTIVITY_MOOD)) {
231 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
235 $Aname = $item['author-name'];
236 $Alink = $item['author-link'];
237 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
239 $txt = t('%1$s is currently %2$s');
241 $item['body'] = sprintf($txt, $A, t($verb));
244 if (activity_match($item['verb'],ACTIVITY_TAG)) {
245 $r = q("SELECT * from `item`,`contact` WHERE
246 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
247 dbesc($item['parent-uri']));
248 if(count($r)==0) return;
251 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
252 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
254 switch($obj['verb']){
256 switch ($obj['object-type']){
257 case ACTIVITY_OBJ_EVENT:
258 $post_type = t('event');
261 $post_type = t('status');
265 if($obj['resource-id']){
266 $post_type = t('photo');
267 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
268 $rr['plink'] = $m[1];
270 $post_type = t('status');
273 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
275 $parsedobj = parse_xml_string($xmlhead.$item['object']);
277 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
278 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
281 if (activity_match($item['verb'],ACTIVITY_FAVORITE)){
283 if ($item['object-type']== "")
286 $Aname = $item['author-name'];
287 $Alink = $item['author-link'];
289 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
291 $obj = parse_xml_string($xmlhead.$item['object']);
292 if(strlen($obj->id)) {
293 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
297 if(count($r) && $r[0]['plink']) {
299 $Bname = $target['author-name'];
300 $Blink = $target['author-link'];
301 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
302 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
303 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
304 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
310 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
311 foreach($matches as $mtch) {
312 if(! strpos($mtch[1],'zrl='))
313 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
317 // add zrl's to public images
318 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
319 if(preg_match($photo_pattern,$item['body'])) {
320 $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
321 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
324 // add sparkle links to appropriate permalinks
326 $x = stristr($item['plink'],'/display/');
329 $y = best_link_url($item,$sparkle,true);
330 if(strstr($y,'/redir/'))
331 $item['plink'] = $y . '?f=&url=' . $item['plink'];
339 * Count the total of comments on this item and its desendants
341 function count_descendants($item) {
342 $total = count($item['children']);
345 foreach($item['children'] as $child) {
346 if(! visible_activity($child))
348 $total += count_descendants($child);
355 function visible_activity($item) {
357 // likes (etc.) can apply to other things besides posts. Check if they are post children,
358 // in which case we handle them specially
360 $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
361 foreach($hidden_activities as $act) {
362 if(activity_match($item['verb'],$act)) {
367 if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
368 if(! (($item['self']) && ($item['uid'] == local_user()))) {
377 * @brief List of all contact fields that are needed for the conversation function
379 function contact_fieldlist() {
381 $fieldlist = "`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
382 `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`";
388 * @brief SQL condition for contacts
390 function contact_condition() {
392 $condition = "NOT `contact`.`blocked` AND NOT `contact`.`pending`";
398 * @brief SQL condition for items
400 function item_condition() {
402 $condition = "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
408 * @brief List of all item fields that are needed for the conversation function
410 function item_fieldlist() {
412 $fieldlist = "`item`.`author-link`, `item`.`verb`, `item`.`id`, `item`.`parent`,
413 `item`.`uid`, `item`.`author-name`, `item`.`tag`, `item`.`location`, `item`.`coord`,
414 `item`.`title`, `item`.`uri`, `item`.`created`, `item`.`app`, `item`.`guid`,
415 `item`.`contact-id`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`rendered-hash`,
416 `item`.`body`, `item`.`rendered-html`, `item`.`private`, `item`.`edited`,
417 `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
418 `item`.`event-id`, `item`.`object-type`, `item`.`starred`, `item`.`created`,
419 `item`.`postopts`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
420 `item`.`plink`, `item`.`wall`,
421 `item`.`id` AS `item_id`, `item`.`network` AS `item_network`";
427 * "Render" a conversation or list of items for HTML display.
428 * There are two major forms of display:
429 * - Sequential or unthreaded ("New Item View" or search results)
430 * - conversation view
431 * The $mode parameter decides between the various renderings and also
432 * figures out how to determine page owner and other contextual items
433 * that are based on unique features of the calling module.
437 if(!function_exists('conversation')) {
438 function conversation(&$a, $items, $mode, $update, $preview = false) {
440 require_once('include/bbcode.php');
441 require_once('include/Contact.php');
442 require_once('mod/proxy.php');
444 $ssl_state = ((local_user()) ? true : false);
447 $page_writeable = false;
448 $live_update_div = '';
453 $str_blocked = get_pconfig(local_user(),'system','blocked');
455 $arr_blocked = explode(',',$str_blocked);
456 for($x = 0; $x < count($arr_blocked); $x ++)
457 $arr_blocked[$x] = trim($arr_blocked[$x]);
462 $previewing = (($preview) ? ' preview ' : '');
464 if($mode === 'network') {
465 $profile_owner = local_user();
466 $page_writeable = true;
468 // The special div is needed for liveUpdate to kick in for this page.
469 // We only launch liveUpdate if you aren't filtering in some incompatible
470 // way and also you aren't writing a comment (discovered in javascript).
472 $live_update_div = '<div id="live-network"></div>' . "\r\n"
473 . "<script> var profile_uid = " . $_SESSION['uid']
474 . "; var netargs = '" . substr($a->cmd,8)
476 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
477 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
478 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
479 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
480 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
481 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
482 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
483 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
484 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
485 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
486 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
487 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
489 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
492 else if($mode === 'profile') {
493 $profile_owner = $a->profile['profile_uid'];
494 $page_writeable = can_write_wall($a,$profile_owner);
497 $tab = notags(trim($_GET['tab']));
498 $tab = ( $tab ? $tab : 'posts' );
499 if($tab === 'posts') {
500 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
501 // because browser prefetching might change it on us. We have to deliver it with the page.
503 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
504 . "<script> var profile_uid = " . $a->profile['profile_uid']
505 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
509 else if($mode === 'notes') {
510 $profile_owner = local_user();
511 $page_writeable = true;
513 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
514 . "<script> var profile_uid = " . local_user()
515 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
518 else if($mode === 'display') {
519 $profile_owner = $a->profile['uid'];
520 $page_writeable = can_write_wall($a,$profile_owner);
522 $live_update_div = '<div id="live-display"></div>' . "\r\n"
523 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
524 . " var profile_page = 1; </script>";
527 else if($mode === 'community') {
529 $page_writeable = false;
531 $live_update_div = '<div id="live-community"></div>' . "\r\n"
532 . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
535 else if($mode === 'search') {
536 $live_update_div = '<div id="live-search"></div>' . "\r\n";
539 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
543 $return_url = $_SESSION['return_url'];
545 $return_url = $_SESSION['return_url'] = $a->query_string;
547 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
548 call_hooks('conversation_start',$cb);
550 $items = $cb['items'];
552 $cmnt_tpl = get_markup_template('comment_item.tpl');
553 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
555 $conv_responses = array(
556 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
557 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
560 // array with html for each thread (parent+comments)
564 $page_template = get_markup_template("conversation.tpl");
566 if($items && count($items)) {
568 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
570 // "New Item View" on network page or search page results
571 // - just loop through the items and format them minimally for display
573 // $tpl = get_markup_template('search_item.tpl');
574 $tpl = 'search_item.tpl';
576 foreach($items as $item) {
580 foreach($arr_blocked as $b) {
581 if($b && link_compare($item['author-link'],$b)) {
599 if($mode === 'search' || $mode === 'community') {
600 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
601 && ($item['id'] != $item['parent']))
603 $nickname = $item['nickname'];
606 $nickname = $a->user['nickname'];
608 // prevent private email from leaking.
609 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
612 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
613 if($item['author-link'] && (! $item['author-name']))
614 $profile_name = $item['author-link'];
622 $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
623 intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
625 foreach($taglist as $tag) {
627 if ($tag["url"] == "")
628 $tag["url"] = $searchpath.strtolower($tag["term"]);
630 if ($tag["type"] == TERM_HASHTAG) {
631 $hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
633 } elseif ($tag["type"] == TERM_MENTION) {
634 $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
637 $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
640 /*foreach(explode(',',$item['tag']) as $tag){
653 $profile_link = best_link_url($item,$sp);
654 if($profile_link === 'mailbox')
657 $sparkle = ' sparkle';
659 $profile_link = zrl($profile_link);
661 // Don't rely on the author-avatar. It is better to use the data from the contact table
662 $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
663 if ($author_contact["thumb"])
664 $profile_avatar = $author_contact["thumb"];
666 $profile_avatar = $item['author-avatar'];
668 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
669 call_hooks('render_location',$locate);
671 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
673 localize_item($item);
674 if($mode === 'network-new')
681 'dropping' => $dropping,
682 'pagedrop' => $page_dropping,
683 'select' => t('Select'),
684 'delete' => t('Delete'),
688 $isstarred = "unstarred";
691 $likebuttons = false;
694 $body = prepare_body($item,true, $preview);
697 list($categories, $folders) = get_cats_and_terms($item);
699 if($a->theme['template_engine'] === 'internal') {
700 $profile_name_e = template_escape($profile_name);
701 $item['title_e'] = template_escape($item['title']);
702 $body_e = template_escape($body);
703 $tags_e = template_escape($tags);
704 $hashtags_e = template_escape($hashtags);
705 $mentions_e = template_escape($mentions);
706 $location_e = template_escape($location);
707 $owner_name_e = template_escape($owner_name);
710 $profile_name_e = $profile_name;
711 $item['title_e'] = $item['title'];
714 $hashtags_e = $hashtags;
715 $mentions_e = $mentions;
716 $location_e = $location;
717 $owner_name_e = $owner_name;
720 if ($item['item_network'] == "")
721 $item['item_network'] = $item['network'];
725 'id' => (($preview) ? 'P0' : $item['item_id']),
726 'network' => $item['item_network'],
727 'network_name' => network_to_name($item['item_network'], $profile_link),
728 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
729 'profile_url' => $profile_link,
730 'item_photo_menu' => item_photo_menu($item),
731 'name' => $profile_name_e,
732 'sparkle' => $sparkle,
734 'thumb' => App::remove_baseurl(proxy_url($profile_avatar, false, PROXY_SIZE_THUMB)),
735 'title' => $item['title_e'],
738 'hashtags' => $hashtags_e,
739 'mentions' => $mentions_e,
740 'txt_cats' => t('Categories:'),
741 'txt_folders' => t('Filed under:'),
742 'has_cats' => ((count($categories)) ? 'true' : ''),
743 'has_folders' => ((count($folders)) ? 'true' : ''),
744 'categories' => $categories,
745 'folders' => $folders,
746 'text' => strip_tags($body_e),
747 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
748 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
749 'location' => $location_e,
751 'owner_name' => $owner_name_e,
752 'owner_url' => $owner_url,
753 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB),
754 'plink' => get_plink($item),
756 'isstarred' => $isstarred,
759 'vote' => $likebuttons,
763 //'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
764 'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
765 'previewing' => $previewing,
766 'wait' => t('Please wait'),
770 $arr = array('item' => $item, 'output' => $tmp_item);
771 call_hooks('display_item', $arr);
773 $threads[$threadsid]['id'] = $item['item_id'];
774 $threads[$threadsid]['network'] = $item['item_network'];
775 $threads[$threadsid]['items'] = array($arr['output']);
782 $page_template = get_markup_template("threaded_conversation.tpl");
784 require_once('object/Conversation.php');
785 require_once('object/Item.php');
787 $conv = new Conversation($mode, $preview);
789 // get all the topmost parents
790 // this shouldn't be needed, as we should have only them in our array
791 // But for now, this array respects the old style, just in case
794 foreach($items as $item) {
798 foreach($arr_blocked as $b) {
800 if($b && link_compare($item['author-link'],$b)) {
811 // Can we put this after the visibility check?
812 builtin_activity_puller($item, $conv_responses);
814 // Only add what is visible
815 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
818 if(! visible_activity($item)) {
822 call_hooks('display_item', $arr);
824 $item['pagedrop'] = $page_dropping;
826 if($item['id'] == $item['parent']) {
827 $item_object = new Item($item);
828 $conv->add_thread($item_object);
832 $threads = $conv->get_template_data($conv_responses);
835 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
841 $o = replace_macros($page_template, array(
842 '$baseurl' => $a->get_baseurl($ssl_state),
843 '$return_path' => $a->query_string,
844 '$live_update' => $live_update_div,
845 '$remove' => t('remove'),
848 '$threads' => $threads,
849 '$dropping' => ($page_dropping && feature_enabled(local_user(),'multi_delete') ? t('Delete Selected Items') : False),
855 function best_link_url($item,&$sparkle,$ssl_state = false) {
862 $clean_url = normalise_link($item['author-link']);
865 $r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' LIMIT 1",
866 dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url)));
868 $best_url = 'redir/'.$r[0]['id'];
873 if(strlen($item['author-link']))
874 $best_url = $item['author-link'];
876 $best_url = $item['url'];
883 if(! function_exists('item_photo_menu')){
884 function item_photo_menu($item){
901 if((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
902 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
906 $profile_link = best_link_url($item,$sparkle,$ssl_state);
907 if($profile_link === 'mailbox')
913 $r = q("SELECT `id`, `network`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
914 intval(local_user()), dbesc(normalise_link($item['author-link'])));
917 $network = $r[0]["network"];
922 $status_link = $profile_link."?url=status";
923 $photos_link = $profile_link."?url=photos";
924 $profile_link = $profile_link."?url=profile";
927 $profile_link = zrl($profile_link);
929 if($cid && !$item['self']) {
930 $poke_link = 'poke/?f=&c='.$cid;
931 $contact_url = 'contacts/'.$cid;
932 $posts_link = 'contacts/'.$cid.'/posts';
934 if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA)))
935 $pm_url = 'message/new/'.$cid;
940 t("Follow Thread") => $sub_link,
941 t("View Status") => $status_link,
942 t("View Profile") => $profile_link,
943 t("View Photos") => $photos_link,
944 t("Network Posts") => $posts_link,
945 t("Edit Contact") => $contact_url,
946 t("Send PM") => $pm_url
949 if ($network == NETWORK_DFRN)
950 $menu[t("Poke")] = $poke_link;
952 if ((($cid == 0) OR ($rel == CONTACT_IS_FOLLOWER)) AND
953 in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
954 $menu[t("Connect/Follow")] = "follow?url=".urlencode($item['author-link']);
956 $menu = array(t("View Profile") => $item['author-link']);
958 $args = array('item' => $item, 'menu' => $menu);
960 call_hooks('item_photo_menu', $args);
962 $menu = $args['menu'];
965 foreach($menu as $k=>$v){
966 if(strpos($v,'javascript:') === 0) {
968 $o .= "<li role=\"menuitem\"><a onclick=\"$v\">$k</a></li>\n";
970 elseif ($v!="") $o .= "<li role=\"menuitem\"><a href=\"$v\">$k</a></li>\n";
976 * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
977 * Increments the count of each matching activity and adds a link to the author as needed.
980 * @param array &$conv_responses (already created with builtin activity structure)
983 if(! function_exists('builtin_activity_puller')) {
984 function builtin_activity_puller($item, &$conv_responses) {
985 foreach($conv_responses as $mode => $v) {
991 $verb = ACTIVITY_LIKE;
994 $verb = ACTIVITY_DISLIKE;
997 $verb = ACTIVITY_ATTEND;
1000 $verb = ACTIVITY_ATTENDNO;
1003 $verb = ACTIVITY_ATTENDMAYBE;
1010 if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
1011 $url = $item['author-link'];
1012 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
1013 $url = 'redir/' . $item['contact-id'];
1014 $sparkle = ' class="sparkle" ';
1019 $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
1021 if(! $item['thr-parent'])
1022 $item['thr-parent'] = $item['parent-uri'];
1024 if(! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
1025 && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))))
1026 $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
1028 // only list each unique author once
1029 if(in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l']))
1032 if(! isset($conv_responses[$mode][$item['thr-parent']]))
1033 $conv_responses[$mode][$item['thr-parent']] = 1;
1035 $conv_responses[$mode][$item['thr-parent']] ++;
1037 $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
1039 // there can only be one activity verb per item so if we found anything, we can stop looking
1045 // Format the vote text for a profile item
1046 // $cnt = number of people who vote the item
1047 // $arr = array of pre-linked names of likers/dislikers
1048 // $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
1050 // returns formatted text
1052 if(! function_exists('format_like')) {
1053 function format_like($cnt,$arr,$type,$id) {
1060 // Phrase if there is only one liker. In other cases it will be uses for the expanded
1061 // list which show all likers
1064 $phrase = sprintf( t('%s likes this.'), $likers);
1067 $phrase = sprintf( t('%s doesn\'t like this.'), $likers);
1070 $phrase = sprintf( t('%s attends.'), $likers);
1073 $phrase = sprintf( t('%s doesn\'t attend.'), $likers);
1075 case 'attendmaybe' :
1076 $phrase = sprintf( t('%s attends maybe.'), $likers);
1082 $total = count($arr);
1083 if($total >= MAX_LIKERS)
1084 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1085 if($total < MAX_LIKERS) {
1086 $last = t('and') . ' ' . $arr[count($arr)-1];
1087 $arr2 = array_slice($arr, 0, -1);
1088 $str = implode(', ', $arr2) . ' ' . $last;
1090 if($total >= MAX_LIKERS) {
1091 $str = implode(', ', $arr);
1092 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1097 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
1101 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
1102 $explikers = sprintf( t('%s like this.'), $likers);
1105 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
1106 $explikers = sprintf( t('%s don\'t like this.'), $likers);
1109 $phrase = sprintf( t('<span %1$s>%2$d people</span> attend'), $spanatts, $cnt);
1110 $explikers = sprintf( t('%s attend.'), $likers);
1113 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
1114 $explikers = sprintf( t('%s don\'t attend.'), $likers);
1117 $phrase = sprintf( t('<span %1$s>%2$d people</span> anttend maybe'), $spanatts, $cnt);
1118 $explikers = sprintf( t('%s anttend maybe.'), $likers);
1122 $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
1126 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
1127 '$phrase' => $phrase,
1137 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
1141 $geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
1143 /* $plaintext = false;
1144 if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
1145 $plaintext = true;*/
1147 if( local_user() && feature_enabled(local_user(),'richtext') )
1150 $tpl = get_markup_template('jot-header.tpl');
1151 $a->page['htmlhead'] .= replace_macros($tpl, array(
1152 '$newpost' => 'true',
1153 '$baseurl' => $a->get_baseurl(true),
1154 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1155 '$geotag' => $geotag,
1156 '$nickname' => $x['nickname'],
1157 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1158 '$linkurl' => t('Please enter a link URL:'),
1159 '$vidurl' => t("Please enter a video link/URL:"),
1160 '$audurl' => t("Please enter an audio link/URL:"),
1161 '$term' => t('Tag term:'),
1162 '$fileas' => t('Save to Folder:'),
1163 '$whereareu' => t('Where are you right now?'),
1164 '$delitems' => t('Delete item(s)?')
1168 $tpl = get_markup_template('jot-end.tpl');
1169 $a->page['end'] .= replace_macros($tpl, array(
1170 '$newpost' => 'true',
1171 '$baseurl' => $a->get_baseurl(true),
1172 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1173 '$geotag' => $geotag,
1174 '$nickname' => $x['nickname'],
1175 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1176 '$linkurl' => t('Please enter a link URL:'),
1177 '$vidurl' => t("Please enter a video link/URL:"),
1178 '$audurl' => t("Please enter an audio link/URL:"),
1179 '$term' => t('Tag term:'),
1180 '$fileas' => t('Save to Folder:'),
1181 '$whereareu' => t('Where are you right now?')
1185 call_hooks('jot_tool', $jotplugins);
1187 // Private/public post links for the non-JS ACL form
1189 if($_REQUEST['public'])
1192 $query_str = $a->query_string;
1193 if(strpos($query_str, 'public=1') !== false)
1194 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1196 // I think $a->query_string may never have ? in it, but I could be wrong
1197 // It looks like it's from the index.php?q=[etc] rewrite that the web
1198 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1199 if(strpos($query_str, '?') === false)
1200 $public_post_link = '?public=1';
1202 $public_post_link = '&public=1';
1206 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1207 $tpl = get_markup_template("jot.tpl");
1209 $o .= replace_macros($tpl,array(
1210 '$return_path' => $query_str,
1211 '$action' => 'item',
1212 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1213 '$upload' => t('Upload photo'),
1214 '$shortupload' => t('upload photo'),
1215 '$attach' => t('Attach file'),
1216 '$shortattach' => t('attach file'),
1217 '$weblink' => t('Insert web link'),
1218 '$shortweblink' => t('web link'),
1219 '$video' => t('Insert video link'),
1220 '$shortvideo' => t('video link'),
1221 '$audio' => t('Insert audio link'),
1222 '$shortaudio' => t('audio link'),
1223 '$setloc' => t('Set your location'),
1224 '$shortsetloc' => t('set location'),
1225 '$noloc' => t('Clear browser location'),
1226 '$shortnoloc' => t('clear location'),
1227 '$title' => $x['title'],
1228 '$placeholdertitle' => t('Set title'),
1229 '$category' => $x['category'],
1230 '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''),
1231 '$wait' => t('Please wait'),
1232 '$permset' => t('Permission settings'),
1233 '$shortpermset' => t('permissions'),
1234 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1235 '$content' => $x['content'],
1236 '$post_id' => $x['post_id'],
1237 '$baseurl' => $a->get_baseurl(true),
1238 '$defloc' => $x['default_location'],
1239 '$visitor' => $x['visitor'],
1240 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1241 '$public' => t('Public post'),
1242 '$jotnets' => $jotnets,
1243 '$lockstate' => $x['lockstate'],
1244 '$bang' => $x['bang'],
1245 '$profile_uid' => $x['profile_uid'],
1246 '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1247 '$jotplugins' => $jotplugins,
1248 '$notes_cid' => $notes_cid,
1249 '$sourceapp' => t($a->sourcename),
1250 '$cancel' => t('Cancel'),
1251 '$rand_num' => random_digits(12),
1253 // ACL permissions box
1254 '$acl' => $x['acl'],
1255 '$acl_data' => $x['acl_data'],
1256 '$group_perms' => t('Post to Groups'),
1257 '$contact_perms' => t('Post to Contacts'),
1258 '$private' => t('Private post'),
1259 '$is_private' => $private_post,
1260 '$public_link' => $public_post_link,
1265 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1273 function get_item_children($arr, $parent) {
1274 $children = array();
1276 foreach($arr as $item) {
1277 if($item['id'] != $item['parent']) {
1278 if(get_config('system','thread_allow') && $a->theme_thread_allow) {
1279 // Fallback to parent-uri if thr-parent is not set
1280 $thr_parent = $item['thr-parent'];
1281 if($thr_parent == '')
1282 $thr_parent = $item['parent-uri'];
1284 if($thr_parent == $parent['uri']) {
1285 $item['children'] = get_item_children($arr, $item);
1286 $children[] = $item;
1289 else if($item['parent'] == $parent['id']) {
1290 $children[] = $item;
1297 function sort_item_children($items) {
1299 usort($result,'sort_thr_created_rev');
1300 foreach($result as $k => $i) {
1301 if(count($result[$k]['children'])) {
1302 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1308 function add_children_to_list($children, &$arr) {
1309 foreach($children as $y) {
1311 if(count($y['children']))
1312 add_children_to_list($y['children'], $arr);
1316 function conv_sort($arr,$order) {
1318 if((!(is_array($arr) && count($arr))))
1322 $children = array();
1325 // This is a preparation for having two different items with the same uri in one thread
1326 // This will otherwise lead to an endless loop.
1328 if (!isset($newarr[$x['uri']]))
1329 $newarr[$x['uri']] = $x;
1334 if($x['id'] == $x['parent'])
1337 if(stristr($order,'created'))
1338 usort($parents,'sort_thr_created');
1339 elseif(stristr($order,'commented'))
1340 usort($parents,'sort_thr_commented');
1343 foreach($parents as $i=>$_x)
1344 $parents[$i]['children'] = get_item_children($arr, $_x);
1346 /*foreach($arr as $x) {
1347 if($x['id'] != $x['parent']) {
1348 $p = find_thread_parent_index($parents,$x);
1350 $parents[$p]['children'][] = $x;
1353 if(count($parents)) {
1354 foreach($parents as $k => $v) {
1355 if(count($parents[$k]['children'])) {
1356 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1357 /*$y = $parents[$k]['children'];
1358 usort($y,'sort_thr_created_rev');
1359 $parents[$k]['children'] = $y;*/
1365 if(count($parents)) {
1366 foreach($parents as $x) {
1368 if(count($x['children']))
1369 add_children_to_list($x['children'], $ret);
1370 /*foreach($x['children'] as $y)
1379 function sort_thr_created($a,$b) {
1380 return strcmp($b['created'],$a['created']);
1383 function sort_thr_created_rev($a,$b) {
1384 return strcmp($a['created'],$b['created']);
1387 function sort_thr_commented($a,$b) {
1388 return strcmp($b['commented'],$a['commented']);
1391 function find_thread_parent_index($arr,$x) {
1392 foreach($arr as $k => $v)
1393 if($v['id'] == $x['parent'])
1398 function render_location_dummy($item) {
1399 if ($item['location'] != "")
1400 return $item['location'];
1402 if ($item['coord'] != "")
1403 return $item['coord'];
1406 function get_responses($conv_responses,$response_verbs,$ob,$item) {
1408 foreach($response_verbs as $v) {
1410 $ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
1411 $ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
1412 if(count($ret[$v]['list']) > MAX_LIKERS) {
1413 $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
1414 array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
1415 . (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
1418 $ret[$v]['list_part'] = '';
1420 $ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']);
1421 $ret[$v]['title'] = $conv_responses[$v]['title'];
1425 foreach($ret as $key) {
1426 if ($key['count'] == true)
1429 $ret['count'] = $count;
1434 function get_response_button_text($v,$count) {
1437 return tt('Like','Likes',$count,'noun');
1440 return tt('Dislike','Dislikes',$count,'noun');
1443 return tt('Attending','Attending',$count,'noun');
1446 return tt('Not Attending','Not Attending',$count,'noun');
1449 return tt('Undecided','Undecided',$count,'noun');