4 function conversation(&$a,$r, $mode, $update) {
6 require_once('bbcode.php');
8 // find all the authors involved in remote conversations
9 // We will use a local profile photo if they are one of our contacts
10 // otherwise we have to get the photo from the item owner's site
12 $author_contacts = extract_item_authors($r,local_user());
15 $cmnt_tpl = load_view_file('view/comment_item.tpl');
16 $like_tpl = load_view_file('view/like.tpl');
17 $noshare_tpl = load_view_file('view/like_noshare.tpl');
18 $tpl = load_view_file('view/wall_item.tpl');
19 $wallwall = load_view_file('view/wallwall_item.tpl');
26 if($mode === 'network-new') {
28 // "New Item View" - just loop through the items and format them minimally for display
30 $tpl = load_view_file('view/search_item.tpl');
31 $droptpl = load_view_file('view/wall_fake_drop.tpl');
33 foreach($r as $item) {
41 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
42 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
43 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
45 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
47 if(strlen($item['author-link'])) {
48 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
49 $profile_link = $redirect_url;
50 $sparkle = ' sparkle';
52 elseif(isset($author_contacts[$item['author-link']])) {
53 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
54 $sparkle = ' sparkle';
58 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
59 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
62 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
64 $location = '<span class="smalltext">' . $coord . '</span>';
67 $drop = replace_macros($droptpl,array('$id' => $item['id']));
68 $lock = '<div class="wall-item-lock"></div>';
70 $o .= replace_macros($tpl,array(
71 '$id' => $item['item_id'],
72 '$linktitle' => sprintf( t('View %s\s profile'), $profile_name),
73 '$profile_url' => $profile_link,
74 '$item_photo_menu' => item_photo_menu($item),
75 '$name' => $profile_name,
76 '$sparkle' => $sparkle,
78 '$thumb' => $profile_avatar,
79 '$title' => $item['title'],
80 '$body' => smilies(bbcode($item['body'])),
81 '$ago' => relative_date($item['created']),
82 '$location' => $location,
84 '$owner_url' => $owner_url,
85 '$owner_photo' => $owner_photo,
86 '$owner_name' => $owner_name,
88 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
102 // Figure out how many comments each parent has
103 // (Comments all have gravity of 6)
104 // Store the result in the $comments array
108 if(intval($rr['gravity']) == 6) {
109 if(! x($comments,$rr['parent']))
110 $comments[$rr['parent']] = 1;
112 $comments[$rr['parent']] += 1;
116 // map all the like/dislike activities for each parent item
117 // Store these in the $alike and $dlike arrays
119 foreach($r as $item) {
120 like_puller($a,$item,$alike,'like');
121 like_puller($a,$item,$dlike,'dislike');
124 $comments_collapsed = false;
128 foreach($r as $item) {
134 $owner_url = $owner_photo = $owner_name = '';
137 // We've already parsed out like/dislike for special treatment. We can ignore them now
139 if(((activity_match($item['verb'],ACTIVITY_LIKE))
140 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
141 && ($item['id'] != $item['parent']))
144 // Take care of author collapsing and comment collapsing
145 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
146 // If there are more than two comments, squash all but the last 2.
148 if($item['id'] == $item['parent']) {
149 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
151 if($blowhard_count == 3) {
152 $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;" >';
156 $blowhard = $item['cid'];
157 if($blowhard_count >= 3)
163 $comments_collapsed = false;
169 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
170 if(! $comments_collapsed) {
171 $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>';
172 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
173 $comments_collapsed = true;
176 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
182 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
184 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
185 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
186 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
187 : '<div class="wall-item-lock"></div>');
190 // Top-level wall post not written by the wall owner (wall-to-wall)
191 // First figure out who owns it.
195 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
197 if($item['type'] === 'wall') {
198 // I do. Put me on the left of the wall-to-wall notice.
199 $owner_url = $a->contact['url'];
200 $owner_photo = $a->contact['thumb'];
201 $owner_name = $a->contact['name'];
202 $template = $wallwall;
205 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
207 $owner_url = $item['owner-link'];
208 $owner_photo = $item['owner-avatar'];
209 $owner_name = $item['owner-name'];
210 $template = $wallwall;
212 // If it is our contact, use a friendly redirect link
213 if((link_compare($item['owner-link'],$item['url']))
214 && ($item['network'] === 'dfrn')) {
215 $owner_url = $redirect_url;
216 $osparkle = ' sparkle';
222 $return_url = $_SESSION['return_url'];
224 $return_url = $_SESSION['return_url'] = $a->cmd;
227 if($item['id'] == $item['parent']) {
228 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
229 '$id' => $item['id'],
230 '$likethis' => t("I like this \x28toggle\x29"),
231 '$nolike' => t("I don't like this \x28toggle\x29"),
232 '$share' => t('Share'),
233 '$wait' => t('Please wait')
237 if($item['last-child']) {
238 $comment = replace_macros($cmnt_tpl,array(
239 '$return_path' => '',
240 '$jsreload' => '', // $_SESSION['return_url'],
241 '$type' => 'net-comment',
242 '$id' => $item['item_id'],
243 '$parent' => $item['parent'],
244 '$profile_uid' => $_SESSION['uid'],
245 '$mylink' => $a->contact['url'],
246 '$mytitle' => t('This is you'),
247 '$myphoto' => $a->contact['thumb'],
248 '$comment' => t('Comment'),
249 '$submit' => t('Submit'),
255 if(($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
256 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
257 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
259 $photo = $item['photo'];
260 $thumb = $item['thumb'];
262 // Post was remotely authored.
264 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
266 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
267 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
269 if(strlen($item['author-link'])) {
270 $profile_link = $item['author-link'];
271 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
272 $profile_link = $redirect_url;
273 $sparkle = ' sparkle';
275 elseif(isset($author_contacts[$item['author-link']])) {
276 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
277 $sparkle = ' sparkle';
281 $profile_link = $item['url'];
283 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
284 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
286 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
287 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
290 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
292 $location = '<span class="smalltext">' . $coord . '</span>';
295 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
297 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
304 $tmp_item = replace_macros($template,array(
305 '$id' => $item['item_id'],
306 '$linktitle' => t('View $name\'s profile'),
307 '$olinktitle' => t('View $owner_name\'s profile'),
309 '$wall' => t('Wall-to-Wall'),
310 '$vwall' => t('via Wall-To-Wall:'),
311 '$profile_url' => $profile_link,
312 '$item_photo_menu' => item_photo_menu($item),
313 '$name' => $profile_name,
314 '$thumb' => $profile_avatar,
315 '$osparkle' => $osparkle,
316 '$sparkle' => $sparkle,
317 '$title' => $item['title'],
318 '$body' => smilies(bbcode($item['body'])),
319 '$ago' => relative_date($item['created']),
321 '$location' => $location,
322 '$indent' => $indent,
323 '$owner_url' => $owner_url,
324 '$owner_photo' => $owner_photo,
325 '$owner_name' => $owner_name,
326 '$plink' => get_plink($item),
327 '$edpost' => $edpost,
329 '$vote' => $likebuttons,
331 '$dislike' => $dislike,
332 '$comment' => $comment
335 $arr = array('item' => $item, 'output' => $tmp_item);
336 call_hooks('display_item', $arr);
338 $o .= $arr['output'];
344 // if author collapsing is in force but didn't get closed, close it off now.
346 if($blowhard_count >= 3)