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 * "Render" a conversation or list of items for HTML display.
304 * There are two major forms of display:
305 * - Sequential or unthreaded ("New Item View" or search results)
306 * - conversation view
307 * The $mode parameter decides between the various renderings and also
308 * figures out how to determine page owner and other contextual items
309 * that are based on unique features of the calling module.
313 if(!function_exists('conversation')) {
314 function conversation(&$a, $items, $mode, $update, $preview = false) {
317 require_once('bbcode.php');
319 $ssl_state = ((local_user()) ? true : false);
322 $page_writeable = false;
324 $previewing = (($preview) ? ' preview ' : '');
326 if($mode === 'network') {
327 $profile_owner = local_user();
328 $page_writeable = true;
331 if($mode === 'profile') {
332 $profile_owner = $a->profile['profile_uid'];
333 $page_writeable = can_write_wall($a,$profile_owner);
336 if($mode === 'notes') {
337 $profile_owner = local_user();
338 $page_writeable = true;
341 if($mode === 'display') {
342 $profile_owner = $a->profile['uid'];
343 $page_writeable = can_write_wall($a,$profile_owner);
346 if($mode === 'community') {
348 $page_writeable = false;
352 $return_url = $_SESSION['return_url'];
354 $return_url = $_SESSION['return_url'] = $a->query_string;
356 load_contact_links(local_user());
358 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
359 call_hooks('conversation_start',$cb);
361 $items = $cb['items'];
363 $cmnt_tpl = get_markup_template('comment_item.tpl');
364 $tpl = 'wall_item.tpl';
365 $wallwall = 'wallwall_item.tpl';
366 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
372 // array with html for each thread (parent+comments)
376 if($items && count($items)) {
378 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
380 // "New Item View" on network page or search page results
381 // - just loop through the items and format them minimally for display
383 //$tpl = get_markup_template('search_item.tpl');
384 $tpl = 'search_item.tpl';
386 foreach($items as $item) {
395 if($mode === 'search' || $mode === 'community') {
396 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
397 && ($item['id'] != $item['parent']))
399 $nickname = $item['nickname'];
402 $nickname = $a->user['nickname'];
404 // prevent private email from leaking.
405 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
408 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
409 if($item['author-link'] && (! $item['author-name']))
410 $profile_name = $item['author-link'];
415 $profile_link = best_link_url($item,$sp);
416 if($profile_link === 'mailbox')
419 $sparkle = ' sparkle';
421 $profile_link = zrl($profile_link);
423 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
424 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
425 $profile_avatar = $a->contacts[$normalised]['thumb'];
427 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
429 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
430 call_hooks('render_location',$locate);
432 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
434 localize_item($item);
435 if($mode === 'network-new')
442 'dropping' => $dropping,
443 'select' => t('Select'),
444 'delete' => t('Delete'),
448 $isstarred = "unstarred";
451 $likebuttons = false;
454 $body = prepare_body($item,true);
456 //$tmp_item = replace_macros($tpl,array(
459 'id' => (($preview) ? 'P0' : $item['item_id']),
460 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
461 'profile_url' => $profile_link,
462 'item_photo_menu' => item_photo_menu($item),
463 'name' => template_escape($profile_name),
464 'sparkle' => $sparkle,
466 'thumb' => $profile_avatar,
467 'title' => template_escape($item['title']),
468 'body' => template_escape($body),
469 'text' => strip_tags(template_escape($body)),
470 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
471 'location' => template_escape($location),
473 'owner_name' => template_escape($owner_name),
474 'owner_url' => $owner_url,
475 'owner_photo' => $owner_photo,
476 'plink' => get_plink($item),
478 'isstarred' => $isstarred,
481 'vote' => $likebuttons,
485 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
486 'previewing' => $previewing,
487 'wait' => t('Please wait'),
490 $arr = array('item' => $item, 'output' => $tmp_item);
491 call_hooks('display_item', $arr);
493 $threads[$threadsid]['id'] = $item['item_id'];
494 $threads[$threadsid]['items'] = array($arr['output']);
504 // Figure out how many comments each parent has
505 // (Comments all have gravity of 6)
506 // Store the result in the $comments array
509 foreach($items as $item) {
510 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
511 if(! x($comments,$item['parent']))
512 $comments[$item['parent']] = 1;
514 $comments[$item['parent']] += 1;
515 } elseif(! x($comments,$item['parent']))
516 $comments[$item['parent']] = 0; // avoid notices later on
519 // map all the like/dislike activities for each parent item
520 // Store these in the $alike and $dlike arrays
522 foreach($items as $item) {
523 like_puller($a,$item,$alike,'like');
524 like_puller($a,$item,$dlike,'dislike');
527 $comments_collapsed = false;
529 $comment_lastcollapsed = false;
530 $comment_firstcollapsed = false;
535 foreach($items as $item) {
541 $owner_url = $owner_photo = $owner_name = '';
543 // We've already parsed out like/dislike for special treatment. We can ignore them now
545 if(((activity_match($item['verb'],ACTIVITY_LIKE))
546 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
547 && ($item['id'] != $item['parent']))
550 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
553 // Take care of author collapsing and comment collapsing
554 // (author collapsing is currently disabled)
555 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
556 // If there are more than two comments, squash all but the last 2.
560 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
563 $comments_collapsed = false;
564 $comment_lastcollapsed = false;
565 $comment_firstcollapsed = false;
568 $threads[$threadsid]['id'] = $item['item_id'];
569 $threads[$threadsid]['private'] = $item['private'];
570 $threads[$threadsid]['items'] = array();
575 // prevent private email reply to public conversation from leaking.
576 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
580 $comment_lastcollapsed = false;
581 $comment_firstcollapsed = false;
584 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
585 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
588 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
590 if (!$comments_collapsed){
591 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
592 $threads[$threadsid]['hide_text'] = t('show more');
593 $comments_collapsed = true;
594 $comment_firstcollapsed = true;
597 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
599 $comment_lastcollapsed = true;
602 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
604 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
605 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
606 ? t('Private Message')
610 // Top-level wall post not written by the wall owner (wall-to-wall)
611 // First figure out who owns it.
615 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
619 // On the network page, I am the owner. On the display page it will be the profile owner.
620 // This will have been stored in $a->page_contact by our calling page.
621 // Put this person as the wall owner of the wall-to-wall notice.
623 $owner_url = zrl($a->page_contact['url']);
624 $owner_photo = $a->page_contact['thumb'];
625 $owner_name = $a->page_contact['name'];
626 $template = $wallwall;
630 if((! $item['wall']) && $item['owner-link']) {
632 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
633 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
634 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
635 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
637 // The author url doesn't match the owner (typically the contact)
638 // and also doesn't match the contact alias.
639 // The name match is a hack to catch several weird cases where URLs are
640 // all over the park. It can be tricked, but this prevents you from
641 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
642 // well that it's the same Bob Smith.
644 // But it could be somebody else with the same name. It just isn't highly likely.
647 $owner_url = $item['owner-link'];
648 $owner_photo = $item['owner-avatar'];
649 $owner_name = $item['owner-name'];
650 $template = $wallwall;
652 // If it is our contact, use a friendly redirect link
653 if((link_compare($item['owner-link'],$item['url']))
654 && ($item['network'] === NETWORK_DFRN)) {
655 $owner_url = $redirect_url;
656 $osparkle = ' sparkle';
659 $owner_url = zrl($owner_url);
665 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
667 if($page_writeable) {
668 /* if($toplevelpost) { */
669 $likebuttons = array(
670 'like' => array( t("I like this \x28toggle\x29"), t("like")),
671 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
673 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
676 $qc = $qcomment = null;
678 if(in_array('qcomment',$a->plugins)) {
679 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
680 $qcomment = (($qc) ? explode("\n",$qc) : null);
683 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
684 $comment = replace_macros($cmnt_tpl,array(
685 '$return_path' => '',
686 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
687 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
688 '$id' => $item['item_id'],
689 '$parent' => $item['parent'],
690 '$qcomment' => $qcomment,
691 '$profile_uid' => $profile_owner,
692 '$mylink' => $a->contact['url'],
693 '$mytitle' => t('This is you'),
694 '$myphoto' => $a->contact['thumb'],
695 '$comment' => t('Comment'),
696 '$submit' => t('Submit'),
697 '$edbold' => t('Bold'),
698 '$editalic' => t('Italic'),
699 '$eduline' => t('Underline'),
700 '$edquote' => t('Quote'),
701 '$edcode' => t('Code'),
702 '$edimg' => t('Image'),
703 '$edurl' => t('Link'),
704 '$edvideo' => t('Video'),
705 '$preview' => t('Preview'),
706 '$ww' => (($mode === 'network') ? $commentww : '')
711 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
712 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
719 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
723 'dropping' => $dropping,
724 'select' => t('Select'),
725 'delete' => t('Delete'),
731 $isstarred = "unstarred";
732 if ($profile_owner == local_user()) {
734 $isstarred = (($item['starred']) ? "starred" : "unstarred");
737 'do' => t("add star"),
738 'undo' => t("remove star"),
739 'toggle' => t("toggle star status"),
740 'classdo' => (($item['starred']) ? "hidden" : ""),
741 'classundo' => (($item['starred']) ? "" : "hidden"),
742 'starred' => t('starred'),
743 'tagger' => t("add tag"),
747 $filer = t("save to folder");
751 $photo = $item['photo'];
752 $thumb = $item['thumb'];
754 // Post was remotely authored.
756 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
758 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
760 if($item['author-link'] && (! $item['author-name']))
761 $profile_name = $item['author-link'];
764 $profile_link = best_link_url($item,$sp);
765 if($profile_link === 'mailbox')
768 $sparkle = ' sparkle';
770 $profile_link = zrl($profile_link);
772 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
773 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
774 $profile_avatar = $a->contacts[$normalised]['thumb'];
776 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
778 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
779 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
781 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
782 call_hooks('render_location',$locate);
784 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
786 $indent = (($toplevelpost) ? '' : ' comment');
788 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
792 localize_item($item);
796 foreach(explode(',',$item['tag']) as $tag){
798 if ($tag!="") $tags[] = bbcode($tag);
803 $body = prepare_body($item,true);
804 //$tmp_item = replace_macros($template,
806 // collapse comments in template. I don't like this much...
807 'comment_firstcollapsed' => $comment_firstcollapsed,
808 'comment_lastcollapsed' => $comment_lastcollapsed,
809 // template to use to render item (wall, walltowall, search)
810 'template' => $template,
812 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
814 'body' => template_escape($body),
815 'text' => strip_tags(template_escape($body)),
816 'id' => $item['item_id'],
817 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
818 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner-name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
820 'wall' => t('Wall-to-Wall'),
821 'vwall' => t('via Wall-To-Wall:'),
822 'profile_url' => $profile_link,
823 'item_photo_menu' => item_photo_menu($item),
824 'name' => template_escape($profile_name),
825 'thumb' => $profile_avatar,
826 'osparkle' => $osparkle,
827 'sparkle' => $sparkle,
828 'title' => template_escape($item['title']),
829 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
831 'location' => template_escape($location),
833 'owner_url' => $owner_url,
834 'owner_photo' => $owner_photo,
835 'owner_name' => template_escape($owner_name),
836 'plink' => get_plink($item),
838 'isstarred' => $isstarred,
842 'vote' => $likebuttons,
844 'dislike' => $dislike,
845 'comment' => $comment,
846 'previewing' => $previewing,
847 'wait' => t('Please wait'),
852 $arr = array('item' => $item, 'output' => $tmp_item);
853 call_hooks('display_item', $arr);
855 $threads[$threadsid]['items'][] = $arr['output'];
860 $page_template = get_markup_template("conversation.tpl");
861 $o = replace_macros($page_template, array(
862 '$baseurl' => $a->get_baseurl($ssl_state),
865 '$threads' => $threads,
866 '$dropping' => ($dropping?t('Delete Selected Items'):False),
872 function best_link_url($item,&$sparkle,$ssl_state = false) {
879 $clean_url = normalise_link($item['author-link']);
881 if((local_user()) && (local_user() == $item['uid'])) {
882 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
883 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
884 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
888 $best_url = $a->contacts[$clean_url]['url'];
892 if(strlen($item['author-link']))
893 $best_url = $item['author-link'];
895 $best_url = $item['url'];
902 if(! function_exists('item_photo_menu')){
903 function item_photo_menu($item){
910 if(! count($a->contacts))
911 load_contact_links(local_user());
921 $profile_link = best_link_url($item,$sparkle,$ssl_state);
922 if($profile_link === 'mailbox')
926 $cid = intval(basename($profile_link));
927 $status_link = $profile_link . "?url=status";
928 $photos_link = $profile_link . "?url=photos";
929 $profile_link = $profile_link . "?url=profile";
930 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
934 $profile_link = zrl($profile_link);
935 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
936 $cid = $item['contact-id'];
942 if(($cid) && (! $item['self'])) {
943 $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
944 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
945 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
947 $clean_url = normalise_link($item['author-link']);
949 if((local_user()) && (local_user() == $item['uid'])) {
950 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
951 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
952 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
960 t("View Status") => $status_link,
961 t("View Profile") => $profile_link,
962 t("View Photos") => $photos_link,
963 t("Network Posts") => $posts_link,
964 t("Edit Contact") => $contact_url,
965 t("Send PM") => $pm_url,
966 t("Poke") => $poke_link
970 $args = array('item' => $item, 'menu' => $menu);
972 call_hooks('item_photo_menu', $args);
974 $menu = $args['menu'];
977 foreach($menu as $k=>$v){
978 if ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
983 if(! function_exists('like_puller')) {
984 function like_puller($a,$item,&$arr,$mode) {
988 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
990 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
991 $url = $item['author-link'];
992 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
993 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
994 $sparkle = ' class="sparkle" ';
999 if(! $item['thr-parent'])
1000 $item['thr-parent'] = $item['parent-uri'];
1002 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
1003 $arr[$item['thr-parent'] . '-l'] = array();
1004 if(! isset($arr[$item['thr-parent']]))
1005 $arr[$item['thr-parent']] = 1;
1007 $arr[$item['thr-parent']] ++;
1008 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
1013 // Format the like/dislike text for a profile item
1014 // $cnt = number of people who like/dislike the item
1015 // $arr = array of pre-linked names of likers/dislikers
1016 // $type = one of 'like, 'dislike'
1018 // returns formatted text
1020 if(! function_exists('format_like')) {
1021 function format_like($cnt,$arr,$type,$id) {
1024 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
1026 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
1027 $o .= (($type === 'like') ?
1028 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
1030 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
1032 $total = count($arr);
1033 if($total >= MAX_LIKERS)
1034 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
1035 if($total < MAX_LIKERS)
1036 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
1037 $str = implode(', ', $arr);
1038 if($total >= MAX_LIKERS)
1039 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
1040 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
1041 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
1047 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
1051 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
1054 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
1057 $tpl = get_markup_template('jot-header.tpl');
1058 $a->page['htmlhead'] .= replace_macros($tpl, array(
1059 '$newpost' => 'true',
1060 '$baseurl' => $a->get_baseurl(true),
1061 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1062 '$geotag' => $geotag,
1063 '$nickname' => $x['nickname'],
1064 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1065 '$linkurl' => t('Please enter a link URL:'),
1066 '$vidurl' => t("Please enter a video link/URL:"),
1067 '$audurl' => t("Please enter an audio link/URL:"),
1068 '$term' => t('Tag term:'),
1069 '$fileas' => t('Save to Folder:'),
1070 '$whereareu' => t('Where are you right now?')
1074 $tpl = get_markup_template('jot-end.tpl');
1075 $a->page['end'] .= replace_macros($tpl, array(
1076 '$newpost' => 'true',
1077 '$baseurl' => $a->get_baseurl(true),
1078 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1079 '$geotag' => $geotag,
1080 '$nickname' => $x['nickname'],
1081 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1082 '$linkurl' => t('Please enter a link URL:'),
1083 '$vidurl' => t("Please enter a video link/URL:"),
1084 '$audurl' => t("Please enter an audio link/URL:"),
1085 '$term' => t('Tag term:'),
1086 '$fileas' => t('Save to Folder:'),
1087 '$whereareu' => t('Where are you right now?')
1091 $tpl = get_markup_template("jot.tpl");
1096 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
1098 $mail_enabled = false;
1099 $pubmail_enabled = false;
1101 if(($x['is_owner']) && (! $mail_disabled)) {
1102 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
1103 intval(local_user())
1106 $mail_enabled = true;
1107 if(intval($r[0]['pubmail']))
1108 $pubmail_enabled = true;
1113 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
1114 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
1117 call_hooks('jot_tool', $jotplugins);
1118 call_hooks('jot_networks', $jotnets);
1121 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
1123 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1125 $o .= replace_macros($tpl,array(
1126 '$return_path' => $a->query_string,
1127 '$action' => $a->get_baseurl(true) . '/item',
1128 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1129 '$upload' => t('Upload photo'),
1130 '$shortupload' => t('upload photo'),
1131 '$attach' => t('Attach file'),
1132 '$shortattach' => t('attach file'),
1133 '$weblink' => t('Insert web link'),
1134 '$shortweblink' => t('web link'),
1135 '$video' => t('Insert video link'),
1136 '$shortvideo' => t('video link'),
1137 '$audio' => t('Insert audio link'),
1138 '$shortaudio' => t('audio link'),
1139 '$setloc' => t('Set your location'),
1140 '$shortsetloc' => t('set location'),
1141 '$noloc' => t('Clear browser location'),
1142 '$shortnoloc' => t('clear location'),
1144 '$placeholdertitle' => t('Set title'),
1146 '$placeholdercategory' => t('Categories (comma-separated list)'),
1147 '$wait' => t('Please wait'),
1148 '$permset' => t('Permission settings'),
1149 '$shortpermset' => t('permissions'),
1150 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1153 '$baseurl' => $a->get_baseurl(true),
1154 '$defloc' => $x['default_location'],
1155 '$visitor' => $x['visitor'],
1156 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1157 '$emailcc' => t('CC: email addresses'),
1158 '$public' => t('Public post'),
1159 '$jotnets' => $jotnets,
1160 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1161 '$lockstate' => $x['lockstate'],
1162 '$acl' => $x['acl'],
1163 '$bang' => $x['bang'],
1164 '$profile_uid' => $x['profile_uid'],
1165 '$preview' => t('Preview'),
1170 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1178 function conv_sort($arr,$order) {
1180 if((!(is_array($arr) && count($arr))))
1186 if($x['id'] == $x['parent'])
1189 if(stristr($order,'created'))
1190 usort($parents,'sort_thr_created');
1191 elseif(stristr($order,'commented'))
1192 usort($parents,'sort_thr_commented');
1195 foreach($parents as $i=>$_x)
1196 $parents[$i]['children'] = array();
1198 foreach($arr as $x) {
1199 if($x['id'] != $x['parent']) {
1200 $p = find_thread_parent_index($parents,$x);
1202 $parents[$p]['children'][] = $x;
1205 if(count($parents)) {
1206 foreach($parents as $k => $v) {
1207 if(count($parents[$k]['children'])) {
1208 $y = $parents[$k]['children'];
1209 usort($y,'sort_thr_created_rev');
1210 $parents[$k]['children'] = $y;
1216 if(count($parents)) {
1217 foreach($parents as $x) {
1219 if(count($x['children']))
1220 foreach($x['children'] as $y)
1229 function sort_thr_created($a,$b) {
1230 return strcmp($b['created'],$a['created']);
1233 function sort_thr_created_rev($a,$b) {
1234 return strcmp($a['created'],$b['created']);
1237 function sort_thr_commented($a,$b) {
1238 return strcmp($b['commented'],$a['commented']);
1241 function find_thread_parent_index($arr,$x) {
1242 foreach($arr as $k => $v)
1243 if($v['id'] == $x['parent'])
1248 function render_location_google($item) {
1249 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1250 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1253 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1255 $location = '<span class="smalltext">' . $coord . '</span>';