3 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
4 // is identical to the code in mod/message.php for 'item_extract_images' and
5 // 'item_redir_and_replace_images'
6 if(! function_exists('item_extract_images')) {
7 function item_extract_images($body) {
9 $saved_image = array();
14 $img_start = strpos($orig_body, '[img');
15 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
16 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
17 while(($img_st_close !== false) && ($img_end !== false)) {
19 $img_st_close++; // make it point to AFTER the closing bracket
20 $img_end += $img_start;
22 if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
23 // This is an embedded image
25 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
26 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
31 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
33 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
35 if($orig_body === false) // in case the body ends on a closing image tag
38 $img_start = strpos($orig_body, '[img');
39 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
40 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
43 $new_body = $new_body . $orig_body;
45 return array('body' => $new_body, 'images' => $saved_image);
48 if(! function_exists('item_redir_and_replace_images')) {
49 function item_redir_and_replace_images($body, $images, $cid) {
54 for($i = 0; $i < count($images); $i++) {
55 $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
56 $replace = '[url=' . z_path() . '/redir/' . $cid
57 . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
59 $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]');
60 $process_part = substr($origbody, 0, $img_end);
61 $origbody = substr($origbody, $img_end);
63 $process_part = preg_replace($search, $replace, $process_part);
64 $newbody = $newbody . $process_part;
66 $newbody = $newbody . $origbody;
69 foreach($images as $image) {
70 // We're depending on the property of 'foreach' (specified on the PHP website) that
71 // it loops over the array starting from the first element and going sequentially
72 // to the last element
73 $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
82 * Render actions localized
84 function localize_item(&$item){
86 $extracted = item_extract_images($item['body']);
87 if($extracted['images'])
88 $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
90 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
91 if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
93 $r = q("SELECT * from `item`,`contact` WHERE
94 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
95 dbesc($item['parent-uri']));
96 if(count($r)==0) return;
99 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
100 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
102 switch($obj['verb']){
104 switch ($obj['object-type']){
105 case ACTIVITY_OBJ_EVENT:
106 $post_type = t('event');
109 $post_type = t('status');
113 if($obj['resource-id']){
114 $post_type = t('photo');
115 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
116 $rr['plink'] = $m[1];
118 $post_type = t('status');
122 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
124 switch($item['verb']){
126 $bodyverb = t('%1$s likes %2$s\'s %3$s');
128 case ACTIVITY_DISLIKE:
129 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
132 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
135 if ($item['verb']=== ACTIVITY_FRIEND){
137 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
139 $Aname = $item['author-name'];
140 $Alink = $item['author-link'];
142 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
144 $obj = parse_xml_string($xmlhead.$item['object']);
145 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
147 $Bname = $obj->title;
148 $Blink = ""; $Bphoto = "";
149 foreach ($links->link as $l){
150 $atts = $l->attributes();
151 switch($atts['rel']){
152 case "alternate": $Blink = $atts['href'];
153 case "photo": $Bphoto = $atts['href'];
158 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
159 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
160 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
162 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
165 if (stristr($item['verb'],ACTIVITY_POKE)) {
166 $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
169 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
171 $Aname = $item['author-name'];
172 $Alink = $item['author-link'];
174 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
176 $obj = parse_xml_string($xmlhead.$item['object']);
177 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
179 $Bname = $obj->title;
180 $Blink = ""; $Bphoto = "";
181 foreach ($links->link as $l){
182 $atts = $l->attributes();
183 switch($atts['rel']){
184 case "alternate": $Blink = $atts['href'];
185 case "photo": $Bphoto = $atts['href'];
190 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
191 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
192 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
194 // we can't have a translation string with three positions but no distinguishable text
195 // So here is the translate string.
197 $txt = t('%1$s poked %2$s');
199 // now translate the verb
201 $txt = str_replace( t('poked'), t($verb), $txt);
203 // then do the sprintf on the translation string
205 $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
208 if ($item['verb']===ACTIVITY_TAG){
209 $r = q("SELECT * from `item`,`contact` WHERE
210 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
211 dbesc($item['parent-uri']));
212 if(count($r)==0) return;
215 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
216 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
218 switch($obj['verb']){
220 switch ($obj['object-type']){
221 case ACTIVITY_OBJ_EVENT:
222 $post_type = t('event');
225 $post_type = t('status');
229 if($obj['resource-id']){
230 $post_type = t('photo');
231 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
232 $rr['plink'] = $m[1];
234 $post_type = t('status');
237 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
239 $parsedobj = parse_xml_string($xmlhead.$item['object']);
241 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
242 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
245 if ($item['verb']=== ACTIVITY_FAVORITE){
247 if ($item['object-type']== "")
250 $Aname = $item['author-name'];
251 $Alink = $item['author-link'];
253 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
255 $obj = parse_xml_string($xmlhead.$item['object']);
256 if(strlen($obj->id)) {
257 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
261 if(count($r) && $r[0]['plink']) {
263 $Bname = $target['author-name'];
264 $Blink = $target['author-link'];
265 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
266 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
267 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
268 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
274 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
275 foreach($matches as $mtch) {
276 if(! strpos($mtch[1],'zrl='))
277 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
281 // add zrl's to public images
282 if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
283 foreach($matches as $mtch) {
284 $item['body'] = str_replace($mtch[0],'[url=' . zrl($mtch[1] . '/photos/' . $mtch[2] . '/image/' . $mtch[3] ,true) . '][img' . $mtch[4] . ']h' . $mtch[5] . '[/img][/url]',$item['body']);
288 // add sparkle links to appropriate permalinks
290 $x = stristr($item['plink'],'/display/');
293 $y = best_link_url($item,$sparkle,true);
294 if(strstr($y,'/redir/'))
295 $item['plink'] = $y . '?f=&url=' . $item['plink'];
303 * Recursively prepare a thread for HTML
306 function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $thread_level=1) {
309 $wall_template = 'wall_thread.tpl';
310 $wallwall_template = 'wallwall_thread.tpl';
312 $nb_items = count($items);
314 foreach($items as $item) {
315 // prevent private email reply to public conversation from leaking.
316 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
317 // Don't count it as a visible item
327 $template = $wall_template;
330 $owner_url = $owner_photo = $owner_name = '';
334 $isstarred = "unstarred";
335 $photo = $item['photo'];
336 $thumb = $item['thumb'];
339 $lastcollapsed = false;
340 $firstcollapsed = false;
342 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
343 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
344 $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
345 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
346 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
347 ? t('Private Message')
349 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
350 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
351 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
352 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
355 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
359 'dropping' => $dropping,
360 'select' => t('Select'),
361 'delete' => t('Delete'),
364 $filer = (($profile_owner == local_user()) ? t("save to folder") : false);
366 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
367 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
368 if($item['author-link'] && (! $item['author-name']))
369 $profile_name = $item['author-link'];
372 $profile_link = best_link_url($item,$sp);
373 if($profile_link === 'mailbox')
376 $sparkle = ' sparkle';
378 $profile_link = zrl($profile_link);
380 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
381 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
382 $profile_avatar = $a->contacts[$normalised]['thumb'];
384 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
386 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
387 call_hooks('render_location',$locate);
388 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
391 foreach(explode(',',$item['tag']) as $tag){
393 if ($tag!="") $tags[] = bbcode($tag);
396 like_puller($a,$item,$alike,'like');
397 like_puller($a,$item,$dlike,'dislike');
399 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
400 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
403 if((! $item['self']) && ($mode !== 'profile')) {
406 // On the network page, I am the owner. On the display page it will be the profile owner.
407 // This will have been stored in $a->page_contact by our calling page.
408 // Put this person as the wall owner of the wall-to-wall notice.
410 $owner_url = zrl($a->page_contact['url']);
411 $owner_photo = $a->page_contact['thumb'];
412 $owner_name = $a->page_contact['name'];
413 $template = $wallwall_template;
417 else if($item['owner-link']) {
419 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
420 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
421 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
422 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
424 // The author url doesn't match the owner (typically the contact)
425 // and also doesn't match the contact alias.
426 // The name match is a hack to catch several weird cases where URLs are
427 // all over the park. It can be tricked, but this prevents you from
428 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
429 // well that it's the same Bob Smith.
431 // But it could be somebody else with the same name. It just isn't highly likely.
434 $owner_url = $item['owner-link'];
435 $owner_photo = $item['owner-avatar'];
436 $owner_name = $item['owner-name'];
437 $template = $wallwall_template;
439 // If it is our contact, use a friendly redirect link
440 if((link_compare($item['owner-link'],$item['url']))
441 && ($item['network'] === NETWORK_DFRN)) {
442 $owner_url = $redirect_url;
443 $osparkle = ' sparkle';
446 $owner_url = zrl($owner_url);
449 if($profile_owner == local_user()) {
450 $isstarred = (($item['starred']) ? "starred" : "unstarred");
453 'do' => t("add star"),
454 'undo' => t("remove star"),
455 'toggle' => t("toggle star status"),
456 'classdo' => (($item['starred']) ? "hidden" : ""),
457 'classundo' => (($item['starred']) ? "" : "hidden"),
458 'starred' => t('starred'),
459 'tagger' => t("add tag"),
466 if(($nb_items > 2) || ($thread_level > 2)) {
467 if($items_seen == 1) {
468 $firstcollapsed = true;
470 if($thread_level > 2) {
471 if($items_seen == $nb_items)
472 $lastcollapsed = true;
474 else if($items_seen == ($nb_items - 2)) {
475 $lastcollapsed = true;
480 if($page_writeable) {
482 'like' => array( t("I like this \x28toggle\x29"), t("like")),
483 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
485 if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
488 if($show_comment_box) {
489 $qc = $qcomment = null;
491 if(in_array('qcomment',$a->plugins)) {
492 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
493 $qcomment = (($qc) ? explode("\n",$qc) : null);
495 $comment = replace_macros($cmnt_tpl,array(
496 '$return_path' => '',
497 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
498 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
499 '$id' => $item['item_id'],
500 '$parent' => $item['item_id'],
501 '$qcomment' => $qcomment,
502 '$profile_uid' => $profile_owner,
503 '$mylink' => $a->contact['url'],
504 '$mytitle' => t('This is you'),
505 '$myphoto' => $a->contact['thumb'],
506 '$comment' => t('Comment'),
507 '$submit' => t('Submit'),
508 '$edbold' => t('Bold'),
509 '$editalic' => t('Italic'),
510 '$eduline' => t('Underline'),
511 '$edquote' => t('Quote'),
512 '$edcode' => t('Code'),
513 '$edimg' => t('Image'),
514 '$edurl' => t('Link'),
515 '$edvideo' => t('Video'),
516 '$preview' => t('Preview'),
517 '$ww' => (($mode === 'network') ? $commentww : '')
522 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
525 localize_item($item);
527 $body = prepare_body($item,true);
530 // collapse comments in template. I don't like this much...
531 'comment_firstcollapsed' => $firstcollapsed,
532 'comment_lastcollapsed' => $lastcollapsed,
533 // template to use to render item (wall, walltowall, search)
534 'template' => $template,
536 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
538 'body' => template_escape($body),
539 'text' => strip_tags(template_escape($body)),
540 'id' => $item['item_id'],
541 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
542 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
544 'wall' => t('Wall-to-Wall'),
545 'vwall' => t('via Wall-To-Wall:'),
546 'profile_url' => $profile_link,
547 'item_photo_menu' => item_photo_menu($item),
548 'name' => template_escape($profile_name),
549 'thumb' => $profile_avatar,
550 'osparkle' => $osparkle,
551 'sparkle' => $sparkle,
552 'title' => template_escape($item['title']),
553 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
555 'location' => template_escape($location),
557 'owner_url' => $owner_url,
558 'owner_photo' => $owner_photo,
559 'owner_name' => template_escape($owner_name),
560 'plink' => get_plink($item),
562 'isstarred' => $isstarred,
568 'dislike' => $dislike,
569 'comment' => $comment,
570 'previewing' => $previewing,
571 'wait' => t('Please wait'),
574 $arr = array('item' => $item, 'output' => $tmp_item);
575 call_hooks('display_item', $arr);
577 $item_result = $arr['output'];
578 if($firstcollapsed) {
579 $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$nb_items),$nb_items );
580 $item_result['hide_text'] = t('show more');
583 $item_result['children'] = array();
584 // Show children of children only if enabled
585 if(count($item['children'])
586 && (($thread_level < 2) || get_config('system','thread_allow'))) {
587 $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, ($thread_level + 1));
589 $item_result['private'] = $item['private'];
590 $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : '');
591 $result[] = $item_result;
598 * "Render" a conversation or list of items for HTML display.
599 * There are two major forms of display:
600 * - Sequential or unthreaded ("New Item View" or search results)
601 * - conversation view
602 * The $mode parameter decides between the various renderings and also
603 * figures out how to determine page owner and other contextual items
604 * that are based on unique features of the calling module.
608 if(!function_exists('conversation')) {
609 function conversation(&$a, $items, $mode, $update, $preview = false, $thr_c = false) {
612 require_once('bbcode.php');
614 $ssl_state = ((local_user()) ? true : false);
617 $page_writeable = false;
619 $previewing = (($preview) ? ' preview ' : '');
621 if($mode === 'network') {
622 $profile_owner = local_user();
623 $page_writeable = true;
626 if($mode === 'profile') {
627 $profile_owner = $a->profile['profile_uid'];
628 $page_writeable = can_write_wall($a,$profile_owner);
631 if($mode === 'notes') {
632 $profile_owner = local_user();
633 $page_writeable = true;
636 if($mode === 'display') {
637 $profile_owner = $a->profile['uid'];
638 $page_writeable = can_write_wall($a,$profile_owner);
641 if($mode === 'community') {
643 $page_writeable = false;
647 $return_url = $_SESSION['return_url'];
649 $return_url = $_SESSION['return_url'] = $a->query_string;
651 load_contact_links(local_user());
653 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
654 call_hooks('conversation_start',$cb);
656 $items = $cb['items'];
658 $cmnt_tpl = get_markup_template('comment_item.tpl');
659 $tpl = 'wall_item.tpl';
660 $wallwall = 'wallwall_item.tpl';
661 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
667 // array with html for each thread (parent+comments)
671 if($items && count($items)) {
673 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
675 // "New Item View" on network page or search page results
676 // - just loop through the items and format them minimally for display
678 //$tpl = get_markup_template('search_item.tpl');
679 $tpl = 'search_item.tpl';
681 foreach($items as $item) {
690 if($mode === 'search' || $mode === 'community') {
691 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
692 && ($item['id'] != $item['parent']))
694 $nickname = $item['nickname'];
697 $nickname = $a->user['nickname'];
699 // prevent private email from leaking.
700 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
703 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
704 if($item['author-link'] && (! $item['author-name']))
705 $profile_name = $item['author-link'];
710 $profile_link = best_link_url($item,$sp);
711 if($profile_link === 'mailbox')
714 $sparkle = ' sparkle';
716 $profile_link = zrl($profile_link);
718 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
719 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
720 $profile_avatar = $a->contacts[$normalised]['thumb'];
722 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
724 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
725 call_hooks('render_location',$locate);
727 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
729 localize_item($item);
730 if($mode === 'network-new')
737 'dropping' => $dropping,
738 'select' => t('Select'),
739 'delete' => t('Delete'),
743 $isstarred = "unstarred";
746 $likebuttons = false;
749 $body = prepare_body($item,true);
751 //$tmp_item = replace_macros($tpl,array(
754 'id' => (($preview) ? 'P0' : $item['item_id']),
755 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
756 'profile_url' => $profile_link,
757 'item_photo_menu' => item_photo_menu($item),
758 'name' => template_escape($profile_name),
759 'sparkle' => $sparkle,
761 'thumb' => $profile_avatar,
762 'title' => template_escape($item['title']),
763 'body' => template_escape($body),
764 'text' => strip_tags(template_escape($body)),
765 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
766 'location' => template_escape($location),
768 'owner_name' => template_escape($owner_name),
769 'owner_url' => $owner_url,
770 'owner_photo' => $owner_photo,
771 'plink' => get_plink($item),
773 'isstarred' => $isstarred,
776 'vote' => $likebuttons,
780 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
781 'previewing' => $previewing,
782 'wait' => t('Please wait'),
785 $arr = array('item' => $item, 'output' => $tmp_item);
786 call_hooks('display_item', $arr);
788 $threads[$threadsid]['id'] = $item['item_id'];
789 $threads[$threadsid]['items'] = array($arr['output']);
799 // Threaded comments, $thr_c is used for now since we don't know what other parts of friendica uses this function
800 // Better not rely on the new code for stuff we haven't examined yet
802 // get all the topmost parents
803 // this shouldn't be needed, as we should have only them in ou array
804 // But for now, this array respects the old style, just in case
807 foreach($items as $item) {
808 if($item['id'] == $item['parent']) {
813 $threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner);
817 // Figure out how many comments each parent has
818 // (Comments all have gravity of 6)
819 // Store the result in the $comments array
822 foreach($items as $item) {
823 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
824 if(! x($comments,$item['parent']))
825 $comments[$item['parent']] = 1;
827 $comments[$item['parent']] += 1;
828 } elseif(! x($comments,$item['parent']))
829 $comments[$item['parent']] = 0; // avoid notices later on
832 // map all the like/dislike activities for each parent item
833 // Store these in the $alike and $dlike arrays
835 foreach($items as $item) {
836 like_puller($a,$item,$alike,'like');
837 like_puller($a,$item,$dlike,'dislike');
840 $comments_collapsed = false;
842 $comment_lastcollapsed = false;
843 $comment_firstcollapsed = false;
848 foreach($items as $item) {
854 $owner_url = $owner_photo = $owner_name = '';
856 // We've already parsed out like/dislike for special treatment. We can ignore them now
858 if(((activity_match($item['verb'],ACTIVITY_LIKE))
859 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
860 && ($item['id'] != $item['parent']))
863 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
866 // Take care of author collapsing and comment collapsing
867 // (author collapsing is currently disabled)
868 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
869 // If there are more than two comments, squash all but the last 2.
873 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
876 $comments_collapsed = false;
877 $comment_lastcollapsed = false;
878 $comment_firstcollapsed = false;
881 $threads[$threadsid]['id'] = $item['item_id'];
882 $threads[$threadsid]['private'] = $item['private'];
883 $threads[$threadsid]['items'] = array();
888 // prevent private email reply to public conversation from leaking.
889 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
893 $comment_lastcollapsed = false;
894 $comment_firstcollapsed = false;
897 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
898 // Show comment box on every writable item
899 $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
902 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
904 if (!$comments_collapsed){
905 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
906 $threads[$threadsid]['hide_text'] = t('show more');
907 $comments_collapsed = true;
908 $comment_firstcollapsed = true;
911 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
913 $comment_lastcollapsed = true;
916 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
918 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
919 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
920 ? t('Private Message')
924 // Top-level wall post not written by the wall owner (wall-to-wall)
925 // First figure out who owns it.
929 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
933 // On the network page, I am the owner. On the display page it will be the profile owner.
934 // This will have been stored in $a->page_contact by our calling page.
935 // Put this person as the wall owner of the wall-to-wall notice.
937 $owner_url = zrl($a->page_contact['url']);
938 $owner_photo = $a->page_contact['thumb'];
939 $owner_name = $a->page_contact['name'];
940 $template = $wallwall;
944 if((! $item['wall']) && $item['owner-link']) {
946 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
947 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
948 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
949 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
951 // The author url doesn't match the owner (typically the contact)
952 // and also doesn't match the contact alias.
953 // The name match is a hack to catch several weird cases where URLs are
954 // all over the park. It can be tricked, but this prevents you from
955 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
956 // well that it's the same Bob Smith.
958 // But it could be somebody else with the same name. It just isn't highly likely.
961 $owner_url = $item['owner-link'];
962 $owner_photo = $item['owner-avatar'];
963 $owner_name = $item['owner-name'];
964 $template = $wallwall;
966 // If it is our contact, use a friendly redirect link
967 if((link_compare($item['owner-link'],$item['url']))
968 && ($item['network'] === NETWORK_DFRN)) {
969 $owner_url = $redirect_url;
970 $osparkle = ' sparkle';
973 $owner_url = zrl($owner_url);
979 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
981 if($page_writeable) {
982 /* if($toplevelpost) { */
983 $likebuttons = array(
984 'like' => array( t("I like this \x28toggle\x29"), t("like")),
985 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
987 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
990 $qc = $qcomment = null;
992 if(in_array('qcomment',$a->plugins)) {
993 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
994 $qcomment = (($qc) ? explode("\n",$qc) : null);
997 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
998 $comment = replace_macros($cmnt_tpl,array(
999 '$return_path' => '',
1000 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
1001 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
1002 '$id' => $item['item_id'],
1003 '$parent' => $item['item_id'],
1004 '$qcomment' => $qcomment,
1005 '$profile_uid' => $profile_owner,
1006 '$mylink' => $a->contact['url'],
1007 '$mytitle' => t('This is you'),
1008 '$myphoto' => $a->contact['thumb'],
1009 '$comment' => t('Comment'),
1010 '$submit' => t('Submit'),
1011 '$edbold' => t('Bold'),
1012 '$editalic' => t('Italic'),
1013 '$eduline' => t('Underline'),
1014 '$edquote' => t('Quote'),
1015 '$edcode' => t('Code'),
1016 '$edimg' => t('Image'),
1017 '$edurl' => t('Link'),
1018 '$edvideo' => t('Video'),
1019 '$preview' => t('Preview'),
1020 '$ww' => (($mode === 'network') ? $commentww : '')
1025 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
1026 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
1033 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1037 'dropping' => $dropping,
1038 'select' => t('Select'),
1039 'delete' => t('Delete'),
1045 $isstarred = "unstarred";
1046 if ($profile_owner == local_user()) {
1048 $isstarred = (($item['starred']) ? "starred" : "unstarred");
1051 'do' => t("add star"),
1052 'undo' => t("remove star"),
1053 'toggle' => t("toggle star status"),
1054 'classdo' => (($item['starred']) ? "hidden" : ""),
1055 'classundo' => (($item['starred']) ? "" : "hidden"),
1056 'starred' => t('starred'),
1057 'tagger' => t("add tag"),
1058 'classtagger' => "",
1061 $filer = t("save to folder");
1065 $photo = $item['photo'];
1066 $thumb = $item['thumb'];
1068 // Post was remotely authored.
1070 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
1072 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1074 if($item['author-link'] && (! $item['author-name']))
1075 $profile_name = $item['author-link'];
1078 $profile_link = best_link_url($item,$sp);
1079 if($profile_link === 'mailbox')
1082 $sparkle = ' sparkle';
1084 $profile_link = zrl($profile_link);
1086 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
1087 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
1088 $profile_avatar = $a->contacts[$normalised]['thumb'];
1090 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
1092 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
1093 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
1095 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
1096 call_hooks('render_location',$locate);
1098 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
1100 $indent = (($toplevelpost) ? '' : ' comment');
1102 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
1103 $indent .= ' shiny';
1106 localize_item($item);
1110 foreach(explode(',',$item['tag']) as $tag){
1112 if ($tag!="") $tags[] = bbcode($tag);
1117 $body = prepare_body($item,true);
1118 //$tmp_item = replace_macros($template,
1120 // collapse comments in template. I don't like this much...
1121 'comment_firstcollapsed' => $firstcollapsed,
1122 'comment_lastcollapsed' => $lastcollapsed,
1123 // template to use to render item (wall, walltowall, search)
1124 'template' => $template,
1126 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
1128 'body' => template_escape($body),
1129 'text' => strip_tags(template_escape($body)),
1130 'id' => $item['item_id'],
1131 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
1132 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner-name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
1134 'wall' => t('Wall-to-Wall'),
1135 'vwall' => t('via Wall-To-Wall:'),
1136 'profile_url' => $profile_link,
1137 'item_photo_menu' => item_photo_menu($item),
1138 'name' => template_escape($profile_name),
1139 'thumb' => $profile_avatar,
1140 'osparkle' => $osparkle,
1141 'sparkle' => $sparkle,
1142 'title' => template_escape($item['title']),
1143 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
1145 'location' => template_escape($location),
1146 'indent' => $indent,
1147 'owner_url' => $owner_url,
1148 'owner_photo' => $owner_photo,
1149 'owner_name' => template_escape($owner_name),
1150 'plink' => get_plink($item),
1151 'edpost' => $edpost,
1152 'isstarred' => $isstarred,
1156 'vote' => $likebuttons,
1158 'dislike' => $dislike,
1159 'comment' => $comment,
1160 'previewing' => $previewing,
1161 'wait' => t('Please wait'),
1166 $arr = array('item' => $item, 'output' => $tmp_item);
1167 call_hooks('display_item', $arr);
1169 $threads[$threadsid]['items'][] = $arr['output'];
1177 $page_template = get_markup_template("conversation.tpl");
1179 $page_template = get_markup_template("threaded_conversation.tpl");
1180 $o = replace_macros($page_template, array(
1181 '$baseurl' => $a->get_baseurl($ssl_state),
1183 '$user' => $a->user,
1184 '$threads' => $threads,
1185 '$dropping' => ($dropping?t('Delete Selected Items'):False),
1191 function best_link_url($item,&$sparkle,$ssl_state = false) {
1198 $clean_url = normalise_link($item['author-link']);
1200 if((local_user()) && (local_user() == $item['uid'])) {
1201 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
1202 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
1203 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
1207 $best_url = $a->contacts[$clean_url]['url'];
1211 if(strlen($item['author-link']))
1212 $best_url = $item['author-link'];
1214 $best_url = $item['url'];
1221 if(! function_exists('item_photo_menu')){
1222 function item_photo_menu($item){
1229 if(! count($a->contacts))
1230 load_contact_links(local_user());
1240 $profile_link = best_link_url($item,$sparkle,$ssl_state);
1241 if($profile_link === 'mailbox')
1245 $cid = intval(basename($profile_link));
1246 $status_link = $profile_link . "?url=status";
1247 $photos_link = $profile_link . "?url=photos";
1248 $profile_link = $profile_link . "?url=profile";
1249 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
1253 $profile_link = zrl($profile_link);
1254 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
1255 $cid = $item['contact-id'];
1261 if(($cid) && (! $item['self'])) {
1262 $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
1263 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
1264 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
1266 $clean_url = normalise_link($item['author-link']);
1268 if((local_user()) && (local_user() == $item['uid'])) {
1269 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
1270 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
1271 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
1279 t("View Status") => $status_link,
1280 t("View Profile") => $profile_link,
1281 t("View Photos") => $photos_link,
1282 t("Network Posts") => $posts_link,
1283 t("Edit Contact") => $contact_url,
1284 t("Send PM") => $pm_url,
1285 t("Poke") => $poke_link
1289 $args = array('item' => $item, 'menu' => $menu);
1291 call_hooks('item_photo_menu', $args);
1293 $menu = $args['menu'];
1296 foreach($menu as $k=>$v){
1297 if ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
1302 if(! function_exists('like_puller')) {
1303 function like_puller($a,$item,&$arr,$mode) {
1307 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
1309 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
1310 $url = $item['author-link'];
1311 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
1312 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
1313 $sparkle = ' class="sparkle" ';
1318 if(! $item['thr-parent'])
1319 $item['thr-parent'] = $item['parent-uri'];
1321 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
1322 $arr[$item['thr-parent'] . '-l'] = array();
1323 if(! isset($arr[$item['thr-parent']]))
1324 $arr[$item['thr-parent']] = 1;
1326 $arr[$item['thr-parent']] ++;
1327 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
1332 // Format the like/dislike text for a profile item
1333 // $cnt = number of people who like/dislike the item
1334 // $arr = array of pre-linked names of likers/dislikers
1335 // $type = one of 'like, 'dislike'
1337 // returns formatted text
1339 if(! function_exists('format_like')) {
1340 function format_like($cnt,$arr,$type,$id) {
1343 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
1345 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
1346 $o .= (($type === 'like') ?
1347 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
1349 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
1351 $total = count($arr);
1352 if($total >= MAX_LIKERS)
1353 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1354 if($total < MAX_LIKERS)
1355 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
1356 $str = implode(', ', $arr);
1357 if($total >= MAX_LIKERS)
1358 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1359 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
1360 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
1366 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
1370 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
1373 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
1376 $tpl = get_markup_template('jot-header.tpl');
1377 $a->page['htmlhead'] .= replace_macros($tpl, array(
1378 '$newpost' => 'true',
1379 '$baseurl' => $a->get_baseurl(true),
1380 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1381 '$geotag' => $geotag,
1382 '$nickname' => $x['nickname'],
1383 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1384 '$linkurl' => t('Please enter a link URL:'),
1385 '$vidurl' => t("Please enter a video link/URL:"),
1386 '$audurl' => t("Please enter an audio link/URL:"),
1387 '$term' => t('Tag term:'),
1388 '$fileas' => t('Save to Folder:'),
1389 '$whereareu' => t('Where are you right now?')
1393 $tpl = get_markup_template('jot-end.tpl');
1394 $a->page['end'] .= replace_macros($tpl, array(
1395 '$newpost' => 'true',
1396 '$baseurl' => $a->get_baseurl(true),
1397 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1398 '$geotag' => $geotag,
1399 '$nickname' => $x['nickname'],
1400 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1401 '$linkurl' => t('Please enter a link URL:'),
1402 '$vidurl' => t("Please enter a video link/URL:"),
1403 '$audurl' => t("Please enter an audio link/URL:"),
1404 '$term' => t('Tag term:'),
1405 '$fileas' => t('Save to Folder:'),
1406 '$whereareu' => t('Where are you right now?')
1410 $tpl = get_markup_template("jot.tpl");
1415 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
1417 $mail_enabled = false;
1418 $pubmail_enabled = false;
1420 if(($x['is_owner']) && (! $mail_disabled)) {
1421 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
1422 intval(local_user())
1425 $mail_enabled = true;
1426 if(intval($r[0]['pubmail']))
1427 $pubmail_enabled = true;
1432 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
1433 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
1436 call_hooks('jot_tool', $jotplugins);
1437 call_hooks('jot_networks', $jotnets);
1440 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
1442 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1444 $o .= replace_macros($tpl,array(
1445 '$return_path' => $a->query_string,
1446 '$action' => $a->get_baseurl(true) . '/item',
1447 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1448 '$upload' => t('Upload photo'),
1449 '$shortupload' => t('upload photo'),
1450 '$attach' => t('Attach file'),
1451 '$shortattach' => t('attach file'),
1452 '$weblink' => t('Insert web link'),
1453 '$shortweblink' => t('web link'),
1454 '$video' => t('Insert video link'),
1455 '$shortvideo' => t('video link'),
1456 '$audio' => t('Insert audio link'),
1457 '$shortaudio' => t('audio link'),
1458 '$setloc' => t('Set your location'),
1459 '$shortsetloc' => t('set location'),
1460 '$noloc' => t('Clear browser location'),
1461 '$shortnoloc' => t('clear location'),
1463 '$placeholdertitle' => t('Set title'),
1465 '$placeholdercategory' => t('Categories (comma-separated list)'),
1466 '$wait' => t('Please wait'),
1467 '$permset' => t('Permission settings'),
1468 '$shortpermset' => t('permissions'),
1469 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1472 '$baseurl' => $a->get_baseurl(true),
1473 '$defloc' => $x['default_location'],
1474 '$visitor' => $x['visitor'],
1475 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1476 '$emailcc' => t('CC: email addresses'),
1477 '$public' => t('Public post'),
1478 '$jotnets' => $jotnets,
1479 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1480 '$lockstate' => $x['lockstate'],
1481 '$acl' => $x['acl'],
1482 '$bang' => $x['bang'],
1483 '$profile_uid' => $x['profile_uid'],
1484 '$preview' => t('Preview'),
1489 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1497 function get_item_children($arr, $parent) {
1498 $children = array();
1499 foreach($arr as $item) {
1500 if(($item['id'] != $item['parent']) && ($item['thr-parent'] == $parent['uri'])) {
1501 $item['children'] = get_item_children($arr, $item);
1502 $children[] = $item;
1508 function sort_item_children($items) {
1510 usort($result,'sort_thr_created_rev');
1511 foreach($result as $k => $i) {
1512 if(count($result[$k]['children'])) {
1513 $result[$k]['children'] = sort_item_children($result[$k]['children']);
1519 function add_children_to_list($children, &$arr) {
1520 foreach($children as $y) {
1522 if(count($y['children']))
1523 add_children_to_list($y['children'], $arr);
1527 function conv_sort($arr,$order) {
1529 if((!(is_array($arr) && count($arr))))
1533 $children = array();
1536 if($x['id'] == $x['parent'])
1539 if(stristr($order,'created'))
1540 usort($parents,'sort_thr_created');
1541 elseif(stristr($order,'commented'))
1542 usort($parents,'sort_thr_commented');
1545 foreach($parents as $i=>$_x)
1546 $parents[$i]['children'] = get_item_children($arr, $_x);
1548 /*foreach($arr as $x) {
1549 if($x['id'] != $x['parent']) {
1550 $p = find_thread_parent_index($parents,$x);
1552 $parents[$p]['children'][] = $x;
1555 if(count($parents)) {
1556 foreach($parents as $k => $v) {
1557 if(count($parents[$k]['children'])) {
1558 $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
1559 /*$y = $parents[$k]['children'];
1560 usort($y,'sort_thr_created_rev');
1561 $parents[$k]['children'] = $y;*/
1567 if(count($parents)) {
1568 foreach($parents as $x) {
1570 if(count($x['children']))
1571 add_children_to_list($x['children'], $ret);
1572 /*foreach($x['children'] as $y)
1581 function sort_thr_created($a,$b) {
1582 return strcmp($b['created'],$a['created']);
1585 function sort_thr_created_rev($a,$b) {
1586 return strcmp($a['created'],$b['created']);
1589 function sort_thr_commented($a,$b) {
1590 return strcmp($b['commented'],$a['commented']);
1593 function find_thread_parent_index($arr,$x) {
1594 foreach($arr as $k => $v)
1595 if($v['id'] == $x['parent'])
1600 function render_location_google($item) {
1601 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1602 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1605 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1607 $location = '<span class="smalltext">' . $coord . '</span>';