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.
182 if(!function_exists('conversation')){
183 function conversation(&$a, $items, $mode, $update, $preview = false) {
185 require_once('bbcode.php');
188 $page_writeable = false;
190 $previewing = (($preview) ? ' preview ' : '');
192 if($mode === 'network') {
193 $profile_owner = local_user();
194 $page_writeable = true;
197 if($mode === 'profile') {
198 $profile_owner = $a->profile['profile_uid'];
199 $page_writeable = can_write_wall($a,$profile_owner);
202 if($mode === 'notes') {
203 $profile_owner = local_user();
204 $page_writeable = true;
207 if($mode === 'display') {
208 $profile_owner = $a->profile['uid'];
209 $page_writeable = can_write_wall($a,$profile_owner);
212 if($mode === 'community') {
214 $page_writeable = false;
218 $return_url = $_SESSION['return_url'];
220 $return_url = $_SESSION['return_url'] = $a->cmd;
222 load_contact_links(local_user());
224 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
225 call_hooks('conversation_start',$cb);
227 $items = $cb['items'];
229 $cmnt_tpl = get_markup_template('comment_item.tpl');
230 $tpl = 'wall_item.tpl';
231 $wallwall = 'wallwall_item.tpl';
232 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
238 // array with html for each thread (parent+comments)
244 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
246 // "New Item View" on network page or search page results
247 // - just loop through the items and format them minimally for display
249 //$tpl = get_markup_template('search_item.tpl');
250 $tpl = 'search_item.tpl';
252 foreach($items as $item) {
261 if($mode === 'search' || $mode === 'community') {
262 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
263 && ($item['id'] != $item['parent']))
265 $nickname = $item['nickname'];
268 $nickname = $a->user['nickname'];
271 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
272 if($item['author-link'] && (! $item['author-name']))
273 $profile_name = $item['author-link'];
276 $profile_link = best_link_url($item,$sp);
278 $sparkle = ' sparkle';
279 if($profile_link === 'mailbox')
283 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
284 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
285 $profile_avatar = $a->contacts[$normalised]['thumb'];
287 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
289 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
290 call_hooks('render_location',$locate);
292 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
294 localize_item($item);
295 if($mode === 'network-new')
302 'dropping' => $dropping,
303 'select' => t('Select'),
304 'delete' => t('Delete'),
308 $isstarred = "unstarred";
311 $likebuttons = false;
314 $body = prepare_body($item,true);
316 //$tmp_item = replace_macros($tpl,array(
319 'id' => (($preview) ? 'P0' : $item['item_id']),
320 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
321 'profile_url' => $profile_link,
322 'item_photo_menu' => item_photo_menu($item),
323 'name' => template_escape($profile_name),
324 'sparkle' => $sparkle,
326 'thumb' => $profile_avatar,
327 'title' => template_escape($item['title']),
328 'body' => template_escape($body),
329 'text' => strip_tags(template_escape($body)),
330 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
332 'location' => template_escape($location),
334 'owner_name' => template_escape($owner_name),
335 'owner_url' => $owner_url,
336 'owner_photo' => $owner_photo,
337 'plink' => get_plink($item),
339 'isstarred' => $isstarred,
342 'vote' => $likebuttons,
346 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
347 'previewing' => $previewing,
348 'wait' => t('Please wait'),
351 $arr = array('item' => $item, 'output' => $tmp_item);
352 call_hooks('display_item', $arr);
354 $threads[$threadsid]['id'] = $item['item_id'];
355 $threads[$threadsid]['items'] = array($arr['output']);
365 // Figure out how many comments each parent has
366 // (Comments all have gravity of 6)
367 // Store the result in the $comments array
370 foreach($items as $item) {
371 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
372 if(! x($comments,$item['parent']))
373 $comments[$item['parent']] = 1;
375 $comments[$item['parent']] += 1;
379 // map all the like/dislike activities for each parent item
380 // Store these in the $alike and $dlike arrays
382 foreach($items as $item) {
383 like_puller($a,$item,$alike,'like');
384 like_puller($a,$item,$dlike,'dislike');
387 $comments_collapsed = false;
388 $comment_lastcollapsed = false;
389 $comment_firstcollapsed = false;
394 foreach($items as $item) {
400 $owner_url = $owner_photo = $owner_name = '';
402 // We've already parsed out like/dislike for special treatment. We can ignore them now
404 if(((activity_match($item['verb'],ACTIVITY_LIKE))
405 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
406 && ($item['id'] != $item['parent']))
409 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
410 $toplevelprivate = false;
412 // Take care of author collapsing and comment collapsing
413 // (author collapsing is currently disabled)
414 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
415 // If there are more than two comments, squash all but the last 2.
418 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
419 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
423 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
425 if($blowhard_count == 3) {
426 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
427 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
428 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
429 . $item['parent'] . '" style="display: none;" >';
433 $blowhard = $item['cid'];
434 if($blowhard_count >= 3)
442 $comments_collapsed = false;
443 $comment_lastcollapsed = false;
444 $comment_firstcollapsed = false;
447 $threads[$threadsid]['id'] = $item['item_id'];
448 $threads[$threadsid]['items'] = array();
452 // prevent private email from leaking into public conversation
453 if((! $toplevelpost) && (! $toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
456 $comment_lastcollapsed = false;
457 $comment_firstcollapsed = false;
460 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
461 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
464 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
466 if (!$comments_collapsed){
467 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
468 $threads[$threadsid]['hide_text'] = t('show more');
469 $comments_collapsed = true;
470 $comment_firstcollapsed = true;
473 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
475 $comment_lastcollapsed = true;
478 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
480 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
481 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
482 ? t('Private Message')
486 // Top-level wall post not written by the wall owner (wall-to-wall)
487 // First figure out who owns it.
491 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
495 // On the network page, I am the owner. On the display page it will be the profile owner.
496 // This will have been stored in $a->page_contact by our calling page.
497 // Put this person on the left of the wall-to-wall notice.
499 $owner_url = $a->page_contact['url'];
500 $owner_photo = $a->page_contact['thumb'];
501 $owner_name = $a->page_contact['name'];
502 $template = $wallwall;
505 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
509 $owner_url = $item['owner-link'];
510 $owner_photo = $item['owner-avatar'];
511 $owner_name = $item['owner-name'];
512 $template = $wallwall;
514 // If it is our contact, use a friendly redirect link
515 if((link_compare($item['owner-link'],$item['url']))
516 && ($item['network'] === 'dfrn')) {
517 $owner_url = $redirect_url;
518 $osparkle = ' sparkle';
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'));
536 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
537 $qcomment = (($qc) ? explode("\n",$qc) : null);
539 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
540 $comment = replace_macros($cmnt_tpl,array(
541 '$return_path' => '',
542 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
543 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
544 '$id' => $item['item_id'],
545 '$parent' => $item['parent'],
546 '$qcomment' => $qcomment,
547 '$profile_uid' => $profile_owner,
548 '$mylink' => $a->contact['url'],
549 '$mytitle' => t('This is you'),
550 '$myphoto' => $a->contact['thumb'],
551 '$comment' => t('Comment'),
552 '$submit' => t('Submit'),
553 '$preview' => t('Preview'),
554 '$ww' => (($mode === 'network') ? $commentww : '')
559 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
560 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
567 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
571 'dropping' => $dropping,
572 'select' => t('Select'),
573 'delete' => t('Delete'),
577 $isstarred = "unstarred";
578 if ($profile_owner == local_user() && $toplevelpost) {
579 $isstarred = (($item['starred']) ? "starred" : "unstarred");
582 'do' => t("add star"),
583 'undo' => t("remove star"),
584 'toggle' => t("toggle star status"),
585 'classdo' => (($item['starred']) ? "hidden" : ""),
586 'classundo' => (($item['starred']) ? "" : "hidden"),
587 'starred' => t('starred'),
588 'tagger' => t("add tag"),
595 $photo = $item['photo'];
596 $thumb = $item['thumb'];
598 // Post was remotely authored.
600 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
602 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
604 if($item['author-link'] && (! $item['author-name']))
605 $profile_name = $item['author-link'];
609 $profile_link = best_link_url($item,$sp);
611 $sparkle = ' sparkle';
613 if($profile_link === 'mailbox')
616 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
617 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
618 $profile_avatar = $a->contacts[$normalised]['thumb'];
620 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
626 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
627 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
629 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
630 call_hooks('render_location',$locate);
632 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
634 $indent = (($toplevelpost) ? '' : ' comment');
636 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
640 localize_item($item);
644 foreach(explode(',',$item['tag']) as $tag){
646 if ($tag!="") $tags[] = bbcode($tag);
651 $body = prepare_body($item,true);
652 //$tmp_item = replace_macros($template,
654 // collapse comments in template. I don't like this much...
655 'comment_firstcollapsed' => $comment_firstcollapsed,
656 'comment_lastcollapsed' => $comment_lastcollapsed,
657 // template to use to render item (wall, walltowall, search)
658 'template' => $template,
660 'type' => implode("",array_slice(split("/",$item['verb']),-1)),
662 'body' => template_escape($body),
663 'text' => strip_tags(template_escape($body)),
664 'id' => $item['item_id'],
665 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
666 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
668 'wall' => t('Wall-to-Wall'),
669 'vwall' => t('via Wall-To-Wall:'),
670 'profile_url' => $profile_link,
671 'item_photo_menu' => item_photo_menu($item),
672 'name' => template_escape($profile_name),
673 'thumb' => $profile_avatar,
674 'osparkle' => $osparkle,
675 'sparkle' => $sparkle,
676 'title' => template_escape($item['title']),
677 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
679 'location' => template_escape($location),
681 'owner_url' => $owner_url,
682 'owner_photo' => $owner_photo,
683 'owner_name' => template_escape($owner_name),
684 'plink' => get_plink($item),
686 'isstarred' => $isstarred,
689 'vote' => $likebuttons,
691 'dislike' => $dislike,
692 'comment' => $comment,
693 'previewing' => $previewing,
694 'wait' => t('Please wait'),
699 $arr = array('item' => $item, 'output' => $tmp_item);
700 call_hooks('display_item', $arr);
702 $threads[$threadsid]['items'][] = $arr['output'];
707 $page_template = get_markup_template("conversation.tpl");
708 $o .= replace_macros($page_template, array(
709 '$baseurl' => $a->get_baseurl(),
712 '$threads' => $threads,
713 '$dropping' => ($dropping?t('Delete Selected Items'):False),
719 function best_link_url($item,&$sparkle) {
726 $clean_url = normalise_link($item['author-link']);
728 if((local_user()) && (local_user() == $item['uid'])) {
729 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
730 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
731 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
735 $best_url = $a->contacts[$clean_url]['url'];
739 if(strlen($item['author-link']))
740 $best_url = $item['author-link'];
742 $best_url = $item['url'];
749 if(! function_exists('item_photo_menu')){
750 function item_photo_menu($item){
753 if (local_user() && (! count($a->contacts)))
754 load_contact_links(local_user());
763 $profile_link = best_link_url($item,$sparkle);
764 if($profile_link === 'mailbox')
768 $cid = intval(basename($profile_link));
769 $status_link = $profile_link . "?url=status";
770 $photos_link = $profile_link . "?url=photos";
771 $profile_link = $profile_link . "?url=profile";
772 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
775 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
776 $cid = $item['contact-id'];
782 if(($cid) && (! $item['self'])) {
783 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
784 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
788 t("View status") => $status_link,
789 t("View profile") => $profile_link,
790 t("View photos") => $photos_link,
791 t("View recent") => $posts_link,
792 t("Edit contact") => $contact_url,
793 t("Send PM") => $pm_url,
797 $args = array('item' => $item, 'menu' => $menu);
799 call_hooks('item_photo_menu', $args);
801 $menu = $args['menu'];
804 foreach($menu as $k=>$v){
805 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
810 if(! function_exists('like_puller')) {
811 function like_puller($a,$item,&$arr,$mode) {
815 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
817 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
818 $url = $item['author-link'];
819 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
820 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
821 $sparkle = ' class="sparkle" ';
823 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
824 $arr[$item['parent'] . '-l'] = array();
825 if(! isset($arr[$item['parent']]))
826 $arr[$item['parent']] = 1;
828 $arr[$item['parent']] ++;
829 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
834 // Format the like/dislike text for a profile item
835 // $cnt = number of people who like/dislike the item
836 // $arr = array of pre-linked names of likers/dislikers
837 // $type = one of 'like, 'dislike'
839 // returns formatted text
841 if(! function_exists('format_like')) {
842 function format_like($cnt,$arr,$type,$id) {
845 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
847 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
848 $o .= (($type === 'like') ?
849 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
851 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
853 $total = count($arr);
854 if($total >= MAX_LIKERS)
855 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
856 if($total < MAX_LIKERS)
857 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
858 $str = implode(', ', $arr);
859 if($total >= MAX_LIKERS)
860 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
861 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
862 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
868 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
872 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
875 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
878 $tpl = get_markup_template('jot-header.tpl');
880 $a->page['htmlhead'] .= replace_macros($tpl, array(
881 '$newpost' => 'true',
882 '$baseurl' => $a->get_baseurl(),
883 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
884 '$geotag' => $geotag,
885 '$nickname' => $x['nickname'],
886 '$ispublic' => t('Visible to <strong>everybody</strong>'),
887 '$linkurl' => t('Please enter a link URL:'),
888 '$vidurl' => t("Please enter a video link/URL:"),
889 '$audurl' => t("Please enter an audio link/URL:"),
890 '$term' => t('Tag term:'),
891 '$whereareu' => t('Where are you right now?'),
892 '$title' => t('Enter a title for this item')
896 $tpl = get_markup_template("jot.tpl");
901 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
903 $mail_enabled = false;
904 $pubmail_enabled = false;
906 if(($x['is_owner']) && (! $mail_disabled)) {
907 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
911 $mail_enabled = true;
912 if(intval($r[0]['pubmail']))
913 $pubmail_enabled = true;
918 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
919 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
922 call_hooks('jot_tool', $jotplugins);
923 call_hooks('jot_networks', $jotnets);
926 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
928 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
930 $o .= replace_macros($tpl,array(
931 '$return_path' => $a->cmd,
932 '$action' => $a->get_baseurl().'/item',
933 '$share' => (($x['button']) ? $x['button'] : t('Share')),
934 '$upload' => t('Upload photo'),
935 '$shortupload' => t('upload photo'),
936 '$attach' => t('Attach file'),
937 '$shortattach' => t('attach file'),
938 '$weblink' => t('Insert web link'),
939 '$shortweblink' => t('web link'),
940 '$video' => t('Insert video link'),
941 '$shortvideo' => t('video link'),
942 '$audio' => t('Insert audio link'),
943 '$shortaudio' => t('audio link'),
944 '$setloc' => t('Set your location'),
945 '$shortsetloc' => t('set location'),
946 '$noloc' => t('Clear browser location'),
947 '$shortnoloc' => t('clear location'),
949 '$placeholdertitle' => t('Set title'),
950 '$wait' => t('Please wait'),
951 '$permset' => t('Permission settings'),
952 '$shortpermset' => t('permissions'),
953 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
956 '$baseurl' => $a->get_baseurl(),
957 '$defloc' => $x['default_location'],
958 '$visitor' => $x['visitor'],
959 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
960 '$emailcc' => t('CC: email addresses'),
961 '$public' => t('Public post'),
962 '$jotnets' => $jotnets,
963 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
964 '$lockstate' => $x['lockstate'],
966 '$bang' => $x['bang'],
967 '$profile_uid' => $x['profile_uid'],
968 '$preview' => t('Preview'),
973 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
981 function conv_sort($arr,$order) {
983 if((!(is_array($arr) && count($arr))))
989 if($x['id'] == $x['parent'])
992 if(stristr($order,'created'))
993 usort($parents,'sort_thr_created');
994 elseif(stristr($order,'commented'))
995 usort($parents,'sort_thr_commented');
998 foreach($parents as $x)
999 $x['children'] = array();
1001 foreach($arr as $x) {
1002 if($x['id'] != $x['parent']) {
1003 $p = find_thread_parent_index($parents,$x);
1005 $parents[$p]['children'][] = $x;
1008 if(count($parents)) {
1009 foreach($parents as $k => $v) {
1010 if(count($parents[$k]['children'])) {
1011 $y = $parents[$k]['children'];
1012 usort($y,'sort_thr_created_rev');
1013 $parents[$k]['children'] = $y;
1019 if(count($parents)) {
1020 foreach($parents as $x) {
1022 if(count($x['children']))
1023 foreach($x['children'] as $y)
1032 function sort_thr_created($a,$b) {
1033 return strcmp($b['created'],$a['created']);
1036 function sort_thr_created_rev($a,$b) {
1037 return strcmp($a['created'],$b['created']);
1040 function sort_thr_commented($a,$b) {
1041 return strcmp($b['commented'],$a['commented']);
1044 function find_thread_parent_index($arr,$x) {
1045 foreach($arr as $k => $v)
1046 if($v['id'] == $x['parent'])
1051 function render_location_google($item) {
1053 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1054 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1057 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1059 $location = '<span class="smalltext">' . $coord . '</span>';