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