3 * @file include/identity.php
7 use Friendica\Core\Config;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\System;
10 use Friendica\Core\Worker;
12 require_once 'include/ForumManager.php';
13 require_once 'include/bbcode.php';
14 require_once 'mod/proxy.php';
15 require_once 'include/cache.php';
19 * @brief Loads a profile into the page sidebar.
21 * The function requires a writeable copy of the main App structure, and the nickname
22 * of a registered local account.
24 * If the viewer is an authenticated remote viewer, the profile displayed is the
25 * one that has been configured for his/her viewing in the Contact manager.
26 * Passing a non-zero profile ID can also allow a preview of a selected profile
29 * Profile information is placed in the App structure for later retrieval.
30 * Honours the owner's chosen theme for display.
32 * @attention Should only be run in the _init() functions of a module. That ensures that
33 * the theme is chosen before the _init() function of a theme is run, which will usually
34 * load a lot of theme-specific content
37 * @param string $nickname
39 * @param array $profiledata
41 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
43 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
47 if (!$user && count($user) && !count($profiledata)) {
48 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
49 notice( t('Requested account is not available.') . EOL );
54 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
56 if (empty($pdata) && empty($profiledata)) {
57 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
58 notice( t('Requested profile is not available.') . EOL );
63 // fetch user tags if this isn't the default profile
65 if (!$pdata['is-default']) {
66 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
67 intval($pdata['profile_uid'])
70 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
74 $a->profile_uid = $pdata['profile_uid'];
76 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
77 $a->profile['network'] = NETWORK_DFRN;
79 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
81 if (!$profiledata && !PConfig::get(local_user(),'system','always_my_theme'))
82 $_SESSION['theme'] = $a->profile['theme'];
84 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
87 * load/reload current theme info
90 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
92 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
93 if (file_exists($theme_info_file)) {
94 require_once $theme_info_file;
97 if (! (x($a->page,'aside')))
98 $a->page['aside'] = '';
100 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
101 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
102 '$editprofile' => t('Edit profile'),
103 '$profid' => $a->profile['id']
107 $block = (((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
111 * By now, the contact block isn't shown, when a different profile is given
112 * But: When this profile was on the same server, then we could display the contacts
115 $a->page['aside'] .= profile_sidebar($profiledata, true);
117 $a->page['aside'] .= profile_sidebar($a->profile, $block);
120 $a->page['aside'] .= contact_block();*/
127 * @brief Get all profil data of a local user
129 * If the viewer is an authenticated remote viewer, the profile displayed is the
130 * one that has been configured for his/her viewing in the Contact manager.
131 * Passing a non-zero profile ID can also allow a preview of a selected profile
134 * @param string $nickname
136 * @param int $profile
139 * Includes all available profile data
141 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
142 if (remote_user() && count($_SESSION['remote'])) {
143 foreach ($_SESSION['remote'] as $visitor) {
144 if ($visitor['uid'] == $uid) {
145 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
146 if (dbm::is_result($r)) {
147 $profile = $r['profile-id'];
157 $profile_int = intval($profile);
158 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
159 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
160 `profile`.`uid` AS `profile_uid`, `profile`.*,
161 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
163 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
164 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
165 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
170 if (!dbm::is_result($r)) {
171 $r = dba::fetch_first("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`, `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`.`is-default` LIMIT 1",
188 * @brief Formats a profile for display in the sidebar.
190 * It is very difficult to templatise the HTML completely
191 * because of all the conditional logic.
193 * @param array $profile
196 * @return HTML string stuitable for sidebar inclusion
198 * @note Returns empty string if passed $profile is wrong type or not populated
200 * @hooks 'profile_sidebar_enter'
201 * array $profile - profile data
202 * @hooks 'profile_sidebar'
205 function profile_sidebar($profile, $block = 0) {
213 // This function can also use contact information in $profile
214 $is_contact = x($profile, 'cid');
216 if ((! is_array($profile)) && (! count($profile))) {
220 $profile['picdate'] = urlencode($profile['picdate']);
222 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
223 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
225 $profile['network_name'] = "";
228 call_hooks('profile_sidebar_enter', $profile);
231 // don't show connect link to yourself
232 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
234 // don't show connect link to authenticated visitors either
235 if (remote_user() && count($_SESSION['remote'])) {
236 foreach ($_SESSION['remote'] as $visitor) {
237 if ($visitor['uid'] == $profile['uid']) {
244 // Is the local user already connected to that user?
245 if ($connect && local_user()) {
246 if (isset($profile["url"])) {
247 $profile_url = normalise_link($profile["url"]);
249 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
252 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
257 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
260 $remoteconnect = NULL;
261 if (isset($profile['remoteconnect']))
262 $remoteconnect = $profile['remoteconnect'];
264 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
265 $subscribe_feed = t("Atom feed");
267 $subscribe_feed = false;
269 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
270 $wallmessage = t('Message');
271 $wallmessage_link = "wallmessage/".$profile["nickname"];
274 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
275 intval($profile['uid']),
276 intval(remote_user()),
277 intval(CONTACT_IS_FRIEND));
279 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
280 intval($profile['uid']),
281 dbesc(normalise_link(get_my_url())),
282 intval(CONTACT_IS_FRIEND));
285 $remote_url = $r[0]["url"];
286 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
287 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
290 $wallmessage = false;
291 $wallmessage_link = false;
294 // show edit profile to yourself
295 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
296 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
297 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
300 $profile['menu'] = array(
301 'chg_photo' => t('Change profile photo'),
302 'cr_new' => t('Create New Profile'),
303 'entries' => array(),
306 if (dbm::is_result($r)) {
308 foreach ($r as $rr) {
309 $profile['menu']['entries'][] = array(
310 'photo' => $rr['thumb'],
312 'alt' => t('Profile Image'),
313 'profile_name' => $rr['profile-name'],
314 'isdefault' => $rr['is-default'],
315 'visibile_to_everybody' => t('visible to everybody'),
316 'edit_visibility' => t('Edit visibility'),
324 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
325 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
326 $profile['menu'] = array(
327 'chg_photo' => t('Change profile photo'),
329 'entries' => array(),
333 // Fetch the account type
334 $account_type = account_type($profile);
336 if ((x($profile,'address') == 1)
337 || (x($profile,'location') == 1)
338 || (x($profile,'locality') == 1)
339 || (x($profile,'region') == 1)
340 || (x($profile,'postal-code') == 1)
341 || (x($profile,'country-name') == 1))
342 $location = t('Location:');
344 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
347 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
349 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
351 $about = ((x($profile,'about') == 1) ? t('About:') : False);
353 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
355 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
356 $location = $pdesc = $gender = $marital = $homepage = $about = False;
359 $firstname = ((strpos($profile['name'],' '))
360 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
361 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
363 if ($profile['guid'] != "")
365 'guid' => $profile['guid'],
366 'podloc' => System::baseUrl(),
367 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
368 'nickname' => $profile['nickname'],
369 'fullname' => $profile['name'],
370 'firstname' => $firstname,
371 'lastname' => $lastname,
372 'photo300' => $profile['contact_photo'],
373 'photo100' => $profile['contact_thumb'],
374 'photo50' => $profile['contact_micro'],
380 $contact_block = contact_block();
382 if (is_array($a->profile) && !$a->profile['hide-friends']) {
383 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
384 intval($a->profile['uid']));
385 if (dbm::is_result($r))
386 $updated = date("c", strtotime($r[0]['updated']));
388 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
390 AND NOT `self` AND NOT `blocked` AND NOT `pending`
391 AND NOT `hidden` AND NOT `archive`
392 AND `network` IN ('%s', '%s', '%s', '')",
393 intval($profile['uid']),
395 dbesc(NETWORK_DIASPORA),
396 dbesc(NETWORK_OSTATUS)
398 if (dbm::is_result($r))
399 $contacts = intval($r[0]['total']);
404 foreach ($profile as $k => $v) {
405 $k = str_replace('-','_',$k);
409 if (isset($p["about"]))
410 $p["about"] = bbcode($p["about"]);
412 if (isset($p["address"]))
413 $p["address"] = bbcode($p["address"]);
415 $p["address"] = bbcode($p["location"]);
417 if (isset($p["photo"])) {
418 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
420 if ($a->theme['template_engine'] === 'internal')
421 $location = template_escape($location);
423 $tpl = get_markup_template('profile_vcard.tpl');
424 $o .= replace_macros($tpl, array(
427 '$connect' => $connect,
428 '$remoteconnect' => $remoteconnect,
429 '$subscribe_feed' => $subscribe_feed,
430 '$wallmessage' => $wallmessage,
431 '$wallmessage_link' => $wallmessage_link,
432 '$account_type' => $account_type,
433 '$location' => $location,
434 '$gender' => $gender,
435 // '$pdesc' => $pdesc,
436 '$marital' => $marital,
437 '$homepage' => $homepage,
439 '$network' => t('Network:'),
440 '$contacts' => $contacts,
441 '$updated' => $updated,
442 '$diaspora' => $diaspora,
443 '$contact_block' => $contact_block,
446 $arr = array('profile' => &$profile, 'entry' => &$o);
448 call_hooks('profile_sidebar', $arr);
454 function get_birthdays() {
459 if (! local_user() || $a->is_mobile || $a->is_tablet)
462 // $mobile_detect = new Mobile_Detect();
463 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
468 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
469 $bd_short = t('F d');
471 $cachekey = "get_birthdays:".local_user();
472 $r = Cache::get($cachekey);
474 $s = dba::p("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
475 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
476 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
477 ORDER BY `start` ASC ",
479 datetime_convert('UTC','UTC','now + 6 days'),
480 datetime_convert('UTC','UTC','now')
482 if (dbm::is_result($s)) {
483 $r = dba::inArray($s);
484 Cache::set($cachekey, $r, CACHE_HOUR);
487 if (dbm::is_result($r)) {
489 $now = strtotime('now');
493 foreach ($r as $rr) {
494 if (strlen($rr['name']))
496 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
499 $classtoday = $istoday ? ' birthday-today ' : '';
501 foreach ($r as &$rr) {
502 if (! strlen($rr['name']))
507 if (in_array($rr['cid'],$cids))
509 $cids[] = $rr['cid'];
511 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
514 if ($rr['network'] === NETWORK_DFRN) {
515 $sparkle = " sparkle";
516 $url = System::baseUrl() . '/redir/' . $rr['cid'];
520 $rr['title'] = $rr['name'];
521 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
522 $rr['startime'] = Null;
523 $rr['today'] = $today;
528 $tpl = get_markup_template("birthdays_reminder.tpl");
529 return replace_macros($tpl, array(
530 '$baseurl' => System::baseUrl(),
531 '$classtoday' => $classtoday,
533 '$event_reminders' => t('Birthday Reminders'),
534 '$event_title' => t('Birthdays this week:'),
536 '$lbr' => '{', // raw brackets mess up if/endif macro processing
543 function get_events() {
545 require_once 'include/bbcode.php';
549 if (! local_user() || $a->is_mobile || $a->is_tablet) {
553 // $mobile_detect = new Mobile_Detect();
554 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
559 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
560 $bd_short = t('F d');
562 $s = dba::p("SELECT `event`.* FROM `event`
563 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
564 ORDER BY `start` ASC ",
566 datetime_convert('UTC','UTC','now + 7 days'),
567 datetime_convert('UTC','UTC','now - 1 days')
572 if (dbm::is_result($s)) {
573 $now = strtotime('now');
576 while ($rr = dba::fetch($s)) {
577 if (strlen($rr['name'])) {
581 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
582 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
586 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
588 if (strlen($title) > 35) {
589 $title = substr($title,0,32) . '... ';
592 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
593 if (! $description) {
594 $description = t('[No description]');
597 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
599 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
603 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
605 $rr['title'] = $title;
606 $rr['description'] = $desciption;
607 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
608 $rr['startime'] = $strt;
609 $rr['today'] = $today;
614 $classtoday = (($istoday) ? 'event-today' : '');
616 $tpl = get_markup_template("events_reminder.tpl");
617 return replace_macros($tpl, array(
618 '$baseurl' => System::baseUrl(),
619 '$classtoday' => $classtoday,
620 '$count' => count($r),
621 '$event_reminders' => t('Event Reminders'),
622 '$event_title' => t('Events this week:'),
627 function advanced_profile(App $a) {
630 $uid = $a->profile['uid'];
632 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
633 '$title' => t('Profile')
636 if ($a->profile['name']) {
638 $tpl = get_markup_template('profile_advanced.tpl');
642 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
644 if ($a->profile['gender']) {
645 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
648 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
649 $year_bd_format = t('j F, Y');
650 $short_bd_format = t('j F');
653 $val = ((intval($a->profile['dob']))
654 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
655 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
657 $profile['birthday'] = array( t('Birthday:'), $val);
660 if (!empty($a->profile['dob'])
661 && $a->profile['dob'] > '0001-01-01'
662 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
664 $profile['age'] = array( t('Age:'), $age );
667 if ($a->profile['marital']) {
668 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
671 /// @TODO Maybe use x() here, plus below?
672 if ($a->profile['with']) {
673 $profile['marital']['with'] = $a->profile['with'];
676 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
677 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
680 if ($a->profile['sexual']) {
681 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
684 if ($a->profile['homepage']) {
685 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
688 if ($a->profile['hometown']) {
689 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
692 if ($a->profile['pub_keywords']) {
693 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
696 if ($a->profile['politic']) {
697 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
700 if ($a->profile['religion']) {
701 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
704 if ($txt = prepare_text($a->profile['about'])) {
705 $profile['about'] = array( t('About:'), $txt );
708 if ($txt = prepare_text($a->profile['interest'])) {
709 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
712 if ($txt = prepare_text($a->profile['likes'])) {
713 $profile['likes'] = array( t('Likes:'), $txt);
716 if ($txt = prepare_text($a->profile['dislikes'])) {
717 $profile['dislikes'] = array( t('Dislikes:'), $txt);
720 if ($txt = prepare_text($a->profile['contact'])) {
721 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
724 if ($txt = prepare_text($a->profile['music'])) {
725 $profile['music'] = array( t('Musical interests:'), $txt);
728 if ($txt = prepare_text($a->profile['book'])) {
729 $profile['book'] = array( t('Books, literature:'), $txt);
732 if ($txt = prepare_text($a->profile['tv'])) {
733 $profile['tv'] = array( t('Television:'), $txt);
736 if ($txt = prepare_text($a->profile['film'])) {
737 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
740 if ($txt = prepare_text($a->profile['romance'])) {
741 $profile['romance'] = array( t('Love/Romance:'), $txt);
744 if ($txt = prepare_text($a->profile['work'])) {
745 $profile['work'] = array( t('Work/employment:'), $txt);
748 if ($txt = prepare_text($a->profile['education'])) {
749 $profile['education'] = array( t('School/education:'), $txt );
752 //show subcribed forum if it is enabled in the usersettings
753 if (feature_enabled($uid,'forumlist_profile')) {
754 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
757 if ($a->profile['uid'] == local_user()) {
758 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
761 return replace_macros($tpl, array(
762 '$title' => t('Profile'),
763 '$basic' => t('Basic'),
764 '$advanced' => t('Advanced'),
765 '$profile' => $profile
772 function profile_tabs($a, $is_owner=False, $nickname=Null) {
773 //echo "<pre>"; var_dump($a->user); killme();
775 if (is_null($nickname)) {
776 $nickname = $a->user['nickname'];
779 if (x($_GET,'tab')) {
780 $tab = notags(trim($_GET['tab']));
783 $url = System::baseUrl() . '/profile/' . $nickname;
787 'label'=>t('Status'),
789 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
790 'title' => t('Status Messages and Posts'),
791 'id' => 'status-tab',
795 'label' => t('Profile'),
796 'url' => $url.'/?tab=profile',
797 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
798 'title' => t('Profile Details'),
799 'id' => 'profile-tab',
803 'label' => t('Photos'),
804 'url' => System::baseUrl() . '/photos/' . $nickname,
805 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
806 'title' => t('Photo Albums'),
811 'label' => t('Videos'),
812 'url' => System::baseUrl() . '/videos/' . $nickname,
813 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
814 'title' => t('Videos'),
820 // the calendar link for the full featured events calendar
821 if ($is_owner && $a->theme_events_in_profile) {
823 'label' => t('Events'),
824 'url' => System::baseUrl() . '/events',
825 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
826 'title' => t('Events and Calendar'),
827 'id' => 'events-tab',
830 // if the user is not the owner of the calendar we only show a calendar
831 // with the public events of the calendar owner
832 } elseif (! $is_owner) {
834 'label' => t('Events'),
835 'url' => System::baseUrl() . '/cal/' . $nickname,
836 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
837 'title' => t('Events and Calendar'),
838 'id' => 'events-tab',
845 'label' => t('Personal Notes'),
846 'url' => System::baseUrl() . '/notes',
847 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
848 'title' => t('Only You Can See This'),
854 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
856 'label' => t('Contacts'),
857 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
858 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
859 'title' => t('Contacts'),
860 'id' => 'viewcontacts-tab',
865 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
866 call_hooks('profile_tabs', $arr);
868 $tpl = get_markup_template('common_tabs.tpl');
870 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
873 function get_my_url() {
874 if (x($_SESSION, 'my_url')) {
875 return $_SESSION['my_url'];
880 function zrl_init(App $a) {
881 $tmp_str = get_my_url();
882 if (validate_url($tmp_str)) {
884 // Is it a DDoS attempt?
885 // The check fetches the cached value from gprobe to reduce the load for this system
886 $urlparts = parse_url($tmp_str);
888 $result = Cache::get("gprobe:" . $urlparts["host"]);
889 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
890 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
894 Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
895 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
896 call_hooks('zrl_init', $arr);
900 function zrl($s, $force = false) {
904 if ((! strpos($s, '/profile/')) && (! $force)) {
907 if ($force && substr($s, -1, 1) !== '/') {
910 $achar = strpos($s, '?') ? '&' : '?';
911 $mine = get_my_url();
912 if ($mine && ! link_compare($mine, $s)) {
913 return $s . $achar . 'zrl=' . urlencode($mine);
919 * @brief Get the user ID of the page owner
921 * Used from within PCSS themes to set theme parameters. If there's a
922 * puid request variable, that is the "page owner" and normally their theme
923 * settings take precedence; unless a local user sets the "always_my_theme"
924 * system pconfig, which means they don't want to see anybody else's theme
925 * settings except their own while on this site.
927 * @return int user ID
929 * @note Returns local_user instead of user ID if "always_my_theme"
932 function get_theme_uid() {
933 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
934 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {