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');
190 $page_writeable = false;
192 $previewing = (($preview) ? ' preview ' : '');
194 if($mode === 'network') {
195 $profile_owner = local_user();
196 $page_writeable = true;
199 if($mode === 'profile') {
200 $profile_owner = $a->profile['profile_uid'];
201 $page_writeable = can_write_wall($a,$profile_owner);
204 if($mode === 'notes') {
205 $profile_owner = local_user();
206 $page_writeable = true;
209 if($mode === 'display') {
210 $profile_owner = $a->profile['uid'];
211 $page_writeable = can_write_wall($a,$profile_owner);
214 if($mode === 'community') {
216 $page_writeable = false;
220 $return_url = $_SESSION['return_url'];
222 $return_url = $_SESSION['return_url'] = $a->query_string;
224 load_contact_links(local_user());
226 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
227 call_hooks('conversation_start',$cb);
229 $items = $cb['items'];
231 $cmnt_tpl = get_markup_template('comment_item.tpl');
232 $tpl = 'wall_item.tpl';
233 $wallwall = 'wallwall_item.tpl';
234 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
240 // array with html for each thread (parent+comments)
246 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
248 // "New Item View" on network page or search page results
249 // - just loop through the items and format them minimally for display
251 //$tpl = get_markup_template('search_item.tpl');
252 $tpl = 'search_item.tpl';
254 foreach($items as $item) {
263 if($mode === 'search' || $mode === 'community') {
264 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
265 && ($item['id'] != $item['parent']))
267 $nickname = $item['nickname'];
270 $nickname = $a->user['nickname'];
273 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
274 if($item['author-link'] && (! $item['author-name']))
275 $profile_name = $item['author-link'];
278 $profile_link = best_link_url($item,$sp);
280 $sparkle = ' sparkle';
281 if($profile_link === 'mailbox')
285 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
286 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
287 $profile_avatar = $a->contacts[$normalised]['thumb'];
289 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
291 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
292 call_hooks('render_location',$locate);
294 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
296 localize_item($item);
297 if($mode === 'network-new')
304 'dropping' => $dropping,
305 'select' => t('Select'),
306 'delete' => t('Delete'),
310 $isstarred = "unstarred";
313 $likebuttons = false;
316 $body = prepare_body($item,true);
318 //$tmp_item = replace_macros($tpl,array(
321 'id' => (($preview) ? 'P0' : $item['item_id']),
322 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
323 'profile_url' => $profile_link,
324 'item_photo_menu' => item_photo_menu($item),
325 'name' => template_escape($profile_name),
326 'sparkle' => $sparkle,
328 'thumb' => $profile_avatar,
329 'title' => template_escape($item['title']),
330 'body' => template_escape($body),
331 'text' => strip_tags(template_escape($body)),
332 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
334 'location' => template_escape($location),
336 'owner_name' => template_escape($owner_name),
337 'owner_url' => $owner_url,
338 'owner_photo' => $owner_photo,
339 'plink' => get_plink($item),
341 'isstarred' => $isstarred,
344 'vote' => $likebuttons,
348 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
349 'previewing' => $previewing,
350 'wait' => t('Please wait'),
353 $arr = array('item' => $item, 'output' => $tmp_item);
354 call_hooks('display_item', $arr);
356 $threads[$threadsid]['id'] = $item['item_id'];
357 $threads[$threadsid]['items'] = array($arr['output']);
367 // Figure out how many comments each parent has
368 // (Comments all have gravity of 6)
369 // Store the result in the $comments array
372 foreach($items as $item) {
373 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
374 if(! x($comments,$item['parent']))
375 $comments[$item['parent']] = 1;
377 $comments[$item['parent']] += 1;
381 // map all the like/dislike activities for each parent item
382 // Store these in the $alike and $dlike arrays
384 foreach($items as $item) {
385 like_puller($a,$item,$alike,'like');
386 like_puller($a,$item,$dlike,'dislike');
389 $comments_collapsed = false;
390 $comment_lastcollapsed = false;
391 $comment_firstcollapsed = false;
396 foreach($items as $item) {
402 $owner_url = $owner_photo = $owner_name = '';
404 // We've already parsed out like/dislike for special treatment. We can ignore them now
406 if(((activity_match($item['verb'],ACTIVITY_LIKE))
407 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
408 && ($item['id'] != $item['parent']))
411 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
412 $toplevelprivate = false;
414 // Take care of author collapsing and comment collapsing
415 // (author collapsing is currently disabled)
416 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
417 // If there are more than two comments, squash all but the last 2.
420 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
421 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
424 $comments_collapsed = false;
425 $comment_lastcollapsed = false;
426 $comment_firstcollapsed = false;
429 $threads[$threadsid]['id'] = $item['item_id'];
430 $threads[$threadsid]['private'] = $item['private'];
431 $threads[$threadsid]['items'] = array();
436 // prevent private email reply to public conversation from leaking.
437 if($item['private'] && ! $threads[$threadsid]['private'])
441 $comment_lastcollapsed = false;
442 $comment_firstcollapsed = false;
445 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
446 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
449 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
451 if (!$comments_collapsed){
452 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
453 $threads[$threadsid]['hide_text'] = t('show more');
454 $comments_collapsed = true;
455 $comment_firstcollapsed = true;
458 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
460 $comment_lastcollapsed = true;
463 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
465 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
466 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
467 ? t('Private Message')
471 // Top-level wall post not written by the wall owner (wall-to-wall)
472 // First figure out who owns it.
476 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
480 // On the network page, I am the owner. On the display page it will be the profile owner.
481 // This will have been stored in $a->page_contact by our calling page.
482 // Put this person on the left of the wall-to-wall notice.
484 $owner_url = $a->page_contact['url'];
485 $owner_photo = $a->page_contact['thumb'];
486 $owner_name = $a->page_contact['name'];
487 $template = $wallwall;
490 if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
494 $owner_url = $item['owner-link'];
495 $owner_photo = $item['owner-avatar'];
496 $owner_name = $item['owner-name'];
497 $template = $wallwall;
499 // If it is our contact, use a friendly redirect link
500 if((link_compare($item['owner-link'],$item['url']))
501 && ($item['network'] === 'dfrn')) {
502 $owner_url = $redirect_url;
503 $osparkle = ' sparkle';
509 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
511 if($page_writeable) {
513 $likebuttons = array(
514 'like' => array( t("I like this \x28toggle\x29"), t("like")),
515 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
517 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
521 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
522 $qcomment = (($qc) ? explode("\n",$qc) : null);
524 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
525 $comment = replace_macros($cmnt_tpl,array(
526 '$return_path' => '',
527 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
528 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
529 '$id' => $item['item_id'],
530 '$parent' => $item['parent'],
531 '$qcomment' => $qcomment,
532 '$profile_uid' => $profile_owner,
533 '$mylink' => $a->contact['url'],
534 '$mytitle' => t('This is you'),
535 '$myphoto' => $a->contact['thumb'],
536 '$comment' => t('Comment'),
537 '$submit' => t('Submit'),
538 '$preview' => t('Preview'),
539 '$ww' => (($mode === 'network') ? $commentww : '')
544 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
545 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
552 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
556 'dropping' => $dropping,
557 'select' => t('Select'),
558 'delete' => t('Delete'),
562 $isstarred = "unstarred";
563 if ($profile_owner == local_user() && $toplevelpost) {
564 $isstarred = (($item['starred']) ? "starred" : "unstarred");
567 'do' => t("add star"),
568 'undo' => t("remove star"),
569 'toggle' => t("toggle star status"),
570 'classdo' => (($item['starred']) ? "hidden" : ""),
571 'classundo' => (($item['starred']) ? "" : "hidden"),
572 'starred' => t('starred'),
573 'tagger' => t("add tag"),
580 $photo = $item['photo'];
581 $thumb = $item['thumb'];
583 // Post was remotely authored.
585 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
587 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
589 if($item['author-link'] && (! $item['author-name']))
590 $profile_name = $item['author-link'];
594 $profile_link = best_link_url($item,$sp);
596 $sparkle = ' sparkle';
598 if($profile_link === 'mailbox')
601 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
602 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
603 $profile_avatar = $a->contacts[$normalised]['thumb'];
605 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
611 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
612 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
614 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
615 call_hooks('render_location',$locate);
617 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
619 $indent = (($toplevelpost) ? '' : ' comment');
621 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
625 localize_item($item);
629 foreach(explode(',',$item['tag']) as $tag){
631 if ($tag!="") $tags[] = bbcode($tag);
636 $body = prepare_body($item,true);
637 //$tmp_item = replace_macros($template,
639 // collapse comments in template. I don't like this much...
640 'comment_firstcollapsed' => $comment_firstcollapsed,
641 'comment_lastcollapsed' => $comment_lastcollapsed,
642 // template to use to render item (wall, walltowall, search)
643 'template' => $template,
645 'type' => implode("",array_slice(split("/",$item['verb']),-1)),
647 'body' => template_escape($body),
648 'text' => strip_tags(template_escape($body)),
649 'id' => $item['item_id'],
650 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
651 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
653 'wall' => t('Wall-to-Wall'),
654 'vwall' => t('via Wall-To-Wall:'),
655 'profile_url' => $profile_link,
656 'item_photo_menu' => item_photo_menu($item),
657 'name' => template_escape($profile_name),
658 'thumb' => $profile_avatar,
659 'osparkle' => $osparkle,
660 'sparkle' => $sparkle,
661 'title' => template_escape($item['title']),
662 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
664 'location' => template_escape($location),
666 'owner_url' => $owner_url,
667 'owner_photo' => $owner_photo,
668 'owner_name' => template_escape($owner_name),
669 'plink' => get_plink($item),
671 'isstarred' => $isstarred,
674 'vote' => $likebuttons,
676 'dislike' => $dislike,
677 'comment' => $comment,
678 'previewing' => $previewing,
679 'wait' => t('Please wait'),
684 $arr = array('item' => $item, 'output' => $tmp_item);
685 call_hooks('display_item', $arr);
687 $threads[$threadsid]['items'][] = $arr['output'];
692 $page_template = get_markup_template("conversation.tpl");
693 $o .= replace_macros($page_template, array(
694 '$baseurl' => $a->get_baseurl(),
697 '$threads' => $threads,
698 '$dropping' => ($dropping?t('Delete Selected Items'):False),
704 function best_link_url($item,&$sparkle) {
711 $clean_url = normalise_link($item['author-link']);
713 if((local_user()) && (local_user() == $item['uid'])) {
714 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
715 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
716 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
720 $best_url = $a->contacts[$clean_url]['url'];
724 if(strlen($item['author-link']))
725 $best_url = $item['author-link'];
727 $best_url = $item['url'];
734 if(! function_exists('item_photo_menu')){
735 function item_photo_menu($item){
738 if (local_user() && (! count($a->contacts)))
739 load_contact_links(local_user());
748 $profile_link = best_link_url($item,$sparkle);
749 if($profile_link === 'mailbox')
753 $cid = intval(basename($profile_link));
754 $status_link = $profile_link . "?url=status";
755 $photos_link = $profile_link . "?url=photos";
756 $profile_link = $profile_link . "?url=profile";
757 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
760 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
761 $cid = $item['contact-id'];
767 if(($cid) && (! $item['self'])) {
768 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
769 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
773 t("View status") => $status_link,
774 t("View profile") => $profile_link,
775 t("View photos") => $photos_link,
776 t("View recent") => $posts_link,
777 t("Edit contact") => $contact_url,
778 t("Send PM") => $pm_url,
782 $args = array('item' => $item, 'menu' => $menu);
784 call_hooks('item_photo_menu', $args);
786 $menu = $args['menu'];
789 foreach($menu as $k=>$v){
790 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
795 if(! function_exists('like_puller')) {
796 function like_puller($a,$item,&$arr,$mode) {
800 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
802 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
803 $url = $item['author-link'];
804 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
805 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
806 $sparkle = ' class="sparkle" ';
808 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
809 $arr[$item['parent'] . '-l'] = array();
810 if(! isset($arr[$item['parent']]))
811 $arr[$item['parent']] = 1;
813 $arr[$item['parent']] ++;
814 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
819 // Format the like/dislike text for a profile item
820 // $cnt = number of people who like/dislike the item
821 // $arr = array of pre-linked names of likers/dislikers
822 // $type = one of 'like, 'dislike'
824 // returns formatted text
826 if(! function_exists('format_like')) {
827 function format_like($cnt,$arr,$type,$id) {
830 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
832 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
833 $o .= (($type === 'like') ?
834 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
836 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
838 $total = count($arr);
839 if($total >= MAX_LIKERS)
840 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
841 if($total < MAX_LIKERS)
842 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
843 $str = implode(', ', $arr);
844 if($total >= MAX_LIKERS)
845 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
846 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
847 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
853 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
857 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
860 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
863 $tpl = get_markup_template('jot-header.tpl');
865 $a->page['htmlhead'] .= replace_macros($tpl, array(
866 '$newpost' => 'true',
867 '$baseurl' => $a->get_baseurl(),
868 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
869 '$geotag' => $geotag,
870 '$nickname' => $x['nickname'],
871 '$ispublic' => t('Visible to <strong>everybody</strong>'),
872 '$linkurl' => t('Please enter a link URL:'),
873 '$vidurl' => t("Please enter a video link/URL:"),
874 '$audurl' => t("Please enter an audio link/URL:"),
875 '$term' => t('Tag term:'),
876 '$whereareu' => t('Where are you right now?'),
877 '$title' => t('Enter a title for this item')
881 $tpl = get_markup_template("jot.tpl");
886 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
888 $mail_enabled = false;
889 $pubmail_enabled = false;
891 if(($x['is_owner']) && (! $mail_disabled)) {
892 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
896 $mail_enabled = true;
897 if(intval($r[0]['pubmail']))
898 $pubmail_enabled = true;
903 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
904 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
907 call_hooks('jot_tool', $jotplugins);
908 call_hooks('jot_networks', $jotnets);
911 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
913 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
915 $o .= replace_macros($tpl,array(
916 '$return_path' => $a->cmd,
917 '$action' => $a->get_baseurl().'/item',
918 '$share' => (($x['button']) ? $x['button'] : t('Share')),
919 '$upload' => t('Upload photo'),
920 '$shortupload' => t('upload photo'),
921 '$attach' => t('Attach file'),
922 '$shortattach' => t('attach file'),
923 '$weblink' => t('Insert web link'),
924 '$shortweblink' => t('web link'),
925 '$video' => t('Insert video link'),
926 '$shortvideo' => t('video link'),
927 '$audio' => t('Insert audio link'),
928 '$shortaudio' => t('audio link'),
929 '$setloc' => t('Set your location'),
930 '$shortsetloc' => t('set location'),
931 '$noloc' => t('Clear browser location'),
932 '$shortnoloc' => t('clear location'),
934 '$placeholdertitle' => t('Set title'),
935 '$wait' => t('Please wait'),
936 '$permset' => t('Permission settings'),
937 '$shortpermset' => t('permissions'),
938 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
941 '$baseurl' => $a->get_baseurl(),
942 '$defloc' => $x['default_location'],
943 '$visitor' => $x['visitor'],
944 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
945 '$emailcc' => t('CC: email addresses'),
946 '$public' => t('Public post'),
947 '$jotnets' => $jotnets,
948 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
949 '$lockstate' => $x['lockstate'],
951 '$bang' => $x['bang'],
952 '$profile_uid' => $x['profile_uid'],
953 '$preview' => t('Preview'),
958 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
966 function conv_sort($arr,$order) {
968 if((!(is_array($arr) && count($arr))))
974 if($x['id'] == $x['parent'])
977 if(stristr($order,'created'))
978 usort($parents,'sort_thr_created');
979 elseif(stristr($order,'commented'))
980 usort($parents,'sort_thr_commented');
983 foreach($parents as $x)
984 $x['children'] = array();
986 foreach($arr as $x) {
987 if($x['id'] != $x['parent']) {
988 $p = find_thread_parent_index($parents,$x);
990 $parents[$p]['children'][] = $x;
993 if(count($parents)) {
994 foreach($parents as $k => $v) {
995 if(count($parents[$k]['children'])) {
996 $y = $parents[$k]['children'];
997 usort($y,'sort_thr_created_rev');
998 $parents[$k]['children'] = $y;
1004 if(count($parents)) {
1005 foreach($parents as $x) {
1007 if(count($x['children']))
1008 foreach($x['children'] as $y)
1017 function sort_thr_created($a,$b) {
1018 return strcmp($b['created'],$a['created']);
1021 function sort_thr_created_rev($a,$b) {
1022 return strcmp($a['created'],$b['created']);
1025 function sort_thr_commented($a,$b) {
1026 return strcmp($b['commented'],$a['commented']);
1029 function find_thread_parent_index($arr,$x) {
1030 foreach($arr as $k => $v)
1031 if($v['id'] == $x['parent'])
1036 function render_location_google($item) {
1038 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1039 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1042 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1044 $location = '<span class="smalltext">' . $coord . '</span>';