4 * Render actions localized
6 function localize_item(&$item){
10 $img_start = strpos($Text,'[img]data:');
11 $img_end = strpos($Text,'[/img]');
13 if($img_start !== false && $img_end !== false && $img_end > $img_start) {
14 $start_fragment = substr($Text,0,$img_start);
15 $img_start += strlen('[img]');
16 $saved_image = substr($Text,$img_start,$img_end - $img_start);
17 $end_fragment = substr($Text,$img_end + strlen('[/img]'));
18 $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
19 $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
20 $replace = '[url=' . z_path() . '/redir/' . $item['contact-id']
21 . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
23 $Text = preg_replace($search,$replace,$Text);
25 if(strlen($saved_image))
26 $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
29 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
30 if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
32 $r = q("SELECT * from `item`,`contact` WHERE
33 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
34 dbesc($item['parent-uri']));
35 if(count($r)==0) return;
38 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
39 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
43 switch ($obj['object-type']){
44 case ACTIVITY_OBJ_EVENT:
45 $post_type = t('event');
48 $post_type = t('status');
52 if($obj['resource-id']){
53 $post_type = t('photo');
54 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
57 $post_type = t('status');
61 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
63 switch($item['verb']){
65 $bodyverb = t('%1$s likes %2$s\'s %3$s');
67 case ACTIVITY_DISLIKE:
68 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
71 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
74 if ($item['verb']=== ACTIVITY_FRIEND){
76 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
78 $Aname = $item['author-name'];
79 $Alink = $item['author-link'];
81 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
83 $obj = parse_xml_string($xmlhead.$item['object']);
84 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
87 $Blink = ""; $Bphoto = "";
88 foreach ($links->link as $l){
89 $atts = $l->attributes();
91 case "alternate": $Blink = $atts['href'];
92 case "photo": $Bphoto = $atts['href'];
97 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
98 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
99 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
101 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
104 if ($item['verb']===ACTIVITY_TAG){
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=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
112 $objauthor = '[url=' . zrl($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');
133 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
135 $parsedobj = parse_xml_string($xmlhead.$item['object']);
137 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
138 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
141 if ($item['verb']=== ACTIVITY_FAVORITE){
143 if ($item['object-type']== "")
146 $Aname = $item['author-name'];
147 $Alink = $item['author-link'];
149 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
151 $obj = parse_xml_string($xmlhead.$item['object']);
152 if(strlen($obj->id)) {
153 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
157 if(count($r) && $r[0]['plink']) {
159 $Bname = $target['author-name'];
160 $Blink = $target['author-link'];
161 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
162 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
163 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
164 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
170 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
171 foreach($matches as $mtch) {
172 if(! strpos($mtch[1],'zrl='))
173 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
181 * "Render" a conversation or list of items for HTML display.
182 * There are two major forms of display:
183 * - Sequential or unthreaded ("New Item View" or search results)
184 * - conversation view
185 * The $mode parameter decides between the various renderings and also
186 * figures out how to determine page owner and other contextual items
187 * that are based on unique features of the calling module.
191 if(!function_exists('conversation')) {
192 function conversation(&$a, $items, $mode, $update, $preview = false) {
195 require_once('bbcode.php');
197 $ssl_state = ((local_user()) ? true : false);
200 $page_writeable = false;
202 $previewing = (($preview) ? ' preview ' : '');
204 if($mode === 'network') {
205 $profile_owner = local_user();
206 $page_writeable = true;
209 if($mode === 'profile') {
210 $profile_owner = $a->profile['profile_uid'];
211 $page_writeable = can_write_wall($a,$profile_owner);
214 if($mode === 'notes') {
215 $profile_owner = local_user();
216 $page_writeable = true;
219 if($mode === 'display') {
220 $profile_owner = $a->profile['uid'];
221 $page_writeable = can_write_wall($a,$profile_owner);
224 if($mode === 'community') {
226 $page_writeable = false;
230 $return_url = $_SESSION['return_url'];
232 $return_url = $_SESSION['return_url'] = $a->query_string;
234 load_contact_links(local_user());
236 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
237 call_hooks('conversation_start',$cb);
239 $items = $cb['items'];
241 $cmnt_tpl = get_markup_template('comment_item.tpl');
242 $tpl = 'wall_item.tpl';
243 $wallwall = 'wallwall_item.tpl';
244 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
250 // array with html for each thread (parent+comments)
254 if($items && count($items)) {
256 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
258 // "New Item View" on network page or search page results
259 // - just loop through the items and format them minimally for display
261 //$tpl = get_markup_template('search_item.tpl');
262 $tpl = 'search_item.tpl';
264 foreach($items as $item) {
273 if($mode === 'search' || $mode === 'community') {
274 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
275 && ($item['id'] != $item['parent']))
277 $nickname = $item['nickname'];
280 $nickname = $a->user['nickname'];
282 // prevent private email from leaking.
283 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
286 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
287 if($item['author-link'] && (! $item['author-name']))
288 $profile_name = $item['author-link'];
293 $profile_link = best_link_url($item,$sp);
294 if($profile_link === 'mailbox')
297 $sparkle = ' sparkle';
299 $profile_link = zrl($profile_link);
301 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
302 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
303 $profile_avatar = $a->contacts[$normalised]['thumb'];
305 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
307 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
308 call_hooks('render_location',$locate);
310 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
312 localize_item($item);
313 if($mode === 'network-new')
320 'dropping' => $dropping,
321 'select' => t('Select'),
322 'delete' => t('Delete'),
326 $isstarred = "unstarred";
329 $likebuttons = false;
332 $body = prepare_body($item,true);
334 //$tmp_item = replace_macros($tpl,array(
337 'id' => (($preview) ? 'P0' : $item['item_id']),
338 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
339 'profile_url' => $profile_link,
340 'item_photo_menu' => item_photo_menu($item),
341 'name' => template_escape($profile_name),
342 'sparkle' => $sparkle,
344 'thumb' => $profile_avatar,
345 'title' => template_escape($item['title']),
346 'body' => template_escape($body),
347 'text' => strip_tags(template_escape($body)),
348 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
349 'location' => template_escape($location),
351 'owner_name' => template_escape($owner_name),
352 'owner_url' => $owner_url,
353 'owner_photo' => $owner_photo,
354 'plink' => get_plink($item),
356 'isstarred' => $isstarred,
359 'vote' => $likebuttons,
363 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
364 'previewing' => $previewing,
365 'wait' => t('Please wait'),
368 $arr = array('item' => $item, 'output' => $tmp_item);
369 call_hooks('display_item', $arr);
371 $threads[$threadsid]['id'] = $item['item_id'];
372 $threads[$threadsid]['items'] = array($arr['output']);
382 // Figure out how many comments each parent has
383 // (Comments all have gravity of 6)
384 // Store the result in the $comments array
387 foreach($items as $item) {
388 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
389 if(! x($comments,$item['parent']))
390 $comments[$item['parent']] = 1;
392 $comments[$item['parent']] += 1;
393 } elseif(! x($comments,$item['parent']))
394 $comments[$item['parent']] = 0; // avoid notices later on
397 // map all the like/dislike activities for each parent item
398 // Store these in the $alike and $dlike arrays
400 foreach($items as $item) {
401 like_puller($a,$item,$alike,'like');
402 like_puller($a,$item,$dlike,'dislike');
405 $comments_collapsed = false;
407 $comment_lastcollapsed = false;
408 $comment_firstcollapsed = false;
413 foreach($items as $item) {
419 $owner_url = $owner_photo = $owner_name = '';
421 // We've already parsed out like/dislike for special treatment. We can ignore them now
423 if(((activity_match($item['verb'],ACTIVITY_LIKE))
424 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
425 && ($item['id'] != $item['parent']))
428 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
429 $toplevelprivate = false;
431 // Take care of author collapsing and comment collapsing
432 // (author collapsing is currently disabled)
433 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
434 // If there are more than two comments, squash all but the last 2.
437 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
438 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
441 $comments_collapsed = false;
442 $comment_lastcollapsed = false;
443 $comment_firstcollapsed = false;
446 $threads[$threadsid]['id'] = $item['item_id'];
447 $threads[$threadsid]['private'] = $item['private'];
448 $threads[$threadsid]['items'] = array();
453 // prevent private email reply to public conversation from leaking.
454 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
458 $comment_lastcollapsed = false;
459 $comment_firstcollapsed = false;
462 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
463 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
466 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
468 if (!$comments_collapsed){
469 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
470 $threads[$threadsid]['hide_text'] = t('show more');
471 $comments_collapsed = true;
472 $comment_firstcollapsed = true;
475 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
477 $comment_lastcollapsed = true;
480 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
482 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
483 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
484 ? t('Private Message')
488 // Top-level wall post not written by the wall owner (wall-to-wall)
489 // First figure out who owns it.
493 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
497 // On the network page, I am the owner. On the display page it will be the profile owner.
498 // This will have been stored in $a->page_contact by our calling page.
499 // Put this person on the left of the wall-to-wall notice.
501 $owner_url = zrl($a->page_contact['url']);
502 $owner_photo = $a->page_contact['thumb'];
503 $owner_name = $a->page_contact['name'];
504 $template = $wallwall;
507 if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
511 $owner_url = $item['owner-link'];
512 $owner_photo = $item['owner-avatar'];
513 $owner_name = $item['owner-name'];
514 $template = $wallwall;
516 // If it is our contact, use a friendly redirect link
517 if((link_compare($item['owner-link'],$item['url']))
518 && ($item['network'] === NETWORK_DFRN)) {
519 $owner_url = $redirect_url;
520 $osparkle = ' sparkle';
523 $owner_url = zrl($owner_url);
528 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
530 if($page_writeable) {
532 $likebuttons = array(
533 'like' => array( t("I like this \x28toggle\x29"), t("like")),
534 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
536 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
539 $qc = $qcomment = null;
541 if(in_array('qcomment',$a->plugins)) {
542 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
543 $qcomment = (($qc) ? explode("\n",$qc) : null);
546 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
547 $comment = replace_macros($cmnt_tpl,array(
548 '$return_path' => '',
549 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
550 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
551 '$id' => $item['item_id'],
552 '$parent' => $item['parent'],
553 '$qcomment' => $qcomment,
554 '$profile_uid' => $profile_owner,
555 '$mylink' => $a->contact['url'],
556 '$mytitle' => t('This is you'),
557 '$myphoto' => $a->contact['thumb'],
558 '$comment' => t('Comment'),
559 '$submit' => t('Submit'),
560 '$edbold' => t('Bold'),
561 '$editalic' => t('Italic'),
562 '$eduline' => t('Underline'),
563 '$edquote' => t('Quote'),
564 '$edcode' => t('Code'),
565 '$edimg' => t('Image'),
566 '$edurl' => t('Link'),
567 '$edvideo' => t('Video'),
568 '$preview' => t('Preview'),
569 '$ww' => (($mode === 'network') ? $commentww : '')
574 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
575 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
582 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
586 'dropping' => $dropping,
587 'select' => t('Select'),
588 'delete' => t('Delete'),
594 $isstarred = "unstarred";
595 if ($profile_owner == local_user()) {
597 $isstarred = (($item['starred']) ? "starred" : "unstarred");
600 'do' => t("add star"),
601 'undo' => t("remove star"),
602 'toggle' => t("toggle star status"),
603 'classdo' => (($item['starred']) ? "hidden" : ""),
604 'classundo' => (($item['starred']) ? "" : "hidden"),
605 'starred' => t('starred'),
606 'tagger' => t("add tag"),
610 $filer = t("save to folder");
614 $photo = $item['photo'];
615 $thumb = $item['thumb'];
617 // Post was remotely authored.
619 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
621 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
623 if($item['author-link'] && (! $item['author-name']))
624 $profile_name = $item['author-link'];
627 $profile_link = best_link_url($item,$sp);
628 if($profile_link === 'mailbox')
631 $sparkle = ' sparkle';
633 $profile_link = zrl($profile_link);
635 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
636 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
637 $profile_avatar = $a->contacts[$normalised]['thumb'];
639 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
641 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
642 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
644 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
645 call_hooks('render_location',$locate);
647 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
649 $indent = (($toplevelpost) ? '' : ' comment');
651 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
655 localize_item($item);
659 foreach(explode(',',$item['tag']) as $tag){
661 if ($tag!="") $tags[] = bbcode($tag);
666 $body = prepare_body($item,true);
667 //$tmp_item = replace_macros($template,
669 // collapse comments in template. I don't like this much...
670 'comment_firstcollapsed' => $comment_firstcollapsed,
671 'comment_lastcollapsed' => $comment_lastcollapsed,
672 // template to use to render item (wall, walltowall, search)
673 'template' => $template,
675 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
677 'body' => template_escape($body),
678 'text' => strip_tags(template_escape($body)),
679 'id' => $item['item_id'],
680 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
681 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
683 'wall' => t('Wall-to-Wall'),
684 'vwall' => t('via Wall-To-Wall:'),
685 'profile_url' => $profile_link,
686 'item_photo_menu' => item_photo_menu($item),
687 'name' => template_escape($profile_name),
688 'thumb' => $profile_avatar,
689 'osparkle' => $osparkle,
690 'sparkle' => $sparkle,
691 'title' => template_escape($item['title']),
692 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
694 'location' => template_escape($location),
696 'owner_url' => $owner_url,
697 'owner_photo' => $owner_photo,
698 'owner_name' => template_escape($owner_name),
699 'plink' => get_plink($item),
701 'isstarred' => $isstarred,
705 'vote' => $likebuttons,
707 'dislike' => $dislike,
708 'comment' => $comment,
709 'previewing' => $previewing,
710 'wait' => t('Please wait'),
715 $arr = array('item' => $item, 'output' => $tmp_item);
716 call_hooks('display_item', $arr);
718 $threads[$threadsid]['items'][] = $arr['output'];
723 $page_template = get_markup_template("conversation.tpl");
724 $o = replace_macros($page_template, array(
725 '$baseurl' => $a->get_baseurl($ssl_state),
728 '$threads' => $threads,
729 '$dropping' => ($dropping?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());
783 $profile_link = best_link_url($item,$sparkle,$ssl_state);
784 if($profile_link === 'mailbox')
788 $cid = intval(basename($profile_link));
789 $status_link = $profile_link . "?url=status";
790 $photos_link = $profile_link . "?url=photos";
791 $profile_link = $profile_link . "?url=profile";
792 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
796 $profile_link = zrl($profile_link);
797 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
798 $cid = $item['contact-id'];
804 if(($cid) && (! $item['self'])) {
805 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
806 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
808 $clean_url = normalise_link($item['author-link']);
810 if((local_user()) && (local_user() == $item['uid'])) {
811 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
812 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
813 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
821 t("View Status") => $status_link,
822 t("View Profile") => $profile_link,
823 t("View Photos") => $photos_link,
824 t("Network Posts") => $posts_link,
825 t("Edit Contact") => $contact_url,
826 t("Send PM") => $pm_url,
830 $args = array('item' => $item, 'menu' => $menu);
832 call_hooks('item_photo_menu', $args);
834 $menu = $args['menu'];
837 foreach($menu as $k=>$v){
838 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
843 if(! function_exists('like_puller')) {
844 function like_puller($a,$item,&$arr,$mode) {
848 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
850 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
851 $url = $item['author-link'];
852 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
853 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
854 $sparkle = ' class="sparkle" ';
858 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
859 $arr[$item['parent'] . '-l'] = array();
860 if(! isset($arr[$item['parent']]))
861 $arr[$item['parent']] = 1;
863 $arr[$item['parent']] ++;
864 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
869 // Format the like/dislike text for a profile item
870 // $cnt = number of people who like/dislike the item
871 // $arr = array of pre-linked names of likers/dislikers
872 // $type = one of 'like, 'dislike'
874 // returns formatted text
876 if(! function_exists('format_like')) {
877 function format_like($cnt,$arr,$type,$id) {
880 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
882 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
883 $o .= (($type === 'like') ?
884 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
886 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
888 $total = count($arr);
889 if($total >= MAX_LIKERS)
890 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
891 if($total < MAX_LIKERS)
892 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
893 $str = implode(', ', $arr);
894 if($total >= MAX_LIKERS)
895 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
896 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
897 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
903 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
907 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
910 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
913 $tpl = get_markup_template('jot-header.tpl');
915 $a->page['htmlhead'] .= replace_macros($tpl, array(
916 '$newpost' => 'true',
917 '$baseurl' => $a->get_baseurl(true),
918 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
919 '$geotag' => $geotag,
920 '$nickname' => $x['nickname'],
921 '$ispublic' => t('Visible to <strong>everybody</strong>'),
922 '$linkurl' => t('Please enter a link URL:'),
923 '$vidurl' => t("Please enter a video link/URL:"),
924 '$audurl' => t("Please enter an audio link/URL:"),
925 '$term' => t('Tag term:'),
926 '$fileas' => t('Save to Folder:'),
927 '$whereareu' => t('Where are you right now?')
931 $tpl = get_markup_template("jot.tpl");
936 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
938 $mail_enabled = false;
939 $pubmail_enabled = false;
941 if(($x['is_owner']) && (! $mail_disabled)) {
942 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
946 $mail_enabled = true;
947 if(intval($r[0]['pubmail']))
948 $pubmail_enabled = true;
953 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
954 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
957 call_hooks('jot_tool', $jotplugins);
958 call_hooks('jot_networks', $jotnets);
961 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
963 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
965 $o .= replace_macros($tpl,array(
966 '$return_path' => $a->query_string,
967 '$action' => $a->get_baseurl(true) . '/item',
968 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
969 '$upload' => t('Upload photo'),
970 '$shortupload' => t('upload photo'),
971 '$attach' => t('Attach file'),
972 '$shortattach' => t('attach file'),
973 '$weblink' => t('Insert web link'),
974 '$shortweblink' => t('web link'),
975 '$video' => t('Insert video link'),
976 '$shortvideo' => t('video link'),
977 '$audio' => t('Insert audio link'),
978 '$shortaudio' => t('audio link'),
979 '$setloc' => t('Set your location'),
980 '$shortsetloc' => t('set location'),
981 '$noloc' => t('Clear browser location'),
982 '$shortnoloc' => t('clear location'),
984 '$placeholdertitle' => t('Set title'),
986 '$placeholdercategory' => t('Categories (comma-separated list)'),
987 '$wait' => t('Please wait'),
988 '$permset' => t('Permission settings'),
989 '$shortpermset' => t('permissions'),
990 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
993 '$baseurl' => $a->get_baseurl(true),
994 '$defloc' => $x['default_location'],
995 '$visitor' => $x['visitor'],
996 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
997 '$emailcc' => t('CC: email addresses'),
998 '$public' => t('Public post'),
999 '$jotnets' => $jotnets,
1000 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1001 '$lockstate' => $x['lockstate'],
1002 '$acl' => $x['acl'],
1003 '$bang' => $x['bang'],
1004 '$profile_uid' => $x['profile_uid'],
1005 '$preview' => t('Preview'),
1010 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1018 function conv_sort($arr,$order) {
1020 if((!(is_array($arr) && count($arr))))
1026 if($x['id'] == $x['parent'])
1029 if(stristr($order,'created'))
1030 usort($parents,'sort_thr_created');
1031 elseif(stristr($order,'commented'))
1032 usort($parents,'sort_thr_commented');
1035 foreach($parents as $i=>$_x)
1036 $parents[$i]['children'] = array();
1038 foreach($arr as $x) {
1039 if($x['id'] != $x['parent']) {
1040 $p = find_thread_parent_index($parents,$x);
1042 $parents[$p]['children'][] = $x;
1045 if(count($parents)) {
1046 foreach($parents as $k => $v) {
1047 if(count($parents[$k]['children'])) {
1048 $y = $parents[$k]['children'];
1049 usort($y,'sort_thr_created_rev');
1050 $parents[$k]['children'] = $y;
1056 if(count($parents)) {
1057 foreach($parents as $x) {
1059 if(count($x['children']))
1060 foreach($x['children'] as $y)
1069 function sort_thr_created($a,$b) {
1070 return strcmp($b['created'],$a['created']);
1073 function sort_thr_created_rev($a,$b) {
1074 return strcmp($a['created'],$b['created']);
1077 function sort_thr_commented($a,$b) {
1078 return strcmp($b['commented'],$a['commented']);
1081 function find_thread_parent_index($arr,$x) {
1082 foreach($arr as $k => $v)
1083 if($v['id'] == $x['parent'])
1088 function render_location_google($item) {
1089 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1090 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1093 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1095 $location = '<span class="smalltext">' . $coord . '</span>';