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 (($pdata === false) || (!count($pdata)) && !count($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 = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
142 intval($visitor['cid'])
144 if (dbm::is_result($r))
145 $profile = $r[0]['profile-id'];
154 $profile_int = intval($profile);
155 $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
156 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
158 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
159 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
160 WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d LIMIT 1",
165 if (!dbm::is_result($r)) {
166 $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*,
167 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
169 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
170 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
171 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` LIMIT 1",
182 * @brief Formats a profile for display in the sidebar.
184 * It is very difficult to templatise the HTML completely
185 * because of all the conditional logic.
187 * @param array $profile
190 * @return HTML string stuitable for sidebar inclusion
192 * @note Returns empty string if passed $profile is wrong type or not populated
194 * @hooks 'profile_sidebar_enter'
195 * array $profile - profile data
196 * @hooks 'profile_sidebar'
199 function profile_sidebar($profile, $block = 0) {
207 // This function can also use contact information in $profile
208 $is_contact = x($profile, 'cid');
210 if ((! is_array($profile)) && (! count($profile))) {
214 $profile['picdate'] = urlencode($profile['picdate']);
216 if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
217 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
219 $profile['network_name'] = "";
222 call_hooks('profile_sidebar_enter', $profile);
225 // don't show connect link to yourself
226 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
228 // don't show connect link to authenticated visitors either
229 if (remote_user() && count($_SESSION['remote'])) {
230 foreach ($_SESSION['remote'] as $visitor) {
231 if ($visitor['uid'] == $profile['uid']) {
238 // Is the local user already connected to that user?
239 if ($connect AND local_user()) {
240 if (isset($profile["url"])) {
241 $profile_url = normalise_link($profile["url"]);
243 $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]);
246 $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'",
247 local_user(), $profile_url);
249 if (dbm::is_result($r))
253 if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
256 $remoteconnect = NULL;
257 if (isset($profile['remoteconnect']))
258 $remoteconnect = $profile['remoteconnect'];
260 if ($connect AND ($profile['network'] == NETWORK_DFRN) AND !isset($remoteconnect))
261 $subscribe_feed = t("Atom feed");
263 $subscribe_feed = false;
265 if (remote_user() OR (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' => App::get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
369 'photo100' => App::get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
370 'photo50' => App::get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
376 $contact_block = contact_block();
378 if (is_array($a->profile) AND !$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 $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
471 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
472 WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
473 ORDER BY `start` ASC ",
474 intval(local_user()),
475 dbesc(datetime_convert('UTC','UTC','now + 6 days')),
476 dbesc(datetime_convert('UTC','UTC','now'))
478 if (dbm::is_result($r)) {
479 Cache::set($cachekey, $r, CACHE_HOUR);
482 if (dbm::is_result($r)) {
484 $now = strtotime('now');
488 foreach ($r as $rr) {
489 if (strlen($rr['name']))
491 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
494 $classtoday = $istoday ? ' birthday-today ' : '';
496 foreach ($r as &$rr) {
497 if (! strlen($rr['name']))
502 if (in_array($rr['cid'],$cids))
504 $cids[] = $rr['cid'];
506 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
509 if ($rr['network'] === NETWORK_DFRN) {
510 $sparkle = " sparkle";
511 $url = App::get_baseurl() . '/redir/' . $rr['cid'];
515 $rr['title'] = $rr['name'];
516 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
517 $rr['startime'] = Null;
518 $rr['today'] = $today;
523 $tpl = get_markup_template("birthdays_reminder.tpl");
524 return replace_macros($tpl, array(
525 '$baseurl' => App::get_baseurl(),
526 '$classtoday' => $classtoday,
528 '$event_reminders' => t('Birthday Reminders'),
529 '$event_title' => t('Birthdays this week:'),
531 '$lbr' => '{', // raw brackets mess up if/endif macro processing
538 function get_events() {
540 require_once('include/bbcode.php');
544 if (! local_user() || $a->is_mobile || $a->is_tablet)
548 // $mobile_detect = new Mobile_Detect();
549 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
554 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
555 $bd_short = t('F d');
557 $r = q("SELECT `event`.* FROM `event`
558 WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` >= '%s'
559 ORDER BY `start` ASC ",
560 intval(local_user()),
561 dbesc(datetime_convert('UTC','UTC','now + 7 days')),
562 dbesc(datetime_convert('UTC','UTC','now - 1 days'))
565 if (dbm::is_result($r)) {
566 $now = strtotime('now');
568 foreach ($r as $rr) {
569 if (strlen($rr['name']))
572 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
573 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d'))
576 $classtoday = (($istoday) ? 'event-today' : '');
580 foreach ($r as &$rr) {
581 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
583 if (strlen($title) > 35)
584 $title = substr($title,0,32) . '... ';
586 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
588 $description = t('[No description]');
590 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
592 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
597 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
599 $rr['title'] = $title;
600 $rr['description'] = $desciption;
601 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
602 $rr['startime'] = $strt;
603 $rr['today'] = $today;
607 $tpl = get_markup_template("events_reminder.tpl");
608 return replace_macros($tpl, array(
609 '$baseurl' => App::get_baseurl(),
610 '$classtoday' => $classtoday,
611 '$count' => count($r) - $skip,
612 '$event_reminders' => t('Event Reminders'),
613 '$event_title' => t('Events this week:'),
618 function advanced_profile(App $a) {
621 $uid = $a->profile['uid'];
623 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
624 '$title' => t('Profile')
627 if ($a->profile['name']) {
629 $tpl = get_markup_template('profile_advanced.tpl');
633 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
635 if ($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
637 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
638 $year_bd_format = t('j F, Y');
639 $short_bd_format = t('j F');
642 $val = ((intval($a->profile['dob']))
643 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
644 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
646 $profile['birthday'] = array( t('Birthday:'), $val);
650 if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age );
653 if ($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']);
655 /// @TODO Maybe use x() here, plus below?
656 if ($a->profile['with']) {
657 $profile['marital']['with'] = $a->profile['with'];
660 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
661 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
664 if ($a->profile['sexual']) {
665 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
668 if ($a->profile['homepage']) {
669 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
672 if ($a->profile['hometown']) {
673 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
676 if ($a->profile['pub_keywords']) {
677 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
680 if ($a->profile['politic']) {
681 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
684 if ($a->profile['religion']) {
685 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
688 if ($txt = prepare_text($a->profile['about'])) {
689 $profile['about'] = array( t('About:'), $txt );
692 if ($txt = prepare_text($a->profile['interest'])) {
693 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
696 if ($txt = prepare_text($a->profile['likes'])) {
697 $profile['likes'] = array( t('Likes:'), $txt);
700 if ($txt = prepare_text($a->profile['dislikes'])) {
701 $profile['dislikes'] = array( t('Dislikes:'), $txt);
704 if ($txt = prepare_text($a->profile['contact'])) {
705 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
708 if ($txt = prepare_text($a->profile['music'])) {
709 $profile['music'] = array( t('Musical interests:'), $txt);
712 if ($txt = prepare_text($a->profile['book'])) {
713 $profile['book'] = array( t('Books, literature:'), $txt);
716 if ($txt = prepare_text($a->profile['tv'])) {
717 $profile['tv'] = array( t('Television:'), $txt);
720 if ($txt = prepare_text($a->profile['film'])) {
721 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
724 if ($txt = prepare_text($a->profile['romance'])) {
725 $profile['romance'] = array( t('Love/Romance:'), $txt);
728 if ($txt = prepare_text($a->profile['work'])) {
729 $profile['work'] = array( t('Work/employment:'), $txt);
732 if ($txt = prepare_text($a->profile['education'])) {
733 $profile['education'] = array( t('School/education:'), $txt );
736 //show subcribed forum if it is enabled in the usersettings
737 if (feature_enabled($uid,'forumlist_profile')) {
738 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
741 if ($a->profile['uid'] == local_user()) {
742 $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
745 return replace_macros($tpl, array(
746 '$title' => t('Profile'),
747 '$basic' => t('Basic'),
748 '$advanced' => t('Advanced'),
749 '$profile' => $profile
756 function profile_tabs($a, $is_owner=False, $nickname=Null){
757 //echo "<pre>"; var_dump($a->user); killme();
759 if (is_null($nickname)) {
760 $nickname = $a->user['nickname'];
763 if (x($_GET,'tab')) {
764 $tab = notags(trim($_GET['tab']));
767 $url = App::get_baseurl() . '/profile/' . $nickname;
771 'label'=>t('Status'),
773 'sel' => ((!isset($tab) && $a->argv[0]=='profile')?'active':''),
774 'title' => t('Status Messages and Posts'),
775 'id' => 'status-tab',
779 'label' => t('Profile'),
780 'url' => $url.'/?tab=profile',
781 'sel' => ((isset($tab) && $tab=='profile')?'active':''),
782 'title' => t('Profile Details'),
783 'id' => 'profile-tab',
787 'label' => t('Photos'),
788 'url' => App::get_baseurl() . '/photos/' . $nickname,
789 'sel' => ((!isset($tab) && $a->argv[0]=='photos')?'active':''),
790 'title' => t('Photo Albums'),
795 'label' => t('Videos'),
796 'url' => App::get_baseurl() . '/videos/' . $nickname,
797 'sel' => ((!isset($tab) && $a->argv[0]=='videos')?'active':''),
798 'title' => t('Videos'),
804 // the calendar link for the full featured events calendar
805 if ($is_owner && $a->theme_events_in_profile) {
807 'label' => t('Events'),
808 'url' => App::get_baseurl() . '/events',
809 'sel' =>((!isset($tab) && $a->argv[0]=='events')?'active':''),
810 'title' => t('Events and Calendar'),
811 'id' => 'events-tab',
814 // if the user is not the owner of the calendar we only show a calendar
815 // with the public events of the calendar owner
816 } elseif (! $is_owner) {
818 'label' => t('Events'),
819 'url' => App::get_baseurl() . '/cal/' . $nickname,
820 'sel' =>((!isset($tab) && $a->argv[0]=='cal')?'active':''),
821 'title' => t('Events and Calendar'),
822 'id' => 'events-tab',
829 'label' => t('Personal Notes'),
830 'url' => App::get_baseurl() . '/notes',
831 'sel' =>((!isset($tab) && $a->argv[0]=='notes')?'active':''),
832 'title' => t('Only You Can See This'),
838 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
840 'label' => t('Contacts'),
841 'url' => App::get_baseurl() . '/viewcontacts/' . $nickname,
842 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts')?'active':''),
843 'title' => t('Contacts'),
844 'id' => 'viewcontacts-tab',
849 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
850 call_hooks('profile_tabs', $arr);
852 $tpl = get_markup_template('common_tabs.tpl');
854 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
857 function get_my_url() {
858 if (x($_SESSION,'my_url'))
859 return $_SESSION['my_url'];
863 function zrl_init(App $a) {
864 $tmp_str = get_my_url();
865 if (validate_url($tmp_str)) {
867 // Is it a DDoS attempt?
868 // The check fetches the cached value from gprobe to reduce the load for this system
869 $urlparts = parse_url($tmp_str);
871 $result = Cache::get("gprobe:".$urlparts["host"]);
872 if (!is_null($result)) {
873 if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
874 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
879 proc_run(PRIORITY_LOW, 'include/gprobe.php',bin2hex($tmp_str));
880 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
881 call_hooks('zrl_init',$arr);
885 function zrl($s,$force = false) {
889 if ((! strpos($s,'/profile/')) && (! $force)) {
892 if ($force && substr($s,-1,1) !== '/') {
895 $achar = strpos($s,'?') ? '&' : '?';
896 $mine = get_my_url();
897 if ($mine and ! link_compare($mine,$s)) {
898 return $s . $achar . 'zrl=' . urlencode($mine);
904 * @brief Get the user ID of the page owner
906 * Used from within PCSS themes to set theme parameters. If there's a
907 * puid request variable, that is the "page owner" and normally their theme
908 * settings take precedence; unless a local user sets the "always_my_theme"
909 * system pconfig, which means they don't want to see anybody else's theme
910 * settings except their own while on this site.
912 * @return int user ID
914 * @note Returns local_user instead of user ID if "always_my_theme"
917 function get_theme_uid() {
918 $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
920 if ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) {