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=' . $Alink . ']' . $Aname . '[/url]';
98 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
99 if ($Bphoto!="") $Bphoto = '[url=' . $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=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
112 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
114 switch($obj['verb']){
116 switch ($obj['object-type']){
117 case ACTIVITY_OBJ_EVENT:
118 $post_type = t('event');
121 $post_type = t('status');
125 if($obj['resource-id']){
126 $post_type = t('photo');
127 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
128 $rr['plink'] = $m[1];
130 $post_type = t('status');
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=' . $Alink . ']' . $Aname . '[/url]';
162 $B = '[url=' . $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";
173 * "Render" a conversation or list of items for HTML display.
174 * There are two major forms of display:
175 * - Sequential or unthreaded ("New Item View" or search results)
176 * - conversation view
177 * The $mode parameter decides between the various renderings and also
178 * figures out how to determine page owner and other contextual items
179 * that are based on unique features of the calling module.
183 if(!function_exists('conversation')) {
184 function conversation(&$a, $items, $mode, $update, $preview = false) {
187 require_once('bbcode.php');
189 $ssl_state = ((local_user()) ? true : false);
192 $page_writeable = false;
194 $previewing = (($preview) ? ' preview ' : '');
196 if($mode === 'network') {
197 $profile_owner = local_user();
198 $page_writeable = true;
201 if($mode === 'profile') {
202 $profile_owner = $a->profile['profile_uid'];
203 $page_writeable = can_write_wall($a,$profile_owner);
206 if($mode === 'notes') {
207 $profile_owner = local_user();
208 $page_writeable = true;
211 if($mode === 'display') {
212 $profile_owner = $a->profile['uid'];
213 $page_writeable = can_write_wall($a,$profile_owner);
216 if($mode === 'community') {
218 $page_writeable = false;
222 $return_url = $_SESSION['return_url'];
224 $return_url = $_SESSION['return_url'] = $a->query_string;
226 load_contact_links(local_user());
228 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
229 call_hooks('conversation_start',$cb);
231 $items = $cb['items'];
233 $cmnt_tpl = get_markup_template('comment_item.tpl');
234 $tpl = 'wall_item.tpl';
235 $wallwall = 'wallwall_item.tpl';
236 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
242 // array with html for each thread (parent+comments)
248 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
250 // "New Item View" on network page or search page results
251 // - just loop through the items and format them minimally for display
253 //$tpl = get_markup_template('search_item.tpl');
254 $tpl = 'search_item.tpl';
256 foreach($items as $item) {
265 if($mode === 'search' || $mode === 'community') {
266 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
267 && ($item['id'] != $item['parent']))
269 $nickname = $item['nickname'];
272 $nickname = $a->user['nickname'];
275 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
276 if($item['author-link'] && (! $item['author-name']))
277 $profile_name = $item['author-link'];
280 $profile_link = best_link_url($item,$sp);
282 $sparkle = ' sparkle';
283 if($profile_link === 'mailbox')
287 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
288 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
289 $profile_avatar = $a->contacts[$normalised]['thumb'];
291 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
293 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
294 call_hooks('render_location',$locate);
296 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
298 localize_item($item);
299 if($mode === 'network-new')
306 'dropping' => $dropping,
307 'select' => t('Select'),
308 'delete' => t('Delete'),
312 $isstarred = "unstarred";
315 $likebuttons = false;
318 $body = prepare_body($item,true);
320 //$tmp_item = replace_macros($tpl,array(
323 'id' => (($preview) ? 'P0' : $item['item_id']),
324 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
325 'profile_url' => $profile_link,
326 'item_photo_menu' => item_photo_menu($item),
327 'name' => template_escape($profile_name),
328 'sparkle' => $sparkle,
330 'thumb' => $profile_avatar,
331 'title' => template_escape($item['title']),
332 'body' => template_escape($body),
333 'text' => strip_tags(template_escape($body)),
334 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
336 'location' => template_escape($location),
338 'owner_name' => template_escape($owner_name),
339 'owner_url' => $owner_url,
340 'owner_photo' => $owner_photo,
341 'plink' => get_plink($item),
343 'isstarred' => $isstarred,
346 'vote' => $likebuttons,
350 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
351 'previewing' => $previewing,
352 'wait' => t('Please wait'),
355 $arr = array('item' => $item, 'output' => $tmp_item);
356 call_hooks('display_item', $arr);
358 $threads[$threadsid]['id'] = $item['item_id'];
359 $threads[$threadsid]['items'] = array($arr['output']);
369 // Figure out how many comments each parent has
370 // (Comments all have gravity of 6)
371 // Store the result in the $comments array
374 foreach($items as $item) {
375 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
376 if(! x($comments,$item['parent']))
377 $comments[$item['parent']] = 1;
379 $comments[$item['parent']] += 1;
380 } elseif(! x($comments,$item['parent']))
381 $comments[$item['parent']] = 0; // avoid notices later on
384 // map all the like/dislike activities for each parent item
385 // Store these in the $alike and $dlike arrays
387 foreach($items as $item) {
388 like_puller($a,$item,$alike,'like');
389 like_puller($a,$item,$dlike,'dislike');
392 $comments_collapsed = false;
393 $comment_lastcollapsed = false;
394 $comment_firstcollapsed = false;
399 foreach($items as $item) {
405 $owner_url = $owner_photo = $owner_name = '';
407 // We've already parsed out like/dislike for special treatment. We can ignore them now
409 if(((activity_match($item['verb'],ACTIVITY_LIKE))
410 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
411 && ($item['id'] != $item['parent']))
414 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
415 $toplevelprivate = false;
417 // Take care of author collapsing and comment collapsing
418 // (author collapsing is currently disabled)
419 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
420 // If there are more than two comments, squash all but the last 2.
423 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
424 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
427 $comments_collapsed = false;
428 $comment_lastcollapsed = false;
429 $comment_firstcollapsed = false;
432 $threads[$threadsid]['id'] = $item['item_id'];
433 $threads[$threadsid]['private'] = $item['private'];
434 $threads[$threadsid]['items'] = array();
439 // prevent private email reply to public conversation from leaking.
440 if($item['private'] && ! $threads[$threadsid]['private'])
444 $comment_lastcollapsed = false;
445 $comment_firstcollapsed = false;
448 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
449 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
452 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
454 if (!$comments_collapsed){
455 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
456 $threads[$threadsid]['hide_text'] = t('show more');
457 $comments_collapsed = true;
458 $comment_firstcollapsed = true;
461 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
463 $comment_lastcollapsed = true;
466 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
468 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
469 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
470 ? t('Private Message')
474 // Top-level wall post not written by the wall owner (wall-to-wall)
475 // First figure out who owns it.
479 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
483 // On the network page, I am the owner. On the display page it will be the profile owner.
484 // This will have been stored in $a->page_contact by our calling page.
485 // Put this person on the left of the wall-to-wall notice.
487 $owner_url = $a->page_contact['url'];
488 $owner_photo = $a->page_contact['thumb'];
489 $owner_name = $a->page_contact['name'];
490 $template = $wallwall;
493 if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
497 $owner_url = $item['owner-link'];
498 $owner_photo = $item['owner-avatar'];
499 $owner_name = $item['owner-name'];
500 $template = $wallwall;
502 // If it is our contact, use a friendly redirect link
503 if((link_compare($item['owner-link'],$item['url']))
504 && ($item['network'] === 'dfrn')) {
505 $owner_url = $redirect_url;
506 $osparkle = ' sparkle';
512 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
514 if($page_writeable) {
516 $likebuttons = array(
517 'like' => array( t("I like this \x28toggle\x29"), t("like")),
518 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
520 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
524 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
525 $qcomment = (($qc) ? explode("\n",$qc) : null);
527 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
528 $comment = replace_macros($cmnt_tpl,array(
529 '$return_path' => '',
530 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
531 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
532 '$id' => $item['item_id'],
533 '$parent' => $item['parent'],
534 '$qcomment' => $qcomment,
535 '$profile_uid' => $profile_owner,
536 '$mylink' => $a->contact['url'],
537 '$mytitle' => t('This is you'),
538 '$myphoto' => $a->contact['thumb'],
539 '$comment' => t('Comment'),
540 '$submit' => t('Submit'),
541 '$preview' => t('Preview'),
542 '$ww' => (($mode === 'network') ? $commentww : '')
547 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
548 ? array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"))
555 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
559 'dropping' => $dropping,
560 'select' => t('Select'),
561 'delete' => t('Delete'),
567 $isstarred = "unstarred";
568 if ($profile_owner == local_user()) {
570 $isstarred = (($item['starred']) ? "starred" : "unstarred");
573 'do' => t("add star"),
574 'undo' => t("remove star"),
575 'toggle' => t("toggle star status"),
576 'classdo' => (($item['starred']) ? "hidden" : ""),
577 'classundo' => (($item['starred']) ? "" : "hidden"),
578 'starred' => t('starred'),
579 'tagger' => t("add tag"),
583 $filer = t("file as");
587 $photo = $item['photo'];
588 $thumb = $item['thumb'];
590 // Post was remotely authored.
592 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
594 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
596 if($item['author-link'] && (! $item['author-name']))
597 $profile_name = $item['author-link'];
601 $profile_link = best_link_url($item,$sp);
603 $sparkle = ' sparkle';
605 if($profile_link === 'mailbox')
608 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
609 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
610 $profile_avatar = $a->contacts[$normalised]['thumb'];
612 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
618 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
619 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
621 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
622 call_hooks('render_location',$locate);
624 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
626 $indent = (($toplevelpost) ? '' : ' comment');
628 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
632 localize_item($item);
636 foreach(explode(',',$item['tag']) as $tag){
638 if ($tag!="") $tags[] = bbcode($tag);
643 $body = prepare_body($item,true);
644 //$tmp_item = replace_macros($template,
646 // collapse comments in template. I don't like this much...
647 'comment_firstcollapsed' => $comment_firstcollapsed,
648 'comment_lastcollapsed' => $comment_lastcollapsed,
649 // template to use to render item (wall, walltowall, search)
650 'template' => $template,
652 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
654 'body' => template_escape($body),
655 'text' => strip_tags(template_escape($body)),
656 'id' => $item['item_id'],
657 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
658 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
660 'wall' => t('Wall-to-Wall'),
661 'vwall' => t('via Wall-To-Wall:'),
662 'profile_url' => $profile_link,
663 'item_photo_menu' => item_photo_menu($item),
664 'name' => template_escape($profile_name),
665 'thumb' => $profile_avatar,
666 'osparkle' => $osparkle,
667 'sparkle' => $sparkle,
668 'title' => template_escape($item['title']),
669 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
671 'location' => template_escape($location),
673 'owner_url' => $owner_url,
674 'owner_photo' => $owner_photo,
675 'owner_name' => template_escape($owner_name),
676 'plink' => get_plink($item),
678 'isstarred' => $isstarred,
682 'vote' => $likebuttons,
684 'dislike' => $dislike,
685 'comment' => $comment,
686 'previewing' => $previewing,
687 'wait' => t('Please wait'),
692 $arr = array('item' => $item, 'output' => $tmp_item);
693 call_hooks('display_item', $arr);
695 $threads[$threadsid]['items'][] = $arr['output'];
700 $page_template = get_markup_template("conversation.tpl");
701 $o .= replace_macros($page_template, array(
702 '$baseurl' => $a->get_baseurl($ssl_state),
705 '$threads' => $threads,
706 '$dropping' => ($dropping?t('Delete Selected Items'):False),
712 function best_link_url($item,&$sparkle,$ssl_state = false) {
719 $clean_url = normalise_link($item['author-link']);
721 if((local_user()) && (local_user() == $item['uid'])) {
722 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
723 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
724 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
728 $best_url = $a->contacts[$clean_url]['url'];
732 if(strlen($item['author-link']))
733 $best_url = $item['author-link'];
735 $best_url = $item['url'];
742 if(! function_exists('item_photo_menu')){
743 function item_photo_menu($item){
750 if(! count($a->contacts))
751 load_contact_links(local_user());
760 $profile_link = best_link_url($item,$sparkle,$ssl_state);
761 if($profile_link === 'mailbox')
765 $cid = intval(basename($profile_link));
766 $status_link = $profile_link . "?url=status";
767 $photos_link = $profile_link . "?url=photos";
768 $profile_link = $profile_link . "?url=profile";
769 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
772 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
773 $cid = $item['contact-id'];
779 if(($cid) && (! $item['self'])) {
780 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
781 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
783 $clean_url = normalise_link($item['author-link']);
785 if((local_user()) && (local_user() == $item['uid'])) {
786 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
787 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
788 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
796 t("View status") => $status_link,
797 t("View profile") => $profile_link,
798 t("View photos") => $photos_link,
799 t("View recent") => $posts_link,
800 t("Edit contact") => $contact_url,
801 t("Send PM") => $pm_url,
805 $args = array('item' => $item, 'menu' => $menu);
807 call_hooks('item_photo_menu', $args);
809 $menu = $args['menu'];
812 foreach($menu as $k=>$v){
813 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
818 if(! function_exists('like_puller')) {
819 function like_puller($a,$item,&$arr,$mode) {
823 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
825 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
826 $url = $item['author-link'];
827 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
828 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
829 $sparkle = ' class="sparkle" ';
831 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
832 $arr[$item['parent'] . '-l'] = array();
833 if(! isset($arr[$item['parent']]))
834 $arr[$item['parent']] = 1;
836 $arr[$item['parent']] ++;
837 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
842 // Format the like/dislike text for a profile item
843 // $cnt = number of people who like/dislike the item
844 // $arr = array of pre-linked names of likers/dislikers
845 // $type = one of 'like, 'dislike'
847 // returns formatted text
849 if(! function_exists('format_like')) {
850 function format_like($cnt,$arr,$type,$id) {
853 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
855 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
856 $o .= (($type === 'like') ?
857 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
859 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
861 $total = count($arr);
862 if($total >= MAX_LIKERS)
863 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
864 if($total < MAX_LIKERS)
865 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
866 $str = implode(', ', $arr);
867 if($total >= MAX_LIKERS)
868 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
869 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
870 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
876 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
880 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
883 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
886 $tpl = get_markup_template('jot-header.tpl');
888 $a->page['htmlhead'] .= replace_macros($tpl, array(
889 '$newpost' => 'true',
890 '$baseurl' => $a->get_baseurl(true),
891 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
892 '$geotag' => $geotag,
893 '$nickname' => $x['nickname'],
894 '$ispublic' => t('Visible to <strong>everybody</strong>'),
895 '$linkurl' => t('Please enter a link URL:'),
896 '$vidurl' => t("Please enter a video link/URL:"),
897 '$audurl' => t("Please enter an audio link/URL:"),
898 '$term' => t('Tag term:'),
899 '$fileas' => t('File as:'),
900 '$whereareu' => t('Where are you right now?')
904 $tpl = get_markup_template("jot.tpl");
909 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
911 $mail_enabled = false;
912 $pubmail_enabled = false;
914 if(($x['is_owner']) && (! $mail_disabled)) {
915 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
919 $mail_enabled = true;
920 if(intval($r[0]['pubmail']))
921 $pubmail_enabled = true;
926 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
927 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
930 call_hooks('jot_tool', $jotplugins);
931 call_hooks('jot_networks', $jotnets);
934 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
936 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
938 $o .= replace_macros($tpl,array(
939 '$return_path' => $a->cmd,
940 '$action' => $a->get_baseurl(true) . '/item',
941 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
942 '$upload' => t('Upload photo'),
943 '$shortupload' => t('upload photo'),
944 '$attach' => t('Attach file'),
945 '$shortattach' => t('attach file'),
946 '$weblink' => t('Insert web link'),
947 '$shortweblink' => t('web link'),
948 '$video' => t('Insert video link'),
949 '$shortvideo' => t('video link'),
950 '$audio' => t('Insert audio link'),
951 '$shortaudio' => t('audio link'),
952 '$setloc' => t('Set your location'),
953 '$shortsetloc' => t('set location'),
954 '$noloc' => t('Clear browser location'),
955 '$shortnoloc' => t('clear location'),
957 '$placeholdertitle' => t('Set title'),
958 '$wait' => t('Please wait'),
959 '$permset' => t('Permission settings'),
960 '$shortpermset' => t('permissions'),
961 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
964 '$baseurl' => $a->get_baseurl(true),
965 '$defloc' => $x['default_location'],
966 '$visitor' => $x['visitor'],
967 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
968 '$emailcc' => t('CC: email addresses'),
969 '$public' => t('Public post'),
970 '$jotnets' => $jotnets,
971 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
972 '$lockstate' => $x['lockstate'],
974 '$bang' => $x['bang'],
975 '$profile_uid' => $x['profile_uid'],
976 '$preview' => t('Preview'),
981 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
989 function conv_sort($arr,$order) {
991 if((!(is_array($arr) && count($arr))))
997 if($x['id'] == $x['parent'])
1000 if(stristr($order,'created'))
1001 usort($parents,'sort_thr_created');
1002 elseif(stristr($order,'commented'))
1003 usort($parents,'sort_thr_commented');
1006 foreach($parents as $i=>$_x)
1007 $parents[$i]['children'] = array();
1009 foreach($arr as $x) {
1010 if($x['id'] != $x['parent']) {
1011 $p = find_thread_parent_index($parents,$x);
1013 $parents[$p]['children'][] = $x;
1016 if(count($parents)) {
1017 foreach($parents as $k => $v) {
1018 if(count($parents[$k]['children'])) {
1019 $y = $parents[$k]['children'];
1020 usort($y,'sort_thr_created_rev');
1021 $parents[$k]['children'] = $y;
1027 if(count($parents)) {
1028 foreach($parents as $x) {
1030 if(count($x['children']))
1031 foreach($x['children'] as $y)
1040 function sort_thr_created($a,$b) {
1041 return strcmp($b['created'],$a['created']);
1044 function sort_thr_created_rev($a,$b) {
1045 return strcmp($a['created'],$b['created']);
1048 function sort_thr_commented($a,$b) {
1049 return strcmp($b['commented'],$a['commented']);
1052 function find_thread_parent_index($arr,$x) {
1053 foreach($arr as $k => $v)
1054 if($v['id'] == $x['parent'])
1059 function render_location_google($item) {
1061 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1062 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1065 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1067 $location = '<span class="smalltext">' . $coord . '</span>';