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 ($item['verb']===ACTIVITY_TAG){
166 $r = q("SELECT * from `item`,`contact` WHERE
167 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
168 dbesc($item['parent-uri']));
169 if(count($r)==0) return;
172 $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
173 $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
175 switch($obj['verb']){
177 switch ($obj['object-type']){
178 case ACTIVITY_OBJ_EVENT:
179 $post_type = t('event');
182 $post_type = t('status');
186 if($obj['resource-id']){
187 $post_type = t('photo');
188 $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
189 $rr['plink'] = $m[1];
191 $post_type = t('status');
194 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
196 $parsedobj = parse_xml_string($xmlhead.$item['object']);
198 $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
199 $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
202 if ($item['verb']=== ACTIVITY_FAVORITE){
204 if ($item['object-type']== "")
207 $Aname = $item['author-name'];
208 $Alink = $item['author-link'];
210 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
212 $obj = parse_xml_string($xmlhead.$item['object']);
213 if(strlen($obj->id)) {
214 $r = q("select * from item where uri = '%s' and uid = %d limit 1",
218 if(count($r) && $r[0]['plink']) {
220 $Bname = $target['author-name'];
221 $Blink = $target['author-link'];
222 $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
223 $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
224 $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
225 $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
231 if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
232 foreach($matches as $mtch) {
233 if(! strpos($mtch[1],'zrl='))
234 $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
238 // add zrl's to public images
239 if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
240 foreach($matches as $mtch) {
241 $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']);
245 // add sparkle links to appropriate permalinks
247 $x = stristr($item['plink'],'/display/');
250 $y = best_link_url($item,$sparkle,true);
251 if(strstr($y,'/redir/'))
252 $item['plink'] = $y . '?f=&url=' . $item['plink'];
260 * "Render" a conversation or list of items for HTML display.
261 * There are two major forms of display:
262 * - Sequential or unthreaded ("New Item View" or search results)
263 * - conversation view
264 * The $mode parameter decides between the various renderings and also
265 * figures out how to determine page owner and other contextual items
266 * that are based on unique features of the calling module.
270 if(!function_exists('conversation')) {
271 function conversation(&$a, $items, $mode, $update, $preview = false) {
274 require_once('bbcode.php');
276 $ssl_state = ((local_user()) ? true : false);
279 $page_writeable = false;
281 $previewing = (($preview) ? ' preview ' : '');
283 if($mode === 'network') {
284 $profile_owner = local_user();
285 $page_writeable = true;
288 if($mode === 'profile') {
289 $profile_owner = $a->profile['profile_uid'];
290 $page_writeable = can_write_wall($a,$profile_owner);
293 if($mode === 'notes') {
294 $profile_owner = local_user();
295 $page_writeable = true;
298 if($mode === 'display') {
299 $profile_owner = $a->profile['uid'];
300 $page_writeable = can_write_wall($a,$profile_owner);
303 if($mode === 'community') {
305 $page_writeable = false;
309 $return_url = $_SESSION['return_url'];
311 $return_url = $_SESSION['return_url'] = $a->query_string;
313 load_contact_links(local_user());
315 $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
316 call_hooks('conversation_start',$cb);
318 $items = $cb['items'];
320 $cmnt_tpl = get_markup_template('comment_item.tpl');
321 $tpl = 'wall_item.tpl';
322 $wallwall = 'wallwall_item.tpl';
323 $hide_comments_tpl = get_markup_template('hide_comments.tpl');
329 // array with html for each thread (parent+comments)
333 if($items && count($items)) {
335 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
337 // "New Item View" on network page or search page results
338 // - just loop through the items and format them minimally for display
340 //$tpl = get_markup_template('search_item.tpl');
341 $tpl = 'search_item.tpl';
343 foreach($items as $item) {
352 if($mode === 'search' || $mode === 'community') {
353 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
354 && ($item['id'] != $item['parent']))
356 $nickname = $item['nickname'];
359 $nickname = $a->user['nickname'];
361 // prevent private email from leaking.
362 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
365 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
366 if($item['author-link'] && (! $item['author-name']))
367 $profile_name = $item['author-link'];
372 $profile_link = best_link_url($item,$sp);
373 if($profile_link === 'mailbox')
376 $sparkle = ' sparkle';
378 $profile_link = zrl($profile_link);
380 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
381 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
382 $profile_avatar = $a->contacts[$normalised]['thumb'];
384 $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
386 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
387 call_hooks('render_location',$locate);
389 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
391 localize_item($item);
392 if($mode === 'network-new')
399 'dropping' => $dropping,
400 'select' => t('Select'),
401 'delete' => t('Delete'),
405 $isstarred = "unstarred";
408 $likebuttons = false;
411 $body = prepare_body($item,true);
413 //$tmp_item = replace_macros($tpl,array(
416 'id' => (($preview) ? 'P0' : $item['item_id']),
417 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
418 'profile_url' => $profile_link,
419 'item_photo_menu' => item_photo_menu($item),
420 'name' => template_escape($profile_name),
421 'sparkle' => $sparkle,
423 'thumb' => $profile_avatar,
424 'title' => template_escape($item['title']),
425 'body' => template_escape($body),
426 'text' => strip_tags(template_escape($body)),
427 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
428 'location' => template_escape($location),
430 'owner_name' => template_escape($owner_name),
431 'owner_url' => $owner_url,
432 'owner_photo' => $owner_photo,
433 'plink' => get_plink($item),
435 'isstarred' => $isstarred,
438 'vote' => $likebuttons,
442 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
443 'previewing' => $previewing,
444 'wait' => t('Please wait'),
447 $arr = array('item' => $item, 'output' => $tmp_item);
448 call_hooks('display_item', $arr);
450 $threads[$threadsid]['id'] = $item['item_id'];
451 $threads[$threadsid]['items'] = array($arr['output']);
461 // Figure out how many comments each parent has
462 // (Comments all have gravity of 6)
463 // Store the result in the $comments array
466 foreach($items as $item) {
467 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
468 if(! x($comments,$item['parent']))
469 $comments[$item['parent']] = 1;
471 $comments[$item['parent']] += 1;
472 } elseif(! x($comments,$item['parent']))
473 $comments[$item['parent']] = 0; // avoid notices later on
476 // map all the like/dislike activities for each parent item
477 // Store these in the $alike and $dlike arrays
479 foreach($items as $item) {
480 like_puller($a,$item,$alike,'like');
481 like_puller($a,$item,$dlike,'dislike');
484 $comments_collapsed = false;
486 $comment_lastcollapsed = false;
487 $comment_firstcollapsed = false;
492 foreach($items as $item) {
498 $owner_url = $owner_photo = $owner_name = '';
500 // We've already parsed out like/dislike for special treatment. We can ignore them now
502 if(((activity_match($item['verb'],ACTIVITY_LIKE))
503 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
504 && ($item['id'] != $item['parent']))
507 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
510 // Take care of author collapsing and comment collapsing
511 // (author collapsing is currently disabled)
512 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
513 // If there are more than two comments, squash all but the last 2.
517 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
520 $comments_collapsed = false;
521 $comment_lastcollapsed = false;
522 $comment_firstcollapsed = false;
525 $threads[$threadsid]['id'] = $item['item_id'];
526 $threads[$threadsid]['private'] = $item['private'];
527 $threads[$threadsid]['items'] = array();
532 // prevent private email reply to public conversation from leaking.
533 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
537 $comment_lastcollapsed = false;
538 $comment_firstcollapsed = false;
541 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
542 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
545 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
547 if (!$comments_collapsed){
548 $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
549 $threads[$threadsid]['hide_text'] = t('show more');
550 $comments_collapsed = true;
551 $comment_firstcollapsed = true;
554 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
556 $comment_lastcollapsed = true;
559 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
561 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
562 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
563 ? t('Private Message')
567 // Top-level wall post not written by the wall owner (wall-to-wall)
568 // First figure out who owns it.
572 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
576 // On the network page, I am the owner. On the display page it will be the profile owner.
577 // This will have been stored in $a->page_contact by our calling page.
578 // Put this person as the wall owner of the wall-to-wall notice.
580 $owner_url = zrl($a->page_contact['url']);
581 $owner_photo = $a->page_contact['thumb'];
582 $owner_name = $a->page_contact['name'];
583 $template = $wallwall;
587 if((! $item['wall']) && $item['owner-link']) {
589 $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
590 $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
591 $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
592 if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
594 // The author url doesn't match the owner (typically the contact)
595 // and also doesn't match the contact alias.
596 // The name match is a hack to catch several weird cases where URLs are
597 // all over the park. It can be tricked, but this prevents you from
598 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
599 // well that it's the same Bob Smith.
601 // But it could be somebody else with the same name. It just isn't highly likely.
604 $owner_url = $item['owner-link'];
605 $owner_photo = $item['owner-avatar'];
606 $owner_name = $item['owner-name'];
607 $template = $wallwall;
609 // If it is our contact, use a friendly redirect link
610 if((link_compare($item['owner-link'],$item['url']))
611 && ($item['network'] === NETWORK_DFRN)) {
612 $owner_url = $redirect_url;
613 $osparkle = ' sparkle';
616 $owner_url = zrl($owner_url);
622 $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
624 if($page_writeable) {
625 /* if($toplevelpost) { */
626 $likebuttons = array(
627 'like' => array( t("I like this \x28toggle\x29"), t("like")),
628 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
630 if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
633 $qc = $qcomment = null;
635 if(in_array('qcomment',$a->plugins)) {
636 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
637 $qcomment = (($qc) ? explode("\n",$qc) : null);
640 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
641 $comment = replace_macros($cmnt_tpl,array(
642 '$return_path' => '',
643 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
644 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
645 '$id' => $item['item_id'],
646 '$parent' => $item['parent'],
647 '$qcomment' => $qcomment,
648 '$profile_uid' => $profile_owner,
649 '$mylink' => $a->contact['url'],
650 '$mytitle' => t('This is you'),
651 '$myphoto' => $a->contact['thumb'],
652 '$comment' => t('Comment'),
653 '$submit' => t('Submit'),
654 '$edbold' => t('Bold'),
655 '$editalic' => t('Italic'),
656 '$eduline' => t('Underline'),
657 '$edquote' => t('Quote'),
658 '$edcode' => t('Code'),
659 '$edimg' => t('Image'),
660 '$edurl' => t('Link'),
661 '$edvideo' => t('Video'),
662 '$preview' => t('Preview'),
663 '$ww' => (($mode === 'network') ? $commentww : '')
668 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
669 $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
676 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
680 'dropping' => $dropping,
681 'select' => t('Select'),
682 'delete' => t('Delete'),
688 $isstarred = "unstarred";
689 if ($profile_owner == local_user()) {
691 $isstarred = (($item['starred']) ? "starred" : "unstarred");
694 'do' => t("add star"),
695 'undo' => t("remove star"),
696 'toggle' => t("toggle star status"),
697 'classdo' => (($item['starred']) ? "hidden" : ""),
698 'classundo' => (($item['starred']) ? "" : "hidden"),
699 'starred' => t('starred'),
700 'tagger' => t("add tag"),
704 $filer = t("save to folder");
708 $photo = $item['photo'];
709 $thumb = $item['thumb'];
711 // Post was remotely authored.
713 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
715 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
717 if($item['author-link'] && (! $item['author-name']))
718 $profile_name = $item['author-link'];
721 $profile_link = best_link_url($item,$sp);
722 if($profile_link === 'mailbox')
725 $sparkle = ' sparkle';
727 $profile_link = zrl($profile_link);
729 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
730 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
731 $profile_avatar = $a->contacts[$normalised]['thumb'];
733 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
735 $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
736 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
738 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
739 call_hooks('render_location',$locate);
741 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
743 $indent = (($toplevelpost) ? '' : ' comment');
745 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
749 localize_item($item);
753 foreach(explode(',',$item['tag']) as $tag){
755 if ($tag!="") $tags[] = bbcode($tag);
760 $body = prepare_body($item,true);
761 //$tmp_item = replace_macros($template,
763 // collapse comments in template. I don't like this much...
764 'comment_firstcollapsed' => $comment_firstcollapsed,
765 'comment_lastcollapsed' => $comment_lastcollapsed,
766 // template to use to render item (wall, walltowall, search)
767 'template' => $template,
769 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
771 'body' => template_escape($body),
772 'text' => strip_tags(template_escape($body)),
773 'id' => $item['item_id'],
774 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
775 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
777 'wall' => t('Wall-to-Wall'),
778 'vwall' => t('via Wall-To-Wall:'),
779 'profile_url' => $profile_link,
780 'item_photo_menu' => item_photo_menu($item),
781 'name' => template_escape($profile_name),
782 'thumb' => $profile_avatar,
783 'osparkle' => $osparkle,
784 'sparkle' => $sparkle,
785 'title' => template_escape($item['title']),
786 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
788 'location' => template_escape($location),
790 'owner_url' => $owner_url,
791 'owner_photo' => $owner_photo,
792 'owner_name' => template_escape($owner_name),
793 'plink' => get_plink($item),
795 'isstarred' => $isstarred,
799 'vote' => $likebuttons,
801 'dislike' => $dislike,
802 'comment' => $comment,
803 'previewing' => $previewing,
804 'wait' => t('Please wait'),
809 $arr = array('item' => $item, 'output' => $tmp_item);
810 call_hooks('display_item', $arr);
812 $threads[$threadsid]['items'][] = $arr['output'];
817 $page_template = get_markup_template("conversation.tpl");
818 $o = replace_macros($page_template, array(
819 '$baseurl' => $a->get_baseurl($ssl_state),
822 '$threads' => $threads,
823 '$dropping' => ($dropping?t('Delete Selected Items'):False),
829 function best_link_url($item,&$sparkle,$ssl_state = false) {
836 $clean_url = normalise_link($item['author-link']);
838 if((local_user()) && (local_user() == $item['uid'])) {
839 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
840 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
841 $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
845 $best_url = $a->contacts[$clean_url]['url'];
849 if(strlen($item['author-link']))
850 $best_url = $item['author-link'];
852 $best_url = $item['url'];
859 if(! function_exists('item_photo_menu')){
860 function item_photo_menu($item){
867 if(! count($a->contacts))
868 load_contact_links(local_user());
877 $profile_link = best_link_url($item,$sparkle,$ssl_state);
878 if($profile_link === 'mailbox')
882 $cid = intval(basename($profile_link));
883 $status_link = $profile_link . "?url=status";
884 $photos_link = $profile_link . "?url=photos";
885 $profile_link = $profile_link . "?url=profile";
886 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
890 $profile_link = zrl($profile_link);
891 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
892 $cid = $item['contact-id'];
898 if(($cid) && (! $item['self'])) {
899 $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
900 $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
902 $clean_url = normalise_link($item['author-link']);
904 if((local_user()) && (local_user() == $item['uid'])) {
905 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
906 if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
907 $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
915 t("View Status") => $status_link,
916 t("View Profile") => $profile_link,
917 t("View Photos") => $photos_link,
918 t("Network Posts") => $posts_link,
919 t("Edit Contact") => $contact_url,
920 t("Send PM") => $pm_url,
924 $args = array('item' => $item, 'menu' => $menu);
926 call_hooks('item_photo_menu', $args);
928 $menu = $args['menu'];
931 foreach($menu as $k=>$v){
932 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
937 if(! function_exists('like_puller')) {
938 function like_puller($a,$item,&$arr,$mode) {
942 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
944 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
945 $url = $item['author-link'];
946 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
947 $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
948 $sparkle = ' class="sparkle" ';
953 if(! $item['thr-parent'])
954 $item['thr-parent'] = $item['parent-uri'];
956 if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
957 $arr[$item['thr-parent'] . '-l'] = array();
958 if(! isset($arr[$item['thr-parent']]))
959 $arr[$item['thr-parent']] = 1;
961 $arr[$item['thr-parent']] ++;
962 $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
967 // Format the like/dislike text for a profile item
968 // $cnt = number of people who like/dislike the item
969 // $arr = array of pre-linked names of likers/dislikers
970 // $type = one of 'like, 'dislike'
972 // returns formatted text
974 if(! function_exists('format_like')) {
975 function format_like($cnt,$arr,$type,$id) {
978 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
980 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
981 $o .= (($type === 'like') ?
982 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
984 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
986 $total = count($arr);
987 if($total >= MAX_LIKERS)
988 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
989 if($total < MAX_LIKERS)
990 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
991 $str = implode(', ', $arr);
992 if($total >= MAX_LIKERS)
993 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
994 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
995 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
1001 function status_editor($a,$x, $notes_cid = 0, $popup=false) {
1005 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
1008 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
1011 $tpl = get_markup_template('jot-header.tpl');
1013 $a->page['htmlhead'] .= replace_macros($tpl, array(
1014 '$newpost' => 'true',
1015 '$baseurl' => $a->get_baseurl(true),
1016 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
1017 '$geotag' => $geotag,
1018 '$nickname' => $x['nickname'],
1019 '$ispublic' => t('Visible to <strong>everybody</strong>'),
1020 '$linkurl' => t('Please enter a link URL:'),
1021 '$vidurl' => t("Please enter a video link/URL:"),
1022 '$audurl' => t("Please enter an audio link/URL:"),
1023 '$term' => t('Tag term:'),
1024 '$fileas' => t('Save to Folder:'),
1025 '$whereareu' => t('Where are you right now?')
1029 $tpl = get_markup_template("jot.tpl");
1034 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
1036 $mail_enabled = false;
1037 $pubmail_enabled = false;
1039 if(($x['is_owner']) && (! $mail_disabled)) {
1040 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
1041 intval(local_user())
1044 $mail_enabled = true;
1045 if(intval($r[0]['pubmail']))
1046 $pubmail_enabled = true;
1051 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
1052 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
1055 call_hooks('jot_tool', $jotplugins);
1056 call_hooks('jot_networks', $jotnets);
1059 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
1061 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
1063 $o .= replace_macros($tpl,array(
1064 '$return_path' => $a->query_string,
1065 '$action' => $a->get_baseurl(true) . '/item',
1066 '$share' => (x($x,'button') ? $x['button'] : t('Share')),
1067 '$upload' => t('Upload photo'),
1068 '$shortupload' => t('upload photo'),
1069 '$attach' => t('Attach file'),
1070 '$shortattach' => t('attach file'),
1071 '$weblink' => t('Insert web link'),
1072 '$shortweblink' => t('web link'),
1073 '$video' => t('Insert video link'),
1074 '$shortvideo' => t('video link'),
1075 '$audio' => t('Insert audio link'),
1076 '$shortaudio' => t('audio link'),
1077 '$setloc' => t('Set your location'),
1078 '$shortsetloc' => t('set location'),
1079 '$noloc' => t('Clear browser location'),
1080 '$shortnoloc' => t('clear location'),
1082 '$placeholdertitle' => t('Set title'),
1084 '$placeholdercategory' => t('Categories (comma-separated list)'),
1085 '$wait' => t('Please wait'),
1086 '$permset' => t('Permission settings'),
1087 '$shortpermset' => t('permissions'),
1088 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
1091 '$baseurl' => $a->get_baseurl(true),
1092 '$defloc' => $x['default_location'],
1093 '$visitor' => $x['visitor'],
1094 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
1095 '$emailcc' => t('CC: email addresses'),
1096 '$public' => t('Public post'),
1097 '$jotnets' => $jotnets,
1098 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
1099 '$lockstate' => $x['lockstate'],
1100 '$acl' => $x['acl'],
1101 '$bang' => $x['bang'],
1102 '$profile_uid' => $x['profile_uid'],
1103 '$preview' => t('Preview'),
1108 $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
1116 function conv_sort($arr,$order) {
1118 if((!(is_array($arr) && count($arr))))
1124 if($x['id'] == $x['parent'])
1127 if(stristr($order,'created'))
1128 usort($parents,'sort_thr_created');
1129 elseif(stristr($order,'commented'))
1130 usort($parents,'sort_thr_commented');
1133 foreach($parents as $i=>$_x)
1134 $parents[$i]['children'] = array();
1136 foreach($arr as $x) {
1137 if($x['id'] != $x['parent']) {
1138 $p = find_thread_parent_index($parents,$x);
1140 $parents[$p]['children'][] = $x;
1143 if(count($parents)) {
1144 foreach($parents as $k => $v) {
1145 if(count($parents[$k]['children'])) {
1146 $y = $parents[$k]['children'];
1147 usort($y,'sort_thr_created_rev');
1148 $parents[$k]['children'] = $y;
1154 if(count($parents)) {
1155 foreach($parents as $x) {
1157 if(count($x['children']))
1158 foreach($x['children'] as $y)
1167 function sort_thr_created($a,$b) {
1168 return strcmp($b['created'],$a['created']);
1171 function sort_thr_created_rev($a,$b) {
1172 return strcmp($a['created'],$b['created']);
1175 function sort_thr_commented($a,$b) {
1176 return strcmp($b['commented'],$a['commented']);
1179 function find_thread_parent_index($arr,$x) {
1180 foreach($arr as $k => $v)
1181 if($v['id'] == $x['parent'])
1186 function render_location_google($item) {
1187 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
1188 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
1191 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
1193 $location = '<span class="smalltext">' . $coord . '</span>';