3 * @file include/identity.php
7 use Friendica\Content\Feature;
8 use Friendica\Content\ForumManager;
9 use Friendica\Core\Cache;
10 use Friendica\Core\Config;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\System;
13 use Friendica\Core\Worker;
14 use Friendica\Database\DBM;
15 use Friendica\Model\Contact;
16 use Friendica\Protocol\Diaspora;
18 require_once 'include/bbcode.php';
19 require_once 'mod/proxy.php';
23 * @brief Loads a profile into the page sidebar.
25 * The function requires a writeable copy of the main App structure, and the nickname
26 * of a registered local account.
28 * If the viewer is an authenticated remote viewer, the profile displayed is the
29 * one that has been configured for his/her viewing in the Contact manager.
30 * Passing a non-zero profile ID can also allow a preview of a selected profile
33 * Profile information is placed in the App structure for later retrieval.
34 * Honours the owner's chosen theme for display.
36 * @attention Should only be run in the _init() functions of a module. That ensures that
37 * the theme is chosen before the _init() function of a theme is run, which will usually
38 * load a lot of theme-specific content
40 * @param object $a App
41 * @param string $nickname string
42 * @param int $profile int
43 * @param array $profiledata array
45 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array())
48 "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
52 if (!$user && count($user) && !count($profiledata)) {
53 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
54 notice(t('Requested account is not available.') . EOL);
59 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
61 if (empty($pdata) && empty($profiledata)) {
62 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
63 notice(t('Requested profile is not available.') . EOL);
68 // fetch user tags if this isn't the default profile
70 if (!$pdata['is-default']) {
72 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
73 intval($pdata['profile_uid'])
76 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
80 $a->profile_uid = $pdata['profile_uid'];
82 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
83 $a->profile['network'] = NETWORK_DFRN;
85 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
87 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
88 $_SESSION['theme'] = $a->profile['theme'];
91 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
94 * load/reload current theme info
97 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
99 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
100 if (file_exists($theme_info_file)) {
101 require_once $theme_info_file;
104 if (! (x($a->page, 'aside'))) {
105 $a->page['aside'] = '';
108 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
109 $a->page['aside'] .= replace_macros(
110 get_markup_template('profile_edlink.tpl'),
112 '$editprofile' => t('Edit profile'),
113 '$profid' => $a->profile['id']
118 $block = (((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) ? true : false);
122 * By now, the contact block isn't shown, when a different profile is given
123 * But: When this profile was on the same server, then we could display the contacts
126 $a->page['aside'] .= profile_sidebar($profiledata, true);
128 $a->page['aside'] .= profile_sidebar($a->profile, $block);
132 $a->page['aside'] .= contact_block();*/
139 * @brief Get all profil data of a local user
141 * If the viewer is an authenticated remote viewer, the profile displayed is the
142 * one that has been configured for his/her viewing in the Contact manager.
143 * Passing a non-zero profile ID can also allow a preview of a selected profile
146 * @param string $nickname nick
147 * @param int $uid uid
148 * @param int $profile ID of the profile
150 * Includes all available profile data
152 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
154 if (remote_user() && count($_SESSION['remote'])) {
155 foreach ($_SESSION['remote'] as $visitor) {
156 if ($visitor['uid'] == $uid) {
157 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
158 if (DBM::is_result($r)) {
159 $profile = $r['profile-id'];
169 $profile_int = intval($profile);
170 $r = dba::fetch_first(
171 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
172 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
173 `profile`.`uid` AS `profile_uid`, `profile`.*,
174 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
176 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
177 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
178 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
183 if (!DBM::is_result($r)) {
184 $r = dba::fetch_first(
185 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
186 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
187 `profile`.`uid` AS `profile_uid`, `profile`.*,
188 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
190 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
191 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
192 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
202 * @brief Formats a profile for display in the sidebar.
204 * It is very difficult to templatise the HTML completely
205 * because of all the conditional logic.
207 * @param array $profile
210 * @return HTML string stuitable for sidebar inclusion
212 * @note Returns empty string if passed $profile is wrong type or not populated
214 * @hooks 'profile_sidebar_enter'
215 * array $profile - profile data
216 * @hooks 'profile_sidebar'
219 function profile_sidebar($profile, $block = 0)
228 // This function can also use contact information in $profile
229 $is_contact = x($profile, 'cid');
231 if ((! is_array($profile)) && (! count($profile))) {
235 $profile['picdate'] = urlencode($profile['picdate']);
237 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
238 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
240 $profile['network_name'] = "";
243 call_hooks('profile_sidebar_enter', $profile);
246 // don't show connect link to yourself
247 $connect = (($profile['uid'] != local_user()) ? t('Connect') : false);
249 // don't show connect link to authenticated visitors either
250 if (remote_user() && count($_SESSION['remote'])) {
251 foreach ($_SESSION['remote'] as $visitor) {
252 if ($visitor['uid'] == $profile['uid']) {
259 // Is the local user already connected to that user?
260 if ($connect && local_user()) {
261 if (isset($profile["url"])) {
262 $profile_url = normalise_link($profile["url"]);
264 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
267 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
272 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
275 $remoteconnect = null;
276 if (isset($profile['remoteconnect']))
277 $remoteconnect = $profile['remoteconnect'];
279 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
280 $subscribe_feed = t("Atom feed");
282 $subscribe_feed = false;
284 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
285 $wallmessage = t('Message');
286 $wallmessage_link = "wallmessage/".$profile["nickname"];
290 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
291 intval($profile['uid']),
292 intval(remote_user()),
293 intval(CONTACT_IS_FRIEND)
297 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
298 intval($profile['uid']),
299 dbesc(normalise_link(get_my_url())),
300 intval(CONTACT_IS_FRIEND)
304 $remote_url = $r[0]["url"];
305 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
306 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
309 $wallmessage = false;
310 $wallmessage_link = false;
313 // show edit profile to yourself
314 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
315 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
317 "SELECT * FROM `profile` WHERE `uid` = %d",
321 $profile['menu'] = array(
322 'chg_photo' => t('Change profile photo'),
323 'cr_new' => t('Create New Profile'),
324 'entries' => array(),
327 if (DBM::is_result($r)) {
328 foreach ($r as $rr) {
329 $profile['menu']['entries'][] = array(
330 'photo' => $rr['thumb'],
332 'alt' => t('Profile Image'),
333 'profile_name' => $rr['profile-name'],
334 'isdefault' => $rr['is-default'],
335 'visibile_to_everybody' => t('visible to everybody'),
336 'edit_visibility' => t('Edit visibility'),
341 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
342 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
343 $profile['menu'] = array(
344 'chg_photo' => t('Change profile photo'),
346 'entries' => array(),
350 // Fetch the account type
351 $account_type = Contact::getAccountType($profile);
353 if ((x($profile, 'address') == 1)
354 || (x($profile, 'location') == 1)
355 || (x($profile, 'locality') == 1)
356 || (x($profile, 'region') == 1)
357 || (x($profile, 'postal-code') == 1)
358 || (x($profile, 'country-name') == 1)
360 $location = t('Location:');
363 $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
366 $marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
368 $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
370 $about = ((x($profile, 'about') == 1) ? t('About:') : false);
372 $xmpp = ((x($profile, 'xmpp') == 1) ? t('XMPP:') : false);
374 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
375 $location = $pdesc = $gender = $marital = $homepage = $about = false;
378 $split_name = Diaspora::splitName($profile['name']);
379 $firstname = $split_name['first'];
380 $lastname = $split_name['last'];
382 if ($profile['guid'] != "") {
384 'guid' => $profile['guid'],
385 'podloc' => System::baseUrl(),
386 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
387 'nickname' => $profile['nickname'],
388 'fullname' => $profile['name'],
389 'firstname' => $firstname,
390 'lastname' => $lastname,
391 'photo300' => $profile['contact_photo'],
392 'photo100' => $profile['contact_thumb'],
393 'photo50' => $profile['contact_micro'],
400 $contact_block = contact_block();
402 if (is_array($a->profile) && !$a->profile['hide-friends']) {
404 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
405 intval($a->profile['uid'])
407 if (DBM::is_result($r)) {
408 $updated = date("c", strtotime($r[0]['updated']));
412 "SELECT COUNT(*) AS `total` FROM `contact`
414 AND NOT `self` AND NOT `blocked` AND NOT `pending`
415 AND NOT `hidden` AND NOT `archive`
416 AND `network` IN ('%s', '%s', '%s', '')",
417 intval($profile['uid']),
419 dbesc(NETWORK_DIASPORA),
420 dbesc(NETWORK_OSTATUS)
422 if (DBM::is_result($r)) {
423 $contacts = intval($r[0]['total']);
429 foreach ($profile as $k => $v) {
430 $k = str_replace('-', '_', $k);
434 if (isset($p["about"])) {
435 $p["about"] = bbcode($p["about"]);
438 if (isset($p["address"])) {
439 $p["address"] = bbcode($p["address"]);
441 $p["address"] = bbcode($p["location"]);
444 if (isset($p["photo"])) {
445 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
448 $tpl = get_markup_template('profile_vcard.tpl');
449 $o .= replace_macros(
454 '$connect' => $connect,
455 '$remoteconnect' => $remoteconnect,
456 '$subscribe_feed' => $subscribe_feed,
457 '$wallmessage' => $wallmessage,
458 '$wallmessage_link' => $wallmessage_link,
459 '$account_type' => $account_type,
460 '$location' => $location,
461 '$gender' => $gender,
462 // '$pdesc' => $pdesc,
463 '$marital' => $marital,
464 '$homepage' => $homepage,
466 '$network' => t('Network:'),
467 '$contacts' => $contacts,
468 '$updated' => $updated,
469 '$diaspora' => $diaspora,
470 '$contact_block' => $contact_block,
474 $arr = array('profile' => &$profile, 'entry' => &$o);
476 call_hooks('profile_sidebar', $arr);
482 function get_birthdays()
487 if (! local_user() || $a->is_mobile || $a->is_tablet) {
492 * $mobile_detect = new Mobile_Detect();
493 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
498 $bd_format = t('g A l F d'); // 8 AM Friday January 18
499 $bd_short = t('F d');
501 $cachekey = "get_birthdays:".local_user();
502 $r = Cache::get($cachekey);
505 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
506 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
507 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
508 ORDER BY `start` ASC ",
510 datetime_convert('UTC', 'UTC', 'now + 6 days'),
511 datetime_convert('UTC', 'UTC', 'now')
513 if (DBM::is_result($s)) {
514 $r = dba::inArray($s);
515 Cache::set($cachekey, $r, CACHE_HOUR);
518 if (DBM::is_result($r)) {
520 $now = strtotime('now');
524 foreach ($r as $rr) {
525 if (strlen($rr['name'])) {
528 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
532 $classtoday = $istoday ? ' birthday-today ' : '';
534 foreach ($r as &$rr) {
535 if (! strlen($rr['name'])) {
541 if (in_array($rr['cid'], $cids)) {
544 $cids[] = $rr['cid'];
546 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
549 if ($rr['network'] === NETWORK_DFRN) {
550 $sparkle = " sparkle";
551 $url = System::baseUrl() . '/redir/' . $rr['cid'];
555 $rr['title'] = $rr['name'];
556 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
557 $rr['startime'] = null;
558 $rr['today'] = $today;
562 $tpl = get_markup_template("birthdays_reminder.tpl");
563 return replace_macros(
566 '$baseurl' => System::baseUrl(),
567 '$classtoday' => $classtoday,
569 '$event_reminders' => t('Birthday Reminders'),
570 '$event_title' => t('Birthdays this week:'),
572 '$lbr' => '{', // raw brackets mess up if/endif macro processing
579 function get_events()
581 require_once 'include/bbcode.php';
585 if (! local_user() || $a->is_mobile || $a->is_tablet) {
590 * $mobile_detect = new Mobile_Detect();
591 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
596 $bd_format = t('g A l F d'); // 8 AM Friday January 18
597 $bd_short = t('F d');
600 "SELECT `event`.* FROM `event`
601 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
602 ORDER BY `start` ASC ",
604 datetime_convert('UTC', 'UTC', 'now + 7 days'),
605 datetime_convert('UTC', 'UTC', 'now - 1 days')
610 if (DBM::is_result($s)) {
611 $now = strtotime('now');
614 while ($rr = dba::fetch($s)) {
615 if (strlen($rr['name'])) {
619 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
620 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
624 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
626 if (strlen($title) > 35) {
627 $title = substr($title, 0, 32) . '... ';
630 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
631 if (! $description) {
632 $description = t('[No description]');
635 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
637 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
641 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
643 $rr['title'] = $title;
644 $rr['description'] = $desciption;
645 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
646 $rr['startime'] = $strt;
647 $rr['today'] = $today;
652 $classtoday = (($istoday) ? 'event-today' : '');
654 $tpl = get_markup_template("events_reminder.tpl");
655 return replace_macros(
658 '$baseurl' => System::baseUrl(),
659 '$classtoday' => $classtoday,
660 '$count' => count($r),
661 '$event_reminders' => t('Event Reminders'),
662 '$event_title' => t('Events this week:'),
668 function advanced_profile(App $a)
671 $uid = $a->profile['uid'];
673 $o .= replace_macros(
674 get_markup_template('section_title.tpl'),
676 '$title' => t('Profile')
680 if ($a->profile['name']) {
681 $tpl = get_markup_template('profile_advanced.tpl');
685 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
687 if ($a->profile['gender']) {
688 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
691 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
692 $year_bd_format = t('j F, Y');
693 $short_bd_format = t('j F');
696 $val = ((intval($a->profile['dob']))
697 ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
698 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)));
700 $profile['birthday'] = array( t('Birthday:'), $val);
702 if (!empty($a->profile['dob'])
703 && $a->profile['dob'] > '0001-01-01'
704 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
706 $profile['age'] = array( t('Age:'), $age );
709 if ($a->profile['marital']) {
710 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
713 /// @TODO Maybe use x() here, plus below?
714 if ($a->profile['with']) {
715 $profile['marital']['with'] = $a->profile['with'];
718 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
719 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
722 if ($a->profile['sexual']) {
723 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
726 if ($a->profile['homepage']) {
727 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
730 if ($a->profile['hometown']) {
731 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
734 if ($a->profile['pub_keywords']) {
735 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
738 if ($a->profile['politic']) {
739 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
742 if ($a->profile['religion']) {
743 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
746 if ($txt = prepare_text($a->profile['about'])) {
747 $profile['about'] = array( t('About:'), $txt );
750 if ($txt = prepare_text($a->profile['interest'])) {
751 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
754 if ($txt = prepare_text($a->profile['likes'])) {
755 $profile['likes'] = array( t('Likes:'), $txt);
758 if ($txt = prepare_text($a->profile['dislikes'])) {
759 $profile['dislikes'] = array( t('Dislikes:'), $txt);
762 if ($txt = prepare_text($a->profile['contact'])) {
763 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
766 if ($txt = prepare_text($a->profile['music'])) {
767 $profile['music'] = array( t('Musical interests:'), $txt);
770 if ($txt = prepare_text($a->profile['book'])) {
771 $profile['book'] = array( t('Books, literature:'), $txt);
774 if ($txt = prepare_text($a->profile['tv'])) {
775 $profile['tv'] = array( t('Television:'), $txt);
778 if ($txt = prepare_text($a->profile['film'])) {
779 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
782 if ($txt = prepare_text($a->profile['romance'])) {
783 $profile['romance'] = array( t('Love/Romance:'), $txt);
786 if ($txt = prepare_text($a->profile['work'])) {
787 $profile['work'] = array( t('Work/employment:'), $txt);
790 if ($txt = prepare_text($a->profile['education'])) {
791 $profile['education'] = array( t('School/education:'), $txt );
794 //show subcribed forum if it is enabled in the usersettings
795 if (Feature::isEnabled($uid, 'forumlist_profile')) {
796 $profile['forumlist'] = array( t('Forums:'), ForumManager::profileAdvanced($uid));
799 if ($a->profile['uid'] == local_user()) {
800 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
803 return replace_macros(
806 '$title' => t('Profile'),
807 '$basic' => t('Basic'),
808 '$advanced' => t('Advanced'),
809 '$profile' => $profile
817 function profile_tabs($a, $is_owner = false, $nickname = null)
819 //echo "<pre>"; var_dump($a->user); killme();
821 if (is_null($nickname)) {
822 $nickname = $a->user['nickname'];
825 if (x($_GET, 'tab')) {
826 $tab = notags(trim($_GET['tab']));
829 $url = System::baseUrl() . '/profile/' . $nickname;
833 'label'=>t('Status'),
835 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
836 'title' => t('Status Messages and Posts'),
837 'id' => 'status-tab',
841 'label' => t('Profile'),
842 'url' => $url.'/?tab=profile',
843 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
844 'title' => t('Profile Details'),
845 'id' => 'profile-tab',
849 'label' => t('Photos'),
850 'url' => System::baseUrl() . '/photos/' . $nickname,
851 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
852 'title' => t('Photo Albums'),
857 'label' => t('Videos'),
858 'url' => System::baseUrl() . '/videos/' . $nickname,
859 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
860 'title' => t('Videos'),
866 // the calendar link for the full featured events calendar
867 if ($is_owner && $a->theme_events_in_profile) {
869 'label' => t('Events'),
870 'url' => System::baseUrl() . '/events',
871 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
872 'title' => t('Events and Calendar'),
873 'id' => 'events-tab',
876 // if the user is not the owner of the calendar we only show a calendar
877 // with the public events of the calendar owner
878 } elseif (! $is_owner) {
880 'label' => t('Events'),
881 'url' => System::baseUrl() . '/cal/' . $nickname,
882 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
883 'title' => t('Events and Calendar'),
884 'id' => 'events-tab',
891 'label' => t('Personal Notes'),
892 'url' => System::baseUrl() . '/notes',
893 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
894 'title' => t('Only You Can See This'),
900 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
902 'label' => t('Contacts'),
903 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
904 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
905 'title' => t('Contacts'),
906 'id' => 'viewcontacts-tab',
911 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
912 call_hooks('profile_tabs', $arr);
914 $tpl = get_markup_template('common_tabs.tpl');
916 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
919 function get_my_url()
921 if (x($_SESSION, 'my_url')) {
922 return $_SESSION['my_url'];
927 function zrl_init(App $a)
929 $tmp_str = get_my_url();
930 if (validate_url($tmp_str)) {
931 // Is it a DDoS attempt?
932 // The check fetches the cached value from gprobe to reduce the load for this system
933 $urlparts = parse_url($tmp_str);
935 $result = Cache::get("gprobe:" . $urlparts["host"]);
936 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
937 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
941 Worker::add(PRIORITY_LOW, 'GProbe', $tmp_str);
942 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
943 call_hooks('zrl_init', $arr);
947 function zrl($s, $force = false)
952 if ((! strpos($s, '/profile/')) && (! $force)) {
955 if ($force && substr($s, -1, 1) !== '/') {
958 $achar = strpos($s, '?') ? '&' : '?';
959 $mine = get_my_url();
960 if ($mine && ! link_compare($mine, $s)) {
961 return $s . $achar . 'zrl=' . urlencode($mine);
967 * @brief Get the user ID of the page owner
969 * Used from within PCSS themes to set theme parameters. If there's a
970 * puid request variable, that is the "page owner" and normally their theme
971 * settings take precedence; unless a local user sets the "always_my_theme"
972 * system pconfig, which means they don't want to see anybody else's theme
973 * settings except their own while on this site.
975 * @return int user ID
977 * @note Returns local_user instead of user ID if "always_my_theme"
980 function get_theme_uid()
982 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
983 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {