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