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']);
176 // add zrl's to public images
177 if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
178 foreach($matches as $mtch) {
179 $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']);
187 * "Render" a conversation or list of items for HTML display.
188 * There are two major forms of display:
189 * - Sequential or unthreaded ("New Item View" or search results)
190 * - conversation view
191 * The $mode parameter decides between the various renderings and also
192 * figures out how to determine page owner and other contextual items
193 * that are based on unique features of the calling module.
197 if(!function_exists('conversation')) {
198 function conversation(&$a, $items, $mode, $update, $preview = false) {
201 require_once('bbcode.php');
203 $ssl_state = ((local_user()) ? true : false);
206 $page_writeable = false;
208 $previewing = (($preview) ? ' preview ' : '');
210 if($mode === 'network') {
211 $profile_owner = local_user();
212 $page_writeable = true;
215 if($mode === 'profile') {
216 $profile_owner = $a->profile['profile_uid'];
217 $page_writeable = can_write_wall($a,$profile_owner);
220 if($mode === 'notes') {
221 $profile_owner = local_user();
222 $page_writeable = true;
225 if($mode === 'display') {
226 $profile_owner = $a->profile['uid'];
227 $page_writeable = can_write_wall($a,$profile_owner);
230 if($mode === 'community') {
232 $page_writeable = false;
236 $return_url = $_SESSION['return_url'];
238 $return_url = $_SESSION['return_url'] = $a->query_string;
240 load_contact_links(local_user());
242 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
243 call_hooks('conversation_start',$cb);
245 $items = $cb['items'];
247 $cmnt_tpl = get_markup_template('comment_item.tpl');
248 $tpl = 'wall_item.tpl';
249 $wallwall = 'wallwall_item.tpl';
250 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
256 // array with html for each thread (parent+comments)
260 if($items && count($items)) {
262 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
264 // "New Item View" on network page or search page results
265 // - just loop through the items and format them minimally for display
267 //$tpl = get_markup_template('search_item.tpl');
268 $tpl = 'search_item.tpl';
270 foreach($items as $item) {
279 if($mode === 'search' || $mode === 'community') {
280 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
281 && ($item['id'] != $item['parent']))
283 $nickname = $item['nickname'];
286 $nickname = $a->user['nickname'];
288 // prevent private email from leaking.
289 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
292 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
293 if($item['author-link'] && (! $item['author-name']))
294 $profile_name = $item['author-link'];
299 $profile_link = best_link_url($item,$sp);
300 if($profile_link === 'mailbox')
303 $sparkle = ' sparkle';
305 $profile_link = zrl($profile_link);
307 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
308 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
309 $profile_avatar = $a->contacts[$normalised]['thumb'];
311 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
313 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
314 call_hooks('render_location',$locate);
316 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
318 localize_item($item);
319 if($mode === 'network-new')
326 'dropping' => $dropping,
327 'select' => t('Select'),
328 'delete' => t('Delete'),
332 $isstarred = "unstarred";
335 $likebuttons = false;
338 $body = prepare_body($item,true);
340 //$tmp_item = replace_macros($tpl,array(
343 'id' => (($preview) ? 'P0' : $item['item_id']),
344 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
345 'profile_url' => $profile_link,
346 'item_photo_menu' => item_photo_menu($item),
347 'name' => template_escape($profile_name),
348 'sparkle' => $sparkle,
350 'thumb' => $profile_avatar,
351 'title' => template_escape($item['title']),
352 'body' => template_escape($body),
353 'text' => strip_tags(template_escape($body)),
354 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
355 'location' => template_escape($location),
357 'owner_name' => template_escape($owner_name),
358 'owner_url' => $owner_url,
359 'owner_photo' => $owner_photo,
360 'plink' => get_plink($item),
362 'isstarred' => $isstarred,
365 'vote' => $likebuttons,
369 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
370 'previewing' => $previewing,
371 'wait' => t('Please wait'),
374 $arr = array('item' => $item, 'output' => $tmp_item);
375 call_hooks('display_item', $arr);
377 $threads[$threadsid]['id'] = $item['item_id'];
378 $threads[$threadsid]['items'] = array($arr['output']);
388 // Figure out how many comments each parent has
389 // (Comments all have gravity of 6)
390 // Store the result in the $comments array
393 foreach($items as $item) {
394 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
395 if(! x($comments,$item['parent']))
396 $comments[$item['parent']] = 1;
398 $comments[$item['parent']] += 1;
399 } elseif(! x($comments,$item['parent']))
400 $comments[$item['parent']] = 0; // avoid notices later on
403 // map all the like/dislike activities for each parent item
404 // Store these in the $alike and $dlike arrays
406 foreach($items as $item) {
407 like_puller($a,$item,$alike,'like');
408 like_puller($a,$item,$dlike,'dislike');
411 $comments_collapsed = false;
413 $comment_lastcollapsed = false;
414 $comment_firstcollapsed = false;
419 foreach($items as $item) {
425 $owner_url = $owner_photo = $owner_name = '';
427 // We've already parsed out like/dislike for special treatment. We can ignore them now
429 if(((activity_match($item['verb'],ACTIVITY_LIKE))
430 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
431 && ($item['id'] != $item['parent']))
434 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
435 $toplevelprivate = false;
437 // Take care of author collapsing and comment collapsing
438 // (author collapsing is currently disabled)
439 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
440 // If there are more than two comments, squash all but the last 2.
443 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
444 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
447 $comments_collapsed = false;
448 $comment_lastcollapsed = false;
449 $comment_firstcollapsed = false;
452 $threads[$threadsid]['id'] = $item['item_id'];
453 $threads[$threadsid]['private'] = $item['private'];
454 $threads[$threadsid]['items'] = array();
459 // prevent private email reply to public conversation from leaking.
460 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
464 $comment_lastcollapsed = false;
465 $comment_firstcollapsed = false;
468 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
469 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
472 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
474 if (!$comments_collapsed){
475 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
476 $threads[$threadsid]['hide_text'] = t('show more');
477 $comments_collapsed = true;
478 $comment_firstcollapsed = true;
481 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
483 $comment_lastcollapsed = true;
486 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
488 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
489 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
490 ? t('Private Message')
494 // Top-level wall post not written by the wall owner (wall-to-wall)
495 // First figure out who owns it.
499 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
503 // On the network page, I am the owner. On the display page it will be the profile owner.
504 // This will have been stored in $a->page_contact by our calling page.
505 // Put this person as the wall owner of the wall-to-wall notice.
507 $owner_url = zrl($a->page_contact['url']);
508 $owner_photo = $a->page_contact['thumb'];
509 $owner_name = $a->page_contact['name'];
510 $template = $wallwall;
514 if((! $item['wall']) && $item['owner-link']) {
516 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
517 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
518 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
519 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
521 // The author url doesn't match the owner (typically the contact)
522 // and also doesn't match the contact alias.
523 // The name match is a hack to catch several weird cases where URLs are
524 // all over the park. It can be tricked, but this prevents you from
525 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
526 // well that it's the same Bob Smith.
528 // But it could be somebody else with the same name. It just isn't highly likely.
531 $owner_url = $item['owner-link'];
532 $owner_photo = $item['owner-avatar'];
533 $owner_name = $item['owner-name'];
534 $template = $wallwall;
536 // If it is our contact, use a friendly redirect link
537 if((link_compare($item['owner-link'],$item['url']))
538 && ($item['network'] === NETWORK_DFRN)) {
539 $owner_url = $redirect_url;
540 $osparkle = ' sparkle';
543 $owner_url = zrl($owner_url);
549 $shareable = ((($profile_owner == local_user()) && ((! $item['private']) || $item['network'] === NETWORK_FEED)) ? true : false);
551 if($page_writeable) {
553 $likebuttons = array(
554 'like' => array( t("I like this \x28toggle\x29"), t("like")),
555 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
557 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
560 $qc = $qcomment = null;
562 if(in_array('qcomment',$a->plugins)) {
563 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
564 $qcomment = (($qc) ? explode("\n",$qc) : null);
567 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
568 $comment = replace_macros($cmnt_tpl,array(
569 '$return_path' => '',
570 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
571 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
572 '$id' => $item['item_id'],
573 '$parent' => $item['parent'],
574 '$qcomment' => $qcomment,
575 '$profile_uid' => $profile_owner,
576 '$mylink' => $a->contact['url'],
577 '$mytitle' => t('This is you'),
578 '$myphoto' => $a->contact['thumb'],
579 '$comment' => t('Comment'),
580 '$submit' => t('Submit'),
581 '$edbold' => t('Bold'),
582 '$editalic' => t('Italic'),
583 '$eduline' => t('Underline'),
584 '$edquote' => t('Quote'),
585 '$edcode' => t('Code'),
586 '$edimg' => t('Image'),
587 '$edurl' => t('Link'),
588 '$edvideo' => t('Video'),
589 '$preview' => t('Preview'),
590 '$ww' => (($mode === 'network') ? $commentww : '')
595 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
596 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
603 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
607 'dropping' => $dropping,
608 'select' => t('Select'),
609 'delete' => t('Delete'),
615 $isstarred = "unstarred";
616 if ($profile_owner == local_user()) {
618 $isstarred = (($item['starred']) ? "starred" : "unstarred");
621 'do' => t("add star"),
622 'undo' => t("remove star"),
623 'toggle' => t("toggle star status"),
624 'classdo' => (($item['starred']) ? "hidden" : ""),
625 'classundo' => (($item['starred']) ? "" : "hidden"),
626 'starred' => t('starred'),
627 'tagger' => t("add tag"),
631 $filer = t("save to folder");
635 $photo = $item['photo'];
636 $thumb = $item['thumb'];
638 // Post was remotely authored.
640 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
642 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
644 if($item['author-link'] && (! $item['author-name']))
645 $profile_name = $item['author-link'];
648 $profile_link = best_link_url($item,$sp);
649 if($profile_link === 'mailbox')
652 $sparkle = ' sparkle';
654 $profile_link = zrl($profile_link);
656 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
657 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
658 $profile_avatar = $a->contacts[$normalised]['thumb'];
660 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
662 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
663 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
665 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
666 call_hooks('render_location',$locate);
668 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
670 $indent = (($toplevelpost) ? '' : ' comment');
672 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
676 localize_item($item);
680 foreach(explode(',',$item['tag']) as $tag){
682 if ($tag!="") $tags[] = bbcode($tag);
687 $body = prepare_body($item,true);
688 //$tmp_item = replace_macros($template,
690 // collapse comments in template. I don't like this much...
691 'comment_firstcollapsed' => $comment_firstcollapsed,
692 'comment_lastcollapsed' => $comment_lastcollapsed,
693 // template to use to render item (wall, walltowall, search)
694 'template' => $template,
696 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
698 'body' => template_escape($body),
699 'text' => strip_tags(template_escape($body)),
700 'id' => $item['item_id'],
701 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
702 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
704 'wall' => t('Wall-to-Wall'),
705 'vwall' => t('via Wall-To-Wall:'),
706 'profile_url' => $profile_link,
707 'item_photo_menu' => item_photo_menu($item),
708 'name' => template_escape($profile_name),
709 'thumb' => $profile_avatar,
710 'osparkle' => $osparkle,
711 'sparkle' => $sparkle,
712 'title' => template_escape($item['title']),
713 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
715 'location' => template_escape($location),
717 'owner_url' => $owner_url,
718 'owner_photo' => $owner_photo,
719 'owner_name' => template_escape($owner_name),
720 'plink' => get_plink($item),
722 'isstarred' => $isstarred,
726 'vote' => $likebuttons,
728 'dislike' => $dislike,
729 'comment' => $comment,
730 'previewing' => $previewing,
731 'wait' => t('Please wait'),
736 $arr = array('item' => $item, 'output' => $tmp_item);
737 call_hooks('display_item', $arr);
739 $threads[$threadsid]['items'][] = $arr['output'];
744 $page_template = get_markup_template("conversation.tpl");
745 $o = replace_macros($page_template, array(
746 '$baseurl' => $a->get_baseurl($ssl_state),
749 '$threads' => $threads,
750 '$dropping' => ($dropping?t('Delete Selected Items'):False),
756 function best_link_url($item,&$sparkle,$ssl_state = false) {
763 $clean_url = normalise_link($item['author-link']);
765 if((local_user()) && (local_user() == $item['uid'])) {
766 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
767 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
768 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
772 $best_url = $a->contacts[$clean_url]['url'];
776 if(strlen($item['author-link']))
777 $best_url = $item['author-link'];
779 $best_url = $item['url'];
786 if(! function_exists('item_photo_menu')){
787 function item_photo_menu($item){
794 if(! count($a->contacts))
795 load_contact_links(local_user());
804 $profile_link = best_link_url($item,$sparkle,$ssl_state);
805 if($profile_link === 'mailbox')
809 $cid = intval(basename($profile_link));
810 $status_link = $profile_link . "?url=status";
811 $photos_link = $profile_link . "?url=photos";
812 $profile_link = $profile_link . "?url=profile";
813 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
817 $profile_link = zrl($profile_link);
818 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
819 $cid = $item['contact-id'];
825 if(($cid) && (! $item['self'])) {
826 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
827 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
829 $clean_url = normalise_link($item['author-link']);
831 if((local_user()) && (local_user() == $item['uid'])) {
832 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
833 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
834 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
842 t("View Status") => $status_link,
843 t("View Profile") => $profile_link,
844 t("View Photos") => $photos_link,
845 t("Network Posts") => $posts_link,
846 t("Edit Contact") => $contact_url,
847 t("Send PM") => $pm_url,
851 $args = array('item' => $item, 'menu' => $menu);
853 call_hooks('item_photo_menu', $args);
855 $menu = $args['menu'];
858 foreach($menu as $k=>$v){
859 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
864 if(! function_exists('like_puller')) {
865 function like_puller($a,$item,&$arr,$mode) {
869 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
871 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
872 $url = $item['author-link'];
873 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
874 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
875 $sparkle = ' class="sparkle" ';
879 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
880 $arr[$item['parent'] . '-l'] = array();
881 if(! isset($arr[$item['parent']]))
882 $arr[$item['parent']] = 1;
884 $arr[$item['parent']] ++;
885 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
890 // Format the like/dislike text for a profile item
891 // $cnt = number of people who like/dislike the item
892 // $arr = array of pre-linked names of likers/dislikers
893 // $type = one of 'like, 'dislike'
895 // returns formatted text
897 if(! function_exists('format_like')) {
898 function format_like($cnt,$arr,$type,$id) {
901 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
903 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
904 $o .= (($type === 'like') ?
905 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
907 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
909 $total = count($arr);
910 if($total >= MAX_LIKERS)
911 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
912 if($total < MAX_LIKERS)
913 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
914 $str = implode(', ', $arr);
915 if($total >= MAX_LIKERS)
916 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
917 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
918 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
924 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
928 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
931 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
934 $tpl = get_markup_template('jot-header.tpl');
936 $a->page['htmlhead'] .= replace_macros($tpl, array(
937 '$newpost' => 'true',
938 '$baseurl' => $a->get_baseurl(true),
939 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
940 '$geotag' => $geotag,
941 '$nickname' => $x['nickname'],
942 '$ispublic' => t('Visible to <strong>everybody</strong>'),
943 '$linkurl' => t('Please enter a link URL:'),
944 '$vidurl' => t("Please enter a video link/URL:"),
945 '$audurl' => t("Please enter an audio link/URL:"),
946 '$term' => t('Tag term:'),
947 '$fileas' => t('Save to Folder:'),
948 '$whereareu' => t('Where are you right now?')
952 $tpl = get_markup_template("jot.tpl");
957 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
959 $mail_enabled = false;
960 $pubmail_enabled = false;
962 if(($x['is_owner']) && (! $mail_disabled)) {
963 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
967 $mail_enabled = true;
968 if(intval($r[0]['pubmail']))
969 $pubmail_enabled = true;
974 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
975 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
978 call_hooks('jot_tool', $jotplugins);
979 call_hooks('jot_networks', $jotnets);
982 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
984 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
986 $o .= replace_macros($tpl,array(
987 '$return_path' => $a->query_string,
988 '$action' => $a->get_baseurl(true) . '/item',
989 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
990 '$upload' => t('Upload photo'),
991 '$shortupload' => t('upload photo'),
992 '$attach' => t('Attach file'),
993 '$shortattach' => t('attach file'),
994 '$weblink' => t('Insert web link'),
995 '$shortweblink' => t('web link'),
996 '$video' => t('Insert video link'),
997 '$shortvideo' => t('video link'),
998 '$audio' => t('Insert audio link'),
999 '$shortaudio' => t('audio link'),
1000 '$setloc' => t('Set your location'),
1001 '$shortsetloc' => t('set location'),
1002 '$noloc' => t('Clear browser location'),
1003 '$shortnoloc' => t('clear location'),
1005 '$placeholdertitle' => t('Set title'),
1007 '$placeholdercategory' => t('Categories (comma-separated list)'),
1008 '$wait' => t('Please wait'),
1009 '$permset' => t('Permission settings'),
1010 '$shortpermset' => t('permissions'),
1011 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1014 '$baseurl' => $a->get_baseurl(true),
1015 '$defloc' => $x['default_location'],
1016 '$visitor' => $x['visitor'],
1017 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1018 '$emailcc' => t('CC: email addresses'),
1019 '$public' => t('Public post'),
1020 '$jotnets' => $jotnets,
1021 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1022 '$lockstate' => $x['lockstate'],
1023 '$acl' => $x['acl'],
1024 '$bang' => $x['bang'],
1025 '$profile_uid' => $x['profile_uid'],
1026 '$preview' => t('Preview'),
1031 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1039 function conv_sort($arr,$order) {
1041 if((!(is_array($arr) && count($arr))))
1047 if($x['id'] == $x['parent'])
1050 if(stristr($order,'created'))
1051 usort($parents,'sort_thr_created');
1052 elseif(stristr($order,'commented'))
1053 usort($parents,'sort_thr_commented');
1056 foreach($parents as $i=>$_x)
1057 $parents[$i]['children'] = array();
1059 foreach($arr as $x) {
1060 if($x['id'] != $x['parent']) {
1061 $p = find_thread_parent_index($parents,$x);
1063 $parents[$p]['children'][] = $x;
1066 if(count($parents)) {
1067 foreach($parents as $k => $v) {
1068 if(count($parents[$k]['children'])) {
1069 $y = $parents[$k]['children'];
1070 usort($y,'sort_thr_created_rev');
1071 $parents[$k]['children'] = $y;
1077 if(count($parents)) {
1078 foreach($parents as $x) {
1080 if(count($x['children']))
1081 foreach($x['children'] as $y)
1090 function sort_thr_created($a,$b) {
1091 return strcmp($b['created'],$a['created']);
1094 function sort_thr_created_rev($a,$b) {
1095 return strcmp($a['created'],$b['created']);
1098 function sort_thr_commented($a,$b) {
1099 return strcmp($b['commented'],$a['commented']);
1102 function find_thread_parent_index($arr,$x) {
1103 foreach($arr as $k => $v)
1104 if($v['id'] == $x['parent'])
1109 function render_location_google($item) {
1110 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1111 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1114 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1116 $location = '<span class="smalltext">' . $coord . '</span>';