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"){
12 $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
13 #$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
14 #$objlink = preg_grep("|<link.*href=", $input)$item['object']
15 // $item['verb']=="http://activitystrea.ms/schema/1.0/like"
17 switch($item['verb']){
18 case "http://activitystrea.ms/schema/1.0/like":
19 $bodyverb = t('%1$s likes %2$s\'s %3$s');
21 case "http://activitystrea.ms/schema/1.0/dislike":
22 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
25 $item['body'] = sprintf($bodyverb, $author, "tizio", "coso");
33 * "Render" a conversation or list of items for HTML display.
34 * There are two major forms of display:
35 * - Sequential or unthreaded ("New Item View" or search results)
37 * The $mode parameter decides between the various renderings and also
38 * figures out how to determine page owner and other contextual items
39 * that are based on unique features of the calling module.
42 function conversation(&$a, $items, $mode, $update) {
44 require_once('bbcode.php');
47 $page_writeable = false;
49 if($mode === 'network') {
50 $profile_owner = local_user();
51 $page_writeable = true;
54 if($mode === 'profile') {
55 $profile_owner = $a->profile['profile_uid'];
56 $page_writeable = can_write_wall($a,$profile_owner);
59 if($mode === 'display') {
60 $profile_owner = $a->profile['uid'];
61 $page_writeable = can_write_wall($a,$profile_owner);
65 $return_url = $_SESSION['return_url'];
67 $return_url = $_SESSION['return_url'] = $a->cmd;
70 // find all the authors involved in remote conversations
71 // We will use a local profile photo if they are one of our contacts
72 // otherwise we have to get the photo from the item owner's site
74 $author_contacts = extract_item_authors($items,local_user());
77 $cmnt_tpl = load_view_file('view/comment_item.tpl');
78 $like_tpl = load_view_file('view/like.tpl');
79 $noshare_tpl = load_view_file('view/like_noshare.tpl');
80 $tpl = load_view_file('view/wall_item.tpl');
81 $wallwall = load_view_file('view/wallwall_item.tpl');
88 if($mode === 'network-new' || $mode === 'search') {
90 // "New Item View" on network page or search page results
91 // - just loop through the items and format them minimally for display
93 $tpl = load_view_file('view/search_item.tpl');
94 $droptpl = load_view_file('view/wall_fake_drop.tpl');
96 foreach($items as $item) {
104 if($mode === 'search') {
105 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
106 && ($item['id'] != $item['parent']))
108 $nickname = $item['nickname'];
111 $nickname = $a->user['nickname'];
113 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
114 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
115 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
116 if($profile_link === 'mailbox')
119 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
121 if(strlen($item['author-link'])) {
122 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
123 $profile_link = $redirect_url;
124 $sparkle = ' sparkle';
126 elseif(isset($author_contacts[$item['author-link']])) {
127 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
128 $sparkle = ' sparkle';
132 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
133 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
136 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
138 $location = '<span class="smalltext">' . $coord . '</span>';
144 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
147 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
150 localize_item($item);
152 $drop = replace_macros($droptpl,array('$id' => $item['id']));
153 $lock = '<div class="wall-item-lock"></div>';
155 $o .= replace_macros($tpl,array(
156 '$id' => $item['item_id'],
157 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
158 '$profile_url' => $profile_link,
159 '$item_photo_menu' => item_photo_menu($item),
160 '$name' => $profile_name,
161 '$sparkle' => $sparkle,
163 '$thumb' => $profile_avatar,
164 '$title' => $item['title'],
165 '$body' => smilies(bbcode($item['body'])),
166 '$ago' => relative_date($item['created']),
167 '$location' => $location,
169 '$owner_url' => $owner_url,
170 '$owner_photo' => $owner_photo,
171 '$owner_name' => $owner_name,
173 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
187 // Figure out how many comments each parent has
188 // (Comments all have gravity of 6)
189 // Store the result in the $comments array
192 foreach($items as $item) {
193 if(intval($item['gravity']) == 6) {
194 if(! x($comments,$item['parent']))
195 $comments[$item['parent']] = 1;
197 $comments[$item['parent']] += 1;
201 // map all the like/dislike activities for each parent item
202 // Store these in the $alike and $dlike arrays
204 foreach($items as $item) {
205 like_puller($a,$item,$alike,'like');
206 like_puller($a,$item,$dlike,'dislike');
209 $comments_collapsed = false;
213 foreach($items as $item) {
219 $owner_url = $owner_photo = $owner_name = '';
221 // We've already parsed out like/dislike for special treatment. We can ignore them now
223 if(((activity_match($item['verb'],ACTIVITY_LIKE))
224 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
225 && ($item['id'] != $item['parent']))
228 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
231 // Take care of author collapsing and comment collapsing
232 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
233 // If there are more than two comments, squash all but the last 2.
237 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
239 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
241 if($blowhard_count == 3) {
242 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
243 . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >'
244 . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
245 . $item['parent'] . '" style="display: none;" >';
249 $blowhard = $item['cid'];
250 if($blowhard_count >= 3)
256 $comments_collapsed = false;
262 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
264 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
265 if(! $comments_collapsed) {
266 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
267 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >'
268 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
269 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
270 $comments_collapsed = true;
273 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
277 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
279 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
280 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
281 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
282 : '<div class="wall-item-lock"></div>');
285 // Top-level wall post not written by the wall owner (wall-to-wall)
286 // First figure out who owns it.
290 if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
292 if($item['type'] === 'wall') {
294 // On the network page, I am the owner. On the display page it will be the profile owner.
295 // This will have been stored in $a->page_contact by our calling page.
296 // Put this person on the left of the wall-to-wall notice.
298 $owner_url = $a->page_contact['url'];
299 $owner_photo = $a->page_contact['thumb'];
300 $owner_name = $a->page_contact['name'];
301 $template = $wallwall;
304 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
308 $owner_url = $item['owner-link'];
309 $owner_photo = $item['owner-avatar'];
310 $owner_name = $item['owner-name'];
311 $template = $wallwall;
313 // If it is our contact, use a friendly redirect link
314 if((link_compare($item['owner-link'],$item['url']))
315 && ($item['network'] === 'dfrn')) {
316 $owner_url = $redirect_url;
317 $osparkle = ' sparkle';
325 if($page_writeable) {
327 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
328 '$id' => $item['id'],
329 '$likethis' => t("I like this \x28toggle\x29"),
330 '$nolike' => t("I don't like this \x28toggle\x29"),
331 '$share' => t('Share'),
332 '$wait' => t('Please wait')
336 if(($show_comment_box) || (($show_comment_box == false) && ($item['last-child']))) {
337 $comment = replace_macros($cmnt_tpl,array(
338 '$return_path' => '',
339 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
340 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
341 '$id' => $item['item_id'],
342 '$parent' => $item['parent'],
343 '$profile_uid' => $profile_owner,
344 '$mylink' => $a->contact['url'],
345 '$mytitle' => t('This is you'),
346 '$myphoto' => $a->contact['thumb'],
347 '$comment' => t('Comment'),
348 '$submit' => t('Submit'),
349 '$ww' => (($mode === 'network') ? $commentww : '')
354 $edpost = ((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1))
355 ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
356 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
358 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
360 $photo = $item['photo'];
361 $thumb = $item['thumb'];
363 // Post was remotely authored.
365 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
367 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
368 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
370 if($mode === 'profile') {
371 if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
372 $profile_link = $redirect_url;
373 $sparkle = ' sparkle';
376 $profile_link = $item['url'];
380 elseif(strlen($item['author-link'])) {
381 $profile_link = $item['author-link'];
382 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
383 $profile_link = $redirect_url;
384 $sparkle = ' sparkle';
386 elseif(isset($author_contacts[$item['author-link']])) {
387 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
388 $sparkle = ' sparkle';
392 $profile_link = $item['url'];
394 if($profile_link === 'mailbox')
397 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
398 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
400 $location = (($item['location']) ? '<a target="map" title="' . $item['location']
401 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
402 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
403 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
406 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
408 $location = '<span class="smalltext">' . $coord . '</span>';
411 $indent = (($toplevelpost) ? '' : ' comment');
413 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
417 localize_item($item);
421 $tmp_item = replace_macros($template,array(
422 '$id' => $item['item_id'],
423 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
424 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
426 '$wall' => t('Wall-to-Wall'),
427 '$vwall' => t('via Wall-To-Wall:'),
428 '$profile_url' => $profile_link,
429 '$item_photo_menu' => item_photo_menu($item),
430 '$name' => $profile_name,
431 '$thumb' => $profile_avatar,
432 '$osparkle' => $osparkle,
433 '$sparkle' => $sparkle,
434 '$title' => $item['title'],
435 '$body' => smilies(bbcode($item['body'])),
436 '$ago' => relative_date($item['created']),
438 '$location' => $location,
439 '$indent' => $indent,
440 '$owner_url' => $owner_url,
441 '$owner_photo' => $owner_photo,
442 '$owner_name' => $owner_name,
443 '$plink' => get_plink($item),
444 '$edpost' => $edpost,
446 '$vote' => $likebuttons,
448 '$dislike' => $dislike,
449 '$comment' => $comment
452 $arr = array('item' => $item, 'output' => $tmp_item);
453 call_hooks('display_item', $arr);
455 $o .= $arr['output'];
461 // if author collapsing is in force but didn't get closed, close it off now.
463 if($blowhard_count >= 3)
472 if(! function_exists('extract_item_authors')) {
473 function extract_item_authors($arr,$uid) {
475 if((! $uid) || (! is_array($arr)) || (! count($arr)))
478 foreach($arr as $rr) {
479 if(! in_array("'" . dbesc($rr['author-link']) . "'",$urls))
480 $urls[] = "'" . dbesc($rr['author-link']) . "'";
483 // pre-quoted, don't put quotes on %s
485 $r = q("SELECT `id`,`network`,`url` FROM `contact` WHERE `uid` = %d AND `url` IN ( %s ) AND `self` = 0 AND `blocked` = 0 ",
493 if ($rr['network']=='dfrn')
494 $ret[$rr['url']] = $rr['id'];
495 $authors[$r['url']]= $rr;
497 $a->authors = $authors;
504 if(! function_exists('item_photo_menu')){
505 function item_photo_menu($item){
508 if (!isset($a->authors)){
509 $rr = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `uid`=%d AND `self`=0 AND `blocked`=0 ", intval(local_user()));
511 foreach($rr as $r) $authors[$r['url']]= $r;
512 $a->authors = $authors;
520 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
521 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
523 if($profile_link === 'mailbox')
526 // $item['contact-uid'] is only set on profile page and indicates the uid of the user who owns the profile.
528 $profile_owner = ((x($item,'contact-uid')) && intval($item['contact-uid']) ? intval($item['contact-uid']) : 0);
530 // So we are checking that this is a logged in user on some page that *isn't* a profile page
531 // OR a profile page where the viewer owns the profile.
532 // Then check if we can use a sparkle (redirect) link to the profile by virtue of it being our contact
533 // or a friend's contact that we both have a connection to.
535 if((local_user() && ($profile_owner == 0))
536 || ($profile_owner && $profile_owner == local_user())) {
538 if(strlen($item['author-link']) && link_compare($item['author-link'],$item['url'])) {
539 $redir = $redirect_url;
542 elseif(isset($a->authors[$item['author-link']])) {
543 $redir = $a->get_baseurl() . '/redir/' . $a->authors[$item['author-link']]['id'];
544 $cid = $a->authors[$item['author-link']]['id'];
546 if($item['author-link'] === 'mailbox')
549 if((isset($cid)) && (! $item['self'])) {
550 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
551 if($item['network'] === 'dfrn') {
552 $status_link = $redir . "?url=status";
553 $profile_link = $redir . "?url=profile";
554 $photos_link = $redir . "?url=photos";
555 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
562 t("View status") => $status_link,
563 t("View profile") => $profile_link,
564 t("View photos") => $photos_link,
565 t("Edit contact") => $contact_url,
566 t("Send PM") => $pm_url,
570 $args = array($item, &$menu);
572 call_hooks('item_photo_menu', $args);
575 foreach($menu as $k=>$v){
576 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
581 if(! function_exists('like_puller')) {
582 function like_puller($a,$item,&$arr,$mode) {
586 $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
588 if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
589 $url = $item['author-link'];
590 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
591 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
592 $sparkle = ' class="sparkle" ';
594 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
595 $arr[$item['parent'] . '-l'] = array();
596 if(! isset($arr[$item['parent']]))
597 $arr[$item['parent']] = 1;
599 $arr[$item['parent']] ++;
600 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
605 // Format the like/dislike text for a profile item
606 // $cnt = number of people who like/dislike the item
607 // $arr = array of pre-linked names of likers/dislikers
608 // $type = one of 'like, 'dislike'
610 // returns formatted text
612 if(! function_exists('format_like')) {
613 function format_like($cnt,$arr,$type,$id) {
616 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
618 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
619 $o .= (($type === 'like') ?
620 sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
622 sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
624 $total = count($arr);
625 if($total >= MAX_LIKERS)
626 $arr = array_slice($arr, 0, MAX_LIKERS - 1);
627 if($total < MAX_LIKERS)
628 $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
629 $str = implode(', ', $arr);
630 if($total >= MAX_LIKERS)
631 $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
632 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
633 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';