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