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