3 * @file include/identity.php
7 use Friendica\Core\Cache;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Core\System;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBM;
13 use Friendica\Object\Contact;
15 require_once 'include/ForumManager.php';
16 require_once 'include/bbcode.php';
17 require_once 'mod/proxy.php';
21 * @brief Loads a profile into the page sidebar.
23 * The function requires a writeable copy of the main App structure, and the nickname
24 * of a registered local account.
26 * If the viewer is an authenticated remote viewer, the profile displayed is the
27 * one that has been configured for his/her viewing in the Contact manager.
28 * Passing a non-zero profile ID can also allow a preview of a selected profile
31 * Profile information is placed in the App structure for later retrieval.
32 * Honours the owner's chosen theme for display.
34 * @attention Should only be run in the _init() functions of a module. That ensures that
35 * the theme is chosen before the _init() function of a theme is run, which will usually
36 * load a lot of theme-specific content
38 * @param object $a App
39 * @param string $nickname string
40 * @param int $profile int
41 * @param array $profiledata array
43 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array())
46 "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
50 if (!$user && count($user) && !count($profiledata)) {
51 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
52 notice(t('Requested account is not available.') . EOL);
57 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
59 if (empty($pdata) && empty($profiledata)) {
60 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
61 notice(t('Requested profile is not available.') . EOL);
66 // fetch user tags if this isn't the default profile
68 if (!$pdata['is-default']) {
70 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
71 intval($pdata['profile_uid'])
74 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
78 $a->profile_uid = $pdata['profile_uid'];
80 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
81 $a->profile['network'] = NETWORK_DFRN;
83 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
85 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
86 $_SESSION['theme'] = $a->profile['theme'];
89 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
92 * load/reload current theme info
95 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
97 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
98 if (file_exists($theme_info_file)) {
99 require_once $theme_info_file;
102 if (! (x($a->page, 'aside'))) {
103 $a->page['aside'] = '';
106 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
107 $a->page['aside'] .= replace_macros(
108 get_markup_template('profile_edlink.tpl'),
110 '$editprofile' => t('Edit profile'),
111 '$profid' => $a->profile['id']
116 $block = (((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) ? true : false);
120 * By now, the contact block isn't shown, when a different profile is given
121 * But: When this profile was on the same server, then we could display the contacts
124 $a->page['aside'] .= profile_sidebar($profiledata, true);
126 $a->page['aside'] .= profile_sidebar($a->profile, $block);
130 $a->page['aside'] .= contact_block();*/
137 * @brief Get all profil data of a local user
139 * If the viewer is an authenticated remote viewer, the profile displayed is the
140 * one that has been configured for his/her viewing in the Contact manager.
141 * Passing a non-zero profile ID can also allow a preview of a selected profile
144 * @param string $nickname nick
145 * @param int $uid uid
146 * @param int $profile ID of the profile
148 * Includes all available profile data
150 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
152 if (remote_user() && count($_SESSION['remote'])) {
153 foreach ($_SESSION['remote'] as $visitor) {
154 if ($visitor['uid'] == $uid) {
155 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
156 if (DBM::is_result($r)) {
157 $profile = $r['profile-id'];
167 $profile_int = intval($profile);
168 $r = dba::fetch_first(
169 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
170 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
171 `profile`.`uid` AS `profile_uid`, `profile`.*,
172 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
174 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
175 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
176 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
181 if (!DBM::is_result($r)) {
182 $r = dba::fetch_first(
183 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
184 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
185 `profile`.`uid` AS `profile_uid`, `profile`.*,
186 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
188 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
189 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
190 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
200 * @brief Formats a profile for display in the sidebar.
202 * It is very difficult to templatise the HTML completely
203 * because of all the conditional logic.
205 * @param array $profile
208 * @return HTML string stuitable for sidebar inclusion
210 * @note Returns empty string if passed $profile is wrong type or not populated
212 * @hooks 'profile_sidebar_enter'
213 * array $profile - profile data
214 * @hooks 'profile_sidebar'
217 function profile_sidebar($profile, $block = 0)
226 // This function can also use contact information in $profile
227 $is_contact = x($profile, 'cid');
229 if ((! is_array($profile)) && (! count($profile))) {
233 $profile['picdate'] = urlencode($profile['picdate']);
235 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
236 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
238 $profile['network_name'] = "";
241 call_hooks('profile_sidebar_enter', $profile);
244 // don't show connect link to yourself
245 $connect = (($profile['uid'] != local_user()) ? t('Connect') : false);
247 // don't show connect link to authenticated visitors either
248 if (remote_user() && count($_SESSION['remote'])) {
249 foreach ($_SESSION['remote'] as $visitor) {
250 if ($visitor['uid'] == $profile['uid']) {
257 // Is the local user already connected to that user?
258 if ($connect && local_user()) {
259 if (isset($profile["url"])) {
260 $profile_url = normalise_link($profile["url"]);
262 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
265 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
270 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
273 $remoteconnect = null;
274 if (isset($profile['remoteconnect']))
275 $remoteconnect = $profile['remoteconnect'];
277 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
278 $subscribe_feed = t("Atom feed");
280 $subscribe_feed = false;
282 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
283 $wallmessage = t('Message');
284 $wallmessage_link = "wallmessage/".$profile["nickname"];
288 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
289 intval($profile['uid']),
290 intval(remote_user()),
291 intval(CONTACT_IS_FRIEND)
295 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
296 intval($profile['uid']),
297 dbesc(normalise_link(get_my_url())),
298 intval(CONTACT_IS_FRIEND)
302 $remote_url = $r[0]["url"];
303 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
304 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
307 $wallmessage = false;
308 $wallmessage_link = false;
311 // show edit profile to yourself
312 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(), 'multi_profiles')) {
313 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
315 "SELECT * FROM `profile` WHERE `uid` = %d",
319 $profile['menu'] = array(
320 'chg_photo' => t('Change profile photo'),
321 'cr_new' => t('Create New Profile'),
322 'entries' => array(),
325 if (DBM::is_result($r)) {
326 foreach ($r as $rr) {
327 $profile['menu']['entries'][] = array(
328 'photo' => $rr['thumb'],
330 'alt' => t('Profile Image'),
331 'profile_name' => $rr['profile-name'],
332 'isdefault' => $rr['is-default'],
333 'visibile_to_everybody' => t('visible to everybody'),
334 'edit_visibility' => t('Edit visibility'),
339 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(), 'multi_profiles')) {
340 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
341 $profile['menu'] = array(
342 'chg_photo' => t('Change profile photo'),
344 'entries' => array(),
348 // Fetch the account type
349 $account_type = Contact::getAccountType($profile);
351 if ((x($profile, 'address') == 1)
352 || (x($profile, 'location') == 1)
353 || (x($profile, 'locality') == 1)
354 || (x($profile, 'region') == 1)
355 || (x($profile, 'postal-code') == 1)
356 || (x($profile, 'country-name') == 1)
358 $location = t('Location:');
361 $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
364 $marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
366 $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
368 $about = ((x($profile, 'about') == 1) ? t('About:') : false);
370 $xmpp = ((x($profile, 'xmpp') == 1) ? t('XMPP:') : false);
372 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
373 $location = $pdesc = $gender = $marital = $homepage = $about = false;
376 $firstname = ((strpos($profile['name'], ' '))
377 ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name']);
378 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'], strlen($firstname))));
380 if ($profile['guid'] != "") {
382 'guid' => $profile['guid'],
383 'podloc' => System::baseUrl(),
384 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
385 'nickname' => $profile['nickname'],
386 'fullname' => $profile['name'],
387 'firstname' => $firstname,
388 'lastname' => $lastname,
389 'photo300' => $profile['contact_photo'],
390 'photo100' => $profile['contact_thumb'],
391 'photo50' => $profile['contact_micro'],
398 $contact_block = contact_block();
400 if (is_array($a->profile) && !$a->profile['hide-friends']) {
402 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
403 intval($a->profile['uid'])
405 if (DBM::is_result($r)) {
406 $updated = date("c", strtotime($r[0]['updated']));
410 "SELECT COUNT(*) AS `total` FROM `contact`
412 AND NOT `self` AND NOT `blocked` AND NOT `pending`
413 AND NOT `hidden` AND NOT `archive`
414 AND `network` IN ('%s', '%s', '%s', '')",
415 intval($profile['uid']),
417 dbesc(NETWORK_DIASPORA),
418 dbesc(NETWORK_OSTATUS)
420 if (DBM::is_result($r)) {
421 $contacts = intval($r[0]['total']);
427 foreach ($profile as $k => $v) {
428 $k = str_replace('-', '_', $k);
432 if (isset($p["about"])) {
433 $p["about"] = bbcode($p["about"]);
436 if (isset($p["address"])) {
437 $p["address"] = bbcode($p["address"]);
439 $p["address"] = bbcode($p["location"]);
442 if (isset($p["photo"])) {
443 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
446 if ($a->theme['template_engine'] === 'internal') {
447 $location = template_escape($location);
450 $tpl = get_markup_template('profile_vcard.tpl');
451 $o .= replace_macros(
456 '$connect' => $connect,
457 '$remoteconnect' => $remoteconnect,
458 '$subscribe_feed' => $subscribe_feed,
459 '$wallmessage' => $wallmessage,
460 '$wallmessage_link' => $wallmessage_link,
461 '$account_type' => $account_type,
462 '$location' => $location,
463 '$gender' => $gender,
464 // '$pdesc' => $pdesc,
465 '$marital' => $marital,
466 '$homepage' => $homepage,
468 '$network' => t('Network:'),
469 '$contacts' => $contacts,
470 '$updated' => $updated,
471 '$diaspora' => $diaspora,
472 '$contact_block' => $contact_block,
476 $arr = array('profile' => &$profile, 'entry' => &$o);
478 call_hooks('profile_sidebar', $arr);
484 function get_birthdays()
489 if (! local_user() || $a->is_mobile || $a->is_tablet) {
494 * $mobile_detect = new Mobile_Detect();
495 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
500 $bd_format = t('g A l F d'); // 8 AM Friday January 18
501 $bd_short = t('F d');
503 $cachekey = "get_birthdays:".local_user();
504 $r = Cache::get($cachekey);
507 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
508 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
509 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
510 ORDER BY `start` ASC ",
512 datetime_convert('UTC', 'UTC', 'now + 6 days'),
513 datetime_convert('UTC', 'UTC', 'now')
515 if (DBM::is_result($s)) {
516 $r = dba::inArray($s);
517 Cache::set($cachekey, $r, CACHE_HOUR);
520 if (DBM::is_result($r)) {
522 $now = strtotime('now');
526 foreach ($r as $rr) {
527 if (strlen($rr['name'])) {
530 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
534 $classtoday = $istoday ? ' birthday-today ' : '';
536 foreach ($r as &$rr) {
537 if (! strlen($rr['name'])) {
543 if (in_array($rr['cid'], $cids)) {
546 $cids[] = $rr['cid'];
548 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
551 if ($rr['network'] === NETWORK_DFRN) {
552 $sparkle = " sparkle";
553 $url = System::baseUrl() . '/redir/' . $rr['cid'];
557 $rr['title'] = $rr['name'];
558 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
559 $rr['startime'] = null;
560 $rr['today'] = $today;
564 $tpl = get_markup_template("birthdays_reminder.tpl");
565 return replace_macros(
568 '$baseurl' => System::baseUrl(),
569 '$classtoday' => $classtoday,
571 '$event_reminders' => t('Birthday Reminders'),
572 '$event_title' => t('Birthdays this week:'),
574 '$lbr' => '{', // raw brackets mess up if/endif macro processing
581 function get_events()
583 require_once 'include/bbcode.php';
587 if (! local_user() || $a->is_mobile || $a->is_tablet) {
592 * $mobile_detect = new Mobile_Detect();
593 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
598 $bd_format = t('g A l F d'); // 8 AM Friday January 18
599 $bd_short = t('F d');
602 "SELECT `event`.* FROM `event`
603 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
604 ORDER BY `start` ASC ",
606 datetime_convert('UTC', 'UTC', 'now + 7 days'),
607 datetime_convert('UTC', 'UTC', 'now - 1 days')
612 if (DBM::is_result($s)) {
613 $now = strtotime('now');
616 while ($rr = dba::fetch($s)) {
617 if (strlen($rr['name'])) {
621 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
622 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
626 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
628 if (strlen($title) > 35) {
629 $title = substr($title, 0, 32) . '... ';
632 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
633 if (! $description) {
634 $description = t('[No description]');
637 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
639 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
643 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
645 $rr['title'] = $title;
646 $rr['description'] = $desciption;
647 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
648 $rr['startime'] = $strt;
649 $rr['today'] = $today;
654 $classtoday = (($istoday) ? 'event-today' : '');
656 $tpl = get_markup_template("events_reminder.tpl");
657 return replace_macros(
660 '$baseurl' => System::baseUrl(),
661 '$classtoday' => $classtoday,
662 '$count' => count($r),
663 '$event_reminders' => t('Event Reminders'),
664 '$event_title' => t('Events this week:'),
670 function advanced_profile(App $a)
673 $uid = $a->profile['uid'];
675 $o .= replace_macros(
676 get_markup_template('section_title.tpl'),
678 '$title' => t('Profile')
682 if ($a->profile['name']) {
683 $tpl = get_markup_template('profile_advanced.tpl');
687 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
689 if ($a->profile['gender']) {
690 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
693 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
694 $year_bd_format = t('j F, Y');
695 $short_bd_format = t('j F');
698 $val = ((intval($a->profile['dob']))
699 ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
700 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)));
702 $profile['birthday'] = array( t('Birthday:'), $val);
704 if (!empty($a->profile['dob'])
705 && $a->profile['dob'] > '0001-01-01'
706 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
708 $profile['age'] = array( t('Age:'), $age );
711 if ($a->profile['marital']) {
712 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
715 /// @TODO Maybe use x() here, plus below?
716 if ($a->profile['with']) {
717 $profile['marital']['with'] = $a->profile['with'];
720 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
721 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
724 if ($a->profile['sexual']) {
725 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
728 if ($a->profile['homepage']) {
729 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
732 if ($a->profile['hometown']) {
733 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
736 if ($a->profile['pub_keywords']) {
737 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
740 if ($a->profile['politic']) {
741 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
744 if ($a->profile['religion']) {
745 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
748 if ($txt = prepare_text($a->profile['about'])) {
749 $profile['about'] = array( t('About:'), $txt );
752 if ($txt = prepare_text($a->profile['interest'])) {
753 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
756 if ($txt = prepare_text($a->profile['likes'])) {
757 $profile['likes'] = array( t('Likes:'), $txt);
760 if ($txt = prepare_text($a->profile['dislikes'])) {
761 $profile['dislikes'] = array( t('Dislikes:'), $txt);
764 if ($txt = prepare_text($a->profile['contact'])) {
765 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
768 if ($txt = prepare_text($a->profile['music'])) {
769 $profile['music'] = array( t('Musical interests:'), $txt);
772 if ($txt = prepare_text($a->profile['book'])) {
773 $profile['book'] = array( t('Books, literature:'), $txt);
776 if ($txt = prepare_text($a->profile['tv'])) {
777 $profile['tv'] = array( t('Television:'), $txt);
780 if ($txt = prepare_text($a->profile['film'])) {
781 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
784 if ($txt = prepare_text($a->profile['romance'])) {
785 $profile['romance'] = array( t('Love/Romance:'), $txt);
788 if ($txt = prepare_text($a->profile['work'])) {
789 $profile['work'] = array( t('Work/employment:'), $txt);
792 if ($txt = prepare_text($a->profile['education'])) {
793 $profile['education'] = array( t('School/education:'), $txt );
796 //show subcribed forum if it is enabled in the usersettings
797 if (feature_enabled($uid, 'forumlist_profile')) {
798 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
801 if ($a->profile['uid'] == local_user()) {
802 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
805 return replace_macros(
808 '$title' => t('Profile'),
809 '$basic' => t('Basic'),
810 '$advanced' => t('Advanced'),
811 '$profile' => $profile
819 function profile_tabs($a, $is_owner = false, $nickname = null)
821 //echo "<pre>"; var_dump($a->user); killme();
823 if (is_null($nickname)) {
824 $nickname = $a->user['nickname'];
827 if (x($_GET, 'tab')) {
828 $tab = notags(trim($_GET['tab']));
831 $url = System::baseUrl() . '/profile/' . $nickname;
835 'label'=>t('Status'),
837 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
838 'title' => t('Status Messages and Posts'),
839 'id' => 'status-tab',
843 'label' => t('Profile'),
844 'url' => $url.'/?tab=profile',
845 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
846 'title' => t('Profile Details'),
847 'id' => 'profile-tab',
851 'label' => t('Photos'),
852 'url' => System::baseUrl() . '/photos/' . $nickname,
853 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
854 'title' => t('Photo Albums'),
859 'label' => t('Videos'),
860 'url' => System::baseUrl() . '/videos/' . $nickname,
861 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
862 'title' => t('Videos'),
868 // the calendar link for the full featured events calendar
869 if ($is_owner && $a->theme_events_in_profile) {
871 'label' => t('Events'),
872 'url' => System::baseUrl() . '/events',
873 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
874 'title' => t('Events and Calendar'),
875 'id' => 'events-tab',
878 // if the user is not the owner of the calendar we only show a calendar
879 // with the public events of the calendar owner
880 } elseif (! $is_owner) {
882 'label' => t('Events'),
883 'url' => System::baseUrl() . '/cal/' . $nickname,
884 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
885 'title' => t('Events and Calendar'),
886 'id' => 'events-tab',
893 'label' => t('Personal Notes'),
894 'url' => System::baseUrl() . '/notes',
895 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
896 'title' => t('Only You Can See This'),
902 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
904 'label' => t('Contacts'),
905 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
906 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
907 'title' => t('Contacts'),
908 'id' => 'viewcontacts-tab',
913 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
914 call_hooks('profile_tabs', $arr);
916 $tpl = get_markup_template('common_tabs.tpl');
918 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
921 function get_my_url()
923 if (x($_SESSION, 'my_url')) {
924 return $_SESSION['my_url'];
929 function zrl_init(App $a)
931 $tmp_str = get_my_url();
932 if (validate_url($tmp_str)) {
933 // Is it a DDoS attempt?
934 // The check fetches the cached value from gprobe to reduce the load for this system
935 $urlparts = parse_url($tmp_str);
937 $result = Cache::get("gprobe:" . $urlparts["host"]);
938 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
939 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
943 Worker::add(PRIORITY_LOW, 'GProbe', $tmp_str);
944 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
945 call_hooks('zrl_init', $arr);
949 function zrl($s, $force = false)
954 if ((! strpos($s, '/profile/')) && (! $force)) {
957 if ($force && substr($s, -1, 1) !== '/') {
960 $achar = strpos($s, '?') ? '&' : '?';
961 $mine = get_my_url();
962 if ($mine && ! link_compare($mine, $s)) {
963 return $s . $achar . 'zrl=' . urlencode($mine);
969 * @brief Get the user ID of the page owner
971 * Used from within PCSS themes to set theme parameters. If there's a
972 * puid request variable, that is the "page owner" and normally their theme
973 * settings take precedence; unless a local user sets the "always_my_theme"
974 * system pconfig, which means they don't want to see anybody else's theme
975 * settings except their own while on this site.
977 * @return int user ID
979 * @note Returns local_user instead of user ID if "always_my_theme"
982 function get_theme_uid()
984 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
985 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {