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