]> git.mxchange.org Git - friendica.git/blob - include/identity.php
Bugfix: The bbcode conversion of the profile was inconsistent
[friendica.git] / include / identity.php
1 <?php
2 /**
3  * @file include/identity.php
4  */
5
6 require_once('include/forums.php');
7 require_once('include/bbcode.php');
8 require_once("mod/proxy.php");
9
10 /**
11  *
12  * Function : profile_load
13  * @parameter App    $a
14  * @parameter string $nickname
15  * @parameter int    $profile
16  *
17  * Summary: Loads a profile into the page sidebar.
18  * The function requires a writeable copy of the main App structure, and the nickname
19  * of a registered local account.
20  *
21  * If the viewer is an authenticated remote viewer, the profile displayed is the
22  * one that has been configured for his/her viewing in the Contact manager.
23  * Passing a non-zero profile ID can also allow a preview of a selected profile
24  * by the owner.
25  *
26  * Profile information is placed in the App structure for later retrieval.
27  * Honours the owner's chosen theme for display.
28  *
29  * IMPORTANT: Should only be run in the _init() functions of a module. That ensures that
30  * the theme is chosen before the _init() function of a theme is run, which will usually
31  * load a lot of theme-specific content
32  *
33  */
34
35 if(! function_exists('profile_load')) {
36         function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
37
38                 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
39                         dbesc($nickname)
40                 );
41
42                 if(!$user && count($user) && !count($profiledata)) {
43                         logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
44                         notice( t('Requested account is not available.') . EOL );
45                         $a->error = 404;
46                         return;
47                 }
48
49                 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
50
51                 if(($pdata === false) || (!count($pdata)) && !count($profiledata)) {
52                         logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
53                         notice( t('Requested profile is not available.') . EOL );
54                         $a->error = 404;
55                         return;
56                 }
57
58                 // fetch user tags if this isn't the default profile
59
60                 if(!$pdata['is-default']) {
61                         $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
62                                         intval($pdata['profile_uid'])
63                         );
64                         if($x && count($x))
65                                 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
66                 }
67
68                 $a->profile = $pdata;
69                 $a->profile_uid = $pdata['profile_uid'];
70
71                 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
72                 $a->profile['network'] = NETWORK_DFRN;
73
74                 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
75
76 //              if (!$profiledata)
77 //                      $_SESSION['theme'] = $a->profile['theme'];
78
79                 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
80
81                 /**
82                  * load/reload current theme info
83                  */
84
85                 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
86
87                 $theme_info_file = "view/theme/".current_theme()."/theme.php";
88                 if (file_exists($theme_info_file)){
89                         require_once($theme_info_file);
90                 }
91
92                 if(! (x($a->page,'aside')))
93                         $a->page['aside'] = '';
94
95                 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
96                         $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
97                                 '$editprofile' => t('Edit profile'),
98                                 '$profid' => $a->profile['id']
99                         ));
100                 }
101
102                 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
103
104                 // To-Do:
105                 // By now, the contact block isn't shown, when a different profile is given
106                 // But: When this profile was on the same server, then we could display the contacts
107                 if ($profiledata)
108                         $a->page['aside'] .= profile_sidebar($profiledata, true);
109                 else
110                         $a->page['aside'] .= profile_sidebar($a->profile, $block);
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                 // check if profile is a forum
290                 if((intval($profile['page-flags']) == PAGE_COMMUNITY)
291                                 || (intval($profile['page-flags']) == PAGE_PRVGROUP)
292                                 || (intval($profile['forum']))
293                                 || (intval($profile['prv']))
294                                 || (intval($profile['community'])))
295                         $account_type = t('Forum');
296                 else
297                         $account_type = "";
298
299                 if((x($profile,'address') == 1)
300                                 || (x($profile,'locality') == 1)
301                                 || (x($profile,'region') == 1)
302                                 || (x($profile,'postal-code') == 1)
303                                 || (x($profile,'country-name') == 1))
304                         $location = t('Location:');
305
306                 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
307
308
309                 $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
310
311                 $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
312
313                 $about = ((x($profile,'about') == 1) ?  t('About:') : False);
314
315                 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
316                         $location = $pdesc = $gender = $marital = $homepage = $about = False;
317                 }
318
319                 $firstname = ((strpos($profile['name'],' '))
320                                 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
321                 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
322
323                 $diaspora = array(
324                         'guid' => $profile['guid'],
325                         'podloc' => $a->get_baseurl(),
326                         'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
327                         'nickname' => $profile['nickname'],
328                         'fullname' => $profile['name'],
329                         'firstname' => $firstname,
330                         'lastname' => $lastname,
331                         'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
332                         'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
333                         'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg'),
334                 );
335
336                 if (!$block){
337                         $contact_block = contact_block();
338
339                         if(is_array($a->profile) AND !$a->profile['hide-friends']) {
340                                 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
341                                         intval($a->profile['uid']));
342                                 if(count($r))
343                                         $updated =  date("c", strtotime($r[0]['updated']));
344
345                                 $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
346                                                 AND `network` IN ('%s', '%s', '%s', '')",
347                                         intval($profile['uid']),
348                                         dbesc(NETWORK_DFRN),
349                                         dbesc(NETWORK_DIASPORA),
350                                         dbesc(NETWORK_OSTATUS)
351                                 );
352                                 if(count($r))
353                                         $contacts = intval($r[0]['total']);
354                         }
355                 }
356
357                 $p = array();
358                 foreach($profile as $k => $v) {
359                         $k = str_replace('-','_',$k);
360                         $p[$k] = $v;
361                 }
362
363                 if (isset($p["about"]))
364                         $p["about"] = bbcode($p["about"]);
365
366                 if (isset($p["location"]))
367                         $p["location"] = bbcode($p["location"]);
368
369                 if (isset($p["photo"]))
370                         $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
371
372                 if($a->theme['template_engine'] === 'internal')
373                         $location = template_escape($location);
374
375                 $tpl = get_markup_template('profile_vcard.tpl');
376                 $o .= replace_macros($tpl, array(
377                         '$profile' => $p,
378                         '$connect'  => $connect,
379                         '$remoteconnect'  => $remoteconnect,
380                         '$subscribe_feed' => $subscribe_feed,
381                         '$wallmessage' => $wallmessage,
382                         '$account_type' => $account_type,
383                         '$location' => $location,
384                         '$gender'   => $gender,
385 //                      '$pdesc'        => $pdesc,
386                         '$marital'  => $marital,
387                         '$homepage' => $homepage,
388                         '$about' => $about,
389                         '$network' =>  t('Network:'),
390                         '$contacts' => $contacts,
391                         '$updated' => $updated,
392                         '$diaspora' => $diaspora,
393                         '$contact_block' => $contact_block,
394                 ));
395
396
397                 $arr = array('profile' => &$profile, 'entry' => &$o);
398
399                 call_hooks('profile_sidebar', $arr);
400
401                 return $o;
402         }
403 }
404
405
406 if(! function_exists('get_birthdays')) {
407         function get_birthdays() {
408
409                 $a = get_app();
410                 $o = '';
411
412                 if(! local_user() || $a->is_mobile || $a->is_tablet)
413                         return $o;
414
415 //              $mobile_detect = new Mobile_Detect();
416 //              $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
417
418 //              if($is_mobile)
419 //                      return $o;
420
421                 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
422                 $bd_short = t('F d');
423
424                 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
425                                 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
426                                 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
427                                 ORDER BY `start` ASC ",
428                                 intval(local_user()),
429                                 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
430                                 dbesc(datetime_convert('UTC','UTC','now'))
431                 );
432
433                 if($r && count($r)) {
434                         $total = 0;
435                         $now = strtotime('now');
436                         $cids = array();
437
438                         $istoday = false;
439                         foreach($r as $rr) {
440                                 if(strlen($rr['name']))
441                                         $total ++;
442                                 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
443                                         $istoday = true;
444                         }
445                         $classtoday = $istoday ? ' birthday-today ' : '';
446                         if($total) {
447                                 foreach($r as &$rr) {
448                                         if(! strlen($rr['name']))
449                                                 continue;
450
451                                         // avoid duplicates
452
453                                         if(in_array($rr['cid'],$cids))
454                                                 continue;
455                                         $cids[] = $rr['cid'];
456
457                                         $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
458                                         $sparkle = '';
459                                         $url = $rr['url'];
460                                         if($rr['network'] === NETWORK_DFRN) {
461                                                 $sparkle = " sparkle";
462                                                 $url = $a->get_baseurl() . '/redir/'  . $rr['cid'];
463                                         }
464
465                                         $rr['link'] = $url;
466                                         $rr['title'] = $rr['name'];
467                                         $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ?  ' ' . t('[today]') : '');
468                                         $rr['startime'] = Null;
469                                         $rr['today'] = $today;
470
471                                 }
472                         }
473                 }
474                 $tpl = get_markup_template("birthdays_reminder.tpl");
475                 return replace_macros($tpl, array(
476                         '$baseurl' => $a->get_baseurl(),
477                         '$classtoday' => $classtoday,
478                         '$count' => $total,
479                         '$event_reminders' => t('Birthday Reminders'),
480                         '$event_title' => t('Birthdays this week:'),
481                         '$events' => $r,
482                         '$lbr' => '{',  // raw brackets mess up if/endif macro processing
483                         '$rbr' => '}'
484
485                 ));
486         }
487 }
488
489
490 if(! function_exists('get_events')) {
491         function get_events() {
492
493                 require_once('include/bbcode.php');
494
495                 $a = get_app();
496
497                 if(! local_user() || $a->is_mobile || $a->is_tablet)
498                         return $o;
499
500
501 //              $mobile_detect = new Mobile_Detect();
502 //              $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
503
504 //              if($is_mobile)
505 //                      return $o;
506
507                 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
508                 $bd_short = t('F d');
509
510                 $r = q("SELECT `event`.* FROM `event`
511                                 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
512                                 ORDER BY `start` ASC ",
513                                 intval(local_user()),
514                                 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
515                                 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
516                 );
517
518                 if($r && count($r)) {
519                         $now = strtotime('now');
520                         $istoday = false;
521                         foreach($r as $rr) {
522                                 if(strlen($rr['name']))
523                                         $total ++;
524
525                                 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
526                                 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
527                                         $istoday = true;
528                         }
529                         $classtoday = (($istoday) ? 'event-today' : '');
530
531                         $skip = 0;
532
533                         foreach($r as &$rr) {
534                                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
535
536                                 if(strlen($title) > 35)
537                                         $title = substr($title,0,32) . '... ';
538
539                                 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
540                                 if(! $description)
541                                         $description = t('[No description]');
542
543                                 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
544
545                                 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
546                                         $skip++;
547                                         continue;
548                                 }
549
550                                 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
551
552                                 $rr['title'] = $title;
553                                 $rr['description'] = $desciption;
554                                 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ?  ' ' . t('[today]') : '');
555                                 $rr['startime'] = $strt;
556                                 $rr['today'] = $today;
557                         }
558                 }
559
560                 $tpl = get_markup_template("events_reminder.tpl");
561                 return replace_macros($tpl, array(
562                         '$baseurl' => $a->get_baseurl(),
563                         '$classtoday' => $classtoday,
564                         '$count' => count($r) - $skip,
565                         '$event_reminders' => t('Event Reminders'),
566                         '$event_title' => t('Events this week:'),
567                         '$events' => $r,
568                 ));
569         }
570 }
571
572 function advanced_profile(&$a) {
573
574         $o = '';
575         $uid = $a->profile['uid'];
576
577         $o .= replace_macros(get_markup_template('section_title.tpl'),array(
578                 '$title' => t('Profile')
579         ));
580
581         if($a->profile['name']) {
582
583                 $tpl = get_markup_template('profile_advanced.tpl');
584
585                 $profile = array();
586
587                 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
588
589                 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'),  $a->profile['gender'] );
590
591
592                 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
593
594                         $year_bd_format = t('j F, Y');
595                         $short_bd_format = t('j F');
596
597
598                         $val = ((intval($a->profile['dob']))
599                                 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
600                                 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
601
602                         $profile['birthday'] = array( t('Birthday:'), $val);
603
604                 }
605
606                 if($age = age($a->profile['dob'],$a->profile['timezone'],''))  $profile['age'] = array( t('Age:'), $age );
607
608
609                 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
610
611
612                 if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
613
614                 if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
615                                 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
616                 }
617
618                 if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
619
620                 if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
621
622                 if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
623
624                 if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
625
626                 if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
627
628                 if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
629
630                 if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
631
632                 if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
633
634                 if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
635
636                 if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
637
638
639                 if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
640
641                 if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
642
643                 if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
644
645                 if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
646
647                 if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
648
649                 if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
650
651                 if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
652
653                 if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
654         
655                 //show subcribed forum if it is enabled in the usersettings
656                 if (feature_enabled($uid,'forumlist_profile')) {
657                         $profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid));
658                 }
659
660                 if ($a->profile['uid'] == local_user())
661                         $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
662
663                 return replace_macros($tpl, array(
664                         '$title' => t('Profile'),
665                         '$profile' => $profile
666                 ));
667         }
668
669         return '';
670 }
671
672 if(! function_exists('profile_tabs')){
673         function profile_tabs($a, $is_owner=False, $nickname=Null){
674                 //echo "<pre>"; var_dump($a->user); killme();
675
676                 if (is_null($nickname))
677                         $nickname  = $a->user['nickname'];
678
679                 if(x($_GET,'tab'))
680                         $tab = notags(trim($_GET['tab']));
681
682                 $url = $a->get_baseurl() . '/profile/' . $nickname;
683
684                 $tabs = array(
685                         array(
686                                 'label'=>t('Status'),
687                                 'url' => $url,
688                                 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
689                                 'title' => t('Status Messages and Posts'),
690                                 'id' => 'status-tab',
691                                 'accesskey' => 'm',
692                         ),
693                         array(
694                                 'label' => t('Profile'),
695                                 'url'   => $url.'/?tab=profile',
696                                 'sel'   => ((isset($tab) && $tab=='profile')?'active':''),
697                                 'title' => t('Profile Details'),
698                                 'id' => 'profile-tab',
699                                 'accesskey' => 'r',
700                         ),
701                         array(
702                                 'label' => t('Photos'),
703                                 'url'   => $a->get_baseurl() . '/photos/' . $nickname,
704                                 'sel'   => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
705                                 'title' => t('Photo Albums'),
706                                 'id' => 'photo-tab',
707                                 'accesskey' => 'h',
708                         ),
709                         array(
710                                 'label' => t('Videos'),
711                                 'url'   => $a->get_baseurl() . '/videos/' . $nickname,
712                                 'sel'   => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
713                                 'title' => t('Videos'),
714                                 'id' => 'video-tab',
715                                 'accesskey' => 'v',
716                         ),
717                 );
718
719                 if ($is_owner){
720                         if ($a->theme_events_in_profile)
721                                 $tabs[] = array(
722                                         'label' => t('Events'),
723                                         'url'   => $a->get_baseurl() . '/events',
724                                         'sel'   =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
725                                         'title' => t('Events and Calendar'),
726                                         'id' => 'events-tab',
727                                         'accesskey' => 'e',
728                                 );
729                         $tabs[] = array(
730                                 'label' => t('Personal Notes'),
731                                 'url'   => $a->get_baseurl() . '/notes',
732                                 'sel'   =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
733                                 'title' => t('Only You Can See This'),
734                                 'id' => 'notes-tab',
735                                 'accesskey' => 't',
736                         );
737                 }
738
739                 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
740                         $tabs[] = array(
741                                 'label' => t('Contacts'),
742                                 'url'   => $a->get_baseurl() . '/viewcontacts/' . $nickname,
743                                 'sel'   => ((!isset($tab)&&$a->argv[0]=='viewcontacts')?'active':''),
744                                 'title' => t('Contacts'),
745                                 'id' => 'viewcontacts-tab',
746                                 'accesskey' => 'k',
747                         );
748                 }
749
750                 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
751                 call_hooks('profile_tabs', $arr);
752
753                 $tpl = get_markup_template('common_tabs.tpl');
754
755                 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
756         }
757 }
758
759 function get_my_url() {
760         if(x($_SESSION,'my_url'))
761                 return $_SESSION['my_url'];
762         return false;
763 }
764
765 function zrl_init(&$a) {
766         $tmp_str = get_my_url();
767         if(validate_url($tmp_str)) {
768
769                 // Is it a DDoS attempt?
770                 // The check fetches the cached value from gprobe to reduce the load for this system
771                 $urlparts = parse_url($tmp_str);
772
773                 $result = Cache::get("gprobe:".$urlparts["host"]);
774                 if (!is_null($result)) {
775                         $result = unserialize($result);
776                         if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
777                                 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
778                                 return;
779                         }
780                 }
781
782                 proc_run('php','include/gprobe.php',bin2hex($tmp_str));
783                 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
784                 call_hooks('zrl_init',$arr);
785         }
786 }
787
788 function zrl($s,$force = false) {
789         if(! strlen($s))
790                 return $s;
791         if((! strpos($s,'/profile/')) && (! $force))
792                 return $s;
793         if($force && substr($s,-1,1) !== '/')
794                 $s = $s . '/';
795         $achar = strpos($s,'?') ? '&' : '?';
796         $mine = get_my_url();
797         if($mine and ! link_compare($mine,$s))
798                 return $s . $achar . 'zrl=' . urlencode($mine);
799         return $s;
800 }
801
802 // Used from within PCSS themes to set theme parameters. If there's a
803 // puid request variable, that is the "page owner" and normally their theme
804 // settings take precedence; unless a local user sets the "always_my_theme"
805 // system pconfig, which means they don't want to see anybody else's theme
806 // settings except their own while on this site.
807
808 function get_theme_uid() {
809         $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
810         if(local_user()) {
811                 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))
812                         return local_user();
813         }
814
815         return $uid;
816 }