]> git.mxchange.org Git - friendica.git/blob - include/conversation.php
diaspora share - blocked specified twice
[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                         $toplevelprivate = false;
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                                 $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
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                                 // prevent private email from leaking into public conversation
317                                 if((! $toplevelpost) && (! toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
318                                         continue;
319                                 $comments_seen ++;
320                         }       
321
322                         $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
323                         $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
324
325                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
326                                 if(! $comments_collapsed) {
327                                         $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] 
328                                                 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
329                                                 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
330                                                 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
331                                         $comments_collapsed = true;
332                                 }
333                         }
334                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
335                                 $o .= '</div>';
336                         }
337
338                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
339
340                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
341                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
342                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
343                                 : '<div class="wall-item-lock"></div>');
344
345
346                         // Top-level wall post not written by the wall owner (wall-to-wall)
347                         // First figure out who owns it. 
348
349                         $osparkle = '';
350
351                         if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
352
353                                 if($item['wall']) {
354
355                                         // On the network page, I am the owner. On the display page it will be the profile owner.
356                                         // This will have been stored in $a->page_contact by our calling page.
357                                         // Put this person on the left of the wall-to-wall notice.
358
359                                         $owner_url = $a->page_contact['url'];
360                                         $owner_photo = $a->page_contact['thumb'];
361                                         $owner_name = $a->page_contact['name'];
362                                         $template = $wallwall;
363                                         $commentww = 'ww';      
364                                 }
365                                 if((! $item['wall']) && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
366
367                                         // Could be anybody. 
368
369                                         $owner_url = $item['owner-link'];
370                                         $owner_photo = $item['owner-avatar'];
371                                         $owner_name = $item['owner-name'];
372                                         $template = $wallwall;
373                                         $commentww = 'ww';
374                                         // If it is our contact, use a friendly redirect link
375                                         if((link_compare($item['owner-link'],$item['url'])) 
376                                                 && ($item['network'] === 'dfrn')) {
377                                                 $owner_url = $redirect_url;
378                                                 $osparkle = ' sparkle';
379                                         }
380                                 }
381                         }
382
383
384                         $likebuttons = '';
385
386                         if($page_writeable) {
387                                 if($toplevelpost) {
388                                         $likebuttons = replace_macros((($item['private'] || ($profile_owner != local_user())) ? $noshare_tpl : $like_tpl),array(
389                                                 '$id' => $item['id'],
390                                                 '$likethis' => t("I like this \x28toggle\x29"),
391                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
392                                                 '$share' => t('Share'),
393                                                 '$wait' => t('Please wait') 
394                                         ));
395                                 }
396
397                                 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
398                                         $comment = replace_macros($cmnt_tpl,array(
399                                                 '$return_path' => '', 
400                                                 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
401                                                 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
402                                                 '$id' => $item['item_id'],
403                                                 '$parent' => $item['parent'],
404                                                 '$profile_uid' =>  $profile_owner,
405                                                 '$mylink' => $a->contact['url'],
406                                                 '$mytitle' => t('This is you'),
407                                                 '$myphoto' => $a->contact['thumb'],
408                                                 '$comment' => t('Comment'),
409                                                 '$submit' => t('Submit'),
410                                                 '$ww' => (($mode === 'network') ? $commentww : '')
411                                         ));
412                                 }
413                         }
414
415                         $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
416                                         ? '<a class="editpost icon pencil" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] 
417                                                 . '" title="' . t('Edit') . '"></a>'
418                                         : '');
419
420
421                         $drop = '';
422                         $dropping = false;
423
424                         if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
425                                 $dropping = true;
426
427             $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$select' => t('Select'), '$delete' => t('Delete')));
428
429                         $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>' : '');
430
431
432                         $photo = $item['photo'];
433                         $thumb = $item['thumb'];
434
435                         // Post was remotely authored.
436
437                         $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
438
439                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
440
441                         $sp = false;
442                         $profile_link = best_link_url($item,$sp);
443                         if($sp)
444                                 $sparkle = ' sparkle';
445
446                         if($profile_link === 'mailbox')
447                                 $profile_link = '';
448
449                         $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
450                         if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
451                                 $profile_avatar = $a->contacts[$normalised]['thumb'];
452                         else
453                                 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
454
455
456
457
458
459                         $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
460                         $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
461
462                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] 
463                                 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
464                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] 
465                                 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
466                         if($coord) {
467                                 if($location)
468                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
469                                 else
470                                         $location = '<span class="smalltext">' . $coord . '</span>';
471                         }
472
473                         $indent = (($toplevelpost) ? '' : ' comment');
474
475                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
476                                 $indent .= ' shiny'; 
477
478                         // 
479                         localize_item($item);
480
481                         // Build the HTML
482
483                         $body = prepare_body($item,true);
484
485
486                         $tmp_item = replace_macros($template,array(
487                                 '$id' => $item['item_id'],
488                                 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
489                                 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
490                                 '$to' => t('to'),
491                                 '$wall' => t('Wall-to-Wall'),
492                                 '$vwall' => t('via Wall-To-Wall:'),
493                                 '$profile_url' => $profile_link,
494                                 '$item_photo_menu' => item_photo_menu($item),
495                                 '$name' => $profile_name,
496                                 '$thumb' => $profile_avatar,
497                                 '$osparkle' => $osparkle,
498                                 '$sparkle' => $sparkle,
499                                 '$title' => $item['title'],
500                                 '$body' => $body,
501                                 '$ago' => ((($item['app']) && ($item['id'] == $item['parent'])) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
502                                 '$lock' => $lock,
503                                 '$location' => $location,
504                                 '$indent' => $indent,
505                                 '$owner_url' => $owner_url,
506                                 '$owner_photo' => $owner_photo,
507                                 '$owner_name' => $owner_name,
508                                 '$plink' => get_plink($item),
509                                 '$edpost' => $edpost,
510                                 '$star' => $star,
511                                 '$drop' => $drop,
512                                 '$vote' => $likebuttons,
513                                 '$like' => $like,
514                                 '$dislike' => $dislike,
515                                 '$comment' => $comment
516                         ));
517
518
519                         $arr = array('item' => $item, 'output' => $tmp_item);
520                         call_hooks('display_item', $arr);
521
522                         $o .= $arr['output'];
523
524                 }
525         }
526
527
528         // if author collapsing is in force but didn't get closed, close it off now.
529
530         if($blowhard_count >= 3)
531                 $o .= '</div>';
532
533         if($dropping)
534                 $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>';
535
536         return $o;
537
538
539 function best_link_url($item,&$sparkle) {
540
541         $a = get_app();
542
543         $best_url = '';
544         $sparkle  = false;
545
546         $clean_url = normalise_link($item['author-link']);
547
548         if((local_user()) && (local_user() == $item['uid'])) {
549                 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
550                         if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
551                                 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
552                                 $sparkle = true;
553                         }
554                         else
555                                 $best_url = $a->contacts[$clean_url]['url'];
556                 }
557         }
558         if(! $best_url) {
559                 if(strlen($item['author-link']))
560                         $best_url = $item['author-link'];
561                 else
562                         $best_url = $item['url'];
563         }
564
565         return $best_url;
566 }
567
568
569 if(! function_exists('item_photo_menu')){
570 function item_photo_menu($item){
571         $a = get_app();
572         
573         if (local_user() && (! count($a->contacts)))
574                 load_contact_links(local_user());
575
576         $contact_url="";
577         $pm_url="";
578         $status_link="";
579         $photos_link="";
580         $posts_link="";
581
582         $sparkle = false;
583     $profile_link = best_link_url($item,$sparkle);
584         if($profile_link === 'mailbox')
585                 $profile_link = '';
586
587         if($sparkle) {
588                 $cid = intval(basename($profile_link));
589                 $status_link = $profile_link . "?url=status";
590                 $photos_link = $profile_link . "?url=photos";
591                 $profile_link = $profile_link . "?url=profile";
592                 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
593         }
594         else {
595                 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
596                         $cid = $item['contact-id'];
597                 }               
598                 else {
599                         $cid = 0;
600                 }
601         }
602         if(($cid) && (! $item['self'])) {
603                 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
604                 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
605         }
606
607         $menu = Array(
608                 t("View status") => $status_link,
609                 t("View profile") => $profile_link,
610                 t("View photos") => $photos_link,               
611                 t("View recent") => $posts_link, 
612                 t("Edit contact") => $contact_url,
613                 t("Send PM") => $pm_url,
614         );
615         
616         
617         $args = array($item, &$menu);
618         
619         call_hooks('item_photo_menu', $args);
620         
621         $o = "";
622         foreach($menu as $k=>$v){
623                 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
624         }
625         return $o;
626 }}
627
628 if(! function_exists('like_puller')) {
629 function like_puller($a,$item,&$arr,$mode) {
630
631         $url = '';
632         $sparkle = '';
633         $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
634
635         if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
636                 $url = $item['author-link'];
637                 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
638                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
639                         $sparkle = ' class="sparkle" ';
640                 }
641                 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
642                         $arr[$item['parent'] . '-l'] = array();
643                 if(! isset($arr[$item['parent']]))
644                         $arr[$item['parent']] = 1;
645                 else    
646                         $arr[$item['parent']] ++;
647                 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
648         }
649         return;
650 }}
651
652 // Format the like/dislike text for a profile item
653 // $cnt = number of people who like/dislike the item
654 // $arr = array of pre-linked names of likers/dislikers
655 // $type = one of 'like, 'dislike'
656 // $id  = item id
657 // returns formatted text
658
659 if(! function_exists('format_like')) {
660 function format_like($cnt,$arr,$type,$id) {
661         $o = '';
662         if($cnt == 1)
663                 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
664         else {
665                 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
666                 $o .= (($type === 'like') ? 
667                                         sprintf( t('<span  %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
668                                          : 
669                                         sprintf( t('<span  %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) ); 
670                 $o .= EOL ;
671                 $total = count($arr);
672                 if($total >= MAX_LIKERS)
673                         $arr = array_slice($arr, 0, MAX_LIKERS - 1);
674                 if($total < MAX_LIKERS)
675                         $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
676                 $str = implode(', ', $arr);
677                 if($total >= MAX_LIKERS)
678                         $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
679                 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
680                 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
681         }
682         return $o;
683 }}
684
685
686 function status_editor($a,$x, $notes_cid = 0) {
687
688         $o = '';
689                 
690         $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
691
692                 $tpl = get_markup_template('jot-header.tpl');
693         
694                 $a->page['htmlhead'] .= replace_macros($tpl, array(
695                         '$baseurl' => $a->get_baseurl(),
696                         '$geotag' => $geotag,
697                         '$nickname' => $x['nickname'],
698                         '$ispublic' => t('Visible to <strong>everybody</strong>'),
699                         '$linkurl' => t('Please enter a link URL:'),
700                         '$utubeurl' => t('Please enter a YouTube link:'),
701                         '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
702                         '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
703                         '$whereareu' => t('Where are you right now?'),
704                         '$title' => t('Enter a title for this item') 
705                 ));
706
707
708                 $tpl = get_markup_template("jot.tpl");
709                 
710                 $jotplugins = '';
711                 $jotnets = '';
712
713                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
714
715                 $mail_enabled = false;
716                 $pubmail_enabled = false;
717
718                 if(($x['is_owner']) && (! $mail_disabled)) {
719                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
720                                 intval(local_user())
721                         );
722                         if(count($r)) {
723                                 $mail_enabled = true;
724                                 if(intval($r[0]['pubmail']))
725                                         $pubmail_enabled = true;
726                         }
727                 }
728
729                 if($mail_enabled) {
730                $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
731                         $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
732                 . t("Post to Email") . '</div>';
733                 }
734
735                 call_hooks('jot_tool', $jotplugins);
736                 call_hooks('jot_networks', $jotnets);
737
738                 if($notes_cid)
739                         $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
740
741                 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
742
743                 $o .= replace_macros($tpl,array(
744                         '$return_path' => $a->cmd,
745                         '$action' => 'item',
746                         '$share' => (($x['button']) ? $x['button'] : t('Share')),
747                         '$upload' => t('Upload photo'),
748                         '$attach' => t('Attach file'),
749                         '$weblink' => t('Insert web link'),
750                         '$youtube' => t('Insert YouTube video'),
751                         '$video' => t('Insert Vorbis [.ogg] video'),
752                         '$audio' => t('Insert Vorbis [.ogg] audio'),
753                         '$setloc' => t('Set your location'),
754                         '$noloc' => t('Clear browser location'),
755                         '$title' => t('Set title'),
756                         '$wait' => t('Please wait'),
757                         '$permset' => t('Permission settings'),
758                         '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
759                         '$content' => '',
760                         '$post_id' => '',
761                         '$baseurl' => $a->get_baseurl(),
762                         '$defloc' => $x['default_location'],
763                         '$visitor' => $x['visitor'],
764                         '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
765                         '$emailcc' => t('CC: email addresses'),
766                         '$public' => t('Public post'),
767                         '$jotnets' => $jotnets,
768                         '$emtitle' => t('Example: bob@example.com, mary@example.com'),
769                         '$lockstate' => $x['lockstate'],
770                         '$acl' => $x['acl'],
771                         '$bang' => $x['bang'],
772                         '$profile_uid' => $x['profile_uid'],
773                 ));
774
775         return $o;
776 }