3 * @file include/identity.php
8 require_once 'include/ForumManager.php';
9 require_once 'include/bbcode.php';
10 require_once 'mod/proxy.php';
11 require_once 'include/cache.php';
15 * @brief 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.
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
25 * Profile information is placed in the App structure for later retrieval.
26 * Honours the owner's chosen theme for display.
28 * @attention 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
33 * @param string $nickname
35 * @param array $profiledata
37 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
39 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
43 if (!$user && count($user) && !count($profiledata)) {
44 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
45 notice( t('Requested account is not available.') . EOL );
50 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
52 if (($pdata === false) || (!count($pdata)) && !count($profiledata)) {
53 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
54 notice( t('Requested profile is not available.') . EOL );
59 // fetch user tags if this isn't the default profile
61 if (!$pdata['is-default']) {
62 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
63 intval($pdata['profile_uid'])
66 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
70 $a->profile_uid = $pdata['profile_uid'];
72 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
73 $a->profile['network'] = NETWORK_DFRN;
75 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
77 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
78 $_SESSION['theme'] = $a->profile['theme'];
80 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
83 * load/reload current theme info
86 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
88 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
89 if (file_exists($theme_info_file)) {
90 require_once $theme_info_file;
93 if (! (x($a->page,'aside')))
94 $a->page['aside'] = '';
96 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
97 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
98 '$editprofile' => t('Edit profile'),
99 '$profid' => $a->profile['id']
103 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
107 * By now, the contact block isn't shown, when a different profile is given
108 * But: When this profile was on the same server, then we could display the contacts
111 $a->page['aside'] .= profile_sidebar($profiledata, true);
113 $a->page['aside'] .= profile_sidebar($a->profile, $block);
116 $a->page['aside'] .= contact_block();*/
123 * @brief Get all profil data of a local user
125 * If the viewer is an authenticated remote viewer, the profile displayed is the
126 * one that has been configured for his/her viewing in the Contact manager.
127 * Passing a non-zero profile ID can also allow a preview of a selected profile
130 * @param string $nickname
132 * @param int $profile
135 * Includes all available profile data
137 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
138 if (remote_user() && count($_SESSION['remote'])) {
139 foreach ($_SESSION['remote'] as $visitor) {
140 if ($visitor['uid'] == $uid) {
141 $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
142 intval($visitor['cid'])
144 if (dbm::is_result($r))
145 $profile = $r[0]['profile-id'];
154 $profile_int = intval($profile);
155 $r = q("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
156 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
157 `profile`.`uid` AS `profile_uid`, `profile`.*,
158 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
160 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
161 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
162 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
167 if (!dbm::is_result($r)) {
168 $r = q("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
169 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
170 `profile`.`uid` AS `profile_uid`, `profile`.*,
171 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
173 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
174 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
175 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` LIMIT 1",
186 * @brief Formats a profile for display in the sidebar.
188 * It is very difficult to templatise the HTML completely
189 * because of all the conditional logic.
191 * @param array $profile
194 * @return HTML string stuitable for sidebar inclusion
196 * @note Returns empty string if passed $profile is wrong type or not populated
198 * @hooks 'profile_sidebar_enter'
199 * array $profile - profile data
200 * @hooks 'profile_sidebar'
203 function profile_sidebar($profile, $block = 0) {
211 // This function can also use contact information in $profile
212 $is_contact = x($profile, 'cid');
214 if ((! is_array($profile)) && (! count($profile))) {
218 $profile['picdate'] = urlencode($profile['picdate']);
220 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
221 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
223 $profile['network_name'] = "";
226 call_hooks('profile_sidebar_enter', $profile);
229 // don't show connect link to yourself
230 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
232 // don't show connect link to authenticated visitors either
233 if (remote_user() && count($_SESSION['remote'])) {
234 foreach ($_SESSION['remote'] as $visitor) {
235 if ($visitor['uid'] == $profile['uid']) {
242 // Is the local user already connected to that user?
243 if ($connect && local_user()) {
244 if (isset($profile["url"])) {
245 $profile_url = normalise_link($profile["url"]);
247 $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
250 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
251 local_user(), $profile_url);
253 if (dbm::is_result($r))
257 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
260 $remoteconnect = NULL;
261 if (isset($profile['remoteconnect']))
262 $remoteconnect = $profile['remoteconnect'];
264 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
265 $subscribe_feed = t("Atom feed");
267 $subscribe_feed = false;
269 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
270 $wallmessage = t('Message');
271 $wallmessage_link = "wallmessage/".$profile["nickname"];
274 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
275 intval($profile['uid']),
276 intval(remote_user()),
277 intval(CONTACT_IS_FRIEND));
279 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
280 intval($profile['uid']),
281 dbesc(normalise_link(get_my_url())),
282 intval(CONTACT_IS_FRIEND));
285 $remote_url = $r[0]["url"];
286 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
287 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
290 $wallmessage = false;
291 $wallmessage_link = false;
294 // show edit profile to yourself
295 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
296 $profile['edit'] = array(App::get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
297 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
300 $profile['menu'] = array(
301 'chg_photo' => t('Change profile photo'),
302 'cr_new' => t('Create New Profile'),
303 'entries' => array(),
306 if (dbm::is_result($r)) {
308 foreach ($r as $rr) {
309 $profile['menu']['entries'][] = array(
310 'photo' => $rr['thumb'],
312 'alt' => t('Profile Image'),
313 'profile_name' => $rr['profile-name'],
314 'isdefault' => $rr['is-default'],
315 'visibile_to_everybody' => t('visible to everybody'),
316 'edit_visibility' => t('Edit visibility'),
324 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
325 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
326 $profile['menu'] = array(
327 'chg_photo' => t('Change profile photo'),
329 'entries' => array(),
333 // Fetch the account type
334 $account_type = account_type($profile);
336 if ((x($profile,'address') == 1)
337 || (x($profile,'location') == 1)
338 || (x($profile,'locality') == 1)
339 || (x($profile,'region') == 1)
340 || (x($profile,'postal-code') == 1)
341 || (x($profile,'country-name') == 1))
342 $location = t('Location:');
344 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
347 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
349 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
351 $about = ((x($profile,'about') == 1) ? t('About:') : False);
353 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
355 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
356 $location = $pdesc = $gender = $marital = $homepage = $about = False;
359 $firstname = ((strpos($profile['name'],' '))
360 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
361 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
363 if ($profile['guid'] != "")
365 'guid' => $profile['guid'],
366 'podloc' => App::get_baseurl(),
367 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
368 'nickname' => $profile['nickname'],
369 'fullname' => $profile['name'],
370 'firstname' => $firstname,
371 'lastname' => $lastname,
372 'photo300' => $profile['contact_photo'],
373 'photo100' => $profile['contact_thumb'],
374 'photo50' => $profile['contact_micro'],
380 $contact_block = contact_block();
382 if (is_array($a->profile) && !$a->profile['hide-friends']) {
383 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
384 intval($a->profile['uid']));
385 if (dbm::is_result($r))
386 $updated = date("c", strtotime($r[0]['updated']));
388 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
390 AND NOT `self` AND NOT `blocked` AND NOT `pending`
391 AND NOT `hidden` AND NOT `archive`
392 AND `network` IN ('%s', '%s', '%s', '')",
393 intval($profile['uid']),
395 dbesc(NETWORK_DIASPORA),
396 dbesc(NETWORK_OSTATUS)
398 if (dbm::is_result($r))
399 $contacts = intval($r[0]['total']);
404 foreach ($profile as $k => $v) {
405 $k = str_replace('-','_',$k);
409 if (isset($p["about"]))
410 $p["about"] = bbcode($p["about"]);
412 if (isset($p["address"]))
413 $p["address"] = bbcode($p["address"]);
415 $p["address"] = bbcode($p["location"]);
417 if (isset($p["photo"])) {
418 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
420 if ($a->theme['template_engine'] === 'internal')
421 $location = template_escape($location);
423 $tpl = get_markup_template('profile_vcard.tpl');
424 $o .= replace_macros($tpl, array(
427 '$connect' => $connect,
428 '$remoteconnect' => $remoteconnect,
429 '$subscribe_feed' => $subscribe_feed,
430 '$wallmessage' => $wallmessage,
431 '$wallmessage_link' => $wallmessage_link,
432 '$account_type' => $account_type,
433 '$location' => $location,
434 '$gender' => $gender,
435 // '$pdesc' => $pdesc,
436 '$marital' => $marital,
437 '$homepage' => $homepage,
439 '$network' => t('Network:'),
440 '$contacts' => $contacts,
441 '$updated' => $updated,
442 '$diaspora' => $diaspora,
443 '$contact_block' => $contact_block,
446 $arr = array('profile' => &$profile, 'entry' => &$o);
448 call_hooks('profile_sidebar', $arr);
454 function get_birthdays() {
459 if (! local_user() || $a->is_mobile || $a->is_tablet)
462 // $mobile_detect = new Mobile_Detect();
463 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
468 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
469 $bd_short = t('F d');
471 $cachekey = "get_birthdays:".local_user();
472 $r = Cache::get($cachekey);
474 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
475 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
476 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
477 ORDER BY `start` ASC ",
478 intval(local_user()),
479 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
480 dbesc(datetime_convert('UTC','UTC','now'))
482 if (dbm::is_result($r)) {
483 Cache::set($cachekey, $r, CACHE_HOUR);
486 if (dbm::is_result($r)) {
488 $now = strtotime('now');
492 foreach ($r as $rr) {
493 if (strlen($rr['name']))
495 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
498 $classtoday = $istoday ? ' birthday-today ' : '';
500 foreach ($r as &$rr) {
501 if (! strlen($rr['name']))
506 if (in_array($rr['cid'],$cids))
508 $cids[] = $rr['cid'];
510 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
513 if ($rr['network'] === NETWORK_DFRN) {
514 $sparkle = " sparkle";
515 $url = App::get_baseurl() . '/redir/' . $rr['cid'];
519 $rr['title'] = $rr['name'];
520 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
521 $rr['startime'] = Null;
522 $rr['today'] = $today;
527 $tpl = get_markup_template("birthdays_reminder.tpl");
528 return replace_macros($tpl, array(
529 '$baseurl' => App::get_baseurl(),
530 '$classtoday' => $classtoday,
532 '$event_reminders' => t('Birthday Reminders'),
533 '$event_title' => t('Birthdays this week:'),
535 '$lbr' => '{', // raw brackets mess up if/endif macro processing
542 function get_events() {
544 require_once 'include/bbcode.php';
548 if (! local_user() || $a->is_mobile || $a->is_tablet) {
552 // $mobile_detect = new Mobile_Detect();
553 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
558 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
559 $bd_short = t('F d');
561 $r = q("SELECT `event`.* FROM `event`
562 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
563 ORDER BY `start` ASC ",
564 intval(local_user()),
565 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
566 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
569 if (dbm::is_result($r)) {
570 $now = strtotime('now');
572 foreach ($r as $rr) {
573 if (strlen($rr['name'])) {
577 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
578 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
582 $classtoday = (($istoday) ? 'event-today' : '');
586 foreach ($r as &$rr) {
587 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
589 if (strlen($title) > 35) {
590 $title = substr($title,0,32) . '... ';
593 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
594 if (! $description) {
595 $description = t('[No description]');
598 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
600 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
605 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
607 $rr['title'] = $title;
608 $rr['description'] = $desciption;
609 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
610 $rr['startime'] = $strt;
611 $rr['today'] = $today;
615 $tpl = get_markup_template("events_reminder.tpl");
616 return replace_macros($tpl, array(
617 '$baseurl' => App::get_baseurl(),
618 '$classtoday' => $classtoday,
619 '$count' => count($r) - $skip,
620 '$event_reminders' => t('Event Reminders'),
621 '$event_title' => t('Events this week:'),
626 function advanced_profile(App $a) {
629 $uid = $a->profile['uid'];
631 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
632 '$title' => t('Profile')
635 if ($a->profile['name']) {
637 $tpl = get_markup_template('profile_advanced.tpl');
641 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
643 if ($a->profile['gender']) {
644 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
647 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
648 $year_bd_format = t('j F, Y');
649 $short_bd_format = t('j F');
652 $val = ((intval($a->profile['dob']))
653 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
654 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
656 $profile['birthday'] = array( t('Birthday:'), $val);
660 if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) {
661 $profile['age'] = array( t('Age:'), $age );
664 if ($a->profile['marital']) {
665 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
668 /// @TODO Maybe use x() here, plus below?
669 if ($a->profile['with']) {
670 $profile['marital']['with'] = $a->profile['with'];
673 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
674 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
677 if ($a->profile['sexual']) {
678 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
681 if ($a->profile['homepage']) {
682 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
685 if ($a->profile['hometown']) {
686 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
689 if ($a->profile['pub_keywords']) {
690 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
693 if ($a->profile['politic']) {
694 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
697 if ($a->profile['religion']) {
698 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
701 if ($txt = prepare_text($a->profile['about'])) {
702 $profile['about'] = array( t('About:'), $txt );
705 if ($txt = prepare_text($a->profile['interest'])) {
706 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
709 if ($txt = prepare_text($a->profile['likes'])) {
710 $profile['likes'] = array( t('Likes:'), $txt);
713 if ($txt = prepare_text($a->profile['dislikes'])) {
714 $profile['dislikes'] = array( t('Dislikes:'), $txt);
717 if ($txt = prepare_text($a->profile['contact'])) {
718 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
721 if ($txt = prepare_text($a->profile['music'])) {
722 $profile['music'] = array( t('Musical interests:'), $txt);
725 if ($txt = prepare_text($a->profile['book'])) {
726 $profile['book'] = array( t('Books, literature:'), $txt);
729 if ($txt = prepare_text($a->profile['tv'])) {
730 $profile['tv'] = array( t('Television:'), $txt);
733 if ($txt = prepare_text($a->profile['film'])) {
734 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
737 if ($txt = prepare_text($a->profile['romance'])) {
738 $profile['romance'] = array( t('Love/Romance:'), $txt);
741 if ($txt = prepare_text($a->profile['work'])) {
742 $profile['work'] = array( t('Work/employment:'), $txt);
745 if ($txt = prepare_text($a->profile['education'])) {
746 $profile['education'] = array( t('School/education:'), $txt );
749 //show subcribed forum if it is enabled in the usersettings
750 if (feature_enabled($uid,'forumlist_profile')) {
751 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
754 if ($a->profile['uid'] == local_user()) {
755 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
758 return replace_macros($tpl, array(
759 '$title' => t('Profile'),
760 '$basic' => t('Basic'),
761 '$advanced' => t('Advanced'),
762 '$profile' => $profile
769 function profile_tabs($a, $is_owner=False, $nickname=Null) {
770 //echo "<pre>"; var_dump($a->user); killme();
772 if (is_null($nickname)) {
773 $nickname = $a->user['nickname'];
776 if (x($_GET,'tab')) {
777 $tab = notags(trim($_GET['tab']));
780 $url = App::get_baseurl() . '/profile/' . $nickname;
784 'label'=>t('Status'),
786 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
787 'title' => t('Status Messages and Posts'),
788 'id' => 'status-tab',
792 'label' => t('Profile'),
793 'url' => $url.'/?tab=profile',
794 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
795 'title' => t('Profile Details'),
796 'id' => 'profile-tab',
800 'label' => t('Photos'),
801 'url' => App::get_baseurl() . '/photos/' . $nickname,
802 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
803 'title' => t('Photo Albums'),
808 'label' => t('Videos'),
809 'url' => App::get_baseurl() . '/videos/' . $nickname,
810 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
811 'title' => t('Videos'),
817 // the calendar link for the full featured events calendar
818 if ($is_owner && $a->theme_events_in_profile) {
820 'label' => t('Events'),
821 'url' => App::get_baseurl() . '/events',
822 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
823 'title' => t('Events and Calendar'),
824 'id' => 'events-tab',
827 // if the user is not the owner of the calendar we only show a calendar
828 // with the public events of the calendar owner
829 } elseif (! $is_owner) {
831 'label' => t('Events'),
832 'url' => App::get_baseurl() . '/cal/' . $nickname,
833 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
834 'title' => t('Events and Calendar'),
835 'id' => 'events-tab',
842 'label' => t('Personal Notes'),
843 'url' => App::get_baseurl() . '/notes',
844 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
845 'title' => t('Only You Can See This'),
851 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
853 'label' => t('Contacts'),
854 'url' => App::get_baseurl() . '/viewcontacts/' . $nickname,
855 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
856 'title' => t('Contacts'),
857 'id' => 'viewcontacts-tab',
862 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
863 call_hooks('profile_tabs', $arr);
865 $tpl = get_markup_template('common_tabs.tpl');
867 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
870 function get_my_url() {
871 if (x($_SESSION, 'my_url')) {
872 return $_SESSION['my_url'];
877 function zrl_init(App $a) {
878 $tmp_str = get_my_url();
879 if (validate_url($tmp_str)) {
881 // Is it a DDoS attempt?
882 // The check fetches the cached value from gprobe to reduce the load for this system
883 $urlparts = parse_url($tmp_str);
885 $result = Cache::get("gprobe:" . $urlparts["host"]);
886 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
887 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
891 proc_run(PRIORITY_LOW, 'include/gprobe.php', $tmp_str);
892 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
893 call_hooks('zrl_init', $arr);
897 function zrl($s, $force = false) {
901 if ((! strpos($s, '/profile/')) && (! $force)) {
904 if ($force && substr($s, -1, 1) !== '/') {
907 $achar = strpos($s, '?') ? '&' : '?';
908 $mine = get_my_url();
909 if ($mine && ! link_compare($mine, $s)) {
910 return $s . $achar . 'zrl=' . urlencode($mine);
916 * @brief Get the user ID of the page owner
918 * Used from within PCSS themes to set theme parameters. If there's a
919 * puid request variable, that is the "page owner" and normally their theme
920 * settings take precedence; unless a local user sets the "always_my_theme"
921 * system pconfig, which means they don't want to see anybody else's theme
922 * settings except their own while on this site.
924 * @return int user ID
926 * @note Returns local_user instead of user ID if "always_my_theme"
929 function get_theme_uid() {
930 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
931 if ((local_user()) && ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))) {