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;
14 require_once 'include/ForumManager.php';
15 require_once 'include/bbcode.php';
16 require_once 'mod/proxy.php';
20 * @brief Loads a profile into the page sidebar.
22 * The function requires a writeable copy of the main App structure, and the nickname
23 * of a registered local account.
25 * If the viewer is an authenticated remote viewer, the profile displayed is the
26 * one that has been configured for his/her viewing in the Contact manager.
27 * Passing a non-zero profile ID can also allow a preview of a selected profile
30 * Profile information is placed in the App structure for later retrieval.
31 * Honours the owner's chosen theme for display.
33 * @attention Should only be run in the _init() functions of a module. That ensures that
34 * the theme is chosen before the _init() function of a theme is run, which will usually
35 * load a lot of theme-specific content
37 * @param object $a App
38 * @param string $nickname string
39 * @param int $profile int
40 * @param array $profiledata array
42 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array())
45 "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
49 if (!$user && count($user) && !count($profiledata)) {
50 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
51 notice(t('Requested account is not available.') . EOL);
56 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
58 if (empty($pdata) && empty($profiledata)) {
59 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
60 notice(t('Requested profile is not available.') . EOL);
65 // fetch user tags if this isn't the default profile
67 if (!$pdata['is-default']) {
69 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
70 intval($pdata['profile_uid'])
73 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
77 $a->profile_uid = $pdata['profile_uid'];
79 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
80 $a->profile['network'] = NETWORK_DFRN;
82 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
84 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
85 $_SESSION['theme'] = $a->profile['theme'];
88 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
91 * load/reload current theme info
94 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
96 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
97 if (file_exists($theme_info_file)) {
98 require_once $theme_info_file;
101 if (! (x($a->page, 'aside'))) {
102 $a->page['aside'] = '';
105 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
106 $a->page['aside'] .= replace_macros(
107 get_markup_template('profile_edlink.tpl'),
109 '$editprofile' => t('Edit profile'),
110 '$profid' => $a->profile['id']
115 $block = (((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) ? true : false);
119 * By now, the contact block isn't shown, when a different profile is given
120 * But: When this profile was on the same server, then we could display the contacts
123 $a->page['aside'] .= profile_sidebar($profiledata, true);
125 $a->page['aside'] .= profile_sidebar($a->profile, $block);
129 $a->page['aside'] .= contact_block();*/
136 * @brief Get all profil data of a local user
138 * If the viewer is an authenticated remote viewer, the profile displayed is the
139 * one that has been configured for his/her viewing in the Contact manager.
140 * Passing a non-zero profile ID can also allow a preview of a selected profile
143 * @param string $nickname nick
144 * @param int $uid uid
145 * @param int $profile ID of the profile
147 * Includes all available profile data
149 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
151 if (remote_user() && count($_SESSION['remote'])) {
152 foreach ($_SESSION['remote'] as $visitor) {
153 if ($visitor['uid'] == $uid) {
154 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
155 if (DBM::is_result($r)) {
156 $profile = $r['profile-id'];
166 $profile_int = intval($profile);
167 $r = dba::fetch_first(
168 "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` = ? AND `profile`.`id` = ? LIMIT 1",
180 if (!DBM::is_result($r)) {
181 $r = dba::fetch_first(
182 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
183 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
184 `profile`.`uid` AS `profile_uid`, `profile`.*,
185 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
187 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
188 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
189 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
199 * @brief Formats a profile for display in the sidebar.
201 * It is very difficult to templatise the HTML completely
202 * because of all the conditional logic.
204 * @param array $profile
207 * @return HTML string stuitable for sidebar inclusion
209 * @note Returns empty string if passed $profile is wrong type or not populated
211 * @hooks 'profile_sidebar_enter'
212 * array $profile - profile data
213 * @hooks 'profile_sidebar'
216 function profile_sidebar($profile, $block = 0)
225 // This function can also use contact information in $profile
226 $is_contact = x($profile, 'cid');
228 if ((! is_array($profile)) && (! count($profile))) {
232 $profile['picdate'] = urlencode($profile['picdate']);
234 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
235 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
237 $profile['network_name'] = "";
240 call_hooks('profile_sidebar_enter', $profile);
243 // don't show connect link to yourself
244 $connect = (($profile['uid'] != local_user()) ? t('Connect') : false);
246 // don't show connect link to authenticated visitors either
247 if (remote_user() && count($_SESSION['remote'])) {
248 foreach ($_SESSION['remote'] as $visitor) {
249 if ($visitor['uid'] == $profile['uid']) {
256 // Is the local user already connected to that user?
257 if ($connect && local_user()) {
258 if (isset($profile["url"])) {
259 $profile_url = normalise_link($profile["url"]);
261 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
264 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
269 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
272 $remoteconnect = null;
273 if (isset($profile['remoteconnect']))
274 $remoteconnect = $profile['remoteconnect'];
276 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
277 $subscribe_feed = t("Atom feed");
279 $subscribe_feed = false;
281 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
282 $wallmessage = t('Message');
283 $wallmessage_link = "wallmessage/".$profile["nickname"];
287 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
288 intval($profile['uid']),
289 intval(remote_user()),
290 intval(CONTACT_IS_FRIEND)
294 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
295 intval($profile['uid']),
296 dbesc(normalise_link(get_my_url())),
297 intval(CONTACT_IS_FRIEND)
301 $remote_url = $r[0]["url"];
302 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
303 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
306 $wallmessage = false;
307 $wallmessage_link = false;
310 // show edit profile to yourself
311 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(), 'multi_profiles')) {
312 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
314 "SELECT * FROM `profile` WHERE `uid` = %d",
318 $profile['menu'] = array(
319 'chg_photo' => t('Change profile photo'),
320 'cr_new' => t('Create New Profile'),
321 'entries' => array(),
324 if (DBM::is_result($r)) {
325 foreach ($r as $rr) {
326 $profile['menu']['entries'][] = array(
327 'photo' => $rr['thumb'],
329 'alt' => t('Profile Image'),
330 'profile_name' => $rr['profile-name'],
331 'isdefault' => $rr['is-default'],
332 'visibile_to_everybody' => t('visible to everybody'),
333 'edit_visibility' => t('Edit visibility'),
338 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(), 'multi_profiles')) {
339 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
340 $profile['menu'] = array(
341 'chg_photo' => t('Change profile photo'),
343 'entries' => array(),
347 // Fetch the account type
348 $account_type = account_type($profile);
350 if ((x($profile, 'address') == 1)
351 || (x($profile, 'location') == 1)
352 || (x($profile, 'locality') == 1)
353 || (x($profile, 'region') == 1)
354 || (x($profile, 'postal-code') == 1)
355 || (x($profile, 'country-name') == 1)
357 $location = t('Location:');
360 $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
363 $marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
365 $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
367 $about = ((x($profile, 'about') == 1) ? t('About:') : false);
369 $xmpp = ((x($profile, 'xmpp') == 1) ? t('XMPP:') : false);
371 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
372 $location = $pdesc = $gender = $marital = $homepage = $about = false;
375 $firstname = ((strpos($profile['name'], ' '))
376 ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name']);
377 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'], strlen($firstname))));
379 if ($profile['guid'] != "") {
381 'guid' => $profile['guid'],
382 'podloc' => System::baseUrl(),
383 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
384 'nickname' => $profile['nickname'],
385 'fullname' => $profile['name'],
386 'firstname' => $firstname,
387 'lastname' => $lastname,
388 'photo300' => $profile['contact_photo'],
389 'photo100' => $profile['contact_thumb'],
390 'photo50' => $profile['contact_micro'],
397 $contact_block = contact_block();
399 if (is_array($a->profile) && !$a->profile['hide-friends']) {
401 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
402 intval($a->profile['uid'])
404 if (DBM::is_result($r)) {
405 $updated = date("c", strtotime($r[0]['updated']));
409 "SELECT COUNT(*) AS `total` FROM `contact`
411 AND NOT `self` AND NOT `blocked` AND NOT `pending`
412 AND NOT `hidden` AND NOT `archive`
413 AND `network` IN ('%s', '%s', '%s', '')",
414 intval($profile['uid']),
416 dbesc(NETWORK_DIASPORA),
417 dbesc(NETWORK_OSTATUS)
419 if (DBM::is_result($r)) {
420 $contacts = intval($r[0]['total']);
426 foreach ($profile as $k => $v) {
427 $k = str_replace('-', '_', $k);
431 if (isset($p["about"])) {
432 $p["about"] = bbcode($p["about"]);
435 if (isset($p["address"])) {
436 $p["address"] = bbcode($p["address"]);
438 $p["address"] = bbcode($p["location"]);
441 if (isset($p["photo"])) {
442 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
445 if ($a->theme['template_engine'] === 'internal') {
446 $location = template_escape($location);
449 $tpl = get_markup_template('profile_vcard.tpl');
450 $o .= replace_macros(
455 '$connect' => $connect,
456 '$remoteconnect' => $remoteconnect,
457 '$subscribe_feed' => $subscribe_feed,
458 '$wallmessage' => $wallmessage,
459 '$wallmessage_link' => $wallmessage_link,
460 '$account_type' => $account_type,
461 '$location' => $location,
462 '$gender' => $gender,
463 // '$pdesc' => $pdesc,
464 '$marital' => $marital,
465 '$homepage' => $homepage,
467 '$network' => t('Network:'),
468 '$contacts' => $contacts,
469 '$updated' => $updated,
470 '$diaspora' => $diaspora,
471 '$contact_block' => $contact_block,
475 $arr = array('profile' => &$profile, 'entry' => &$o);
477 call_hooks('profile_sidebar', $arr);
483 function get_birthdays()
488 if (! local_user() || $a->is_mobile || $a->is_tablet) {
493 * $mobile_detect = new Mobile_Detect();
494 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
499 $bd_format = t('g A l F d'); // 8 AM Friday January 18
500 $bd_short = t('F d');
502 $cachekey = "get_birthdays:".local_user();
503 $r = Cache::get($cachekey);
506 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
507 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
508 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
509 ORDER BY `start` ASC ",
511 datetime_convert('UTC', 'UTC', 'now + 6 days'),
512 datetime_convert('UTC', 'UTC', 'now')
514 if (DBM::is_result($s)) {
515 $r = dba::inArray($s);
516 Cache::set($cachekey, $r, CACHE_HOUR);
519 if (DBM::is_result($r)) {
521 $now = strtotime('now');
525 foreach ($r as $rr) {
526 if (strlen($rr['name'])) {
529 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
533 $classtoday = $istoday ? ' birthday-today ' : '';
535 foreach ($r as &$rr) {
536 if (! strlen($rr['name'])) {
542 if (in_array($rr['cid'], $cids)) {
545 $cids[] = $rr['cid'];
547 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
550 if ($rr['network'] === NETWORK_DFRN) {
551 $sparkle = " sparkle";
552 $url = System::baseUrl() . '/redir/' . $rr['cid'];
556 $rr['title'] = $rr['name'];
557 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
558 $rr['startime'] = null;
559 $rr['today'] = $today;
563 $tpl = get_markup_template("birthdays_reminder.tpl");
564 return replace_macros(
567 '$baseurl' => System::baseUrl(),
568 '$classtoday' => $classtoday,
570 '$event_reminders' => t('Birthday Reminders'),
571 '$event_title' => t('Birthdays this week:'),
573 '$lbr' => '{', // raw brackets mess up if/endif macro processing
580 function get_events()
582 require_once 'include/bbcode.php';
586 if (! local_user() || $a->is_mobile || $a->is_tablet) {
591 * $mobile_detect = new Mobile_Detect();
592 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
597 $bd_format = t('g A l F d'); // 8 AM Friday January 18
598 $bd_short = t('F d');
601 "SELECT `event`.* FROM `event`
602 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
603 ORDER BY `start` ASC ",
605 datetime_convert('UTC', 'UTC', 'now + 7 days'),
606 datetime_convert('UTC', 'UTC', 'now - 1 days')
611 if (DBM::is_result($s)) {
612 $now = strtotime('now');
615 while ($rr = dba::fetch($s)) {
616 if (strlen($rr['name'])) {
620 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
621 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
625 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
627 if (strlen($title) > 35) {
628 $title = substr($title, 0, 32) . '... ';
631 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
632 if (! $description) {
633 $description = t('[No description]');
636 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
638 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
642 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
644 $rr['title'] = $title;
645 $rr['description'] = $desciption;
646 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
647 $rr['startime'] = $strt;
648 $rr['today'] = $today;
653 $classtoday = (($istoday) ? 'event-today' : '');
655 $tpl = get_markup_template("events_reminder.tpl");
656 return replace_macros(
659 '$baseurl' => System::baseUrl(),
660 '$classtoday' => $classtoday,
661 '$count' => count($r),
662 '$event_reminders' => t('Event Reminders'),
663 '$event_title' => t('Events this week:'),
669 function advanced_profile(App $a)
672 $uid = $a->profile['uid'];
674 $o .= replace_macros(
675 get_markup_template('section_title.tpl'),
677 '$title' => t('Profile')
681 if ($a->profile['name']) {
682 $tpl = get_markup_template('profile_advanced.tpl');
686 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
688 if ($a->profile['gender']) {
689 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
692 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
693 $year_bd_format = t('j F, Y');
694 $short_bd_format = t('j F');
697 $val = ((intval($a->profile['dob']))
698 ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
699 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)));
701 $profile['birthday'] = array( t('Birthday:'), $val);
703 if (!empty($a->profile['dob'])
704 && $a->profile['dob'] > '0001-01-01'
705 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
707 $profile['age'] = array( t('Age:'), $age );
710 if ($a->profile['marital']) {
711 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
714 /// @TODO Maybe use x() here, plus below?
715 if ($a->profile['with']) {
716 $profile['marital']['with'] = $a->profile['with'];
719 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
720 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
723 if ($a->profile['sexual']) {
724 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
727 if ($a->profile['homepage']) {
728 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
731 if ($a->profile['hometown']) {
732 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
735 if ($a->profile['pub_keywords']) {
736 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
739 if ($a->profile['politic']) {
740 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
743 if ($a->profile['religion']) {
744 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
747 if ($txt = prepare_text($a->profile['about'])) {
748 $profile['about'] = array( t('About:'), $txt );
751 if ($txt = prepare_text($a->profile['interest'])) {
752 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
755 if ($txt = prepare_text($a->profile['likes'])) {
756 $profile['likes'] = array( t('Likes:'), $txt);
759 if ($txt = prepare_text($a->profile['dislikes'])) {
760 $profile['dislikes'] = array( t('Dislikes:'), $txt);
763 if ($txt = prepare_text($a->profile['contact'])) {
764 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
767 if ($txt = prepare_text($a->profile['music'])) {
768 $profile['music'] = array( t('Musical interests:'), $txt);
771 if ($txt = prepare_text($a->profile['book'])) {
772 $profile['book'] = array( t('Books, literature:'), $txt);
775 if ($txt = prepare_text($a->profile['tv'])) {
776 $profile['tv'] = array( t('Television:'), $txt);
779 if ($txt = prepare_text($a->profile['film'])) {
780 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
783 if ($txt = prepare_text($a->profile['romance'])) {
784 $profile['romance'] = array( t('Love/Romance:'), $txt);
787 if ($txt = prepare_text($a->profile['work'])) {
788 $profile['work'] = array( t('Work/employment:'), $txt);
791 if ($txt = prepare_text($a->profile['education'])) {
792 $profile['education'] = array( t('School/education:'), $txt );
795 //show subcribed forum if it is enabled in the usersettings
796 if (feature_enabled($uid, 'forumlist_profile')) {
797 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
800 if ($a->profile['uid'] == local_user()) {
801 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
804 return replace_macros(
807 '$title' => t('Profile'),
808 '$basic' => t('Basic'),
809 '$advanced' => t('Advanced'),
810 '$profile' => $profile
818 function profile_tabs($a, $is_owner = false, $nickname = null)
820 //echo "<pre>"; var_dump($a->user); killme();
822 if (is_null($nickname)) {
823 $nickname = $a->user['nickname'];
826 if (x($_GET, 'tab')) {
827 $tab = notags(trim($_GET['tab']));
830 $url = System::baseUrl() . '/profile/' . $nickname;
834 'label'=>t('Status'),
836 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
837 'title' => t('Status Messages and Posts'),
838 'id' => 'status-tab',
842 'label' => t('Profile'),
843 'url' => $url.'/?tab=profile',
844 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
845 'title' => t('Profile Details'),
846 'id' => 'profile-tab',
850 'label' => t('Photos'),
851 'url' => System::baseUrl() . '/photos/' . $nickname,
852 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
853 'title' => t('Photo Albums'),
858 'label' => t('Videos'),
859 'url' => System::baseUrl() . '/videos/' . $nickname,
860 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
861 'title' => t('Videos'),
867 // the calendar link for the full featured events calendar
868 if ($is_owner && $a->theme_events_in_profile) {
870 'label' => t('Events'),
871 'url' => System::baseUrl() . '/events',
872 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
873 'title' => t('Events and Calendar'),
874 'id' => 'events-tab',
877 // if the user is not the owner of the calendar we only show a calendar
878 // with the public events of the calendar owner
879 } elseif (! $is_owner) {
881 'label' => t('Events'),
882 'url' => System::baseUrl() . '/cal/' . $nickname,
883 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
884 'title' => t('Events and Calendar'),
885 'id' => 'events-tab',
892 'label' => t('Personal Notes'),
893 'url' => System::baseUrl() . '/notes',
894 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
895 'title' => t('Only You Can See This'),
901 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
903 'label' => t('Contacts'),
904 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
905 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
906 'title' => t('Contacts'),
907 'id' => 'viewcontacts-tab',
912 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
913 call_hooks('profile_tabs', $arr);
915 $tpl = get_markup_template('common_tabs.tpl');
917 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
920 function get_my_url()
922 if (x($_SESSION, 'my_url')) {
923 return $_SESSION['my_url'];
928 function zrl_init(App $a)
930 $tmp_str = get_my_url();
931 if (validate_url($tmp_str)) {
932 // Is it a DDoS attempt?
933 // The check fetches the cached value from gprobe to reduce the load for this system
934 $urlparts = parse_url($tmp_str);
936 $result = Cache::get("gprobe:" . $urlparts["host"]);
937 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
938 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
942 Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
943 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
944 call_hooks('zrl_init', $arr);
948 function zrl($s, $force = false)
953 if ((! strpos($s, '/profile/')) && (! $force)) {
956 if ($force && substr($s, -1, 1) !== '/') {
959 $achar = strpos($s, '?') ? '&' : '?';
960 $mine = get_my_url();
961 if ($mine && ! link_compare($mine, $s)) {
962 return $s . $achar . 'zrl=' . urlencode($mine);
968 * @brief Get the user ID of the page owner
970 * Used from within PCSS themes to set theme parameters. If there's a
971 * puid request variable, that is the "page owner" and normally their theme
972 * settings take precedence; unless a local user sets the "always_my_theme"
973 * system pconfig, which means they don't want to see anybody else's theme
974 * settings except their own while on this site.
976 * @return int user ID
978 * @note Returns local_user instead of user ID if "always_my_theme"
981 function get_theme_uid()
983 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
984 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {