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