]> git.mxchange.org Git - friendica.git/blob - include/conversation.php
Merge branch 'translateitems' of https://github.com/fabrixxm/friendika into fabrixxm...
[friendica.git] / include / conversation.php
1 <?php
2
3 /**
4  * Render actions localized
5  */
6 function localize_item(&$item){
7         
8         if ($item['verb']=="http://activitystrea.ms/schema/1.0/like" ||
9                 $item['verb']=="http://activitystrea.ms/schema/1.0/dislike"){
10
11                 $r = q("SELECT * from `item`,`contact` WHERE 
12                                 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
13                                  dbesc($item['parent-uri']));
14                 if(count($r)==0) return;
15                 $obj=$r[0];
16                 
17                 $author  = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
18                 $objauthor =  '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
19                 
20                 $post_type = (($obj['resource-id']) ? t('photo') : t('status'));                
21                 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
22                 
23                 switch($item['verb']){
24                         case "http://activitystrea.ms/schema/1.0/like":
25                                 $bodyverb = t('%1$s likes %2$s\'s %3$s');
26                                 break;
27                         case "http://activitystrea.ms/schema/1.0/dislike":
28                                 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
29                                 break;
30                 }
31                 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
32                         
33         }
34         if ($item['verb']=='http://activitystrea.ms/schema/1.0/make-friend'){
35
36                 $b = str_replace("[/url]","[/url]\n", $item['body']);
37                 preg_match_all("|(\[url.*\[/url\])|", $b, $match);
38
39                 $item['body'] = $match[0][0]." "
40                                                 .t('is now friends with')
41                                                 ." ".$match[0][1]."\n\n\n"
42                                                 .$match[0][2];
43                 
44         }
45         
46 }
47
48 /**
49  * "Render" a conversation or list of items for HTML display.
50  * There are two major forms of display:
51  *      - Sequential or unthreaded ("New Item View" or search results)
52  *      - conversation view
53  * The $mode parameter decides between the various renderings and also
54  * figures out how to determine page owner and other contextual items 
55  * that are based on unique features of the calling module.
56  *
57  */
58 function conversation(&$a, $items, $mode, $update) {
59
60         require_once('bbcode.php');
61
62         $profile_owner = 0;
63         $page_writeable      = false;
64
65         if($mode === 'network') {
66                 $profile_owner = local_user();
67                 $page_writeable = true;
68         }
69
70         if($mode === 'profile') {
71                 $profile_owner = $a->profile['profile_uid'];
72                 $page_writeable = can_write_wall($a,$profile_owner);
73         }
74
75         if($mode === 'display') {
76                 $profile_owner = $a->profile['uid'];
77                 $page_writeable = can_write_wall($a,$profile_owner);
78         }
79
80         if($update)
81                 $return_url = $_SESSION['return_url'];
82         else
83                 $return_url = $_SESSION['return_url'] = $a->cmd;
84
85
86         // find all the authors involved in remote conversations
87         // We will use a local profile photo if they are one of our contacts
88         // otherwise we have to get the photo from the item owner's site
89
90         $author_contacts = extract_item_authors($items,local_user());
91
92
93         $cmnt_tpl    = load_view_file('view/comment_item.tpl');
94         $like_tpl    = load_view_file('view/like.tpl');
95         $noshare_tpl = load_view_file('view/like_noshare.tpl');
96         $tpl         = load_view_file('view/wall_item.tpl');
97         $wallwall    = load_view_file('view/wallwall_item.tpl');
98
99         $alike = array();
100         $dlike = array();
101         
102         if(count($items)) {
103
104                 if($mode === 'network-new' || $mode === 'search') {
105
106                         // "New Item View" on network page or search page results 
107                         // - just loop through the items and format them minimally for display
108
109                         $tpl = load_view_file('view/search_item.tpl');
110                         $droptpl = load_view_file('view/wall_fake_drop.tpl');
111
112                         foreach($items as $item) {
113
114                                 $comment     = '';
115                                 $owner_url   = '';
116                                 $owner_photo = '';
117                                 $owner_name  = '';
118                                 $sparkle     = '';
119
120                                 if($mode === 'search') {
121                                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
122                                                 && ($item['id'] != $item['parent']))
123                                                 continue;
124                                         $nickname = $item['nickname'];
125                                 }
126                                 else
127                                         $nickname = $a->user['nickname'];
128                         
129                                 $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
130                                 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
131                                 $profile_link   = ((strlen($item['author-link']))   ? $item['author-link']   : $item['url']);
132                                 if($profile_link === 'mailbox')
133                                         $profile_link = '';
134
135                                 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
136
137                                 if(strlen($item['author-link'])) {
138                                         if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
139                                                 $profile_link = $redirect_url;
140                                                 $sparkle = ' sparkle';
141                                         }
142                                         elseif(isset($author_contacts[$item['author-link']])) {
143                                                 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
144                                                 $sparkle = ' sparkle';
145                                         }
146                                 }
147
148                                 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
149                                 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
150                                 if($coord) {
151                                         if($location)
152                                                 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
153                                         else
154                                                 $location = '<span class="smalltext">' . $coord . '</span>';
155                                 }
156
157                                 $drop = '';
158                                 $dropping = false;
159
160                                 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
161                                         $dropping = true;
162
163                     $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
164
165                                 // 
166                                 localize_item($item);
167
168                                 $drop = replace_macros($droptpl,array('$id' => $item['id']));
169                                 $lock = '<div class="wall-item-lock"></div>';
170                                 
171                                 $o .= replace_macros($tpl,array(
172                                         '$id' => $item['item_id'],
173                                         '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
174                                         '$profile_url' => $profile_link,
175                                         '$item_photo_menu' => item_photo_menu($item),
176                                         '$name' => $profile_name,
177                                         '$sparkle' => $sparkle,
178                                         '$lock' => $lock,
179                                         '$thumb' => $profile_avatar,
180                                         '$title' => $item['title'],
181                                         '$body' => smilies(bbcode($item['body'])),
182                                         '$ago' => relative_date($item['created']),
183                                         '$location' => $location,
184                                         '$indent' => '',
185                                         '$owner_url' => $owner_url,
186                                         '$owner_photo' => $owner_photo,
187                                         '$owner_name' => $owner_name,
188                                         '$drop' => $drop,
189                                         '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
190                                 ));
191
192                         }
193
194                         return $o;
195                 }
196
197
198
199
200                 // Normal View
201
202
203                 // Figure out how many comments each parent has
204                 // (Comments all have gravity of 6)
205                 // Store the result in the $comments array
206
207                 $comments = array();
208                 foreach($items as $item) {
209                         if(intval($item['gravity']) == 6) {
210                                 if(! x($comments,$item['parent']))
211                                         $comments[$item['parent']] = 1;
212                                 else
213                                         $comments[$item['parent']] += 1;
214                         }
215                 }
216
217                 // map all the like/dislike activities for each parent item 
218                 // Store these in the $alike and $dlike arrays
219
220                 foreach($items as $item) {
221                         like_puller($a,$item,$alike,'like');
222                         like_puller($a,$item,$dlike,'dislike');
223                 }
224
225                 $comments_collapsed = false;
226                 $blowhard = 0;
227                 $blowhard_count = 0;
228
229                 foreach($items as $item) {
230
231                         $comment = '';
232                         $template = $tpl;
233                         $commentww = '';
234                         $sparkle = '';
235                         $owner_url = $owner_photo = $owner_name = '';
236
237                         // We've already parsed out like/dislike for special treatment. We can ignore them now
238
239                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) 
240                                 || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
241                                 && ($item['id'] != $item['parent']))
242                                 continue;
243
244                         $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
245
246
247                         // Take care of author collapsing and comment collapsing
248                         // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
249                         // If there are more than two comments, squash all but the last 2.
250
251                         if($toplevelpost) {
252
253                                 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
254
255                                 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
256                                         $blowhard_count ++;
257                                         if($blowhard_count == 3) {
258                                                 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] 
259                                                         . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >' 
260                                                         . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' 
261                                                         . $item['parent'] . '" style="display: none;" >';
262                                         }
263                                 }
264                                 else {
265                                         $blowhard = $item['cid'];                                       
266                                         if($blowhard_count >= 3)
267                                                 $o .= '</div>';
268                                         $blowhard_count = 0;
269                                 }
270
271                                 $comments_seen = 0;
272                                 $comments_collapsed = false;
273                         }
274                         else
275                                 $comments_seen ++;
276
277
278                         $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
279
280                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
281                                 if(! $comments_collapsed) {
282                                         $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] 
283                                                 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >' 
284                                                 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
285                                                 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
286                                         $comments_collapsed = true;
287                                 }
288                         }
289                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
290                                 $o .= '</div>';
291                         }
292
293                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
294
295                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
296                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
297                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
298                                 : '<div class="wall-item-lock"></div>');
299
300
301                         // Top-level wall post not written by the wall owner (wall-to-wall)
302                         // First figure out who owns it. 
303
304                         $osparkle = '';
305
306                         if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
307
308                                 if($item['type'] === 'wall') {
309
310                                         // On the network page, I am the owner. On the display page it will be the profile owner.
311                                         // This will have been stored in $a->page_contact by our calling page.
312                                         // Put this person on the left of the wall-to-wall notice.
313
314                                         $owner_url = $a->page_contact['url'];
315                                         $owner_photo = $a->page_contact['thumb'];
316                                         $owner_name = $a->page_contact['name'];
317                                         $template = $wallwall;
318                                         $commentww = 'ww';      
319                                 }
320                                 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
321
322                                         // Could be anybody. 
323
324                                         $owner_url = $item['owner-link'];
325                                         $owner_photo = $item['owner-avatar'];
326                                         $owner_name = $item['owner-name'];
327                                         $template = $wallwall;
328                                         $commentww = 'ww';
329                                         // If it is our contact, use a friendly redirect link
330                                         if((link_compare($item['owner-link'],$item['url'])) 
331                                                 && ($item['network'] === 'dfrn')) {
332                                                 $owner_url = $redirect_url;
333                                                 $osparkle = ' sparkle';
334                                         }
335                                 }
336                         }
337
338
339                         $likebuttons = '';
340
341                         if($page_writeable) {
342                                 if($toplevelpost) {
343                                         $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
344                                                 '$id' => $item['id'],
345                                                 '$likethis' => t("I like this \x28toggle\x29"),
346                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
347                                                 '$share' => t('Share'),
348                                                 '$wait' => t('Please wait') 
349                                         ));
350                                 }
351
352                                 if(($show_comment_box) || (($show_comment_box == false) && ($item['last-child']))) {
353                                         $comment = replace_macros($cmnt_tpl,array(
354                                                 '$return_path' => '', 
355                                                 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
356                                                 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
357                                                 '$id' => $item['item_id'],
358                                                 '$parent' => $item['parent'],
359                                                 '$profile_uid' =>  $profile_owner,
360                                                 '$mylink' => $a->contact['url'],
361                                                 '$mytitle' => t('This is you'),
362                                                 '$myphoto' => $a->contact['thumb'],
363                                                 '$comment' => t('Comment'),
364                                                 '$submit' => t('Submit'),
365                                                 '$ww' => (($mode === 'network') ? $commentww : '')
366                                         ));
367                                 }
368                         }
369
370                         $edpost = ((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1))
371                                         ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] 
372                                                 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
373                                         : '');
374                         $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
375
376                         $photo = $item['photo'];
377                         $thumb = $item['thumb'];
378
379                         // Post was remotely authored.
380
381                         $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
382
383                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
384                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
385
386                         if($mode === 'profile') {
387                                 if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
388                         $profile_link = $redirect_url;
389                     $sparkle = ' sparkle';
390                     }
391                                 else {
392                                         $profile_link = $item['url'];
393                                         $sparkle = '';
394                                 }
395                         }
396                         elseif(strlen($item['author-link'])) {
397                                 $profile_link = $item['author-link'];
398                                 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
399                                         $profile_link = $redirect_url;
400                                         $sparkle = ' sparkle';
401                                 }
402                                 elseif(isset($author_contacts[$item['author-link']])) {
403                                         $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
404                                         $sparkle = ' sparkle';
405                                 }
406                         }
407                         else 
408                                 $profile_link = $item['url'];
409
410                         if($profile_link === 'mailbox')
411                                 $profile_link = '';
412
413                         $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
414                         $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
415
416                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] 
417                                 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
418                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] 
419                                 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
420                         if($coord) {
421                                 if($location)
422                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
423                                 else
424                                         $location = '<span class="smalltext">' . $coord . '</span>';
425                         }
426
427                         $indent = (($toplevelpost) ? '' : ' comment');
428
429                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
430                                 $indent .= ' shiny'; 
431
432                         // 
433                         localize_item($item);
434
435                         // Build the HTML
436
437                         $tmp_item = replace_macros($template,array(
438                                 '$id' => $item['item_id'],
439                                 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
440                                 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
441                                 '$to' => t('to'),
442                                 '$wall' => t('Wall-to-Wall'),
443                                 '$vwall' => t('via Wall-To-Wall:'),
444                                 '$profile_url' => $profile_link,
445                                 '$item_photo_menu' => item_photo_menu($item),
446                                 '$name' => $profile_name,
447                                 '$thumb' => $profile_avatar,
448                                 '$osparkle' => $osparkle,
449                                 '$sparkle' => $sparkle,
450                                 '$title' => $item['title'],
451                                 '$body' => smilies(bbcode($item['body'])),
452                                 '$ago' => relative_date($item['created']),
453                                 '$lock' => $lock,
454                                 '$location' => $location,
455                                 '$indent' => $indent,
456                                 '$owner_url' => $owner_url,
457                                 '$owner_photo' => $owner_photo,
458                                 '$owner_name' => $owner_name,
459                                 '$plink' => get_plink($item),
460                                 '$edpost' => $edpost,
461                                 '$drop' => $drop,
462                                 '$vote' => $likebuttons,
463                                 '$like' => $like,
464                                 '$dislike' => $dislike,
465                                 '$comment' => $comment
466                         ));
467
468                         $arr = array('item' => $item, 'output' => $tmp_item);
469                         call_hooks('display_item', $arr);
470
471                         $o .= $arr['output'];
472
473                 }
474         }
475
476
477         // if author collapsing is in force but didn't get closed, close it off now.
478
479         if($blowhard_count >= 3)
480                 $o .= '</div>';
481
482         return $o;
483
484
485
486
487
488 if(! function_exists('extract_item_authors')) {
489 function extract_item_authors($arr,$uid) {
490
491         if((! $uid) || (! is_array($arr)) || (! count($arr)))
492                 return array();
493         $urls = array();
494         foreach($arr as $rr) {
495                 if(! in_array("'" . dbesc($rr['author-link']) . "'",$urls))
496                         $urls[] = "'" . dbesc($rr['author-link']) . "'";
497         }
498
499         // pre-quoted, don't put quotes on %s
500         if(count($urls)) {
501                 $r = q("SELECT `id`,`network`,`url` FROM `contact` WHERE `uid` = %d AND `url` IN ( %s )  AND `self` = 0 AND `blocked` = 0 ",
502                         intval($uid),
503                         implode(',',$urls)
504                 );
505                 if(count($r)) {
506                         $ret = array();
507                         $authors = array();
508                         foreach($r as $rr){
509                                 if ($rr['network']=='dfrn')
510                                         $ret[$rr['url']] = $rr['id'];
511                                 $authors[$r['url']]= $rr;
512                         }
513                         $a->authors = $authors;
514                         return $ret;
515                 }
516         }
517         return array();         
518 }}
519
520 if(! function_exists('item_photo_menu')){
521 function item_photo_menu($item){
522         $a = get_app();
523         
524         if (!isset($a->authors)){
525                 $rr = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `uid`=%d AND `self`=0 AND `blocked`=0 ", intval(local_user()));
526                 $authors = array();
527                 foreach($rr as $r) $authors[$r['url']]= $r;
528                 $a->authors = $authors;
529         }
530         
531         $contact_url="";
532         $pm_url="";
533
534         $status_link="";
535         $photo_link="";
536         $profile_link   = ((strlen($item['author-link']))   ? $item['author-link'] : $item['url']);
537         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
538
539         if($profile_link === 'mailbox')
540                 $profile_link = '';
541
542         // $item['contact-uid'] is only set on profile page and indicates the uid of the user who owns the profile.
543
544         $profile_owner = ((x($item,'contact-uid')) && intval($item['contact-uid']) ? intval($item['contact-uid']) : 0); 
545
546         // So we are checking that this is a logged in user on some page that *isn't* a profile page
547         // OR a profile page where the viewer owns the profile. 
548         // Then check if we can use a sparkle (redirect) link to the profile by virtue of it being our contact
549         // or a friend's contact that we both have a connection to. 
550
551         if((local_user() && ($profile_owner == 0)) 
552                 || ($profile_owner && $profile_owner == local_user())) {
553
554                 if(strlen($item['author-link']) && link_compare($item['author-link'],$item['url'])) {
555                         $redir = $redirect_url;
556                         $cid = $item['cid'];
557                 }
558                 elseif(isset($a->authors[$item['author-link']])) {
559                         $redir = $a->get_baseurl() . '/redir/' . $a->authors[$item['author-link']]['id'];
560                         $cid = $a->authors[$item['author-link']]['id'];
561                 }
562                 if($item['author-link'] === 'mailbox')
563                         $cid = $item['cid'];
564
565                 if((isset($cid)) && (! $item['self'])) {
566                         $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
567                         if($item['network'] === 'dfrn') {
568                                 $status_link = $redir . "?url=status";
569                                 $profile_link = $redir . "?url=profile";
570                                 $photos_link = $redir . "?url=photos";
571                                 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
572                         }
573                 }
574         }
575
576
577         $menu = Array(
578                 t("View status") => $status_link,
579                 t("View profile") => $profile_link,
580                 t("View photos") => $photos_link,               
581                 t("Edit contact") => $contact_url,
582                 t("Send PM") => $pm_url,
583         );
584         
585         
586         $args = array($item, &$menu);
587         
588         call_hooks('item_photo_menu', $args);
589         
590         $o = "";
591         foreach($menu as $k=>$v){
592                 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
593         }
594         return $o;
595 }}
596
597 if(! function_exists('like_puller')) {
598 function like_puller($a,$item,&$arr,$mode) {
599
600         $url = '';
601         $sparkle = '';
602         $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
603
604         if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
605                 $url = $item['author-link'];
606                 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
607                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
608                         $sparkle = ' class="sparkle" ';
609                 }
610                 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
611                         $arr[$item['parent'] . '-l'] = array();
612                 if(! isset($arr[$item['parent']]))
613                         $arr[$item['parent']] = 1;
614                 else    
615                         $arr[$item['parent']] ++;
616                 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
617         }
618         return;
619 }}
620
621 // Format the like/dislike text for a profile item
622 // $cnt = number of people who like/dislike the item
623 // $arr = array of pre-linked names of likers/dislikers
624 // $type = one of 'like, 'dislike'
625 // $id  = item id
626 // returns formatted text
627
628 if(! function_exists('format_like')) {
629 function format_like($cnt,$arr,$type,$id) {
630         $o = '';
631         if($cnt == 1)
632                 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
633         else {
634                 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
635                 $o .= (($type === 'like') ? 
636                                         sprintf( t('<span  %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
637                                          : 
638                                         sprintf( t('<span  %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) ); 
639                 $o .= EOL ;
640                 $total = count($arr);
641                 if($total >= MAX_LIKERS)
642                         $arr = array_slice($arr, 0, MAX_LIKERS - 1);
643                 if($total < MAX_LIKERS)
644                         $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
645                 $str = implode(', ', $arr);
646                 if($total >= MAX_LIKERS)
647                         $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
648                 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
649                 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
650         }
651         return $o;
652 }}