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