3 * @file src/Model/Profile.php
5 namespace Friendica\Model;
8 use Friendica\Content\Feature;
9 use Friendica\Content\ForumManager;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\Addon;
12 use Friendica\Core\Cache;
13 use Friendica\Core\Config;
14 use Friendica\Core\L10n;
15 use Friendica\Core\PConfig;
16 use Friendica\Core\System;
17 use Friendica\Core\Worker;
18 use Friendica\Database\DBM;
19 use Friendica\Model\Contact;
20 use Friendica\Protocol\Diaspora;
21 use Friendica\Util\DateTimeFormat;
22 use Friendica\Util\Network;
23 use Friendica\Util\Temporal;
26 require_once 'include/dba.php';
27 require_once 'include/bbcode.php';
28 require_once 'mod/proxy.php';
33 * @brief Returns a formatted location string from the given profile array
35 * @param array $profile Profile array (Generated from the "profile" table)
37 * @return string Location string
39 public static function formatLocation(array $profile)
43 if ($profile['locality']) {
44 $location .= $profile['locality'];
47 if ($profile['region'] && ($profile['locality'] != $profile['region'])) {
52 $location .= $profile['region'];
55 if ($profile['country-name']) {
60 $location .= $profile['country-name'];
68 * Loads a profile into the page sidebar.
70 * The function requires a writeable copy of the main App structure, and the nickname
71 * of a registered local account.
73 * If the viewer is an authenticated remote viewer, the profile displayed is the
74 * one that has been configured for his/her viewing in the Contact manager.
75 * Passing a non-zero profile ID can also allow a preview of a selected profile
78 * Profile information is placed in the App structure for later retrieval.
79 * Honours the owner's chosen theme for display.
81 * @attention Should only be run in the _init() functions of a module. That ensures that
82 * the theme is chosen before the _init() function of a theme is run, which will usually
83 * load a lot of theme-specific content
85 * @brief Loads a profile into the page sidebar.
86 * @param object $a App
87 * @param string $nickname string
88 * @param int $profile int
89 * @param array $profiledata array
90 * @param boolean $show_connect Show connect link
92 public static function load(App $a, $nickname, $profile = 0, $profiledata = [], $show_connect = true)
94 $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
96 if (!$user && !count($user) && !count($profiledata)) {
97 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
98 notice(L10n::t('Requested account is not available.') . EOL);
103 if (!x($a->page, 'aside')) {
104 $a->page['aside'] = '';
108 $a->page['aside'] .= self::sidebar($profiledata, true, $show_connect);
110 if (!DBM::is_result($user)) {
115 $pdata = self::getByNickname($nickname, $user[0]['uid'], $profile);
117 if (empty($pdata) && empty($profiledata)) {
118 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
119 notice(L10n::t('Requested profile is not available.') . EOL);
124 // fetch user tags if this isn't the default profile
126 if (!$pdata['is-default']) {
128 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
129 intval($pdata['profile_uid'])
131 if ($x && count($x)) {
132 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
136 $a->profile = $pdata;
137 $a->profile_uid = $pdata['profile_uid'];
139 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
140 $a->profile['network'] = NETWORK_DFRN;
142 $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename'];
144 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
145 $_SESSION['theme'] = $a->profile['theme'];
148 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
151 * load/reload current theme info
154 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
156 $theme_info_file = 'view/theme/' . current_theme() . '/theme.php';
157 if (file_exists($theme_info_file)) {
158 require_once $theme_info_file;
161 if (!x($a->page, 'aside')) {
162 $a->page['aside'] = '';
165 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
166 $a->page['aside'] .= replace_macros(
167 get_markup_template('profile_edlink.tpl'),
169 '$editprofile' => L10n::t('Edit profile'),
170 '$profid' => $a->profile['id']
175 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
179 * By now, the contact block isn't shown, when a different profile is given
180 * But: When this profile was on the same server, then we could display the contacts
183 $a->page['aside'] .= self::sidebar($a->profile, $block, $show_connect);
190 * Get all profile data of a local user
192 * If the viewer is an authenticated remote viewer, the profile displayed is the
193 * one that has been configured for his/her viewing in the Contact manager.
194 * Passing a non-zero profile ID can also allow a preview of a selected profile
197 * Includes all available profile data
199 * @brief Get all profile data of a local user
200 * @param string $nickname nick
201 * @param int $uid uid
202 * @param int $profile_id ID of the profile
205 public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
207 if (remote_user() && count($_SESSION['remote'])) {
208 foreach ($_SESSION['remote'] as $visitor) {
209 if ($visitor['uid'] == $uid) {
210 $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
211 if (DBM::is_result($contact)) {
212 $profile_id = $contact['profile-id'];
222 $profile = dba::fetch_first(
223 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
224 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
225 `profile`.`uid` AS `profile_uid`, `profile`.*,
226 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
228 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
229 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
230 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
235 if (!DBM::is_result($profile)) {
236 $profile = dba::fetch_first(
237 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
238 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
239 `profile`.`uid` AS `profile_uid`, `profile`.*,
240 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
242 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
243 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
244 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
253 * Formats a profile for display in the sidebar.
255 * It is very difficult to templatise the HTML completely
256 * because of all the conditional logic.
258 * @brief Formats a profile for display in the sidebar.
259 * @param array $profile
261 * @param boolean $show_connect Show connect link
263 * @return string HTML sidebar module
265 * @note Returns empty string if passed $profile is wrong type or not populated
267 * @hooks 'profile_sidebar_enter'
268 * array $profile - profile data
269 * @hooks 'profile_sidebar'
272 private static function sidebar($profile, $block = 0, $show_connect = true)
279 // This function can also use contact information in $profile
280 $is_contact = x($profile, 'cid');
282 if (!is_array($profile) && !count($profile)) {
286 $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
288 if (($profile['network'] != '') && ($profile['network'] != NETWORK_DFRN)) {
289 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
291 $profile['network_name'] = '';
294 Addon::callHooks('profile_sidebar_enter', $profile);
297 // don't show connect link to yourself
298 $connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false;
300 // don't show connect link to authenticated visitors either
301 if (remote_user() && count($_SESSION['remote'])) {
302 foreach ($_SESSION['remote'] as $visitor) {
303 if ($visitor['uid'] == $profile['uid']) {
310 if (!$show_connect) {
314 // Is the local user already connected to that user?
315 if ($connect && local_user()) {
316 if (isset($profile['url'])) {
317 $profile_url = normalise_link($profile['url']);
319 $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']);
322 if (dba::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) {
327 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect'])) {
331 $remoteconnect = null;
332 if (isset($profile['remoteconnect'])) {
333 $remoteconnect = $profile['remoteconnect'];
336 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect)) {
337 $subscribe_feed = L10n::t('Atom feed');
339 $subscribe_feed = false;
342 if (remote_user() || (self::getMyURL() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
343 $wallmessage = L10n::t('Message');
344 $wallmessage_link = 'wallmessage/' . $profile['nickname'];
348 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
349 intval($profile['uid']),
350 intval(remote_user()),
351 intval(CONTACT_IS_FRIEND)
355 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
356 intval($profile['uid']),
357 dbesc(normalise_link(self::getMyURL())),
358 intval(CONTACT_IS_FRIEND)
362 $remote_url = $r[0]['url'];
363 $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url);
364 $wallmessage_link = $message_path . base64_encode($profile['addr']);
367 $wallmessage = false;
368 $wallmessage_link = false;
371 // show edit profile to yourself
372 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
373 $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')];
375 "SELECT * FROM `profile` WHERE `uid` = %d",
380 'chg_photo' => L10n::t('Change profile photo'),
381 'cr_new' => L10n::t('Create New Profile'),
385 if (DBM::is_result($r)) {
386 foreach ($r as $rr) {
387 $profile['menu']['entries'][] = [
388 'photo' => $rr['thumb'],
390 'alt' => L10n::t('Profile Image'),
391 'profile_name' => $rr['profile-name'],
392 'isdefault' => $rr['is-default'],
393 'visibile_to_everybody' => L10n::t('visible to everybody'),
394 'edit_visibility' => L10n::t('Edit visibility'),
399 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
400 $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
402 'chg_photo' => L10n::t('Change profile photo'),
408 // Fetch the account type
409 $account_type = Contact::getAccountType($profile);
411 if (x($profile, 'address')
412 || x($profile, 'location')
413 || x($profile, 'locality')
414 || x($profile, 'region')
415 || x($profile, 'postal-code')
416 || x($profile, 'country-name')
418 $location = L10n::t('Location:');
421 $gender = x($profile, 'gender') ? L10n::t('Gender:') : false;
422 $marital = x($profile, 'marital') ? L10n::t('Status:') : false;
423 $homepage = x($profile, 'homepage') ? L10n::t('Homepage:') : false;
424 $about = x($profile, 'about') ? L10n::t('About:') : false;
425 $xmpp = x($profile, 'xmpp') ? L10n::t('XMPP:') : false;
427 if ((x($profile, 'hidewall') || $block) && !local_user() && !remote_user()) {
428 $location = $gender = $marital = $homepage = $about = false;
431 $split_name = Diaspora::splitName($profile['name']);
432 $firstname = $split_name['first'];
433 $lastname = $split_name['last'];
435 if (x($profile, 'guid')) {
437 'guid' => $profile['guid'],
438 'podloc' => System::baseUrl(),
439 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
440 'nickname' => $profile['nickname'],
441 'fullname' => $profile['name'],
442 'firstname' => $firstname,
443 'lastname' => $lastname,
444 'photo300' => $profile['contact_photo'],
445 'photo100' => $profile['contact_thumb'],
446 'photo50' => $profile['contact_micro'],
456 $contact_block = contact_block();
458 if (is_array($a->profile) && !$a->profile['hide-friends']) {
460 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
461 intval($a->profile['uid'])
463 if (DBM::is_result($r)) {
464 $updated = date('c', strtotime($r[0]['updated']));
468 "SELECT COUNT(*) AS `total` FROM `contact`
470 AND NOT `self` AND NOT `blocked` AND NOT `pending`
471 AND NOT `hidden` AND NOT `archive`
472 AND `network` IN ('%s', '%s', '%s', '')",
473 intval($profile['uid']),
475 dbesc(NETWORK_DIASPORA),
476 dbesc(NETWORK_OSTATUS)
478 if (DBM::is_result($r)) {
479 $contacts = intval($r[0]['total']);
485 foreach ($profile as $k => $v) {
486 $k = str_replace('-', '_', $k);
490 if (isset($p['about'])) {
491 $p['about'] = BBCode::convert($p['about']);
494 if (isset($p['address'])) {
495 $p['address'] = BBCode::convert($p['address']);
497 $p['address'] = BBCode::convert($p['location']);
500 if (isset($p['photo'])) {
501 $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
504 $tpl = get_markup_template('profile_vcard.tpl');
505 $o .= replace_macros($tpl, [
508 '$connect' => $connect,
509 '$remoteconnect' => $remoteconnect,
510 '$subscribe_feed' => $subscribe_feed,
511 '$wallmessage' => $wallmessage,
512 '$wallmessage_link' => $wallmessage_link,
513 '$account_type' => $account_type,
514 '$location' => $location,
515 '$gender' => $gender,
516 '$marital' => $marital,
517 '$homepage' => $homepage,
519 '$network' => L10n::t('Network:'),
520 '$contacts' => $contacts,
521 '$updated' => $updated,
522 '$diaspora' => $diaspora,
523 '$contact_block' => $contact_block,
526 $arr = ['profile' => &$profile, 'entry' => &$o];
528 Addon::callHooks('profile_sidebar', $arr);
533 public static function getBirthdays()
538 if (!local_user() || $a->is_mobile || $a->is_tablet) {
543 * $mobile_detect = new Mobile_Detect();
544 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
549 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
550 $bd_short = L10n::t('F d');
552 $cachekey = 'get_birthdays:' . local_user();
553 $r = Cache::get($cachekey);
556 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
557 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
558 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
559 ORDER BY `start` ASC ",
561 DateTimeFormat::utc('now + 6 days'),
562 DateTimeFormat::utcNow()
564 if (DBM::is_result($s)) {
565 $r = dba::inArray($s);
566 Cache::set($cachekey, $r, CACHE_HOUR);
572 if (DBM::is_result($r)) {
573 $now = strtotime('now');
577 foreach ($r as $rr) {
578 if (strlen($rr['name'])) {
581 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
585 $classtoday = $istoday ? ' birthday-today ' : '';
587 foreach ($r as &$rr) {
588 if (!strlen($rr['name'])) {
594 if (in_array($rr['cid'], $cids)) {
597 $cids[] = $rr['cid'];
599 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
601 if ($rr['network'] === NETWORK_DFRN) {
602 $url = System::baseUrl() . '/redir/' . $rr['cid'];
606 $rr['title'] = $rr['name'];
607 $rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
608 $rr['startime'] = null;
609 $rr['today'] = $today;
613 $tpl = get_markup_template('birthdays_reminder.tpl');
614 return replace_macros($tpl, [
615 '$baseurl' => System::baseUrl(),
616 '$classtoday' => $classtoday,
618 '$event_reminders' => L10n::t('Birthday Reminders'),
619 '$event_title' => L10n::t('Birthdays this week:'),
621 '$lbr' => '{', // raw brackets mess up if/endif macro processing
626 public static function getEvents()
628 require_once 'include/bbcode.php';
633 if (!local_user() || $a->is_mobile || $a->is_tablet) {
638 * $mobile_detect = new Mobile_Detect();
639 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
644 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
648 "SELECT `event`.* FROM `event`
649 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
650 ORDER BY `start` ASC ",
652 DateTimeFormat::utc('now + 7 days'),
653 DateTimeFormat::utc('now - 1 days')
658 if (DBM::is_result($s)) {
661 while ($rr = dba::fetch($s)) {
662 if (strlen($rr['name'])) {
666 $strt = DateTimeFormat::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC', 'UTC', 'Y-m-d');
667 if ($strt === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
671 $title = strip_tags(html_entity_decode(BBCode::convert($rr['summary']), ENT_QUOTES, 'UTF-8'));
673 if (strlen($title) > 35) {
674 $title = substr($title, 0, 32) . '... ';
677 $description = substr(strip_tags(BBCode::convert($rr['desc'])), 0, 32) . '... ';
679 $description = L10n::t('[No description]');
682 $strt = DateTimeFormat::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC');
684 if (substr($strt, 0, 10) < DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
688 $today = ((substr($strt, 0, 10) === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) ? true : false);
690 $rr['title'] = $title;
691 $rr['description'] = $description;
692 $rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : '');
693 $rr['startime'] = $strt;
694 $rr['today'] = $today;
699 $classtoday = (($istoday) ? 'event-today' : '');
701 $tpl = get_markup_template('events_reminder.tpl');
702 return replace_macros($tpl, [
703 '$baseurl' => System::baseUrl(),
704 '$classtoday' => $classtoday,
705 '$count' => count($r),
706 '$event_reminders' => L10n::t('Event Reminders'),
707 '$event_title' => L10n::t('Events this week:'),
712 public static function getAdvanced(App $a)
715 $uid = $a->profile['uid'];
717 $o .= replace_macros(
718 get_markup_template('section_title.tpl'),
719 ['$title' => L10n::t('Profile')]
722 if ($a->profile['name']) {
723 $tpl = get_markup_template('profile_advanced.tpl');
727 $profile['fullname'] = [L10n::t('Full Name:'), $a->profile['name']];
729 if (Feature::isEnabled($uid, 'profile_membersince')) {
730 $profile['membersince'] = [L10n::t('Member since:'), DateTimeFormat::local($a->profile['register_date'])];
733 if ($a->profile['gender']) {
734 $profile['gender'] = [L10n::t('Gender:'), $a->profile['gender']];
737 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
738 $year_bd_format = L10n::t('j F, Y');
739 $short_bd_format = L10n::t('j F');
741 $val = day_translate(
742 intval($a->profile['dob']) ?
743 DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)
744 : DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)
747 $profile['birthday'] = [L10n::t('Birthday:'), $val];
750 if (!empty($a->profile['dob'])
751 && $a->profile['dob'] > '0001-01-01'
752 && $age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'], '')
754 $profile['age'] = [L10n::t('Age:'), $age];
757 if ($a->profile['marital']) {
758 $profile['marital'] = [L10n::t('Status:'), $a->profile['marital']];
761 /// @TODO Maybe use x() here, plus below?
762 if ($a->profile['with']) {
763 $profile['marital']['with'] = $a->profile['with'];
766 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
767 $profile['howlong'] = Temporal::getRelativeDate($a->profile['howlong'], L10n::t('for %1$d %2$s'));
770 if ($a->profile['sexual']) {
771 $profile['sexual'] = [L10n::t('Sexual Preference:'), $a->profile['sexual']];
774 if ($a->profile['homepage']) {
775 $profile['homepage'] = [L10n::t('Homepage:'), linkify($a->profile['homepage'])];
778 if ($a->profile['hometown']) {
779 $profile['hometown'] = [L10n::t('Hometown:'), linkify($a->profile['hometown'])];
782 if ($a->profile['pub_keywords']) {
783 $profile['pub_keywords'] = [L10n::t('Tags:'), $a->profile['pub_keywords']];
786 if ($a->profile['politic']) {
787 $profile['politic'] = [L10n::t('Political Views:'), $a->profile['politic']];
790 if ($a->profile['religion']) {
791 $profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
794 if ($txt = prepare_text($a->profile['about'])) {
795 $profile['about'] = [L10n::t('About:'), $txt];
798 if ($txt = prepare_text($a->profile['interest'])) {
799 $profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
802 if ($txt = prepare_text($a->profile['likes'])) {
803 $profile['likes'] = [L10n::t('Likes:'), $txt];
806 if ($txt = prepare_text($a->profile['dislikes'])) {
807 $profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
810 if ($txt = prepare_text($a->profile['contact'])) {
811 $profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
814 if ($txt = prepare_text($a->profile['music'])) {
815 $profile['music'] = [L10n::t('Musical interests:'), $txt];
818 if ($txt = prepare_text($a->profile['book'])) {
819 $profile['book'] = [L10n::t('Books, literature:'), $txt];
822 if ($txt = prepare_text($a->profile['tv'])) {
823 $profile['tv'] = [L10n::t('Television:'), $txt];
826 if ($txt = prepare_text($a->profile['film'])) {
827 $profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
830 if ($txt = prepare_text($a->profile['romance'])) {
831 $profile['romance'] = [L10n::t('Love/Romance:'), $txt];
834 if ($txt = prepare_text($a->profile['work'])) {
835 $profile['work'] = [L10n::t('Work/employment:'), $txt];
838 if ($txt = prepare_text($a->profile['education'])) {
839 $profile['education'] = [L10n::t('School/education:'), $txt];
842 //show subcribed forum if it is enabled in the usersettings
843 if (Feature::isEnabled($uid, 'forumlist_profile')) {
844 $profile['forumlist'] = [L10n::t('Forums:'), ForumManager::profileAdvanced($uid)];
847 if ($a->profile['uid'] == local_user()) {
848 $profile['edit'] = [System::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
851 return replace_macros($tpl, [
852 '$title' => L10n::t('Profile'),
853 '$basic' => L10n::t('Basic'),
854 '$advanced' => L10n::t('Advanced'),
855 '$profile' => $profile
862 public static function getTabs($a, $is_owner = false, $nickname = null)
864 if (is_null($nickname)) {
865 $nickname = $a->user['nickname'];
869 if (x($_GET, 'tab')) {
870 $tab = notags(trim($_GET['tab']));
873 $url = System::baseUrl() . '/profile/' . $nickname;
877 'label' => L10n::t('Status'),
879 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
880 'title' => L10n::t('Status Messages and Posts'),
881 'id' => 'status-tab',
885 'label' => L10n::t('Profile'),
886 'url' => $url . '/?tab=profile',
887 'sel' => $tab == 'profile' ? 'active' : '',
888 'title' => L10n::t('Profile Details'),
889 'id' => 'profile-tab',
893 'label' => L10n::t('Photos'),
894 'url' => System::baseUrl() . '/photos/' . $nickname,
895 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
896 'title' => L10n::t('Photo Albums'),
901 'label' => L10n::t('Videos'),
902 'url' => System::baseUrl() . '/videos/' . $nickname,
903 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
904 'title' => L10n::t('Videos'),
910 // the calendar link for the full featured events calendar
911 if ($is_owner && $a->theme_events_in_profile) {
913 'label' => L10n::t('Events'),
914 'url' => System::baseUrl() . '/events',
915 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
916 'title' => L10n::t('Events and Calendar'),
917 'id' => 'events-tab',
920 // if the user is not the owner of the calendar we only show a calendar
921 // with the public events of the calendar owner
922 } elseif (!$is_owner) {
924 'label' => L10n::t('Events'),
925 'url' => System::baseUrl() . '/cal/' . $nickname,
926 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
927 'title' => L10n::t('Events and Calendar'),
928 'id' => 'events-tab',
935 'label' => L10n::t('Personal Notes'),
936 'url' => System::baseUrl() . '/notes',
937 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
938 'title' => L10n::t('Only You Can See This'),
944 if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
946 'label' => L10n::t('Contacts'),
947 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
948 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
949 'title' => L10n::t('Contacts'),
950 'id' => 'viewcontacts-tab',
955 $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs];
956 Addon::callHooks('profile_tabs', $arr);
958 $tpl = get_markup_template('common_tabs.tpl');
960 return replace_macros($tpl, ['$tabs' => $arr['tabs']]);
964 * Retrieves the my_url session variable
968 public static function getMyURL()
970 if (x($_SESSION, 'my_url')) {
971 return $_SESSION['my_url'];
976 public static function zrlInit(App $a)
978 $my_url = self::getMyURL();
979 $my_url = Network::isUrlValid($my_url);
981 // Is it a DDoS attempt?
982 // The check fetches the cached value from gprobe to reduce the load for this system
983 $urlparts = parse_url($my_url);
985 $result = Cache::get('gprobe:' . $urlparts['host']);
986 if ((!is_null($result)) && (in_array($result['network'], [NETWORK_FEED, NETWORK_PHANTOM]))) {
987 logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
991 Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
992 $arr = ['zrl' => $my_url, 'url' => $a->cmd];
993 Addon::callHooks('zrl_init', $arr);
997 public static function zrl($s, $force = false)
1002 if ((!strpos($s, '/profile/')) && (!$force)) {
1005 if ($force && substr($s, -1, 1) !== '/') {
1008 $achar = strpos($s, '?') ? '&' : '?';
1009 $mine = self::getMyURL();
1010 if ($mine && !link_compare($mine, $s)) {
1011 return $s . $achar . 'zrl=' . urlencode($mine);
1017 * Get the user ID of the page owner.
1019 * Used from within PCSS themes to set theme parameters. If there's a
1020 * puid request variable, that is the "page owner" and normally their theme
1021 * settings take precedence; unless a local user sets the "always_my_theme"
1022 * system pconfig, which means they don't want to see anybody else's theme
1023 * settings except their own while on this site.
1025 * @brief Get the user ID of the page owner
1026 * @return int user ID
1028 * @note Returns local_user instead of user ID if "always_my_theme"
1031 public static function getThemeUid()
1033 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
1034 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
1035 return local_user();