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