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;
11 use Friendica\Database\DBM;
13 require_once 'include/ForumManager.php';
14 require_once 'include/bbcode.php';
15 require_once 'mod/proxy.php';
16 require_once 'include/cache.php';
20 * @brief Loads a profile into the page sidebar.
22 * The function requires a writeable copy of the main App structure, and the nickname
23 * of a registered local account.
25 * If the viewer is an authenticated remote viewer, the profile displayed is the
26 * one that has been configured for his/her viewing in the Contact manager.
27 * Passing a non-zero profile ID can also allow a preview of a selected profile
30 * Profile information is placed in the App structure for later retrieval.
31 * Honours the owner's chosen theme for display.
33 * @attention Should only be run in the _init() functions of a module. That ensures that
34 * the theme is chosen before the _init() function of a theme is run, which will usually
35 * load a lot of theme-specific content
38 * @param string $nickname
40 * @param array $profiledata
42 function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
44 $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
48 if (!$user && count($user) && !count($profiledata)) {
49 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
50 notice( t('Requested account is not available.') . EOL );
55 $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
57 if (empty($pdata) && empty($profiledata)) {
58 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
59 notice( t('Requested profile is not available.') . EOL );
64 // fetch user tags if this isn't the default profile
66 if (!$pdata['is-default']) {
67 $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
68 intval($pdata['profile_uid'])
71 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
75 $a->profile_uid = $pdata['profile_uid'];
77 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
78 $a->profile['network'] = NETWORK_DFRN;
80 $a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
82 if (!$profiledata && !PConfig::get(local_user(),'system','always_my_theme'))
83 $_SESSION['theme'] = $a->profile['theme'];
85 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
88 * load/reload current theme info
91 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
93 $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
94 if (file_exists($theme_info_file)) {
95 require_once $theme_info_file;
98 if (! (x($a->page,'aside')))
99 $a->page['aside'] = '';
101 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
102 $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array(
103 '$editprofile' => t('Edit profile'),
104 '$profid' => $a->profile['id']
108 $block = (((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
112 * By now, the contact block isn't shown, when a different profile is given
113 * But: When this profile was on the same server, then we could display the contacts
116 $a->page['aside'] .= profile_sidebar($profiledata, true);
118 $a->page['aside'] .= profile_sidebar($a->profile, $block);
121 $a->page['aside'] .= contact_block();*/
128 * @brief Get all profil data of a local user
130 * If the viewer is an authenticated remote viewer, the profile displayed is the
131 * one that has been configured for his/her viewing in the Contact manager.
132 * Passing a non-zero profile ID can also allow a preview of a selected profile
135 * @param string $nickname
137 * @param int $profile
140 * Includes all available profile data
142 function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
143 if (remote_user() && count($_SESSION['remote'])) {
144 foreach ($_SESSION['remote'] as $visitor) {
145 if ($visitor['uid'] == $uid) {
146 $r = dba::select('contact', array('profile-id'), array('id' => $visitor['cid']), array('limit' => 1));
147 if (DBM::is_result($r)) {
148 $profile = $r['profile-id'];
158 $profile_int = intval($profile);
159 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
160 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
161 `profile`.`uid` AS `profile_uid`, `profile`.*,
162 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
164 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
165 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
166 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
171 if (!DBM::is_result($r)) {
172 $r = dba::fetch_first("SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
173 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
174 `profile`.`uid` AS `profile_uid`, `profile`.*,
175 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.*
177 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
178 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
179 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
189 * @brief Formats a profile for display in the sidebar.
191 * It is very difficult to templatise the HTML completely
192 * because of all the conditional logic.
194 * @param array $profile
197 * @return HTML string stuitable for sidebar inclusion
199 * @note Returns empty string if passed $profile is wrong type or not populated
201 * @hooks 'profile_sidebar_enter'
202 * array $profile - profile data
203 * @hooks 'profile_sidebar'
206 function profile_sidebar($profile, $block = 0) {
214 // This function can also use contact information in $profile
215 $is_contact = x($profile, 'cid');
217 if ((! is_array($profile)) && (! count($profile))) {
221 $profile['picdate'] = urlencode($profile['picdate']);
223 if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
224 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
226 $profile['network_name'] = "";
229 call_hooks('profile_sidebar_enter', $profile);
232 // don't show connect link to yourself
233 $connect = (($profile['uid'] != local_user()) ? t('Connect') : False);
235 // don't show connect link to authenticated visitors either
236 if (remote_user() && count($_SESSION['remote'])) {
237 foreach ($_SESSION['remote'] as $visitor) {
238 if ($visitor['uid'] == $profile['uid']) {
245 // Is the local user already connected to that user?
246 if ($connect && local_user()) {
247 if (isset($profile["url"])) {
248 $profile_url = normalise_link($profile["url"]);
250 $profile_url = normalise_link(System::baseUrl()."/profile/".$profile["nickname"]);
253 if (dba::exists('contact', array('pending' => false, 'uid' => local_user(), 'nurl' => $profile_url))) {
258 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
261 $remoteconnect = NULL;
262 if (isset($profile['remoteconnect']))
263 $remoteconnect = $profile['remoteconnect'];
265 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
266 $subscribe_feed = t("Atom feed");
268 $subscribe_feed = false;
270 if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
271 $wallmessage = t('Message');
272 $wallmessage_link = "wallmessage/".$profile["nickname"];
275 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
276 intval($profile['uid']),
277 intval(remote_user()),
278 intval(CONTACT_IS_FRIEND));
280 $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
281 intval($profile['uid']),
282 dbesc(normalise_link(get_my_url())),
283 intval(CONTACT_IS_FRIEND));
286 $remote_url = $r[0]["url"];
287 $message_path = preg_replace("=(.*)/profile/(.*)=ism", "$1/message/new/", $remote_url);
288 $wallmessage_link = $message_path.base64_encode($profile["addr"]);
291 $wallmessage = false;
292 $wallmessage_link = false;
295 // show edit profile to yourself
296 if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(),'multi_profiles')) {
297 $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles'));
298 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
301 $profile['menu'] = array(
302 'chg_photo' => t('Change profile photo'),
303 'cr_new' => t('Create New Profile'),
304 'entries' => array(),
307 if (DBM::is_result($r)) {
309 foreach ($r as $rr) {
310 $profile['menu']['entries'][] = array(
311 'photo' => $rr['thumb'],
313 'alt' => t('Profile Image'),
314 'profile_name' => $rr['profile-name'],
315 'isdefault' => $rr['is-default'],
316 'visibile_to_everybody' => t('visible to everybody'),
317 'edit_visibility' => t('Edit visibility'),
325 if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(),'multi_profiles')) {
326 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile'));
327 $profile['menu'] = array(
328 'chg_photo' => t('Change profile photo'),
330 'entries' => array(),
334 // Fetch the account type
335 $account_type = account_type($profile);
337 if ((x($profile,'address') == 1)
338 || (x($profile,'location') == 1)
339 || (x($profile,'locality') == 1)
340 || (x($profile,'region') == 1)
341 || (x($profile,'postal-code') == 1)
342 || (x($profile,'country-name') == 1))
343 $location = t('Location:');
345 $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
348 $marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
350 $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
352 $about = ((x($profile,'about') == 1) ? t('About:') : False);
354 $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False);
356 if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
357 $location = $pdesc = $gender = $marital = $homepage = $about = False;
360 $firstname = ((strpos($profile['name'],' '))
361 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
362 $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname))));
364 if ($profile['guid'] != "")
366 'guid' => $profile['guid'],
367 'podloc' => System::baseUrl(),
368 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
369 'nickname' => $profile['nickname'],
370 'fullname' => $profile['name'],
371 'firstname' => $firstname,
372 'lastname' => $lastname,
373 'photo300' => $profile['contact_photo'],
374 'photo100' => $profile['contact_thumb'],
375 'photo50' => $profile['contact_micro'],
381 $contact_block = contact_block();
383 if (is_array($a->profile) && !$a->profile['hide-friends']) {
384 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
385 intval($a->profile['uid']));
386 if (DBM::is_result($r))
387 $updated = date("c", strtotime($r[0]['updated']));
389 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
391 AND NOT `self` AND NOT `blocked` AND NOT `pending`
392 AND NOT `hidden` AND NOT `archive`
393 AND `network` IN ('%s', '%s', '%s', '')",
394 intval($profile['uid']),
396 dbesc(NETWORK_DIASPORA),
397 dbesc(NETWORK_OSTATUS)
399 if (DBM::is_result($r))
400 $contacts = intval($r[0]['total']);
405 foreach ($profile as $k => $v) {
406 $k = str_replace('-','_',$k);
410 if (isset($p["about"]))
411 $p["about"] = bbcode($p["about"]);
413 if (isset($p["address"]))
414 $p["address"] = bbcode($p["address"]);
416 $p["address"] = bbcode($p["location"]);
418 if (isset($p["photo"])) {
419 $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
421 if ($a->theme['template_engine'] === 'internal')
422 $location = template_escape($location);
424 $tpl = get_markup_template('profile_vcard.tpl');
425 $o .= replace_macros($tpl, array(
428 '$connect' => $connect,
429 '$remoteconnect' => $remoteconnect,
430 '$subscribe_feed' => $subscribe_feed,
431 '$wallmessage' => $wallmessage,
432 '$wallmessage_link' => $wallmessage_link,
433 '$account_type' => $account_type,
434 '$location' => $location,
435 '$gender' => $gender,
436 // '$pdesc' => $pdesc,
437 '$marital' => $marital,
438 '$homepage' => $homepage,
440 '$network' => t('Network:'),
441 '$contacts' => $contacts,
442 '$updated' => $updated,
443 '$diaspora' => $diaspora,
444 '$contact_block' => $contact_block,
447 $arr = array('profile' => &$profile, 'entry' => &$o);
449 call_hooks('profile_sidebar', $arr);
455 function get_birthdays() {
460 if (! local_user() || $a->is_mobile || $a->is_tablet)
463 // $mobile_detect = new Mobile_Detect();
464 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
469 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
470 $bd_short = t('F d');
472 $cachekey = "get_birthdays:".local_user();
473 $r = Cache::get($cachekey);
475 $s = dba::p("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
476 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
477 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
478 ORDER BY `start` ASC ",
480 datetime_convert('UTC','UTC','now + 6 days'),
481 datetime_convert('UTC','UTC','now')
483 if (DBM::is_result($s)) {
484 $r = dba::inArray($s);
485 Cache::set($cachekey, $r, CACHE_HOUR);
488 if (DBM::is_result($r)) {
490 $now = strtotime('now');
494 foreach ($r as $rr) {
495 if (strlen($rr['name']))
497 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
500 $classtoday = $istoday ? ' birthday-today ' : '';
502 foreach ($r as &$rr) {
503 if (! strlen($rr['name']))
508 if (in_array($rr['cid'],$cids))
510 $cids[] = $rr['cid'];
512 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
515 if ($rr['network'] === NETWORK_DFRN) {
516 $sparkle = " sparkle";
517 $url = System::baseUrl() . '/redir/' . $rr['cid'];
521 $rr['title'] = $rr['name'];
522 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
523 $rr['startime'] = Null;
524 $rr['today'] = $today;
529 $tpl = get_markup_template("birthdays_reminder.tpl");
530 return replace_macros($tpl, array(
531 '$baseurl' => System::baseUrl(),
532 '$classtoday' => $classtoday,
534 '$event_reminders' => t('Birthday Reminders'),
535 '$event_title' => t('Birthdays this week:'),
537 '$lbr' => '{', // raw brackets mess up if/endif macro processing
544 function get_events() {
546 require_once 'include/bbcode.php';
550 if (! local_user() || $a->is_mobile || $a->is_tablet) {
554 // $mobile_detect = new Mobile_Detect();
555 // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
560 $bd_format = t('g A l F d') ; // 8 AM Friday January 18
561 $bd_short = t('F d');
563 $s = dba::p("SELECT `event`.* FROM `event`
564 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
565 ORDER BY `start` ASC ",
567 datetime_convert('UTC','UTC','now + 7 days'),
568 datetime_convert('UTC','UTC','now - 1 days')
573 if (DBM::is_result($s)) {
574 $now = strtotime('now');
577 while ($rr = dba::fetch($s)) {
578 if (strlen($rr['name'])) {
582 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
583 if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
587 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
589 if (strlen($title) > 35) {
590 $title = substr($title,0,32) . '... ';
593 $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
594 if (! $description) {
595 $description = t('[No description]');
598 $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
600 if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
604 $today = ((substr($strt,0,10) === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) ? true : false);
606 $rr['title'] = $title;
607 $rr['description'] = $desciption;
608 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
609 $rr['startime'] = $strt;
610 $rr['today'] = $today;
615 $classtoday = (($istoday) ? 'event-today' : '');
617 $tpl = get_markup_template("events_reminder.tpl");
618 return replace_macros($tpl, array(
619 '$baseurl' => System::baseUrl(),
620 '$classtoday' => $classtoday,
621 '$count' => count($r),
622 '$event_reminders' => t('Event Reminders'),
623 '$event_title' => t('Events this week:'),
628 function advanced_profile(App $a) {
631 $uid = $a->profile['uid'];
633 $o .= replace_macros(get_markup_template('section_title.tpl'),array(
634 '$title' => t('Profile')
637 if ($a->profile['name']) {
639 $tpl = get_markup_template('profile_advanced.tpl');
643 $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
645 if ($a->profile['gender']) {
646 $profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
649 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
650 $year_bd_format = t('j F, Y');
651 $short_bd_format = t('j F');
654 $val = ((intval($a->profile['dob']))
655 ? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
656 : day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],5) . ' 00:00 +00:00',$short_bd_format)));
658 $profile['birthday'] = array( t('Birthday:'), $val);
661 if (!empty($a->profile['dob'])
662 && $a->profile['dob'] > '0001-01-01'
663 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
665 $profile['age'] = array( t('Age:'), $age );
668 if ($a->profile['marital']) {
669 $profile['marital'] = array( t('Status:'), $a->profile['marital']);
672 /// @TODO Maybe use x() here, plus below?
673 if ($a->profile['with']) {
674 $profile['marital']['with'] = $a->profile['with'];
677 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
678 $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
681 if ($a->profile['sexual']) {
682 $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] );
685 if ($a->profile['homepage']) {
686 $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) );
689 if ($a->profile['hometown']) {
690 $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) );
693 if ($a->profile['pub_keywords']) {
694 $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']);
697 if ($a->profile['politic']) {
698 $profile['politic'] = array( t('Political Views:'), $a->profile['politic']);
701 if ($a->profile['religion']) {
702 $profile['religion'] = array( t('Religion:'), $a->profile['religion']);
705 if ($txt = prepare_text($a->profile['about'])) {
706 $profile['about'] = array( t('About:'), $txt );
709 if ($txt = prepare_text($a->profile['interest'])) {
710 $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
713 if ($txt = prepare_text($a->profile['likes'])) {
714 $profile['likes'] = array( t('Likes:'), $txt);
717 if ($txt = prepare_text($a->profile['dislikes'])) {
718 $profile['dislikes'] = array( t('Dislikes:'), $txt);
721 if ($txt = prepare_text($a->profile['contact'])) {
722 $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
725 if ($txt = prepare_text($a->profile['music'])) {
726 $profile['music'] = array( t('Musical interests:'), $txt);
729 if ($txt = prepare_text($a->profile['book'])) {
730 $profile['book'] = array( t('Books, literature:'), $txt);
733 if ($txt = prepare_text($a->profile['tv'])) {
734 $profile['tv'] = array( t('Television:'), $txt);
737 if ($txt = prepare_text($a->profile['film'])) {
738 $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt);
741 if ($txt = prepare_text($a->profile['romance'])) {
742 $profile['romance'] = array( t('Love/Romance:'), $txt);
745 if ($txt = prepare_text($a->profile['work'])) {
746 $profile['work'] = array( t('Work/employment:'), $txt);
749 if ($txt = prepare_text($a->profile['education'])) {
750 $profile['education'] = array( t('School/education:'), $txt );
753 //show subcribed forum if it is enabled in the usersettings
754 if (feature_enabled($uid,'forumlist_profile')) {
755 $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
758 if ($a->profile['uid'] == local_user()) {
759 $profile['edit'] = array(System::baseUrl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile'));
762 return replace_macros($tpl, array(
763 '$title' => t('Profile'),
764 '$basic' => t('Basic'),
765 '$advanced' => t('Advanced'),
766 '$profile' => $profile
773 function profile_tabs($a, $is_owner=False, $nickname=Null) {
774 //echo "<pre>"; var_dump($a->user); killme();
776 if (is_null($nickname)) {
777 $nickname = $a->user['nickname'];
780 if (x($_GET,'tab')) {
781 $tab = notags(trim($_GET['tab']));
784 $url = System::baseUrl() . '/profile/' . $nickname;
788 'label'=>t('Status'),
790 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
791 'title' => t('Status Messages and Posts'),
792 'id' => 'status-tab',
796 'label' => t('Profile'),
797 'url' => $url.'/?tab=profile',
798 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
799 'title' => t('Profile Details'),
800 'id' => 'profile-tab',
804 'label' => t('Photos'),
805 'url' => System::baseUrl() . '/photos/' . $nickname,
806 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
807 'title' => t('Photo Albums'),
812 'label' => t('Videos'),
813 'url' => System::baseUrl() . '/videos/' . $nickname,
814 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
815 'title' => t('Videos'),
821 // the calendar link for the full featured events calendar
822 if ($is_owner && $a->theme_events_in_profile) {
824 'label' => t('Events'),
825 'url' => System::baseUrl() . '/events',
826 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
827 'title' => t('Events and Calendar'),
828 'id' => 'events-tab',
831 // if the user is not the owner of the calendar we only show a calendar
832 // with the public events of the calendar owner
833 } elseif (! $is_owner) {
835 'label' => t('Events'),
836 'url' => System::baseUrl() . '/cal/' . $nickname,
837 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
838 'title' => t('Events and Calendar'),
839 'id' => 'events-tab',
846 'label' => t('Personal Notes'),
847 'url' => System::baseUrl() . '/notes',
848 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
849 'title' => t('Only You Can See This'),
855 if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
857 'label' => t('Contacts'),
858 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
859 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
860 'title' => t('Contacts'),
861 'id' => 'viewcontacts-tab',
866 $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
867 call_hooks('profile_tabs', $arr);
869 $tpl = get_markup_template('common_tabs.tpl');
871 return replace_macros($tpl,array('$tabs' => $arr['tabs']));
874 function get_my_url() {
875 if (x($_SESSION, 'my_url')) {
876 return $_SESSION['my_url'];
881 function zrl_init(App $a) {
882 $tmp_str = get_my_url();
883 if (validate_url($tmp_str)) {
885 // Is it a DDoS attempt?
886 // The check fetches the cached value from gprobe to reduce the load for this system
887 $urlparts = parse_url($tmp_str);
889 $result = Cache::get("gprobe:" . $urlparts["host"]);
890 if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
891 logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
895 Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
896 $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
897 call_hooks('zrl_init', $arr);
901 function zrl($s, $force = false) {
905 if ((! strpos($s, '/profile/')) && (! $force)) {
908 if ($force && substr($s, -1, 1) !== '/') {
911 $achar = strpos($s, '?') ? '&' : '?';
912 $mine = get_my_url();
913 if ($mine && ! link_compare($mine, $s)) {
914 return $s . $achar . 'zrl=' . urlencode($mine);
920 * @brief Get the user ID of the page owner
922 * Used from within PCSS themes to set theme parameters. If there's a
923 * puid request variable, that is the "page owner" and normally their theme
924 * settings take precedence; unless a local user sets the "always_my_theme"
925 * system pconfig, which means they don't want to see anybody else's theme
926 * settings except their own while on this site.
928 * @return int user ID
930 * @note Returns local_user instead of user ID if "always_my_theme"
933 function get_theme_uid() {
934 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
935 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {