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);
23 // find all the authors involved in remote conversations
24 // We will use a local profile photo if they are one of our contacts
25 // otherwise we have to get the photo from the item owner's site
27 $author_contacts = extract_item_authors($r,local_user());
30 $cmnt_tpl = load_view_file('view/comment_item.tpl');
31 $like_tpl = load_view_file('view/like.tpl');
32 $noshare_tpl = load_view_file('view/like_noshare.tpl');
33 $tpl = load_view_file('view/wall_item.tpl');
34 $wallwall = load_view_file('view/wallwall_item.tpl');
41 if($mode === 'network-new') {
43 // "New Item View" - just loop through the items and format them minimally for display
45 $tpl = load_view_file('view/search_item.tpl');
46 $droptpl = load_view_file('view/wall_fake_drop.tpl');
48 foreach($r as $item) {
56 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
57 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
58 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
60 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
62 if(strlen($item['author-link'])) {
63 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
64 $profile_link = $redirect_url;
65 $sparkle = ' sparkle';
67 elseif(isset($author_contacts[$item['author-link']])) {
68 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
69 $sparkle = ' sparkle';
73 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
74 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
77 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
79 $location = '<span class="smalltext">' . $coord . '</span>';
85 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
88 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
92 $drop = replace_macros($droptpl,array('$id' => $item['id']));
93 $lock = '<div class="wall-item-lock"></div>';
95 $o .= replace_macros($tpl,array(
96 '$id' => $item['item_id'],
97 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
98 '$profile_url' => $profile_link,
99 '$item_photo_menu' => item_photo_menu($item),
100 '$name' => $profile_name,
101 '$sparkle' => $sparkle,
103 '$thumb' => $profile_avatar,
104 '$title' => $item['title'],
105 '$body' => smilies(bbcode($item['body'])),
106 '$ago' => relative_date($item['created']),
107 '$location' => $location,
109 '$owner_url' => $owner_url,
110 '$owner_photo' => $owner_photo,
111 '$owner_name' => $owner_name,
113 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
127 // Figure out how many comments each parent has
128 // (Comments all have gravity of 6)
129 // Store the result in the $comments array
133 if(intval($rr['gravity']) == 6) {
134 if(! x($comments,$rr['parent']))
135 $comments[$rr['parent']] = 1;
137 $comments[$rr['parent']] += 1;
141 // map all the like/dislike activities for each parent item
142 // Store these in the $alike and $dlike arrays
144 foreach($r as $item) {
145 like_puller($a,$item,$alike,'like');
146 like_puller($a,$item,$dlike,'dislike');
149 $comments_collapsed = false;
153 foreach($r as $item) {
159 $owner_url = $owner_photo = $owner_name = '';
162 // We've already parsed out like/dislike for special treatment. We can ignore them now
164 if(((activity_match($item['verb'],ACTIVITY_LIKE))
165 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
166 && ($item['id'] != $item['parent']))
169 // Take care of author collapsing and comment collapsing
170 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
171 // If there are more than two comments, squash all but the last 2.
173 if($item['id'] == $item['parent']) {
174 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
176 if($blowhard_count == 3) {
177 $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;" >';
181 $blowhard = $item['cid'];
182 if($blowhard_count >= 3)
188 $comments_collapsed = false;
194 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
195 if(! $comments_collapsed) {
196 $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>';
197 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
198 $comments_collapsed = true;
201 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
207 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
209 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
210 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
211 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
212 : '<div class="wall-item-lock"></div>');
215 // Top-level wall post not written by the wall owner (wall-to-wall)
216 // First figure out who owns it.
220 if(($item['parent'] == $item['item_id']) && (! $item['self']) && ($mode !== 'profile')) {
222 if($item['type'] === 'wall') {
223 // I do. Put me on the left of the wall-to-wall notice.
224 $owner_url = $a->contact['url'];
225 $owner_photo = $a->contact['thumb'];
226 $owner_name = $a->contact['name'];
227 $template = $wallwall;
230 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
232 $owner_url = $item['owner-link'];
233 $owner_photo = $item['owner-avatar'];
234 $owner_name = $item['owner-name'];
235 $template = $wallwall;
237 // If it is our contact, use a friendly redirect link
238 if((link_compare($item['owner-link'],$item['url']))
239 && ($item['network'] === 'dfrn')) {
240 $owner_url = $redirect_url;
241 $osparkle = ' sparkle';
247 $return_url = $_SESSION['return_url'];
249 $return_url = $_SESSION['return_url'] = $a->cmd;
254 if($item['id'] == $item['parent']) {
255 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
256 '$id' => $item['id'],
257 '$likethis' => t("I like this \x28toggle\x29"),
258 '$nolike' => t("I don't like this \x28toggle\x29"),
259 '$share' => t('Share'),
260 '$wait' => t('Please wait')
264 if($item['last-child']) {
265 $comment = replace_macros($cmnt_tpl,array(
266 '$return_path' => '',
267 '$jsreload' => '', // $_SESSION['return_url'],
268 '$type' => 'net-comment',
269 '$id' => $item['item_id'],
270 '$parent' => $item['parent'],
271 '$profile_uid' => $profile_owner,
272 '$mylink' => $a->contact['url'],
273 '$mytitle' => t('This is you'),
274 '$myphoto' => $a->contact['thumb'],
275 '$comment' => t('Comment'),
276 '$submit' => t('Submit'),
283 if(($profile_owner == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
284 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
285 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
287 $photo = $item['photo'];
288 $thumb = $item['thumb'];
290 // Post was remotely authored.
292 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
294 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
295 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
297 if($mode === 'profile') {
298 if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
299 $profile_link = $redirect_url;
300 $sparkle = ' sparkle';
303 $profile_link = $item['url'];
307 elseif(strlen($item['author-link'])) {
308 $profile_link = $item['author-link'];
309 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
310 $profile_link = $redirect_url;
311 $sparkle = ' sparkle';
313 elseif(isset($author_contacts[$item['author-link']])) {
314 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
315 $sparkle = ' sparkle';
319 $profile_link = $item['url'];
321 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
322 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
324 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
325 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
328 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
330 $location = '<span class="smalltext">' . $coord . '</span>';
333 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
335 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
342 $tmp_item = replace_macros($template,array(
343 '$id' => $item['item_id'],
344 '$linktitle' => t('View $name\'s profile'),
345 '$olinktitle' => t('View $owner_name\'s profile'),
347 '$wall' => t('Wall-to-Wall'),
348 '$vwall' => t('via Wall-To-Wall:'),
349 '$profile_url' => $profile_link,
350 '$item_photo_menu' => item_photo_menu($item),
351 '$name' => $profile_name,
352 '$thumb' => $profile_avatar,
353 '$osparkle' => $osparkle,
354 '$sparkle' => $sparkle,
355 '$title' => $item['title'],
356 '$body' => smilies(bbcode($item['body'])),
357 '$ago' => relative_date($item['created']),
359 '$location' => $location,
360 '$indent' => $indent,
361 '$owner_url' => $owner_url,
362 '$owner_photo' => $owner_photo,
363 '$owner_name' => $owner_name,
364 '$plink' => get_plink($item),
365 '$edpost' => $edpost,
367 '$vote' => $likebuttons,
369 '$dislike' => $dislike,
370 '$comment' => $comment
373 $arr = array('item' => $item, 'output' => $tmp_item);
374 call_hooks('display_item', $arr);
376 $o .= $arr['output'];
382 // if author collapsing is in force but didn't get closed, close it off now.
384 if($blowhard_count >= 3)