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']);
180 * "Render" a conversation or list of items for HTML display.
181 * There are two major forms of display:
182 * - Sequential or unthreaded ("New Item View" or search results)
183 * - conversation view
184 * The $mode parameter decides between the various renderings and also
185 * figures out how to determine page owner and other contextual items
186 * that are based on unique features of the calling module.
190 if(!function_exists('conversation')) {
191 function conversation(&$a, $items, $mode, $update, $preview = false) {
194 require_once('bbcode.php');
196 $ssl_state = ((local_user()) ? true : false);
199 $page_writeable = false;
201 $previewing = (($preview) ? ' preview ' : '');
203 if($mode === 'network') {
204 $profile_owner = local_user();
205 $page_writeable = true;
208 if($mode === 'profile') {
209 $profile_owner = $a->profile['profile_uid'];
210 $page_writeable = can_write_wall($a,$profile_owner);
213 if($mode === 'notes') {
214 $profile_owner = local_user();
215 $page_writeable = true;
218 if($mode === 'display') {
219 $profile_owner = $a->profile['uid'];
220 $page_writeable = can_write_wall($a,$profile_owner);
223 if($mode === 'community') {
225 $page_writeable = false;
229 $return_url = $_SESSION['return_url'];
231 $return_url = $_SESSION['return_url'] = $a->query_string;
233 load_contact_links(local_user());
235 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
236 call_hooks('conversation_start',$cb);
238 $items = $cb['items'];
240 $cmnt_tpl = get_markup_template('comment_item.tpl');
241 $tpl = 'wall_item.tpl';
242 $wallwall = 'wallwall_item.tpl';
243 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
249 // array with html for each thread (parent+comments)
253 if($items && count($items)) {
255 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
257 // "New Item View" on network page or search page results
258 // - just loop through the items and format them minimally for display
260 //$tpl = get_markup_template('search_item.tpl');
261 $tpl = 'search_item.tpl';
263 foreach($items as $item) {
272 if($mode === 'search' || $mode === 'community') {
273 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
274 && ($item['id'] != $item['parent']))
276 $nickname = $item['nickname'];
279 $nickname = $a->user['nickname'];
281 // prevent private email from leaking.
282 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
285 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
286 if($item['author-link'] && (! $item['author-name']))
287 $profile_name = $item['author-link'];
292 $profile_link = best_link_url($item,$sp);
293 if($profile_link === 'mailbox')
296 $sparkle = ' sparkle';
298 $profile_link = zrl($profile_link);
300 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
301 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
302 $profile_avatar = $a->contacts[$normalised]['thumb'];
304 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
306 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
307 call_hooks('render_location',$locate);
309 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
311 localize_item($item);
312 if($mode === 'network-new')
319 'dropping' => $dropping,
320 'select' => t('Select'),
321 'delete' => t('Delete'),
325 $isstarred = "unstarred";
328 $likebuttons = false;
331 $body = prepare_body($item,true);
333 //$tmp_item = replace_macros($tpl,array(
336 'id' => (($preview) ? 'P0' : $item['item_id']),
337 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
338 'profile_url' => $profile_link,
339 'item_photo_menu' => item_photo_menu($item),
340 'name' => template_escape($profile_name),
341 'sparkle' => $sparkle,
343 'thumb' => $profile_avatar,
344 'title' => template_escape($item['title']),
345 'body' => template_escape($body),
346 'text' => strip_tags(template_escape($body)),
347 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
348 'location' => template_escape($location),
350 'owner_name' => template_escape($owner_name),
351 'owner_url' => $owner_url,
352 'owner_photo' => $owner_photo,
353 'plink' => get_plink($item),
355 'isstarred' => $isstarred,
358 'vote' => $likebuttons,
362 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
363 'previewing' => $previewing,
364 'wait' => t('Please wait'),
367 $arr = array('item' => $item, 'output' => $tmp_item);
368 call_hooks('display_item', $arr);
370 $threads[$threadsid]['id'] = $item['item_id'];
371 $threads[$threadsid]['items'] = array($arr['output']);
381 // Figure out how many comments each parent has
382 // (Comments all have gravity of 6)
383 // Store the result in the $comments array
386 foreach($items as $item) {
387 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
388 if(! x($comments,$item['parent']))
389 $comments[$item['parent']] = 1;
391 $comments[$item['parent']] += 1;
392 } elseif(! x($comments,$item['parent']))
393 $comments[$item['parent']] = 0; // avoid notices later on
396 // map all the like/dislike activities for each parent item
397 // Store these in the $alike and $dlike arrays
399 foreach($items as $item) {
400 like_puller($a,$item,$alike,'like');
401 like_puller($a,$item,$dlike,'dislike');
404 $comments_collapsed = false;
406 $comment_lastcollapsed = false;
407 $comment_firstcollapsed = false;
412 foreach($items as $item) {
418 $owner_url = $owner_photo = $owner_name = '';
420 // We've already parsed out like/dislike for special treatment. We can ignore them now
422 if(((activity_match($item['verb'],ACTIVITY_LIKE))
423 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
424 && ($item['id'] != $item['parent']))
427 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
428 $toplevelprivate = false;
430 // Take care of author collapsing and comment collapsing
431 // (author collapsing is currently disabled)
432 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
433 // If there are more than two comments, squash all but the last 2.
436 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
437 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
440 $comments_collapsed = false;
441 $comment_lastcollapsed = false;
442 $comment_firstcollapsed = false;
445 $threads[$threadsid]['id'] = $item['item_id'];
446 $threads[$threadsid]['private'] = $item['private'];
447 $threads[$threadsid]['items'] = array();
452 // prevent private email reply to public conversation from leaking.
453 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
457 $comment_lastcollapsed = false;
458 $comment_firstcollapsed = false;
461 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
462 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
465 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
467 if (!$comments_collapsed){
468 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
469 $threads[$threadsid]['hide_text'] = t('show more');
470 $comments_collapsed = true;
471 $comment_firstcollapsed = true;
474 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
476 $comment_lastcollapsed = true;
479 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
481 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
482 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
483 ? t('Private Message')
487 // Top-level wall post not written by the wall owner (wall-to-wall)
488 // First figure out who owns it.
492 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
496 // On the network page, I am the owner. On the display page it will be the profile owner.
497 // This will have been stored in $a->page_contact by our calling page.
498 // Put this person on the left of the wall-to-wall notice.
500 $owner_url = zrl($a->page_contact['url']);
501 $owner_photo = $a->page_contact['thumb'];
502 $owner_name = $a->page_contact['name'];
503 $template = $wallwall;
506 if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
510 $owner_url = $item['owner-link'];
511 $owner_photo = $item['owner-avatar'];
512 $owner_name = $item['owner-name'];
513 $template = $wallwall;
515 // If it is our contact, use a friendly redirect link
516 if((link_compare($item['owner-link'],$item['url']))
517 && ($item['network'] === NETWORK_DFRN)) {
518 $owner_url = $redirect_url;
519 $osparkle = ' sparkle';
522 $owner_url = zrl($owner_url);
527 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
529 if($page_writeable) {
531 $likebuttons = array(
532 'like' => array( t("I like this \x28toggle\x29"), t("like")),
533 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
535 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
538 $qc = $qcomment = null;
540 if(in_array('qcomment',$a->plugins)) {
541 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
542 $qcomment = (($qc) ? explode("\n",$qc) : null);
545 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
546 $comment = replace_macros($cmnt_tpl,array(
547 '$return_path' => '',
548 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
549 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
550 '$id' => $item['item_id'],
551 '$parent' => $item['parent'],
552 '$qcomment' => $qcomment,
553 '$profile_uid' => $profile_owner,
554 '$mylink' => $a->contact['url'],
555 '$mytitle' => t('This is you'),
556 '$myphoto' => $a->contact['thumb'],
557 '$comment' => t('Comment'),
558 '$submit' => t('Submit'),
559 '$edbold' => t('Bold'),
560 '$editalic' => t('Italic'),
561 '$eduline' => t('Underline'),
562 '$edquote' => t('Quote'),
563 '$edcode' => t('Code'),
564 '$edimg' => t('Image'),
565 '$edurl' => t('Link'),
566 '$edvideo' => t('Video'),
567 '$preview' => t('Preview'),
568 '$ww' => (($mode === 'network') ? $commentww : '')
573 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
574 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
581 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
585 'dropping' => $dropping,
586 'select' => t('Select'),
587 'delete' => t('Delete'),
593 $isstarred = "unstarred";
594 if ($profile_owner == local_user()) {
596 $isstarred = (($item['starred']) ? "starred" : "unstarred");
599 'do' => t("add star"),
600 'undo' => t("remove star"),
601 'toggle' => t("toggle star status"),
602 'classdo' => (($item['starred']) ? "hidden" : ""),
603 'classundo' => (($item['starred']) ? "" : "hidden"),
604 'starred' => t('starred'),
605 'tagger' => t("add tag"),
609 $filer = t("save to folder");
613 $photo = $item['photo'];
614 $thumb = $item['thumb'];
616 // Post was remotely authored.
618 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
620 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
622 if($item['author-link'] && (! $item['author-name']))
623 $profile_name = $item['author-link'];
626 $profile_link = best_link_url($item,$sp);
627 if($profile_link === 'mailbox')
630 $sparkle = ' sparkle';
632 $profile_link = zrl($profile_link);
634 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
635 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
636 $profile_avatar = $a->contacts[$normalised]['thumb'];
638 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
640 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
641 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
643 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
644 call_hooks('render_location',$locate);
646 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
648 $indent = (($toplevelpost) ? '' : ' comment');
650 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
654 localize_item($item);
658 foreach(explode(',',$item['tag']) as $tag){
660 if ($tag!="") $tags[] = bbcode($tag);
665 $body = prepare_body($item,true);
666 //$tmp_item = replace_macros($template,
668 // collapse comments in template. I don't like this much...
669 'comment_firstcollapsed' => $comment_firstcollapsed,
670 'comment_lastcollapsed' => $comment_lastcollapsed,
671 // template to use to render item (wall, walltowall, search)
672 'template' => $template,
674 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
676 'body' => template_escape($body),
677 'text' => strip_tags(template_escape($body)),
678 'id' => $item['item_id'],
679 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
680 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
682 'wall' => t('Wall-to-Wall'),
683 'vwall' => t('via Wall-To-Wall:'),
684 'profile_url' => $profile_link,
685 'item_photo_menu' => item_photo_menu($item),
686 'name' => template_escape($profile_name),
687 'thumb' => $profile_avatar,
688 'osparkle' => $osparkle,
689 'sparkle' => $sparkle,
690 'title' => template_escape($item['title']),
691 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
693 'location' => template_escape($location),
695 'owner_url' => $owner_url,
696 'owner_photo' => $owner_photo,
697 'owner_name' => template_escape($owner_name),
698 'plink' => get_plink($item),
700 'isstarred' => $isstarred,
704 'vote' => $likebuttons,
706 'dislike' => $dislike,
707 'comment' => $comment,
708 'previewing' => $previewing,
709 'wait' => t('Please wait'),
714 $arr = array('item' => $item, 'output' => $tmp_item);
715 call_hooks('display_item', $arr);
717 $threads[$threadsid]['items'][] = $arr['output'];
722 $page_template = get_markup_template("conversation.tpl");
723 $o = replace_macros($page_template, array(
724 '$baseurl' => $a->get_baseurl($ssl_state),
727 '$threads' => $threads,
728 '$dropping' => ($dropping?t('Delete Selected Items'):False),
734 function best_link_url($item,&$sparkle,$ssl_state = false) {
741 $clean_url = normalise_link($item['author-link']);
743 if((local_user()) && (local_user() == $item['uid'])) {
744 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
745 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
746 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
750 $best_url = $a->contacts[$clean_url]['url'];
754 if(strlen($item['author-link']))
755 $best_url = $item['author-link'];
757 $best_url = $item['url'];
764 if(! function_exists('item_photo_menu')){
765 function item_photo_menu($item){
772 if(! count($a->contacts))
773 load_contact_links(local_user());
782 $profile_link = best_link_url($item,$sparkle,$ssl_state);
783 if($profile_link === 'mailbox')
787 $cid = intval(basename($profile_link));
788 $status_link = $profile_link . "?url=status";
789 $photos_link = $profile_link . "?url=photos";
790 $profile_link = $profile_link . "?url=profile";
791 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
795 $profile_link = zrl($profile_link);
796 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
797 $cid = $item['contact-id'];
803 if(($cid) && (! $item['self'])) {
804 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
805 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
807 $clean_url = normalise_link($item['author-link']);
809 if((local_user()) && (local_user() == $item['uid'])) {
810 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
811 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
812 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
820 t("View Status") => $status_link,
821 t("View Profile") => $profile_link,
822 t("View Photos") => $photos_link,
823 t("Network Posts") => $posts_link,
824 t("Edit Contact") => $contact_url,
825 t("Send PM") => $pm_url,
829 $args = array('item' => $item, 'menu' => $menu);
831 call_hooks('item_photo_menu', $args);
833 $menu = $args['menu'];
836 foreach($menu as $k=>$v){
837 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
842 if(! function_exists('like_puller')) {
843 function like_puller($a,$item,&$arr,$mode) {
847 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
849 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
850 $url = $item['author-link'];
851 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
852 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
853 $sparkle = ' class="sparkle" ';
857 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
858 $arr[$item['parent'] . '-l'] = array();
859 if(! isset($arr[$item['parent']]))
860 $arr[$item['parent']] = 1;
862 $arr[$item['parent']] ++;
863 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
868 // Format the like/dislike text for a profile item
869 // $cnt = number of people who like/dislike the item
870 // $arr = array of pre-linked names of likers/dislikers
871 // $type = one of 'like, 'dislike'
873 // returns formatted text
875 if(! function_exists('format_like')) {
876 function format_like($cnt,$arr,$type,$id) {
879 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
881 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
882 $o .= (($type === 'like') ?
883 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
885 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
887 $total = count($arr);
888 if($total >= MAX_LIKERS)
889 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
890 if($total < MAX_LIKERS)
891 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
892 $str = implode(', ', $arr);
893 if($total >= MAX_LIKERS)
894 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
895 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
896 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
902 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
906 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
909 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
912 $tpl = get_markup_template('jot-header.tpl');
914 $a->page['htmlhead'] .= replace_macros($tpl, array(
915 '$newpost' => 'true',
916 '$baseurl' => $a->get_baseurl(true),
917 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
918 '$geotag' => $geotag,
919 '$nickname' => $x['nickname'],
920 '$ispublic' => t('Visible to <strong>everybody</strong>'),
921 '$linkurl' => t('Please enter a link URL:'),
922 '$vidurl' => t("Please enter a video link/URL:"),
923 '$audurl' => t("Please enter an audio link/URL:"),
924 '$term' => t('Tag term:'),
925 '$fileas' => t('Save to Folder:'),
926 '$whereareu' => t('Where are you right now?')
930 $tpl = get_markup_template("jot.tpl");
935 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
937 $mail_enabled = false;
938 $pubmail_enabled = false;
940 if(($x['is_owner']) && (! $mail_disabled)) {
941 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
945 $mail_enabled = true;
946 if(intval($r[0]['pubmail']))
947 $pubmail_enabled = true;
952 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
953 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
956 call_hooks('jot_tool', $jotplugins);
957 call_hooks('jot_networks', $jotnets);
960 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
962 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
964 $o .= replace_macros($tpl,array(
965 '$return_path' => $a->query_string,
966 '$action' => $a->get_baseurl(true) . '/item',
967 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
968 '$upload' => t('Upload photo'),
969 '$shortupload' => t('upload photo'),
970 '$attach' => t('Attach file'),
971 '$shortattach' => t('attach file'),
972 '$weblink' => t('Insert web link'),
973 '$shortweblink' => t('web link'),
974 '$video' => t('Insert video link'),
975 '$shortvideo' => t('video link'),
976 '$audio' => t('Insert audio link'),
977 '$shortaudio' => t('audio link'),
978 '$setloc' => t('Set your location'),
979 '$shortsetloc' => t('set location'),
980 '$noloc' => t('Clear browser location'),
981 '$shortnoloc' => t('clear location'),
983 '$placeholdertitle' => t('Set title'),
985 '$placeholdercategory' => t('Categories (comma-separated list)'),
986 '$wait' => t('Please wait'),
987 '$permset' => t('Permission settings'),
988 '$shortpermset' => t('permissions'),
989 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
992 '$baseurl' => $a->get_baseurl(true),
993 '$defloc' => $x['default_location'],
994 '$visitor' => $x['visitor'],
995 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
996 '$emailcc' => t('CC: email addresses'),
997 '$public' => t('Public post'),
998 '$jotnets' => $jotnets,
999 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1000 '$lockstate' => $x['lockstate'],
1001 '$acl' => $x['acl'],
1002 '$bang' => $x['bang'],
1003 '$profile_uid' => $x['profile_uid'],
1004 '$preview' => t('Preview'),
1009 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1017 function conv_sort($arr,$order) {
1019 if((!(is_array($arr) && count($arr))))
1025 if($x['id'] == $x['parent'])
1028 if(stristr($order,'created'))
1029 usort($parents,'sort_thr_created');
1030 elseif(stristr($order,'commented'))
1031 usort($parents,'sort_thr_commented');
1034 foreach($parents as $i=>$_x)
1035 $parents[$i]['children'] = array();
1037 foreach($arr as $x) {
1038 if($x['id'] != $x['parent']) {
1039 $p = find_thread_parent_index($parents,$x);
1041 $parents[$p]['children'][] = $x;
1044 if(count($parents)) {
1045 foreach($parents as $k => $v) {
1046 if(count($parents[$k]['children'])) {
1047 $y = $parents[$k]['children'];
1048 usort($y,'sort_thr_created_rev');
1049 $parents[$k]['children'] = $y;
1055 if(count($parents)) {
1056 foreach($parents as $x) {
1058 if(count($x['children']))
1059 foreach($x['children'] as $y)
1068 function sort_thr_created($a,$b) {
1069 return strcmp($b['created'],$a['created']);
1072 function sort_thr_created_rev($a,$b) {
1073 return strcmp($a['created'],$b['created']);
1076 function sort_thr_commented($a,$b) {
1077 return strcmp($b['commented'],$a['commented']);
1080 function find_thread_parent_index($arr,$x) {
1081 foreach($arr as $k => $v)
1082 if($v['id'] == $x['parent'])
1087 function render_location_google($item) {
1088 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1089 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1092 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1094 $location = '<span class="smalltext">' . $coord . '</span>';