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