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 );
123 * "Render" a conversation or list of items for HTML display.
124 * There are two major forms of display:
125 * - Sequential or unthreaded ("New Item View" or search results)
126 * - conversation view
127 * The $mode parameter decides between the various renderings and also
128 * figures out how to determine page owner and other contextual items
129 * that are based on unique features of the calling module.
132 function conversation(&$a, $items, $mode, $update, $preview = false) {
134 require_once('bbcode.php');
137 $page_writeable = false;
139 $previewing = (($preview) ? ' preview ' : '');
141 if($mode === 'network') {
142 $profile_owner = local_user();
143 $page_writeable = true;
146 if($mode === 'profile') {
147 $profile_owner = $a->profile['profile_uid'];
148 $page_writeable = can_write_wall($a,$profile_owner);
151 if($mode === 'notes') {
152 $profile_owner = local_user();
153 $page_writeable = true;
156 if($mode === 'display') {
157 $profile_owner = $a->profile['uid'];
158 $page_writeable = can_write_wall($a,$profile_owner);
161 if($mode === 'community') {
163 $page_writeable = false;
167 $return_url = $_SESSION['return_url'];
169 $return_url = $_SESSION['return_url'] = $a->cmd;
171 load_contact_links(local_user());
173 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
174 call_hooks('conversation_start',$cb);
176 $items = $cb['items'];
178 $cmnt_tpl = get_markup_template('comment_item.tpl');
179 $tpl = get_markup_template('wall_item.tpl');
180 $wallwall = get_markup_template('wallwall_item.tpl');
181 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
187 // array with html for each thread (parent+comments)
193 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
195 // "New Item View" on network page or search page results
196 // - just loop through the items and format them minimally for display
198 $tpl = get_markup_template('search_item.tpl');
200 foreach($items as $item) {
209 if($mode === 'search' || $mode === 'community') {
210 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
211 && ($item['id'] != $item['parent']))
213 $nickname = $item['nickname'];
216 $nickname = $a->user['nickname'];
219 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
220 if($item['author-link'] && (! $item['author-name']))
221 $profile_name = $item['author-link'];
224 $profile_link = best_link_url($item,$sp);
226 $sparkle = ' sparkle';
227 if($profile_link === 'mailbox')
231 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
232 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
233 $profile_avatar = $a->contacts[$normalised]['thumb'];
235 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
237 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
238 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
241 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
243 $location = '<span class="smalltext">' . $coord . '</span>';
247 localize_item($item);
248 if($mode === 'network-new')
255 'dropping' => $dropping,
256 'select' => t('Select'),
257 'delete' => t('Delete'),
261 $isstarred = "unstarred";
264 $likebuttons = false;
267 $body = prepare_body($item,true);
269 $tmp_item = replace_macros($tpl,array(
270 '$id' => (($preview) ? 'P0' : $item['item_id']),
271 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
272 '$profile_url' => $profile_link,
273 '$item_photo_menu' => item_photo_menu($item),
274 '$name' => template_escape($profile_name),
275 '$sparkle' => $sparkle,
277 '$thumb' => $profile_avatar,
278 '$title' => template_escape($item['title']),
279 '$body' => template_escape($body),
280 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
282 '$location' => template_escape($location),
284 '$owner_name' => template_escape($owner_name),
285 '$owner_url' => $owner_url,
286 '$owner_photo' => $owner_photo,
287 '$plink' => get_plink($item),
289 '$isstarred' => $isstarred,
292 '$vote' => $likebuttons,
296 '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
297 '$previewing' => $previewing,
298 '$wait' => t('Please wait'),
301 $arr = array('item' => $item, 'output' => $tmp_item);
302 call_hooks('display_item', $arr);
304 $threads[$threadsid]['id'] = $item['item_id'];
305 $threads[$threadsid]['html'] .= $arr['output'];
315 // Figure out how many comments each parent has
316 // (Comments all have gravity of 6)
317 // Store the result in the $comments array
320 foreach($items as $item) {
321 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
322 if(! x($comments,$item['parent']))
323 $comments[$item['parent']] = 1;
325 $comments[$item['parent']] += 1;
329 // map all the like/dislike activities for each parent item
330 // Store these in the $alike and $dlike arrays
332 foreach($items as $item) {
333 like_puller($a,$item,$alike,'like');
334 like_puller($a,$item,$dlike,'dislike');
337 $comments_collapsed = false;
342 foreach($items as $item) {
348 $owner_url = $owner_photo = $owner_name = '';
350 // We've already parsed out like/dislike for special treatment. We can ignore them now
352 if(((activity_match($item['verb'],ACTIVITY_LIKE))
353 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
354 && ($item['id'] != $item['parent']))
357 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
358 $toplevelprivate = false;
360 // Take care of author collapsing and comment collapsing
361 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
362 // If there are more than two comments, squash all but the last 2.
365 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
366 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
368 /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
370 if($blowhard_count == 3) {
371 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
372 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
373 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
374 . $item['parent'] . '" style="display: none;" >';
378 $blowhard = $item['cid'];
379 if($blowhard_count >= 3)
385 $comments_collapsed = false;
388 $threads[$threadsid]['id'] = $item['item_id'];
389 $threads[$threadsid]['html'] = "";
393 // prevent private email from leaking into public conversation
394 if((! $toplevelpost) && (! toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
399 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
400 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
403 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
404 if(! $comments_collapsed) {
406 // IMPORTANT: the closing </div> in the hide_comments template
407 // is supplied below in code.
409 $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
410 '$id' => $item['parent'],
411 '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
412 $comments[$item['parent']]),
413 '$display' => 'none',
414 '$hide_text' => t('show more')
416 $comments_collapsed = true;
419 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
420 $threads[$threadsid]['html'] .= '</div>';
423 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
425 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
426 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
427 ? t('Private Message')
431 // Top-level wall post not written by the wall owner (wall-to-wall)
432 // First figure out who owns it.
436 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
440 // On the network page, I am the owner. On the display page it will be the profile owner.
441 // This will have been stored in $a->page_contact by our calling page.
442 // Put this person on the left of the wall-to-wall notice.
444 $owner_url = $a->page_contact['url'];
445 $owner_photo = $a->page_contact['thumb'];
446 $owner_name = $a->page_contact['name'];
447 $template = $wallwall;
450 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
454 $owner_url = $item['owner-link'];
455 $owner_photo = $item['owner-avatar'];
456 $owner_name = $item['owner-name'];
457 $template = $wallwall;
459 // If it is our contact, use a friendly redirect link
460 if((link_compare($item['owner-link'],$item['url']))
461 && ($item['network'] === 'dfrn')) {
462 $owner_url = $redirect_url;
463 $osparkle = ' sparkle';
469 $shareable = ((($profile_owner == local_user()) && ($mode != 'display') && (! $item['private'])) ? true : false);
471 if($page_writeable) {
473 $likebuttons = array(
474 'like' => array( t("I like this \x28toggle\x29"), t("like")),
475 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
477 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
480 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
481 $comment = replace_macros($cmnt_tpl,array(
482 '$return_path' => '',
483 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
484 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
485 '$id' => $item['item_id'],
486 '$parent' => $item['parent'],
487 '$profile_uid' => $profile_owner,
488 '$mylink' => $a->contact['url'],
489 '$mytitle' => t('This is you'),
490 '$myphoto' => $a->contact['thumb'],
491 '$comment' => t('Comment'),
492 '$submit' => t('Submit'),
493 '$preview' => t('Preview'),
494 '$ww' => (($mode === 'network') ? $commentww : '')
499 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
500 ? array($a->get_baseurl()."/editpost/".$item['id'], t("Edit"))
507 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
511 'dropping' => $dropping,
512 'select' => t('Select'),
513 'delete' => t('Delete'),
517 $isstarred = "unstarred";
518 if ($profile_owner == local_user() && $toplevelpost) {
519 $isstarred = (($item['starred']) ? "starred" : "unstarred");
522 'do' => t("add star"),
523 'undo' => t("remove star"),
524 'toggle' => t("toggle star status"),
525 'classdo' => (($item['starred']) ? "hidden" : ""),
526 'classundo' => (($item['starred']) ? "" : "hidden"),
527 'starred' => t('starred'),
528 'tagger' => t("add tag"),
535 $photo = $item['photo'];
536 $thumb = $item['thumb'];
538 // Post was remotely authored.
540 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
542 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
544 if($item['author-link'] && (! $item['author-name']))
545 $profile_name = $item['author-link'];
549 $profile_link = best_link_url($item,$sp);
551 $sparkle = ' sparkle';
553 if($profile_link === 'mailbox')
556 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
557 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
558 $profile_avatar = $a->contacts[$normalised]['thumb'];
560 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
566 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
567 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
569 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
570 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
571 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
572 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
575 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
577 $location = '<span class="smalltext">' . $coord . '</span>';
580 $indent = (($toplevelpost) ? '' : ' comment');
582 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
586 localize_item($item);
590 foreach(explode(',',$item['tag']) as $tag){
592 if ($tag!="") $tags[] = bbcode($tag);
598 $body = prepare_body($item,true);
601 $tmp_item = replace_macros($template,array(
602 '$type' => implode("",array_slice(split("/",$item['verb']),-1)),
604 '$body' => template_escape($body),
605 '$id' => $item['item_id'],
606 '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
607 '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
609 '$wall' => t('Wall-to-Wall'),
610 '$vwall' => t('via Wall-To-Wall:'),
611 '$profile_url' => $profile_link,
612 '$item_photo_menu' => item_photo_menu($item),
613 '$name' => template_escape($profile_name),
614 '$thumb' => $profile_avatar,
615 '$osparkle' => $osparkle,
616 '$sparkle' => $sparkle,
617 '$title' => template_escape($item['title']),
618 '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
620 '$location' => template_escape($location),
621 '$indent' => $indent,
622 '$owner_url' => $owner_url,
623 '$owner_photo' => $owner_photo,
624 '$owner_name' => template_escape($owner_name),
625 '$plink' => get_plink($item),
626 '$edpost' => $edpost,
627 '$isstarred' => $isstarred,
630 '$vote' => $likebuttons,
632 '$dislike' => $dislike,
633 '$comment' => $comment,
634 '$previewing' => $previewing,
635 '$wait' => t('Please wait'),
640 $arr = array('item' => $item, 'output' => $tmp_item);
641 call_hooks('display_item', $arr);
643 $threads[$threadsid]['html'] .= $arr['output'];
649 $page_template = get_markup_template("conversation.tpl");
650 $o .= replace_macros($page_template, array(
651 '$threads' => $threads,
652 '$dropping' => ($dropping?t('Delete Selected Items'):False),
658 function best_link_url($item,&$sparkle) {
665 $clean_url = normalise_link($item['author-link']);
667 if((local_user()) && (local_user() == $item['uid'])) {
668 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
669 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
670 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
674 $best_url = $a->contacts[$clean_url]['url'];
678 if(strlen($item['author-link']))
679 $best_url = $item['author-link'];
681 $best_url = $item['url'];
688 if(! function_exists('item_photo_menu')){
689 function item_photo_menu($item){
692 if (local_user() && (! count($a->contacts)))
693 load_contact_links(local_user());
702 $profile_link = best_link_url($item,$sparkle);
703 if($profile_link === 'mailbox')
707 $cid = intval(basename($profile_link));
708 $status_link = $profile_link . "?url=status";
709 $photos_link = $profile_link . "?url=photos";
710 $profile_link = $profile_link . "?url=profile";
711 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
714 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
715 $cid = $item['contact-id'];
721 if(($cid) && (! $item['self'])) {
722 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
723 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
727 t("View status") => $status_link,
728 t("View profile") => $profile_link,
729 t("View photos") => $photos_link,
730 t("View recent") => $posts_link,
731 t("Edit contact") => $contact_url,
732 t("Send PM") => $pm_url,
736 $args = array('item' => $item, 'menu' => $menu);
738 call_hooks('item_photo_menu', $args);
740 $menu = $args['menu'];
743 foreach($menu as $k=>$v){
744 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
749 if(! function_exists('like_puller')) {
750 function like_puller($a,$item,&$arr,$mode) {
754 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
756 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
757 $url = $item['author-link'];
758 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
759 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
760 $sparkle = ' class="sparkle" ';
762 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
763 $arr[$item['parent'] . '-l'] = array();
764 if(! isset($arr[$item['parent']]))
765 $arr[$item['parent']] = 1;
767 $arr[$item['parent']] ++;
768 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
773 // Format the like/dislike text for a profile item
774 // $cnt = number of people who like/dislike the item
775 // $arr = array of pre-linked names of likers/dislikers
776 // $type = one of 'like, 'dislike'
778 // returns formatted text
780 if(! function_exists('format_like')) {
781 function format_like($cnt,$arr,$type,$id) {
784 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
786 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
787 $o .= (($type === 'like') ?
788 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
790 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
792 $total = count($arr);
793 if($total >= MAX_LIKERS)
794 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
795 if($total < MAX_LIKERS)
796 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
797 $str = implode(', ', $arr);
798 if($total >= MAX_LIKERS)
799 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
800 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
801 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
807 function status_editor($a,$x, $notes_cid = 0) {
811 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
813 $tpl = get_markup_template('jot-header.tpl');
815 $a->page['htmlhead'] .= replace_macros($tpl, array(
816 '$newpost' => 'true',
817 '$baseurl' => $a->get_baseurl(),
818 '$geotag' => $geotag,
819 '$nickname' => $x['nickname'],
820 '$ispublic' => t('Visible to <strong>everybody</strong>'),
821 '$linkurl' => t('Please enter a link URL:'),
822 '$vidurl' => t("Please enter a video link/URL:"),
823 '$audurl' => t("Please enter an audio link/URL:"),
824 '$term' => t('Tag term:'),
825 '$whereareu' => t('Where are you right now?'),
826 '$title' => t('Enter a title for this item')
830 $tpl = get_markup_template("jot.tpl");
835 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
837 $mail_enabled = false;
838 $pubmail_enabled = false;
840 if(($x['is_owner']) && (! $mail_disabled)) {
841 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
845 $mail_enabled = true;
846 if(intval($r[0]['pubmail']))
847 $pubmail_enabled = true;
852 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
853 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> '
854 . t("Post to Email") . '</div>';
857 call_hooks('jot_tool', $jotplugins);
858 call_hooks('jot_networks', $jotnets);
861 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
863 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
865 $o .= replace_macros($tpl,array(
866 '$return_path' => $a->cmd,
868 '$share' => (($x['button']) ? $x['button'] : t('Share')),
869 '$upload' => t('Upload photo'),
870 '$shortupload' => t('upload photo'),
871 '$attach' => t('Attach file'),
872 '$shortattach' => t('attach file'),
873 '$weblink' => t('Insert web link'),
874 '$shortweblink' => t('web link'),
875 '$video' => t('Insert video link'),
876 '$shortvideo' => t('video link'),
877 '$audio' => t('Insert audio link'),
878 '$shortaudio' => t('audio link'),
879 '$setloc' => t('Set your location'),
880 '$shortsetloc' => t('set location'),
881 '$noloc' => t('Clear browser location'),
882 '$shortnoloc' => t('clear location'),
884 '$placeholdertitle' => t('Set title'),
885 '$wait' => t('Please wait'),
886 '$permset' => t('Permission settings'),
887 '$shortpermset' => t('permissions'),
888 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
891 '$baseurl' => $a->get_baseurl(),
892 '$defloc' => $x['default_location'],
893 '$visitor' => $x['visitor'],
894 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
895 '$emailcc' => t('CC: email addresses'),
896 '$public' => t('Public post'),
897 '$jotnets' => $jotnets,
898 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
899 '$lockstate' => $x['lockstate'],
901 '$bang' => $x['bang'],
902 '$profile_uid' => $x['profile_uid'],
903 '$preview' => t('Preview'),
910 function conv_sort($arr,$order) {
912 if((!(is_array($arr) && count($arr))))
918 if($x['id'] == $x['parent'])
921 if(stristr($order,'created'))
922 usort($parents,'sort_thr_created');
923 elseif(stristr($order,'commented'))
924 usort($parents,'sort_thr_commented');
927 foreach($parents as $x)
928 $x['children'] = array();
930 foreach($arr as $x) {
931 if($x['id'] != $x['parent']) {
932 $p = find_thread_parent_index($parents,$x);
934 $parents[$p]['children'][] = $x;
937 if(count($parents)) {
938 foreach($parents as $k => $v) {
939 if(count($parents[$k]['children'])) {
940 $y = $parents[$k]['children'];
941 usort($y,'sort_thr_created_rev');
942 $parents[$k]['children'] = $y;
948 if(count($parents)) {
949 foreach($parents as $x) {
951 if(count($x['children']))
952 foreach($x['children'] as $y)
961 function sort_thr_created($a,$b) {
962 return strcmp($b['created'],$a['created']);
965 function sort_thr_created_rev($a,$b) {
966 return strcmp($a['created'],$b['created']);
969 function sort_thr_commented($a,$b) {
970 return strcmp($b['commented'],$a['commented']);
973 function find_thread_parent_index($arr,$x) {
974 foreach($arr as $k => $v)
975 if($v['id'] == $x['parent'])