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.
207 $txt = t('%1$s poked %2$s');
209 // now translate the verb
211 $txt = str_replace( t('poked'), t($verb), $txt);
213 // then do the sprintf on the translation string
215 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
218 if (stristr($item['verb'],ACTIVITY_MOOD)) {
219 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
223 $Aname = $item['author-name'];
224 $Alink = $item['author-link'];
225 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
227 $txt = t('%1$s is currently %2$s');
229 $item['body'] = sprintf($txt, $A, t($verb));
232 if (activity_match($item['verb'],ACTIVITY_TAG)) {
233 $r = q("SELECT * from `item`,`contact` WHERE
234 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
235 dbesc($item['parent-uri']));
236 if(count($r)==0) return;
239 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
240 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
242 switch($obj['verb']){
244 switch ($obj['object-type']){
245 case ACTIVITY_OBJ_EVENT:
246 $post_type = t('event');
249 $post_type = t('status');
253 if($obj['resource-id']){
254 $post_type = t('photo');
255 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
256 $rr['plink'] = $m[1];
258 $post_type = t('status');
261 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
263 $parsedobj = parse_xml_string($xmlhead.$item['object']);
265 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
266 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
269 if (activity_match($item['verb'],ACTIVITY_FAVORITE)){
271 if ($item['object-type']== "")
274 $Aname = $item['author-name'];
275 $Alink = $item['author-link'];
277 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
279 $obj = parse_xml_string($xmlhead.$item['object']);
280 if(strlen($obj->id)) {
281 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
285 if(count($r) && $r[0]['plink']) {
287 $Bname = $target['author-name'];
288 $Blink = $target['author-link'];
289 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
290 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
291 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
292 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
298 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
299 foreach($matches as $mtch) {
300 if(! strpos($mtch[1],'zrl='))
301 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
305 // add zrl's to public images
306 $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
307 if(preg_match($photo_pattern,$item['body'])) {
308 $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
309 $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
312 // add sparkle links to appropriate permalinks
314 $x = stristr($item['plink'],'/display/');
317 $y = best_link_url($item,$sparkle,true);
318 if(strstr($y,'/redir/'))
319 $item['plink'] = $y . '?f=&url=' . $item['plink'];
327 * Count the total of comments on this item and its desendants
329 function count_descendants($item) {
330 $total = count($item['children']);
333 foreach($item['children'] as $child) {
334 if(! visible_activity($child))
336 $total += count_descendants($child);
343 function visible_activity($item) {
345 if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE))
348 if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
349 if(! (($item['self']) && ($item['uid'] == local_user()))) {
359 * "Render" a conversation or list of items for HTML display.
360 * There are two major forms of display:
361 * - Sequential or unthreaded ("New Item View" or search results)
362 * - conversation view
363 * The $mode parameter decides between the various renderings and also
364 * figures out how to determine page owner and other contextual items
365 * that are based on unique features of the calling module.
369 if(!function_exists('conversation')) {
370 function conversation(&$a, $items, $mode, $update, $preview = false) {
373 require_once('include/bbcode.php');
375 $ssl_state = ((local_user()) ? true : false);
378 $page_writeable = false;
379 $live_update_div = '';
381 $previewing = (($preview) ? ' preview ' : '');
383 if($mode === 'network') {
384 $profile_owner = local_user();
385 $page_writeable = true;
387 // The special div is needed for liveUpdate to kick in for this page.
388 // We only launch liveUpdate if you aren't filtering in some incompatible
389 // way and also you aren't writing a comment (discovered in javascript).
391 $live_update_div = '<div id="live-network"></div>' . "\r\n"
392 . "<script> var profile_uid = " . $_SESSION['uid']
393 . "; var netargs = '" . substr($a->cmd,8)
395 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
396 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
397 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
398 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
399 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
400 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
401 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
402 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
403 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
404 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
405 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
406 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
408 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
411 else if($mode === 'profile') {
412 $profile_owner = $a->profile['profile_uid'];
413 $page_writeable = can_write_wall($a,$profile_owner);
416 $tab = notags(trim($_GET['tab']));
417 $tab = ( $tab ? $tab : 'posts' );
418 if($tab === 'posts') {
419 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
420 // because browser prefetching might change it on us. We have to deliver it with the page.
422 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
423 . "<script> var profile_uid = " . $a->profile['profile_uid']
424 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
428 else if($mode === 'notes') {
429 $profile_owner = local_user();
430 $page_writeable = true;
432 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
433 . "<script> var profile_uid = " . local_user()
434 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
437 else if($mode === 'display') {
438 $profile_owner = $a->profile['uid'];
439 $page_writeable = can_write_wall($a,$profile_owner);
441 $live_update_div = '<div id="live-display"></div>' . "\r\n"
442 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
443 . " var profile_page = 1; </script>";
446 else if($mode === 'community') {
448 $page_writeable = false;
450 $live_update_div = '<div id="live-community"></div>' . "\r\n"
451 . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
454 else if($mode === 'search') {
455 $live_update_div = '<div id="live-search"></div>' . "\r\n";
458 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
462 $return_url = $_SESSION['return_url'];
464 $return_url = $_SESSION['return_url'] = $a->query_string;
466 load_contact_links(local_user());
468 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
469 call_hooks('conversation_start',$cb);
471 $items = $cb['items'];
473 $cmnt_tpl = get_markup_template('comment_item.tpl');
474 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
480 // array with html for each thread (parent+comments)
484 $page_template = get_markup_template("conversation.tpl");
486 if($items && count($items)) {
488 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
490 // "New Item View" on network page or search page results
491 // - just loop through the items and format them minimally for display
493 // $tpl = get_markup_template('search_item.tpl');
494 $tpl = 'search_item.tpl';
496 foreach($items as $item) {
505 if($mode === 'search' || $mode === 'community') {
506 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
507 && ($item['id'] != $item['parent']))
509 $nickname = $item['nickname'];
512 $nickname = $a->user['nickname'];
514 // prevent private email from leaking.
515 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
518 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
519 if($item['author-link'] && (! $item['author-name']))
520 $profile_name = $item['author-link'];
527 foreach(explode(',',$item['tag']) as $tag){
540 $profile_link = best_link_url($item,$sp);
541 if($profile_link === 'mailbox')
544 $sparkle = ' sparkle';
546 $profile_link = zrl($profile_link);
548 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
549 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
550 $profile_avatar = $a->contacts[$normalised]['thumb'];
552 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
554 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
555 call_hooks('render_location',$locate);
557 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
559 localize_item($item);
560 if($mode === 'network-new')
567 'dropping' => $dropping,
568 'pagedrop' => $page_dropping,
569 'select' => t('Select'),
570 'delete' => t('Delete'),
574 $isstarred = "unstarred";
577 $likebuttons = false;
580 $body = prepare_body($item,true);
583 list($categories, $folders) = get_cats_and_terms($item);
585 if($a->theme['template_engine'] === 'internal') {
586 $profile_name_e = template_escape($profile_name);
587 $item['title_e'] = template_escape($item['title']);
588 $body_e = template_escape($body);
589 $tags_e = template_escape($tags);
590 $hashtags_e = template_escape($hashtags);
591 $mentions_e = template_escape($mentions);
592 $location_e = template_escape($location);
593 $owner_name_e = template_escape($owner_name);
596 $profile_name_e = $profile_name;
597 $item['title_e'] = $item['title'];
600 $hashtags_e = $hashtags;
601 $mentions_e = $mentions;
602 $location_e = $location;
603 $owner_name_e = $owner_name;
608 'id' => (($preview) ? 'P0' : $item['item_id']),
609 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
610 'profile_url' => $profile_link,
611 'item_photo_menu' => item_photo_menu($item),
612 'name' => $profile_name_e,
613 'sparkle' => $sparkle,
615 'thumb' => $profile_avatar,
616 'title' => $item['title_e'],
619 'hashtags' => $hashtags_e,
620 'mentions' => $mentions_e,
621 'txt_cats' => t('Categories:'),
622 'txt_folders' => t('Filed under:'),
623 'has_cats' => ((count($categories)) ? 'true' : ''),
624 'has_folders' => ((count($folders)) ? 'true' : ''),
625 'categories' => $categories,
626 'folders' => $folders,
627 'text' => strip_tags($body_e),
628 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
629 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
630 'location' => $location_e,
632 'owner_name' => $owner_name_e,
633 'owner_url' => $owner_url,
634 'owner_photo' => $owner_photo,
635 'plink' => get_plink($item),
637 'isstarred' => $isstarred,
640 'vote' => $likebuttons,
644 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
645 'previewing' => $previewing,
646 'wait' => t('Please wait'),
650 $arr = array('item' => $item, 'output' => $tmp_item);
651 call_hooks('display_item', $arr);
653 $threads[$threadsid]['id'] = $item['item_id'];
654 $threads[$threadsid]['items'] = array($arr['output']);
662 $page_template = get_markup_template("threaded_conversation.tpl");
664 require_once('object/Conversation.php');
665 require_once('object/Item.php');
667 $conv = new Conversation($mode, $preview);
669 // get all the topmost parents
670 // this shouldn't be needed, as we should have only them in our array
671 // But for now, this array respects the old style, just in case
674 foreach($items as $item) {
676 // Can we put this after the visibility check?
677 like_puller($a,$item,$alike,'like');
678 like_puller($a,$item,$dlike,'dislike');
680 // Only add what is visible
681 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
684 if(! visible_activity($item)) {
688 call_hooks('display_item', $arr);
690 $item['pagedrop'] = $page_dropping;
692 if($item['id'] == $item['parent']) {
693 $item_object = new Item($item);
694 $conv->add_thread($item_object);
698 $threads = $conv->get_template_data($alike, $dlike);
700 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
706 $o = replace_macros($page_template, array(
707 '$baseurl' => $a->get_baseurl($ssl_state),
708 '$return_path' => $a->query_string,
709 '$live_update' => $live_update_div,
710 '$remove' => t('remove'),
713 '$threads' => $threads,
714 '$dropping' => ($page_dropping && feature_enabled(local_user(),'multi_delete') ? t('Delete Selected Items') : False),
720 function best_link_url($item,&$sparkle,$ssl_state = false) {
727 $clean_url = normalise_link($item['author-link']);
729 if((local_user()) && (local_user() == $item['uid'])) {
730 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
731 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
732 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
736 $best_url = $a->contacts[$clean_url]['url'];
740 if(strlen($item['author-link']))
741 $best_url = $item['author-link'];
743 $best_url = $item['url'];
750 if(! function_exists('item_photo_menu')){
751 function item_photo_menu($item){
758 if(! count($a->contacts))
759 load_contact_links(local_user());
769 if((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
770 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
774 $profile_link = best_link_url($item,$sparkle,$ssl_state);
775 if($profile_link === 'mailbox')
779 $cid = intval(basename($profile_link));
780 $status_link = $profile_link . "?url=status";
781 $photos_link = $profile_link . "?url=photos";
782 $profile_link = $profile_link . "?url=profile";
783 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
787 $profile_link = zrl($profile_link);
788 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
789 $cid = $item['contact-id'];
795 if(($cid) && (! $item['self'])) {
796 $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
797 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
798 $posts_link = $a->get_baseurl($ssl_state) . '/network/0?nets=all&cid=' . $cid;
800 $clean_url = normalise_link($item['author-link']);
802 if((local_user()) && (local_user() == $item['uid'])) {
803 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
804 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
805 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
813 t("Follow Thread") => $sub_link,
814 t("View Status") => $status_link,
815 t("View Profile") => $profile_link,
816 t("View Photos") => $photos_link,
817 t("Network Posts") => $posts_link,
818 t("Edit Contact") => $contact_url,
819 t("Send PM") => $pm_url,
820 t("Poke") => $poke_link
824 $args = array('item' => $item, 'menu' => $menu);
826 call_hooks('item_photo_menu', $args);
828 $menu = $args['menu'];
831 foreach($menu as $k=>$v){
832 if(strpos($v,'javascript:') === 0) {
834 $o .= "<li><a href=\"#\" onclick=\"$v\">$k</a></li>\n";
836 elseif ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
841 if(! function_exists('like_puller')) {
842 function like_puller($a,$item,&$arr,$mode) {
846 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
848 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
849 $url = $item['author-link'];
850 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
851 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
852 $sparkle = ' class="sparkle" ';
857 if(! $item['thr-parent'])
858 $item['thr-parent'] = $item['parent-uri'];
860 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
861 $arr[$item['thr-parent'] . '-l'] = array();
862 if(! isset($arr[$item['thr-parent']]))
863 $arr[$item['thr-parent']] = 1;
865 $arr[$item['thr-parent']] ++;
866 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
871 // Format the like/dislike text for a profile item
872 // $cnt = number of people who like/dislike the item
873 // $arr = array of pre-linked names of likers/dislikers
874 // $type = one of 'like, 'dislike'
876 // returns formatted text
878 if(! function_exists('format_like')) {
879 function format_like($cnt,$arr,$type,$id) {
882 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
884 $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
887 $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
890 $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
894 $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
895 '$phrase' => $phrase,
900 $total = count($arr);
901 if($total >= MAX_LIKERS)
902 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
903 if($total < MAX_LIKERS) {
904 $last = t('and') . ' ' . $arr[count($arr)-1];
905 $arr2 = array_slice($arr, 0, -1);
906 $str = implode(', ', $arr2) . ' ' . $last;
908 if($total >= MAX_LIKERS) {
909 $str = implode(', ', $arr);
910 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
912 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
913 $o .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
919 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
923 $geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
925 /* $plaintext = false;
926 if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
929 if( local_user() && feature_enabled(local_user(),'richtext') )
932 $tpl = get_markup_template('jot-header.tpl');
933 $a->page['htmlhead'] .= replace_macros($tpl, array(
934 '$newpost' => 'true',
935 '$baseurl' => $a->get_baseurl(true),
936 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
937 '$geotag' => $geotag,
938 '$nickname' => $x['nickname'],
939 '$ispublic' => t('Visible to <strong>everybody</strong>'),
940 '$linkurl' => t('Please enter a link URL:'),
941 '$vidurl' => t("Please enter a video link/URL:"),
942 '$audurl' => t("Please enter an audio link/URL:"),
943 '$term' => t('Tag term:'),
944 '$fileas' => t('Save to Folder:'),
945 '$whereareu' => t('Where are you right now?'),
946 '$delitems' => t('Delete item(s)?')
950 $tpl = get_markup_template('jot-end.tpl');
951 $a->page['end'] .= replace_macros($tpl, array(
952 '$newpost' => 'true',
953 '$baseurl' => $a->get_baseurl(true),
954 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
955 '$geotag' => $geotag,
956 '$nickname' => $x['nickname'],
957 '$ispublic' => t('Visible to <strong>everybody</strong>'),
958 '$linkurl' => t('Please enter a link URL:'),
959 '$vidurl' => t("Please enter a video link/URL:"),
960 '$audurl' => t("Please enter an audio link/URL:"),
961 '$term' => t('Tag term:'),
962 '$fileas' => t('Save to Folder:'),
963 '$whereareu' => t('Where are you right now?')
970 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
972 $mail_enabled = false;
973 $pubmail_enabled = false;
975 if(($x['is_owner']) && (! $mail_disabled)) {
976 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
980 $mail_enabled = true;
981 if(intval($r[0]['pubmail']))
982 $pubmail_enabled = true;
987 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
988 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
991 call_hooks('jot_tool', $jotplugins);
992 call_hooks('jot_networks', $jotnets);
995 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
998 // Private/public post links for the non-JS ACL form
1000 if($_REQUEST['public'])
1003 $query_str = $a->query_string;
1004 if(strpos($query_str, 'public=1') !== false)
1005 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1007 // I think $a->query_string may never have ? in it, but I could be wrong
1008 // It looks like it's from the index.php?q=[etc] rewrite that the web
1009 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1010 if(strpos($query_str, '?') === false)
1011 $public_post_link = '?public=1';
1013 $public_post_link = '&public=1';
1017 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1018 $tpl = get_markup_template("jot.tpl");
1020 $o .= replace_macros($tpl,array(
1021 '$return_path' => $query_str,
1022 '$action' => $a->get_baseurl(true) . '/item',
1023 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1024 '$upload' => t('Upload photo'),
1025 '$shortupload' => t('upload photo'),
1026 '$attach' => t('Attach file'),
1027 '$shortattach' => t('attach file'),
1028 '$weblink' => t('Insert web link'),
1029 '$shortweblink' => t('web link'),
1030 '$video' => t('Insert video link'),
1031 '$shortvideo' => t('video link'),
1032 '$audio' => t('Insert audio link'),
1033 '$shortaudio' => t('audio link'),
1034 '$setloc' => t('Set your location'),
1035 '$shortsetloc' => t('set location'),
1036 '$noloc' => t('Clear browser location'),
1037 '$shortnoloc' => t('clear location'),
1039 '$placeholdertitle' => t('Set title'),
1041 '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''),
1042 '$wait' => t('Please wait'),
1043 '$permset' => t('Permission settings'),
1044 '$shortpermset' => t('permissions'),
1045 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1048 '$baseurl' => $a->get_baseurl(true),
1049 '$defloc' => $x['default_location'],
1050 '$visitor' => $x['visitor'],
1051 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1052 '$emailcc' => t('CC: email addresses'),
1053 '$public' => t('Public post'),
1054 '$jotnets' => $jotnets,
1055 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1056 '$lockstate' => $x['lockstate'],
1057 '$bang' => $x['bang'],
1058 '$profile_uid' => $x['profile_uid'],
1059 '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1060 '$jotplugins' => $jotplugins,
1061 '$sourceapp' => t($a->sourcename),
1062 '$cancel' => t('Cancel'),
1063 '$rand_num' => random_digits(12),
1065 // ACL permissions box
1066 '$acl' => $x['acl'],
1067 '$acl_data' => $x['acl_data'],
1068 '$group_perms' => t('Post to Groups'),
1069 '$contact_perms' => t('Post to Contacts'),
1070 '$private' => t('Private post'),
1071 '$is_private' => $private_post,
1072 '$public_link' => $public_post_link,
1077 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1085 function get_item_children($arr, $parent) {
1086 $children = array();
1088 foreach($arr as $item) {
1089 if($item['id'] != $item['parent']) {
1090 if(get_config('system','thread_allow') && $a->theme_thread_allow) {
1091 // Fallback to parent-uri if thr-parent is not set
1092 $thr_parent = $item['thr-parent'];
1093 if($thr_parent == '')
1094 $thr_parent = $item['parent-uri'];
1096 if($thr_parent == $parent['uri']) {
1097 $item['children'] = get_item_children($arr, $item);
1098 $children[] = $item;
1101 else if($item['parent'] == $parent['id']) {
1102 $children[] = $item;
1109 function sort_item_children($items) {
1111 usort($result,'sort_thr_created_rev');
1112 foreach($result as $k => $i) {
1113 if(count($result[$k]['children'])) {
1114 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1120 function add_children_to_list($children, &$arr) {
1121 foreach($children as $y) {
1123 if(count($y['children']))
1124 add_children_to_list($y['children'], $arr);
1128 function conv_sort($arr,$order) {
1130 if((!(is_array($arr) && count($arr))))
1134 $children = array();
1137 if($x['id'] == $x['parent'])
1140 if(stristr($order,'created'))
1141 usort($parents,'sort_thr_created');
1142 elseif(stristr($order,'commented'))
1143 usort($parents,'sort_thr_commented');
1146 foreach($parents as $i=>$_x)
1147 $parents[$i]['children'] = get_item_children($arr, $_x);
1149 /*foreach($arr as $x) {
1150 if($x['id'] != $x['parent']) {
1151 $p = find_thread_parent_index($parents,$x);
1153 $parents[$p]['children'][] = $x;
1156 if(count($parents)) {
1157 foreach($parents as $k => $v) {
1158 if(count($parents[$k]['children'])) {
1159 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1160 /*$y = $parents[$k]['children'];
1161 usort($y,'sort_thr_created_rev');
1162 $parents[$k]['children'] = $y;*/
1168 if(count($parents)) {
1169 foreach($parents as $x) {
1171 if(count($x['children']))
1172 add_children_to_list($x['children'], $ret);
1173 /*foreach($x['children'] as $y)
1182 function sort_thr_created($a,$b) {
1183 return strcmp($b['created'],$a['created']);
1186 function sort_thr_created_rev($a,$b) {
1187 return strcmp($a['created'],$b['created']);
1190 function sort_thr_commented($a,$b) {
1191 return strcmp($b['commented'],$a['commented']);
1194 function find_thread_parent_index($arr,$x) {
1195 foreach($arr as $k => $v)
1196 if($v['id'] == $x['parent'])
1201 function render_location_google($item) {
1202 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1203 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1206 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1208 $location = '<span class="smalltext">' . $coord . '</span>';