4 function conversation(&$a, $items, $mode, $update) {
6 require_once('bbcode.php');
9 $page_writeable = false;
11 if($mode === 'network') {
12 $profile_owner = local_user();
13 $page_writeable = true;
16 if($mode === 'profile') {
17 $profile_owner = $a->profile['profile_uid'];
18 $page_writeable = can_write_wall($a,$profile_owner);
21 if($mode === 'display') {
22 $profile_owner = $a->profile['uid'];
23 $page_writeable = can_write_wall($a,$profile_owner);
27 $return_url = $_SESSION['return_url'];
29 $return_url = $_SESSION['return_url'] = $a->cmd;
32 // find all the authors involved in remote conversations
33 // We will use a local profile photo if they are one of our contacts
34 // otherwise we have to get the photo from the item owner's site
36 $author_contacts = extract_item_authors($items,local_user());
39 $cmnt_tpl = load_view_file('view/comment_item.tpl');
40 $like_tpl = load_view_file('view/like.tpl');
41 $noshare_tpl = load_view_file('view/like_noshare.tpl');
42 $tpl = load_view_file('view/wall_item.tpl');
43 $wallwall = load_view_file('view/wallwall_item.tpl');
50 if($mode === 'network-new' || $mode === 'search') {
52 // "New Item View" on network page or search page results
53 // - just loop through the items and format them minimally for display
55 $tpl = load_view_file('view/search_item.tpl');
56 $droptpl = load_view_file('view/wall_fake_drop.tpl');
58 foreach($items as $item) {
66 if($mode === 'search') {
67 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
68 && ($item['id'] != $item['parent']))
70 $nickname = $item['nickname'];
73 $nickname = $a->user['nickname'];
75 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
76 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
77 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
79 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
81 if(strlen($item['author-link'])) {
82 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
83 $profile_link = $redirect_url;
84 $sparkle = ' sparkle';
86 elseif(isset($author_contacts[$item['author-link']])) {
87 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
88 $sparkle = ' sparkle';
92 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
93 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
96 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
98 $location = '<span class="smalltext">' . $coord . '</span>';
104 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
107 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
111 $drop = replace_macros($droptpl,array('$id' => $item['id']));
112 $lock = '<div class="wall-item-lock"></div>';
114 $o .= replace_macros($tpl,array(
115 '$id' => $item['item_id'],
116 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
117 '$profile_url' => $profile_link,
118 '$item_photo_menu' => item_photo_menu($item),
119 '$name' => $profile_name,
120 '$sparkle' => $sparkle,
122 '$thumb' => $profile_avatar,
123 '$title' => $item['title'],
124 '$body' => smilies(bbcode($item['body'])),
125 '$ago' => relative_date($item['created']),
126 '$location' => $location,
128 '$owner_url' => $owner_url,
129 '$owner_photo' => $owner_photo,
130 '$owner_name' => $owner_name,
132 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
146 // Figure out how many comments each parent has
147 // (Comments all have gravity of 6)
148 // Store the result in the $comments array
151 foreach($items as $item) {
152 if(intval($item['gravity']) == 6) {
153 if(! x($comments,$item['parent']))
154 $comments[$item['parent']] = 1;
156 $comments[$item['parent']] += 1;
160 // map all the like/dislike activities for each parent item
161 // Store these in the $alike and $dlike arrays
163 foreach($items as $item) {
164 like_puller($a,$item,$alike,'like');
165 like_puller($a,$item,$dlike,'dislike');
168 $comments_collapsed = false;
172 foreach($items as $item) {
178 $owner_url = $owner_photo = $owner_name = '';
180 // We've already parsed out like/dislike for special treatment. We can ignore them now
182 if(((activity_match($item['verb'],ACTIVITY_LIKE))
183 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
184 && ($item['id'] != $item['parent']))
187 $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
190 // Take care of author collapsing and comment collapsing
191 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
192 // If there are more than two comments, squash all but the last 2.
196 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
198 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
200 if($blowhard_count == 3) {
201 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >' . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' . $item['parent'] . '" style="display: none;" >';
205 $blowhard = $item['cid'];
206 if($blowhard_count >= 3)
212 $comments_collapsed = false;
218 $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
220 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
221 if(! $comments_collapsed) {
222 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >' . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>';
223 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
224 $comments_collapsed = true;
227 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
233 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
235 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
236 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
237 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
238 : '<div class="wall-item-lock"></div>');
241 // Top-level wall post not written by the wall owner (wall-to-wall)
242 // First figure out who owns it.
246 if(($item['parent'] == $item['item_id']) && (! $item['self']) && ($mode !== 'profile')) {
248 if($item['type'] === 'wall') {
249 // I do. Put me on the left of the wall-to-wall notice.
250 $owner_url = $a->page_contact['url'];
251 $owner_photo = $a->page_contact['thumb'];
252 $owner_name = $a->page_contact['name'];
253 $template = $wallwall;
256 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
258 $owner_url = $item['owner-link'];
259 $owner_photo = $item['owner-avatar'];
260 $owner_name = $item['owner-name'];
261 $template = $wallwall;
263 // If it is our contact, use a friendly redirect link
264 if((link_compare($item['owner-link'],$item['url']))
265 && ($item['network'] === 'dfrn')) {
266 $owner_url = $redirect_url;
267 $osparkle = ' sparkle';
275 if($page_writeable) {
276 if($item['id'] == $item['parent']) {
277 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
278 '$id' => $item['id'],
279 '$likethis' => t("I like this \x28toggle\x29"),
280 '$nolike' => t("I don't like this \x28toggle\x29"),
281 '$share' => t('Share'),
282 '$wait' => t('Please wait')
286 if(($show_comment_box) || (($show_comment_box == false) && ($item['last-child']))) {
287 $comment = replace_macros($cmnt_tpl,array(
288 '$return_path' => '',
289 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
290 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
291 '$id' => $item['item_id'],
292 '$parent' => $item['parent'],
293 '$profile_uid' => $profile_owner,
294 '$mylink' => $a->contact['url'],
295 '$mytitle' => t('This is you'),
296 '$myphoto' => $a->contact['thumb'],
297 '$comment' => t('Comment'),
298 '$submit' => t('Submit'),
299 '$ww' => (($mode === 'network') ? $commentww : '')
305 if(($profile_owner == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
306 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
307 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
309 $photo = $item['photo'];
310 $thumb = $item['thumb'];
312 // Post was remotely authored.
314 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
316 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
317 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
319 if($mode === 'profile') {
320 if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
321 $profile_link = $redirect_url;
322 $sparkle = ' sparkle';
325 $profile_link = $item['url'];
329 elseif(strlen($item['author-link'])) {
330 $profile_link = $item['author-link'];
331 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
332 $profile_link = $redirect_url;
333 $sparkle = ' sparkle';
335 elseif(isset($author_contacts[$item['author-link']])) {
336 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
337 $sparkle = ' sparkle';
341 $profile_link = $item['url'];
343 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
344 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
346 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
347 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
350 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
352 $location = '<span class="smalltext">' . $coord . '</span>';
355 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
357 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
364 $tmp_item = replace_macros($template,array(
365 '$id' => $item['item_id'],
366 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
367 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
369 '$wall' => t('Wall-to-Wall'),
370 '$vwall' => t('via Wall-To-Wall:'),
371 '$profile_url' => $profile_link,
372 '$item_photo_menu' => item_photo_menu($item),
373 '$name' => $profile_name,
374 '$thumb' => $profile_avatar,
375 '$osparkle' => $osparkle,
376 '$sparkle' => $sparkle,
377 '$title' => $item['title'],
378 '$body' => smilies(bbcode($item['body'])),
379 '$ago' => relative_date($item['created']),
381 '$location' => $location,
382 '$indent' => $indent,
383 '$owner_url' => $owner_url,
384 '$owner_photo' => $owner_photo,
385 '$owner_name' => $owner_name,
386 '$plink' => get_plink($item),
387 '$edpost' => $edpost,
389 '$vote' => $likebuttons,
391 '$dislike' => $dislike,
392 '$comment' => $comment
395 $arr = array('item' => $item, 'output' => $tmp_item);
396 call_hooks('display_item', $arr);
398 $o .= $arr['output'];
404 // if author collapsing is in force but didn't get closed, close it off now.
406 if($blowhard_count >= 3)