3 * @file include/identity.php
8 require_once 'include/ForumManager.php';
9 require_once 'include/bbcode.php';
10 require_once 'mod/proxy.php';
11 require_once 'include/cache.php';
15 * @brief Loads a profile into the page sidebar.
17 * The function requires a writeable copy of the main App structure, and the nickname
18 * of a registered local account.
20 * If the viewer is an authenticated remote viewer, the profile displayed is the
21 * one that has been configured for his/her viewing in the Contact manager.
22 * Passing a non-zero profile ID can also allow a preview of a selected profile
25 * Profile information is placed in the App structure for later retrieval.
26 * Honours the owner's chosen theme for display.
28 * @attention Should only be run in the _init() functions of a module. That ensures that
29 * the theme is chosen before the _init() function of a theme is run, which will usually
30 * load a lot of theme-specific content
33 * @param string $nickname
35 * @param array $profiledata
37 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
39 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
43 if (!$user && count($user) && !count($profiledata)) {
44 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
45 notice( t('Requested account is not available.') . EOL );
50 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
52 if (empty($pdata) && empty($profiledata)) {
53 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
54 notice( t('Requested profile is not available.') . EOL );
59 // fetch user tags if this isn't the default profile
61 if (!$pdata['is-default']) {
62 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
63 intval($pdata['profile_uid'])
66 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
70 $a->profile_uid = $pdata['profile_uid'];
72 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
73 $a->profile['network'] = NETWORK_DFRN;
75 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
77 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
78 $_SESSION['theme'] = $a->profile['theme'];
80 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
83 * load/reload current theme info
86 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
88 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
89 if (file_exists($theme_info_file)) {
90 require_once $theme_info_file;
93 if (! (x($a->page,'aside')))
94 $a->page['aside'] = '';
96 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
97 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
98 '$editprofile' => t('Edit profile'),
99 '$profid' => $a->profile['id']
103 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
107 * By now, the contact block isn't shown, when a different profile is given
108 * But: When this profile was on the same server, then we could display the contacts
111 $a->page['aside'] .= profile_sidebar($profiledata, true);
113 $a->page['aside'] .= profile_sidebar($a->profile, $block);
116 $a->page['aside'] .= contact_block();*/
123 * @brief Get all profil data of a local user
125 * If the viewer is an authenticated remote viewer, the profile displayed is the
126 * one that has been configured for his/her viewing in the Contact manager.
127 * Passing a non-zero profile ID can also allow a preview of a selected profile
130 * @param string $nickname
132 * @param int $profile
135 * Includes all available profile data
137 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
138 if (remote_user() && count($_SESSION['remote'])) {
139 foreach ($_SESSION['remote'] as $visitor) {
140 if ($visitor['uid'] == $uid) {
141 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
142 if (dbm::is_result($r)) {
143 $profile = $r['profile-id'];
153 $profile_int = intval($profile);
154 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
155 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
156 `profile`.`uid` AS `profile_uid`, `profile`.*,
157 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
159 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
160 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
161 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
166 if (!dbm::is_result($r)) {
167 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
168 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
169 `profile`.`uid` AS `profile_uid`, `profile`.*,
170 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
172 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
173 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
174 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
184 * @brief Formats a profile for display in the sidebar.
186 * It is very difficult to templatise the HTML completely
187 * because of all the conditional logic.
189 * @param array $profile
192 * @return HTML string stuitable for sidebar inclusion
194 * @note Returns empty string if passed $profile is wrong type or not populated
196 * @hooks 'profile_sidebar_enter'
197 * array $profile - profile data
198 * @hooks 'profile_sidebar'
201 function profile_sidebar($profile, $block = 0) {
209 // This function can also use contact information in $profile
210 $is_contact = x($profile, 'cid');
212 if ((! is_array($profile)) && (! count($profile))) {
216 $profile['picdate'] = urlencode($profile['picdate']);
218 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
219 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
221 $profile['network_name'] = "";
224 call_hooks('profile_sidebar_enter', $profile);
227 // don't show connect link to yourself
228 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
230 // don't show connect link to authenticated visitors either
231 if (remote_user() && count($_SESSION['remote'])) {
232 foreach ($_SESSION['remote'] as $visitor) {
233 if ($visitor['uid'] == $profile['uid']) {
240 // Is the local user already connected to that user?
241 if ($connect && local_user()) {
242 if (isset($profile["url"])) {
243 $profile_url = normalise_link($profile["url"]);
245 $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
248 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
253 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
256 $remoteconnect = NULL;
257 if (isset($profile['remoteconnect']))
258 $remoteconnect = $profile['remoteconnect'];
260 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
261 $subscribe_feed = t("Atom feed");
263 $subscribe_feed = false;
265 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
266 $wallmessage = t('Message');
267 $wallmessage_link = "wallmessage/".$profile["nickname"];
270 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
271 intval($profile['uid']),
272 intval(remote_user()),
273 intval(CONTACT_IS_FRIEND));
275 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
276 intval($profile['uid']),
277 dbesc(normalise_link(get_my_url())),
278 intval(CONTACT_IS_FRIEND));
281 $remote_url = $r[0]["url"];
282 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
283 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
286 $wallmessage = false;
287 $wallmessage_link = false;
290 // show edit profile to yourself
291 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
292 $profile['edit'] = array(App::get_baseurl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
293 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
296 $profile['menu'] = array(
297 'chg_photo' => t('Change profile photo'),
298 'cr_new' => t('Create New Profile'),
299 'entries' => array(),
302 if (dbm::is_result($r)) {
304 foreach ($r as $rr) {
305 $profile['menu']['entries'][] = array(
306 'photo' => $rr['thumb'],
308 'alt' => t('Profile Image'),
309 'profile_name' => $rr['profile-name'],
310 'isdefault' => $rr['is-default'],
311 'visibile_to_everybody' => t('visible to everybody'),
312 'edit_visibility' => t('Edit visibility'),
320 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
321 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
322 $profile['menu'] = array(
323 'chg_photo' => t('Change profile photo'),
325 'entries' => array(),
329 // Fetch the account type
330 $account_type = account_type($profile);
332 if ((x($profile,'address') == 1)
333 || (x($profile,'location') == 1)
334 || (x($profile,'locality') == 1)
335 || (x($profile,'region') == 1)
336 || (x($profile,'postal-code') == 1)
337 || (x($profile,'country-name') == 1))
338 $location = t('Location:');
340 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
343 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
345 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
347 $about = ((x($profile,'about') == 1) ? t('About:') : False);
349 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
351 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
352 $location = $pdesc = $gender = $marital = $homepage = $about = False;
355 $firstname = ((strpos($profile['name'],' '))
356 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
357 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
359 if ($profile['guid'] != "")
361 'guid' => $profile['guid'],
362 'podloc' => App::get_baseurl(),
363 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
364 'nickname' => $profile['nickname'],
365 'fullname' => $profile['name'],
366 'firstname' => $firstname,
367 'lastname' => $lastname,
368 'photo300' => $profile['contact_photo'],
369 'photo100' => $profile['contact_thumb'],
370 'photo50' => $profile['contact_micro'],
376 $contact_block = contact_block();
378 if (is_array($a->profile) && !$a->profile['hide-friends']) {
379 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
380 intval($a->profile['uid']));
381 if (dbm::is_result($r))
382 $updated = date("c", strtotime($r[0]['updated']));
384 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
386 AND NOT `self` AND NOT `blocked` AND NOT `pending`
387 AND NOT `hidden` AND NOT `archive`
388 AND `network` IN ('%s', '%s', '%s', '')",
389 intval($profile['uid']),
391 dbesc(NETWORK_DIASPORA),
392 dbesc(NETWORK_OSTATUS)
394 if (dbm::is_result($r))
395 $contacts = intval($r[0]['total']);
400 foreach ($profile as $k => $v) {
401 $k = str_replace('-','_',$k);
405 if (isset($p["about"]))
406 $p["about"] = bbcode($p["about"]);
408 if (isset($p["address"]))
409 $p["address"] = bbcode($p["address"]);
411 $p["address"] = bbcode($p["location"]);
413 if (isset($p["photo"])) {
414 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
416 if ($a->theme['template_engine'] === 'internal')
417 $location = template_escape($location);
419 $tpl = get_markup_template('profile_vcard.tpl');
420 $o .= replace_macros($tpl, array(
423 '$connect' => $connect,
424 '$remoteconnect' => $remoteconnect,
425 '$subscribe_feed' => $subscribe_feed,
426 '$wallmessage' => $wallmessage,
427 '$wallmessage_link' => $wallmessage_link,
428 '$account_type' => $account_type,
429 '$location' => $location,
430 '$gender' => $gender,
431 // '$pdesc' => $pdesc,
432 '$marital' => $marital,
433 '$homepage' => $homepage,
435 '$network' => t('Network:'),
436 '$contacts' => $contacts,
437 '$updated' => $updated,
438 '$diaspora' => $diaspora,
439 '$contact_block' => $contact_block,
442 $arr = array('profile' => &$profile, 'entry' => &$o);
444 call_hooks('profile_sidebar', $arr);
450 function get_birthdays() {
455 if (! local_user() || $a->is_mobile || $a->is_tablet)
458 // $mobile_detect = new Mobile_Detect();
459 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
464 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
465 $bd_short = t('F d');
467 $cachekey = "get_birthdays:".local_user();
468 $r = Cache::get($cachekey);
470 $s = dba::p("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
471 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
472 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
473 ORDER BY `start` ASC ",
475 datetime_convert('UTC','UTC','now + 6 days'),
476 datetime_convert('UTC','UTC','now')
478 if (dbm::is_result($s)) {
479 $r = dba::inArray($s);
480 Cache::set($cachekey, $r, CACHE_HOUR);
483 if (dbm::is_result($r)) {
485 $now = strtotime('now');
489 foreach ($r as $rr) {
490 if (strlen($rr['name']))
492 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
495 $classtoday = $istoday ? ' birthday-today ' : '';
497 foreach ($r as &$rr) {
498 if (! strlen($rr['name']))
503 if (in_array($rr['cid'],$cids))
505 $cids[] = $rr['cid'];
507 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
510 if ($rr['network'] === NETWORK_DFRN) {
511 $sparkle = " sparkle";
512 $url = App::get_baseurl() . '/redir/' . $rr['cid'];
516 $rr['title'] = $rr['name'];
517 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
518 $rr['startime'] = Null;
519 $rr['today'] = $today;
524 $tpl = get_markup_template("birthdays_reminder.tpl");
525 return replace_macros($tpl, array(
526 '$baseurl' => App::get_baseurl(),
527 '$classtoday' => $classtoday,
529 '$event_reminders' => t('Birthday Reminders'),
530 '$event_title' => t('Birthdays this week:'),
532 '$lbr' => '{', // raw brackets mess up if/endif macro processing
539 function get_events() {
541 require_once 'include/bbcode.php';
545 if (! local_user() || $a->is_mobile || $a->is_tablet) {
549 // $mobile_detect = new Mobile_Detect();
550 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
555 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
556 $bd_short = t('F d');
558 $s = dba::p("SELECT `event`.* FROM `event`
559 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
560 ORDER BY `start` ASC ",
562 datetime_convert('UTC','UTC','now + 7 days'),
563 datetime_convert('UTC','UTC','now - 1 days')
568 if (dbm::is_result($s)) {
569 $now = strtotime('now');
572 while ($rr = dba::fetch($s)) {
573 if (strlen($rr['name'])) {
577 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
578 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
582 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
584 if (strlen($title) > 35) {
585 $title = substr($title,0,32) . '... ';
588 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
589 if (! $description) {
590 $description = t('[No description]');
593 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
595 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
599 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
601 $rr['title'] = $title;
602 $rr['description'] = $desciption;
603 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
604 $rr['startime'] = $strt;
605 $rr['today'] = $today;
610 $classtoday = (($istoday) ? 'event-today' : '');
612 $tpl = get_markup_template("events_reminder.tpl");
613 return replace_macros($tpl, array(
614 '$baseurl' => App::get_baseurl(),
615 '$classtoday' => $classtoday,
616 '$count' => count($r),
617 '$event_reminders' => t('Event Reminders'),
618 '$event_title' => t('Events this week:'),
623 function advanced_profile(App $a) {
626 $uid = $a->profile['uid'];
628 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
629 '$title' => t('Profile')
632 if ($a->profile['name']) {
634 $tpl = get_markup_template('profile_advanced.tpl');
638 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
640 if ($a->profile['gender']) {
641 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
644 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
645 $year_bd_format = t('j F, Y');
646 $short_bd_format = t('j F');
649 $val = ((intval($a->profile['dob']))
650 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
651 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
653 $profile['birthday'] = array( t('Birthday:'), $val);
656 if (!empty($a->profile['dob'])
657 && $a->profile['dob'] > '0001-01-01'
658 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
660 $profile['age'] = array( t('Age:'), $age );
663 if ($a->profile['marital']) {
664 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
667 /// @TODO Maybe use x() here, plus below?
668 if ($a->profile['with']) {
669 $profile['marital']['with'] = $a->profile['with'];
672 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
673 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
676 if ($a->profile['sexual']) {
677 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
680 if ($a->profile['homepage']) {
681 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
684 if ($a->profile['hometown']) {
685 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
688 if ($a->profile['pub_keywords']) {
689 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
692 if ($a->profile['politic']) {
693 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
696 if ($a->profile['religion']) {
697 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
700 if ($txt = prepare_text($a->profile['about'])) {
701 $profile['about'] = array( t('About:'), $txt );
704 if ($txt = prepare_text($a->profile['interest'])) {
705 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
708 if ($txt = prepare_text($a->profile['likes'])) {
709 $profile['likes'] = array( t('Likes:'), $txt);
712 if ($txt = prepare_text($a->profile['dislikes'])) {
713 $profile['dislikes'] = array( t('Dislikes:'), $txt);
716 if ($txt = prepare_text($a->profile['contact'])) {
717 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
720 if ($txt = prepare_text($a->profile['music'])) {
721 $profile['music'] = array( t('Musical interests:'), $txt);
724 if ($txt = prepare_text($a->profile['book'])) {
725 $profile['book'] = array( t('Books, literature:'), $txt);
728 if ($txt = prepare_text($a->profile['tv'])) {
729 $profile['tv'] = array( t('Television:'), $txt);
732 if ($txt = prepare_text($a->profile['film'])) {
733 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
736 if ($txt = prepare_text($a->profile['romance'])) {
737 $profile['romance'] = array( t('Love/Romance:'), $txt);
740 if ($txt = prepare_text($a->profile['work'])) {
741 $profile['work'] = array( t('Work/employment:'), $txt);
744 if ($txt = prepare_text($a->profile['education'])) {
745 $profile['education'] = array( t('School/education:'), $txt );
748 //show subcribed forum if it is enabled in the usersettings
749 if (feature_enabled($uid,'forumlist_profile')) {
750 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
753 if ($a->profile['uid'] == local_user()) {
754 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
757 return replace_macros($tpl, array(
758 '$title' => t('Profile'),
759 '$basic' => t('Basic'),
760 '$advanced' => t('Advanced'),
761 '$profile' => $profile
768 function profile_tabs($a, $is_owner=False, $nickname=Null) {
769 //echo "<pre>"; var_dump($a->user); killme();
771 if (is_null($nickname)) {
772 $nickname = $a->user['nickname'];
775 if (x($_GET,'tab')) {
776 $tab = notags(trim($_GET['tab']));
779 $url = App::get_baseurl() . '/profile/' . $nickname;
783 'label'=>t('Status'),
785 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
786 'title' => t('Status Messages and Posts'),
787 'id' => 'status-tab',
791 'label' => t('Profile'),
792 'url' => $url.'/?tab=profile',
793 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
794 'title' => t('Profile Details'),
795 'id' => 'profile-tab',
799 'label' => t('Photos'),
800 'url' => App::get_baseurl() . '/photos/' . $nickname,
801 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
802 'title' => t('Photo Albums'),
807 'label' => t('Videos'),
808 'url' => App::get_baseurl() . '/videos/' . $nickname,
809 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
810 'title' => t('Videos'),
816 // the calendar link for the full featured events calendar
817 if ($is_owner && $a->theme_events_in_profile) {
819 'label' => t('Events'),
820 'url' => App::get_baseurl() . '/events',
821 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
822 'title' => t('Events and Calendar'),
823 'id' => 'events-tab',
826 // if the user is not the owner of the calendar we only show a calendar
827 // with the public events of the calendar owner
828 } elseif (! $is_owner) {
830 'label' => t('Events'),
831 'url' => App::get_baseurl() . '/cal/' . $nickname,
832 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
833 'title' => t('Events and Calendar'),
834 'id' => 'events-tab',
841 'label' => t('Personal Notes'),
842 'url' => App::get_baseurl() . '/notes',
843 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
844 'title' => t('Only You Can See This'),
850 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
852 'label' => t('Contacts'),
853 'url' => App::get_baseurl() . '/viewcontacts/' . $nickname,
854 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
855 'title' => t('Contacts'),
856 'id' => 'viewcontacts-tab',
861 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
862 call_hooks('profile_tabs', $arr);
864 $tpl = get_markup_template('common_tabs.tpl');
866 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
869 function get_my_url() {
870 if (x($_SESSION, 'my_url')) {
871 return $_SESSION['my_url'];
876 function zrl_init(App $a) {
877 $tmp_str = get_my_url();
878 if (validate_url($tmp_str)) {
880 // Is it a DDoS attempt?
881 // The check fetches the cached value from gprobe to reduce the load for this system
882 $urlparts = parse_url($tmp_str);
884 $result = Cache::get("gprobe:" . $urlparts["host"]);
885 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
886 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
890 proc_run(PRIORITY_LOW, 'include/gprobe.php', $tmp_str);
891 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
892 call_hooks('zrl_init', $arr);
896 function zrl($s, $force = false) {
900 if ((! strpos($s, '/profile/')) && (! $force)) {
903 if ($force && substr($s, -1, 1) !== '/') {
906 $achar = strpos($s, '?') ? '&' : '?';
907 $mine = get_my_url();
908 if ($mine && ! link_compare($mine, $s)) {
909 return $s . $achar . 'zrl=' . urlencode($mine);
915 * @brief Get the user ID of the page owner
917 * Used from within PCSS themes to set theme parameters. If there's a
918 * puid request variable, that is the "page owner" and normally their theme
919 * settings take precedence; unless a local user sets the "always_my_theme"
920 * system pconfig, which means they don't want to see anybody else's theme
921 * settings except their own while on this site.
923 * @return int user ID
925 * @note Returns local_user instead of user ID if "always_my_theme"
928 function get_theme_uid() {
929 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
930 if ((local_user()) && ((get_pconfig(local_user(), 'system', 'always_my_theme')) || (! $uid))) {