4 * Render actions localized
6 function localize_item(&$item){
10 $img_start = strpos($Text,'[img]data:');
11 $img_end = strpos($Text,'[/img]');
13 if($img_start !== false && $img_end !== false && $img_end > $img_start) {
14 $start_fragment = substr($Text,0,$img_start);
15 $img_start += strlen('[img]');
16 $saved_image = substr($Text,$img_start,$img_end - $img_start);
17 $end_fragment = substr($Text,$img_end + strlen('[/img]'));
18 $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
19 $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
20 $replace = '[url=' . z_path() . '/redir/' . $item['contact-id']
21 . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
23 $Text = preg_replace($search,$replace,$Text);
25 if(strlen($saved_image))
26 $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
29 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
30 if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
32 $r = q("SELECT * from `item`,`contact` WHERE
33 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
34 dbesc($item['parent-uri']));
35 if(count($r)==0) return;
38 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
39 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
43 switch ($obj['object-type']){
44 case ACTIVITY_OBJ_EVENT:
45 $post_type = t('event');
48 $post_type = t('status');
52 if($obj['resource-id']){
53 $post_type = t('photo');
54 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
57 $post_type = t('status');
61 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
63 switch($item['verb']){
65 $bodyverb = t('%1$s likes %2$s\'s %3$s');
67 case ACTIVITY_DISLIKE:
68 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
71 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
74 if ($item['verb']=== ACTIVITY_FRIEND){
76 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
78 $Aname = $item['author-name'];
79 $Alink = $item['author-link'];
81 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
83 $obj = parse_xml_string($xmlhead.$item['object']);
84 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
87 $Blink = ""; $Bphoto = "";
88 foreach ($links->link as $l){
89 $atts = $l->attributes();
91 case "alternate": $Blink = $atts['href'];
92 case "photo": $Bphoto = $atts['href'];
97 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
98 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
99 if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
101 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
104 if ($item['verb']===ACTIVITY_TAG){
105 $r = q("SELECT * from `item`,`contact` WHERE
106 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
107 dbesc($item['parent-uri']));
108 if(count($r)==0) return;
111 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
112 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
114 switch($obj['verb']){
116 switch ($obj['object-type']){
117 case ACTIVITY_OBJ_EVENT:
118 $post_type = t('event');
121 $post_type = t('status');
125 if($obj['resource-id']){
126 $post_type = t('photo');
127 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
128 $rr['plink'] = $m[1];
130 $post_type = t('status');
133 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
135 $parsedobj = parse_xml_string($xmlhead.$item['object']);
137 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
138 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
141 if ($item['verb']=== ACTIVITY_FAVORITE){
143 if ($item['object-type']== "")
146 $Aname = $item['author-name'];
147 $Alink = $item['author-link'];
149 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
151 $obj = parse_xml_string($xmlhead.$item['object']);
152 if(strlen($obj->id)) {
153 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
157 if(count($r) && $r[0]['plink']) {
159 $Bname = $target['author-name'];
160 $Blink = $target['author-link'];
161 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
162 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
163 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
164 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
170 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
171 foreach($matches as $mtch) {
172 if(! strpos($mtch[1],'zrl='))
173 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
181 * "Render" a conversation or list of items for HTML display.
182 * There are two major forms of display:
183 * - Sequential or unthreaded ("New Item View" or search results)
184 * - conversation view
185 * The $mode parameter decides between the various renderings and also
186 * figures out how to determine page owner and other contextual items
187 * that are based on unique features of the calling module.
191 if(!function_exists('conversation')) {
192 function conversation(&$a, $items, $mode, $update, $preview = false) {
195 require_once('bbcode.php');
197 $ssl_state = ((local_user()) ? true : false);
200 $page_writeable = false;
202 $previewing = (($preview) ? ' preview ' : '');
204 if($mode === 'network') {
205 $profile_owner = local_user();
206 $page_writeable = true;
209 if($mode === 'profile') {
210 $profile_owner = $a->profile['profile_uid'];
211 $page_writeable = can_write_wall($a,$profile_owner);
214 if($mode === 'notes') {
215 $profile_owner = local_user();
216 $page_writeable = true;
219 if($mode === 'display') {
220 $profile_owner = $a->profile['uid'];
221 $page_writeable = can_write_wall($a,$profile_owner);
224 if($mode === 'community') {
226 $page_writeable = false;
230 $return_url = $_SESSION['return_url'];
232 $return_url = $_SESSION['return_url'] = $a->query_string;
234 load_contact_links(local_user());
236 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
237 call_hooks('conversation_start',$cb);
239 $items = $cb['items'];
241 $cmnt_tpl = get_markup_template('comment_item.tpl');
242 $tpl = 'wall_item.tpl';
243 $wallwall = 'wallwall_item.tpl';
244 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
250 // array with html for each thread (parent+comments)
254 if($items && count($items)) {
256 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
258 // "New Item View" on network page or search page results
259 // - just loop through the items and format them minimally for display
261 //$tpl = get_markup_template('search_item.tpl');
262 $tpl = 'search_item.tpl';
264 foreach($items as $item) {
273 if($mode === 'search' || $mode === 'community') {
274 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
275 && ($item['id'] != $item['parent']))
277 $nickname = $item['nickname'];
280 $nickname = $a->user['nickname'];
282 // prevent private email from leaking.
283 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
286 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
287 if($item['author-link'] && (! $item['author-name']))
288 $profile_name = $item['author-link'];
293 $profile_link = best_link_url($item,$sp);
294 if($profile_link === 'mailbox')
297 $sparkle = ' sparkle';
299 $profile_link = zrl($profile_link);
301 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
302 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
303 $profile_avatar = $a->contacts[$normalised]['thumb'];
305 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
307 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
308 call_hooks('render_location',$locate);
310 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
312 localize_item($item);
313 if($mode === 'network-new')
320 'dropping' => $dropping,
321 'select' => t('Select'),
322 'delete' => t('Delete'),
326 $isstarred = "unstarred";
329 $likebuttons = false;
332 $body = prepare_body($item,true);
334 //$tmp_item = replace_macros($tpl,array(
337 'id' => (($preview) ? 'P0' : $item['item_id']),
338 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
339 'profile_url' => $profile_link,
340 'item_photo_menu' => item_photo_menu($item),
341 'name' => template_escape($profile_name),
342 'sparkle' => $sparkle,
344 'thumb' => $profile_avatar,
345 'title' => template_escape($item['title']),
346 'body' => template_escape($body),
347 'text' => strip_tags(template_escape($body)),
348 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
349 'location' => template_escape($location),
351 'owner_name' => template_escape($owner_name),
352 'owner_url' => $owner_url,
353 'owner_photo' => $owner_photo,
354 'plink' => get_plink($item),
356 'isstarred' => $isstarred,
359 'vote' => $likebuttons,
363 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
364 'previewing' => $previewing,
365 'wait' => t('Please wait'),
368 $arr = array('item' => $item, 'output' => $tmp_item);
369 call_hooks('display_item', $arr);
371 $threads[$threadsid]['id'] = $item['item_id'];
372 $threads[$threadsid]['items'] = array($arr['output']);
382 // Figure out how many comments each parent has
383 // (Comments all have gravity of 6)
384 // Store the result in the $comments array
387 foreach($items as $item) {
388 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
389 if(! x($comments,$item['parent']))
390 $comments[$item['parent']] = 1;
392 $comments[$item['parent']] += 1;
393 } elseif(! x($comments,$item['parent']))
394 $comments[$item['parent']] = 0; // avoid notices later on
397 // map all the like/dislike activities for each parent item
398 // Store these in the $alike and $dlike arrays
400 foreach($items as $item) {
401 like_puller($a,$item,$alike,'like');
402 like_puller($a,$item,$dlike,'dislike');
405 $comments_collapsed = false;
407 $comment_lastcollapsed = false;
408 $comment_firstcollapsed = false;
413 foreach($items as $item) {
419 $owner_url = $owner_photo = $owner_name = '';
421 // We've already parsed out like/dislike for special treatment. We can ignore them now
423 if(((activity_match($item['verb'],ACTIVITY_LIKE))
424 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
425 && ($item['id'] != $item['parent']))
428 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
429 $toplevelprivate = false;
431 // Take care of author collapsing and comment collapsing
432 // (author collapsing is currently disabled)
433 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
434 // If there are more than two comments, squash all but the last 2.
437 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
438 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
441 $comments_collapsed = false;
442 $comment_lastcollapsed = false;
443 $comment_firstcollapsed = false;
446 $threads[$threadsid]['id'] = $item['item_id'];
447 $threads[$threadsid]['private'] = $item['private'];
448 $threads[$threadsid]['items'] = array();
453 // prevent private email reply to public conversation from leaking.
454 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
458 $comment_lastcollapsed = false;
459 $comment_firstcollapsed = false;
462 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
463 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
466 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
468 if (!$comments_collapsed){
469 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
470 $threads[$threadsid]['hide_text'] = t('show more');
471 $comments_collapsed = true;
472 $comment_firstcollapsed = true;
475 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
477 $comment_lastcollapsed = true;
480 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
482 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
483 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
484 ? t('Private Message')
488 // Top-level wall post not written by the wall owner (wall-to-wall)
489 // First figure out who owns it.
493 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
497 // On the network page, I am the owner. On the display page it will be the profile owner.
498 // This will have been stored in $a->page_contact by our calling page.
499 // Put this person as the wall owner of the wall-to-wall notice.
501 $owner_url = zrl($a->page_contact['url']);
502 $owner_photo = $a->page_contact['thumb'];
503 $owner_name = $a->page_contact['name'];
504 $template = $wallwall;
508 if((! $item['wall']) && $item['owner-link']) {
510 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
511 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
512 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
513 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
515 // The author url doesn't match the owner (typically the contact)
516 // and also doesn't match the contact alias.
517 // The name match is a hack to catch several weird cases where URLs are
518 // all over the park. It can be tricked, but this prevents you from
519 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
520 // well that it's the same Bob Smith.
522 // But it could be somebody else with the same name. It just isn't highly likely.
525 $owner_url = $item['owner-link'];
526 $owner_photo = $item['owner-avatar'];
527 $owner_name = $item['owner-name'];
528 $template = $wallwall;
530 // If it is our contact, use a friendly redirect link
531 if((link_compare($item['owner-link'],$item['url']))
532 && ($item['network'] === NETWORK_DFRN)) {
533 $owner_url = $redirect_url;
534 $osparkle = ' sparkle';
537 $owner_url = zrl($owner_url);
543 $shareable = ((($profile_owner == local_user()) && (! $item['private'])) ? true : false); //($mode != 'display') &&
545 if($page_writeable) {
547 $likebuttons = array(
548 'like' => array( t("I like this \x28toggle\x29"), t("like")),
549 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
551 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
554 $qc = $qcomment = null;
556 if(in_array('qcomment',$a->plugins)) {
557 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
558 $qcomment = (($qc) ? explode("\n",$qc) : null);
561 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
562 $comment = replace_macros($cmnt_tpl,array(
563 '$return_path' => '',
564 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
565 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
566 '$id' => $item['item_id'],
567 '$parent' => $item['parent'],
568 '$qcomment' => $qcomment,
569 '$profile_uid' => $profile_owner,
570 '$mylink' => $a->contact['url'],
571 '$mytitle' => t('This is you'),
572 '$myphoto' => $a->contact['thumb'],
573 '$comment' => t('Comment'),
574 '$submit' => t('Submit'),
575 '$edbold' => t('Bold'),
576 '$editalic' => t('Italic'),
577 '$eduline' => t('Underline'),
578 '$edquote' => t('Quote'),
579 '$edcode' => t('Code'),
580 '$edimg' => t('Image'),
581 '$edurl' => t('Link'),
582 '$edvideo' => t('Video'),
583 '$preview' => t('Preview'),
584 '$ww' => (($mode === 'network') ? $commentww : '')
589 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
590 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
597 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
601 'dropping' => $dropping,
602 'select' => t('Select'),
603 'delete' => t('Delete'),
609 $isstarred = "unstarred";
610 if ($profile_owner == local_user()) {
612 $isstarred = (($item['starred']) ? "starred" : "unstarred");
615 'do' => t("add star"),
616 'undo' => t("remove star"),
617 'toggle' => t("toggle star status"),
618 'classdo' => (($item['starred']) ? "hidden" : ""),
619 'classundo' => (($item['starred']) ? "" : "hidden"),
620 'starred' => t('starred'),
621 'tagger' => t("add tag"),
625 $filer = t("save to folder");
629 $photo = $item['photo'];
630 $thumb = $item['thumb'];
632 // Post was remotely authored.
634 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
636 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
638 if($item['author-link'] && (! $item['author-name']))
639 $profile_name = $item['author-link'];
642 $profile_link = best_link_url($item,$sp);
643 if($profile_link === 'mailbox')
646 $sparkle = ' sparkle';
648 $profile_link = zrl($profile_link);
650 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
651 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
652 $profile_avatar = $a->contacts[$normalised]['thumb'];
654 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
656 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
657 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
659 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
660 call_hooks('render_location',$locate);
662 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
664 $indent = (($toplevelpost) ? '' : ' comment');
666 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
670 localize_item($item);
674 foreach(explode(',',$item['tag']) as $tag){
676 if ($tag!="") $tags[] = bbcode($tag);
681 $body = prepare_body($item,true);
682 //$tmp_item = replace_macros($template,
684 // collapse comments in template. I don't like this much...
685 'comment_firstcollapsed' => $comment_firstcollapsed,
686 'comment_lastcollapsed' => $comment_lastcollapsed,
687 // template to use to render item (wall, walltowall, search)
688 'template' => $template,
690 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
692 'body' => template_escape($body),
693 'text' => strip_tags(template_escape($body)),
694 'id' => $item['item_id'],
695 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
696 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
698 'wall' => t('Wall-to-Wall'),
699 'vwall' => t('via Wall-To-Wall:'),
700 'profile_url' => $profile_link,
701 'item_photo_menu' => item_photo_menu($item),
702 'name' => template_escape($profile_name),
703 'thumb' => $profile_avatar,
704 'osparkle' => $osparkle,
705 'sparkle' => $sparkle,
706 'title' => template_escape($item['title']),
707 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
709 'location' => template_escape($location),
711 'owner_url' => $owner_url,
712 'owner_photo' => $owner_photo,
713 'owner_name' => template_escape($owner_name),
714 'plink' => get_plink($item),
716 'isstarred' => $isstarred,
720 'vote' => $likebuttons,
722 'dislike' => $dislike,
723 'comment' => $comment,
724 'previewing' => $previewing,
725 'wait' => t('Please wait'),
730 $arr = array('item' => $item, 'output' => $tmp_item);
731 call_hooks('display_item', $arr);
733 $threads[$threadsid]['items'][] = $arr['output'];
738 $page_template = get_markup_template("conversation.tpl");
739 $o = replace_macros($page_template, array(
740 '$baseurl' => $a->get_baseurl($ssl_state),
743 '$threads' => $threads,
744 '$dropping' => ($dropping?t('Delete Selected Items'):False),
750 function best_link_url($item,&$sparkle,$ssl_state = false) {
757 $clean_url = normalise_link($item['author-link']);
759 if((local_user()) && (local_user() == $item['uid'])) {
760 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
761 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
762 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
766 $best_url = $a->contacts[$clean_url]['url'];
770 if(strlen($item['author-link']))
771 $best_url = $item['author-link'];
773 $best_url = $item['url'];
780 if(! function_exists('item_photo_menu')){
781 function item_photo_menu($item){
788 if(! count($a->contacts))
789 load_contact_links(local_user());
798 $profile_link = best_link_url($item,$sparkle,$ssl_state);
799 if($profile_link === 'mailbox')
803 $cid = intval(basename($profile_link));
804 $status_link = $profile_link . "?url=status";
805 $photos_link = $profile_link . "?url=photos";
806 $profile_link = $profile_link . "?url=profile";
807 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
811 $profile_link = zrl($profile_link);
812 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
813 $cid = $item['contact-id'];
819 if(($cid) && (! $item['self'])) {
820 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
821 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
823 $clean_url = normalise_link($item['author-link']);
825 if((local_user()) && (local_user() == $item['uid'])) {
826 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
827 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
828 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
836 t("View Status") => $status_link,
837 t("View Profile") => $profile_link,
838 t("View Photos") => $photos_link,
839 t("Network Posts") => $posts_link,
840 t("Edit Contact") => $contact_url,
841 t("Send PM") => $pm_url,
845 $args = array('item' => $item, 'menu' => $menu);
847 call_hooks('item_photo_menu', $args);
849 $menu = $args['menu'];
852 foreach($menu as $k=>$v){
853 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
858 if(! function_exists('like_puller')) {
859 function like_puller($a,$item,&$arr,$mode) {
863 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
865 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
866 $url = $item['author-link'];
867 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
868 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
869 $sparkle = ' class="sparkle" ';
873 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
874 $arr[$item['parent'] . '-l'] = array();
875 if(! isset($arr[$item['parent']]))
876 $arr[$item['parent']] = 1;
878 $arr[$item['parent']] ++;
879 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
884 // Format the like/dislike text for a profile item
885 // $cnt = number of people who like/dislike the item
886 // $arr = array of pre-linked names of likers/dislikers
887 // $type = one of 'like, 'dislike'
889 // returns formatted text
891 if(! function_exists('format_like')) {
892 function format_like($cnt,$arr,$type,$id) {
895 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
897 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
898 $o .= (($type === 'like') ?
899 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
901 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
903 $total = count($arr);
904 if($total >= MAX_LIKERS)
905 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
906 if($total < MAX_LIKERS)
907 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
908 $str = implode(', ', $arr);
909 if($total >= MAX_LIKERS)
910 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
911 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
912 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
918 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
922 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
925 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
928 $tpl = get_markup_template('jot-header.tpl');
930 $a->page['htmlhead'] .= replace_macros($tpl, array(
931 '$newpost' => 'true',
932 '$baseurl' => $a->get_baseurl(true),
933 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
934 '$geotag' => $geotag,
935 '$nickname' => $x['nickname'],
936 '$ispublic' => t('Visible to <strong>everybody</strong>'),
937 '$linkurl' => t('Please enter a link URL:'),
938 '$vidurl' => t("Please enter a video link/URL:"),
939 '$audurl' => t("Please enter an audio link/URL:"),
940 '$term' => t('Tag term:'),
941 '$fileas' => t('Save to Folder:'),
942 '$whereareu' => t('Where are you right now?')
946 $tpl = get_markup_template("jot.tpl");
951 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
953 $mail_enabled = false;
954 $pubmail_enabled = false;
956 if(($x['is_owner']) && (! $mail_disabled)) {
957 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
961 $mail_enabled = true;
962 if(intval($r[0]['pubmail']))
963 $pubmail_enabled = true;
968 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
969 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
972 call_hooks('jot_tool', $jotplugins);
973 call_hooks('jot_networks', $jotnets);
976 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
978 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
980 $o .= replace_macros($tpl,array(
981 '$return_path' => $a->query_string,
982 '$action' => $a->get_baseurl(true) . '/item',
983 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
984 '$upload' => t('Upload photo'),
985 '$shortupload' => t('upload photo'),
986 '$attach' => t('Attach file'),
987 '$shortattach' => t('attach file'),
988 '$weblink' => t('Insert web link'),
989 '$shortweblink' => t('web link'),
990 '$video' => t('Insert video link'),
991 '$shortvideo' => t('video link'),
992 '$audio' => t('Insert audio link'),
993 '$shortaudio' => t('audio link'),
994 '$setloc' => t('Set your location'),
995 '$shortsetloc' => t('set location'),
996 '$noloc' => t('Clear browser location'),
997 '$shortnoloc' => t('clear location'),
999 '$placeholdertitle' => t('Set title'),
1001 '$placeholdercategory' => t('Categories (comma-separated list)'),
1002 '$wait' => t('Please wait'),
1003 '$permset' => t('Permission settings'),
1004 '$shortpermset' => t('permissions'),
1005 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1008 '$baseurl' => $a->get_baseurl(true),
1009 '$defloc' => $x['default_location'],
1010 '$visitor' => $x['visitor'],
1011 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1012 '$emailcc' => t('CC: email addresses'),
1013 '$public' => t('Public post'),
1014 '$jotnets' => $jotnets,
1015 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1016 '$lockstate' => $x['lockstate'],
1017 '$acl' => $x['acl'],
1018 '$bang' => $x['bang'],
1019 '$profile_uid' => $x['profile_uid'],
1020 '$preview' => t('Preview'),
1025 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1033 function conv_sort($arr,$order) {
1035 if((!(is_array($arr) && count($arr))))
1041 if($x['id'] == $x['parent'])
1044 if(stristr($order,'created'))
1045 usort($parents,'sort_thr_created');
1046 elseif(stristr($order,'commented'))
1047 usort($parents,'sort_thr_commented');
1050 foreach($parents as $i=>$_x)
1051 $parents[$i]['children'] = array();
1053 foreach($arr as $x) {
1054 if($x['id'] != $x['parent']) {
1055 $p = find_thread_parent_index($parents,$x);
1057 $parents[$p]['children'][] = $x;
1060 if(count($parents)) {
1061 foreach($parents as $k => $v) {
1062 if(count($parents[$k]['children'])) {
1063 $y = $parents[$k]['children'];
1064 usort($y,'sort_thr_created_rev');
1065 $parents[$k]['children'] = $y;
1071 if(count($parents)) {
1072 foreach($parents as $x) {
1074 if(count($x['children']))
1075 foreach($x['children'] as $y)
1084 function sort_thr_created($a,$b) {
1085 return strcmp($b['created'],$a['created']);
1088 function sort_thr_created_rev($a,$b) {
1089 return strcmp($a['created'],$b['created']);
1092 function sort_thr_commented($a,$b) {
1093 return strcmp($b['commented'],$a['commented']);
1096 function find_thread_parent_index($arr,$x) {
1097 foreach($arr as $k => $v)
1098 if($v['id'] == $x['parent'])
1103 function render_location_google($item) {
1104 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1105 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1108 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1110 $location = '<span class="smalltext">' . $coord . '</span>';