3 require_once("include/bbcode.php");
6 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
7 // is identical to the code in mod/message.php for 'item_extract_images' and
8 // 'item_redir_and_replace_images'
9 if(! function_exists('item_extract_images')) {
10 function item_extract_images($body) {
12 $saved_image = array();
17 $img_start = strpos($orig_body, '[img');
18 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
19 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
20 while(($img_st_close !== false) && ($img_end !== false)) {
22 $img_st_close++; // make it point to AFTER the closing bracket
23 $img_end += $img_start;
25 if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
26 // This is an embedded image
28 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
29 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
34 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
36 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
38 if($orig_body === false) // in case the body ends on a closing image tag
41 $img_start = strpos($orig_body, '[img');
42 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
43 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
46 $new_body = $new_body . $orig_body;
48 return array('body' => $new_body, 'images' => $saved_image);
51 if(! function_exists('item_redir_and_replace_images')) {
52 function item_redir_and_replace_images($body, $images, $cid) {
58 $pos = get_bb_tag_pos($origbody, 'url', 1);
59 while($pos !== false && $cnt < 1000) {
61 $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
62 $replace = '[url=' . z_path() . '/redir/' . $cid
63 . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
65 $newbody .= substr($origbody, 0, $pos['start']['open']);
66 $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
67 $origbody = substr($origbody, $pos['end']['close']);
68 if($origbody === false)
71 $subject = preg_replace($search, $replace, $subject);
75 $pos = get_bb_tag_pos($origbody, 'url', 1);
77 $newbody .= $origbody;
80 foreach($images as $image) {
81 // We're depending on the property of 'foreach' (specified on the PHP website) that
82 // it loops over the array starting from the first element and going sequentially
83 // to the last element
84 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
93 * Render actions localized
95 function localize_item(&$item){
97 $extracted = item_extract_images($item['body']);
98 if($extracted['images'])
99 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
101 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
102 if (activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)){
104 $r = q("SELECT * from `item`,`contact` WHERE
105 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
106 dbesc($item['parent-uri']));
107 if(count($r)==0) return;
110 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
111 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
113 switch($obj['verb']){
115 switch ($obj['object-type']){
116 case ACTIVITY_OBJ_EVENT:
117 $post_type = t('event');
120 $post_type = t('status');
124 if($obj['resource-id']){
125 $post_type = t('photo');
126 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
127 $rr['plink'] = $m[1];
129 $post_type = t('status');
133 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
135 if(activity_match($item['verb'],ACTIVITY_LIKE)) {
136 $bodyverb = t('%1$s likes %2$s\'s %3$s');
138 elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) {
139 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
141 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
144 if (activity_match($item['verb'],ACTIVITY_FRIEND)) {
146 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
148 $Aname = $item['author-name'];
149 $Alink = $item['author-link'];
151 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
153 $obj = parse_xml_string($xmlhead.$item['object']);
154 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
156 $Bname = $obj->title;
157 $Blink = ""; $Bphoto = "";
158 foreach ($links->link as $l){
159 $atts = $l->attributes();
160 switch($atts['rel']){
161 case "alternate": $Blink = $atts['href'];
162 case "photo": $Bphoto = $atts['href'];
167 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
168 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
169 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
171 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
174 if (stristr($item['verb'],ACTIVITY_POKE)) {
175 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
178 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
180 $Aname = $item['author-name'];
181 $Alink = $item['author-link'];
183 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
185 $obj = parse_xml_string($xmlhead.$item['object']);
186 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
188 $Bname = $obj->title;
189 $Blink = ""; $Bphoto = "";
190 foreach ($links->link as $l){
191 $atts = $l->attributes();
192 switch($atts['rel']){
193 case "alternate": $Blink = $atts['href'];
194 case "photo": $Bphoto = $atts['href'];
199 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
200 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
201 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
203 // we can't have a translation string with three positions but no distinguishable text
204 // So here is the translate string.
206 $txt = t('%1$s poked %2$s');
208 // now translate the verb
210 $txt = str_replace( t('poked'), 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) {
372 require_once('include/bbcode.php');
374 $ssl_state = ((local_user()) ? true : false);
377 $page_writeable = false;
378 $live_update_div = '';
380 $previewing = (($preview) ? ' preview ' : '');
382 if($mode === 'network') {
383 $profile_owner = local_user();
384 $page_writeable = true;
386 // The special div is needed for liveUpdate to kick in for this page.
387 // We only launch liveUpdate if you aren't filtering in some incompatible
388 // way and also you aren't writing a comment (discovered in javascript).
390 $live_update_div = '<div id="live-network"></div>' . "\r\n"
391 . "<script> var profile_uid = " . $_SESSION['uid']
392 . "; var netargs = '" . substr($a->cmd,8)
394 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
395 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
396 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
397 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
398 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
399 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
400 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
401 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
402 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
403 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
404 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
405 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
407 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
410 else if($mode === 'profile') {
411 $profile_owner = $a->profile['profile_uid'];
412 $page_writeable = can_write_wall($a,$profile_owner);
415 $tab = notags(trim($_GET['tab']));
416 $tab = ( $tab ? $tab : 'posts' );
417 if($tab === 'posts') {
418 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
419 // because browser prefetching might change it on us. We have to deliver it with the page.
421 $live_update_div = '<div id="live-profile"></div>' . "\r\n"
422 . "<script> var profile_uid = " . $a->profile['profile_uid']
423 . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
427 else if($mode === 'notes') {
428 $profile_owner = local_user();
429 $page_writeable = true;
431 $live_update_div = '<div id="live-notes"></div>' . "\r\n"
432 . "<script> var profile_uid = " . local_user()
433 . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
436 else if($mode === 'display') {
437 $profile_owner = $a->profile['uid'];
438 $page_writeable = can_write_wall($a,$profile_owner);
440 $live_update_div = '<div id="live-display"></div>' . "\r\n"
441 . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
442 . " var profile_page = 1; </script>";
445 else if($mode === 'community') {
447 $page_writeable = false;
449 $live_update_div = '<div id="live-community"></div>' . "\r\n"
450 . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
453 else if($mode === 'search') {
454 $live_update_div = '<div id="live-search"></div>' . "\r\n";
457 $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
461 $return_url = $_SESSION['return_url'];
463 $return_url = $_SESSION['return_url'] = $a->query_string;
465 load_contact_links(local_user());
467 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
468 call_hooks('conversation_start',$cb);
470 $items = $cb['items'];
472 $cmnt_tpl = get_markup_template('comment_item.tpl');
473 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
479 // array with html for each thread (parent+comments)
483 $page_template = get_markup_template("conversation.tpl");
485 if($items && count($items)) {
487 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
489 // "New Item View" on network page or search page results
490 // - just loop through the items and format them minimally for display
492 // $tpl = get_markup_template('search_item.tpl');
493 $tpl = 'search_item.tpl';
495 foreach($items as $item) {
504 if($mode === 'search' || $mode === 'community') {
505 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
506 && ($item['id'] != $item['parent']))
508 $nickname = $item['nickname'];
511 $nickname = $a->user['nickname'];
513 // prevent private email from leaking.
514 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
517 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
518 if($item['author-link'] && (! $item['author-name']))
519 $profile_name = $item['author-link'];
527 $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
528 intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
530 foreach($taglist as $tag) {
532 if ($tag["url"] == "")
533 $tag["url"] = $searchpath.strtolower($tag["term"]);
535 if ($tag["type"] == TERM_HASHTAG) {
536 $hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
538 } elseif ($tag["type"] == TERM_MENTION) {
539 $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
542 $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
545 /*foreach(explode(',',$item['tag']) as $tag){
558 $profile_link = best_link_url($item,$sp);
559 if($profile_link === 'mailbox')
562 $sparkle = ' sparkle';
564 $profile_link = zrl($profile_link);
566 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
567 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
568 $profile_avatar = $a->contacts[$normalised]['thumb'];
570 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
572 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
573 call_hooks('render_location',$locate);
575 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
577 localize_item($item);
578 if($mode === 'network-new')
585 'dropping' => $dropping,
586 'pagedrop' => $page_dropping,
587 'select' => t('Select'),
588 'delete' => t('Delete'),
592 $isstarred = "unstarred";
595 $likebuttons = false;
598 $body = prepare_body($item,true);
601 list($categories, $folders) = get_cats_and_terms($item);
603 if($a->theme['template_engine'] === 'internal') {
604 $profile_name_e = template_escape($profile_name);
605 $item['title_e'] = template_escape($item['title']);
606 $body_e = template_escape($body);
607 $tags_e = template_escape($tags);
608 $hashtags_e = template_escape($hashtags);
609 $mentions_e = template_escape($mentions);
610 $location_e = template_escape($location);
611 $owner_name_e = template_escape($owner_name);
614 $profile_name_e = $profile_name;
615 $item['title_e'] = $item['title'];
618 $hashtags_e = $hashtags;
619 $mentions_e = $mentions;
620 $location_e = $location;
621 $owner_name_e = $owner_name;
626 'id' => (($preview) ? 'P0' : $item['item_id']),
627 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
628 'profile_url' => $profile_link,
629 'item_photo_menu' => item_photo_menu($item),
630 'name' => $profile_name_e,
631 'sparkle' => $sparkle,
633 'thumb' => $profile_avatar,
634 'title' => $item['title_e'],
637 'hashtags' => $hashtags_e,
638 'mentions' => $mentions_e,
639 'txt_cats' => t('Categories:'),
640 'txt_folders' => t('Filed under:'),
641 'has_cats' => ((count($categories)) ? 'true' : ''),
642 'has_folders' => ((count($folders)) ? 'true' : ''),
643 'categories' => $categories,
644 'folders' => $folders,
645 'text' => strip_tags($body_e),
646 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
647 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
648 'location' => $location_e,
650 'owner_name' => $owner_name_e,
651 'owner_url' => $owner_url,
652 'owner_photo' => $owner_photo,
653 'plink' => get_plink($item),
655 'isstarred' => $isstarred,
658 'vote' => $likebuttons,
662 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
663 'previewing' => $previewing,
664 'wait' => t('Please wait'),
668 $arr = array('item' => $item, 'output' => $tmp_item);
669 call_hooks('display_item', $arr);
671 $threads[$threadsid]['id'] = $item['item_id'];
672 $threads[$threadsid]['items'] = array($arr['output']);
680 $page_template = get_markup_template("threaded_conversation.tpl");
682 require_once('object/Conversation.php');
683 require_once('object/Item.php');
685 $conv = new Conversation($mode, $preview);
687 // get all the topmost parents
688 // this shouldn't be needed, as we should have only them in our array
689 // But for now, this array respects the old style, just in case
692 foreach($items as $item) {
694 // Can we put this after the visibility check?
695 like_puller($a,$item,$alike,'like');
696 like_puller($a,$item,$dlike,'dislike');
698 // Only add what is visible
699 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
702 if(! visible_activity($item)) {
706 $item['pagedrop'] = $page_dropping;
708 if($item['id'] == $item['parent']) {
709 $item_object = new Item($item);
710 $conv->add_thread($item_object);
714 $threads = $conv->get_template_data($alike, $dlike);
716 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
722 $o = replace_macros($page_template, array(
723 '$baseurl' => $a->get_baseurl($ssl_state),
724 '$live_update' => $live_update_div,
725 '$remove' => t('remove'),
728 '$threads' => $threads,
729 '$dropping' => ($page_dropping && feature_enabled(local_user(),'multi_delete') ? t('Delete Selected Items') : False),
735 function best_link_url($item,&$sparkle,$ssl_state = false) {
742 $clean_url = normalise_link($item['author-link']);
744 if((local_user()) && (local_user() == $item['uid'])) {
745 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
746 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
747 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
751 $best_url = $a->contacts[$clean_url]['url'];
755 if(strlen($item['author-link']))
756 $best_url = $item['author-link'];
758 $best_url = $item['url'];
765 if(! function_exists('item_photo_menu')){
766 function item_photo_menu($item){
773 if(! count($a->contacts))
774 load_contact_links(local_user());
784 if((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
785 $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
789 $profile_link = best_link_url($item,$sparkle,$ssl_state);
790 if($profile_link === 'mailbox')
794 $cid = intval(basename($profile_link));
795 $status_link = $profile_link . "?url=status";
796 $photos_link = $profile_link . "?url=photos";
797 $profile_link = $profile_link . "?url=profile";
798 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
802 $profile_link = zrl($profile_link);
803 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
804 $cid = $item['contact-id'];
810 if(($cid) && (! $item['self'])) {
811 $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
812 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
813 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
815 $clean_url = normalise_link($item['author-link']);
817 if((local_user()) && (local_user() == $item['uid'])) {
818 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
819 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
820 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
828 t("Follow Thread") => $sub_link,
829 t("View Status") => $status_link,
830 t("View Profile") => $profile_link,
831 t("View Photos") => $photos_link,
832 t("Network Posts") => $posts_link,
833 t("Edit Contact") => $contact_url,
834 t("Send PM") => $pm_url,
835 t("Poke") => $poke_link
839 $args = array('item' => $item, 'menu' => $menu);
841 call_hooks('item_photo_menu', $args);
843 $menu = $args['menu'];
846 foreach($menu as $k=>$v){
847 if(strpos($v,'javascript:') === 0) {
849 $o .= "<li><a href=\"#\" onclick=\"$v\">$k</a></li>\n";
851 elseif ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
856 if(! function_exists('like_puller')) {
857 function like_puller($a,$item,&$arr,$mode) {
861 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
863 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
864 $url = $item['author-link'];
865 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
866 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
867 $sparkle = ' class="sparkle" ';
872 if(! $item['thr-parent'])
873 $item['thr-parent'] = $item['parent-uri'];
875 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
876 $arr[$item['thr-parent'] . '-l'] = array();
877 if(! isset($arr[$item['thr-parent']]))
878 $arr[$item['thr-parent']] = 1;
880 $arr[$item['thr-parent']] ++;
881 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
886 // Format the like/dislike text for a profile item
887 // $cnt = number of people who like/dislike the item
888 // $arr = array of pre-linked names of likers/dislikers
889 // $type = one of 'like, 'dislike'
891 // returns formatted text
893 if(! function_exists('format_like')) {
894 function format_like($cnt,$arr,$type,$id) {
897 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
899 //$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
902 // $phrase = sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt);
903 $mood = t('like this');
906 // $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt);
907 $mood = t('don\'t like this');
910 $tpl = get_markup_template("voting_fakelink.tpl");
911 $phrase = replace_macros($tpl, array(
912 '$vote_id' => $type . 'list-' . $id,
914 '$people' => t('people'),
915 '$vote_mood' => $mood
920 $total = count($arr);
921 if($total >= MAX_LIKERS)
922 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
923 if($total < MAX_LIKERS) {
924 $last = t('and') . ' ' . $arr[count($arr)-1];
925 $arr2 = array_slice($arr, 0, -1);
926 $str = implode(', ', $arr2) . ' ' . $last;
928 if($total >= MAX_LIKERS) {
929 $str = implode(', ', $arr);
930 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
932 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
933 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
939 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
943 $geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
945 /* $plaintext = false;
946 if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
949 if( local_user() && feature_enabled(local_user(),'richtext') )
952 $tpl = get_markup_template('jot-header.tpl');
953 $a->page['htmlhead'] .= replace_macros($tpl, array(
954 '$newpost' => 'true',
955 '$baseurl' => $a->get_baseurl(true),
956 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
957 '$geotag' => $geotag,
958 '$nickname' => $x['nickname'],
959 '$ispublic' => t('Visible to <strong>everybody</strong>'),
960 '$linkurl' => t('Please enter a link URL:'),
961 '$vidurl' => t("Please enter a video link/URL:"),
962 '$audurl' => t("Please enter an audio link/URL:"),
963 '$term' => t('Tag term:'),
964 '$fileas' => t('Save to Folder:'),
965 '$whereareu' => t('Where are you right now?'),
966 '$delitems' => t('Delete item(s)?')
970 $tpl = get_markup_template('jot-end.tpl');
971 $a->page['end'] .= replace_macros($tpl, array(
972 '$newpost' => 'true',
973 '$baseurl' => $a->get_baseurl(true),
974 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
975 '$geotag' => $geotag,
976 '$nickname' => $x['nickname'],
977 '$ispublic' => t('Visible to <strong>everybody</strong>'),
978 '$linkurl' => t('Please enter a link URL:'),
979 '$vidurl' => t("Please enter a video link/URL:"),
980 '$audurl' => t("Please enter an audio link/URL:"),
981 '$term' => t('Tag term:'),
982 '$fileas' => t('Save to Folder:'),
983 '$whereareu' => t('Where are you right now?')
987 $tpl = get_markup_template("jot.tpl");
992 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
994 $mail_enabled = false;
995 $pubmail_enabled = false;
997 if(($x['is_owner']) && (! $mail_disabled)) {
998 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
1002 $mail_enabled = true;
1003 if(intval($r[0]['pubmail']))
1004 $pubmail_enabled = true;
1009 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
1010 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
1013 call_hooks('jot_tool', $jotplugins);
1014 call_hooks('jot_networks', $jotnets);
1017 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
1019 // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1021 $o .= replace_macros($tpl,array(
1022 '$return_path' => $a->query_string,
1023 '$action' => $a->get_baseurl(true) . '/item',
1024 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1025 '$upload' => t('Upload photo'),
1026 '$shortupload' => t('upload photo'),
1027 '$attach' => t('Attach file'),
1028 '$shortattach' => t('attach file'),
1029 '$weblink' => t('Insert web link'),
1030 '$shortweblink' => t('web link'),
1031 '$video' => t('Insert video link'),
1032 '$shortvideo' => t('video link'),
1033 '$audio' => t('Insert audio link'),
1034 '$shortaudio' => t('audio link'),
1035 '$setloc' => t('Set your location'),
1036 '$shortsetloc' => t('set location'),
1037 '$noloc' => t('Clear browser location'),
1038 '$shortnoloc' => t('clear location'),
1040 '$placeholdertitle' => t('Set title'),
1042 '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''),
1043 '$wait' => t('Please wait'),
1044 '$permset' => t('Permission settings'),
1045 '$shortpermset' => t('permissions'),
1046 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1049 '$baseurl' => $a->get_baseurl(true),
1050 '$defloc' => $x['default_location'],
1051 '$visitor' => $x['visitor'],
1052 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1053 '$emailcc' => t('CC: email addresses'),
1054 '$public' => t('Public post'),
1055 '$jotnets' => $jotnets,
1056 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1057 '$lockstate' => $x['lockstate'],
1058 '$acl' => $x['acl'],
1059 '$bang' => $x['bang'],
1060 '$profile_uid' => $x['profile_uid'],
1061 '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
1062 '$jotplugins' => $jotplugins,
1063 '$sourceapp' => t($a->sourcename),
1064 '$cancel' => t('Cancel'),
1065 '$rand_num' => random_digits(12)
1070 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1078 function get_item_children($arr, $parent) {
1079 $children = array();
1081 foreach($arr as $item) {
1082 if($item['id'] != $item['parent']) {
1083 if(get_config('system','thread_allow') && $a->theme_thread_allow) {
1084 // Fallback to parent-uri if thr-parent is not set
1085 $thr_parent = $item['thr-parent'];
1086 if($thr_parent == '')
1087 $thr_parent = $item['parent-uri'];
1089 if($thr_parent == $parent['uri']) {
1090 $item['children'] = get_item_children($arr, $item);
1091 $children[] = $item;
1094 else if($item['parent'] == $parent['id']) {
1095 $children[] = $item;
1102 function sort_item_children($items) {
1104 usort($result,'sort_thr_created_rev');
1105 foreach($result as $k => $i) {
1106 if(count($result[$k]['children'])) {
1107 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1113 function add_children_to_list($children, &$arr) {
1114 foreach($children as $y) {
1116 if(count($y['children']))
1117 add_children_to_list($y['children'], $arr);
1121 function conv_sort($arr,$order) {
1123 if((!(is_array($arr) && count($arr))))
1127 $children = array();
1130 if($x['id'] == $x['parent'])
1133 if(stristr($order,'created'))
1134 usort($parents,'sort_thr_created');
1135 elseif(stristr($order,'commented'))
1136 usort($parents,'sort_thr_commented');
1139 foreach($parents as $i=>$_x)
1140 $parents[$i]['children'] = get_item_children($arr, $_x);
1142 /*foreach($arr as $x) {
1143 if($x['id'] != $x['parent']) {
1144 $p = find_thread_parent_index($parents,$x);
1146 $parents[$p]['children'][] = $x;
1149 if(count($parents)) {
1150 foreach($parents as $k => $v) {
1151 if(count($parents[$k]['children'])) {
1152 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1153 /*$y = $parents[$k]['children'];
1154 usort($y,'sort_thr_created_rev');
1155 $parents[$k]['children'] = $y;*/
1161 if(count($parents)) {
1162 foreach($parents as $x) {
1164 if(count($x['children']))
1165 add_children_to_list($x['children'], $ret);
1166 /*foreach($x['children'] as $y)
1175 function sort_thr_created($a,$b) {
1176 return strcmp($b['created'],$a['created']);
1179 function sort_thr_created_rev($a,$b) {
1180 return strcmp($a['created'],$b['created']);
1183 function sort_thr_commented($a,$b) {
1184 return strcmp($b['commented'],$a['commented']);
1187 function find_thread_parent_index($arr,$x) {
1188 foreach($arr as $k => $v)
1189 if($v['id'] == $x['parent'])
1194 function render_location_google($item) {
1195 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1196 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1199 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1201 $location = '<span class="smalltext">' . $coord . '</span>';