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 === 'notes') {
95 $profile_owner = $a->profile['profile_uid'];
96 $page_writeable = true;
99 if($mode === 'display') {
100 $profile_owner = $a->profile['uid'];
101 $page_writeable = can_write_wall($a,$profile_owner);
105 $return_url = $_SESSION['return_url'];
107 $return_url = $_SESSION['return_url'] = $a->cmd;
109 load_contact_links(local_user());
112 $cmnt_tpl = get_markup_template('comment_item.tpl');
113 $like_tpl = get_markup_template('like.tpl');
114 $noshare_tpl = get_markup_template('like_noshare.tpl');
115 $tpl = get_markup_template('wall_item.tpl');
116 $wallwall = get_markup_template('wallwall_item.tpl');
123 if($mode === 'network-new' || $mode === 'search') {
125 // "New Item View" on network page or search page results
126 // - just loop through the items and format them minimally for display
128 $tpl = get_markup_template('search_item.tpl');
129 $droptpl = get_markup_template('wall_fake_drop.tpl');
131 foreach($items as $item) {
139 if($mode === 'search') {
140 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
141 && ($item['id'] != $item['parent']))
143 $nickname = $item['nickname'];
146 $nickname = $a->user['nickname'];
148 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
151 $profile_link = best_link_url($item,$sp);
153 $sparkle = ' sparkle';
154 if($profile_link === 'mailbox')
158 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
159 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
160 $profile_avatar = $a->contacts[$normalised]['thumb'];
162 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
164 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
165 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
168 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
170 $location = '<span class="smalltext">' . $coord . '</span>';
176 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
179 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
182 localize_item($item);
184 $drop = replace_macros($droptpl,array('$id' => $item['id']));
185 $lock = '<div class="wall-item-lock"></div>';
187 $o .= replace_macros($tpl,array(
188 '$id' => $item['item_id'],
189 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
190 '$profile_url' => $profile_link,
191 '$item_photo_menu' => item_photo_menu($item),
192 '$name' => $profile_name,
193 '$sparkle' => $sparkle,
195 '$thumb' => $profile_avatar,
196 '$title' => $item['title'],
197 '$body' => smilies(bbcode($item['body'])),
198 '$ago' => relative_date($item['created']),
199 '$location' => $location,
201 '$owner_url' => $owner_url,
202 '$owner_photo' => $owner_photo,
203 '$owner_name' => $owner_name,
205 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
219 // Figure out how many comments each parent has
220 // (Comments all have gravity of 6)
221 // Store the result in the $comments array
224 foreach($items as $item) {
225 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
226 if(! x($comments,$item['parent']))
227 $comments[$item['parent']] = 1;
229 $comments[$item['parent']] += 1;
233 // map all the like/dislike activities for each parent item
234 // Store these in the $alike and $dlike arrays
236 foreach($items as $item) {
237 like_puller($a,$item,$alike,'like');
238 like_puller($a,$item,$dlike,'dislike');
241 $comments_collapsed = false;
245 foreach($items as $item) {
251 $owner_url = $owner_photo = $owner_name = '';
253 // We've already parsed out like/dislike for special treatment. We can ignore them now
255 if(((activity_match($item['verb'],ACTIVITY_LIKE))
256 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
257 && ($item['id'] != $item['parent']))
260 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
263 // Take care of author collapsing and comment collapsing
264 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
265 // If there are more than two comments, squash all but the last 2.
269 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
271 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
273 if($blowhard_count == 3) {
274 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
275 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
276 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
277 . $item['parent'] . '" style="display: none;" >';
281 $blowhard = $item['cid'];
282 if($blowhard_count >= 3)
288 $comments_collapsed = false;
294 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
295 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
297 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
298 if(! $comments_collapsed) {
299 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
300 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >'
301 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
302 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
303 $comments_collapsed = true;
306 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
310 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
312 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
313 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
314 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
315 : '<div class="wall-item-lock"></div>');
318 // Top-level wall post not written by the wall owner (wall-to-wall)
319 // First figure out who owns it.
323 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
325 if($item['type'] === 'wall') {
327 // On the network page, I am the owner. On the display page it will be the profile owner.
328 // This will have been stored in $a->page_contact by our calling page.
329 // Put this person on the left of the wall-to-wall notice.
331 $owner_url = $a->page_contact['url'];
332 $owner_photo = $a->page_contact['thumb'];
333 $owner_name = $a->page_contact['name'];
334 $template = $wallwall;
337 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
341 $owner_url = $item['owner-link'];
342 $owner_photo = $item['owner-avatar'];
343 $owner_name = $item['owner-name'];
344 $template = $wallwall;
346 // If it is our contact, use a friendly redirect link
347 if((link_compare($item['owner-link'],$item['url']))
348 && ($item['network'] === 'dfrn')) {
349 $owner_url = $redirect_url;
350 $osparkle = ' sparkle';
358 if($page_writeable) {
360 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
361 '$id' => $item['id'],
362 '$likethis' => t("I like this \x28toggle\x29"),
363 '$nolike' => t("I don't like this \x28toggle\x29"),
364 '$share' => t('Share'),
365 '$wait' => t('Please wait')
369 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
370 $comment = replace_macros($cmnt_tpl,array(
371 '$return_path' => '',
372 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
373 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
374 '$id' => $item['item_id'],
375 '$parent' => $item['parent'],
376 '$profile_uid' => $profile_owner,
377 '$mylink' => $a->contact['url'],
378 '$mytitle' => t('This is you'),
379 '$myphoto' => $a->contact['thumb'],
380 '$comment' => t('Comment'),
381 '$submit' => t('Submit'),
382 '$ww' => (($mode === 'network') ? $commentww : '')
387 $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
388 ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
389 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
391 $drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
393 $photo = $item['photo'];
394 $thumb = $item['thumb'];
396 // Post was remotely authored.
398 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
400 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
403 $profile_link = best_link_url($item,$sp);
405 $sparkle = ' sparkle';
407 if($profile_link === 'mailbox')
410 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
411 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
412 $profile_avatar = $a->contacts[$normalised]['thumb'];
414 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
420 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
421 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
423 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
424 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
425 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
426 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
429 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
431 $location = '<span class="smalltext">' . $coord . '</span>';
434 $indent = (($toplevelpost) ? '' : ' comment');
436 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
440 localize_item($item);
444 $tmp_item = replace_macros($template,array(
445 '$id' => $item['item_id'],
446 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
447 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
449 '$wall' => t('Wall-to-Wall'),
450 '$vwall' => t('via Wall-To-Wall:'),
451 '$profile_url' => $profile_link,
452 '$item_photo_menu' => item_photo_menu($item),
453 '$name' => $profile_name,
454 '$thumb' => $profile_avatar,
455 '$osparkle' => $osparkle,
456 '$sparkle' => $sparkle,
457 '$title' => $item['title'],
458 '$body' => smilies(bbcode($item['body'])),
459 '$ago' => relative_date($item['created']),
461 '$location' => $location,
462 '$indent' => $indent,
463 '$owner_url' => $owner_url,
464 '$owner_photo' => $owner_photo,
465 '$owner_name' => $owner_name,
466 '$plink' => get_plink($item),
467 '$edpost' => $edpost,
469 '$vote' => $likebuttons,
471 '$dislike' => $dislike,
472 '$comment' => $comment
475 $arr = array('item' => $item, 'output' => $tmp_item);
476 call_hooks('display_item', $arr);
478 $o .= $arr['output'];
484 // if author collapsing is in force but didn't get closed, close it off now.
486 if($blowhard_count >= 3)
493 if(! function_exists('load_contact_links')) {
494 function load_contact_links($uid) {
500 if(! $uid || x($a->contacts,'empty'))
503 $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
508 $url = normalise_link($rr['url']);
513 $ret['empty'] = true;
519 function best_link_url($item,&$sparkle) {
526 $clean_url = normalise_link($item['author-link']);
528 if((local_user()) && (local_user() == $item['uid'])) {
529 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
530 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
531 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
535 $best_url = $a->contacts[$clean_url]['url'];
539 if(strlen($item['author-link']))
540 $best_url = $item['author-link'];
542 $best_url = $item['url'];
549 if(! function_exists('item_photo_menu')){
550 function item_photo_menu($item){
553 if (local_user() && (! count($a->contacts)))
554 load_contact_links(local_user());
563 $profile_link = best_link_url($item,$sparkle);
564 if($profile_link === 'mailbox')
568 $cid = intval(basename($profile_link));
569 $status_link = $profile_link . "?url=status";
570 $photos_link = $profile_link . "?url=photos";
571 $profile_link = $profile_link . "?url=profile";
572 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
575 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
576 $cid = $item['contact-id'];
582 if(($cid) && (! $item['self'])) {
583 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
584 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
588 t("View status") => $status_link,
589 t("View profile") => $profile_link,
590 t("View photos") => $photos_link,
591 t("View recent") => $posts_link,
592 t("Edit contact") => $contact_url,
593 t("Send PM") => $pm_url,
597 $args = array($item, &$menu);
599 call_hooks('item_photo_menu', $args);
602 foreach($menu as $k=>$v){
603 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
608 if(! function_exists('like_puller')) {
609 function like_puller($a,$item,&$arr,$mode) {
613 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
615 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
616 $url = $item['author-link'];
617 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
618 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
619 $sparkle = ' class="sparkle" ';
621 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
622 $arr[$item['parent'] . '-l'] = array();
623 if(! isset($arr[$item['parent']]))
624 $arr[$item['parent']] = 1;
626 $arr[$item['parent']] ++;
627 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
632 // Format the like/dislike text for a profile item
633 // $cnt = number of people who like/dislike the item
634 // $arr = array of pre-linked names of likers/dislikers
635 // $type = one of 'like, 'dislike'
637 // returns formatted text
639 if(! function_exists('format_like')) {
640 function format_like($cnt,$arr,$type,$id) {
643 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
645 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
646 $o .= (($type === 'like') ?
647 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
649 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
651 $total = count($arr);
652 if($total >= MAX_LIKERS)
653 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
654 if($total < MAX_LIKERS)
655 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
656 $str = implode(', ', $arr);
657 if($total >= MAX_LIKERS)
658 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
659 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
660 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
666 function status_editor($a,$x, $notes_cid = 0) {
670 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
672 $tpl = get_markup_template('jot-header.tpl');
674 $a->page['htmlhead'] .= replace_macros($tpl, array(
675 '$baseurl' => $a->get_baseurl(),
676 '$geotag' => $geotag,
677 '$nickname' => $x['nickname'],
678 '$ispublic' => t('Visible to <strong>everybody</strong>'),
679 '$linkurl' => t('Please enter a link URL:'),
680 '$utubeurl' => t('Please enter a YouTube link:'),
681 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
682 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
683 '$whereareu' => t('Where are you right now?'),
684 '$title' => t('Enter a title for this item')
688 $tpl = get_markup_template("jot.tpl");
693 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
695 $mail_enabled = false;
696 $pubmail_enabled = false;
698 if(($x['is_owner']) && (! $mail_disabled)) {
699 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
703 $mail_enabled = true;
704 if(intval($r[0]['pubmail']))
705 $pubmail_enabled = true;
710 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
711 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
712 . t("Post to Email") . '</div>';
715 call_hooks('jot_tool', $jotplugins);
716 call_hooks('jot_networks', $jotnets);
719 $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
721 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
723 $o .= replace_macros($tpl,array(
724 '$return_path' => $a->cmd,
726 '$share' => (($x['button']) ? $x['button'] : t('Share')),
727 '$upload' => t('Upload photo'),
728 '$weblink' => t('Insert web link'),
729 '$youtube' => t('Insert YouTube video'),
730 '$video' => t('Insert Vorbis [.ogg] video'),
731 '$audio' => t('Insert Vorbis [.ogg] audio'),
732 '$setloc' => t('Set your location'),
733 '$noloc' => t('Clear browser location'),
734 '$title' => t('Set title'),
735 '$wait' => t('Please wait'),
736 '$permset' => t('Permission settings'),
737 '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
740 '$baseurl' => $a->get_baseurl(),
741 '$defloc' => $x['default_location'],
742 '$visitor' => $x['visitor'],
743 '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
744 '$emailcc' => t('CC: email addresses'),
745 '$public' => t('Public post'),
746 '$jotnets' => $jotnets,
747 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
748 '$lockstate' => $x['lockstate'],
750 '$bang' => $x['bang'],
751 '$profile_uid' => $x['profile_uid'],