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'];
282 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
283 if($item['author-link'] && (! $item['author-name']))
284 $profile_name = $item['author-link'];
289 $profile_link = best_link_url($item,$sp);
290 if($profile_link === 'mailbox')
293 $sparkle = ' sparkle';
295 $profile_link = zrl($profile_link);
297 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
298 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
299 $profile_avatar = $a->contacts[$normalised]['thumb'];
301 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
303 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
304 call_hooks('render_location',$locate);
306 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
308 localize_item($item);
309 if($mode === 'network-new')
316 'dropping' => $dropping,
317 'select' => t('Select'),
318 'delete' => t('Delete'),
322 $isstarred = "unstarred";
325 $likebuttons = false;
328 $body = prepare_body($item,true);
330 //$tmp_item = replace_macros($tpl,array(
333 'id' => (($preview) ? 'P0' : $item['item_id']),
334 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
335 'profile_url' => $profile_link,
336 'item_photo_menu' => item_photo_menu($item),
337 'name' => template_escape($profile_name),
338 'sparkle' => $sparkle,
340 'thumb' => $profile_avatar,
341 'title' => template_escape($item['title']),
342 'body' => template_escape($body),
343 'text' => strip_tags(template_escape($body)),
344 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
345 'location' => template_escape($location),
347 'owner_name' => template_escape($owner_name),
348 'owner_url' => $owner_url,
349 'owner_photo' => $owner_photo,
350 'plink' => get_plink($item),
352 'isstarred' => $isstarred,
355 'vote' => $likebuttons,
359 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
360 'previewing' => $previewing,
361 'wait' => t('Please wait'),
364 $arr = array('item' => $item, 'output' => $tmp_item);
365 call_hooks('display_item', $arr);
367 $threads[$threadsid]['id'] = $item['item_id'];
368 $threads[$threadsid]['items'] = array($arr['output']);
378 // Figure out how many comments each parent has
379 // (Comments all have gravity of 6)
380 // Store the result in the $comments array
383 foreach($items as $item) {
384 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
385 if(! x($comments,$item['parent']))
386 $comments[$item['parent']] = 1;
388 $comments[$item['parent']] += 1;
389 } elseif(! x($comments,$item['parent']))
390 $comments[$item['parent']] = 0; // avoid notices later on
393 // map all the like/dislike activities for each parent item
394 // Store these in the $alike and $dlike arrays
396 foreach($items as $item) {
397 like_puller($a,$item,$alike,'like');
398 like_puller($a,$item,$dlike,'dislike');
401 $comments_collapsed = false;
403 $comment_lastcollapsed = false;
404 $comment_firstcollapsed = false;
409 foreach($items as $item) {
415 $owner_url = $owner_photo = $owner_name = '';
417 // We've already parsed out like/dislike for special treatment. We can ignore them now
419 if(((activity_match($item['verb'],ACTIVITY_LIKE))
420 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
421 && ($item['id'] != $item['parent']))
424 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
425 $toplevelprivate = false;
427 // Take care of author collapsing and comment collapsing
428 // (author collapsing is currently disabled)
429 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
430 // If there are more than two comments, squash all but the last 2.
433 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
434 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
437 $comments_collapsed = false;
438 $comment_lastcollapsed = false;
439 $comment_firstcollapsed = false;
442 $threads[$threadsid]['id'] = $item['item_id'];
443 $threads[$threadsid]['private'] = $item['private'];
444 $threads[$threadsid]['items'] = array();
449 // prevent private email reply to public conversation from leaking.
450 if($item['private'] && ! $threads[$threadsid]['private'])
454 $comment_lastcollapsed = false;
455 $comment_firstcollapsed = false;
458 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
459 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
462 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
464 if (!$comments_collapsed){
465 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
466 $threads[$threadsid]['hide_text'] = t('show more');
467 $comments_collapsed = true;
468 $comment_firstcollapsed = true;
471 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
473 $comment_lastcollapsed = true;
476 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
478 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
479 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
480 ? t('Private Message')
484 // Top-level wall post not written by the wall owner (wall-to-wall)
485 // First figure out who owns it.
489 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
493 // On the network page, I am the owner. On the display page it will be the profile owner.
494 // This will have been stored in $a->page_contact by our calling page.
495 // Put this person on the left of the wall-to-wall notice.
497 $owner_url = zrl($a->page_contact['url']);
498 $owner_photo = $a->page_contact['thumb'];
499 $owner_name = $a->page_contact['name'];
500 $template = $wallwall;
503 if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
507 $owner_url = $item['owner-link'];
508 $owner_photo = $item['owner-avatar'];
509 $owner_name = $item['owner-name'];
510 $template = $wallwall;
512 // If it is our contact, use a friendly redirect link
513 if((link_compare($item['owner-link'],$item['url']))
514 && ($item['network'] === NETWORK_DFRN)) {
515 $owner_url = $redirect_url;
516 $osparkle = ' sparkle';
519 $owner_url = zrl($owner_url);
524 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
526 if($page_writeable) {
528 $likebuttons = array(
529 'like' => array( t("I like this \x28toggle\x29"), t("like")),
530 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
532 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
535 $qc = $qcomment = null;
537 if(in_array('qcomment',$a->plugins)) {
538 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
539 $qcomment = (($qc) ? explode("\n",$qc) : null);
542 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
543 $comment = replace_macros($cmnt_tpl,array(
544 '$return_path' => '',
545 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
546 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
547 '$id' => $item['item_id'],
548 '$parent' => $item['parent'],
549 '$qcomment' => $qcomment,
550 '$profile_uid' => $profile_owner,
551 '$mylink' => $a->contact['url'],
552 '$mytitle' => t('This is you'),
553 '$myphoto' => $a->contact['thumb'],
554 '$comment' => t('Comment'),
555 '$submit' => t('Submit'),
556 '$preview' => t('Preview'),
557 '$ww' => (($mode === 'network') ? $commentww : '')
562 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
563 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
570 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
574 'dropping' => $dropping,
575 'select' => t('Select'),
576 'delete' => t('Delete'),
582 $isstarred = "unstarred";
583 if ($profile_owner == local_user()) {
585 $isstarred = (($item['starred']) ? "starred" : "unstarred");
588 'do' => t("add star"),
589 'undo' => t("remove star"),
590 'toggle' => t("toggle star status"),
591 'classdo' => (($item['starred']) ? "hidden" : ""),
592 'classundo' => (($item['starred']) ? "" : "hidden"),
593 'starred' => t('starred'),
594 'tagger' => t("add tag"),
598 $filer = t("save to folder");
602 $photo = $item['photo'];
603 $thumb = $item['thumb'];
605 // Post was remotely authored.
607 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
609 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
611 if($item['author-link'] && (! $item['author-name']))
612 $profile_name = $item['author-link'];
615 $profile_link = best_link_url($item,$sp);
616 if($profile_link === 'mailbox')
619 $sparkle = ' sparkle';
621 $profile_link = zrl($profile_link);
623 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
624 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
625 $profile_avatar = $a->contacts[$normalised]['thumb'];
627 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
629 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
630 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
632 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
633 call_hooks('render_location',$locate);
635 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
637 $indent = (($toplevelpost) ? '' : ' comment');
639 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
643 localize_item($item);
647 foreach(explode(',',$item['tag']) as $tag){
649 if ($tag!="") $tags[] = bbcode($tag);
654 $body = prepare_body($item,true);
655 //$tmp_item = replace_macros($template,
657 // collapse comments in template. I don't like this much...
658 'comment_firstcollapsed' => $comment_firstcollapsed,
659 'comment_lastcollapsed' => $comment_lastcollapsed,
660 // template to use to render item (wall, walltowall, search)
661 'template' => $template,
663 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
665 'body' => template_escape($body),
666 'text' => strip_tags(template_escape($body)),
667 'id' => $item['item_id'],
668 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
669 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
671 'wall' => t('Wall-to-Wall'),
672 'vwall' => t('via Wall-To-Wall:'),
673 'profile_url' => $profile_link,
674 'item_photo_menu' => item_photo_menu($item),
675 'name' => template_escape($profile_name),
676 'thumb' => $profile_avatar,
677 'osparkle' => $osparkle,
678 'sparkle' => $sparkle,
679 'title' => template_escape($item['title']),
680 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
682 'location' => template_escape($location),
684 'owner_url' => $owner_url,
685 'owner_photo' => $owner_photo,
686 'owner_name' => template_escape($owner_name),
687 'plink' => get_plink($item),
689 'isstarred' => $isstarred,
693 'vote' => $likebuttons,
695 'dislike' => $dislike,
696 'comment' => $comment,
697 'previewing' => $previewing,
698 'wait' => t('Please wait'),
703 $arr = array('item' => $item, 'output' => $tmp_item);
704 call_hooks('display_item', $arr);
706 $threads[$threadsid]['items'][] = $arr['output'];
711 $page_template = get_markup_template("conversation.tpl");
712 $o = replace_macros($page_template, array(
713 '$baseurl' => $a->get_baseurl($ssl_state),
716 '$threads' => $threads,
717 '$dropping' => ($dropping?t('Delete Selected Items'):False),
723 function best_link_url($item,&$sparkle,$ssl_state = false) {
730 $clean_url = normalise_link($item['author-link']);
732 if((local_user()) && (local_user() == $item['uid'])) {
733 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
734 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
735 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
739 $best_url = $a->contacts[$clean_url]['url'];
743 if(strlen($item['author-link']))
744 $best_url = $item['author-link'];
746 $best_url = $item['url'];
753 if(! function_exists('item_photo_menu')){
754 function item_photo_menu($item){
761 if(! count($a->contacts))
762 load_contact_links(local_user());
771 $profile_link = best_link_url($item,$sparkle,$ssl_state);
772 if($profile_link === 'mailbox')
776 $cid = intval(basename($profile_link));
777 $status_link = $profile_link . "?url=status";
778 $photos_link = $profile_link . "?url=photos";
779 $profile_link = $profile_link . "?url=profile";
780 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
784 $profile_link = zrl($profile_link);
785 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
786 $cid = $item['contact-id'];
792 if(($cid) && (! $item['self'])) {
793 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
794 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
796 $clean_url = normalise_link($item['author-link']);
798 if((local_user()) && (local_user() == $item['uid'])) {
799 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
800 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
801 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
809 t("View Status") => $status_link,
810 t("View Profile") => $profile_link,
811 t("View Photos") => $photos_link,
812 t("Network Posts") => $posts_link,
813 t("Edit Contact") => $contact_url,
814 t("Send PM") => $pm_url,
818 $args = array('item' => $item, 'menu' => $menu);
820 call_hooks('item_photo_menu', $args);
822 $menu = $args['menu'];
825 foreach($menu as $k=>$v){
826 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
831 if(! function_exists('like_puller')) {
832 function like_puller($a,$item,&$arr,$mode) {
836 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
838 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
839 $url = $item['author-link'];
840 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
841 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
842 $sparkle = ' class="sparkle" ';
846 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
847 $arr[$item['parent'] . '-l'] = array();
848 if(! isset($arr[$item['parent']]))
849 $arr[$item['parent']] = 1;
851 $arr[$item['parent']] ++;
852 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
857 // Format the like/dislike text for a profile item
858 // $cnt = number of people who like/dislike the item
859 // $arr = array of pre-linked names of likers/dislikers
860 // $type = one of 'like, 'dislike'
862 // returns formatted text
864 if(! function_exists('format_like')) {
865 function format_like($cnt,$arr,$type,$id) {
868 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
870 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
871 $o .= (($type === 'like') ?
872 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
874 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
876 $total = count($arr);
877 if($total >= MAX_LIKERS)
878 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
879 if($total < MAX_LIKERS)
880 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
881 $str = implode(', ', $arr);
882 if($total >= MAX_LIKERS)
883 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
884 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
885 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
891 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
895 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
898 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
901 $tpl = get_markup_template('jot-header.tpl');
903 $a->page['htmlhead'] .= replace_macros($tpl, array(
904 '$newpost' => 'true',
905 '$baseurl' => $a->get_baseurl(true),
906 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
907 '$geotag' => $geotag,
908 '$nickname' => $x['nickname'],
909 '$ispublic' => t('Visible to <strong>everybody</strong>'),
910 '$linkurl' => t('Please enter a link URL:'),
911 '$vidurl' => t("Please enter a video link/URL:"),
912 '$audurl' => t("Please enter an audio link/URL:"),
913 '$term' => t('Tag term:'),
914 '$fileas' => t('Save to Folder:'),
915 '$whereareu' => t('Where are you right now?')
919 $tpl = get_markup_template("jot.tpl");
924 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
926 $mail_enabled = false;
927 $pubmail_enabled = false;
929 if(($x['is_owner']) && (! $mail_disabled)) {
930 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
934 $mail_enabled = true;
935 if(intval($r[0]['pubmail']))
936 $pubmail_enabled = true;
941 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
942 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
945 call_hooks('jot_tool', $jotplugins);
946 call_hooks('jot_networks', $jotnets);
949 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
951 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
953 $o .= replace_macros($tpl,array(
954 '$return_path' => $a->cmd,
955 '$action' => $a->get_baseurl(true) . '/item',
956 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
957 '$upload' => t('Upload photo'),
958 '$shortupload' => t('upload photo'),
959 '$attach' => t('Attach file'),
960 '$shortattach' => t('attach file'),
961 '$weblink' => t('Insert web link'),
962 '$shortweblink' => t('web link'),
963 '$video' => t('Insert video link'),
964 '$shortvideo' => t('video link'),
965 '$audio' => t('Insert audio link'),
966 '$shortaudio' => t('audio link'),
967 '$setloc' => t('Set your location'),
968 '$shortsetloc' => t('set location'),
969 '$noloc' => t('Clear browser location'),
970 '$shortnoloc' => t('clear location'),
972 '$placeholdertitle' => t('Set title'),
974 '$placeholdercategory' => t('Categories (comma-separated list)'),
975 '$wait' => t('Please wait'),
976 '$permset' => t('Permission settings'),
977 '$shortpermset' => t('permissions'),
978 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
981 '$baseurl' => $a->get_baseurl(true),
982 '$defloc' => $x['default_location'],
983 '$visitor' => $x['visitor'],
984 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
985 '$emailcc' => t('CC: email addresses'),
986 '$public' => t('Public post'),
987 '$jotnets' => $jotnets,
988 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
989 '$lockstate' => $x['lockstate'],
991 '$bang' => $x['bang'],
992 '$profile_uid' => $x['profile_uid'],
993 '$preview' => t('Preview'),
998 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1006 function conv_sort($arr,$order) {
1008 if((!(is_array($arr) && count($arr))))
1014 if($x['id'] == $x['parent'])
1017 if(stristr($order,'created'))
1018 usort($parents,'sort_thr_created');
1019 elseif(stristr($order,'commented'))
1020 usort($parents,'sort_thr_commented');
1023 foreach($parents as $i=>$_x)
1024 $parents[$i]['children'] = array();
1026 foreach($arr as $x) {
1027 if($x['id'] != $x['parent']) {
1028 $p = find_thread_parent_index($parents,$x);
1030 $parents[$p]['children'][] = $x;
1033 if(count($parents)) {
1034 foreach($parents as $k => $v) {
1035 if(count($parents[$k]['children'])) {
1036 $y = $parents[$k]['children'];
1037 usort($y,'sort_thr_created_rev');
1038 $parents[$k]['children'] = $y;
1044 if(count($parents)) {
1045 foreach($parents as $x) {
1047 if(count($x['children']))
1048 foreach($x['children'] as $y)
1057 function sort_thr_created($a,$b) {
1058 return strcmp($b['created'],$a['created']);
1061 function sort_thr_created_rev($a,$b) {
1062 return strcmp($a['created'],$b['created']);
1065 function sort_thr_commented($a,$b) {
1066 return strcmp($b['commented'],$a['commented']);
1069 function find_thread_parent_index($arr,$x) {
1070 foreach($arr as $k => $v)
1071 if($v['id'] == $x['parent'])
1076 function render_location_google($item) {
1077 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1078 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1081 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1083 $location = '<span class="smalltext">' . $coord . '</span>';