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