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) || activity_match($item['verb'],ACTIVITY_DISLIKE)){
105 $r = q("SELECT * from `item`,`contact` WHERE
106 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
107 dbesc($item['parent-uri']));
108 if(count($r)==0) return;
111 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
112 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
114 switch($obj['verb']){
116 switch ($obj['object-type']){
117 case ACTIVITY_OBJ_EVENT:
118 $post_type = t('event');
121 $post_type = t('status');
125 if($obj['resource-id']){
126 $post_type = t('photo');
127 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
128 $rr['plink'] = $m[1];
130 $post_type = t('status');
134 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
136 if(activity_match($item['verb'],ACTIVITY_LIKE)) {
137 $bodyverb = t('%1$s likes %2$s\'s %3$s');
139 elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) {
140 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
142 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
145 if (activity_match($item['verb'],ACTIVITY_FRIEND)) {
147 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
149 $Aname = $item['author-name'];
150 $Alink = $item['author-link'];
152 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
154 $obj = parse_xml_string($xmlhead.$item['object']);
155 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
157 $Bname = $obj->title;
158 $Blink = ""; $Bphoto = "";
159 foreach ($links->link as $l){
160 $atts = $l->attributes();
161 switch($atts['rel']){
162 case "alternate": $Blink = $atts['href'];
163 case "photo": $Bphoto = $atts['href'];
168 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
169 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
170 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
172 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
175 if (stristr($item['verb'],ACTIVITY_POKE)) {
176 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
179 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
181 $Aname = $item['author-name'];
182 $Alink = $item['author-link'];
184 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
186 $obj = parse_xml_string($xmlhead.$item['object']);
187 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
189 $Bname = $obj->title;
190 $Blink = ""; $Bphoto = "";
191 foreach ($links->link as $l){
192 $atts = $l->attributes();
193 switch($atts['rel']){
194 case "alternate": $Blink = $atts['href'];
195 case "photo": $Bphoto = $atts['href'];
200 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
201 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
202 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
204 // we can't have a translation string with three positions but no distinguishable text
205 // So here is the translate string.
206 $txt = t('%1$s poked %2$s');
208 // now translate the verb
209 $poked_t = trim(sprintf($txt, "",""));
210 $txt = str_replace( $poked_t, t($verb), $txt);
212 // then do the sprintf on the translation string
214 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
217 if (stristr($item['verb'],ACTIVITY_MOOD)) {
218 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
222 $Aname = $item['author-name'];
223 $Alink = $item['author-link'];
224 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
226 $txt = t('%1$s is currently %2$s');
228 $item['body'] = sprintf($txt, $A, t($verb));
231 if (activity_match($item['verb'],ACTIVITY_TAG)) {
232 $r = q("SELECT * from `item`,`contact` WHERE
233 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
234 dbesc($item['parent-uri']));
235 if(count($r)==0) return;
238 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
239 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
241 switch($obj['verb']){
243 switch ($obj['object-type']){
244 case ACTIVITY_OBJ_EVENT:
245 $post_type = t('event');
248 $post_type = t('status');
252 if($obj['resource-id']){
253 $post_type = t('photo');
254 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
255 $rr['plink'] = $m[1];
257 $post_type = t('status');
260 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
262 $parsedobj = parse_xml_string($xmlhead.$item['object']);
264 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
265 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
268 if (activity_match($item['verb'],ACTIVITY_FAVORITE)){
270 if ($item['object-type']== "")
273 $Aname = $item['author-name'];
274 $Alink = $item['author-link'];
276 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
278 $obj = parse_xml_string($xmlhead.$item['object']);
279 if(strlen($obj->id)) {
280 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
284 if(count($r) && $r[0]['plink']) {
286 $Bname = $target['author-name'];
287 $Blink = $target['author-link'];
288 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
289 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
290 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
291 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
297 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
298 foreach($matches as $mtch) {
299 if(! strpos($mtch[1],'zrl='))
300 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
304 // add zrl's to public images
305 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
306 if(preg_match($photo_pattern,$item['body'])) {
307 $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
308 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
311 // add sparkle links to appropriate permalinks
313 $x = stristr($item['plink'],'/display/');
316 $y = best_link_url($item,$sparkle,true);
317 if(strstr($y,'/redir/'))
318 $item['plink'] = $y . '?f=&url=' . $item['plink'];
326 * Count the total of comments on this item and its desendants
328 function count_descendants($item) {
329 $total = count($item['children']);
332 foreach($item['children'] as $child) {
333 if(! visible_activity($child))
335 $total += count_descendants($child);
342 function visible_activity($item) {
344 if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE))
347 if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
348 if(! (($item['self']) && ($item['uid'] == local_user()))) {
358 * "Render" a conversation or list of items for HTML display.
359 * There are two major forms of display:
360 * - Sequential or unthreaded ("New Item View" or search results)
361 * - conversation view
362 * The $mode parameter decides between the various renderings and also
363 * figures out how to determine page owner and other contextual items
364 * that are based on unique features of the calling module.
368 if(!function_exists('conversation')) {
369 function conversation(&$a, $items, $mode, $update, $preview = false) {
371 require_once('include/bbcode.php');
372 require_once('mod/proxy.php');
374 $ssl_state = ((local_user()) ? true : false);
377 $page_writeable = false;
378 $live_update_div = '';
383 $str_blocked = get_pconfig(local_user(),'system','blocked');
385 $arr_blocked = explode(',',$str_blocked);
386 for($x = 0; $x < count($arr_blocked); $x ++)
387 $arr_blocked[$x] = trim($arr_blocked[$x]);
392 $previewing = (($preview) ? ' preview ' : '');
394 if($mode === 'network') {
395 $profile_owner = local_user();
396 $page_writeable = true;
398 // The special div is needed for liveUpdate to kick in for this page.
399 // We only launch liveUpdate if you aren't filtering in some incompatible
400 // way and also you aren't writing a comment (discovered in javascript).
402 $live_update_div = '<div id="live-network"></div>' . "\r\n"
403 . "<script> var profile_uid = " . $_SESSION['uid']
404 . "; var netargs = '" . substr($a->cmd,8)
406 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
407 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
408 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
409 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
410 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
411 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
412 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
413 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
414 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
415 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
416 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
417 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
419 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
422 else if($mode === 'profile') {
423 $profile_owner = $a->profile['profile_uid'];
424 $page_writeable = can_write_wall($a,$profile_owner);
427 $tab = notags(trim($_GET['tab']));
428 $tab = ( $tab ? $tab : 'posts' );
429 if($tab === 'posts') {
430 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
431 // because browser prefetching might change it on us. We have to deliver it with the page.
433 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
434 . "<script> var profile_uid = " . $a->profile['profile_uid']
435 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
439 else if($mode === 'notes') {
440 $profile_owner = local_user();
441 $page_writeable = true;
443 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
444 . "<script> var profile_uid = " . local_user()
445 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
448 else if($mode === 'display') {
449 $profile_owner = $a->profile['uid'];
450 $page_writeable = can_write_wall($a,$profile_owner);
452 $live_update_div = '<div id="live-display"></div>' . "\r\n"
453 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
454 . " var profile_page = 1; </script>";
457 else if($mode === 'community') {
459 $page_writeable = false;
461 $live_update_div = '<div id="live-community"></div>' . "\r\n"
462 . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
465 else if($mode === 'search') {
466 $live_update_div = '<div id="live-search"></div>' . "\r\n";
469 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
473 $return_url = $_SESSION['return_url'];
475 $return_url = $_SESSION['return_url'] = $a->query_string;
477 load_contact_links(local_user());
479 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
480 call_hooks('conversation_start',$cb);
482 $items = $cb['items'];
484 $cmnt_tpl = get_markup_template('comment_item.tpl');
485 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
490 // array with html for each thread (parent+comments)
494 $page_template = get_markup_template("conversation.tpl");
496 if($items && count($items)) {
498 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
500 // "New Item View" on network page or search page results
501 // - just loop through the items and format them minimally for display
503 // $tpl = get_markup_template('search_item.tpl');
504 $tpl = 'search_item.tpl';
506 foreach($items as $item) {
510 foreach($arr_blocked as $b) {
511 if($b && link_compare($item['author-link'],$b)) {
529 if($mode === 'search' || $mode === 'community') {
530 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
531 && ($item['id'] != $item['parent']))
533 $nickname = $item['nickname'];
536 $nickname = $a->user['nickname'];
538 // prevent private email from leaking.
539 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
542 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
543 if($item['author-link'] && (! $item['author-name']))
544 $profile_name = $item['author-link'];
552 $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
553 intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
555 foreach($taglist as $tag) {
557 if ($tag["url"] == "")
558 $tag["url"] = $searchpath.strtolower($tag["term"]);
560 if ($tag["type"] == TERM_HASHTAG) {
561 $hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
563 } elseif ($tag["type"] == TERM_MENTION) {
564 $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
567 $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
570 /*foreach(explode(',',$item['tag']) as $tag){
583 $profile_link = best_link_url($item,$sp);
584 if($profile_link === 'mailbox')
587 $sparkle = ' sparkle';
589 $profile_link = zrl($profile_link);
591 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
592 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
593 $profile_avatar = $a->contacts[$normalised]['thumb'];
595 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
597 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
598 call_hooks('render_location',$locate);
600 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
602 localize_item($item);
603 if($mode === 'network-new')
610 'dropping' => $dropping,
611 'pagedrop' => $page_dropping,
612 'select' => t('Select'),
613 'delete' => t('Delete'),
617 $isstarred = "unstarred";
620 $likebuttons = false;
623 $body = prepare_body($item,true, $preview);
626 list($categories, $folders) = get_cats_and_terms($item);
628 if($a->theme['template_engine'] === 'internal') {
629 $profile_name_e = template_escape($profile_name);
630 $item['title_e'] = template_escape($item['title']);
631 $body_e = template_escape($body);
632 $tags_e = template_escape($tags);
633 $hashtags_e = template_escape($hashtags);
634 $mentions_e = template_escape($mentions);
635 $location_e = template_escape($location);
636 $owner_name_e = template_escape($owner_name);
639 $profile_name_e = $profile_name;
640 $item['title_e'] = $item['title'];
643 $hashtags_e = $hashtags;
644 $mentions_e = $mentions;
645 $location_e = $location;
646 $owner_name_e = $owner_name;
651 'id' => (($preview) ? 'P0' : $item['item_id']),
652 'network' => $item['item_network'],
653 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
654 'profile_url' => $profile_link,
655 'item_photo_menu' => item_photo_menu($item),
656 'name' => $profile_name_e,
657 'sparkle' => $sparkle,
659 'thumb' => proxy_url($profile_avatar),
660 'title' => $item['title_e'],
663 'hashtags' => $hashtags_e,
664 'mentions' => $mentions_e,
665 'txt_cats' => t('Categories:'),
666 'txt_folders' => t('Filed under:'),
667 'has_cats' => ((count($categories)) ? 'true' : ''),
668 'has_folders' => ((count($folders)) ? 'true' : ''),
669 'categories' => $categories,
670 'folders' => $folders,
671 'text' => strip_tags($body_e),
672 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
673 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
674 'location' => $location_e,
676 'owner_name' => $owner_name_e,
677 'owner_url' => $owner_url,
678 'owner_photo' => proxy_url($owner_photo),
679 'plink' => get_plink($item),
681 'isstarred' => $isstarred,
684 'vote' => $likebuttons,
688 //'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
689 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/'.$item['guid'], 'title'=> t('View in context'))),
690 'previewing' => $previewing,
691 'wait' => t('Please wait'),
695 $arr = array('item' => $item, 'output' => $tmp_item);
696 call_hooks('display_item', $arr);
698 $threads[$threadsid]['id'] = $item['item_id'];
699 $threads[$threadsid]['network'] = $item['item_network'];
700 $threads[$threadsid]['items'] = array($arr['output']);
707 $page_template = get_markup_template("threaded_conversation.tpl");
709 require_once('object/Conversation.php');
710 require_once('object/Item.php');
712 $conv = new Conversation($mode, $preview);
714 // get all the topmost parents
715 // this shouldn't be needed, as we should have only them in our array
716 // But for now, this array respects the old style, just in case
719 foreach($items as $item) {
723 foreach($arr_blocked as $b) {
725 if($b && link_compare($item['author-link'],$b)) {
736 // Can we put this after the visibility check?
737 like_puller($a,$item,$alike,'like');
738 like_puller($a,$item,$dlike,'dislike');
740 // Only add what is visible
741 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
744 if(! visible_activity($item)) {
748 call_hooks('display_item', $arr);
750 $item['pagedrop'] = $page_dropping;
752 if($item['id'] == $item['parent']) {
753 $item_object = new Item($item);
754 $conv->add_thread($item_object);
758 $threads = $conv->get_template_data($alike, $dlike);
761 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
767 $o = replace_macros($page_template, array(
768 '$baseurl' => $a->get_baseurl($ssl_state),
769 '$return_path' => $a->query_string,
770 '$live_update' => $live_update_div,
771 '$remove' => t('remove'),
774 '$threads' => $threads,
775 '$dropping' => ($page_dropping && feature_enabled(local_user(),'multi_delete') ? t('Delete Selected Items') : False),
781 function best_link_url($item,&$sparkle,$ssl_state = false) {
788 $clean_url = normalise_link($item['author-link']);
790 if((local_user()) && (local_user() == $item['uid'])) {
791 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
792 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
793 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
797 $best_url = $a->contacts[$clean_url]['url'];
801 if(strlen($item['author-link']))
802 $best_url = $item['author-link'];
804 $best_url = $item['url'];
811 if(! function_exists('item_photo_menu')){
812 function item_photo_menu($item){
819 if(! count($a->contacts))
820 load_contact_links(local_user());
830 if((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
831 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
835 $profile_link = best_link_url($item,$sparkle,$ssl_state);
836 if($profile_link === 'mailbox')
840 $cid = intval(basename($profile_link));
841 $status_link = $profile_link . "?url=status";
842 $photos_link = $profile_link . "?url=photos";
843 $profile_link = $profile_link . "?url=profile";
844 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
848 $profile_link = zrl($profile_link);
849 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
850 $cid = $item['contact-id'];
856 if(($cid) && (! $item['self'])) {
857 $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
858 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
859 $posts_link = $a->get_baseurl($ssl_state) . '/network/0?nets=all&cid=' . $cid;
861 $clean_url = normalise_link($item['author-link']);
863 if((local_user()) && (local_user() == $item['uid'])) {
864 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
865 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
866 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
874 t("Follow Thread") => $sub_link,
875 t("View Status") => $status_link,
876 t("View Profile") => $profile_link,
877 t("View Photos") => $photos_link,
878 t("Network Posts") => $posts_link,
879 t("Edit Contact") => $contact_url,
880 t("Send PM") => $pm_url,
881 t("Poke") => $poke_link
885 $args = array('item' => $item, 'menu' => $menu);
887 call_hooks('item_photo_menu', $args);
889 $menu = $args['menu'];
892 foreach($menu as $k=>$v){
893 if(strpos($v,'javascript:') === 0) {
895 $o .= "<li><a href=\"#\" onclick=\"$v\">$k</a></li>\n";
897 elseif ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
902 if(! function_exists('like_puller')) {
903 function like_puller($a,$item,&$arr,$mode) {
907 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
909 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
910 $url = $item['author-link'];
911 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
912 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
913 $sparkle = ' class="sparkle" ';
918 if(! $item['thr-parent'])
919 $item['thr-parent'] = $item['parent-uri'];
921 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
922 $arr[$item['thr-parent'] . '-l'] = array();
923 if(! isset($arr[$item['thr-parent']]))
924 $arr[$item['thr-parent']] = 1;
926 $arr[$item['thr-parent']] ++;
927 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
932 // Format the like/dislike text for a profile item
933 // $cnt = number of people who like/dislike the item
934 // $arr = array of pre-linked names of likers/dislikers
935 // $type = one of 'like, 'dislike'
937 // returns formatted text
939 if(! function_exists('format_like')) {
940 function format_like($cnt,$arr,$type,$id) {
943 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
945 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
948 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
951 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
955 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
956 '$phrase' => $phrase,
961 $total = count($arr);
962 if($total >= MAX_LIKERS)
963 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
964 if($total < MAX_LIKERS) {
965 $last = t('and') . ' ' . $arr[count($arr)-1];
966 $arr2 = array_slice($arr, 0, -1);
967 $str = implode(', ', $arr2) . ' ' . $last;
969 if($total >= MAX_LIKERS) {
970 $str = implode(', ', $arr);
971 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
973 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
974 $o .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
980 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
984 $geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
986 /* $plaintext = false;
987 if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
990 if( local_user() && feature_enabled(local_user(),'richtext') )
993 $tpl = get_markup_template('jot-header.tpl');
994 $a->page['htmlhead'] .= replace_macros($tpl, array(
995 '$newpost' => 'true',
996 '$baseurl' => $a->get_baseurl(true),
997 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
998 '$geotag' => $geotag,
999 '$nickname' => $x['nickname'],
1000 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1001 '$linkurl' => t('Please enter a link URL:'),
1002 '$vidurl' => t("Please enter a video link/URL:"),
1003 '$audurl' => t("Please enter an audio link/URL:"),
1004 '$term' => t('Tag term:'),
1005 '$fileas' => t('Save to Folder:'),
1006 '$whereareu' => t('Where are you right now?'),
1007 '$delitems' => t('Delete item(s)?')
1011 $tpl = get_markup_template('jot-end.tpl');
1012 $a->page['end'] .= replace_macros($tpl, array(
1013 '$newpost' => 'true',
1014 '$baseurl' => $a->get_baseurl(true),
1015 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1016 '$geotag' => $geotag,
1017 '$nickname' => $x['nickname'],
1018 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1019 '$linkurl' => t('Please enter a link URL:'),
1020 '$vidurl' => t("Please enter a video link/URL:"),
1021 '$audurl' => t("Please enter an audio link/URL:"),
1022 '$term' => t('Tag term:'),
1023 '$fileas' => t('Save to Folder:'),
1024 '$whereareu' => t('Where are you right now?')
1031 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
1033 $mail_enabled = false;
1034 $pubmail_enabled = false;
1036 if(($x['is_owner']) && (! $mail_disabled)) {
1037 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
1038 intval(local_user())
1041 $mail_enabled = true;
1042 if(intval($r[0]['pubmail']))
1043 $pubmail_enabled = true;
1047 if (!$a->user['hidewall']) {
1049 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
1050 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
1053 call_hooks('jot_networks', $jotnets);
1055 $jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'),
1056 t('Hide your profile details from unknown viewers?'));
1058 call_hooks('jot_tool', $jotplugins);
1061 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
1064 // Private/public post links for the non-JS ACL form
1066 if($_REQUEST['public'])
1069 $query_str = $a->query_string;
1070 if(strpos($query_str, 'public=1') !== false)
1071 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1073 // I think $a->query_string may never have ? in it, but I could be wrong
1074 // It looks like it's from the index.php?q=[etc] rewrite that the web
1075 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1076 if(strpos($query_str, '?') === false)
1077 $public_post_link = '?public=1';
1079 $public_post_link = '&public=1';
1083 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1084 $tpl = get_markup_template("jot.tpl");
1086 $o .= replace_macros($tpl,array(
1087 '$return_path' => $query_str,
1088 '$action' => $a->get_baseurl(true) . '/item',
1089 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1090 '$upload' => t('Upload photo'),
1091 '$shortupload' => t('upload photo'),
1092 '$attach' => t('Attach file'),
1093 '$shortattach' => t('attach file'),
1094 '$weblink' => t('Insert web link'),
1095 '$shortweblink' => t('web link'),
1096 '$video' => t('Insert video link'),
1097 '$shortvideo' => t('video link'),
1098 '$audio' => t('Insert audio link'),
1099 '$shortaudio' => t('audio link'),
1100 '$setloc' => t('Set your location'),
1101 '$shortsetloc' => t('set location'),
1102 '$noloc' => t('Clear browser location'),
1103 '$shortnoloc' => t('clear location'),
1104 '$title' => $x['title'],
1105 '$placeholdertitle' => t('Set title'),
1106 '$category' => $x['category'],
1107 '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''),
1108 '$wait' => t('Please wait'),
1109 '$permset' => t('Permission settings'),
1110 '$shortpermset' => t('permissions'),
1111 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1112 '$content' => $x['content'],
1113 '$post_id' => $x['post_id'],
1114 '$baseurl' => $a->get_baseurl(true),
1115 '$defloc' => $x['default_location'],
1116 '$visitor' => $x['visitor'],
1117 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1118 '$emailcc' => t('CC: email addresses'),
1119 '$public' => t('Public post'),
1120 '$jotnets' => $jotnets,
1121 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1122 '$lockstate' => $x['lockstate'],
1123 '$bang' => $x['bang'],
1124 '$profile_uid' => $x['profile_uid'],
1125 '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1126 '$jotplugins' => $jotplugins,
1127 '$sourceapp' => t($a->sourcename),
1128 '$cancel' => t('Cancel'),
1129 '$rand_num' => random_digits(12),
1131 // ACL permissions box
1132 '$acl' => $x['acl'],
1133 '$acl_data' => $x['acl_data'],
1134 '$group_perms' => t('Post to Groups'),
1135 '$contact_perms' => t('Post to Contacts'),
1136 '$private' => t('Private post'),
1137 '$is_private' => $private_post,
1138 '$public_link' => $public_post_link,
1143 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1151 function get_item_children($arr, $parent) {
1152 $children = array();
1154 foreach($arr as $item) {
1155 if($item['id'] != $item['parent']) {
1156 if(get_config('system','thread_allow') && $a->theme_thread_allow) {
1157 // Fallback to parent-uri if thr-parent is not set
1158 $thr_parent = $item['thr-parent'];
1159 if($thr_parent == '')
1160 $thr_parent = $item['parent-uri'];
1162 if($thr_parent == $parent['uri']) {
1163 $item['children'] = get_item_children($arr, $item);
1164 $children[] = $item;
1167 else if($item['parent'] == $parent['id']) {
1168 $children[] = $item;
1175 function sort_item_children($items) {
1177 usort($result,'sort_thr_created_rev');
1178 foreach($result as $k => $i) {
1179 if(count($result[$k]['children'])) {
1180 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1186 function add_children_to_list($children, &$arr) {
1187 foreach($children as $y) {
1189 if(count($y['children']))
1190 add_children_to_list($y['children'], $arr);
1194 function conv_sort($arr,$order) {
1196 if((!(is_array($arr) && count($arr))))
1200 $children = array();
1203 if($x['id'] == $x['parent'])
1206 if(stristr($order,'created'))
1207 usort($parents,'sort_thr_created');
1208 elseif(stristr($order,'commented'))
1209 usort($parents,'sort_thr_commented');
1212 foreach($parents as $i=>$_x)
1213 $parents[$i]['children'] = get_item_children($arr, $_x);
1215 /*foreach($arr as $x) {
1216 if($x['id'] != $x['parent']) {
1217 $p = find_thread_parent_index($parents,$x);
1219 $parents[$p]['children'][] = $x;
1222 if(count($parents)) {
1223 foreach($parents as $k => $v) {
1224 if(count($parents[$k]['children'])) {
1225 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1226 /*$y = $parents[$k]['children'];
1227 usort($y,'sort_thr_created_rev');
1228 $parents[$k]['children'] = $y;*/
1234 if(count($parents)) {
1235 foreach($parents as $x) {
1237 if(count($x['children']))
1238 add_children_to_list($x['children'], $ret);
1239 /*foreach($x['children'] as $y)
1248 function sort_thr_created($a,$b) {
1249 return strcmp($b['created'],$a['created']);
1252 function sort_thr_created_rev($a,$b) {
1253 return strcmp($a['created'],$b['created']);
1256 function sort_thr_commented($a,$b) {
1257 return strcmp($b['commented'],$a['commented']);
1260 function find_thread_parent_index($arr,$x) {
1261 foreach($arr as $k => $v)
1262 if($v['id'] == $x['parent'])
1267 function render_location_google($item) {
1268 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1269 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1272 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1274 $location = '<span class="smalltext">' . $coord . '</span>';