4 * Render actions localized
6 function localize_item(&$item){
8 if ($item['verb']=="http://activitystrea.ms/schema/1.0/like" ||
9 $item['verb']=="http://activitystrea.ms/schema/1.0/dislike"){
11 $r = q("SELECT * from `item`,`contact` WHERE
12 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
13 dbesc($item['parent-uri']));
14 if(count($r)==0) return;
17 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
18 $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
20 $post_type = (($obj['resource-id']) ? t('photo') : t('status'));
21 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
23 switch($item['verb']){
24 case "http://activitystrea.ms/schema/1.0/like":
25 $bodyverb = t('%1$s likes %2$s\'s %3$s');
27 case "http://activitystrea.ms/schema/1.0/dislike":
28 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
31 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
34 if ($item['verb']=='http://activitystrea.ms/schema/1.0/make-friend'){
36 if ($item['object-type']=="" || $item['object-type']!='http://activitystrea.ms/schema/1.0/person') return;
38 $Aname = $item['author-name'];
39 $Alink = $item['author-link'];
41 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
43 $obj = parse_xml_string($xmlhead.$item['object']);
44 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
47 $Blink = ""; $Bphoto = "";
48 foreach ($links->link as $l){
49 $atts = $l->attributes();
51 case "alternate": $Blink = $atts['href'];
52 case "photo": $Bphoto = $atts['href'];
57 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
58 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
59 if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
61 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
68 * "Render" a conversation or list of items for HTML display.
69 * There are two major forms of display:
70 * - Sequential or unthreaded ("New Item View" or search results)
72 * The $mode parameter decides between the various renderings and also
73 * figures out how to determine page owner and other contextual items
74 * that are based on unique features of the calling module.
77 function conversation(&$a, $items, $mode, $update) {
79 require_once('bbcode.php');
82 $page_writeable = false;
84 if($mode === 'network') {
85 $profile_owner = local_user();
86 $page_writeable = true;
89 if($mode === 'profile') {
90 $profile_owner = $a->profile['profile_uid'];
91 $page_writeable = can_write_wall($a,$profile_owner);
94 if($mode === 'display') {
95 $profile_owner = $a->profile['uid'];
96 $page_writeable = can_write_wall($a,$profile_owner);
100 $return_url = $_SESSION['return_url'];
102 $return_url = $_SESSION['return_url'] = $a->cmd;
104 load_contact_links(local_user());
107 $cmnt_tpl = load_view_file('view/comment_item.tpl');
108 $like_tpl = load_view_file('view/like.tpl');
109 $noshare_tpl = load_view_file('view/like_noshare.tpl');
110 $tpl = load_view_file('view/wall_item.tpl');
111 $wallwall = load_view_file('view/wallwall_item.tpl');
118 if($mode === 'network-new' || $mode === 'search') {
120 // "New Item View" on network page or search page results
121 // - just loop through the items and format them minimally for display
123 $tpl = load_view_file('view/search_item.tpl');
124 $droptpl = load_view_file('view/wall_fake_drop.tpl');
126 foreach($items as $item) {
134 if($mode === 'search') {
135 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
136 && ($item['id'] != $item['parent']))
138 $nickname = $item['nickname'];
141 $nickname = $a->user['nickname'];
143 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
144 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
147 $profile_link = best_link_url($item,$sp);
149 $sparkle = ' sparkle';
150 if($profile_link === 'mailbox')
154 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
155 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
158 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
160 $location = '<span class="smalltext">' . $coord . '</span>';
166 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
169 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
172 localize_item($item);
174 $drop = replace_macros($droptpl,array('$id' => $item['id']));
175 $lock = '<div class="wall-item-lock"></div>';
177 $o .= replace_macros($tpl,array(
178 '$id' => $item['item_id'],
179 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
180 '$profile_url' => $profile_link,
181 '$item_photo_menu' => item_photo_menu($item),
182 '$name' => $profile_name,
183 '$sparkle' => $sparkle,
185 '$thumb' => $profile_avatar,
186 '$title' => $item['title'],
187 '$body' => smilies(bbcode($item['body'])),
188 '$ago' => relative_date($item['created']),
189 '$location' => $location,
191 '$owner_url' => $owner_url,
192 '$owner_photo' => $owner_photo,
193 '$owner_name' => $owner_name,
195 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
209 // Figure out how many comments each parent has
210 // (Comments all have gravity of 6)
211 // Store the result in the $comments array
214 foreach($items as $item) {
215 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
216 if(! x($comments,$item['parent']))
217 $comments[$item['parent']] = 1;
219 $comments[$item['parent']] += 1;
223 // map all the like/dislike activities for each parent item
224 // Store these in the $alike and $dlike arrays
226 foreach($items as $item) {
227 like_puller($a,$item,$alike,'like');
228 like_puller($a,$item,$dlike,'dislike');
231 $comments_collapsed = false;
235 foreach($items as $item) {
241 $owner_url = $owner_photo = $owner_name = '';
243 // We've already parsed out like/dislike for special treatment. We can ignore them now
245 if(((activity_match($item['verb'],ACTIVITY_LIKE))
246 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
247 && ($item['id'] != $item['parent']))
250 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
253 // Take care of author collapsing and comment collapsing
254 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
255 // If there are more than two comments, squash all but the last 2.
259 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
261 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
263 if($blowhard_count == 3) {
264 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
265 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >'
266 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
267 . $item['parent'] . '" style="display: none;" >';
271 $blowhard = $item['cid'];
272 if($blowhard_count >= 3)
278 $comments_collapsed = false;
284 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
285 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
287 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
288 if(! $comments_collapsed) {
289 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
290 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >'
291 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
292 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
293 $comments_collapsed = true;
296 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
300 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
302 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
303 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
304 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
305 : '<div class="wall-item-lock"></div>');
308 // Top-level wall post not written by the wall owner (wall-to-wall)
309 // First figure out who owns it.
313 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
315 if($item['type'] === 'wall') {
317 // On the network page, I am the owner. On the display page it will be the profile owner.
318 // This will have been stored in $a->page_contact by our calling page.
319 // Put this person on the left of the wall-to-wall notice.
321 $owner_url = $a->page_contact['url'];
322 $owner_photo = $a->page_contact['thumb'];
323 $owner_name = $a->page_contact['name'];
324 $template = $wallwall;
327 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
331 $owner_url = $item['owner-link'];
332 $owner_photo = $item['owner-avatar'];
333 $owner_name = $item['owner-name'];
334 $template = $wallwall;
336 // If it is our contact, use a friendly redirect link
337 if((link_compare($item['owner-link'],$item['url']))
338 && ($item['network'] === 'dfrn')) {
339 $owner_url = $redirect_url;
340 $osparkle = ' sparkle';
348 if($page_writeable) {
350 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
351 '$id' => $item['id'],
352 '$likethis' => t("I like this \x28toggle\x29"),
353 '$nolike' => t("I don't like this \x28toggle\x29"),
354 '$share' => t('Share'),
355 '$wait' => t('Please wait')
359 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
360 $comment = replace_macros($cmnt_tpl,array(
361 '$return_path' => '',
362 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
363 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
364 '$id' => $item['item_id'],
365 '$parent' => $item['parent'],
366 '$profile_uid' => $profile_owner,
367 '$mylink' => $a->contact['url'],
368 '$mytitle' => t('This is you'),
369 '$myphoto' => $a->contact['thumb'],
370 '$comment' => t('Comment'),
371 '$submit' => t('Submit'),
372 '$ww' => (($mode === 'network') ? $commentww : '')
377 $edpost = ((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1))
378 ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
379 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
381 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
383 $photo = $item['photo'];
384 $thumb = $item['thumb'];
386 // Post was remotely authored.
388 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
390 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
391 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
394 $profile_link = best_link_url($item,$sp);
396 $sparkle = ' sparkle';
398 if($profile_link === 'mailbox')
402 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
403 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
405 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
406 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
407 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
408 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
411 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
413 $location = '<span class="smalltext">' . $coord . '</span>';
416 $indent = (($toplevelpost) ? '' : ' comment');
418 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
422 localize_item($item);
426 $tmp_item = replace_macros($template,array(
427 '$id' => $item['item_id'],
428 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
429 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
431 '$wall' => t('Wall-to-Wall'),
432 '$vwall' => t('via Wall-To-Wall:'),
433 '$profile_url' => $profile_link,
434 '$item_photo_menu' => item_photo_menu($item),
435 '$name' => $profile_name,
436 '$thumb' => $profile_avatar,
437 '$osparkle' => $osparkle,
438 '$sparkle' => $sparkle,
439 '$title' => $item['title'],
440 '$body' => smilies(bbcode($item['body'])),
441 '$ago' => relative_date($item['created']),
443 '$location' => $location,
444 '$indent' => $indent,
445 '$owner_url' => $owner_url,
446 '$owner_photo' => $owner_photo,
447 '$owner_name' => $owner_name,
448 '$plink' => get_plink($item),
449 '$edpost' => $edpost,
451 '$vote' => $likebuttons,
453 '$dislike' => $dislike,
454 '$comment' => $comment
457 $arr = array('item' => $item, 'output' => $tmp_item);
458 call_hooks('display_item', $arr);
460 $o .= $arr['output'];
466 // if author collapsing is in force but didn't get closed, close it off now.
468 if($blowhard_count >= 3)
475 if(! function_exists('load_contact_links')) {
476 function load_contact_links($uid) {
482 if(! $uid || x($a->contacts,'empty'))
485 $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
490 $url = normalise_link($rr['url']);
495 $ret['empty'] = true;
501 function best_link_url($item,&$sparkle) {
508 $clean_url = normalise_link($item['author-link']);
510 if((local_user()) && (local_user() == $item['uid'])) {
511 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
512 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
513 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
517 $best_url = $a->contacts[$clean_url]['url'];
521 if(strlen($item['author-link']))
522 $best_url = $item['author-link'];
524 $best_url = $item['url'];
531 if(! function_exists('item_photo_menu')){
532 function item_photo_menu($item){
535 if (local_user() && (! count($a->contacts)))
536 load_contact_links(local_user());
545 $profile_link = best_link_url($item,$sparkle);
546 if($profile_link === 'mailbox')
550 $cid = intval(basename($profile_link));
551 $status_link = $profile_link . "?url=status";
552 $photos_link = $profile_link . "?url=photos";
553 $profile_link = $profile_link . "?url=profile";
554 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
557 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
558 $cid = $item['contact-id'];
564 if(($cid) && (! $item['self'])) {
565 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
566 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
570 t("View status") => $status_link,
571 t("View profile") => $profile_link,
572 t("View photos") => $photos_link,
573 t("View recent") => $posts_link,
574 t("Edit contact") => $contact_url,
575 t("Send PM") => $pm_url,
579 $args = array($item, &$menu);
581 call_hooks('item_photo_menu', $args);
584 foreach($menu as $k=>$v){
585 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
590 if(! function_exists('like_puller')) {
591 function like_puller($a,$item,&$arr,$mode) {
595 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
597 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
598 $url = $item['author-link'];
599 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
600 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
601 $sparkle = ' class="sparkle" ';
603 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
604 $arr[$item['parent'] . '-l'] = array();
605 if(! isset($arr[$item['parent']]))
606 $arr[$item['parent']] = 1;
608 $arr[$item['parent']] ++;
609 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
614 // Format the like/dislike text for a profile item
615 // $cnt = number of people who like/dislike the item
616 // $arr = array of pre-linked names of likers/dislikers
617 // $type = one of 'like, 'dislike'
619 // returns formatted text
621 if(! function_exists('format_like')) {
622 function format_like($cnt,$arr,$type,$id) {
625 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
627 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
628 $o .= (($type === 'like') ?
629 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
631 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
633 $total = count($arr);
634 if($total >= MAX_LIKERS)
635 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
636 if($total < MAX_LIKERS)
637 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
638 $str = implode(', ', $arr);
639 if($total >= MAX_LIKERS)
640 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
641 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
642 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
648 function status_editor($a,$x) {
652 $geotag = (($x['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
654 $tpl = load_view_file('view/jot-header.tpl');
656 $a->page['htmlhead'] .= replace_macros($tpl, array(
657 '$baseurl' => $a->get_baseurl(),
658 '$geotag' => $geotag,
659 '$nickname' => $x['nickname'],
660 '$ispublic' => t('Visible to <strong>everybody</strong>'),
661 '$linkurl' => t('Please enter a link URL:'),
662 '$utubeurl' => t('Please enter a YouTube link:'),
663 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
664 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
665 '$whereareu' => t('Where are you right now?'),
666 '$title' => t('Enter a title for this item')
670 $tpl = load_view_file("view/jot.tpl");
675 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
677 $mail_enabled = false;
678 $pubmail_enabled = false;
680 if(($x['is_owner']) && (! $mail_disabled)) {
681 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
685 $mail_enabled = true;
686 if(intval($r[0]['pubmail']))
687 $pubmail_enabled = true;
692 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
693 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
694 . t("Post to Email") . '</div>';
697 call_hooks('jot_tool', $jotplugins);
698 call_hooks('jot_networks', $jotnets);
700 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
702 $o .= replace_macros($tpl,array(
703 '$return_path' => $a->cmd,
705 '$share' => t('Share'),
706 '$upload' => t('Upload photo'),
707 '$weblink' => t('Insert web link'),
708 '$youtube' => t('Insert YouTube video'),
709 '$video' => t('Insert Vorbis [.ogg] video'),
710 '$audio' => t('Insert Vorbis [.ogg] audio'),
711 '$setloc' => t('Set your location'),
712 '$noloc' => t('Clear browser location'),
713 '$title' => t('Set title'),
714 '$wait' => t('Please wait'),
715 '$permset' => t('Permission settings'),
718 '$baseurl' => $a->get_baseurl(),
719 '$defloc' => $x['default_location'],
720 '$visitor' => $x['visitor'],
721 '$emailcc' => t('CC: email addresses'),
722 '$jotnets' => $jotnets,
723 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
724 '$lockstate' => $x['lockstate'],
726 '$bang' => $x['bang'],
727 '$profile_uid' => $x['profile_uid'],