4 function conversation(&$a,$r, $mode, $update) {
6 require_once('bbcode.php');
11 if($mode === 'network') {
12 $profile_owner = local_user();
16 if($mode === 'profile') {
17 $profile_owner = $a->profile['profile_uid'];
18 $writable = can_write_wall($a,$profile_owner);
21 if($mode === 'display') {
22 $profile_owner = $a->profile['uid'];
23 $writable = can_write_wall($a,$profile_owner);
29 $return_url = $_SESSION['return_url'];
31 $return_url = $_SESSION['return_url'] = $a->cmd;
34 // find all the authors involved in remote conversations
35 // We will use a local profile photo if they are one of our contacts
36 // otherwise we have to get the photo from the item owner's site
38 $author_contacts = extract_item_authors($r,local_user());
41 $cmnt_tpl = load_view_file('view/comment_item.tpl');
42 $like_tpl = load_view_file('view/like.tpl');
43 $noshare_tpl = load_view_file('view/like_noshare.tpl');
44 $tpl = load_view_file('view/wall_item.tpl');
45 $wallwall = load_view_file('view/wallwall_item.tpl');
52 if($mode === 'network-new' || $mode === 'search') {
54 // "New Item View" on network page or search page results
55 // - just loop through the items and format them minimally for display
57 $tpl = load_view_file('view/search_item.tpl');
58 $droptpl = load_view_file('view/wall_fake_drop.tpl');
60 foreach($r as $item) {
68 if($mode === 'search') {
69 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
70 && ($item['id'] != $item['parent']))
72 $nickname = $item['nickname'];
75 $nickname = $a->user['nickname'];
77 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
78 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
79 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
81 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
83 if(strlen($item['author-link'])) {
84 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
85 $profile_link = $redirect_url;
86 $sparkle = ' sparkle';
88 elseif(isset($author_contacts[$item['author-link']])) {
89 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
90 $sparkle = ' sparkle';
94 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
95 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
98 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
100 $location = '<span class="smalltext">' . $coord . '</span>';
106 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
109 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
113 $drop = replace_macros($droptpl,array('$id' => $item['id']));
114 $lock = '<div class="wall-item-lock"></div>';
116 $o .= replace_macros($tpl,array(
117 '$id' => $item['item_id'],
118 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
119 '$profile_url' => $profile_link,
120 '$item_photo_menu' => item_photo_menu($item),
121 '$name' => $profile_name,
122 '$sparkle' => $sparkle,
124 '$thumb' => $profile_avatar,
125 '$title' => $item['title'],
126 '$body' => smilies(bbcode($item['body'])),
127 '$ago' => relative_date($item['created']),
128 '$location' => $location,
130 '$owner_url' => $owner_url,
131 '$owner_photo' => $owner_photo,
132 '$owner_name' => $owner_name,
134 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
148 // Figure out how many comments each parent has
149 // (Comments all have gravity of 6)
150 // Store the result in the $comments array
154 if(intval($rr['gravity']) == 6) {
155 if(! x($comments,$rr['parent']))
156 $comments[$rr['parent']] = 1;
158 $comments[$rr['parent']] += 1;
162 // map all the like/dislike activities for each parent item
163 // Store these in the $alike and $dlike arrays
165 foreach($r as $item) {
166 like_puller($a,$item,$alike,'like');
167 like_puller($a,$item,$dlike,'dislike');
170 $comments_collapsed = false;
174 foreach($r as $item) {
180 $owner_url = $owner_photo = $owner_name = '';
183 // We've already parsed out like/dislike for special treatment. We can ignore them now
185 if(((activity_match($item['verb'],ACTIVITY_LIKE))
186 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
187 && ($item['id'] != $item['parent']))
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.
194 if($item['id'] == $item['parent']) {
195 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
197 if($blowhard_count == 3) {
198 $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;" >';
202 $blowhard = $item['cid'];
203 if($blowhard_count >= 3)
209 $comments_collapsed = false;
215 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
216 if(! $comments_collapsed) {
217 $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>';
218 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
219 $comments_collapsed = true;
222 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
228 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
230 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
231 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
232 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
233 : '<div class="wall-item-lock"></div>');
236 // Top-level wall post not written by the wall owner (wall-to-wall)
237 // First figure out who owns it.
241 if(($item['parent'] == $item['item_id']) && (! $item['self']) && ($mode !== 'profile')) {
243 if($item['type'] === 'wall') {
244 // I do. Put me on the left of the wall-to-wall notice.
245 $owner_url = $a->contact['url'];
246 $owner_photo = $a->contact['thumb'];
247 $owner_name = $a->contact['name'];
248 $template = $wallwall;
251 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
253 $owner_url = $item['owner-link'];
254 $owner_photo = $item['owner-avatar'];
255 $owner_name = $item['owner-name'];
256 $template = $wallwall;
258 // If it is our contact, use a friendly redirect link
259 if((link_compare($item['owner-link'],$item['url']))
260 && ($item['network'] === 'dfrn')) {
261 $owner_url = $redirect_url;
262 $osparkle = ' sparkle';
271 if($item['id'] == $item['parent']) {
272 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
273 '$id' => $item['id'],
274 '$likethis' => t("I like this \x28toggle\x29"),
275 '$nolike' => t("I don't like this \x28toggle\x29"),
276 '$share' => t('Share'),
277 '$wait' => t('Please wait')
281 if($item['last-child']) {
282 $comment = replace_macros($cmnt_tpl,array(
283 '$return_path' => '',
284 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
285 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
286 '$id' => $item['item_id'],
287 '$parent' => $item['parent'],
288 '$profile_uid' => $profile_owner,
289 '$mylink' => $a->contact['url'],
290 '$mytitle' => t('This is you'),
291 '$myphoto' => $a->contact['thumb'],
292 '$comment' => t('Comment'),
293 '$submit' => t('Submit'),
294 '$ww' => (($mode === 'network') ? $commentww : '')
300 if(($profile_owner == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
301 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
302 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
304 $photo = $item['photo'];
305 $thumb = $item['thumb'];
307 // Post was remotely authored.
309 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
311 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
312 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
314 if($mode === 'profile') {
315 if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
316 $profile_link = $redirect_url;
317 $sparkle = ' sparkle';
320 $profile_link = $item['url'];
324 elseif(strlen($item['author-link'])) {
325 $profile_link = $item['author-link'];
326 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
327 $profile_link = $redirect_url;
328 $sparkle = ' sparkle';
330 elseif(isset($author_contacts[$item['author-link']])) {
331 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
332 $sparkle = ' sparkle';
336 $profile_link = $item['url'];
338 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
339 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
341 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
342 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
345 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
347 $location = '<span class="smalltext">' . $coord . '</span>';
350 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
352 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
359 $tmp_item = replace_macros($template,array(
360 '$id' => $item['item_id'],
361 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
362 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
364 '$wall' => t('Wall-to-Wall'),
365 '$vwall' => t('via Wall-To-Wall:'),
366 '$profile_url' => $profile_link,
367 '$item_photo_menu' => item_photo_menu($item),
368 '$name' => $profile_name,
369 '$thumb' => $profile_avatar,
370 '$osparkle' => $osparkle,
371 '$sparkle' => $sparkle,
372 '$title' => $item['title'],
373 '$body' => smilies(bbcode($item['body'])),
374 '$ago' => relative_date($item['created']),
376 '$location' => $location,
377 '$indent' => $indent,
378 '$owner_url' => $owner_url,
379 '$owner_photo' => $owner_photo,
380 '$owner_name' => $owner_name,
381 '$plink' => get_plink($item),
382 '$edpost' => $edpost,
384 '$vote' => $likebuttons,
386 '$dislike' => $dislike,
387 '$comment' => $comment
390 $arr = array('item' => $item, 'output' => $tmp_item);
391 call_hooks('display_item', $arr);
393 $o .= $arr['output'];
399 // if author collapsing is in force but didn't get closed, close it off now.
401 if($blowhard_count >= 3)