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
44 * @param boolean $show_connect Show connect link
46 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array(), $show_connect = true)
49 "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
53 if (!$user && count($user) && !count($profiledata)) {
54 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
55 notice(t('Requested account is not available.') . EOL);
60 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
62 if (empty($pdata) && empty($profiledata)) {
63 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
64 notice(t('Requested profile is not available.') . EOL);
69 // fetch user tags if this isn't the default profile
71 if (!$pdata['is-default']) {
73 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
74 intval($pdata['profile_uid'])
77 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
81 $a->profile_uid = $pdata['profile_uid'];
83 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
84 $a->profile['network'] = NETWORK_DFRN;
86 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
88 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
89 $_SESSION['theme'] = $a->profile['theme'];
92 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
95 * load/reload current theme info
98 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
100 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
101 if (file_exists($theme_info_file)) {
102 require_once $theme_info_file;
105 if (! (x($a->page, 'aside'))) {
106 $a->page['aside'] = '';
109 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
110 $a->page['aside'] .= replace_macros(
111 get_markup_template('profile_edlink.tpl'),
113 '$editprofile' => t('Edit profile'),
114 '$profid' => $a->profile['id']
119 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
123 * By now, the contact block isn't shown, when a different profile is given
124 * But: When this profile was on the same server, then we could display the contacts
127 $a->page['aside'] .= profile_sidebar($profiledata, true, $show_connect);
129 $a->page['aside'] .= profile_sidebar($a->profile, $block, $show_connect);
133 $a->page['aside'] .= contact_block();*/
140 * @brief Get all profil data of a local user
142 * If the viewer is an authenticated remote viewer, the profile displayed is the
143 * one that has been configured for his/her viewing in the Contact manager.
144 * Passing a non-zero profile ID can also allow a preview of a selected profile
147 * @param string $nickname nick
148 * @param int $uid uid
149 * @param int $profile ID of the profile
151 * Includes all available profile data
153 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
155 if (remote_user() && count($_SESSION['remote'])) {
156 foreach ($_SESSION['remote'] as $visitor) {
157 if ($visitor['uid'] == $uid) {
158 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
159 if (DBM::is_result($r)) {
160 $profile = $r['profile-id'];
170 $profile_int = intval($profile);
171 $r = dba::fetch_first(
172 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
173 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
174 `profile`.`uid` AS `profile_uid`, `profile`.*,
175 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
177 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
178 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
179 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
184 if (!DBM::is_result($r)) {
185 $r = dba::fetch_first(
186 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
187 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
188 `profile`.`uid` AS `profile_uid`, `profile`.*,
189 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
191 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
192 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
193 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
203 * @brief Formats a profile for display in the sidebar.
205 * It is very difficult to templatise the HTML completely
206 * because of all the conditional logic.
208 * @param array $profile
210 * @param boolean $show_connect Show connect link
212 * @return HTML string stuitable for sidebar inclusion
214 * @note Returns empty string if passed $profile is wrong type or not populated
216 * @hooks 'profile_sidebar_enter'
217 * array $profile - profile data
218 * @hooks 'profile_sidebar'
221 function profile_sidebar($profile, $block = 0, $show_connect = true)
230 // This function can also use contact information in $profile
231 $is_contact = x($profile, 'cid');
233 if ((! is_array($profile)) && (! count($profile))) {
237 $profile['picdate'] = urlencode($profile['picdate']);
239 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
240 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
242 $profile['network_name'] = "";
245 call_hooks('profile_sidebar_enter', $profile);
248 // don't show connect link to yourself
249 $connect = (($profile['uid'] != local_user()) ? t('Connect') : false);
251 // don't show connect link to authenticated visitors either
252 if (remote_user() && count($_SESSION['remote'])) {
253 foreach ($_SESSION['remote'] as $visitor) {
254 if ($visitor['uid'] == $profile['uid']) {
261 if (!$show_connect) {
265 // Is the local user already connected to that user?
266 if ($connect && local_user()) {
267 if (isset($profile["url"])) {
268 $profile_url = normalise_link($profile["url"]);
270 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
273 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
278 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
281 $remoteconnect = null;
282 if (isset($profile['remoteconnect']))
283 $remoteconnect = $profile['remoteconnect'];
285 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
286 $subscribe_feed = t("Atom feed");
288 $subscribe_feed = false;
290 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
291 $wallmessage = t('Message');
292 $wallmessage_link = "wallmessage/".$profile["nickname"];
296 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
297 intval($profile['uid']),
298 intval(remote_user()),
299 intval(CONTACT_IS_FRIEND)
303 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
304 intval($profile['uid']),
305 dbesc(normalise_link(get_my_url())),
306 intval(CONTACT_IS_FRIEND)
310 $remote_url = $r[0]["url"];
311 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
312 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
315 $wallmessage = false;
316 $wallmessage_link = false;
319 // show edit profile to yourself
320 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
321 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
323 "SELECT * FROM `profile` WHERE `uid` = %d",
327 $profile['menu'] = array(
328 'chg_photo' => t('Change profile photo'),
329 'cr_new' => t('Create New Profile'),
330 'entries' => array(),
333 if (DBM::is_result($r)) {
334 foreach ($r as $rr) {
335 $profile['menu']['entries'][] = array(
336 'photo' => $rr['thumb'],
338 'alt' => t('Profile Image'),
339 'profile_name' => $rr['profile-name'],
340 'isdefault' => $rr['is-default'],
341 'visibile_to_everybody' => t('visible to everybody'),
342 'edit_visibility' => t('Edit visibility'),
347 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
348 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
349 $profile['menu'] = array(
350 'chg_photo' => t('Change profile photo'),
352 'entries' => array(),
356 // Fetch the account type
357 $account_type = Contact::getAccountType($profile);
359 if ((x($profile, 'address') == 1)
360 || (x($profile, 'location') == 1)
361 || (x($profile, 'locality') == 1)
362 || (x($profile, 'region') == 1)
363 || (x($profile, 'postal-code') == 1)
364 || (x($profile, 'country-name') == 1)
366 $location = t('Location:');
369 $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
372 $marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
374 $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
376 $about = ((x($profile, 'about') == 1) ? t('About:') : false);
378 $xmpp = ((x($profile, 'xmpp') == 1) ? t('XMPP:') : false);
380 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
381 $location = $pdesc = $gender = $marital = $homepage = $about = false;
384 $split_name = Diaspora::splitName($profile['name']);
385 $firstname = $split_name['first'];
386 $lastname = $split_name['last'];
388 if ($profile['guid'] != "") {
390 'guid' => $profile['guid'],
391 'podloc' => System::baseUrl(),
392 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
393 'nickname' => $profile['nickname'],
394 'fullname' => $profile['name'],
395 'firstname' => $firstname,
396 'lastname' => $lastname,
397 'photo300' => $profile['contact_photo'],
398 'photo100' => $profile['contact_thumb'],
399 'photo50' => $profile['contact_micro'],
406 $contact_block = contact_block();
408 if (is_array($a->profile) && !$a->profile['hide-friends']) {
410 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
411 intval($a->profile['uid'])
413 if (DBM::is_result($r)) {
414 $updated = date("c", strtotime($r[0]['updated']));
418 "SELECT COUNT(*) AS `total` FROM `contact`
420 AND NOT `self` AND NOT `blocked` AND NOT `pending`
421 AND NOT `hidden` AND NOT `archive`
422 AND `network` IN ('%s', '%s', '%s', '')",
423 intval($profile['uid']),
425 dbesc(NETWORK_DIASPORA),
426 dbesc(NETWORK_OSTATUS)
428 if (DBM::is_result($r)) {
429 $contacts = intval($r[0]['total']);
435 foreach ($profile as $k => $v) {
436 $k = str_replace('-', '_', $k);
440 if (isset($p["about"])) {
441 $p["about"] = bbcode($p["about"]);
444 if (isset($p["address"])) {
445 $p["address"] = bbcode($p["address"]);
447 $p["address"] = bbcode($p["location"]);
450 if (isset($p["photo"])) {
451 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
454 $tpl = get_markup_template('profile_vcard.tpl');
455 $o .= replace_macros(
460 '$connect' => $connect,
461 '$remoteconnect' => $remoteconnect,
462 '$subscribe_feed' => $subscribe_feed,
463 '$wallmessage' => $wallmessage,
464 '$wallmessage_link' => $wallmessage_link,
465 '$account_type' => $account_type,
466 '$location' => $location,
467 '$gender' => $gender,
468 // '$pdesc' => $pdesc,
469 '$marital' => $marital,
470 '$homepage' => $homepage,
472 '$network' => t('Network:'),
473 '$contacts' => $contacts,
474 '$updated' => $updated,
475 '$diaspora' => $diaspora,
476 '$contact_block' => $contact_block,
480 $arr = array('profile' => &$profile, 'entry' => &$o);
482 call_hooks('profile_sidebar', $arr);
488 function get_birthdays()
493 if (! local_user() || $a->is_mobile || $a->is_tablet) {
498 * $mobile_detect = new Mobile_Detect();
499 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
504 $bd_format = t('g A l F d'); // 8 AM Friday January 18
505 $bd_short = t('F d');
507 $cachekey = "get_birthdays:".local_user();
508 $r = Cache::get($cachekey);
511 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
512 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
513 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
514 ORDER BY `start` ASC ",
516 datetime_convert('UTC', 'UTC', 'now + 6 days'),
517 datetime_convert('UTC', 'UTC', 'now')
519 if (DBM::is_result($s)) {
520 $r = dba::inArray($s);
521 Cache::set($cachekey, $r, CACHE_HOUR);
524 if (DBM::is_result($r)) {
526 $now = strtotime('now');
530 foreach ($r as $rr) {
531 if (strlen($rr['name'])) {
534 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
538 $classtoday = $istoday ? ' birthday-today ' : '';
540 foreach ($r as &$rr) {
541 if (! strlen($rr['name'])) {
547 if (in_array($rr['cid'], $cids)) {
550 $cids[] = $rr['cid'];
552 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
555 if ($rr['network'] === NETWORK_DFRN) {
556 $sparkle = " sparkle";
557 $url = System::baseUrl() . '/redir/' . $rr['cid'];
561 $rr['title'] = $rr['name'];
562 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
563 $rr['startime'] = null;
564 $rr['today'] = $today;
568 $tpl = get_markup_template("birthdays_reminder.tpl");
569 return replace_macros(
572 '$baseurl' => System::baseUrl(),
573 '$classtoday' => $classtoday,
575 '$event_reminders' => t('Birthday Reminders'),
576 '$event_title' => t('Birthdays this week:'),
578 '$lbr' => '{', // raw brackets mess up if/endif macro processing
585 function get_events()
587 require_once 'include/bbcode.php';
591 if (! local_user() || $a->is_mobile || $a->is_tablet) {
596 * $mobile_detect = new Mobile_Detect();
597 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
602 $bd_format = t('g A l F d'); // 8 AM Friday January 18
603 $bd_short = t('F d');
606 "SELECT `event`.* FROM `event`
607 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
608 ORDER BY `start` ASC ",
610 datetime_convert('UTC', 'UTC', 'now + 7 days'),
611 datetime_convert('UTC', 'UTC', 'now - 1 days')
616 if (DBM::is_result($s)) {
617 $now = strtotime('now');
620 while ($rr = dba::fetch($s)) {
621 if (strlen($rr['name'])) {
625 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
626 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
630 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
632 if (strlen($title) > 35) {
633 $title = substr($title, 0, 32) . '... ';
636 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
637 if (! $description) {
638 $description = t('[No description]');
641 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
643 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
647 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
649 $rr['title'] = $title;
650 $rr['description'] = $desciption;
651 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
652 $rr['startime'] = $strt;
653 $rr['today'] = $today;
658 $classtoday = (($istoday) ? 'event-today' : '');
660 $tpl = get_markup_template("events_reminder.tpl");
661 return replace_macros(
664 '$baseurl' => System::baseUrl(),
665 '$classtoday' => $classtoday,
666 '$count' => count($r),
667 '$event_reminders' => t('Event Reminders'),
668 '$event_title' => t('Events this week:'),
674 function advanced_profile(App $a)
677 $uid = $a->profile['uid'];
679 $o .= replace_macros(
680 get_markup_template('section_title.tpl'),
682 '$title' => t('Profile')
686 if ($a->profile['name']) {
687 $tpl = get_markup_template('profile_advanced.tpl');
691 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
693 if ($a->profile['gender']) {
694 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
697 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
698 $year_bd_format = t('j F, Y');
699 $short_bd_format = t('j F');
702 $val = ((intval($a->profile['dob']))
703 ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
704 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)));
706 $profile['birthday'] = array( t('Birthday:'), $val);
708 if (!empty($a->profile['dob'])
709 && $a->profile['dob'] > '0001-01-01'
710 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
712 $profile['age'] = array( t('Age:'), $age );
715 if ($a->profile['marital']) {
716 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
719 /// @TODO Maybe use x() here, plus below?
720 if ($a->profile['with']) {
721 $profile['marital']['with'] = $a->profile['with'];
724 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
725 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
728 if ($a->profile['sexual']) {
729 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
732 if ($a->profile['homepage']) {
733 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
736 if ($a->profile['hometown']) {
737 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
740 if ($a->profile['pub_keywords']) {
741 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
744 if ($a->profile['politic']) {
745 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
748 if ($a->profile['religion']) {
749 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
752 if ($txt = prepare_text($a->profile['about'])) {
753 $profile['about'] = array( t('About:'), $txt );
756 if ($txt = prepare_text($a->profile['interest'])) {
757 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
760 if ($txt = prepare_text($a->profile['likes'])) {
761 $profile['likes'] = array( t('Likes:'), $txt);
764 if ($txt = prepare_text($a->profile['dislikes'])) {
765 $profile['dislikes'] = array( t('Dislikes:'), $txt);
768 if ($txt = prepare_text($a->profile['contact'])) {
769 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
772 if ($txt = prepare_text($a->profile['music'])) {
773 $profile['music'] = array( t('Musical interests:'), $txt);
776 if ($txt = prepare_text($a->profile['book'])) {
777 $profile['book'] = array( t('Books, literature:'), $txt);
780 if ($txt = prepare_text($a->profile['tv'])) {
781 $profile['tv'] = array( t('Television:'), $txt);
784 if ($txt = prepare_text($a->profile['film'])) {
785 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
788 if ($txt = prepare_text($a->profile['romance'])) {
789 $profile['romance'] = array( t('Love/Romance:'), $txt);
792 if ($txt = prepare_text($a->profile['work'])) {
793 $profile['work'] = array( t('Work/employment:'), $txt);
796 if ($txt = prepare_text($a->profile['education'])) {
797 $profile['education'] = array( t('School/education:'), $txt );
800 //show subcribed forum if it is enabled in the usersettings
801 if (Feature::isEnabled($uid, 'forumlist_profile')) {
802 $profile['forumlist'] = array( t('Forums:'), ForumManager::profileAdvanced($uid));
805 if ($a->profile['uid'] == local_user()) {
806 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
809 return replace_macros(
812 '$title' => t('Profile'),
813 '$basic' => t('Basic'),
814 '$advanced' => t('Advanced'),
815 '$profile' => $profile
823 function profile_tabs($a, $is_owner = false, $nickname = null)
825 //echo "<pre>"; var_dump($a->user); killme();
827 if (is_null($nickname)) {
828 $nickname = $a->user['nickname'];
831 if (x($_GET, 'tab')) {
832 $tab = notags(trim($_GET['tab']));
835 $url = System::baseUrl() . '/profile/' . $nickname;
839 'label'=>t('Status'),
841 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
842 'title' => t('Status Messages and Posts'),
843 'id' => 'status-tab',
847 'label' => t('Profile'),
848 'url' => $url.'/?tab=profile',
849 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
850 'title' => t('Profile Details'),
851 'id' => 'profile-tab',
855 'label' => t('Photos'),
856 'url' => System::baseUrl() . '/photos/' . $nickname,
857 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
858 'title' => t('Photo Albums'),
863 'label' => t('Videos'),
864 'url' => System::baseUrl() . '/videos/' . $nickname,
865 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
866 'title' => t('Videos'),
872 // the calendar link for the full featured events calendar
873 if ($is_owner && $a->theme_events_in_profile) {
875 'label' => t('Events'),
876 'url' => System::baseUrl() . '/events',
877 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
878 'title' => t('Events and Calendar'),
879 'id' => 'events-tab',
882 // if the user is not the owner of the calendar we only show a calendar
883 // with the public events of the calendar owner
884 } elseif (! $is_owner) {
886 'label' => t('Events'),
887 'url' => System::baseUrl() . '/cal/' . $nickname,
888 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
889 'title' => t('Events and Calendar'),
890 'id' => 'events-tab',
897 'label' => t('Personal Notes'),
898 'url' => System::baseUrl() . '/notes',
899 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
900 'title' => t('Only You Can See This'),
906 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
908 'label' => t('Contacts'),
909 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
910 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
911 'title' => t('Contacts'),
912 'id' => 'viewcontacts-tab',
917 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
918 call_hooks('profile_tabs', $arr);
920 $tpl = get_markup_template('common_tabs.tpl');
922 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
925 function get_my_url()
927 if (x($_SESSION, 'my_url')) {
928 return $_SESSION['my_url'];
933 function zrl_init(App $a)
935 $tmp_str = get_my_url();
936 if (validate_url($tmp_str)) {
937 // Is it a DDoS attempt?
938 // The check fetches the cached value from gprobe to reduce the load for this system
939 $urlparts = parse_url($tmp_str);
941 $result = Cache::get("gprobe:" . $urlparts["host"]);
942 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
943 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
947 Worker::add(PRIORITY_LOW, 'GProbe', $tmp_str);
948 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
949 call_hooks('zrl_init', $arr);
953 function zrl($s, $force = false)
958 if ((! strpos($s, '/profile/')) && (! $force)) {
961 if ($force && substr($s, -1, 1) !== '/') {
964 $achar = strpos($s, '?') ? '&' : '?';
965 $mine = get_my_url();
966 if ($mine && ! link_compare($mine, $s)) {
967 return $s . $achar . 'zrl=' . urlencode($mine);
973 * @brief Get the user ID of the page owner
975 * Used from within PCSS themes to set theme parameters. If there's a
976 * puid request variable, that is the "page owner" and normally their theme
977 * settings take precedence; unless a local user sets the "always_my_theme"
978 * system pconfig, which means they don't want to see anybody else's theme
979 * settings except their own while on this site.
981 * @return int user ID
983 * @note Returns local_user instead of user ID if "always_my_theme"
986 function get_theme_uid()
988 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
989 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {