4 * Render actions localized
6 function localize_item(&$item){
7 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
8 if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
10 $r = q("SELECT * from `item`,`contact` WHERE
11 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
12 dbesc($item['parent-uri']));
13 if(count($r)==0) return;
16 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
17 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
21 switch ($obj['object-type']){
22 case ACTIVITY_OBJ_EVENT:
23 $post_type = t('event');
26 $post_type = t('status');
30 if($obj['resource-id']){
31 $post_type = t('photo');
32 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
35 $post_type = t('status');
39 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
41 switch($item['verb']){
43 $bodyverb = t('%1$s likes %2$s\'s %3$s');
45 case ACTIVITY_DISLIKE:
46 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
49 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
52 if ($item['verb']=== ACTIVITY_FRIEND){
54 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
56 $Aname = $item['author-name'];
57 $Alink = $item['author-link'];
59 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
61 $obj = parse_xml_string($xmlhead.$item['object']);
62 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
65 $Blink = ""; $Bphoto = "";
66 foreach ($links->link as $l){
67 $atts = $l->attributes();
69 case "alternate": $Blink = $atts['href'];
70 case "photo": $Bphoto = $atts['href'];
75 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
76 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
77 if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
79 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
82 if ($item['verb']===ACTIVITY_TAG){
83 $r = q("SELECT * from `item`,`contact` WHERE
84 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
85 dbesc($item['parent-uri']));
86 if(count($r)==0) return;
89 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
90 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
94 switch ($obj['object-type']){
95 case ACTIVITY_OBJ_EVENT:
96 $post_type = t('event');
99 $post_type = t('status');
103 if($obj['resource-id']){
104 $post_type = t('photo');
105 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
106 $rr['plink'] = $m[1];
108 $post_type = t('status');
111 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
113 $parsedobj = parse_xml_string($xmlhead.$item['object']);
115 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
116 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
119 if ($item['verb']=== ACTIVITY_FAVORITE){
121 if ($item['object-type']== "")
124 $Aname = $item['author-name'];
125 $Alink = $item['author-link'];
127 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
129 $obj = parse_xml_string($xmlhead.$item['object']);
130 if(strlen($obj->id)) {
131 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
135 if(count($r) && $r[0]['plink']) {
137 $Bname = $target['author-name'];
138 $Blink = $target['author-link'];
139 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
140 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
141 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
142 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
151 * "Render" a conversation or list of items for HTML display.
152 * There are two major forms of display:
153 * - Sequential or unthreaded ("New Item View" or search results)
154 * - conversation view
155 * The $mode parameter decides between the various renderings and also
156 * figures out how to determine page owner and other contextual items
157 * that are based on unique features of the calling module.
160 function conversation(&$a, $items, $mode, $update, $preview = false) {
162 require_once('bbcode.php');
165 $page_writeable = false;
167 $previewing = (($preview) ? ' preview ' : '');
169 if($mode === 'network') {
170 $profile_owner = local_user();
171 $page_writeable = true;
174 if($mode === 'profile') {
175 $profile_owner = $a->profile['profile_uid'];
176 $page_writeable = can_write_wall($a,$profile_owner);
179 if($mode === 'notes') {
180 $profile_owner = local_user();
181 $page_writeable = true;
184 if($mode === 'display') {
185 $profile_owner = $a->profile['uid'];
186 $page_writeable = can_write_wall($a,$profile_owner);
189 if($mode === 'community') {
191 $page_writeable = false;
195 $return_url = $_SESSION['return_url'];
197 $return_url = $_SESSION['return_url'] = $a->cmd;
199 load_contact_links(local_user());
201 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
202 call_hooks('conversation_start',$cb);
204 $items = $cb['items'];
206 $cmnt_tpl = get_markup_template('comment_item.tpl');
207 $tpl = get_markup_template('wall_item.tpl');
208 $wallwall = get_markup_template('wallwall_item.tpl');
209 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
215 // array with html for each thread (parent+comments)
221 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
223 // "New Item View" on network page or search page results
224 // - just loop through the items and format them minimally for display
226 $tpl = get_markup_template('search_item.tpl');
228 foreach($items as $item) {
237 if($mode === 'search' || $mode === 'community') {
238 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
239 && ($item['id'] != $item['parent']))
241 $nickname = $item['nickname'];
244 $nickname = $a->user['nickname'];
247 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
248 if($item['author-link'] && (! $item['author-name']))
249 $profile_name = $item['author-link'];
252 $profile_link = best_link_url($item,$sp);
254 $sparkle = ' sparkle';
255 if($profile_link === 'mailbox')
259 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
260 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
261 $profile_avatar = $a->contacts[$normalised]['thumb'];
263 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
265 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
266 call_hooks('render_location',$locate);
268 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
270 localize_item($item);
271 if($mode === 'network-new')
278 'dropping' => $dropping,
279 'select' => t('Select'),
280 'delete' => t('Delete'),
284 $isstarred = "unstarred";
287 $likebuttons = false;
290 $body = prepare_body($item,true);
292 $tmp_item = replace_macros($tpl,array(
293 '$id' => (($preview) ? 'P0' : $item['item_id']),
294 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
295 '$profile_url' => $profile_link,
296 '$item_photo_menu' => item_photo_menu($item),
297 '$name' => template_escape($profile_name),
298 '$sparkle' => $sparkle,
300 '$thumb' => $profile_avatar,
301 '$title' => template_escape($item['title']),
302 '$body' => template_escape($body),
303 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
305 '$location' => template_escape($location),
307 '$owner_name' => template_escape($owner_name),
308 '$owner_url' => $owner_url,
309 '$owner_photo' => $owner_photo,
310 '$plink' => get_plink($item),
312 '$isstarred' => $isstarred,
315 '$vote' => $likebuttons,
319 '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
320 '$previewing' => $previewing,
321 '$wait' => t('Please wait'),
324 $arr = array('item' => $item, 'output' => $tmp_item);
325 call_hooks('display_item', $arr);
327 $threads[$threadsid]['id'] = $item['item_id'];
328 $threads[$threadsid]['html'] .= $arr['output'];
338 // Figure out how many comments each parent has
339 // (Comments all have gravity of 6)
340 // Store the result in the $comments array
343 foreach($items as $item) {
344 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
345 if(! x($comments,$item['parent']))
346 $comments[$item['parent']] = 1;
348 $comments[$item['parent']] += 1;
352 // map all the like/dislike activities for each parent item
353 // Store these in the $alike and $dlike arrays
355 foreach($items as $item) {
356 like_puller($a,$item,$alike,'like');
357 like_puller($a,$item,$dlike,'dislike');
360 $comments_collapsed = false;
365 foreach($items as $item) {
371 $owner_url = $owner_photo = $owner_name = '';
373 // We've already parsed out like/dislike for special treatment. We can ignore them now
375 if(((activity_match($item['verb'],ACTIVITY_LIKE))
376 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
377 && ($item['id'] != $item['parent']))
380 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
381 $toplevelprivate = false;
383 // Take care of author collapsing and comment collapsing
384 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
385 // If there are more than two comments, squash all but the last 2.
388 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
389 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
391 /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
393 if($blowhard_count == 3) {
394 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
395 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
396 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
397 . $item['parent'] . '" style="display: none;" >';
401 $blowhard = $item['cid'];
402 if($blowhard_count >= 3)
408 $comments_collapsed = false;
411 $threads[$threadsid]['id'] = $item['item_id'];
412 $threads[$threadsid]['html'] = "";
416 // prevent private email from leaking into public conversation
417 if((! $toplevelpost) && (! toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
422 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
423 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
426 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
427 if(! $comments_collapsed) {
429 // IMPORTANT: the closing </div> in the hide_comments template
430 // is supplied below in code.
432 $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
433 '$id' => $item['parent'],
434 '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
435 $comments[$item['parent']]),
436 '$display' => 'none',
437 '$hide_text' => t('show more')
439 $comments_collapsed = true;
442 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
443 $threads[$threadsid]['html'] .= '</div>';
446 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
448 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
449 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
450 ? t('Private Message')
454 // Top-level wall post not written by the wall owner (wall-to-wall)
455 // First figure out who owns it.
459 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
463 // On the network page, I am the owner. On the display page it will be the profile owner.
464 // This will have been stored in $a->page_contact by our calling page.
465 // Put this person on the left of the wall-to-wall notice.
467 $owner_url = $a->page_contact['url'];
468 $owner_photo = $a->page_contact['thumb'];
469 $owner_name = $a->page_contact['name'];
470 $template = $wallwall;
473 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
477 $owner_url = $item['owner-link'];
478 $owner_photo = $item['owner-avatar'];
479 $owner_name = $item['owner-name'];
480 $template = $wallwall;
482 // If it is our contact, use a friendly redirect link
483 if((link_compare($item['owner-link'],$item['url']))
484 && ($item['network'] === 'dfrn')) {
485 $owner_url = $redirect_url;
486 $osparkle = ' sparkle';
492 $shareable = ((($profile_owner == local_user()) && ($mode != 'display') && (! $item['private'])) ? true : false);
494 if($page_writeable) {
496 $likebuttons = array(
497 'like' => array( t("I like this \x28toggle\x29"), t("like")),
498 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
500 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
503 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
504 $comment = replace_macros($cmnt_tpl,array(
505 '$return_path' => '',
506 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
507 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
508 '$id' => $item['item_id'],
509 '$parent' => $item['parent'],
510 '$profile_uid' => $profile_owner,
511 '$mylink' => $a->contact['url'],
512 '$mytitle' => t('This is you'),
513 '$myphoto' => $a->contact['thumb'],
514 '$comment' => t('Comment'),
515 '$submit' => t('Submit'),
516 '$preview' => t('Preview'),
517 '$ww' => (($mode === 'network') ? $commentww : '')
522 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
523 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
530 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
534 'dropping' => $dropping,
535 'select' => t('Select'),
536 'delete' => t('Delete'),
540 $isstarred = "unstarred";
541 if ($profile_owner == local_user() && $toplevelpost) {
542 $isstarred = (($item['starred']) ? "starred" : "unstarred");
545 'do' => t("add star"),
546 'undo' => t("remove star"),
547 'toggle' => t("toggle star status"),
548 'classdo' => (($item['starred']) ? "hidden" : ""),
549 'classundo' => (($item['starred']) ? "" : "hidden"),
550 'starred' => t('starred'),
551 'tagger' => t("add tag"),
558 $photo = $item['photo'];
559 $thumb = $item['thumb'];
561 // Post was remotely authored.
563 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
565 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
567 if($item['author-link'] && (! $item['author-name']))
568 $profile_name = $item['author-link'];
572 $profile_link = best_link_url($item,$sp);
574 $sparkle = ' sparkle';
576 if($profile_link === 'mailbox')
579 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
580 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
581 $profile_avatar = $a->contacts[$normalised]['thumb'];
583 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
589 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
590 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
592 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
593 call_hooks('render_location',$locate);
595 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
597 $indent = (($toplevelpost) ? '' : ' comment');
599 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
603 localize_item($item);
607 foreach(explode(',',$item['tag']) as $tag){
609 if ($tag!="") $tags[] = bbcode($tag);
615 $body = prepare_body($item,true);
618 $tmp_item = replace_macros($template,array(
619 '$type' => implode("",array_slice(split("/",$item['verb']),-1)),
621 '$body' => template_escape($body),
622 '$id' => $item['item_id'],
623 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
624 '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
626 '$wall' => t('Wall-to-Wall'),
627 '$vwall' => t('via Wall-To-Wall:'),
628 '$profile_url' => $profile_link,
629 '$item_photo_menu' => item_photo_menu($item),
630 '$name' => template_escape($profile_name),
631 '$thumb' => $profile_avatar,
632 '$osparkle' => $osparkle,
633 '$sparkle' => $sparkle,
634 '$title' => template_escape($item['title']),
635 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
637 '$location' => template_escape($location),
638 '$indent' => $indent,
639 '$owner_url' => $owner_url,
640 '$owner_photo' => $owner_photo,
641 '$owner_name' => template_escape($owner_name),
642 '$plink' => get_plink($item),
643 '$edpost' => $edpost,
644 '$isstarred' => $isstarred,
647 '$vote' => $likebuttons,
649 '$dislike' => $dislike,
650 '$comment' => $comment,
651 '$previewing' => $previewing,
652 '$wait' => t('Please wait'),
657 $arr = array('item' => $item, 'output' => $tmp_item);
658 call_hooks('display_item', $arr);
660 $threads[$threadsid]['html'] .= $arr['output'];
666 $page_template = get_markup_template("conversation.tpl");
667 $o .= replace_macros($page_template, array(
668 '$threads' => $threads,
669 '$dropping' => ($dropping?t('Delete Selected Items'):False),
675 function best_link_url($item,&$sparkle) {
682 $clean_url = normalise_link($item['author-link']);
684 if((local_user()) && (local_user() == $item['uid'])) {
685 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
686 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
687 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
691 $best_url = $a->contacts[$clean_url]['url'];
695 if(strlen($item['author-link']))
696 $best_url = $item['author-link'];
698 $best_url = $item['url'];
705 if(! function_exists('item_photo_menu')){
706 function item_photo_menu($item){
709 if (local_user() && (! count($a->contacts)))
710 load_contact_links(local_user());
719 $profile_link = best_link_url($item,$sparkle);
720 if($profile_link === 'mailbox')
724 $cid = intval(basename($profile_link));
725 $status_link = $profile_link . "?url=status";
726 $photos_link = $profile_link . "?url=photos";
727 $profile_link = $profile_link . "?url=profile";
728 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
731 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
732 $cid = $item['contact-id'];
738 if(($cid) && (! $item['self'])) {
739 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
740 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
744 t("View status") => $status_link,
745 t("View profile") => $profile_link,
746 t("View photos") => $photos_link,
747 t("View recent") => $posts_link,
748 t("Edit contact") => $contact_url,
749 t("Send PM") => $pm_url,
753 $args = array('item' => $item, 'menu' => $menu);
755 call_hooks('item_photo_menu', $args);
757 $menu = $args['menu'];
760 foreach($menu as $k=>$v){
761 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
766 if(! function_exists('like_puller')) {
767 function like_puller($a,$item,&$arr,$mode) {
771 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
773 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
774 $url = $item['author-link'];
775 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
776 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
777 $sparkle = ' class="sparkle" ';
779 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
780 $arr[$item['parent'] . '-l'] = array();
781 if(! isset($arr[$item['parent']]))
782 $arr[$item['parent']] = 1;
784 $arr[$item['parent']] ++;
785 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
790 // Format the like/dislike text for a profile item
791 // $cnt = number of people who like/dislike the item
792 // $arr = array of pre-linked names of likers/dislikers
793 // $type = one of 'like, 'dislike'
795 // returns formatted text
797 if(! function_exists('format_like')) {
798 function format_like($cnt,$arr,$type,$id) {
801 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
803 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
804 $o .= (($type === 'like') ?
805 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
807 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
809 $total = count($arr);
810 if($total >= MAX_LIKERS)
811 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
812 if($total < MAX_LIKERS)
813 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
814 $str = implode(', ', $arr);
815 if($total >= MAX_LIKERS)
816 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
817 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
818 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
824 function status_editor($a,$x, $notes_cid = 0) {
828 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
831 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
834 $tpl = get_markup_template('jot-header.tpl');
836 $a->page['htmlhead'] .= replace_macros($tpl, array(
837 '$newpost' => 'true',
838 '$baseurl' => $a->get_baseurl(),
839 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
840 '$geotag' => $geotag,
841 '$nickname' => $x['nickname'],
842 '$ispublic' => t('Visible to <strong>everybody</strong>'),
843 '$linkurl' => t('Please enter a link URL:'),
844 '$vidurl' => t("Please enter a video link/URL:"),
845 '$audurl' => t("Please enter an audio link/URL:"),
846 '$term' => t('Tag term:'),
847 '$whereareu' => t('Where are you right now?'),
848 '$title' => t('Enter a title for this item')
852 $tpl = get_markup_template("jot.tpl");
857 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
859 $mail_enabled = false;
860 $pubmail_enabled = false;
862 if(($x['is_owner']) && (! $mail_disabled)) {
863 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
867 $mail_enabled = true;
868 if(intval($r[0]['pubmail']))
869 $pubmail_enabled = true;
874 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
875 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
878 call_hooks('jot_tool', $jotplugins);
879 call_hooks('jot_networks', $jotnets);
882 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
884 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
886 $o .= replace_macros($tpl,array(
887 '$return_path' => $a->cmd,
889 '$share' => (($x['button']) ? $x['button'] : t('Share')),
890 '$upload' => t('Upload photo'),
891 '$shortupload' => t('upload photo'),
892 '$attach' => t('Attach file'),
893 '$shortattach' => t('attach file'),
894 '$weblink' => t('Insert web link'),
895 '$shortweblink' => t('web link'),
896 '$video' => t('Insert video link'),
897 '$shortvideo' => t('video link'),
898 '$audio' => t('Insert audio link'),
899 '$shortaudio' => t('audio link'),
900 '$setloc' => t('Set your location'),
901 '$shortsetloc' => t('set location'),
902 '$noloc' => t('Clear browser location'),
903 '$shortnoloc' => t('clear location'),
905 '$placeholdertitle' => t('Set title'),
906 '$wait' => t('Please wait'),
907 '$permset' => t('Permission settings'),
908 '$shortpermset' => t('permissions'),
909 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
912 '$baseurl' => $a->get_baseurl(),
913 '$defloc' => $x['default_location'],
914 '$visitor' => $x['visitor'],
915 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
916 '$emailcc' => t('CC: email addresses'),
917 '$public' => t('Public post'),
918 '$jotnets' => $jotnets,
919 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
920 '$lockstate' => $x['lockstate'],
922 '$bang' => $x['bang'],
923 '$profile_uid' => $x['profile_uid'],
924 '$preview' => t('Preview'),
931 function conv_sort($arr,$order) {
933 if((!(is_array($arr) && count($arr))))
939 if($x['id'] == $x['parent'])
942 if(stristr($order,'created'))
943 usort($parents,'sort_thr_created');
944 elseif(stristr($order,'commented'))
945 usort($parents,'sort_thr_commented');
948 foreach($parents as $x)
949 $x['children'] = array();
951 foreach($arr as $x) {
952 if($x['id'] != $x['parent']) {
953 $p = find_thread_parent_index($parents,$x);
955 $parents[$p]['children'][] = $x;
958 if(count($parents)) {
959 foreach($parents as $k => $v) {
960 if(count($parents[$k]['children'])) {
961 $y = $parents[$k]['children'];
962 usort($y,'sort_thr_created_rev');
963 $parents[$k]['children'] = $y;
969 if(count($parents)) {
970 foreach($parents as $x) {
972 if(count($x['children']))
973 foreach($x['children'] as $y)
982 function sort_thr_created($a,$b) {
983 return strcmp($b['created'],$a['created']);
986 function sort_thr_created_rev($a,$b) {
987 return strcmp($a['created'],$b['created']);
990 function sort_thr_commented($a,$b) {
991 return strcmp($b['commented'],$a['commented']);
994 function find_thread_parent_index($arr,$x) {
995 foreach($arr as $k => $v)
996 if($v['id'] == $x['parent'])
1001 function render_location_google($item) {
1003 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1004 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1007 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1009 $location = '<span class="smalltext">' . $coord . '</span>';