]> git.mxchange.org Git - friendica.git/blob - include/conversation.php
Fix missing wrapping span on bbcode to html, split embed data fetch and rappresentati...
[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                 if ($item['object-type']=="" || $item['object-type']!='http://activitystrea.ms/schema/1.0/person') return;
37
38                 $Aname = $item['author-name'];
39                 $Alink = $item['author-link'];
40                 
41                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
42                 
43                 $obj = parse_xml_string($xmlhead.$item['object']);
44                 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
45                 
46                 $Bname = $obj->title;
47                 $Blink = ""; $Bphoto = "";
48                 foreach ($links->link as $l){
49                         $atts = $l->attributes();
50                         switch($atts['rel']){
51                                 case "alternate": $Blink = $atts['href'];
52                                 case "photo": $Bphoto = $atts['href'];
53                         }
54                         
55                 }
56                 
57                 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
58                 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
59                 if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
60
61                 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
62
63         }
64         
65 }
66
67 /**
68  * "Render" a conversation or list of items for HTML display.
69  * There are two major forms of display:
70  *      - Sequential or unthreaded ("New Item View" or search results)
71  *      - conversation view
72  * The $mode parameter decides between the various renderings and also
73  * figures out how to determine page owner and other contextual items 
74  * that are based on unique features of the calling module.
75  *
76  */
77 function conversation(&$a, $items, $mode, $update) {
78
79         require_once('bbcode.php');
80
81         $profile_owner = 0;
82         $page_writeable      = false;
83
84         if($mode === 'network') {
85                 $profile_owner = local_user();
86                 $page_writeable = true;
87         }
88
89         if($mode === 'profile') {
90                 $profile_owner = $a->profile['profile_uid'];
91                 $page_writeable = can_write_wall($a,$profile_owner);
92         }
93
94         if($mode === 'notes') {
95                 $profile_owner = $a->profile['profile_uid'];
96                 $page_writeable = true;
97         }
98
99         if($mode === 'display') {
100                 $profile_owner = $a->profile['uid'];
101                 $page_writeable = can_write_wall($a,$profile_owner);
102         }
103
104         if($update)
105                 $return_url = $_SESSION['return_url'];
106         else
107                 $return_url = $_SESSION['return_url'] = $a->cmd;
108
109         load_contact_links(local_user());
110
111
112         $cmnt_tpl    = get_markup_template('comment_item.tpl');
113         $like_tpl    = get_markup_template('like.tpl');
114         $noshare_tpl = get_markup_template('like_noshare.tpl');
115         $tpl         = get_markup_template('wall_item.tpl');
116         $wallwall    = get_markup_template('wallwall_item.tpl');
117
118         $alike = array();
119         $dlike = array();
120         
121         if(count($items)) {
122
123                 if($mode === 'network-new' || $mode === 'search') {
124
125                         // "New Item View" on network page or search page results 
126                         // - just loop through the items and format them minimally for display
127
128                         $tpl = get_markup_template('search_item.tpl');
129                         $droptpl = get_markup_template('wall_fake_drop.tpl');
130
131                         foreach($items as $item) {
132
133                                 $comment     = '';
134                                 $owner_url   = '';
135                                 $owner_photo = '';
136                                 $owner_name  = '';
137                                 $sparkle     = '';
138
139                                 if($mode === 'search') {
140                                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
141                                                 && ($item['id'] != $item['parent']))
142                                                 continue;
143                                         $nickname = $item['nickname'];
144                                 }
145                                 else
146                                         $nickname = $a->user['nickname'];
147                         
148                                 $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
149
150                                 $sp = false;
151                                 $profile_link = best_link_url($item,$sp);
152                                 if($sp)
153                                         $sparkle = ' sparkle';
154                                 if($profile_link === 'mailbox')
155                                         $profile_link = '';
156
157
158                                 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
159                                 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
160                                         $profile_avatar = $a->contacts[$normalised]['thumb'];
161                                 else
162                                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
163
164                                 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
165                                 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
166                                 if($coord) {
167                                         if($location)
168                                                 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
169                                         else
170                                                 $location = '<span class="smalltext">' . $coord . '</span>';
171                                 }
172
173                                 $drop = '';
174                                 $dropping = false;
175
176                                 if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
177                                         $dropping = true;
178
179                     $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
180
181                                 // 
182                                 localize_item($item);
183
184                                 $drop = replace_macros($droptpl,array('$id' => $item['id']));
185                                 $lock = '<div class="wall-item-lock"></div>';
186                                 
187                                 $o .= replace_macros($tpl,array(
188                                         '$id' => $item['item_id'],
189                                         '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
190                                         '$profile_url' => $profile_link,
191                                         '$item_photo_menu' => item_photo_menu($item),
192                                         '$name' => $profile_name,
193                                         '$sparkle' => $sparkle,
194                                         '$lock' => $lock,
195                                         '$thumb' => $profile_avatar,
196                                         '$title' => $item['title'],
197                                         '$body' => smilies(bbcode($item['body'])),
198                                         '$ago' => relative_date($item['created']),
199                                         '$location' => $location,
200                                         '$indent' => '',
201                                         '$owner_url' => $owner_url,
202                                         '$owner_photo' => $owner_photo,
203                                         '$owner_name' => $owner_name,
204                                         '$drop' => $drop,
205                                         '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
206                                 ));
207
208                         }
209
210                         return $o;
211                 }
212
213
214
215
216                 // Normal View
217
218
219                 // Figure out how many comments each parent has
220                 // (Comments all have gravity of 6)
221                 // Store the result in the $comments array
222
223                 $comments = array();
224                 foreach($items as $item) {
225                         if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
226                                 if(! x($comments,$item['parent']))
227                                         $comments[$item['parent']] = 1;
228                                 else
229                                         $comments[$item['parent']] += 1;
230                         }
231                 }
232
233                 // map all the like/dislike activities for each parent item 
234                 // Store these in the $alike and $dlike arrays
235
236                 foreach($items as $item) {
237                         like_puller($a,$item,$alike,'like');
238                         like_puller($a,$item,$dlike,'dislike');
239                 }
240
241                 $comments_collapsed = false;
242                 $blowhard = 0;
243                 $blowhard_count = 0;
244
245                 foreach($items as $item) {
246
247                         $comment = '';
248                         $template = $tpl;
249                         $commentww = '';
250                         $sparkle = '';
251                         $owner_url = $owner_photo = $owner_name = '';
252
253                         // We've already parsed out like/dislike for special treatment. We can ignore them now
254
255                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) 
256                                 || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
257                                 && ($item['id'] != $item['parent']))
258                                 continue;
259
260                         $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
261
262
263                         // Take care of author collapsing and comment collapsing
264                         // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
265                         // If there are more than two comments, squash all but the last 2.
266
267                         if($toplevelpost) {
268
269                                 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
270
271                                 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
272                                         $blowhard_count ++;
273                                         if($blowhard_count == 3) {
274                                                 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] 
275                                                         . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
276                                                         . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' 
277                                                         . $item['parent'] . '" style="display: none;" >';
278                                         }
279                                 }
280                                 else {
281                                         $blowhard = $item['cid'];                                       
282                                         if($blowhard_count >= 3)
283                                                 $o .= '</div>';
284                                         $blowhard_count = 0;
285                                 }
286
287                                 $comments_seen = 0;
288                                 $comments_collapsed = false;
289                         }
290                         else
291                                 $comments_seen ++;
292
293
294                         $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
295                         $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
296
297                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
298                                 if(! $comments_collapsed) {
299                                         $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] 
300                                                 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
301                                                 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
302                                                 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
303                                         $comments_collapsed = true;
304                                 }
305                         }
306                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
307                                 $o .= '</div>';
308                         }
309
310                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
311
312                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
313                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
314                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
315                                 : '<div class="wall-item-lock"></div>');
316
317
318                         // Top-level wall post not written by the wall owner (wall-to-wall)
319                         // First figure out who owns it. 
320
321                         $osparkle = '';
322
323                         if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
324
325                                 if($item['type'] === 'wall') {
326
327                                         // On the network page, I am the owner. On the display page it will be the profile owner.
328                                         // This will have been stored in $a->page_contact by our calling page.
329                                         // Put this person on the left of the wall-to-wall notice.
330
331                                         $owner_url = $a->page_contact['url'];
332                                         $owner_photo = $a->page_contact['thumb'];
333                                         $owner_name = $a->page_contact['name'];
334                                         $template = $wallwall;
335                                         $commentww = 'ww';      
336                                 }
337                                 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
338
339                                         // Could be anybody. 
340
341                                         $owner_url = $item['owner-link'];
342                                         $owner_photo = $item['owner-avatar'];
343                                         $owner_name = $item['owner-name'];
344                                         $template = $wallwall;
345                                         $commentww = 'ww';
346                                         // If it is our contact, use a friendly redirect link
347                                         if((link_compare($item['owner-link'],$item['url'])) 
348                                                 && ($item['network'] === 'dfrn')) {
349                                                 $owner_url = $redirect_url;
350                                                 $osparkle = ' sparkle';
351                                         }
352                                 }
353                         }
354
355
356                         $likebuttons = '';
357
358                         if($page_writeable) {
359                                 if($toplevelpost) {
360                                         $likebuttons = replace_macros((($item['private'] || ($profile_owner != local_user())) ? $noshare_tpl : $like_tpl),array(
361                                                 '$id' => $item['id'],
362                                                 '$likethis' => t("I like this \x28toggle\x29"),
363                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
364                                                 '$share' => t('Share'),
365                                                 '$wait' => t('Please wait') 
366                                         ));
367                                 }
368
369                                 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
370                                         $comment = replace_macros($cmnt_tpl,array(
371                                                 '$return_path' => '', 
372                                                 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
373                                                 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
374                                                 '$id' => $item['item_id'],
375                                                 '$parent' => $item['parent'],
376                                                 '$profile_uid' =>  $profile_owner,
377                                                 '$mylink' => $a->contact['url'],
378                                                 '$mytitle' => t('This is you'),
379                                                 '$myphoto' => $a->contact['thumb'],
380                                                 '$comment' => t('Comment'),
381                                                 '$submit' => t('Submit'),
382                                                 '$ww' => (($mode === 'network') ? $commentww : '')
383                                         ));
384                                 }
385                         }
386
387                         $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
388                                         ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] 
389                                                 . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
390                                         : '');
391                         $drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
392
393                         $photo = $item['photo'];
394                         $thumb = $item['thumb'];
395
396                         // Post was remotely authored.
397
398                         $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
399
400                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
401
402                         $sp = false;
403                         $profile_link = best_link_url($item,$sp);
404                         if($sp)
405                                 $sparkle = ' sparkle';
406
407                         if($profile_link === 'mailbox')
408                                 $profile_link = '';
409
410                         $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
411                         if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
412                                 $profile_avatar = $a->contacts[$normalised]['thumb'];
413                         else
414                                 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
415
416
417
418
419
420                         $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
421                         $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
422
423                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] 
424                                 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
425                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] 
426                                 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
427                         if($coord) {
428                                 if($location)
429                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
430                                 else
431                                         $location = '<span class="smalltext">' . $coord . '</span>';
432                         }
433
434                         $indent = (($toplevelpost) ? '' : ' comment');
435
436                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
437                                 $indent .= ' shiny'; 
438
439                         // 
440                         localize_item($item);
441
442                         // Build the HTML
443
444                         $tmp_item = replace_macros($template,array(
445                                 '$id' => $item['item_id'],
446                                 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
447                                 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
448                                 '$to' => t('to'),
449                                 '$wall' => t('Wall-to-Wall'),
450                                 '$vwall' => t('via Wall-To-Wall:'),
451                                 '$profile_url' => $profile_link,
452                                 '$item_photo_menu' => item_photo_menu($item),
453                                 '$name' => $profile_name,
454                                 '$thumb' => $profile_avatar,
455                                 '$osparkle' => $osparkle,
456                                 '$sparkle' => $sparkle,
457                                 '$title' => $item['title'],
458                                 '$body' => smilies(bbcode($item['body'])),
459                                 '$ago' => relative_date($item['created']),
460                                 '$lock' => $lock,
461                                 '$location' => $location,
462                                 '$indent' => $indent,
463                                 '$owner_url' => $owner_url,
464                                 '$owner_photo' => $owner_photo,
465                                 '$owner_name' => $owner_name,
466                                 '$plink' => get_plink($item),
467                                 '$edpost' => $edpost,
468                                 '$drop' => $drop,
469                                 '$vote' => $likebuttons,
470                                 '$like' => $like,
471                                 '$dislike' => $dislike,
472                                 '$comment' => $comment
473                         ));
474
475                         $arr = array('item' => $item, 'output' => $tmp_item);
476                         call_hooks('display_item', $arr);
477
478                         $o .= $arr['output'];
479
480                 }
481         }
482
483
484         // if author collapsing is in force but didn't get closed, close it off now.
485
486         if($blowhard_count >= 3)
487                 $o .= '</div>';
488
489         return $o;
490
491
492
493 if(! function_exists('load_contact_links')) {
494 function load_contact_links($uid) {
495
496         $a = get_app();
497
498         $ret = array();
499
500         if(! $uid || x($a->contacts,'empty'))
501                 return;
502
503         $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
504                         intval($uid)
505         );
506         if(count($r)) {
507                 foreach($r as $rr){
508                         $url = normalise_link($rr['url']);
509                         $ret[$url] = $rr;
510                 }
511         }
512         else 
513                 $ret['empty'] = true;   
514         $a->contacts = $ret;
515         return;         
516 }}
517
518
519 function best_link_url($item,&$sparkle) {
520
521         $a = get_app();
522
523         $best_url = '';
524         $sparkle  = false;
525
526         $clean_url = normalise_link($item['author-link']);
527
528         if((local_user()) && (local_user() == $item['uid'])) {
529                 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
530                         if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
531                                 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
532                                 $sparkle = true;
533                         }
534                         else
535                                 $best_url = $a->contacts[$clean_url]['url'];
536                 }
537         }
538         if(! $best_url) {
539                 if(strlen($item['author-link']))
540                         $best_url = $item['author-link'];
541                 else
542                         $best_url = $item['url'];
543         }
544
545         return $best_url;
546 }
547
548
549 if(! function_exists('item_photo_menu')){
550 function item_photo_menu($item){
551         $a = get_app();
552         
553         if (local_user() && (! count($a->contacts)))
554                 load_contact_links(local_user());
555
556         $contact_url="";
557         $pm_url="";
558         $status_link="";
559         $photos_link="";
560         $posts_link="";
561
562         $sparkle = false;
563     $profile_link = best_link_url($item,$sparkle);
564         if($profile_link === 'mailbox')
565                 $profile_link = '';
566
567         if($sparkle) {
568                 $cid = intval(basename($profile_link));
569                 $status_link = $profile_link . "?url=status";
570                 $photos_link = $profile_link . "?url=photos";
571                 $profile_link = $profile_link . "?url=profile";
572                 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
573         }
574         else {
575                 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
576                         $cid = $item['contact-id'];
577                 }               
578                 else {
579                         $cid = 0;
580                 }
581         }
582         if(($cid) && (! $item['self'])) {
583                 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
584                 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
585         }
586
587         $menu = Array(
588                 t("View status") => $status_link,
589                 t("View profile") => $profile_link,
590                 t("View photos") => $photos_link,               
591                 t("View recent") => $posts_link, 
592                 t("Edit contact") => $contact_url,
593                 t("Send PM") => $pm_url,
594         );
595         
596         
597         $args = array($item, &$menu);
598         
599         call_hooks('item_photo_menu', $args);
600         
601         $o = "";
602         foreach($menu as $k=>$v){
603                 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
604         }
605         return $o;
606 }}
607
608 if(! function_exists('like_puller')) {
609 function like_puller($a,$item,&$arr,$mode) {
610
611         $url = '';
612         $sparkle = '';
613         $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
614
615         if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
616                 $url = $item['author-link'];
617                 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
618                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
619                         $sparkle = ' class="sparkle" ';
620                 }
621                 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
622                         $arr[$item['parent'] . '-l'] = array();
623                 if(! isset($arr[$item['parent']]))
624                         $arr[$item['parent']] = 1;
625                 else    
626                         $arr[$item['parent']] ++;
627                 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
628         }
629         return;
630 }}
631
632 // Format the like/dislike text for a profile item
633 // $cnt = number of people who like/dislike the item
634 // $arr = array of pre-linked names of likers/dislikers
635 // $type = one of 'like, 'dislike'
636 // $id  = item id
637 // returns formatted text
638
639 if(! function_exists('format_like')) {
640 function format_like($cnt,$arr,$type,$id) {
641         $o = '';
642         if($cnt == 1)
643                 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
644         else {
645                 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
646                 $o .= (($type === 'like') ? 
647                                         sprintf( t('<span  %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
648                                          : 
649                                         sprintf( t('<span  %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) ); 
650                 $o .= EOL ;
651                 $total = count($arr);
652                 if($total >= MAX_LIKERS)
653                         $arr = array_slice($arr, 0, MAX_LIKERS - 1);
654                 if($total < MAX_LIKERS)
655                         $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
656                 $str = implode(', ', $arr);
657                 if($total >= MAX_LIKERS)
658                         $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
659                 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
660                 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
661         }
662         return $o;
663 }}
664
665
666 function status_editor($a,$x, $notes_cid = 0) {
667
668         $o = '';
669                 
670         $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
671
672                 $tpl = get_markup_template('jot-header.tpl');
673         
674                 $a->page['htmlhead'] .= replace_macros($tpl, array(
675                         '$baseurl' => $a->get_baseurl(),
676                         '$geotag' => $geotag,
677                         '$nickname' => $x['nickname'],
678                         '$ispublic' => t('Visible to <strong>everybody</strong>'),
679                         '$linkurl' => t('Please enter a link URL:'),
680                         '$utubeurl' => t('Please enter a YouTube link:'),
681                         '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
682                         '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
683                         '$whereareu' => t('Where are you right now?'),
684                         '$title' => t('Enter a title for this item') 
685                 ));
686
687
688                 $tpl = get_markup_template("jot.tpl");
689                 
690                 $jotplugins = '';
691                 $jotnets = '';
692
693                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
694
695                 $mail_enabled = false;
696                 $pubmail_enabled = false;
697
698                 if(($x['is_owner']) && (! $mail_disabled)) {
699                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
700                                 intval(local_user())
701                         );
702                         if(count($r)) {
703                                 $mail_enabled = true;
704                                 if(intval($r[0]['pubmail']))
705                                         $pubmail_enabled = true;
706                         }
707                 }
708
709                 if($mail_enabled) {
710                $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
711                         $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
712                 . t("Post to Email") . '</div>';
713                 }
714
715                 call_hooks('jot_tool', $jotplugins);
716                 call_hooks('jot_networks', $jotnets);
717
718                 if($notes_cid)
719                         $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
720
721                 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
722
723                 $o .= replace_macros($tpl,array(
724                         '$return_path' => $a->cmd,
725                         '$action' => 'item',
726                         '$share' => (($x['button']) ? $x['button'] : t('Share')),
727                         '$upload' => t('Upload photo'),
728                         '$weblink' => t('Insert web link'),
729                         '$youtube' => t('Insert YouTube video'),
730                         '$video' => t('Insert Vorbis [.ogg] video'),
731                         '$audio' => t('Insert Vorbis [.ogg] audio'),
732                         '$setloc' => t('Set your location'),
733                         '$noloc' => t('Clear browser location'),
734                         '$title' => t('Set title'),
735                         '$wait' => t('Please wait'),
736                         '$permset' => t('Permission settings'),
737                         '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
738                         '$content' => '',
739                         '$post_id' => '',
740                         '$baseurl' => $a->get_baseurl(),
741                         '$defloc' => $x['default_location'],
742                         '$visitor' => $x['visitor'],
743                         '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
744                         '$emailcc' => t('CC: email addresses'),
745                         '$public' => t('Public post'),
746                         '$jotnets' => $jotnets,
747                         '$emtitle' => t('Example: bob@example.com, mary@example.com'),
748                         '$lockstate' => $x['lockstate'],
749                         '$acl' => $x['acl'],
750                         '$bang' => $x['bang'],
751                         '$profile_uid' => $x['profile_uid'],
752                 ));
753
754         return $o;
755 }