]> git.mxchange.org Git - friendica.git/blob - include/identity.php
Merge remote-tracking branch 'upstream/develop' into 1509-new-feed-import
[friendica.git] / include / identity.php
1 <?php
2
3
4 /**
5  *
6  * Function : profile_load
7  * @parameter App    $a
8  * @parameter string $nickname
9  * @parameter int    $profile
10  *
11  * Summary: Loads a profile into the page sidebar.
12  * The function requires a writeable copy of the main App structure, and the nickname
13  * of a registered local account.
14  *
15  * If the viewer is an authenticated remote viewer, the profile displayed is the
16  * one that has been configured for his/her viewing in the Contact manager.
17  * Passing a non-zero profile ID can also allow a preview of a selected profile
18  * by the owner.
19  *
20  * Profile information is placed in the App structure for later retrieval.
21  * Honours the owner's chosen theme for display.
22  *
23  * IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
24  * the theme is chosen before the _init() function of a theme is run, which will usually
25  * load a lot of theme-specific content
26  *
27  */
28
29 if(! function_exists('profile_load')) {
30         function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
31
32                 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
33                         dbesc($nickname)
34                 );
35
36                 if(!$user && count($user) && !count($profiledata)) {
37                         logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
38                         notice( t('Requested account is not available.') . EOL );
39                         $a->error = 404;
40                         return;
41                 }
42
43                 if(remote_user() && count($_SESSION['remote'])) {
44                         foreach($_SESSION['remote'] as $visitor) {
45                                 if($visitor['uid'] == $user[0]['uid']) {
46                                         $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
47                                                 intval($visitor['cid'])
48                                         );
49                                         if(count($r))
50                                                 $profile = $r[0]['profile-id'];
51                                         break;
52                                 }
53                         }
54                 }
55
56                 $r = null;
57
58                 if($profile) {
59                         $profile_int = intval($profile);
60                         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
61                                         INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
62                                         WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d and `contact`.`self` = 1 LIMIT 1",
63                                         dbesc($nickname),
64                                         intval($profile_int)
65                         );
66                 }
67                 if((!$r) && (!count($r))) {
68                         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
69                                         INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
70                                         WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
71                                         dbesc($nickname)
72                         );
73                 }
74
75                 if(($r === false) || (!count($r)) && !count($profiledata)) {
76                         logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
77                         notice( t('Requested profile is not available.') . EOL );
78                         $a->error = 404;
79                         return;
80                 }
81
82                 // fetch user tags if this isn't the default profile
83
84                 if(!$r[0]['is-default']) {
85                         $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1",
86                                         intval($r[0]['profile_uid'])
87                         );
88                         if($x && count($x))
89                                 $r[0]['pub_keywords'] = $x[0]['pub_keywords'];
90                 }
91
92                 $a->profile = $r[0];
93                 $a->profile_uid = $r[0]['profile_uid'];
94
95                 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
96                 $a->profile['network'] = NETWORK_DFRN;
97
98                 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
99
100 //              if (!$profiledata)
101 //                      $_SESSION['theme'] = $a->profile['theme'];
102
103                 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
104
105                 /**
106                  * load/reload current theme info
107                  */
108
109                 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
110
111                 $theme_info_file = "view/theme/".current_theme()."/theme.php";
112                 if (file_exists($theme_info_file)){
113                         require_once($theme_info_file);
114                 }
115
116                 if(! (x($a->page,'aside')))
117                         $a->page['aside'] = '';
118
119                 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
120                         $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
121                                 '$editprofile' => t('Edit profile'),
122                                 '$profid' => $a->profile['id']
123                         ));
124                 }
125
126                 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
127
128                 // To-Do:
129                 // By now, the contact block isn't shown, when a different profile is given
130                 // But: When this profile was on the same server, then we could display the contacts
131                 if ($profiledata)
132                         $a->page['aside'] .= profile_sidebar($profiledata, true);
133                 else
134                         $a->page['aside'] .= profile_sidebar($a->profile, $block);
135
136
137                 /*if(! $block)
138                  $a->page['aside'] .= contact_block();*/
139
140                 return;
141         }
142 }
143
144
145 /**
146  *
147  * Function: profile_sidebar
148  *
149  * Formats a profile for display in the sidebar.
150  * It is very difficult to templatise the HTML completely
151  * because of all the conditional logic.
152  *
153  * @parameter: array $profile
154  *
155  * Returns HTML string stuitable for sidebar inclusion
156  * Exceptions: Returns empty string if passed $profile is wrong type or not populated
157  *
158  */
159
160
161 if(! function_exists('profile_sidebar')) {
162         function profile_sidebar($profile, $block = 0) {
163                 $a = get_app();
164
165                 $o = '';
166                 $location = false;
167                 $address = false;
168                 $pdesc = true;
169
170                 if((! is_array($profile)) && (! count($profile)))
171                         return $o;
172
173                 $profile['picdate'] = urlencode($profile['picdate']);
174
175                 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
176                         require_once('include/contact_selectors.php');
177                         if ($profile['url'] != "")
178                                 $profile['network_name'] = '<a href="'.$profile['url'].'">'.network_to_name($profile['network'], $profile['url'])."</a>";
179                         else
180                                 $profile['network_name'] = network_to_name($profile['network']);
181                 } else
182                         $profile['network_name'] = "";
183
184                 call_hooks('profile_sidebar_enter', $profile);
185
186
187                 // don't show connect link to yourself
188                 $connect = (($profile['uid'] != local_user()) ? t('Connect')  : False);
189
190                 // don't show connect link to authenticated visitors either
191                 if(remote_user() && count($_SESSION['remote'])) {
192                         foreach($_SESSION['remote'] as $visitor) {
193                                 if($visitor['uid'] == $profile['uid']) {
194                                         $connect = false;
195                                         break;
196                                 }
197                         }
198                 }
199
200                 // Is the local user already connected to that user?
201                 if ($connect AND local_user()) {
202                         if (isset($profile["url"]))
203                                 $profile_url = normalise_link($profile["url"]);
204                         else
205                                 $profile_url = normalise_link($a->get_baseurl()."/profile/".$profile["nickname"]);
206
207                         $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
208                                 local_user(), $profile_url);
209                         if (count($r))
210                                 $connect = false;
211                 }
212
213                 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
214                                 $connect = false;
215
216                 if (isset($profile['remoteconnect']))
217                         $remoteconnect = $profile['remoteconnect'];
218
219                 if( get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()) )
220                         $wallmessage = t('Message');
221                 else
222                         $wallmessage = false;
223
224                 // show edit profile to yourself
225                 if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
226                         $profile['edit'] = array($a->get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
227                         $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
228                                         local_user());
229
230                         $profile['menu'] = array(
231                                 'chg_photo' => t('Change profile photo'),
232                                 'cr_new' => t('Create New Profile'),
233                                 'entries' => array(),
234                         );
235
236                         if(count($r)) {
237
238                                 foreach($r as $rr) {
239                                         $profile['menu']['entries'][] = array(
240                                                 'photo' => $rr['thumb'],
241                                                 'id' => $rr['id'],
242                                                 'alt' => t('Profile Image'),
243                                                 'profile_name' => $rr['profile-name'],
244                                                 'isdefault' => $rr['is-default'],
245                                                 'visibile_to_everybody' =>  t('visible to everybody'),
246                                                 'edit_visibility' => t('Edit visibility'),
247
248                                         );
249                                 }
250
251
252                         }
253                 }
254                 if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
255                         $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
256                         $profile['menu'] = array(
257                                 'chg_photo' => t('Change profile photo'),
258                                 'cr_new' => null,
259                                 'entries' => array(),
260                         );
261                 }
262
263                 if((x($profile,'address') == 1)
264                                 || (x($profile,'locality') == 1)
265                                 || (x($profile,'region') == 1)
266                                 || (x($profile,'postal-code') == 1)
267                                 || (x($profile,'country-name') == 1))
268                         $location = t('Location:');
269
270                 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
271
272
273                 $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
274
275                 $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
276
277                 $about = ((x($profile,'about') == 1) ?  t('About:') : False);
278
279                 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
280                         $location = $pdesc = $gender = $marital = $homepage = $about = False;
281                 }
282
283                 $firstname = ((strpos($profile['name'],' '))
284                                 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
285                 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
286
287                 $diaspora = array(
288                         'guid' => $profile['guid'],
289                         'podloc' => $a->get_baseurl(),
290                         'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
291                         'nickname' => $profile['nickname'],
292                         'fullname' => $profile['name'],
293                         'firstname' => $firstname,
294                         'lastname' => $lastname,
295                         'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
296                         'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
297                         'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg'),
298                 );
299
300                 if (!$block){
301                         $contact_block = contact_block();
302
303                         if(is_array($a->profile) AND !$a->profile['hide-friends']) {
304                                 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
305                                         intval($a->profile['uid']));
306                                 if(count($r))
307                                         $updated =  date("c", strtotime($r[0]['updated']));
308
309                                 $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0
310                                                 AND `network` IN ('%s', '%s', '%s', '')",
311                                         intval($profile['uid']),
312                                         dbesc(NETWORK_DFRN),
313                                         dbesc(NETWORK_DIASPORA),
314                                         dbesc(NETWORK_OSTATUS)
315                                 );
316                                 if(count($r))
317                                         $contacts = intval($r[0]['total']);
318                         }
319                 }
320
321                 $p = array();
322                 foreach($profile as $k => $v) {
323                         $k = str_replace('-','_',$k);
324                         $p[$k] = $v;
325                 }
326
327                 if($a->theme['template_engine'] === 'internal')
328                         $location = template_escape($location);
329
330                 $tpl = get_markup_template('profile_vcard.tpl');
331                 $o .= replace_macros($tpl, array(
332                         '$profile' => $p,
333                         '$connect'  => $connect,
334                         '$remoteconnect'  => $remoteconnect,
335                         '$wallmessage' => $wallmessage,
336                         '$location' => $location,
337                         '$gender'   => $gender,
338                         '$pdesc'        => $pdesc,
339                         '$marital'  => $marital,
340                         '$homepage' => $homepage,
341                         '$about' => $about,
342                         '$network' =>  t('Network:'),
343                         '$contacts' => $contacts,
344                         '$updated' => $updated,
345                         '$diaspora' => $diaspora,
346                         '$contact_block' => $contact_block,
347                 ));
348
349
350                 $arr = array('profile' => &$profile, 'entry' => &$o);
351
352                 call_hooks('profile_sidebar', $arr);
353
354                 return $o;
355         }
356 }
357
358
359 if(! function_exists('get_birthdays')) {
360         function get_birthdays() {
361
362                 $a = get_app();
363                 $o = '';
364
365                 if(! local_user() || $a->is_mobile || $a->is_tablet)
366                         return $o;
367
368 //              $mobile_detect = new Mobile_Detect();
369 //              $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
370
371 //              if($is_mobile)
372 //                      return $o;
373
374                 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
375                 $bd_short = t('F d');
376
377                 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
378                                 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
379                                 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
380                                 ORDER BY `start` ASC ",
381                                 intval(local_user()),
382                                 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
383                                 dbesc(datetime_convert('UTC','UTC','now'))
384                 );
385
386                 if($r && count($r)) {
387                         $total = 0;
388                         $now = strtotime('now');
389                         $cids = array();
390
391                         $istoday = false;
392                         foreach($r as $rr) {
393                                 if(strlen($rr['name']))
394                                         $total ++;
395                                 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
396                                         $istoday = true;
397                         }
398                         $classtoday = $istoday ? ' birthday-today ' : '';
399                         if($total) {
400                                 foreach($r as &$rr) {
401                                         if(! strlen($rr['name']))
402                                                 continue;
403
404                                         // avoid duplicates
405
406                                         if(in_array($rr['cid'],$cids))
407                                                 continue;
408                                         $cids[] = $rr['cid'];
409
410                                         $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
411                                         $sparkle = '';
412                                         $url = $rr['url'];
413                                         if($rr['network'] === NETWORK_DFRN) {
414                                                 $sparkle = " sparkle";
415                                                 $url = $a->get_baseurl() . '/redir/'  . $rr['cid'];
416                                         }
417
418                                         $rr['link'] = $url;
419                                         $rr['title'] = $rr['name'];
420                                         $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ?  ' ' . t('[today]') : '');
421                                         $rr['startime'] = Null;
422                                         $rr['today'] = $today;
423
424                                 }
425                         }
426                 }
427                 $tpl = get_markup_template("birthdays_reminder.tpl");
428                 return replace_macros($tpl, array(
429                         '$baseurl' => $a->get_baseurl(),
430                         '$classtoday' => $classtoday,
431                         '$count' => $total,
432                         '$event_reminders' => t('Birthday Reminders'),
433                         '$event_title' => t('Birthdays this week:'),
434                         '$events' => $r,
435                         '$lbr' => '{',  // raw brackets mess up if/endif macro processing
436                         '$rbr' => '}'
437
438                 ));
439         }
440 }
441
442
443 if(! function_exists('get_events')) {
444         function get_events() {
445
446                 require_once('include/bbcode.php');
447
448                 $a = get_app();
449
450                 if(! local_user() || $a->is_mobile || $a->is_tablet)
451                         return $o;
452
453
454 //              $mobile_detect = new Mobile_Detect();
455 //              $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
456
457 //              if($is_mobile)
458 //                      return $o;
459
460                 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
461                 $bd_short = t('F d');
462
463                 $r = q("SELECT `event`.* FROM `event`
464                                 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
465                                 ORDER BY `start` ASC ",
466                                 intval(local_user()),
467                                 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
468                                 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
469                 );
470
471                 if($r && count($r)) {
472                         $now = strtotime('now');
473                         $istoday = false;
474                         foreach($r as $rr) {
475                                 if(strlen($rr['name']))
476                                         $total ++;
477
478                                 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
479                                 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
480                                         $istoday = true;
481                         }
482                         $classtoday = (($istoday) ? 'event-today' : '');
483
484                         $skip = 0;
485
486                         foreach($r as &$rr) {
487                                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
488
489                                 if(strlen($title) > 35)
490                                         $title = substr($title,0,32) . '... ';
491
492                                 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
493                                 if(! $description)
494                                         $description = t('[No description]');
495
496                                 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
497
498                                 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
499                                         $skip++;
500                                         continue;
501                                 }
502
503                                 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
504                                 
505                                 $rr['title'] = $title;
506                                 $rr['description'] = $desciption;
507                                 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ?  ' ' . t('[today]') : '');
508                                 $rr['startime'] = $strt;
509                                 $rr['today'] = $today;
510                         }
511                 }
512
513                 $tpl = get_markup_template("events_reminder.tpl");
514                 return replace_macros($tpl, array(
515                         '$baseurl' => $a->get_baseurl(),
516                         '$classtoday' => $classtoday,
517                         '$count' => count($r) - $skip,
518                         '$event_reminders' => t('Event Reminders'),
519                         '$event_title' => t('Events this week:'),
520                         '$events' => $r,
521                 ));
522         }
523 }
524
525 function advanced_profile(&$a) {
526
527         $o = '';
528
529         $o .= replace_macros(get_markup_template("section_title.tpl"),array(
530                 '$title' => t('Profile')
531         ));
532
533         if($a->profile['name']) {
534
535                 $tpl = get_markup_template('profile_advanced.tpl');
536                 
537                 $profile = array();
538                 
539                 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
540                 
541                 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'),  $a->profile['gender'] );
542                 
543
544                 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
545                 
546                         $year_bd_format = t('j F, Y');
547                         $short_bd_format = t('j F');
548
549                 
550                         $val = ((intval($a->profile['dob'])) 
551                                 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
552                                 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
553
554                         $profile['birthday'] = array( t('Birthday:'), $val);
555
556                 }
557
558                 if($age = age($a->profile['dob'],$a->profile['timezone'],''))  $profile['age'] = array( t('Age:'), $age );
559                         
560
561                 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
562
563
564                 if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
565
566                 if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
567                                 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
568                 }
569
570                 if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
571
572                 if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
573
574                 if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
575
576                 if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
577
578                 if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
579
580                 if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
581
582                 if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
583
584                 if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
585
586                 if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
587
588                 if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
589
590
591                 if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
592
593                 if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
594                 
595                 if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
596
597                 if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
598
599                 if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
600
601                 if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
602                 
603                 if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
604
605                 if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
606                 
607                 if ($a->profile['uid'] == local_user())
608                         $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
609                 
610                 return replace_macros($tpl, array(
611                         '$title' => t('Profile'),
612                         '$profile' => $profile
613                 ));
614         }
615
616         return '';
617 }
618
619 if(! function_exists('profile_tabs')){
620         function profile_tabs($a, $is_owner=False, $nickname=Null){
621                 //echo "<pre>"; var_dump($a->user); killme();
622
623                 if (is_null($nickname))
624                         $nickname  = $a->user['nickname'];
625
626                 if(x($_GET,'tab'))
627                         $tab = notags(trim($_GET['tab']));
628
629                 $url = $a->get_baseurl() . '/profile/' . $nickname;
630
631                 $tabs = array(
632                         array(
633                                 'label'=>t('Status'),
634                                 'url' => $url,
635                                 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
636                                 'title' => t('Status Messages and Posts'),
637                                 'id' => 'status-tab',
638                                 'accesskey' => 'm',
639                         ),
640                         array(
641                                 'label' => t('Profile'),
642                                 'url'   => $url.'/?tab=profile',
643                                 'sel'   => ((isset($tab) && $tab=='profile')?'active':''),
644                                 'title' => t('Profile Details'),
645                                 'id' => 'profile-tab',
646                                 'accesskey' => 'r',
647                         ),
648                         array(
649                                 'label' => t('Photos'),
650                                 'url'   => $a->get_baseurl() . '/photos/' . $nickname,
651                                 'sel'   => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
652                                 'title' => t('Photo Albums'),
653                                 'id' => 'photo-tab',
654                                 'accesskey' => 'h',
655                         ),
656                         array(
657                                 'label' => t('Videos'),
658                                 'url'   => $a->get_baseurl() . '/videos/' . $nickname,
659                                 'sel'   => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
660                                 'title' => t('Videos'),
661                                 'id' => 'video-tab',
662                                 'accesskey' => 'v',
663                         ),
664                 );
665
666                 if ($is_owner){
667                         $tabs[] = array(
668                                 'label' => t('Events'),
669                                 'url'   => $a->get_baseurl() . '/events',
670                                 'sel'   =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
671                                 'title' => t('Events and Calendar'),
672                                 'id' => 'events-tab',
673                                 'accesskey' => 'e',
674                         );
675                         $tabs[] = array(
676                                 'label' => t('Personal Notes'),
677                                 'url'   => $a->get_baseurl() . '/notes',
678                                 'sel'   =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
679                                 'title' => t('Only You Can See This'),
680                                 'id' => 'notes-tab',
681                                 'accesskey' => 't',
682                         );
683                 }
684
685
686                 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
687                 call_hooks('profile_tabs', $arr);
688
689                 $tpl = get_markup_template('common_tabs.tpl');
690
691                 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
692         }
693 }
694
695 function get_my_url() {
696         if(x($_SESSION,'my_url'))
697                 return $_SESSION['my_url'];
698         return false;
699 }
700
701 function zrl_init(&$a) {
702         $tmp_str = get_my_url();
703         if(validate_url($tmp_str)) {
704
705                 // Is it a DDoS attempt?
706                 // The check fetches the cached value from gprobe to reduce the load for this system
707                 $urlparts = parse_url($tmp_str);
708
709                 $result = Cache::get("gprobe:".$urlparts["host"]);
710                 if (!is_null($result)) {
711                         $result = unserialize($result);
712                         if ($result["network"] == NETWORK_FEED) {
713                                 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
714                                 return;
715                         }
716                 }
717
718                 proc_run('php','include/gprobe.php',bin2hex($tmp_str));
719                 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
720                 call_hooks('zrl_init',$arr);
721         }
722 }
723
724 function zrl($s,$force = false) {
725         if(! strlen($s))
726                 return $s;
727         if((! strpos($s,'/profile/')) && (! $force))
728                 return $s;
729         if($force && substr($s,-1,1) !== '/')
730                 $s = $s . '/';
731         $achar = strpos($s,'?') ? '&' : '?';
732         $mine = get_my_url();
733         if($mine and ! link_compare($mine,$s))
734                 return $s . $achar . 'zrl=' . urlencode($mine);
735         return $s;
736 }
737
738 // Used from within PCSS themes to set theme parameters. If there's a
739 // puid request variable, that is the "page owner" and normally their theme
740 // settings take precedence; unless a local user sets the "always_my_theme" 
741 // system pconfig, which means they don't want to see anybody else's theme 
742 // settings except their own while on this site.
743
744 function get_theme_uid() {
745         $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
746         if(local_user()) {
747                 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))
748                         return local_user();
749         }
750
751         return $uid;
752 }