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