4 * Render actions localized
6 function localize_item(&$item){
11 // find private image (w/data url) if present and convert image
12 // link to a magic-auth redirect.
15 $img_start = strpos($Text,'[img]data:');
16 $img_end = strpos($Text,'[/img]');
18 if($img_start !== false && $img_end !== false && $img_end > $img_start) {
19 $start_fragment = substr($Text,0,$img_start);
20 $img_start += strlen('[img]');
21 $saved_image = substr($Text,$img_start,$img_end - $img_start);
22 $end_fragment = substr($Text,$img_end + strlen('[/img]'));
23 $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
24 $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
25 $replace = '[url=' . z_path() . '/redir/' . $item['contact-id']
26 . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
28 $Text = preg_replace($search,$replace,$Text);
30 if(strlen($saved_image))
31 $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
34 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
35 if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
37 $r = q("SELECT * from `item`,`contact` WHERE
38 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
39 dbesc($item['parent-uri']));
40 if(count($r)==0) return;
43 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
44 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
48 switch ($obj['object-type']){
49 case ACTIVITY_OBJ_EVENT:
50 $post_type = t('event');
53 $post_type = t('status');
57 if($obj['resource-id']){
58 $post_type = t('photo');
59 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
62 $post_type = t('status');
66 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
68 switch($item['verb']){
70 $bodyverb = t('%1$s likes %2$s\'s %3$s');
72 case ACTIVITY_DISLIKE:
73 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
76 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
79 if ($item['verb']=== ACTIVITY_FRIEND){
81 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
83 $Aname = $item['author-name'];
84 $Alink = $item['author-link'];
86 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
88 $obj = parse_xml_string($xmlhead.$item['object']);
89 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
92 $Blink = ""; $Bphoto = "";
93 foreach ($links->link as $l){
94 $atts = $l->attributes();
96 case "alternate": $Blink = $atts['href'];
97 case "photo": $Bphoto = $atts['href'];
102 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
103 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
104 if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
106 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
109 if ($item['verb']===ACTIVITY_TAG){
110 $r = q("SELECT * from `item`,`contact` WHERE
111 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
112 dbesc($item['parent-uri']));
113 if(count($r)==0) return;
116 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
117 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
119 switch($obj['verb']){
121 switch ($obj['object-type']){
122 case ACTIVITY_OBJ_EVENT:
123 $post_type = t('event');
126 $post_type = t('status');
130 if($obj['resource-id']){
131 $post_type = t('photo');
132 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
133 $rr['plink'] = $m[1];
135 $post_type = t('status');
138 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
140 $parsedobj = parse_xml_string($xmlhead.$item['object']);
142 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
143 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
146 if ($item['verb']=== ACTIVITY_FAVORITE){
148 if ($item['object-type']== "")
151 $Aname = $item['author-name'];
152 $Alink = $item['author-link'];
154 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
156 $obj = parse_xml_string($xmlhead.$item['object']);
157 if(strlen($obj->id)) {
158 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
162 if(count($r) && $r[0]['plink']) {
164 $Bname = $target['author-name'];
165 $Blink = $target['author-link'];
166 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
167 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
168 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
169 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
178 * "Render" a conversation or list of items for HTML display.
179 * There are two major forms of display:
180 * - Sequential or unthreaded ("New Item View" or search results)
181 * - conversation view
182 * The $mode parameter decides between the various renderings and also
183 * figures out how to determine page owner and other contextual items
184 * that are based on unique features of the calling module.
187 function conversation(&$a, $items, $mode, $update, $preview = false) {
189 require_once('bbcode.php');
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->cmd;
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 = get_markup_template('wall_item.tpl');
235 $wallwall = get_markup_template('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');
255 foreach($items as $item) {
264 if($mode === 'search' || $mode === 'community') {
265 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
266 && ($item['id'] != $item['parent']))
268 $nickname = $item['nickname'];
271 $nickname = $a->user['nickname'];
274 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
275 if($item['author-link'] && (! $item['author-name']))
276 $profile_name = $item['author-link'];
279 $profile_link = best_link_url($item,$sp);
281 $sparkle = ' sparkle';
282 if($profile_link === 'mailbox')
286 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
287 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
288 $profile_avatar = $a->contacts[$normalised]['thumb'];
290 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
292 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
293 call_hooks('render_location',$locate);
295 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
297 localize_item($item);
298 if($mode === 'network-new')
305 'dropping' => $dropping,
306 'select' => t('Select'),
307 'delete' => t('Delete'),
311 $isstarred = "unstarred";
314 $likebuttons = false;
317 $body = prepare_body($item,true);
319 $tmp_item = replace_macros($tpl,array(
320 '$id' => (($preview) ? 'P0' : $item['item_id']),
321 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
322 '$profile_url' => $profile_link,
323 '$item_photo_menu' => item_photo_menu($item),
324 '$name' => template_escape($profile_name),
325 '$sparkle' => $sparkle,
327 '$thumb' => $profile_avatar,
328 '$title' => template_escape($item['title']),
329 '$body' => 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]['html'] .= $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;
376 } elseif(! x($comments,$item['parent']))
377 $comments[$item['parent']] = 0; // avoid notices later on
380 // map all the like/dislike activities for each parent item
381 // Store these in the $alike and $dlike arrays
383 foreach($items as $item) {
384 like_puller($a,$item,$alike,'like');
385 like_puller($a,$item,$dlike,'dislike');
388 $comments_collapsed = false;
393 foreach($items as $item) {
399 $owner_url = $owner_photo = $owner_name = '';
401 // We've already parsed out like/dislike for special treatment. We can ignore them now
403 if(((activity_match($item['verb'],ACTIVITY_LIKE))
404 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
405 && ($item['id'] != $item['parent']))
408 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
409 $toplevelprivate = false;
411 // Take care of author collapsing and comment collapsing
412 // (author collapsing is currently disabled)
413 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
414 // If there are more than two comments, squash all but the last 2.
417 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
418 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
422 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
424 if($blowhard_count == 3) {
425 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
426 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
427 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
428 . $item['parent'] . '" style="display: none;" >';
432 $blowhard = $item['cid'];
433 if($blowhard_count >= 3)
441 $comments_collapsed = false;
444 $threads[$threadsid]['id'] = $item['item_id'];
445 $threads[$threadsid]['html'] = "";
449 // prevent private email from leaking into public conversation
450 if((! $toplevelpost) && (! $toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
455 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
456 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
459 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
460 if(! $comments_collapsed) {
462 // IMPORTANT: the closing </div> in the hide_comments template
463 // is supplied below in code.
465 $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
466 '$id' => $item['parent'],
467 '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
468 $comments[$item['parent']]),
469 '$display' => 'none',
470 '$hide_text' => t('show more')
472 $comments_collapsed = true;
475 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
476 $threads[$threadsid]['html'] .= '</div>';
479 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
481 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
482 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
483 ? t('Private Message')
487 // Top-level wall post not written by the wall owner (wall-to-wall)
488 // First figure out who owns it.
492 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
496 // On the network page, I am the owner. On the display page it will be the profile owner.
497 // This will have been stored in $a->page_contact by our calling page.
498 // Put this person on the left of the wall-to-wall notice.
500 $owner_url = $a->page_contact['url'];
501 $owner_photo = $a->page_contact['thumb'];
502 $owner_name = $a->page_contact['name'];
503 $template = $wallwall;
506 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
510 $owner_url = $item['owner-link'];
511 $owner_photo = $item['owner-avatar'];
512 $owner_name = $item['owner-name'];
513 $template = $wallwall;
515 // If it is our contact, use a friendly redirect link
516 if((link_compare($item['owner-link'],$item['url']))
517 && ($item['network'] === 'dfrn')) {
518 $owner_url = $redirect_url;
519 $osparkle = ' sparkle';
525 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
527 if($page_writeable) {
529 $likebuttons = array(
530 'like' => array( t("I like this \x28toggle\x29"), t("like")),
531 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
533 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
537 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
538 $qcomment = (($qc) ? explode("\n",$qc) : null);
540 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
541 $comment = replace_macros($cmnt_tpl,array(
542 '$return_path' => '',
543 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
544 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
545 '$id' => $item['item_id'],
546 '$parent' => $item['parent'],
547 '$qcomment' => $qcomment,
548 '$profile_uid' => $profile_owner,
549 '$mylink' => $a->contact['url'],
550 '$mytitle' => t('This is you'),
551 '$myphoto' => $a->contact['thumb'],
552 '$comment' => t('Comment'),
553 '$submit' => t('Submit'),
554 '$preview' => t('Preview'),
555 '$ww' => (($mode === 'network') ? $commentww : '')
560 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
561 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
568 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
572 'dropping' => $dropping,
573 'select' => t('Select'),
574 'delete' => t('Delete'),
578 $isstarred = "unstarred";
579 if ($profile_owner == local_user() && $toplevelpost) {
580 $isstarred = (($item['starred']) ? "starred" : "unstarred");
583 'do' => t("add star"),
584 'undo' => t("remove star"),
585 'toggle' => t("toggle star status"),
586 'classdo' => (($item['starred']) ? "hidden" : ""),
587 'classundo' => (($item['starred']) ? "" : "hidden"),
588 'starred' => t('starred'),
589 'tagger' => t("add tag"),
596 $photo = $item['photo'];
597 $thumb = $item['thumb'];
599 // Post was remotely authored.
601 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
603 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
605 if($item['author-link'] && (! $item['author-name']))
606 $profile_name = $item['author-link'];
610 $profile_link = best_link_url($item,$sp);
612 $sparkle = ' sparkle';
614 if($profile_link === 'mailbox')
617 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
618 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
619 $profile_avatar = $a->contacts[$normalised]['thumb'];
621 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
627 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
628 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
630 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
631 call_hooks('render_location',$locate);
633 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
635 $indent = (($toplevelpost) ? '' : ' comment');
637 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
641 localize_item($item);
645 foreach(explode(',',$item['tag']) as $tag){
647 if ($tag!="") $tags[] = bbcode($tag);
652 $body = prepare_body($item,true);
654 $tmp_item = replace_macros($template,array(
655 '$type' => implode("",array_slice(explode("/",$item['verb']),-1)),
657 '$body' => template_escape($body),
658 '$id' => $item['item_id'],
659 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
660 '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
662 '$wall' => t('Wall-to-Wall'),
663 '$vwall' => t('via Wall-To-Wall:'),
664 '$profile_url' => $profile_link,
665 '$item_photo_menu' => item_photo_menu($item),
666 '$name' => template_escape($profile_name),
667 '$thumb' => $profile_avatar,
668 '$osparkle' => $osparkle,
669 '$sparkle' => $sparkle,
670 '$title' => template_escape($item['title']),
671 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
673 '$location' => template_escape($location),
674 '$indent' => $indent,
675 '$owner_url' => $owner_url,
676 '$owner_photo' => $owner_photo,
677 '$owner_name' => template_escape($owner_name),
678 '$plink' => get_plink($item),
679 '$edpost' => $edpost,
680 '$isstarred' => $isstarred,
683 '$vote' => $likebuttons,
685 '$dislike' => $dislike,
686 '$comment' => $comment,
687 '$previewing' => $previewing,
688 '$wait' => t('Please wait'),
693 $arr = array('item' => $item, 'output' => $tmp_item);
694 call_hooks('display_item', $arr);
696 $threads[$threadsid]['html'] .= $arr['output'];
702 $page_template = get_markup_template("conversation.tpl");
703 $o .= replace_macros($page_template, array(
704 '$threads' => $threads,
705 '$dropping' => ($dropping?t('Delete Selected Items'):False),
711 function best_link_url($item,&$sparkle) {
718 $clean_url = normalise_link($item['author-link']);
720 if((local_user()) && (local_user() == $item['uid'])) {
721 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
722 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
723 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
727 $best_url = $a->contacts[$clean_url]['url'];
731 if(strlen($item['author-link']))
732 $best_url = $item['author-link'];
734 $best_url = $item['url'];
741 if(! function_exists('item_photo_menu')){
742 function item_photo_menu($item){
745 if (local_user() && (! count($a->contacts)))
746 load_contact_links(local_user());
755 $profile_link = best_link_url($item,$sparkle);
756 if($profile_link === 'mailbox')
760 $cid = intval(basename($profile_link));
761 $status_link = $profile_link . "?url=status";
762 $photos_link = $profile_link . "?url=photos";
763 $profile_link = $profile_link . "?url=profile";
764 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
767 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
768 $cid = $item['contact-id'];
774 if(($cid) && (! $item['self'])) {
775 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
776 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
780 t("View status") => $status_link,
781 t("View profile") => $profile_link,
782 t("View photos") => $photos_link,
783 t("View recent") => $posts_link,
784 t("Edit contact") => $contact_url,
785 t("Send PM") => $pm_url,
789 $args = array('item' => $item, 'menu' => $menu);
791 call_hooks('item_photo_menu', $args);
793 $menu = $args['menu'];
796 foreach($menu as $k=>$v){
797 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
802 if(! function_exists('like_puller')) {
803 function like_puller($a,$item,&$arr,$mode) {
807 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
809 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
810 $url = $item['author-link'];
811 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
812 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
813 $sparkle = ' class="sparkle" ';
815 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
816 $arr[$item['parent'] . '-l'] = array();
817 if(! isset($arr[$item['parent']]))
818 $arr[$item['parent']] = 1;
820 $arr[$item['parent']] ++;
821 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
826 // Format the like/dislike text for a profile item
827 // $cnt = number of people who like/dislike the item
828 // $arr = array of pre-linked names of likers/dislikers
829 // $type = one of 'like, 'dislike'
831 // returns formatted text
833 if(! function_exists('format_like')) {
834 function format_like($cnt,$arr,$type,$id) {
837 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
839 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
840 $o .= (($type === 'like') ?
841 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
843 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
845 $total = count($arr);
846 if($total >= MAX_LIKERS)
847 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
848 if($total < MAX_LIKERS)
849 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
850 $str = implode(', ', $arr);
851 if($total >= MAX_LIKERS)
852 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
853 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
854 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
860 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
864 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
867 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
870 $tpl = get_markup_template('jot-header.tpl');
872 $a->page['htmlhead'] .= replace_macros($tpl, array(
873 '$newpost' => 'true',
874 '$baseurl' => $a->get_baseurl(),
875 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
876 '$geotag' => $geotag,
877 '$nickname' => $x['nickname'],
878 '$ispublic' => t('Visible to <strong>everybody</strong>'),
879 '$linkurl' => t('Please enter a link URL:'),
880 '$vidurl' => t("Please enter a video link/URL:"),
881 '$audurl' => t("Please enter an audio link/URL:"),
882 '$term' => t('Tag term:'),
883 '$whereareu' => t('Where are you right now?'),
884 '$title' => t('Enter a title for this item')
888 $tpl = get_markup_template("jot.tpl");
893 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
895 $mail_enabled = false;
896 $pubmail_enabled = false;
898 if(($x['is_owner']) && (! $mail_disabled)) {
899 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
903 $mail_enabled = true;
904 if(intval($r[0]['pubmail']))
905 $pubmail_enabled = true;
910 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
911 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
914 call_hooks('jot_tool', $jotplugins);
915 call_hooks('jot_networks', $jotnets);
918 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
920 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
922 $o .= replace_macros($tpl,array(
923 '$return_path' => $a->cmd,
924 '$action' => $a->get_baseurl().'/item',
925 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
926 '$upload' => t('Upload photo'),
927 '$shortupload' => t('upload photo'),
928 '$attach' => t('Attach file'),
929 '$shortattach' => t('attach file'),
930 '$weblink' => t('Insert web link'),
931 '$shortweblink' => t('web link'),
932 '$video' => t('Insert video link'),
933 '$shortvideo' => t('video link'),
934 '$audio' => t('Insert audio link'),
935 '$shortaudio' => t('audio link'),
936 '$setloc' => t('Set your location'),
937 '$shortsetloc' => t('set location'),
938 '$noloc' => t('Clear browser location'),
939 '$shortnoloc' => t('clear location'),
941 '$placeholdertitle' => t('Set title'),
942 '$wait' => t('Please wait'),
943 '$permset' => t('Permission settings'),
944 '$shortpermset' => t('permissions'),
945 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
948 '$baseurl' => $a->get_baseurl(),
949 '$defloc' => $x['default_location'],
950 '$visitor' => $x['visitor'],
951 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
952 '$emailcc' => t('CC: email addresses'),
953 '$public' => t('Public post'),
954 '$jotnets' => $jotnets,
955 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
956 '$lockstate' => $x['lockstate'],
958 '$bang' => $x['bang'],
959 '$profile_uid' => $x['profile_uid'],
960 '$preview' => t('Preview'),
965 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
973 function conv_sort($arr,$order) {
975 if((!(is_array($arr) && count($arr))))
981 if($x['id'] == $x['parent'])
984 if(stristr($order,'created'))
985 usort($parents,'sort_thr_created');
986 elseif(stristr($order,'commented'))
987 usort($parents,'sort_thr_commented');
990 foreach($parents as $i=>$_x)
991 $parents[$i]['children'] = array();
993 foreach($arr as $x) {
994 if($x['id'] != $x['parent']) {
995 $p = find_thread_parent_index($parents,$x);
997 $parents[$p]['children'][] = $x;
1000 if(count($parents)) {
1001 foreach($parents as $k => $v) {
1002 if(count($parents[$k]['children'])) {
1003 $y = $parents[$k]['children'];
1004 usort($y,'sort_thr_created_rev');
1005 $parents[$k]['children'] = $y;
1011 if(count($parents)) {
1012 foreach($parents as $x) {
1014 if(count($x['children']))
1015 foreach($x['children'] as $y)
1024 function sort_thr_created($a,$b) {
1025 return strcmp($b['created'],$a['created']);
1028 function sort_thr_created_rev($a,$b) {
1029 return strcmp($a['created'],$b['created']);
1032 function sort_thr_commented($a,$b) {
1033 return strcmp($b['commented'],$a['commented']);
1036 function find_thread_parent_index($arr,$x) {
1037 foreach($arr as $k => $v)
1038 if($v['id'] == $x['parent'])
1043 function render_location_google($item) {
1045 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1046 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1049 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1051 $location = '<span class="smalltext">' . $coord . '</span>';