3 * @file src/Model/Profile.php
5 namespace Friendica\Model;
8 use Friendica\Content\Feature;
9 use Friendica\Content\ForumManager;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Cache;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Core\PConfig;
15 use Friendica\Core\System;
16 use Friendica\Core\Worker;
17 use Friendica\Database\DBM;
18 use Friendica\Model\Contact;
19 use Friendica\Protocol\Diaspora;
20 use Friendica\Util\Network;
21 use Friendica\Util\Temporal;
24 require_once 'include/dba.php';
25 require_once 'include/bbcode.php';
26 require_once 'mod/proxy.php';
31 * @brief Returns a formatted location string from the given profile array
33 * @param array $profile Profile array (Generated from the "profile" table)
35 * @return string Location string
37 public static function formatLocation(array $profile)
41 if ($profile['locality']) {
42 $location .= $profile['locality'];
45 if ($profile['region'] && ($profile['locality'] != $profile['region'])) {
50 $location .= $profile['region'];
53 if ($profile['country-name']) {
58 $location .= $profile['country-name'];
66 * Loads a profile into the page sidebar.
68 * The function requires a writeable copy of the main App structure, and the nickname
69 * of a registered local account.
71 * If the viewer is an authenticated remote viewer, the profile displayed is the
72 * one that has been configured for his/her viewing in the Contact manager.
73 * Passing a non-zero profile ID can also allow a preview of a selected profile
76 * Profile information is placed in the App structure for later retrieval.
77 * Honours the owner's chosen theme for display.
79 * @attention Should only be run in the _init() functions of a module. That ensures that
80 * the theme is chosen before the _init() function of a theme is run, which will usually
81 * load a lot of theme-specific content
83 * @brief Loads a profile into the page sidebar.
84 * @param object $a App
85 * @param string $nickname string
86 * @param int $profile int
87 * @param array $profiledata array
88 * @param boolean $show_connect Show connect link
90 public static function load(App $a, $nickname, $profile = 0, $profiledata = [], $show_connect = true)
92 $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
94 if (!$user && !count($user) && !count($profiledata)) {
95 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
96 notice(L10n::t('Requested account is not available.') . EOL);
101 if (!x($a->page, 'aside')) {
102 $a->page['aside'] = '';
106 $a->page['aside'] .= self::sidebar($profiledata, true, $show_connect);
108 if (!DBM::is_result($user)) {
113 $pdata = self::getByNickname($nickname, $user[0]['uid'], $profile);
115 if (empty($pdata) && empty($profiledata)) {
116 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
117 notice(L10n::t('Requested profile is not available.') . EOL);
122 // fetch user tags if this isn't the default profile
124 if (!$pdata['is-default']) {
126 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
127 intval($pdata['profile_uid'])
129 if ($x && count($x)) {
130 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
134 $a->profile = $pdata;
135 $a->profile_uid = $pdata['profile_uid'];
137 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
138 $a->profile['network'] = NETWORK_DFRN;
140 $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename'];
142 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
143 $_SESSION['theme'] = $a->profile['theme'];
146 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
149 * load/reload current theme info
152 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
154 $theme_info_file = 'view/theme/' . current_theme() . '/theme.php';
155 if (file_exists($theme_info_file)) {
156 require_once $theme_info_file;
159 if (!x($a->page, 'aside')) {
160 $a->page['aside'] = '';
163 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
164 $a->page['aside'] .= replace_macros(
165 get_markup_template('profile_edlink.tpl'),
167 '$editprofile' => L10n::t('Edit profile'),
168 '$profid' => $a->profile['id']
173 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
177 * By now, the contact block isn't shown, when a different profile is given
178 * But: When this profile was on the same server, then we could display the contacts
181 $a->page['aside'] .= self::sidebar($a->profile, $block, $show_connect);
188 * Get all profile data of a local user
190 * If the viewer is an authenticated remote viewer, the profile displayed is the
191 * one that has been configured for his/her viewing in the Contact manager.
192 * Passing a non-zero profile ID can also allow a preview of a selected profile
195 * Includes all available profile data
197 * @brief Get all profile data of a local user
198 * @param string $nickname nick
199 * @param int $uid uid
200 * @param int $profile_id ID of the profile
203 public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
205 if (remote_user() && count($_SESSION['remote'])) {
206 foreach ($_SESSION['remote'] as $visitor) {
207 if ($visitor['uid'] == $uid) {
208 $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
209 if (DBM::is_result($contact)) {
210 $profile_id = $contact['profile-id'];
220 $profile = dba::fetch_first(
221 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
222 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
223 `profile`.`uid` AS `profile_uid`, `profile`.*,
224 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
226 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
227 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
228 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
233 if (!DBM::is_result($profile)) {
234 $profile = dba::fetch_first(
235 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
236 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
237 `profile`.`uid` AS `profile_uid`, `profile`.*,
238 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
240 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
241 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
242 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
251 * Formats a profile for display in the sidebar.
253 * It is very difficult to templatise the HTML completely
254 * because of all the conditional logic.
256 * @brief Formats a profile for display in the sidebar.
257 * @param array $profile
259 * @param boolean $show_connect Show connect link
261 * @return HTML string suitable for sidebar inclusion
263 * @note Returns empty string if passed $profile is wrong type or not populated
265 * @hooks 'profile_sidebar_enter'
266 * array $profile - profile data
267 * @hooks 'profile_sidebar'
270 private static function sidebar($profile, $block = 0, $show_connect = true)
277 // This function can also use contact information in $profile
278 $is_contact = x($profile, 'cid');
280 if (!is_array($profile) && !count($profile)) {
284 $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
286 if (($profile['network'] != '') && ($profile['network'] != NETWORK_DFRN)) {
287 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
289 $profile['network_name'] = '';
292 Addon::callHooks('profile_sidebar_enter', $profile);
295 // don't show connect link to yourself
296 $connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false;
298 // don't show connect link to authenticated visitors either
299 if (remote_user() && count($_SESSION['remote'])) {
300 foreach ($_SESSION['remote'] as $visitor) {
301 if ($visitor['uid'] == $profile['uid']) {
308 if (!$show_connect) {
312 // Is the local user already connected to that user?
313 if ($connect && local_user()) {
314 if (isset($profile['url'])) {
315 $profile_url = normalise_link($profile['url']);
317 $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']);
320 if (dba::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) {
325 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect'])) {
329 $remoteconnect = null;
330 if (isset($profile['remoteconnect'])) {
331 $remoteconnect = $profile['remoteconnect'];
334 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect)) {
335 $subscribe_feed = L10n::t('Atom feed');
337 $subscribe_feed = false;
340 if (remote_user() || (self::getMyURL() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
341 $wallmessage = L10n::t('Message');
342 $wallmessage_link = 'wallmessage/' . $profile['nickname'];
346 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
347 intval($profile['uid']),
348 intval(remote_user()),
349 intval(CONTACT_IS_FRIEND)
353 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
354 intval($profile['uid']),
355 dbesc(normalise_link(self::getMyURL())),
356 intval(CONTACT_IS_FRIEND)
360 $remote_url = $r[0]['url'];
361 $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url);
362 $wallmessage_link = $message_path . base64_encode($profile['addr']);
365 $wallmessage = false;
366 $wallmessage_link = false;
369 // show edit profile to yourself
370 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
371 $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')];
373 "SELECT * FROM `profile` WHERE `uid` = %d",
378 'chg_photo' => L10n::t('Change profile photo'),
379 'cr_new' => L10n::t('Create New Profile'),
383 if (DBM::is_result($r)) {
384 foreach ($r as $rr) {
385 $profile['menu']['entries'][] = [
386 'photo' => $rr['thumb'],
388 'alt' => L10n::t('Profile Image'),
389 'profile_name' => $rr['profile-name'],
390 'isdefault' => $rr['is-default'],
391 'visibile_to_everybody' => L10n::t('visible to everybody'),
392 'edit_visibility' => L10n::t('Edit visibility'),
397 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
398 $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
400 'chg_photo' => L10n::t('Change profile photo'),
406 // Fetch the account type
407 $account_type = Contact::getAccountType($profile);
409 if (x($profile, 'address')
410 || x($profile, 'location')
411 || x($profile, 'locality')
412 || x($profile, 'region')
413 || x($profile, 'postal-code')
414 || x($profile, 'country-name')
416 $location = L10n::t('Location:');
419 $gender = x($profile, 'gender') ? L10n::t('Gender:') : false;
420 $marital = x($profile, 'marital') ? L10n::t('Status:') : false;
421 $homepage = x($profile, 'homepage') ? L10n::t('Homepage:') : false;
422 $about = x($profile, 'about') ? L10n::t('About:') : false;
423 $xmpp = x($profile, 'xmpp') ? L10n::t('XMPP:') : false;
425 if ((x($profile, 'hidewall') || $block) && !local_user() && !remote_user()) {
426 $location = $gender = $marital = $homepage = $about = false;
429 $split_name = Diaspora::splitName($profile['name']);
430 $firstname = $split_name['first'];
431 $lastname = $split_name['last'];
433 if (x($profile, 'guid')) {
435 'guid' => $profile['guid'],
436 'podloc' => System::baseUrl(),
437 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
438 'nickname' => $profile['nickname'],
439 'fullname' => $profile['name'],
440 'firstname' => $firstname,
441 'lastname' => $lastname,
442 'photo300' => $profile['contact_photo'],
443 'photo100' => $profile['contact_thumb'],
444 'photo50' => $profile['contact_micro'],
454 $contact_block = contact_block();
456 if (is_array($a->profile) && !$a->profile['hide-friends']) {
458 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
459 intval($a->profile['uid'])
461 if (DBM::is_result($r)) {
462 $updated = date('c', strtotime($r[0]['updated']));
466 "SELECT COUNT(*) AS `total` FROM `contact`
468 AND NOT `self` AND NOT `blocked` AND NOT `pending`
469 AND NOT `hidden` AND NOT `archive`
470 AND `network` IN ('%s', '%s', '%s', '')",
471 intval($profile['uid']),
473 dbesc(NETWORK_DIASPORA),
474 dbesc(NETWORK_OSTATUS)
476 if (DBM::is_result($r)) {
477 $contacts = intval($r[0]['total']);
483 foreach ($profile as $k => $v) {
484 $k = str_replace('-', '_', $k);
488 if (isset($p['about'])) {
489 $p['about'] = bbcode($p['about']);
492 if (isset($p['address'])) {
493 $p['address'] = bbcode($p['address']);
495 $p['address'] = bbcode($p['location']);
498 if (isset($p['photo'])) {
499 $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
502 $tpl = get_markup_template('profile_vcard.tpl');
503 $o .= replace_macros($tpl, [
506 '$connect' => $connect,
507 '$remoteconnect' => $remoteconnect,
508 '$subscribe_feed' => $subscribe_feed,
509 '$wallmessage' => $wallmessage,
510 '$wallmessage_link' => $wallmessage_link,
511 '$account_type' => $account_type,
512 '$location' => $location,
513 '$gender' => $gender,
514 '$marital' => $marital,
515 '$homepage' => $homepage,
517 '$network' => L10n::t('Network:'),
518 '$contacts' => $contacts,
519 '$updated' => $updated,
520 '$diaspora' => $diaspora,
521 '$contact_block' => $contact_block,
524 $arr = ['profile' => &$profile, 'entry' => &$o];
526 Addon::callHooks('profile_sidebar', $arr);
531 public static function getBirthdays()
536 if (!local_user() || $a->is_mobile || $a->is_tablet) {
541 * $mobile_detect = new Mobile_Detect();
542 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
547 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
548 $bd_short = L10n::t('F d');
550 $cachekey = 'get_birthdays:' . local_user();
551 $r = Cache::get($cachekey);
554 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
555 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
556 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
557 ORDER BY `start` ASC ",
559 Temporal::convert('now + 6 days'),
562 if (DBM::is_result($s)) {
563 $r = dba::inArray($s);
564 Cache::set($cachekey, $r, CACHE_HOUR);
567 if (DBM::is_result($r)) {
569 $now = strtotime('now');
573 foreach ($r as $rr) {
574 if (strlen($rr['name'])) {
577 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
581 $classtoday = $istoday ? ' birthday-today ' : '';
583 foreach ($r as &$rr) {
584 if (!strlen($rr['name'])) {
590 if (in_array($rr['cid'], $cids)) {
593 $cids[] = $rr['cid'];
595 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
597 if ($rr['network'] === NETWORK_DFRN) {
598 $url = System::baseUrl() . '/redir/' . $rr['cid'];
602 $rr['title'] = $rr['name'];
603 $rr['date'] = day_translate(Temporal::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
604 $rr['startime'] = null;
605 $rr['today'] = $today;
609 $tpl = get_markup_template('birthdays_reminder.tpl');
610 return replace_macros($tpl, [
611 '$baseurl' => System::baseUrl(),
612 '$classtoday' => $classtoday,
614 '$event_reminders' => L10n::t('Birthday Reminders'),
615 '$event_title' => L10n::t('Birthdays this week:'),
617 '$lbr' => '{', // raw brackets mess up if/endif macro processing
622 public static function getEvents()
624 require_once 'include/bbcode.php';
628 if (!local_user() || $a->is_mobile || $a->is_tablet) {
633 * $mobile_detect = new Mobile_Detect();
634 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
639 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
643 "SELECT `event`.* FROM `event`
644 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
645 ORDER BY `start` ASC ",
647 Temporal::convert('now + 7 days'),
648 Temporal::convert('now - 1 days')
653 if (DBM::is_result($s)) {
656 while ($rr = dba::fetch($s)) {
657 if (strlen($rr['name'])) {
661 $strt = Temporal::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC', 'UTC', 'Y-m-d');
662 if ($strt === Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) {
666 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
668 if (strlen($title) > 35) {
669 $title = substr($title, 0, 32) . '... ';
672 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
674 $description = L10n::t('[No description]');
677 $strt = Temporal::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC');
679 if (substr($strt, 0, 10) < Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) {
683 $today = ((substr($strt, 0, 10) === Temporal::convert('now', $a->timezone, 'UTC', 'Y-m-d')) ? true : false);
685 $rr['title'] = $title;
686 $rr['description'] = $description;
687 $rr['date'] = day_translate(Temporal::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : '');
688 $rr['startime'] = $strt;
689 $rr['today'] = $today;
694 $classtoday = (($istoday) ? 'event-today' : '');
696 $tpl = get_markup_template('events_reminder.tpl');
697 return replace_macros($tpl, [
698 '$baseurl' => System::baseUrl(),
699 '$classtoday' => $classtoday,
700 '$count' => count($r),
701 '$event_reminders' => L10n::t('Event Reminders'),
702 '$event_title' => L10n::t('Events this week:'),
707 public static function getAdvanced(App $a)
710 $uid = $a->profile['uid'];
712 $o .= replace_macros(
713 get_markup_template('section_title.tpl'),
714 ['$title' => L10n::t('Profile')]
717 if ($a->profile['name']) {
718 $tpl = get_markup_template('profile_advanced.tpl');
722 $profile['fullname'] = [L10n::t('Full Name:'), $a->profile['name']];
724 if ($a->profile['gender']) {
725 $profile['gender'] = [L10n::t('Gender:'), $a->profile['gender']];
728 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
729 $year_bd_format = L10n::t('j F, Y');
730 $short_bd_format = L10n::t('j F');
732 $val = intval($a->profile['dob']) ?
733 day_translate(Temporal::convert($a->profile['dob'] . ' 00:00 +00:00', 'UTC', 'UTC', $year_bd_format))
734 : day_translate(Temporal::convert('2001-' . substr($a->profile['dob'], 'UTC', 'UTC', 5) . ' 00:00 +00:00', $short_bd_format));
736 $profile['birthday'] = [L10n::t('Birthday:'), $val];
739 if (!empty($a->profile['dob'])
740 && $a->profile['dob'] > '0001-01-01'
741 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
743 $profile['age'] = [L10n::t('Age:'), $age];
746 if ($a->profile['marital']) {
747 $profile['marital'] = [L10n::t('Status:'), $a->profile['marital']];
750 /// @TODO Maybe use x() here, plus below?
751 if ($a->profile['with']) {
752 $profile['marital']['with'] = $a->profile['with'];
755 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
756 $profile['howlong'] = relative_date($a->profile['howlong'], L10n::t('for %1$d %2$s'));
759 if ($a->profile['sexual']) {
760 $profile['sexual'] = [L10n::t('Sexual Preference:'), $a->profile['sexual']];
763 if ($a->profile['homepage']) {
764 $profile['homepage'] = [L10n::t('Homepage:'), linkify($a->profile['homepage'])];
767 if ($a->profile['hometown']) {
768 $profile['hometown'] = [L10n::t('Hometown:'), linkify($a->profile['hometown'])];
771 if ($a->profile['pub_keywords']) {
772 $profile['pub_keywords'] = [L10n::t('Tags:'), $a->profile['pub_keywords']];
775 if ($a->profile['politic']) {
776 $profile['politic'] = [L10n::t('Political Views:'), $a->profile['politic']];
779 if ($a->profile['religion']) {
780 $profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
783 if ($txt = prepare_text($a->profile['about'])) {
784 $profile['about'] = [L10n::t('About:'), $txt];
787 if ($txt = prepare_text($a->profile['interest'])) {
788 $profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
791 if ($txt = prepare_text($a->profile['likes'])) {
792 $profile['likes'] = [L10n::t('Likes:'), $txt];
795 if ($txt = prepare_text($a->profile['dislikes'])) {
796 $profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
799 if ($txt = prepare_text($a->profile['contact'])) {
800 $profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
803 if ($txt = prepare_text($a->profile['music'])) {
804 $profile['music'] = [L10n::t('Musical interests:'), $txt];
807 if ($txt = prepare_text($a->profile['book'])) {
808 $profile['book'] = [L10n::t('Books, literature:'), $txt];
811 if ($txt = prepare_text($a->profile['tv'])) {
812 $profile['tv'] = [L10n::t('Television:'), $txt];
815 if ($txt = prepare_text($a->profile['film'])) {
816 $profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
819 if ($txt = prepare_text($a->profile['romance'])) {
820 $profile['romance'] = [L10n::t('Love/Romance:'), $txt];
823 if ($txt = prepare_text($a->profile['work'])) {
824 $profile['work'] = [L10n::t('Work/employment:'), $txt];
827 if ($txt = prepare_text($a->profile['education'])) {
828 $profile['education'] = [L10n::t('School/education:'), $txt];
831 //show subcribed forum if it is enabled in the usersettings
832 if (Feature::isEnabled($uid, 'forumlist_profile')) {
833 $profile['forumlist'] = [L10n::t('Forums:'), ForumManager::profileAdvanced($uid)];
836 if ($a->profile['uid'] == local_user()) {
837 $profile['edit'] = [System::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
840 return replace_macros($tpl, [
841 '$title' => L10n::t('Profile'),
842 '$basic' => L10n::t('Basic'),
843 '$advanced' => L10n::t('Advanced'),
844 '$profile' => $profile
851 public static function getTabs($a, $is_owner = false, $nickname = null)
853 if (is_null($nickname)) {
854 $nickname = $a->user['nickname'];
858 if (x($_GET, 'tab')) {
859 $tab = notags(trim($_GET['tab']));
862 $url = System::baseUrl() . '/profile/' . $nickname;
866 'label' => L10n::t('Status'),
868 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
869 'title' => L10n::t('Status Messages and Posts'),
870 'id' => 'status-tab',
874 'label' => L10n::t('Profile'),
875 'url' => $url . '/?tab=profile',
876 'sel' => $tab == 'profile' ? 'active' : '',
877 'title' => L10n::t('Profile Details'),
878 'id' => 'profile-tab',
882 'label' => L10n::t('Photos'),
883 'url' => System::baseUrl() . '/photos/' . $nickname,
884 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
885 'title' => L10n::t('Photo Albums'),
890 'label' => L10n::t('Videos'),
891 'url' => System::baseUrl() . '/videos/' . $nickname,
892 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
893 'title' => L10n::t('Videos'),
899 // the calendar link for the full featured events calendar
900 if ($is_owner && $a->theme_events_in_profile) {
902 'label' => L10n::t('Events'),
903 'url' => System::baseUrl() . '/events',
904 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
905 'title' => L10n::t('Events and Calendar'),
906 'id' => 'events-tab',
909 // if the user is not the owner of the calendar we only show a calendar
910 // with the public events of the calendar owner
911 } elseif (!$is_owner) {
913 'label' => L10n::t('Events'),
914 'url' => System::baseUrl() . '/cal/' . $nickname,
915 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
916 'title' => L10n::t('Events and Calendar'),
917 'id' => 'events-tab',
924 'label' => L10n::t('Personal Notes'),
925 'url' => System::baseUrl() . '/notes',
926 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
927 'title' => L10n::t('Only You Can See This'),
933 if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
935 'label' => L10n::t('Contacts'),
936 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
937 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
938 'title' => L10n::t('Contacts'),
939 'id' => 'viewcontacts-tab',
944 $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs];
945 Addon::callHooks('profile_tabs', $arr);
947 $tpl = get_markup_template('common_tabs.tpl');
949 return replace_macros($tpl, ['$tabs' => $arr['tabs']]);
953 * Retrieves the my_url session variable
957 public static function getMyURL()
959 if (x($_SESSION, 'my_url')) {
960 return $_SESSION['my_url'];
965 public static function zrlInit(App $a)
967 $my_url = self::getMyURL();
968 $my_url = Network::isUrlValid($my_url);
970 // Is it a DDoS attempt?
971 // The check fetches the cached value from gprobe to reduce the load for this system
972 $urlparts = parse_url($my_url);
974 $result = Cache::get('gprobe:' . $urlparts['host']);
975 if ((!is_null($result)) && (in_array($result['network'], [NETWORK_FEED, NETWORK_PHANTOM]))) {
976 logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
980 Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
981 $arr = ['zrl' => $my_url, 'url' => $a->cmd];
982 Addon::callHooks('zrl_init', $arr);
986 public static function zrl($s, $force = false)
991 if ((!strpos($s, '/profile/')) && (!$force)) {
994 if ($force && substr($s, -1, 1) !== '/') {
997 $achar = strpos($s, '?') ? '&' : '?';
998 $mine = self::getMyURL();
999 if ($mine && !link_compare($mine, $s)) {
1000 return $s . $achar . 'zrl=' . urlencode($mine);
1006 * Get the user ID of the page owner.
1008 * Used from within PCSS themes to set theme parameters. If there's a
1009 * puid request variable, that is the "page owner" and normally their theme
1010 * settings take precedence; unless a local user sets the "always_my_theme"
1011 * system pconfig, which means they don't want to see anybody else's theme
1012 * settings except their own while on this site.
1014 * @brief Get the user ID of the page owner
1015 * @return int user ID
1017 * @note Returns local_user instead of user ID if "always_my_theme"
1020 public static function getThemeUid()
1022 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
1023 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
1024 return local_user();