3 * @file include/identity.php
7 use Friendica\Core\System;
9 require_once 'include/ForumManager.php';
10 require_once 'include/bbcode.php';
11 require_once 'mod/proxy.php';
12 require_once 'include/cache.php';
16 * @brief Loads a profile into the page sidebar.
18 * The function requires a writeable copy of the main App structure, and the nickname
19 * of a registered local account.
21 * If the viewer is an authenticated remote viewer, the profile displayed is the
22 * one that has been configured for his/her viewing in the Contact manager.
23 * Passing a non-zero profile ID can also allow a preview of a selected profile
26 * Profile information is placed in the App structure for later retrieval.
27 * Honours the owner's chosen theme for display.
29 * @attention Should only be run in the _init() functions of a module. That ensures that
30 * the theme is chosen before the _init() function of a theme is run, which will usually
31 * load a lot of theme-specific content
34 * @param string $nickname
36 * @param array $profiledata
38 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
40 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
44 if (!$user && count($user) && !count($profiledata)) {
45 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
46 notice( t('Requested account is not available.') . EOL );
51 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
53 if (empty($pdata) && empty($profiledata)) {
54 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
55 notice( t('Requested profile is not available.') . EOL );
60 // fetch user tags if this isn't the default profile
62 if (!$pdata['is-default']) {
63 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
64 intval($pdata['profile_uid'])
67 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
71 $a->profile_uid = $pdata['profile_uid'];
73 $a->profile['mobile-theme'] = get_pconfig($a->profile['profile_uid'], 'system', 'mobile_theme');
74 $a->profile['network'] = NETWORK_DFRN;
76 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
78 if (!$profiledata && !get_pconfig(local_user(),'system','always_my_theme'))
79 $_SESSION['theme'] = $a->profile['theme'];
81 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
84 * load/reload current theme info
87 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
89 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
90 if (file_exists($theme_info_file)) {
91 require_once $theme_info_file;
94 if (! (x($a->page,'aside')))
95 $a->page['aside'] = '';
97 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
98 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
99 '$editprofile' => t('Edit profile'),
100 '$profid' => $a->profile['id']
104 $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
108 * By now, the contact block isn't shown, when a different profile is given
109 * But: When this profile was on the same server, then we could display the contacts
112 $a->page['aside'] .= profile_sidebar($profiledata, true);
114 $a->page['aside'] .= profile_sidebar($a->profile, $block);
117 $a->page['aside'] .= contact_block();*/
124 * @brief Get all profil data of a local user
126 * If the viewer is an authenticated remote viewer, the profile displayed is the
127 * one that has been configured for his/her viewing in the Contact manager.
128 * Passing a non-zero profile ID can also allow a preview of a selected profile
131 * @param string $nickname
133 * @param int $profile
136 * Includes all available profile data
138 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
139 if (remote_user() && count($_SESSION['remote'])) {
140 foreach ($_SESSION['remote'] as $visitor) {
141 if ($visitor['uid'] == $uid) {
142 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
143 if (dbm::is_result($r)) {
144 $profile = $r['profile-id'];
154 $profile_int = intval($profile);
155 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
156 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
157 `profile`.`uid` AS `profile_uid`, `profile`.*,
158 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
160 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
161 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
162 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
167 if (!dbm::is_result($r)) {
168 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
169 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
170 `profile`.`uid` AS `profile_uid`, `profile`.*,
171 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
173 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
174 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
175 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
185 * @brief Formats a profile for display in the sidebar.
187 * It is very difficult to templatise the HTML completely
188 * because of all the conditional logic.
190 * @param array $profile
193 * @return HTML string stuitable for sidebar inclusion
195 * @note Returns empty string if passed $profile is wrong type or not populated
197 * @hooks 'profile_sidebar_enter'
198 * array $profile - profile data
199 * @hooks 'profile_sidebar'
202 function profile_sidebar($profile, $block = 0) {
210 // This function can also use contact information in $profile
211 $is_contact = x($profile, 'cid');
213 if ((! is_array($profile)) && (! count($profile))) {
217 $profile['picdate'] = urlencode($profile['picdate']);
219 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
220 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
222 $profile['network_name'] = "";
225 call_hooks('profile_sidebar_enter', $profile);
228 // don't show connect link to yourself
229 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
231 // don't show connect link to authenticated visitors either
232 if (remote_user() && count($_SESSION['remote'])) {
233 foreach ($_SESSION['remote'] as $visitor) {
234 if ($visitor['uid'] == $profile['uid']) {
241 // Is the local user already connected to that user?
242 if ($connect && local_user()) {
243 if (isset($profile["url"])) {
244 $profile_url = normalise_link($profile["url"]);
246 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
249 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
254 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
257 $remoteconnect = NULL;
258 if (isset($profile['remoteconnect']))
259 $remoteconnect = $profile['remoteconnect'];
261 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
262 $subscribe_feed = t("Atom feed");
264 $subscribe_feed = false;
266 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
267 $wallmessage = t('Message');
268 $wallmessage_link = "wallmessage/".$profile["nickname"];
271 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
272 intval($profile['uid']),
273 intval(remote_user()),
274 intval(CONTACT_IS_FRIEND));
276 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
277 intval($profile['uid']),
278 dbesc(normalise_link(get_my_url())),
279 intval(CONTACT_IS_FRIEND));
282 $remote_url = $r[0]["url"];
283 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
284 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
287 $wallmessage = false;
288 $wallmessage_link = false;
291 // show edit profile to yourself
292 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
293 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
294 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
297 $profile['menu'] = array(
298 'chg_photo' => t('Change profile photo'),
299 'cr_new' => t('Create New Profile'),
300 'entries' => array(),
303 if (dbm::is_result($r)) {
305 foreach ($r as $rr) {
306 $profile['menu']['entries'][] = array(
307 'photo' => $rr['thumb'],
309 'alt' => t('Profile Image'),
310 'profile_name' => $rr['profile-name'],
311 'isdefault' => $rr['is-default'],
312 'visibile_to_everybody' => t('visible to everybody'),
313 'edit_visibility' => t('Edit visibility'),
321 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
322 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
323 $profile['menu'] = array(
324 'chg_photo' => t('Change profile photo'),
326 'entries' => array(),
330 // Fetch the account type
331 $account_type = account_type($profile);
333 if ((x($profile,'address') == 1)
334 || (x($profile,'location') == 1)
335 || (x($profile,'locality') == 1)
336 || (x($profile,'region') == 1)
337 || (x($profile,'postal-code') == 1)
338 || (x($profile,'country-name') == 1))
339 $location = t('Location:');
341 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
344 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
346 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
348 $about = ((x($profile,'about') == 1) ? t('About:') : False);
350 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
352 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
353 $location = $pdesc = $gender = $marital = $homepage = $about = False;
356 $firstname = ((strpos($profile['name'],' '))
357 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
358 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
360 if ($profile['guid'] != "")
362 'guid' => $profile['guid'],
363 'podloc' => System::baseUrl(),
364 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
365 'nickname' => $profile['nickname'],
366 'fullname' => $profile['name'],
367 'firstname' => $firstname,
368 'lastname' => $lastname,
369 'photo300' => $profile['contact_photo'],
370 'photo100' => $profile['contact_thumb'],
371 'photo50' => $profile['contact_micro'],
377 $contact_block = contact_block();
379 if (is_array($a->profile) && !$a->profile['hide-friends']) {
380 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
381 intval($a->profile['uid']));
382 if (dbm::is_result($r))
383 $updated = date("c", strtotime($r[0]['updated']));
385 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
387 AND NOT `self` AND NOT `blocked` AND NOT `pending`
388 AND NOT `hidden` AND NOT `archive`
389 AND `network` IN ('%s', '%s', '%s', '')",
390 intval($profile['uid']),
392 dbesc(NETWORK_DIASPORA),
393 dbesc(NETWORK_OSTATUS)
395 if (dbm::is_result($r))
396 $contacts = intval($r[0]['total']);
401 foreach ($profile as $k => $v) {
402 $k = str_replace('-','_',$k);
406 if (isset($p["about"]))
407 $p["about"] = bbcode($p["about"]);
409 if (isset($p["address"]))
410 $p["address"] = bbcode($p["address"]);
412 $p["address"] = bbcode($p["location"]);
414 if (isset($p["photo"])) {
415 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
417 if ($a->theme['template_engine'] === 'internal')
418 $location = template_escape($location);
420 $tpl = get_markup_template('profile_vcard.tpl');
421 $o .= replace_macros($tpl, array(
424 '$connect' => $connect,
425 '$remoteconnect' => $remoteconnect,
426 '$subscribe_feed' => $subscribe_feed,
427 '$wallmessage' => $wallmessage,
428 '$wallmessage_link' => $wallmessage_link,
429 '$account_type' => $account_type,
430 '$location' => $location,
431 '$gender' => $gender,
432 // '$pdesc' => $pdesc,
433 '$marital' => $marital,
434 '$homepage' => $homepage,
436 '$network' => t('Network:'),
437 '$contacts' => $contacts,
438 '$updated' => $updated,
439 '$diaspora' => $diaspora,
440 '$contact_block' => $contact_block,
443 $arr = array('profile' => &$profile, 'entry' => &$o);
445 call_hooks('profile_sidebar', $arr);
451 function get_birthdays() {
456 if (! local_user() || $a->is_mobile || $a->is_tablet)
459 // $mobile_detect = new Mobile_Detect();
460 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
465 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
466 $bd_short = t('F d');
468 $cachekey = "get_birthdays:".local_user();
469 $r = Cache::get($cachekey);
471 $s = dba::p("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
472 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
473 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
474 ORDER BY `start` ASC ",
476 datetime_convert('UTC','UTC','now + 6 days'),
477 datetime_convert('UTC','UTC','now')
479 if (dbm::is_result($s)) {
480 $r = dba::inArray($s);
481 Cache::set($cachekey, $r, CACHE_HOUR);
484 if (dbm::is_result($r)) {
486 $now = strtotime('now');
490 foreach ($r as $rr) {
491 if (strlen($rr['name']))
493 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
496 $classtoday = $istoday ? ' birthday-today ' : '';
498 foreach ($r as &$rr) {
499 if (! strlen($rr['name']))
504 if (in_array($rr['cid'],$cids))
506 $cids[] = $rr['cid'];
508 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
511 if ($rr['network'] === NETWORK_DFRN) {
512 $sparkle = " sparkle";
513 $url = System::baseUrl() . '/redir/' . $rr['cid'];
517 $rr['title'] = $rr['name'];
518 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
519 $rr['startime'] = Null;
520 $rr['today'] = $today;
525 $tpl = get_markup_template("birthdays_reminder.tpl");
526 return replace_macros($tpl, array(
527 '$baseurl' => System::baseUrl(),
528 '$classtoday' => $classtoday,
530 '$event_reminders' => t('Birthday Reminders'),
531 '$event_title' => t('Birthdays this week:'),
533 '$lbr' => '{', // raw brackets mess up if/endif macro processing
540 function get_events() {
542 require_once 'include/bbcode.php';
546 if (! local_user() || $a->is_mobile || $a->is_tablet) {
550 // $mobile_detect = new Mobile_Detect();
551 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
556 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
557 $bd_short = t('F d');
559 $s = dba::p("SELECT `event`.* FROM `event`
560 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
561 ORDER BY `start` ASC ",
563 datetime_convert('UTC','UTC','now + 7 days'),
564 datetime_convert('UTC','UTC','now - 1 days')
569 if (dbm::is_result($s)) {
570 $now = strtotime('now');
573 while ($rr = dba::fetch($s)) {
574 if (strlen($rr['name'])) {
578 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
579 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
583 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
585 if (strlen($title) > 35) {
586 $title = substr($title,0,32) . '... ';
589 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
590 if (! $description) {
591 $description = t('[No description]');
594 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
596 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
600 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
602 $rr['title'] = $title;
603 $rr['description'] = $desciption;
604 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
605 $rr['startime'] = $strt;
606 $rr['today'] = $today;
611 $classtoday = (($istoday) ? 'event-today' : '');
613 $tpl = get_markup_template("events_reminder.tpl");
614 return replace_macros($tpl, array(
615 '$baseurl' => System::baseUrl(),
616 '$classtoday' => $classtoday,
617 '$count' => count($r),
618 '$event_reminders' => t('Event Reminders'),
619 '$event_title' => t('Events this week:'),
624 function advanced_profile(App $a) {
627 $uid = $a->profile['uid'];
629 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
630 '$title' => t('Profile')
633 if ($a->profile['name']) {
635 $tpl = get_markup_template('profile_advanced.tpl');
639 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
641 if ($a->profile['gender']) {
642 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
645 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
646 $year_bd_format = t('j F, Y');
647 $short_bd_format = t('j F');
650 $val = ((intval($a->profile['dob']))
651 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
652 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
654 $profile['birthday'] = array( t('Birthday:'), $val);
657 if (!empty($a->profile['dob'])
658 && $a->profile['dob'] > '0001-01-01'
659 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
661 $profile['age'] = array( t('Age:'), $age );
664 if ($a->profile['marital']) {
665 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
668 /// @TODO Maybe use x() here, plus below?
669 if ($a->profile['with']) {
670 $profile['marital']['with'] = $a->profile['with'];
673 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
674 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
677 if ($a->profile['sexual']) {
678 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
681 if ($a->profile['homepage']) {
682 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
685 if ($a->profile['hometown']) {
686 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
689 if ($a->profile['pub_keywords']) {
690 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
693 if ($a->profile['politic']) {
694 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
697 if ($a->profile['religion']) {
698 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
701 if ($txt = prepare_text($a->profile['about'])) {
702 $profile['about'] = array( t('About:'), $txt );
705 if ($txt = prepare_text($a->profile['interest'])) {
706 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
709 if ($txt = prepare_text($a->profile['likes'])) {
710 $profile['likes'] = array( t('Likes:'), $txt);
713 if ($txt = prepare_text($a->profile['dislikes'])) {
714 $profile['dislikes'] = array( t('Dislikes:'), $txt);
717 if ($txt = prepare_text($a->profile['contact'])) {
718 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
721 if ($txt = prepare_text($a->profile['music'])) {
722 $profile['music'] = array( t('Musical interests:'), $txt);
725 if ($txt = prepare_text($a->profile['book'])) {
726 $profile['book'] = array( t('Books, literature:'), $txt);
729 if ($txt = prepare_text($a->profile['tv'])) {
730 $profile['tv'] = array( t('Television:'), $txt);
733 if ($txt = prepare_text($a->profile['film'])) {
734 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
737 if ($txt = prepare_text($a->profile['romance'])) {
738 $profile['romance'] = array( t('Love/Romance:'), $txt);
741 if ($txt = prepare_text($a->profile['work'])) {
742 $profile['work'] = array( t('Work/employment:'), $txt);
745 if ($txt = prepare_text($a->profile['education'])) {
746 $profile['education'] = array( t('School/education:'), $txt );
749 //show subcribed forum if it is enabled in the usersettings
750 if (feature_enabled($uid,'forumlist_profile')) {
751 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
754 if ($a->profile['uid'] == local_user()) {
755 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
758 return replace_macros($tpl, array(
759 '$title' => t('Profile'),
760 '$basic' => t('Basic'),
761 '$advanced' => t('Advanced'),
762 '$profile' => $profile
769 function profile_tabs($a, $is_owner=False, $nickname=Null) {
770 //echo "<pre>"; var_dump($a->user); killme();
772 if (is_null($nickname)) {
773 $nickname = $a->user['nickname'];
776 if (x($_GET,'tab')) {
777 $tab = notags(trim($_GET['tab']));
780 $url = System::baseUrl() . '/profile/' . $nickname;
784 'label'=>t('Status'),
786 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
787 'title' => t('Status Messages and Posts'),
788 'id' => 'status-tab',
792 'label' => t('Profile'),
793 'url' => $url.'/?tab=profile',
794 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
795 'title' => t('Profile Details'),
796 'id' => 'profile-tab',
800 'label' => t('Photos'),
801 'url' => System::baseUrl() . '/photos/' . $nickname,
802 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
803 'title' => t('Photo Albums'),
808 'label' => t('Videos'),
809 'url' => System::baseUrl() . '/videos/' . $nickname,
810 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
811 'title' => t('Videos'),
817 // the calendar link for the full featured events calendar
818 if ($is_owner && $a->theme_events_in_profile) {
820 'label' => t('Events'),
821 'url' => System::baseUrl() . '/events',
822 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
823 'title' => t('Events and Calendar'),
824 'id' => 'events-tab',
827 // if the user is not the owner of the calendar we only show a calendar
828 // with the public events of the calendar owner
829 } elseif (! $is_owner) {
831 'label' => t('Events'),
832 'url' => System::baseUrl() . '/cal/' . $nickname,
833 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
834 'title' => t('Events and Calendar'),
835 'id' => 'events-tab',
842 'label' => t('Personal Notes'),
843 'url' => System::baseUrl() . '/notes',
844 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
845 'title' => t('Only You Can See This'),
851 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
853 'label' => t('Contacts'),
854 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
855 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
856 'title' => t('Contacts'),
857 'id' => 'viewcontacts-tab',
862 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
863 call_hooks('profile_tabs', $arr);
865 $tpl = get_markup_template('common_tabs.tpl');
867 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
870 function get_my_url() {
871 if (x($_SESSION, 'my_url')) {
872 return $_SESSION['my_url'];
877 function zrl_init(App $a) {
878 $tmp_str = get_my_url();
879 if (validate_url($tmp_str)) {
881 // Is it a DDoS attempt?
882 // The check fetches the cached value from gprobe to reduce the load for this system
883 $urlparts = parse_url($tmp_str);
885 $result = Cache::get("gprobe:" . $urlparts["host"]);
886 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
887 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
891 proc_run(PRIORITY_LOW, 'include/gprobe.php', $tmp_str);
892 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
893 call_hooks('zrl_init', $arr);
897 function zrl($s, $force = false) {
901 if ((! strpos($s, '/profile/')) && (! $force)) {
904 if ($force && substr($s, -1, 1) !== '/') {
907 $achar = strpos($s, '?') ? '&' : '?';
908 $mine = get_my_url();
909 if ($mine && ! link_compare($mine, $s)) {
910 return $s . $achar . 'zrl=' . urlencode($mine);
916 * @brief Get the user ID of the page owner
918 * Used from within PCSS themes to set theme parameters. If there's a
919 * puid request variable, that is the "page owner" and normally their theme
920 * settings take precedence; unless a local user sets the "always_my_theme"
921 * system pconfig, which means they don't want to see anybody else's theme
922 * settings except their own while on this site.
924 * @return int user ID
926 * @note Returns local_user instead of user ID if "always_my_theme"
929 function get_theme_uid() {
930 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
931 if ((local_user()) && ((get_pconfig(local_user(), 'system', 'always_my_theme')) || (! $uid))) {