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