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