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 function conversation(&$a, $items, $mode, $update, $preview = false) {
184 require_once('bbcode.php');
187 $page_writeable = false;
189 $previewing = (($preview) ? ' preview ' : '');
191 if($mode === 'network') {
192 $profile_owner = local_user();
193 $page_writeable = true;
196 if($mode === 'profile') {
197 $profile_owner = $a->profile['profile_uid'];
198 $page_writeable = can_write_wall($a,$profile_owner);
201 if($mode === 'notes') {
202 $profile_owner = local_user();
203 $page_writeable = true;
206 if($mode === 'display') {
207 $profile_owner = $a->profile['uid'];
208 $page_writeable = can_write_wall($a,$profile_owner);
211 if($mode === 'community') {
213 $page_writeable = false;
217 $return_url = $_SESSION['return_url'];
219 $return_url = $_SESSION['return_url'] = $a->cmd;
221 load_contact_links(local_user());
223 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
224 call_hooks('conversation_start',$cb);
226 $items = $cb['items'];
228 $cmnt_tpl = get_markup_template('comment_item.tpl');
229 $tpl = get_markup_template('wall_item.tpl');
230 $wallwall = get_markup_template('wallwall_item.tpl');
231 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
237 // array with html for each thread (parent+comments)
243 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
245 // "New Item View" on network page or search page results
246 // - just loop through the items and format them minimally for display
248 $tpl = get_markup_template('search_item.tpl');
250 foreach($items as $item) {
259 if($mode === 'search' || $mode === 'community') {
260 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
261 && ($item['id'] != $item['parent']))
263 $nickname = $item['nickname'];
266 $nickname = $a->user['nickname'];
269 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
270 if($item['author-link'] && (! $item['author-name']))
271 $profile_name = $item['author-link'];
274 $profile_link = best_link_url($item,$sp);
276 $sparkle = ' sparkle';
277 if($profile_link === 'mailbox')
281 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
282 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
283 $profile_avatar = $a->contacts[$normalised]['thumb'];
285 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
287 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
288 call_hooks('render_location',$locate);
290 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
292 localize_item($item);
293 if($mode === 'network-new')
300 'dropping' => $dropping,
301 'select' => t('Select'),
302 'delete' => t('Delete'),
306 $isstarred = "unstarred";
309 $likebuttons = false;
312 $body = prepare_body($item,true);
314 $tmp_item = replace_macros($tpl,array(
315 '$id' => (($preview) ? 'P0' : $item['item_id']),
316 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
317 '$profile_url' => $profile_link,
318 '$item_photo_menu' => item_photo_menu($item),
319 '$name' => template_escape($profile_name),
320 '$sparkle' => $sparkle,
322 '$thumb' => $profile_avatar,
323 '$title' => template_escape($item['title']),
324 '$body' => template_escape($body),
325 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
327 '$location' => template_escape($location),
329 '$owner_name' => template_escape($owner_name),
330 '$owner_url' => $owner_url,
331 '$owner_photo' => $owner_photo,
332 '$plink' => get_plink($item),
334 '$isstarred' => $isstarred,
337 '$vote' => $likebuttons,
341 '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
342 '$previewing' => $previewing,
343 '$wait' => t('Please wait'),
346 $arr = array('item' => $item, 'output' => $tmp_item);
347 call_hooks('display_item', $arr);
349 $threads[$threadsid]['id'] = $item['item_id'];
350 $threads[$threadsid]['html'] .= $arr['output'];
360 // Figure out how many comments each parent has
361 // (Comments all have gravity of 6)
362 // Store the result in the $comments array
365 foreach($items as $item) {
366 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
367 if(! x($comments,$item['parent']))
368 $comments[$item['parent']] = 1;
370 $comments[$item['parent']] += 1;
374 // map all the like/dislike activities for each parent item
375 // Store these in the $alike and $dlike arrays
377 foreach($items as $item) {
378 like_puller($a,$item,$alike,'like');
379 like_puller($a,$item,$dlike,'dislike');
382 $comments_collapsed = false;
387 foreach($items as $item) {
393 $owner_url = $owner_photo = $owner_name = '';
395 // We've already parsed out like/dislike for special treatment. We can ignore them now
397 if(((activity_match($item['verb'],ACTIVITY_LIKE))
398 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
399 && ($item['id'] != $item['parent']))
402 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
403 $toplevelprivate = false;
405 // Take care of author collapsing and comment collapsing
406 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
407 // If there are more than two comments, squash all but the last 2.
410 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
411 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
413 /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
415 if($blowhard_count == 3) {
416 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
417 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
418 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
419 . $item['parent'] . '" style="display: none;" >';
423 $blowhard = $item['cid'];
424 if($blowhard_count >= 3)
430 $comments_collapsed = false;
433 $threads[$threadsid]['id'] = $item['item_id'];
434 $threads[$threadsid]['html'] = "";
438 // prevent private email from leaking into public conversation
439 if((! $toplevelpost) && (! $toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
444 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
445 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
448 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
449 if(! $comments_collapsed) {
451 // IMPORTANT: the closing </div> in the hide_comments template
452 // is supplied below in code.
454 $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
455 '$id' => $item['parent'],
456 '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
457 $comments[$item['parent']]),
458 '$display' => 'none',
459 '$hide_text' => t('show more')
461 $comments_collapsed = true;
464 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
465 $threads[$threadsid]['html'] .= '</div>';
468 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
470 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
471 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
472 ? t('Private Message')
476 // Top-level wall post not written by the wall owner (wall-to-wall)
477 // First figure out who owns it.
481 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
485 // On the network page, I am the owner. On the display page it will be the profile owner.
486 // This will have been stored in $a->page_contact by our calling page.
487 // Put this person on the left of the wall-to-wall notice.
489 $owner_url = $a->page_contact['url'];
490 $owner_photo = $a->page_contact['thumb'];
491 $owner_name = $a->page_contact['name'];
492 $template = $wallwall;
495 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
499 $owner_url = $item['owner-link'];
500 $owner_photo = $item['owner-avatar'];
501 $owner_name = $item['owner-name'];
502 $template = $wallwall;
504 // If it is our contact, use a friendly redirect link
505 if((link_compare($item['owner-link'],$item['url']))
506 && ($item['network'] === 'dfrn')) {
507 $owner_url = $redirect_url;
508 $osparkle = ' sparkle';
514 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
516 if($page_writeable) {
518 $likebuttons = array(
519 'like' => array( t("I like this \x28toggle\x29"), t("like")),
520 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
522 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
526 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
527 $qcomment = (($qc) ? explode("\n",$qc) : null);
529 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
530 $comment = replace_macros($cmnt_tpl,array(
531 '$return_path' => '',
532 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
533 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
534 '$id' => $item['item_id'],
535 '$parent' => $item['parent'],
536 '$qcomment' => $qcomment,
537 '$profile_uid' => $profile_owner,
538 '$mylink' => $a->contact['url'],
539 '$mytitle' => t('This is you'),
540 '$myphoto' => $a->contact['thumb'],
541 '$comment' => t('Comment'),
542 '$submit' => t('Submit'),
543 '$preview' => t('Preview'),
544 '$ww' => (($mode === 'network') ? $commentww : '')
549 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
550 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
557 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
561 'dropping' => $dropping,
562 'select' => t('Select'),
563 'delete' => t('Delete'),
567 $isstarred = "unstarred";
568 if ($profile_owner == local_user() && $toplevelpost) {
569 $isstarred = (($item['starred']) ? "starred" : "unstarred");
572 'do' => t("add star"),
573 'undo' => t("remove star"),
574 'toggle' => t("toggle star status"),
575 'classdo' => (($item['starred']) ? "hidden" : ""),
576 'classundo' => (($item['starred']) ? "" : "hidden"),
577 'starred' => t('starred'),
578 'tagger' => t("add tag"),
585 $photo = $item['photo'];
586 $thumb = $item['thumb'];
588 // Post was remotely authored.
590 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
592 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
594 if($item['author-link'] && (! $item['author-name']))
595 $profile_name = $item['author-link'];
599 $profile_link = best_link_url($item,$sp);
601 $sparkle = ' sparkle';
603 if($profile_link === 'mailbox')
606 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
607 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
608 $profile_avatar = $a->contacts[$normalised]['thumb'];
610 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
616 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
617 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
619 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
620 call_hooks('render_location',$locate);
622 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
624 $indent = (($toplevelpost) ? '' : ' comment');
626 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
630 localize_item($item);
634 foreach(explode(',',$item['tag']) as $tag){
636 if ($tag!="") $tags[] = bbcode($tag);
641 $body = prepare_body($item,true);
643 $tmp_item = replace_macros($template,array(
644 '$type' => implode("",array_slice(explode("/",$item['verb']),-1)),
646 '$body' => template_escape($body),
647 '$id' => $item['item_id'],
648 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
649 '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
651 '$wall' => t('Wall-to-Wall'),
652 '$vwall' => t('via Wall-To-Wall:'),
653 '$profile_url' => $profile_link,
654 '$item_photo_menu' => item_photo_menu($item),
655 '$name' => template_escape($profile_name),
656 '$thumb' => $profile_avatar,
657 '$osparkle' => $osparkle,
658 '$sparkle' => $sparkle,
659 '$title' => template_escape($item['title']),
660 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
662 '$location' => template_escape($location),
663 '$indent' => $indent,
664 '$owner_url' => $owner_url,
665 '$owner_photo' => $owner_photo,
666 '$owner_name' => template_escape($owner_name),
667 '$plink' => get_plink($item),
668 '$edpost' => $edpost,
669 '$isstarred' => $isstarred,
672 '$vote' => $likebuttons,
674 '$dislike' => $dislike,
675 '$comment' => $comment,
676 '$previewing' => $previewing,
677 '$wait' => t('Please wait'),
682 $arr = array('item' => $item, 'output' => $tmp_item);
683 call_hooks('display_item', $arr);
685 $threads[$threadsid]['html'] .= $arr['output'];
691 $page_template = get_markup_template("conversation.tpl");
692 $o .= replace_macros($page_template, array(
693 '$threads' => $threads,
694 '$dropping' => ($dropping?t('Delete Selected Items'):False),
700 function best_link_url($item,&$sparkle) {
707 $clean_url = normalise_link($item['author-link']);
709 if((local_user()) && (local_user() == $item['uid'])) {
710 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
711 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
712 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
716 $best_url = $a->contacts[$clean_url]['url'];
720 if(strlen($item['author-link']))
721 $best_url = $item['author-link'];
723 $best_url = $item['url'];
730 if(! function_exists('item_photo_menu')){
731 function item_photo_menu($item){
734 if (local_user() && (! count($a->contacts)))
735 load_contact_links(local_user());
744 $profile_link = best_link_url($item,$sparkle);
745 if($profile_link === 'mailbox')
749 $cid = intval(basename($profile_link));
750 $status_link = $profile_link . "?url=status";
751 $photos_link = $profile_link . "?url=photos";
752 $profile_link = $profile_link . "?url=profile";
753 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
756 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
757 $cid = $item['contact-id'];
763 if(($cid) && (! $item['self'])) {
764 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
765 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
769 t("View status") => $status_link,
770 t("View profile") => $profile_link,
771 t("View photos") => $photos_link,
772 t("View recent") => $posts_link,
773 t("Edit contact") => $contact_url,
774 t("Send PM") => $pm_url,
778 $args = array('item' => $item, 'menu' => $menu);
780 call_hooks('item_photo_menu', $args);
782 $menu = $args['menu'];
785 foreach($menu as $k=>$v){
786 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
791 if(! function_exists('like_puller')) {
792 function like_puller($a,$item,&$arr,$mode) {
796 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
798 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
799 $url = $item['author-link'];
800 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
801 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
802 $sparkle = ' class="sparkle" ';
804 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
805 $arr[$item['parent'] . '-l'] = array();
806 if(! isset($arr[$item['parent']]))
807 $arr[$item['parent']] = 1;
809 $arr[$item['parent']] ++;
810 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
815 // Format the like/dislike text for a profile item
816 // $cnt = number of people who like/dislike the item
817 // $arr = array of pre-linked names of likers/dislikers
818 // $type = one of 'like, 'dislike'
820 // returns formatted text
822 if(! function_exists('format_like')) {
823 function format_like($cnt,$arr,$type,$id) {
826 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
828 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
829 $o .= (($type === 'like') ?
830 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
832 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
834 $total = count($arr);
835 if($total >= MAX_LIKERS)
836 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
837 if($total < MAX_LIKERS)
838 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
839 $str = implode(', ', $arr);
840 if($total >= MAX_LIKERS)
841 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
842 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
843 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
849 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
853 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
856 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
859 $tpl = get_markup_template('jot-header.tpl');
861 $a->page['htmlhead'] .= replace_macros($tpl, array(
862 '$newpost' => 'true',
863 '$baseurl' => $a->get_baseurl(),
864 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
865 '$geotag' => $geotag,
866 '$nickname' => $x['nickname'],
867 '$ispublic' => t('Visible to <strong>everybody</strong>'),
868 '$linkurl' => t('Please enter a link URL:'),
869 '$vidurl' => t("Please enter a video link/URL:"),
870 '$audurl' => t("Please enter an audio link/URL:"),
871 '$term' => t('Tag term:'),
872 '$whereareu' => t('Where are you right now?'),
873 '$title' => t('Enter a title for this item')
877 $tpl = get_markup_template("jot.tpl");
882 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
884 $mail_enabled = false;
885 $pubmail_enabled = false;
887 if(($x['is_owner']) && (! $mail_disabled)) {
888 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
892 $mail_enabled = true;
893 if(intval($r[0]['pubmail']))
894 $pubmail_enabled = true;
899 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
900 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
903 call_hooks('jot_tool', $jotplugins);
904 call_hooks('jot_networks', $jotnets);
907 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
909 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
911 $o .= replace_macros($tpl,array(
912 '$return_path' => $a->cmd,
913 '$action' => $a->get_baseurl().'/item',
914 '$share' => (($x['button']) ? $x['button'] : t('Share')),
915 '$upload' => t('Upload photo'),
916 '$shortupload' => t('upload photo'),
917 '$attach' => t('Attach file'),
918 '$shortattach' => t('attach file'),
919 '$weblink' => t('Insert web link'),
920 '$shortweblink' => t('web link'),
921 '$video' => t('Insert video link'),
922 '$shortvideo' => t('video link'),
923 '$audio' => t('Insert audio link'),
924 '$shortaudio' => t('audio link'),
925 '$setloc' => t('Set your location'),
926 '$shortsetloc' => t('set location'),
927 '$noloc' => t('Clear browser location'),
928 '$shortnoloc' => t('clear location'),
930 '$placeholdertitle' => t('Set title'),
931 '$wait' => t('Please wait'),
932 '$permset' => t('Permission settings'),
933 '$shortpermset' => t('permissions'),
934 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
937 '$baseurl' => $a->get_baseurl(),
938 '$defloc' => $x['default_location'],
939 '$visitor' => $x['visitor'],
940 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
941 '$emailcc' => t('CC: email addresses'),
942 '$public' => t('Public post'),
943 '$jotnets' => $jotnets,
944 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
945 '$lockstate' => $x['lockstate'],
947 '$bang' => $x['bang'],
948 '$profile_uid' => $x['profile_uid'],
949 '$preview' => t('Preview'),
954 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
962 function conv_sort($arr,$order) {
964 if((!(is_array($arr) && count($arr))))
970 if($x['id'] == $x['parent'])
973 if(stristr($order,'created'))
974 usort($parents,'sort_thr_created');
975 elseif(stristr($order,'commented'))
976 usort($parents,'sort_thr_commented');
979 foreach($parents as $x)
980 $x['children'] = array();
982 foreach($arr as $x) {
983 if($x['id'] != $x['parent']) {
984 $p = find_thread_parent_index($parents,$x);
986 $parents[$p]['children'][] = $x;
989 if(count($parents)) {
990 foreach($parents as $k => $v) {
991 if(count($parents[$k]['children'])) {
992 $y = $parents[$k]['children'];
993 usort($y,'sort_thr_created_rev');
994 $parents[$k]['children'] = $y;
1000 if(count($parents)) {
1001 foreach($parents as $x) {
1003 if(count($x['children']))
1004 foreach($x['children'] as $y)
1013 function sort_thr_created($a,$b) {
1014 return strcmp($b['created'],$a['created']);
1017 function sort_thr_created_rev($a,$b) {
1018 return strcmp($a['created'],$b['created']);
1021 function sort_thr_commented($a,$b) {
1022 return strcmp($b['commented'],$a['commented']);
1025 function find_thread_parent_index($arr,$x) {
1026 foreach($arr as $k => $v)
1027 if($v['id'] == $x['parent'])
1032 function render_location_google($item) {
1034 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1035 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1038 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1040 $location = '<span class="smalltext">' . $coord . '</span>';