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 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
266 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
269 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
271 $location = '<span class="smalltext">' . $coord . '</span>';
275 localize_item($item);
276 if($mode === 'network-new')
283 'dropping' => $dropping,
284 'select' => t('Select'),
285 'delete' => t('Delete'),
289 $isstarred = "unstarred";
292 $likebuttons = false;
295 $body = prepare_body($item,true);
297 $tmp_item = replace_macros($tpl,array(
298 '$id' => (($preview) ? 'P0' : $item['item_id']),
299 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
300 '$profile_url' => $profile_link,
301 '$item_photo_menu' => item_photo_menu($item),
302 '$name' => template_escape($profile_name),
303 '$sparkle' => $sparkle,
305 '$thumb' => $profile_avatar,
306 '$title' => template_escape($item['title']),
307 '$body' => template_escape($body),
308 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
310 '$location' => template_escape($location),
312 '$owner_name' => template_escape($owner_name),
313 '$owner_url' => $owner_url,
314 '$owner_photo' => $owner_photo,
315 '$plink' => get_plink($item),
317 '$isstarred' => $isstarred,
320 '$vote' => $likebuttons,
324 '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
325 '$previewing' => $previewing,
326 '$wait' => t('Please wait'),
329 $arr = array('item' => $item, 'output' => $tmp_item);
330 call_hooks('display_item', $arr);
332 $threads[$threadsid]['id'] = $item['item_id'];
333 $threads[$threadsid]['html'] .= $arr['output'];
343 // Figure out how many comments each parent has
344 // (Comments all have gravity of 6)
345 // Store the result in the $comments array
348 foreach($items as $item) {
349 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
350 if(! x($comments,$item['parent']))
351 $comments[$item['parent']] = 1;
353 $comments[$item['parent']] += 1;
357 // map all the like/dislike activities for each parent item
358 // Store these in the $alike and $dlike arrays
360 foreach($items as $item) {
361 like_puller($a,$item,$alike,'like');
362 like_puller($a,$item,$dlike,'dislike');
365 $comments_collapsed = false;
370 foreach($items as $item) {
376 $owner_url = $owner_photo = $owner_name = '';
378 // We've already parsed out like/dislike for special treatment. We can ignore them now
380 if(((activity_match($item['verb'],ACTIVITY_LIKE))
381 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
382 && ($item['id'] != $item['parent']))
385 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
386 $toplevelprivate = false;
388 // Take care of author collapsing and comment collapsing
389 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
390 // If there are more than two comments, squash all but the last 2.
393 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
394 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
396 /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
398 if($blowhard_count == 3) {
399 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
400 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
401 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
402 . $item['parent'] . '" style="display: none;" >';
406 $blowhard = $item['cid'];
407 if($blowhard_count >= 3)
413 $comments_collapsed = false;
416 $threads[$threadsid]['id'] = $item['item_id'];
417 $threads[$threadsid]['html'] = "";
421 // prevent private email from leaking into public conversation
422 if((! $toplevelpost) && (! toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
427 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
428 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
431 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
432 if(! $comments_collapsed) {
434 // IMPORTANT: the closing </div> in the hide_comments template
435 // is supplied below in code.
437 $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
438 '$id' => $item['parent'],
439 '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
440 $comments[$item['parent']]),
441 '$display' => 'none',
442 '$hide_text' => t('show more')
444 $comments_collapsed = true;
447 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
448 $threads[$threadsid]['html'] .= '</div>';
451 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
453 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
454 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
455 ? t('Private Message')
459 // Top-level wall post not written by the wall owner (wall-to-wall)
460 // First figure out who owns it.
464 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
468 // On the network page, I am the owner. On the display page it will be the profile owner.
469 // This will have been stored in $a->page_contact by our calling page.
470 // Put this person on the left of the wall-to-wall notice.
472 $owner_url = $a->page_contact['url'];
473 $owner_photo = $a->page_contact['thumb'];
474 $owner_name = $a->page_contact['name'];
475 $template = $wallwall;
478 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
482 $owner_url = $item['owner-link'];
483 $owner_photo = $item['owner-avatar'];
484 $owner_name = $item['owner-name'];
485 $template = $wallwall;
487 // If it is our contact, use a friendly redirect link
488 if((link_compare($item['owner-link'],$item['url']))
489 && ($item['network'] === 'dfrn')) {
490 $owner_url = $redirect_url;
491 $osparkle = ' sparkle';
497 $shareable = ((($profile_owner == local_user()) && ($mode != 'display') && (! $item['private'])) ? true : false);
499 if($page_writeable) {
501 $likebuttons = array(
502 'like' => array( t("I like this \x28toggle\x29"), t("like")),
503 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
505 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
508 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
509 $comment = replace_macros($cmnt_tpl,array(
510 '$return_path' => '',
511 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
512 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
513 '$id' => $item['item_id'],
514 '$parent' => $item['parent'],
515 '$profile_uid' => $profile_owner,
516 '$mylink' => $a->contact['url'],
517 '$mytitle' => t('This is you'),
518 '$myphoto' => $a->contact['thumb'],
519 '$comment' => t('Comment'),
520 '$submit' => t('Submit'),
521 '$preview' => t('Preview'),
522 '$ww' => (($mode === 'network') ? $commentww : '')
527 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
528 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
535 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
539 'dropping' => $dropping,
540 'select' => t('Select'),
541 'delete' => t('Delete'),
545 $isstarred = "unstarred";
546 if ($profile_owner == local_user() && $toplevelpost) {
547 $isstarred = (($item['starred']) ? "starred" : "unstarred");
550 'do' => t("add star"),
551 'undo' => t("remove star"),
552 'toggle' => t("toggle star status"),
553 'classdo' => (($item['starred']) ? "hidden" : ""),
554 'classundo' => (($item['starred']) ? "" : "hidden"),
555 'starred' => t('starred'),
556 'tagger' => t("add tag"),
563 $photo = $item['photo'];
564 $thumb = $item['thumb'];
566 // Post was remotely authored.
568 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
570 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
572 if($item['author-link'] && (! $item['author-name']))
573 $profile_name = $item['author-link'];
577 $profile_link = best_link_url($item,$sp);
579 $sparkle = ' sparkle';
581 if($profile_link === 'mailbox')
584 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
585 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
586 $profile_avatar = $a->contacts[$normalised]['thumb'];
588 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
594 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
595 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
597 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
598 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
599 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
600 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
603 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
605 $location = '<span class="smalltext">' . $coord . '</span>';
608 $indent = (($toplevelpost) ? '' : ' comment');
610 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
614 localize_item($item);
618 foreach(explode(',',$item['tag']) as $tag){
620 if ($tag!="") $tags[] = bbcode($tag);
626 $body = prepare_body($item,true);
629 $tmp_item = replace_macros($template,array(
630 '$type' => implode("",array_slice(split("/",$item['verb']),-1)),
632 '$body' => template_escape($body),
633 '$id' => $item['item_id'],
634 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
635 '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
637 '$wall' => t('Wall-to-Wall'),
638 '$vwall' => t('via Wall-To-Wall:'),
639 '$profile_url' => $profile_link,
640 '$item_photo_menu' => item_photo_menu($item),
641 '$name' => template_escape($profile_name),
642 '$thumb' => $profile_avatar,
643 '$osparkle' => $osparkle,
644 '$sparkle' => $sparkle,
645 '$title' => template_escape($item['title']),
646 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
648 '$location' => template_escape($location),
649 '$indent' => $indent,
650 '$owner_url' => $owner_url,
651 '$owner_photo' => $owner_photo,
652 '$owner_name' => template_escape($owner_name),
653 '$plink' => get_plink($item),
654 '$edpost' => $edpost,
655 '$isstarred' => $isstarred,
658 '$vote' => $likebuttons,
660 '$dislike' => $dislike,
661 '$comment' => $comment,
662 '$previewing' => $previewing,
663 '$wait' => t('Please wait'),
668 $arr = array('item' => $item, 'output' => $tmp_item);
669 call_hooks('display_item', $arr);
671 $threads[$threadsid]['html'] .= $arr['output'];
677 $page_template = get_markup_template("conversation.tpl");
678 $o .= replace_macros($page_template, array(
679 '$threads' => $threads,
680 '$dropping' => ($dropping?t('Delete Selected Items'):False),
686 function best_link_url($item,&$sparkle) {
693 $clean_url = normalise_link($item['author-link']);
695 if((local_user()) && (local_user() == $item['uid'])) {
696 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
697 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
698 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
702 $best_url = $a->contacts[$clean_url]['url'];
706 if(strlen($item['author-link']))
707 $best_url = $item['author-link'];
709 $best_url = $item['url'];
716 if(! function_exists('item_photo_menu')){
717 function item_photo_menu($item){
720 if (local_user() && (! count($a->contacts)))
721 load_contact_links(local_user());
730 $profile_link = best_link_url($item,$sparkle);
731 if($profile_link === 'mailbox')
735 $cid = intval(basename($profile_link));
736 $status_link = $profile_link . "?url=status";
737 $photos_link = $profile_link . "?url=photos";
738 $profile_link = $profile_link . "?url=profile";
739 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
742 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
743 $cid = $item['contact-id'];
749 if(($cid) && (! $item['self'])) {
750 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
751 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
755 t("View status") => $status_link,
756 t("View profile") => $profile_link,
757 t("View photos") => $photos_link,
758 t("View recent") => $posts_link,
759 t("Edit contact") => $contact_url,
760 t("Send PM") => $pm_url,
764 $args = array('item' => $item, 'menu' => $menu);
766 call_hooks('item_photo_menu', $args);
768 $menu = $args['menu'];
771 foreach($menu as $k=>$v){
772 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
777 if(! function_exists('like_puller')) {
778 function like_puller($a,$item,&$arr,$mode) {
782 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
784 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
785 $url = $item['author-link'];
786 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
787 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
788 $sparkle = ' class="sparkle" ';
790 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
791 $arr[$item['parent'] . '-l'] = array();
792 if(! isset($arr[$item['parent']]))
793 $arr[$item['parent']] = 1;
795 $arr[$item['parent']] ++;
796 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
801 // Format the like/dislike text for a profile item
802 // $cnt = number of people who like/dislike the item
803 // $arr = array of pre-linked names of likers/dislikers
804 // $type = one of 'like, 'dislike'
806 // returns formatted text
808 if(! function_exists('format_like')) {
809 function format_like($cnt,$arr,$type,$id) {
812 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
814 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
815 $o .= (($type === 'like') ?
816 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
818 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
820 $total = count($arr);
821 if($total >= MAX_LIKERS)
822 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
823 if($total < MAX_LIKERS)
824 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
825 $str = implode(', ', $arr);
826 if($total >= MAX_LIKERS)
827 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
828 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
829 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
835 function status_editor($a,$x, $notes_cid = 0) {
839 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
841 $tpl = get_markup_template('jot-header.tpl');
843 $a->page['htmlhead'] .= replace_macros($tpl, array(
844 '$newpost' => 'true',
845 '$baseurl' => $a->get_baseurl(),
846 '$geotag' => $geotag,
847 '$nickname' => $x['nickname'],
848 '$ispublic' => t('Visible to <strong>everybody</strong>'),
849 '$linkurl' => t('Please enter a link URL:'),
850 '$vidurl' => t("Please enter a video link/URL:"),
851 '$audurl' => t("Please enter an audio link/URL:"),
852 '$term' => t('Tag term:'),
853 '$whereareu' => t('Where are you right now?'),
854 '$title' => t('Enter a title for this item')
858 $tpl = get_markup_template("jot.tpl");
863 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
865 $mail_enabled = false;
866 $pubmail_enabled = false;
868 if(($x['is_owner']) && (! $mail_disabled)) {
869 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
873 $mail_enabled = true;
874 if(intval($r[0]['pubmail']))
875 $pubmail_enabled = true;
880 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
881 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> '
882 . t("Post to Email") . '</div>';
885 call_hooks('jot_tool', $jotplugins);
886 call_hooks('jot_networks', $jotnets);
889 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
891 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
893 $o .= replace_macros($tpl,array(
894 '$return_path' => $a->cmd,
896 '$share' => (($x['button']) ? $x['button'] : t('Share')),
897 '$upload' => t('Upload photo'),
898 '$shortupload' => t('upload photo'),
899 '$attach' => t('Attach file'),
900 '$shortattach' => t('attach file'),
901 '$weblink' => t('Insert web link'),
902 '$shortweblink' => t('web link'),
903 '$video' => t('Insert video link'),
904 '$shortvideo' => t('video link'),
905 '$audio' => t('Insert audio link'),
906 '$shortaudio' => t('audio link'),
907 '$setloc' => t('Set your location'),
908 '$shortsetloc' => t('set location'),
909 '$noloc' => t('Clear browser location'),
910 '$shortnoloc' => t('clear location'),
912 '$placeholdertitle' => t('Set title'),
913 '$wait' => t('Please wait'),
914 '$permset' => t('Permission settings'),
915 '$shortpermset' => t('permissions'),
916 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
919 '$baseurl' => $a->get_baseurl(),
920 '$defloc' => $x['default_location'],
921 '$visitor' => $x['visitor'],
922 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
923 '$emailcc' => t('CC: email addresses'),
924 '$public' => t('Public post'),
925 '$jotnets' => $jotnets,
926 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
927 '$lockstate' => $x['lockstate'],
929 '$bang' => $x['bang'],
930 '$profile_uid' => $x['profile_uid'],
931 '$preview' => t('Preview'),
938 function conv_sort($arr,$order) {
940 if((!(is_array($arr) && count($arr))))
946 if($x['id'] == $x['parent'])
949 if(stristr($order,'created'))
950 usort($parents,'sort_thr_created');
951 elseif(stristr($order,'commented'))
952 usort($parents,'sort_thr_commented');
955 foreach($parents as $x)
956 $x['children'] = array();
958 foreach($arr as $x) {
959 if($x['id'] != $x['parent']) {
960 $p = find_thread_parent_index($parents,$x);
962 $parents[$p]['children'][] = $x;
965 if(count($parents)) {
966 foreach($parents as $k => $v) {
967 if(count($parents[$k]['children'])) {
968 $y = $parents[$k]['children'];
969 usort($y,'sort_thr_created_rev');
970 $parents[$k]['children'] = $y;
976 if(count($parents)) {
977 foreach($parents as $x) {
979 if(count($x['children']))
980 foreach($x['children'] as $y)
989 function sort_thr_created($a,$b) {
990 return strcmp($b['created'],$a['created']);
993 function sort_thr_created_rev($a,$b) {
994 return strcmp($a['created'],$b['created']);
997 function sort_thr_commented($a,$b) {
998 return strcmp($b['commented'],$a['commented']);
1001 function find_thread_parent_index($arr,$x) {
1002 foreach($arr as $k => $v)
1003 if($v['id'] == $x['parent'])