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 = get_markup_template('comment_item.tpl');
108 $like_tpl = get_markup_template('like.tpl');
109 $noshare_tpl = get_markup_template('like_noshare.tpl');
110 $tpl = get_markup_template('wall_item.tpl');
111 $wallwall = get_markup_template('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 = get_markup_template('search_item.tpl');
124 $droptpl = get_markup_template('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']);
146 $profile_link = best_link_url($item,$sp);
148 $sparkle = ' sparkle';
149 if($profile_link === 'mailbox')
153 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
154 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
155 $profile_avatar = $a->contacts[$normalised]['thumb'];
157 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
159 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
160 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
163 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
165 $location = '<span class="smalltext">' . $coord . '</span>';
171 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
174 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
177 localize_item($item);
179 $drop = replace_macros($droptpl,array('$id' => $item['id']));
180 $lock = '<div class="wall-item-lock"></div>';
182 $o .= replace_macros($tpl,array(
183 '$id' => $item['item_id'],
184 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
185 '$profile_url' => $profile_link,
186 '$item_photo_menu' => item_photo_menu($item),
187 '$name' => $profile_name,
188 '$sparkle' => $sparkle,
190 '$thumb' => $profile_avatar,
191 '$title' => $item['title'],
192 '$body' => smilies(bbcode($item['body'])),
193 '$ago' => relative_date($item['created']),
194 '$location' => $location,
196 '$owner_url' => $owner_url,
197 '$owner_photo' => $owner_photo,
198 '$owner_name' => $owner_name,
200 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
214 // Figure out how many comments each parent has
215 // (Comments all have gravity of 6)
216 // Store the result in the $comments array
219 foreach($items as $item) {
220 if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
221 if(! x($comments,$item['parent']))
222 $comments[$item['parent']] = 1;
224 $comments[$item['parent']] += 1;
228 // map all the like/dislike activities for each parent item
229 // Store these in the $alike and $dlike arrays
231 foreach($items as $item) {
232 like_puller($a,$item,$alike,'like');
233 like_puller($a,$item,$dlike,'dislike');
236 $comments_collapsed = false;
240 foreach($items as $item) {
246 $owner_url = $owner_photo = $owner_name = '';
248 // We've already parsed out like/dislike for special treatment. We can ignore them now
250 if(((activity_match($item['verb'],ACTIVITY_LIKE))
251 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
252 && ($item['id'] != $item['parent']))
255 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
258 // Take care of author collapsing and comment collapsing
259 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
260 // If there are more than two comments, squash all but the last 2.
264 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
266 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
268 if($blowhard_count == 3) {
269 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
270 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
271 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
272 . $item['parent'] . '" style="display: none;" >';
276 $blowhard = $item['cid'];
277 if($blowhard_count >= 3)
283 $comments_collapsed = false;
289 $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
290 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
292 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
293 if(! $comments_collapsed) {
294 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
295 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >'
296 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
297 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
298 $comments_collapsed = true;
301 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
305 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
307 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
308 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
309 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
310 : '<div class="wall-item-lock"></div>');
313 // Top-level wall post not written by the wall owner (wall-to-wall)
314 // First figure out who owns it.
318 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
320 if($item['type'] === 'wall') {
322 // On the network page, I am the owner. On the display page it will be the profile owner.
323 // This will have been stored in $a->page_contact by our calling page.
324 // Put this person on the left of the wall-to-wall notice.
326 $owner_url = $a->page_contact['url'];
327 $owner_photo = $a->page_contact['thumb'];
328 $owner_name = $a->page_contact['name'];
329 $template = $wallwall;
332 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
336 $owner_url = $item['owner-link'];
337 $owner_photo = $item['owner-avatar'];
338 $owner_name = $item['owner-name'];
339 $template = $wallwall;
341 // If it is our contact, use a friendly redirect link
342 if((link_compare($item['owner-link'],$item['url']))
343 && ($item['network'] === 'dfrn')) {
344 $owner_url = $redirect_url;
345 $osparkle = ' sparkle';
353 if($page_writeable) {
355 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
356 '$id' => $item['id'],
357 '$likethis' => t("I like this \x28toggle\x29"),
358 '$nolike' => t("I don't like this \x28toggle\x29"),
359 '$share' => t('Share'),
360 '$wait' => t('Please wait')
364 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
365 $comment = replace_macros($cmnt_tpl,array(
366 '$return_path' => '',
367 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
368 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
369 '$id' => $item['item_id'],
370 '$parent' => $item['parent'],
371 '$profile_uid' => $profile_owner,
372 '$mylink' => $a->contact['url'],
373 '$mytitle' => t('This is you'),
374 '$myphoto' => $a->contact['thumb'],
375 '$comment' => t('Comment'),
376 '$submit' => t('Submit'),
377 '$ww' => (($mode === 'network') ? $commentww : '')
382 $edpost = ((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1))
383 ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
384 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
386 $drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
388 $photo = $item['photo'];
389 $thumb = $item['thumb'];
391 // Post was remotely authored.
393 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
395 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
398 $profile_link = best_link_url($item,$sp);
400 $sparkle = ' sparkle';
402 if($profile_link === 'mailbox')
405 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
406 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
407 $profile_avatar = $a->contacts[$normalised]['thumb'];
409 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
415 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
416 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
418 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
419 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
420 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
421 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
424 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
426 $location = '<span class="smalltext">' . $coord . '</span>';
429 $indent = (($toplevelpost) ? '' : ' comment');
431 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
435 localize_item($item);
439 $tmp_item = replace_macros($template,array(
440 '$id' => $item['item_id'],
441 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
442 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
444 '$wall' => t('Wall-to-Wall'),
445 '$vwall' => t('via Wall-To-Wall:'),
446 '$profile_url' => $profile_link,
447 '$item_photo_menu' => item_photo_menu($item),
448 '$name' => $profile_name,
449 '$thumb' => $profile_avatar,
450 '$osparkle' => $osparkle,
451 '$sparkle' => $sparkle,
452 '$title' => $item['title'],
453 '$body' => smilies(bbcode($item['body'])),
454 '$ago' => relative_date($item['created']),
456 '$location' => $location,
457 '$indent' => $indent,
458 '$owner_url' => $owner_url,
459 '$owner_photo' => $owner_photo,
460 '$owner_name' => $owner_name,
461 '$plink' => get_plink($item),
462 '$edpost' => $edpost,
464 '$vote' => $likebuttons,
466 '$dislike' => $dislike,
467 '$comment' => $comment
470 $arr = array('item' => $item, 'output' => $tmp_item);
471 call_hooks('display_item', $arr);
473 $o .= $arr['output'];
479 // if author collapsing is in force but didn't get closed, close it off now.
481 if($blowhard_count >= 3)
488 if(! function_exists('load_contact_links')) {
489 function load_contact_links($uid) {
495 if(! $uid || x($a->contacts,'empty'))
498 $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
503 $url = normalise_link($rr['url']);
508 $ret['empty'] = true;
514 function best_link_url($item,&$sparkle) {
521 $clean_url = normalise_link($item['author-link']);
523 if((local_user()) && (local_user() == $item['uid'])) {
524 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
525 if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
526 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
530 $best_url = $a->contacts[$clean_url]['url'];
534 if(strlen($item['author-link']))
535 $best_url = $item['author-link'];
537 $best_url = $item['url'];
544 if(! function_exists('item_photo_menu')){
545 function item_photo_menu($item){
548 if (local_user() && (! count($a->contacts)))
549 load_contact_links(local_user());
558 $profile_link = best_link_url($item,$sparkle);
559 if($profile_link === 'mailbox')
563 $cid = intval(basename($profile_link));
564 $status_link = $profile_link . "?url=status";
565 $photos_link = $profile_link . "?url=photos";
566 $profile_link = $profile_link . "?url=profile";
567 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
570 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
571 $cid = $item['contact-id'];
577 if(($cid) && (! $item['self'])) {
578 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
579 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
583 t("View status") => $status_link,
584 t("View profile") => $profile_link,
585 t("View photos") => $photos_link,
586 t("View recent") => $posts_link,
587 t("Edit contact") => $contact_url,
588 t("Send PM") => $pm_url,
592 $args = array($item, &$menu);
594 call_hooks('item_photo_menu', $args);
597 foreach($menu as $k=>$v){
598 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
603 if(! function_exists('like_puller')) {
604 function like_puller($a,$item,&$arr,$mode) {
608 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
610 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
611 $url = $item['author-link'];
612 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
613 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
614 $sparkle = ' class="sparkle" ';
616 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
617 $arr[$item['parent'] . '-l'] = array();
618 if(! isset($arr[$item['parent']]))
619 $arr[$item['parent']] = 1;
621 $arr[$item['parent']] ++;
622 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
627 // Format the like/dislike text for a profile item
628 // $cnt = number of people who like/dislike the item
629 // $arr = array of pre-linked names of likers/dislikers
630 // $type = one of 'like, 'dislike'
632 // returns formatted text
634 if(! function_exists('format_like')) {
635 function format_like($cnt,$arr,$type,$id) {
638 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
640 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
641 $o .= (($type === 'like') ?
642 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
644 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
646 $total = count($arr);
647 if($total >= MAX_LIKERS)
648 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
649 if($total < MAX_LIKERS)
650 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
651 $str = implode(', ', $arr);
652 if($total >= MAX_LIKERS)
653 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
654 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
655 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
661 function status_editor($a,$x) {
665 $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
667 $tpl = get_markup_template('jot-header.tpl');
669 $a->page['htmlhead'] .= replace_macros($tpl, array(
670 '$baseurl' => $a->get_baseurl(),
671 '$geotag' => $geotag,
672 '$nickname' => $x['nickname'],
673 '$ispublic' => t('Visible to <strong>everybody</strong>'),
674 '$linkurl' => t('Please enter a link URL:'),
675 '$utubeurl' => t('Please enter a YouTube link:'),
676 '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
677 '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
678 '$whereareu' => t('Where are you right now?'),
679 '$title' => t('Enter a title for this item')
683 $tpl = get_markup_template("jot.tpl");
688 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
690 $mail_enabled = false;
691 $pubmail_enabled = false;
693 if(($x['is_owner']) && (! $mail_disabled)) {
694 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
698 $mail_enabled = true;
699 if(intval($r[0]['pubmail']))
700 $pubmail_enabled = true;
705 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
706 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
707 . t("Post to Email") . '</div>';
710 call_hooks('jot_tool', $jotplugins);
711 call_hooks('jot_networks', $jotnets);
713 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
715 $o .= replace_macros($tpl,array(
716 '$return_path' => $a->cmd,
718 '$share' => t('Share'),
719 '$upload' => t('Upload photo'),
720 '$weblink' => t('Insert web link'),
721 '$youtube' => t('Insert YouTube video'),
722 '$video' => t('Insert Vorbis [.ogg] video'),
723 '$audio' => t('Insert Vorbis [.ogg] audio'),
724 '$setloc' => t('Set your location'),
725 '$noloc' => t('Clear browser location'),
726 '$title' => t('Set title'),
727 '$wait' => t('Please wait'),
728 '$permset' => t('Permission settings'),
731 '$baseurl' => $a->get_baseurl(),
732 '$defloc' => $x['default_location'],
733 '$visitor' => $x['visitor'],
734 '$emailcc' => t('CC: email addresses'),
735 '$jotnets' => $jotnets,
736 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
737 '$lockstate' => $x['lockstate'],
739 '$bang' => $x['bang'],
740 '$profile_uid' => $x['profile_uid'],