3 * @file include/identity.php
7 use Friendica\Core\System;
8 use Friendica\Core\Worker;
10 require_once 'include/ForumManager.php';
11 require_once 'include/bbcode.php';
12 require_once 'mod/proxy.php';
13 require_once 'include/cache.php';
17 * @brief Loads a profile into the page sidebar.
19 * The function requires a writeable copy of the main App structure, and the nickname
20 * of a registered local account.
22 * If the viewer is an authenticated remote viewer, the profile displayed is the
23 * one that has been configured for his/her viewing in the Contact manager.
24 * Passing a non-zero profile ID can also allow a preview of a selected profile
27 * Profile information is placed in the App structure for later retrieval.
28 * Honours the owner's chosen theme for display.
30 * @attention Should only be run in the _init() functions of a module. That ensures that
31 * the theme is chosen before the _init() function of a theme is run, which will usually
32 * load a lot of theme-specific content
35 * @param string $nickname
37 * @param array $profiledata
39 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
41 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
45 if (!$user && count($user) && !count($profiledata)) {
46 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
47 notice( t('Requested account is not available.') . EOL );
52 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
54 if (empty($pdata) && empty($profiledata)) {
55 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
56 notice( t('Requested profile is not available.') . EOL );
61 // fetch user tags if this isn't the default profile
63 if (!$pdata['is-default']) {
64 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
65 intval($pdata['profile_uid'])
68 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
72 $a->profile_uid = $pdata['profile_uid'];
74 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
75 $a->profile['network'] = NETWORK_DFRN;
77 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
79 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
80 $_SESSION['theme'] = $a->profile['theme'];
82 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
85 * load/reload current theme info
88 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
90 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
91 if (file_exists($theme_info_file)) {
92 require_once $theme_info_file;
95 if (! (x($a->page,'aside')))
96 $a->page['aside'] = '';
98 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
99 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
100 '$editprofile' => t('Edit profile'),
101 '$profid' => $a->profile['id']
105 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
109 * By now, the contact block isn't shown, when a different profile is given
110 * But: When this profile was on the same server, then we could display the contacts
113 $a->page['aside'] .= profile_sidebar($profiledata, true);
115 $a->page['aside'] .= profile_sidebar($a->profile, $block);
118 $a->page['aside'] .= contact_block();*/
125 * @brief Get all profil data of a local user
127 * If the viewer is an authenticated remote viewer, the profile displayed is the
128 * one that has been configured for his/her viewing in the Contact manager.
129 * Passing a non-zero profile ID can also allow a preview of a selected profile
132 * @param string $nickname
134 * @param int $profile
137 * Includes all available profile data
139 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
140 if (remote_user() && count($_SESSION['remote'])) {
141 foreach ($_SESSION['remote'] as $visitor) {
142 if ($visitor['uid'] == $uid) {
143 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
144 if (dbm::is_result($r)) {
145 $profile = $r['profile-id'];
155 $profile_int = intval($profile);
156 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
157 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
158 `profile`.`uid` AS `profile_uid`, `profile`.*,
159 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
161 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
162 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
163 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
168 if (!dbm::is_result($r)) {
169 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
170 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
171 `profile`.`uid` AS `profile_uid`, `profile`.*,
172 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
174 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
175 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
176 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
186 * @brief Formats a profile for display in the sidebar.
188 * It is very difficult to templatise the HTML completely
189 * because of all the conditional logic.
191 * @param array $profile
194 * @return HTML string stuitable for sidebar inclusion
196 * @note Returns empty string if passed $profile is wrong type or not populated
198 * @hooks 'profile_sidebar_enter'
199 * array $profile - profile data
200 * @hooks 'profile_sidebar'
203 function profile_sidebar($profile, $block = 0) {
211 // This function can also use contact information in $profile
212 $is_contact = x($profile, 'cid');
214 if ((! is_array($profile)) && (! count($profile))) {
218 $profile['picdate'] = urlencode($profile['picdate']);
220 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
221 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
223 $profile['network_name'] = "";
226 call_hooks('profile_sidebar_enter', $profile);
229 // don't show connect link to yourself
230 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
232 // don't show connect link to authenticated visitors either
233 if (remote_user() && count($_SESSION['remote'])) {
234 foreach ($_SESSION['remote'] as $visitor) {
235 if ($visitor['uid'] == $profile['uid']) {
242 // Is the local user already connected to that user?
243 if ($connect && local_user()) {
244 if (isset($profile["url"])) {
245 $profile_url = normalise_link($profile["url"]);
247 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
250 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
255 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
258 $remoteconnect = NULL;
259 if (isset($profile['remoteconnect']))
260 $remoteconnect = $profile['remoteconnect'];
262 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
263 $subscribe_feed = t("Atom feed");
265 $subscribe_feed = false;
267 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
268 $wallmessage = t('Message');
269 $wallmessage_link = "wallmessage/".$profile["nickname"];
272 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
273 intval($profile['uid']),
274 intval(remote_user()),
275 intval(CONTACT_IS_FRIEND));
277 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
278 intval($profile['uid']),
279 dbesc(normalise_link(get_my_url())),
280 intval(CONTACT_IS_FRIEND));
283 $remote_url = $r[0]["url"];
284 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
285 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
288 $wallmessage = false;
289 $wallmessage_link = false;
292 // show edit profile to yourself
293 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
294 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
295 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
298 $profile['menu'] = array(
299 'chg_photo' => t('Change profile photo'),
300 'cr_new' => t('Create New Profile'),
301 'entries' => array(),
304 if (dbm::is_result($r)) {
306 foreach ($r as $rr) {
307 $profile['menu']['entries'][] = array(
308 'photo' => $rr['thumb'],
310 'alt' => t('Profile Image'),
311 'profile_name' => $rr['profile-name'],
312 'isdefault' => $rr['is-default'],
313 'visibile_to_everybody' => t('visible to everybody'),
314 'edit_visibility' => t('Edit visibility'),
322 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
323 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
324 $profile['menu'] = array(
325 'chg_photo' => t('Change profile photo'),
327 'entries' => array(),
331 // Fetch the account type
332 $account_type = account_type($profile);
334 if ((x($profile,'address') == 1)
335 || (x($profile,'location') == 1)
336 || (x($profile,'locality') == 1)
337 || (x($profile,'region') == 1)
338 || (x($profile,'postal-code') == 1)
339 || (x($profile,'country-name') == 1))
340 $location = t('Location:');
342 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
345 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
347 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
349 $about = ((x($profile,'about') == 1) ? t('About:') : False);
351 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
353 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
354 $location = $pdesc = $gender = $marital = $homepage = $about = False;
357 $firstname = ((strpos($profile['name'],' '))
358 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
359 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
361 if ($profile['guid'] != "")
363 'guid' => $profile['guid'],
364 'podloc' => System::baseUrl(),
365 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
366 'nickname' => $profile['nickname'],
367 'fullname' => $profile['name'],
368 'firstname' => $firstname,
369 'lastname' => $lastname,
370 'photo300' => $profile['contact_photo'],
371 'photo100' => $profile['contact_thumb'],
372 'photo50' => $profile['contact_micro'],
378 $contact_block = contact_block();
380 if (is_array($a->profile) && !$a->profile['hide-friends']) {
381 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
382 intval($a->profile['uid']));
383 if (dbm::is_result($r))
384 $updated = date("c", strtotime($r[0]['updated']));
386 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
388 AND NOT `self` AND NOT `blocked` AND NOT `pending`
389 AND NOT `hidden` AND NOT `archive`
390 AND `network` IN ('%s', '%s', '%s', '')",
391 intval($profile['uid']),
393 dbesc(NETWORK_DIASPORA),
394 dbesc(NETWORK_OSTATUS)
396 if (dbm::is_result($r))
397 $contacts = intval($r[0]['total']);
402 foreach ($profile as $k => $v) {
403 $k = str_replace('-','_',$k);
407 if (isset($p["about"]))
408 $p["about"] = bbcode($p["about"]);
410 if (isset($p["address"]))
411 $p["address"] = bbcode($p["address"]);
413 $p["address"] = bbcode($p["location"]);
415 if (isset($p["photo"])) {
416 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
418 if ($a->theme['template_engine'] === 'internal')
419 $location = template_escape($location);
421 $tpl = get_markup_template('profile_vcard.tpl');
422 $o .= replace_macros($tpl, array(
425 '$connect' => $connect,
426 '$remoteconnect' => $remoteconnect,
427 '$subscribe_feed' => $subscribe_feed,
428 '$wallmessage' => $wallmessage,
429 '$wallmessage_link' => $wallmessage_link,
430 '$account_type' => $account_type,
431 '$location' => $location,
432 '$gender' => $gender,
433 // '$pdesc' => $pdesc,
434 '$marital' => $marital,
435 '$homepage' => $homepage,
437 '$network' => t('Network:'),
438 '$contacts' => $contacts,
439 '$updated' => $updated,
440 '$diaspora' => $diaspora,
441 '$contact_block' => $contact_block,
444 $arr = array('profile' => &$profile, 'entry' => &$o);
446 call_hooks('profile_sidebar', $arr);
452 function get_birthdays() {
457 if (! local_user() || $a->is_mobile || $a->is_tablet)
460 // $mobile_detect = new Mobile_Detect();
461 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
466 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
467 $bd_short = t('F d');
469 $cachekey = "get_birthdays:".local_user();
470 $r = Cache::get($cachekey);
472 $s = dba::p("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
473 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
474 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
475 ORDER BY `start` ASC ",
477 datetime_convert('UTC','UTC','now + 6 days'),
478 datetime_convert('UTC','UTC','now')
480 if (dbm::is_result($s)) {
481 $r = dba::inArray($s);
482 Cache::set($cachekey, $r, CACHE_HOUR);
485 if (dbm::is_result($r)) {
487 $now = strtotime('now');
491 foreach ($r as $rr) {
492 if (strlen($rr['name']))
494 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
497 $classtoday = $istoday ? ' birthday-today ' : '';
499 foreach ($r as &$rr) {
500 if (! strlen($rr['name']))
505 if (in_array($rr['cid'],$cids))
507 $cids[] = $rr['cid'];
509 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
512 if ($rr['network'] === NETWORK_DFRN) {
513 $sparkle = " sparkle";
514 $url = System::baseUrl() . '/redir/' . $rr['cid'];
518 $rr['title'] = $rr['name'];
519 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
520 $rr['startime'] = Null;
521 $rr['today'] = $today;
526 $tpl = get_markup_template("birthdays_reminder.tpl");
527 return replace_macros($tpl, array(
528 '$baseurl' => System::baseUrl(),
529 '$classtoday' => $classtoday,
531 '$event_reminders' => t('Birthday Reminders'),
532 '$event_title' => t('Birthdays this week:'),
534 '$lbr' => '{', // raw brackets mess up if/endif macro processing
541 function get_events() {
543 require_once 'include/bbcode.php';
547 if (! local_user() || $a->is_mobile || $a->is_tablet) {
551 // $mobile_detect = new Mobile_Detect();
552 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
557 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
558 $bd_short = t('F d');
560 $s = dba::p("SELECT `event`.* FROM `event`
561 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
562 ORDER BY `start` ASC ",
564 datetime_convert('UTC','UTC','now + 7 days'),
565 datetime_convert('UTC','UTC','now - 1 days')
570 if (dbm::is_result($s)) {
571 $now = strtotime('now');
574 while ($rr = dba::fetch($s)) {
575 if (strlen($rr['name'])) {
579 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
580 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
584 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
586 if (strlen($title) > 35) {
587 $title = substr($title,0,32) . '... ';
590 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
591 if (! $description) {
592 $description = t('[No description]');
595 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
597 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
601 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
603 $rr['title'] = $title;
604 $rr['description'] = $desciption;
605 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
606 $rr['startime'] = $strt;
607 $rr['today'] = $today;
612 $classtoday = (($istoday) ? 'event-today' : '');
614 $tpl = get_markup_template("events_reminder.tpl");
615 return replace_macros($tpl, array(
616 '$baseurl' => System::baseUrl(),
617 '$classtoday' => $classtoday,
618 '$count' => count($r),
619 '$event_reminders' => t('Event Reminders'),
620 '$event_title' => t('Events this week:'),
625 function advanced_profile(App $a) {
628 $uid = $a->profile['uid'];
630 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
631 '$title' => t('Profile')
634 if ($a->profile['name']) {
636 $tpl = get_markup_template('profile_advanced.tpl');
640 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
642 if ($a->profile['gender']) {
643 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
646 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
647 $year_bd_format = t('j F, Y');
648 $short_bd_format = t('j F');
651 $val = ((intval($a->profile['dob']))
652 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
653 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
655 $profile['birthday'] = array( t('Birthday:'), $val);
658 if (!empty($a->profile['dob'])
659 && $a->profile['dob'] > '0001-01-01'
660 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
662 $profile['age'] = array( t('Age:'), $age );
665 if ($a->profile['marital']) {
666 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
669 /// @TODO Maybe use x() here, plus below?
670 if ($a->profile['with']) {
671 $profile['marital']['with'] = $a->profile['with'];
674 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
675 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
678 if ($a->profile['sexual']) {
679 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
682 if ($a->profile['homepage']) {
683 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
686 if ($a->profile['hometown']) {
687 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
690 if ($a->profile['pub_keywords']) {
691 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
694 if ($a->profile['politic']) {
695 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
698 if ($a->profile['religion']) {
699 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
702 if ($txt = prepare_text($a->profile['about'])) {
703 $profile['about'] = array( t('About:'), $txt );
706 if ($txt = prepare_text($a->profile['interest'])) {
707 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
710 if ($txt = prepare_text($a->profile['likes'])) {
711 $profile['likes'] = array( t('Likes:'), $txt);
714 if ($txt = prepare_text($a->profile['dislikes'])) {
715 $profile['dislikes'] = array( t('Dislikes:'), $txt);
718 if ($txt = prepare_text($a->profile['contact'])) {
719 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
722 if ($txt = prepare_text($a->profile['music'])) {
723 $profile['music'] = array( t('Musical interests:'), $txt);
726 if ($txt = prepare_text($a->profile['book'])) {
727 $profile['book'] = array( t('Books, literature:'), $txt);
730 if ($txt = prepare_text($a->profile['tv'])) {
731 $profile['tv'] = array( t('Television:'), $txt);
734 if ($txt = prepare_text($a->profile['film'])) {
735 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
738 if ($txt = prepare_text($a->profile['romance'])) {
739 $profile['romance'] = array( t('Love/Romance:'), $txt);
742 if ($txt = prepare_text($a->profile['work'])) {
743 $profile['work'] = array( t('Work/employment:'), $txt);
746 if ($txt = prepare_text($a->profile['education'])) {
747 $profile['education'] = array( t('School/education:'), $txt );
750 //show subcribed forum if it is enabled in the usersettings
751 if (feature_enabled($uid,'forumlist_profile')) {
752 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
755 if ($a->profile['uid'] == local_user()) {
756 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
759 return replace_macros($tpl, array(
760 '$title' => t('Profile'),
761 '$basic' => t('Basic'),
762 '$advanced' => t('Advanced'),
763 '$profile' => $profile
770 function profile_tabs($a, $is_owner=False, $nickname=Null) {
771 //echo "<pre>"; var_dump($a->user); killme();
773 if (is_null($nickname)) {
774 $nickname = $a->user['nickname'];
777 if (x($_GET,'tab')) {
778 $tab = notags(trim($_GET['tab']));
781 $url = System::baseUrl() . '/profile/' . $nickname;
785 'label'=>t('Status'),
787 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
788 'title' => t('Status Messages and Posts'),
789 'id' => 'status-tab',
793 'label' => t('Profile'),
794 'url' => $url.'/?tab=profile',
795 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
796 'title' => t('Profile Details'),
797 'id' => 'profile-tab',
801 'label' => t('Photos'),
802 'url' => System::baseUrl() . '/photos/' . $nickname,
803 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
804 'title' => t('Photo Albums'),
809 'label' => t('Videos'),
810 'url' => System::baseUrl() . '/videos/' . $nickname,
811 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
812 'title' => t('Videos'),
818 // the calendar link for the full featured events calendar
819 if ($is_owner && $a->theme_events_in_profile) {
821 'label' => t('Events'),
822 'url' => System::baseUrl() . '/events',
823 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
824 'title' => t('Events and Calendar'),
825 'id' => 'events-tab',
828 // if the user is not the owner of the calendar we only show a calendar
829 // with the public events of the calendar owner
830 } elseif (! $is_owner) {
832 'label' => t('Events'),
833 'url' => System::baseUrl() . '/cal/' . $nickname,
834 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
835 'title' => t('Events and Calendar'),
836 'id' => 'events-tab',
843 'label' => t('Personal Notes'),
844 'url' => System::baseUrl() . '/notes',
845 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
846 'title' => t('Only You Can See This'),
852 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
854 'label' => t('Contacts'),
855 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
856 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
857 'title' => t('Contacts'),
858 'id' => 'viewcontacts-tab',
863 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
864 call_hooks('profile_tabs', $arr);
866 $tpl = get_markup_template('common_tabs.tpl');
868 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
871 function get_my_url() {
872 if (x($_SESSION, 'my_url')) {
873 return $_SESSION['my_url'];
878 function zrl_init(App $a) {
879 $tmp_str = get_my_url();
880 if (validate_url($tmp_str)) {
882 // Is it a DDoS attempt?
883 // The check fetches the cached value from gprobe to reduce the load for this system
884 $urlparts = parse_url($tmp_str);
886 $result = Cache::get("gprobe:" . $urlparts["host"]);
887 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
888 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
892 Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
893 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
894 call_hooks('zrl_init', $arr);
898 function zrl($s, $force = false) {
902 if ((! strpos($s, '/profile/')) && (! $force)) {
905 if ($force && substr($s, -1, 1) !== '/') {
908 $achar = strpos($s, '?') ? '&' : '?';
909 $mine = get_my_url();
910 if ($mine && ! link_compare($mine, $s)) {
911 return $s . $achar . 'zrl=' . urlencode($mine);
917 * @brief Get the user ID of the page owner
919 * Used from within PCSS themes to set theme parameters. If there's a
920 * puid request variable, that is the "page owner" and normally their theme
921 * settings take precedence; unless a local user sets the "always_my_theme"
922 * system pconfig, which means they don't want to see anybody else's theme
923 * settings except their own while on this site.
925 * @return int user ID
927 * @note Returns local_user instead of user ID if "always_my_theme"
930 function get_theme_uid() {
931 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
932 if ((local_user()) && ((get_pconfig(local_user(), 'system', 'always_my_theme')) || (! $uid))) {