]> git.mxchange.org Git - friendica.git/blob - include/conversation.php
some w3c validation issues
[friendica.git] / include / conversation.php
1 <?php
2
3
4 function conversation(&$a,$r, $mode, $update) {
5
6         require_once('bbcode.php');
7
8         $profile_owner = 0;
9         $writable      = false;
10
11         if($mode === 'network') {
12                 $profile_owner = local_user();
13                 $writable = true;
14         }
15
16         if($mode === 'profile') {
17                 $profile_owner = $a->profile['profile_uid'];
18                 $writable = can_write_wall($a,$profile_owner);
19         }
20
21
22
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
26
27         $author_contacts = extract_item_authors($r,local_user());
28
29
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');
35
36         $alike = array();
37         $dlike = array();
38         
39         if(count($r)) {
40
41                 if($mode === 'network-new') {
42
43                         // "New Item View" - just loop through the items and format them minimally for display
44
45                         $tpl = load_view_file('view/search_item.tpl');
46                         $droptpl = load_view_file('view/wall_fake_drop.tpl');
47
48                         foreach($r as $item) {
49
50                                 $comment     = '';
51                                 $owner_url   = '';
52                                 $owner_photo = '';
53                                 $owner_name  = '';
54                                 $sparkle     = '';
55                         
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']);
59
60                                 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
61
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';
66                                         }
67                                         elseif(isset($author_contacts[$item['author-link']])) {
68                                                 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
69                                                 $sparkle = ' sparkle';
70                                         }
71                                 }
72
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>' : '');
75                                 if($coord) {
76                                         if($location)
77                                                 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
78                                         else
79                                                 $location = '<span class="smalltext">' . $coord . '</span>';
80                                 }
81
82                                 $drop = '';
83                                 $dropping = false;
84
85                                 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
86                                         $dropping = true;
87
88                     $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
89
90
91
92                                 $drop = replace_macros($droptpl,array('$id' => $item['id']));
93                                 $lock = '<div class="wall-item-lock"></div>';
94                                 
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,
102                                         '$lock' => $lock,
103                                         '$thumb' => $profile_avatar,
104                                         '$title' => $item['title'],
105                                         '$body' => smilies(bbcode($item['body'])),
106                                         '$ago' => relative_date($item['created']),
107                                         '$location' => $location,
108                                         '$indent' => '',
109                                         '$owner_url' => $owner_url,
110                                         '$owner_photo' => $owner_photo,
111                                         '$owner_name' => $owner_name,
112                                         '$drop' => $drop,
113                                         '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
114                                 ));
115
116                         }
117
118                         return $o;
119                 }
120
121
122
123
124                 // Normal View
125
126
127                 // Figure out how many comments each parent has
128                 // (Comments all have gravity of 6)
129                 // Store the result in the $comments array
130
131                 $comments = array();
132                 foreach($r as $rr) {
133                         if(intval($rr['gravity']) == 6) {
134                                 if(! x($comments,$rr['parent']))
135                                         $comments[$rr['parent']] = 1;
136                                 else
137                                         $comments[$rr['parent']] += 1;
138                         }
139                 }
140
141                 // map all the like/dislike activities for each parent item 
142                 // Store these in the $alike and $dlike arrays
143
144                 foreach($r as $item) {
145                         like_puller($a,$item,$alike,'like');
146                         like_puller($a,$item,$dlike,'dislike');
147                 }
148
149                 $comments_collapsed = false;
150                 $blowhard = 0;
151                 $blowhard_count = 0;
152
153                 foreach($r as $item) {
154
155                         $comment = '';
156                         $template = $tpl;
157                         $commentww = '';
158                         $sparkle = '';
159                         $owner_url = $owner_photo = $owner_name = '';
160
161
162                         // We've already parsed out like/dislike for special treatment. We can ignore them now
163
164                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) 
165                                 || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
166                                 && ($item['id'] != $item['parent']))
167                                 continue;
168
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.
172
173                         if($item['id'] == $item['parent']) {
174                                 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
175                                         $blowhard_count ++;
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;" >';
178                                         }
179                                 }
180                                 else {
181                                         $blowhard = $item['cid'];                                       
182                                         if($blowhard_count >= 3)
183                                                 $o .= '</div>';
184                                         $blowhard_count = 0;
185                                 }
186
187                                 $comments_seen = 0;
188                                 $comments_collapsed = false;
189                         }
190                         else
191                                 $comments_seen ++;
192
193
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;
199                                 }
200                         }
201                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
202                                 $o .= '</div>';
203                         }
204
205
206
207                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
208
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>');
213
214
215                         // Top-level wall post not written by the wall owner (wall-to-wall)
216                         // First figure out who owns it. 
217
218                         $osparkle = '';
219
220                         if(($item['parent'] == $item['item_id']) && (! $item['self']) && ($mode !== 'profile')) {
221
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;
228                                         $commentww = 'ww';      
229                                 }
230                                 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
231                                         // Could be anybody. 
232                                         $owner_url = $item['owner-link'];
233                                         $owner_photo = $item['owner-avatar'];
234                                         $owner_name = $item['owner-name'];
235                                         $template = $wallwall;
236                                         $commentww = 'ww';
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';
242                                         }
243                                 }
244                         }
245
246                         if($update)
247                                 $return_url = $_SESSION['return_url'];
248                         else
249                                 $return_url = $_SESSION['return_url'] = $a->cmd;
250
251                         $likebuttons = '';
252
253                         if($writable) {
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') 
261                                         ));
262                                 }
263
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'),
277                                                 '$ww' => $commentww
278                                         ));
279                                 }
280                         }
281
282                         $edpost = '';
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')));
286
287                         $photo = $item['photo'];
288                         $thumb = $item['thumb'];
289
290                         // Post was remotely authored.
291
292                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
293
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);
296
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';
301                     }
302                                 else {
303                                         $profile_link = $item['url'];
304                                         $sparkle = '';
305                                 }
306                         }
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';
312                                 }
313                                 elseif(isset($author_contacts[$item['author-link']])) {
314                                         $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
315                                         $sparkle = ' sparkle';
316                                 }
317                         }
318                         else 
319                                 $profile_link = $item['url'];
320
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']) : '');
323
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>' : '');
326                         if($coord) {
327                                 if($location)
328                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
329                                 else
330                                         $location = '<span class="smalltext">' . $coord . '</span>';
331                         }
332
333                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
334
335                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
336                                 $indent .= ' shiny'; 
337
338
339
340                         // Build the HTML
341
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'),
346                                 '$to' => t('to'),
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']),
358                                 '$lock' => $lock,
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,
366                                 '$drop' => $drop,
367                                 '$vote' => $likebuttons,
368                                 '$like' => $like,
369                                 '$dislike' => $dislike,
370                                 '$comment' => $comment
371                         ));
372
373                         $arr = array('item' => $item, 'output' => $tmp_item);
374                         call_hooks('display_item', $arr);
375
376                         $o .= $arr['output'];
377
378                 }
379         }
380
381
382         // if author collapsing is in force but didn't get closed, close it off now.
383
384         if($blowhard_count >= 3)
385                 $o .= '</div>';
386
387         return $o;
388