3 * @file include/identity.php
6 require_once('include/ForumManager.php');
7 require_once('include/bbcode.php');
8 require_once("mod/proxy.php");
12 * @brief Loads a profile into the page sidebar.
14 * The function requires a writeable copy of the main App structure, and the nickname
15 * of a registered local account.
17 * If the viewer is an authenticated remote viewer, the profile displayed is the
18 * one that has been configured for his/her viewing in the Contact manager.
19 * Passing a non-zero profile ID can also allow a preview of a selected profile
22 * Profile information is placed in the App structure for later retrieval.
23 * Honours the owner's chosen theme for display.
25 * @attention Should only be run in the _init() functions of a module. That ensures that
26 * the theme is chosen before the _init() function of a theme is run, which will usually
27 * load a lot of theme-specific content
30 * @param string $nickname
32 * @param array $profiledata
34 function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) {
36 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
40 if(!$user && count($user) && !count($profiledata)) {
41 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
42 notice( t('Requested account is not available.') . EOL );
47 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
49 if(($pdata === false) || (!count($pdata)) && !count($profiledata)) {
50 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
51 notice( t('Requested profile is not available.') . EOL );
56 // fetch user tags if this isn't the default profile
58 if(!$pdata['is-default']) {
59 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
60 intval($pdata['profile_uid'])
63 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
67 $a->profile_uid = $pdata['profile_uid'];
69 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
70 $a->profile['network'] = NETWORK_DFRN;
72 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
74 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
75 $_SESSION['theme'] = $a->profile['theme'];
77 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
80 * load/reload current theme info
83 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
85 $theme_info_file = "view/theme/".current_theme()."/theme.php";
86 if (file_exists($theme_info_file)){
87 require_once($theme_info_file);
90 if(! (x($a->page,'aside')))
91 $a->page['aside'] = '';
93 if(local_user() && local_user() == $a->profile['uid'] && $profiledata) {
94 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
95 '$editprofile' => t('Edit profile'),
96 '$profid' => $a->profile['id']
100 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
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
108 $a->page['aside'] .= profile_sidebar($profiledata, true);
110 $a->page['aside'] .= profile_sidebar($a->profile, $block);
113 $a->page['aside'] .= contact_block();*/
120 * @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
127 * @param string $nickname
129 * @param int $profile
132 * Includes all available profile data
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'])
142 $profile = $r[0]['profile-id'];
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",
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",
173 * @brief Formats a profile for display in the sidebar.
175 * It is very difficult to templatise the HTML completely
176 * because of all the conditional logic.
178 * @param array $profile
181 * @return HTML string stuitable for sidebar inclusion
183 * @note Returns empty string if passed $profile is wrong type or not populated
185 * @hooks 'profile_sidebar_enter'
186 * array $profile - profile data
187 * @hooks 'profile_sidebar'
190 function profile_sidebar($profile, $block = 0) {
198 if((! is_array($profile)) && (! count($profile)))
201 $profile['picdate'] = urlencode($profile['picdate']);
203 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
204 $profile['network_name'] = format_network_name($profile['network'],$profile['url']);
206 $profile['network_name'] = "";
208 call_hooks('profile_sidebar_enter', $profile);
211 // don't show connect link to yourself
212 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
214 // don't show connect link to authenticated visitors either
215 if(remote_user() && count($_SESSION['remote'])) {
216 foreach($_SESSION['remote'] as $visitor) {
217 if($visitor['uid'] == $profile['uid']) {
224 // Is the local user already connected to that user?
225 if ($connect AND local_user()) {
226 if (isset($profile["url"]))
227 $profile_url = normalise_link($profile["url"]);
229 $profile_url = normalise_link($a->get_baseurl()."/profile/".$profile["nickname"]);
231 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
232 local_user(), $profile_url);
237 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
240 $remoteconnect = NULL;
241 if (isset($profile['remoteconnect']))
242 $remoteconnect = $profile['remoteconnect'];
244 if ($connect AND ($profile['network'] == NETWORK_DFRN) AND !isset($remoteconnect))
245 $subscribe_feed = t("Atom feed");
247 $subscribe_feed = false;
249 if (remote_user() OR (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
250 $wallmessage = t('Message');
251 $wallmessage_link = "wallmessage/".$profile["nickname"];
254 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
255 intval($profile['uid']),
256 intval(remote_user()),
257 intval(CONTACT_IS_FRIEND));
259 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
260 intval($profile['uid']),
261 dbesc(normalise_link(get_my_url())),
262 intval(CONTACT_IS_FRIEND));
265 $remote_url = $r[0]["url"];
266 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
267 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
270 $wallmessage = false;
271 $wallmessage_link = false;
274 // show edit profile to yourself
275 if ($profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
276 $profile['edit'] = array($a->get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
277 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
280 $profile['menu'] = array(
281 'chg_photo' => t('Change profile photo'),
282 'cr_new' => t('Create New Profile'),
283 'entries' => array(),
289 $profile['menu']['entries'][] = array(
290 'photo' => $rr['thumb'],
292 'alt' => t('Profile Image'),
293 'profile_name' => $rr['profile-name'],
294 'isdefault' => $rr['is-default'],
295 'visibile_to_everybody' => t('visible to everybody'),
296 'edit_visibility' => t('Edit visibility'),
304 if ($profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
305 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
306 $profile['menu'] = array(
307 'chg_photo' => t('Change profile photo'),
309 'entries' => array(),
313 // check if profile is a forum
314 if((intval($profile['page-flags']) == PAGE_COMMUNITY)
315 || (intval($profile['page-flags']) == PAGE_PRVGROUP)
316 || (isset($profile['forum']) && intval($profile['forum']))
317 || (isset($profile['prv']) && intval($profile['prv']))
318 || (isset($profile['community']) && intval($profile['community'])))
319 $account_type = t('Forum');
323 if((x($profile,'address') == 1)
324 || (x($profile,'location') == 1)
325 || (x($profile,'locality') == 1)
326 || (x($profile,'region') == 1)
327 || (x($profile,'postal-code') == 1)
328 || (x($profile,'country-name') == 1))
329 $location = t('Location:');
331 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
334 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
336 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
338 $about = ((x($profile,'about') == 1) ? t('About:') : False);
340 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
342 if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
343 $location = $pdesc = $gender = $marital = $homepage = $about = False;
346 $firstname = ((strpos($profile['name'],' '))
347 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
348 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
350 if ($profile['guid'] != "")
352 'guid' => $profile['guid'],
353 'podloc' => $a->get_baseurl(),
354 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
355 'nickname' => $profile['nickname'],
356 'fullname' => $profile['name'],
357 'firstname' => $firstname,
358 'lastname' => $lastname,
359 'photo300' => $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
360 'photo100' => $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
361 'photo50' => $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
367 $contact_block = contact_block();
369 if(is_array($a->profile) AND !$a->profile['hide-friends']) {
370 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
371 intval($a->profile['uid']));
373 $updated = date("c", strtotime($r[0]['updated']));
375 $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
376 AND `network` IN ('%s', '%s', '%s', '')",
377 intval($profile['uid']),
379 dbesc(NETWORK_DIASPORA),
380 dbesc(NETWORK_OSTATUS)
383 $contacts = intval($r[0]['total']);
388 foreach($profile as $k => $v) {
389 $k = str_replace('-','_',$k);
393 if (isset($p["about"]))
394 $p["about"] = bbcode($p["about"]);
396 if (isset($p["address"]))
397 $p["address"] = bbcode($p["address"]);
399 $p["address"] = bbcode($p["location"]);
401 if (isset($p["photo"]))
402 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
404 if($a->theme['template_engine'] === 'internal')
405 $location = template_escape($location);
407 $tpl = get_markup_template('profile_vcard.tpl');
408 $o .= replace_macros($tpl, array(
411 '$connect' => $connect,
412 '$remoteconnect' => $remoteconnect,
413 '$subscribe_feed' => $subscribe_feed,
414 '$wallmessage' => $wallmessage,
415 '$wallmessage_link' => $wallmessage_link,
416 '$account_type' => $account_type,
417 '$location' => $location,
418 '$gender' => $gender,
419 // '$pdesc' => $pdesc,
420 '$marital' => $marital,
421 '$homepage' => $homepage,
423 '$network' => t('Network:'),
424 '$contacts' => $contacts,
425 '$updated' => $updated,
426 '$diaspora' => $diaspora,
427 '$contact_block' => $contact_block,
430 $arr = array('profile' => &$profile, 'entry' => &$o);
432 call_hooks('profile_sidebar', $arr);
438 function get_birthdays() {
443 if(! local_user() || $a->is_mobile || $a->is_tablet)
446 // $mobile_detect = new Mobile_Detect();
447 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
452 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
453 $bd_short = t('F d');
455 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
456 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
457 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
458 ORDER BY `start` ASC ",
459 intval(local_user()),
460 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
461 dbesc(datetime_convert('UTC','UTC','now'))
464 if($r && count($r)) {
466 $now = strtotime('now');
471 if(strlen($rr['name']))
473 if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
476 $classtoday = $istoday ? ' birthday-today ' : '';
478 foreach($r as &$rr) {
479 if(! strlen($rr['name']))
484 if(in_array($rr['cid'],$cids))
486 $cids[] = $rr['cid'];
488 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
491 if($rr['network'] === NETWORK_DFRN) {
492 $sparkle = " sparkle";
493 $url = $a->get_baseurl() . '/redir/' . $rr['cid'];
497 $rr['title'] = $rr['name'];
498 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
499 $rr['startime'] = Null;
500 $rr['today'] = $today;
505 $tpl = get_markup_template("birthdays_reminder.tpl");
506 return replace_macros($tpl, array(
507 '$baseurl' => $a->get_baseurl(),
508 '$classtoday' => $classtoday,
510 '$event_reminders' => t('Birthday Reminders'),
511 '$event_title' => t('Birthdays this week:'),
513 '$lbr' => '{', // raw brackets mess up if/endif macro processing
520 function get_events() {
522 require_once('include/bbcode.php');
526 if(! local_user() || $a->is_mobile || $a->is_tablet)
530 // $mobile_detect = new Mobile_Detect();
531 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
536 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
537 $bd_short = t('F d');
539 $r = q("SELECT `event`.* FROM `event`
540 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
541 ORDER BY `start` ASC ",
542 intval(local_user()),
543 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
544 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
547 if($r && count($r)) {
548 $now = strtotime('now');
551 if(strlen($rr['name']))
554 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
555 if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
558 $classtoday = (($istoday) ? 'event-today' : '');
562 foreach($r as &$rr) {
563 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
565 if(strlen($title) > 35)
566 $title = substr($title,0,32) . '... ';
568 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
570 $description = t('[No description]');
572 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
574 if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
579 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
581 $rr['title'] = $title;
582 $rr['description'] = $desciption;
583 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
584 $rr['startime'] = $strt;
585 $rr['today'] = $today;
589 $tpl = get_markup_template("events_reminder.tpl");
590 return replace_macros($tpl, array(
591 '$baseurl' => $a->get_baseurl(),
592 '$classtoday' => $classtoday,
593 '$count' => count($r) - $skip,
594 '$event_reminders' => t('Event Reminders'),
595 '$event_title' => t('Events this week:'),
600 function advanced_profile(&$a) {
603 $uid = $a->profile['uid'];
605 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
606 '$title' => t('Profile')
609 if($a->profile['name']) {
611 $tpl = get_markup_template('profile_advanced.tpl');
615 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
617 if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
620 if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
622 $year_bd_format = t('j F, Y');
623 $short_bd_format = t('j F');
626 $val = ((intval($a->profile['dob']))
627 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
628 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
630 $profile['birthday'] = array( t('Birthday:'), $val);
634 if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
637 if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
640 if($a->profile['with']) $profile['marital']['with'] = $a->profile['with'];
642 if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
643 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
646 if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
648 if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
650 if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
652 if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
654 if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
656 if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
658 if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt );
660 if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
662 if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
664 if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
667 if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
669 if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
671 if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
673 if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt);
675 if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
677 if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
679 if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
681 if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
683 //show subcribed forum if it is enabled in the usersettings
684 if (feature_enabled($uid,'forumlist_profile')) {
685 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
688 if ($a->profile['uid'] == local_user())
689 $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
691 return replace_macros($tpl, array(
692 '$title' => t('Profile'),
693 '$basic' => t('Basic'),
694 '$advanced' => t('Advanced'),
695 '$profile' => $profile
702 function profile_tabs($a, $is_owner=False, $nickname=Null){
703 //echo "<pre>"; var_dump($a->user); killme();
705 if (is_null($nickname))
706 $nickname = $a->user['nickname'];
709 $tab = notags(trim($_GET['tab']));
711 $url = $a->get_baseurl() . '/profile/' . $nickname;
715 'label'=>t('Status'),
717 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''),
718 'title' => t('Status Messages and Posts'),
719 'id' => 'status-tab',
723 'label' => t('Profile'),
724 'url' => $url.'/?tab=profile',
725 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
726 'title' => t('Profile Details'),
727 'id' => 'profile-tab',
731 'label' => t('Photos'),
732 'url' => $a->get_baseurl() . '/photos/' . $nickname,
733 'sel' => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''),
734 'title' => t('Photo Albums'),
739 'label' => t('Videos'),
740 'url' => $a->get_baseurl() . '/videos/' . $nickname,
741 'sel' => ((!isset($tab)&&$a->argv[0]=='videos')?'active':''),
742 'title' => t('Videos'),
748 // the calendar link for the full featured events calendar
749 if ($is_owner && $a->theme_events_in_profile) {
751 'label' => t('Events'),
752 'url' => $a->get_baseurl() . '/events',
753 'sel' =>((!isset($tab)&&$a->argv[0]=='events')?'active':''),
754 'title' => t('Events and Calendar'),
755 'id' => 'events-tab',
758 // if the user is not the owner of the calendar we only show a calendar
759 // with the public events of the calendar owner
760 } elseif (! $is_owner) {
762 'label' => t('Events'),
763 'url' => $a->get_baseurl() . '/cal/' . $nickname,
764 'sel' =>((!isset($tab)&&$a->argv[0]=='cal')?'active':''),
765 'title' => t('Events and Calendar'),
766 'id' => 'events-tab',
773 'label' => t('Personal Notes'),
774 'url' => $a->get_baseurl() . '/notes',
775 'sel' =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''),
776 'title' => t('Only You Can See This'),
782 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
784 'label' => t('Contacts'),
785 'url' => $a->get_baseurl() . '/viewcontacts/' . $nickname,
786 'sel' => ((!isset($tab)&&$a->argv[0]=='viewcontacts')?'active':''),
787 'title' => t('Contacts'),
788 'id' => 'viewcontacts-tab',
793 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
794 call_hooks('profile_tabs', $arr);
796 $tpl = get_markup_template('common_tabs.tpl');
798 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
801 function get_my_url() {
802 if(x($_SESSION,'my_url'))
803 return $_SESSION['my_url'];
807 function zrl_init(&$a) {
808 $tmp_str = get_my_url();
809 if(validate_url($tmp_str)) {
811 // Is it a DDoS attempt?
812 // The check fetches the cached value from gprobe to reduce the load for this system
813 $urlparts = parse_url($tmp_str);
815 $result = Cache::get("gprobe:".$urlparts["host"]);
816 if (!is_null($result)) {
817 $result = unserialize($result);
818 if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
819 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
824 proc_run(PRIORITY_LOW, 'include/gprobe.php',bin2hex($tmp_str));
825 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
826 call_hooks('zrl_init',$arr);
830 function zrl($s,$force = false) {
833 if((! strpos($s,'/profile/')) && (! $force))
835 if($force && substr($s,-1,1) !== '/')
837 $achar = strpos($s,'?') ? '&' : '?';
838 $mine = get_my_url();
839 if($mine and ! link_compare($mine,$s))
840 return $s . $achar . 'zrl=' . urlencode($mine);
845 * @brief Get the user ID of the page owner
847 * Used from within PCSS themes to set theme parameters. If there's a
848 * puid request variable, that is the "page owner" and normally their theme
849 * settings take precedence; unless a local user sets the "always_my_theme"
850 * system pconfig, which means they don't want to see anybody else's theme
851 * settings except their own while on this site.
853 * @return int user ID
855 * @note Returns local_user instead of user ID if "always_my_theme"
858 function get_theme_uid() {
859 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
861 if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))