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 'mod/proxy.php';
32 * @brief Returns a formatted location string from the given profile array
34 * @param array $profile Profile array (Generated from the "profile" table)
36 * @return string Location string
38 public static function formatLocation(array $profile)
42 if ($profile['locality']) {
43 $location .= $profile['locality'];
46 if ($profile['region'] && ($profile['locality'] != $profile['region'])) {
51 $location .= $profile['region'];
54 if ($profile['country-name']) {
59 $location .= $profile['country-name'];
67 * Loads a profile into the page sidebar.
69 * The function requires a writeable copy of the main App structure, and the nickname
70 * of a registered local account.
72 * If the viewer is an authenticated remote viewer, the profile displayed is the
73 * one that has been configured for his/her viewing in the Contact manager.
74 * Passing a non-zero profile ID can also allow a preview of a selected profile
77 * Profile information is placed in the App structure for later retrieval.
78 * Honours the owner's chosen theme for display.
80 * @attention Should only be run in the _init() functions of a module. That ensures that
81 * the theme is chosen before the _init() function of a theme is run, which will usually
82 * load a lot of theme-specific content
84 * @brief Loads a profile into the page sidebar.
85 * @param object $a App
86 * @param string $nickname string
87 * @param int $profile int
88 * @param array $profiledata array
89 * @param boolean $show_connect Show connect link
91 public static function load(App $a, $nickname, $profile = 0, $profiledata = [], $show_connect = true)
93 $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
95 if (!$user && !count($user) && !count($profiledata)) {
96 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
97 notice(L10n::t('Requested account is not available.') . EOL);
102 if (!x($a->page, 'aside')) {
103 $a->page['aside'] = '';
107 $a->page['aside'] .= self::sidebar($profiledata, true, $show_connect);
109 if (!DBM::is_result($user)) {
114 $pdata = self::getByNickname($nickname, $user[0]['uid'], $profile);
116 if (empty($pdata) && empty($profiledata)) {
117 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
118 notice(L10n::t('Requested profile is not available.') . EOL);
123 // fetch user tags if this isn't the default profile
125 if (!$pdata['is-default']) {
127 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
128 intval($pdata['profile_uid'])
130 if ($x && count($x)) {
131 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
135 $a->profile = $pdata;
136 $a->profile_uid = $pdata['profile_uid'];
138 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
139 $a->profile['network'] = NETWORK_DFRN;
141 $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename'];
143 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
144 $_SESSION['theme'] = $a->profile['theme'];
147 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
150 * load/reload current theme info
153 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
155 $theme_info_file = 'view/theme/' . current_theme() . '/theme.php';
156 if (file_exists($theme_info_file)) {
157 require_once $theme_info_file;
160 if (!x($a->page, 'aside')) {
161 $a->page['aside'] = '';
164 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
165 $a->page['aside'] .= replace_macros(
166 get_markup_template('profile_edlink.tpl'),
168 '$editprofile' => L10n::t('Edit profile'),
169 '$profid' => $a->profile['id']
174 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
178 * By now, the contact block isn't shown, when a different profile is given
179 * But: When this profile was on the same server, then we could display the contacts
182 $a->page['aside'] .= self::sidebar($a->profile, $block, $show_connect);
189 * Get all profile data of a local user
191 * If the viewer is an authenticated remote viewer, the profile displayed is the
192 * one that has been configured for his/her viewing in the Contact manager.
193 * Passing a non-zero profile ID can also allow a preview of a selected profile
196 * Includes all available profile data
198 * @brief Get all profile data of a local user
199 * @param string $nickname nick
200 * @param int $uid uid
201 * @param int $profile_id ID of the profile
204 public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
206 if (remote_user() && count($_SESSION['remote'])) {
207 foreach ($_SESSION['remote'] as $visitor) {
208 if ($visitor['uid'] == $uid) {
209 $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
210 if (DBM::is_result($contact)) {
211 $profile_id = $contact['profile-id'];
221 $profile = dba::fetch_first(
222 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
223 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
224 `profile`.`uid` AS `profile_uid`, `profile`.*,
225 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
227 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
228 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
229 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
234 if (!DBM::is_result($profile)) {
235 $profile = dba::fetch_first(
236 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
237 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
238 `profile`.`uid` AS `profile_uid`, `profile`.*,
239 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
241 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
242 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
243 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
252 * Formats a profile for display in the sidebar.
254 * It is very difficult to templatise the HTML completely
255 * because of all the conditional logic.
257 * @brief Formats a profile for display in the sidebar.
258 * @param array $profile
260 * @param boolean $show_connect Show connect link
262 * @return string HTML sidebar module
264 * @note Returns empty string if passed $profile is wrong type or not populated
266 * @hooks 'profile_sidebar_enter'
267 * array $profile - profile data
268 * @hooks 'profile_sidebar'
271 private static function sidebar($profile, $block = 0, $show_connect = true)
278 // This function can also use contact information in $profile
279 $is_contact = x($profile, 'cid');
281 if (!is_array($profile) && !count($profile)) {
285 $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
287 if (($profile['network'] != '') && ($profile['network'] != NETWORK_DFRN)) {
288 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
290 $profile['network_name'] = '';
293 Addon::callHooks('profile_sidebar_enter', $profile);
296 // don't show connect link to yourself
297 $connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false;
299 // don't show connect link to authenticated visitors either
300 if (remote_user() && count($_SESSION['remote'])) {
301 foreach ($_SESSION['remote'] as $visitor) {
302 if ($visitor['uid'] == $profile['uid']) {
309 if (!$show_connect) {
313 // Is the local user already connected to that user?
314 if ($connect && local_user()) {
315 if (isset($profile['url'])) {
316 $profile_url = normalise_link($profile['url']);
318 $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']);
321 if (dba::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) {
326 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect'])) {
330 $remoteconnect = null;
331 if (isset($profile['remoteconnect'])) {
332 $remoteconnect = $profile['remoteconnect'];
335 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect)) {
336 $subscribe_feed = L10n::t('Atom feed');
338 $subscribe_feed = false;
341 if (remote_user() || (self::getMyURL() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
342 $wallmessage = L10n::t('Message');
343 $wallmessage_link = 'wallmessage/' . $profile['nickname'];
347 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
348 intval($profile['uid']),
349 intval(remote_user()),
350 intval(CONTACT_IS_FRIEND)
354 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
355 intval($profile['uid']),
356 dbesc(normalise_link(self::getMyURL())),
357 intval(CONTACT_IS_FRIEND)
361 $remote_url = $r[0]['url'];
362 $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url);
363 $wallmessage_link = $message_path . base64_encode($profile['addr']);
366 $wallmessage = false;
367 $wallmessage_link = false;
370 // show edit profile to yourself
371 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
372 $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')];
374 "SELECT * FROM `profile` WHERE `uid` = %d",
379 'chg_photo' => L10n::t('Change profile photo'),
380 'cr_new' => L10n::t('Create New Profile'),
384 if (DBM::is_result($r)) {
385 foreach ($r as $rr) {
386 $profile['menu']['entries'][] = [
387 'photo' => $rr['thumb'],
389 'alt' => L10n::t('Profile Image'),
390 'profile_name' => $rr['profile-name'],
391 'isdefault' => $rr['is-default'],
392 'visibile_to_everybody' => L10n::t('visible to everybody'),
393 'edit_visibility' => L10n::t('Edit visibility'),
398 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
399 $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
401 'chg_photo' => L10n::t('Change profile photo'),
407 // Fetch the account type
408 $account_type = Contact::getAccountType($profile);
410 if (x($profile, 'address')
411 || x($profile, 'location')
412 || x($profile, 'locality')
413 || x($profile, 'region')
414 || x($profile, 'postal-code')
415 || x($profile, 'country-name')
417 $location = L10n::t('Location:');
420 $gender = x($profile, 'gender') ? L10n::t('Gender:') : false;
421 $marital = x($profile, 'marital') ? L10n::t('Status:') : false;
422 $homepage = x($profile, 'homepage') ? L10n::t('Homepage:') : false;
423 $about = x($profile, 'about') ? L10n::t('About:') : false;
424 $xmpp = x($profile, 'xmpp') ? L10n::t('XMPP:') : false;
426 if ((x($profile, 'hidewall') || $block) && !local_user() && !remote_user()) {
427 $location = $gender = $marital = $homepage = $about = false;
430 $split_name = Diaspora::splitName($profile['name']);
431 $firstname = $split_name['first'];
432 $lastname = $split_name['last'];
434 if (x($profile, 'guid')) {
436 'guid' => $profile['guid'],
437 'podloc' => System::baseUrl(),
438 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
439 'nickname' => $profile['nickname'],
440 'fullname' => $profile['name'],
441 'firstname' => $firstname,
442 'lastname' => $lastname,
443 'photo300' => $profile['contact_photo'],
444 'photo100' => $profile['contact_thumb'],
445 'photo50' => $profile['contact_micro'],
455 $contact_block = contact_block();
457 if (is_array($a->profile) && !$a->profile['hide-friends']) {
459 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
460 intval($a->profile['uid'])
462 if (DBM::is_result($r)) {
463 $updated = date('c', strtotime($r[0]['updated']));
467 "SELECT COUNT(*) AS `total` FROM `contact`
469 AND NOT `self` AND NOT `blocked` AND NOT `pending`
470 AND NOT `hidden` AND NOT `archive`
471 AND `network` IN ('%s', '%s', '%s', '')",
472 intval($profile['uid']),
474 dbesc(NETWORK_DIASPORA),
475 dbesc(NETWORK_OSTATUS)
477 if (DBM::is_result($r)) {
478 $contacts = intval($r[0]['total']);
484 foreach ($profile as $k => $v) {
485 $k = str_replace('-', '_', $k);
489 if (isset($p['about'])) {
490 $p['about'] = BBCode::convert($p['about']);
493 if (isset($p['address'])) {
494 $p['address'] = BBCode::convert($p['address']);
496 $p['address'] = BBCode::convert($p['location']);
499 if (isset($p['photo'])) {
500 $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
503 $tpl = get_markup_template('profile_vcard.tpl');
504 $o .= replace_macros($tpl, [
507 '$connect' => $connect,
508 '$remoteconnect' => $remoteconnect,
509 '$subscribe_feed' => $subscribe_feed,
510 '$wallmessage' => $wallmessage,
511 '$wallmessage_link' => $wallmessage_link,
512 '$account_type' => $account_type,
513 '$location' => $location,
514 '$gender' => $gender,
515 '$marital' => $marital,
516 '$homepage' => $homepage,
518 '$network' => L10n::t('Network:'),
519 '$contacts' => $contacts,
520 '$updated' => $updated,
521 '$diaspora' => $diaspora,
522 '$contact_block' => $contact_block,
525 $arr = ['profile' => &$profile, 'entry' => &$o];
527 Addon::callHooks('profile_sidebar', $arr);
532 public static function getBirthdays()
537 if (!local_user() || $a->is_mobile || $a->is_tablet) {
542 * $mobile_detect = new Mobile_Detect();
543 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
548 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
549 $bd_short = L10n::t('F d');
551 $cachekey = 'get_birthdays:' . local_user();
552 $r = Cache::get($cachekey);
555 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
556 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
557 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
558 ORDER BY `start` ASC ",
560 DateTimeFormat::utc('now + 6 days'),
561 DateTimeFormat::utcNow()
563 if (DBM::is_result($s)) {
564 $r = dba::inArray($s);
565 Cache::set($cachekey, $r, CACHE_HOUR);
571 if (DBM::is_result($r)) {
572 $now = strtotime('now');
576 foreach ($r as $rr) {
577 if (strlen($rr['name'])) {
580 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
584 $classtoday = $istoday ? ' birthday-today ' : '';
586 foreach ($r as &$rr) {
587 if (!strlen($rr['name'])) {
593 if (in_array($rr['cid'], $cids)) {
596 $cids[] = $rr['cid'];
598 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
600 if ($rr['network'] === NETWORK_DFRN) {
601 $url = System::baseUrl() . '/redir/' . $rr['cid'];
605 $rr['title'] = $rr['name'];
606 $rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
607 $rr['startime'] = null;
608 $rr['today'] = $today;
612 $tpl = get_markup_template('birthdays_reminder.tpl');
613 return replace_macros($tpl, [
614 '$baseurl' => System::baseUrl(),
615 '$classtoday' => $classtoday,
617 '$event_reminders' => L10n::t('Birthday Reminders'),
618 '$event_title' => L10n::t('Birthdays this week:'),
620 '$lbr' => '{', // raw brackets mess up if/endif macro processing
625 public static function getEventsReminderHTML()
630 if (!local_user() || $a->is_mobile || $a->is_tablet) {
635 * $mobile_detect = new Mobile_Detect();
636 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
641 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
647 WHERE `event`.`uid` = ?
648 AND `event`.`type` != 'birthday'
649 AND `event`.`start` < ?
650 AND `event`.`start` >= ?
654 WHERE `item`.`uid` = `event`.`uid`
655 AND `item`.`parent-uri` = `event`.`uri`
656 AND `item`.`verb` = ?
658 AND NOT `item`.`deleted`
660 ORDER BY `event`.`start` ASC",
662 DateTimeFormat::utc('now + 7 days'),
663 DateTimeFormat::utc('now - 1 days'),
669 if (DBM::is_result($s)) {
672 while ($rr = dba::fetch($s)) {
673 if (strlen($rr['name'])) {
677 $strt = DateTimeFormat::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC', 'UTC', 'Y-m-d');
678 if ($strt === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
682 $title = strip_tags(html_entity_decode(BBCode::convert($rr['summary']), ENT_QUOTES, 'UTF-8'));
684 if (strlen($title) > 35) {
685 $title = substr($title, 0, 32) . '... ';
688 $description = substr(strip_tags(BBCode::convert($rr['desc'])), 0, 32) . '... ';
690 $description = L10n::t('[No description]');
693 $strt = DateTimeFormat::convert($rr['start'], $rr['convert'] ? $a->timezone : 'UTC');
695 if (substr($strt, 0, 10) < DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
699 $today = ((substr($strt, 0, 10) === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) ? true : false);
701 $rr['title'] = $title;
702 $rr['description'] = $description;
703 $rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : '');
704 $rr['startime'] = $strt;
705 $rr['today'] = $today;
710 $classtoday = (($istoday) ? 'event-today' : '');
712 $tpl = get_markup_template('events_reminder.tpl');
713 return replace_macros($tpl, [
714 '$baseurl' => System::baseUrl(),
715 '$classtoday' => $classtoday,
716 '$count' => count($r),
717 '$event_reminders' => L10n::t('Event Reminders'),
718 '$event_title' => L10n::t('Events this week:'),
723 public static function getAdvanced(App $a)
726 $uid = $a->profile['uid'];
728 $o .= replace_macros(
729 get_markup_template('section_title.tpl'),
730 ['$title' => L10n::t('Profile')]
733 if ($a->profile['name']) {
734 $tpl = get_markup_template('profile_advanced.tpl');
738 $profile['fullname'] = [L10n::t('Full Name:'), $a->profile['name']];
740 if (Feature::isEnabled($uid, 'profile_membersince')) {
741 $profile['membersince'] = [L10n::t('Member since:'), DateTimeFormat::local($a->profile['register_date'])];
744 if ($a->profile['gender']) {
745 $profile['gender'] = [L10n::t('Gender:'), $a->profile['gender']];
748 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
749 $year_bd_format = L10n::t('j F, Y');
750 $short_bd_format = L10n::t('j F');
752 $val = day_translate(
753 intval($a->profile['dob']) ?
754 DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)
755 : DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)
758 $profile['birthday'] = [L10n::t('Birthday:'), $val];
761 if (!empty($a->profile['dob'])
762 && $a->profile['dob'] > '0001-01-01'
763 && $age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'], '')
765 $profile['age'] = [L10n::t('Age:'), $age];
768 if ($a->profile['marital']) {
769 $profile['marital'] = [L10n::t('Status:'), $a->profile['marital']];
772 /// @TODO Maybe use x() here, plus below?
773 if ($a->profile['with']) {
774 $profile['marital']['with'] = $a->profile['with'];
777 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
778 $profile['howlong'] = Temporal::getRelativeDate($a->profile['howlong'], L10n::t('for %1$d %2$s'));
781 if ($a->profile['sexual']) {
782 $profile['sexual'] = [L10n::t('Sexual Preference:'), $a->profile['sexual']];
785 if ($a->profile['homepage']) {
786 $profile['homepage'] = [L10n::t('Homepage:'), linkify($a->profile['homepage'])];
789 if ($a->profile['hometown']) {
790 $profile['hometown'] = [L10n::t('Hometown:'), linkify($a->profile['hometown'])];
793 if ($a->profile['pub_keywords']) {
794 $profile['pub_keywords'] = [L10n::t('Tags:'), $a->profile['pub_keywords']];
797 if ($a->profile['politic']) {
798 $profile['politic'] = [L10n::t('Political Views:'), $a->profile['politic']];
801 if ($a->profile['religion']) {
802 $profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
805 if ($txt = prepare_text($a->profile['about'])) {
806 $profile['about'] = [L10n::t('About:'), $txt];
809 if ($txt = prepare_text($a->profile['interest'])) {
810 $profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
813 if ($txt = prepare_text($a->profile['likes'])) {
814 $profile['likes'] = [L10n::t('Likes:'), $txt];
817 if ($txt = prepare_text($a->profile['dislikes'])) {
818 $profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
821 if ($txt = prepare_text($a->profile['contact'])) {
822 $profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
825 if ($txt = prepare_text($a->profile['music'])) {
826 $profile['music'] = [L10n::t('Musical interests:'), $txt];
829 if ($txt = prepare_text($a->profile['book'])) {
830 $profile['book'] = [L10n::t('Books, literature:'), $txt];
833 if ($txt = prepare_text($a->profile['tv'])) {
834 $profile['tv'] = [L10n::t('Television:'), $txt];
837 if ($txt = prepare_text($a->profile['film'])) {
838 $profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
841 if ($txt = prepare_text($a->profile['romance'])) {
842 $profile['romance'] = [L10n::t('Love/Romance:'), $txt];
845 if ($txt = prepare_text($a->profile['work'])) {
846 $profile['work'] = [L10n::t('Work/employment:'), $txt];
849 if ($txt = prepare_text($a->profile['education'])) {
850 $profile['education'] = [L10n::t('School/education:'), $txt];
853 //show subcribed forum if it is enabled in the usersettings
854 if (Feature::isEnabled($uid, 'forumlist_profile')) {
855 $profile['forumlist'] = [L10n::t('Forums:'), ForumManager::profileAdvanced($uid)];
858 if ($a->profile['uid'] == local_user()) {
859 $profile['edit'] = [System::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
862 return replace_macros($tpl, [
863 '$title' => L10n::t('Profile'),
864 '$basic' => L10n::t('Basic'),
865 '$advanced' => L10n::t('Advanced'),
866 '$profile' => $profile
873 public static function getTabs($a, $is_owner = false, $nickname = null)
875 if (is_null($nickname)) {
876 $nickname = $a->user['nickname'];
880 if (x($_GET, 'tab')) {
881 $tab = notags(trim($_GET['tab']));
884 $url = System::baseUrl() . '/profile/' . $nickname;
888 'label' => L10n::t('Status'),
890 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
891 'title' => L10n::t('Status Messages and Posts'),
892 'id' => 'status-tab',
896 'label' => L10n::t('Profile'),
897 'url' => $url . '/?tab=profile',
898 'sel' => $tab == 'profile' ? 'active' : '',
899 'title' => L10n::t('Profile Details'),
900 'id' => 'profile-tab',
904 'label' => L10n::t('Photos'),
905 'url' => System::baseUrl() . '/photos/' . $nickname,
906 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
907 'title' => L10n::t('Photo Albums'),
912 'label' => L10n::t('Videos'),
913 'url' => System::baseUrl() . '/videos/' . $nickname,
914 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
915 'title' => L10n::t('Videos'),
921 // the calendar link for the full featured events calendar
922 if ($is_owner && $a->theme_events_in_profile) {
924 'label' => L10n::t('Events'),
925 'url' => System::baseUrl() . '/events',
926 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
927 'title' => L10n::t('Events and Calendar'),
928 'id' => 'events-tab',
931 // if the user is not the owner of the calendar we only show a calendar
932 // with the public events of the calendar owner
933 } elseif (!$is_owner) {
935 'label' => L10n::t('Events'),
936 'url' => System::baseUrl() . '/cal/' . $nickname,
937 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
938 'title' => L10n::t('Events and Calendar'),
939 'id' => 'events-tab',
946 'label' => L10n::t('Personal Notes'),
947 'url' => System::baseUrl() . '/notes',
948 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
949 'title' => L10n::t('Only You Can See This'),
955 if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
957 'label' => L10n::t('Contacts'),
958 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
959 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
960 'title' => L10n::t('Contacts'),
961 'id' => 'viewcontacts-tab',
966 $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs];
967 Addon::callHooks('profile_tabs', $arr);
969 $tpl = get_markup_template('common_tabs.tpl');
971 return replace_macros($tpl, ['$tabs' => $arr['tabs']]);
975 * Retrieves the my_url session variable
979 public static function getMyURL()
981 if (x($_SESSION, 'my_url')) {
982 return $_SESSION['my_url'];
987 public static function zrlInit(App $a)
989 $my_url = self::getMyURL();
990 $my_url = Network::isUrlValid($my_url);
992 // Is it a DDoS attempt?
993 // The check fetches the cached value from gprobe to reduce the load for this system
994 $urlparts = parse_url($my_url);
996 $result = Cache::get('gprobe:' . $urlparts['host']);
997 if ((!is_null($result)) && (in_array($result['network'], [NETWORK_FEED, NETWORK_PHANTOM]))) {
998 logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
1002 Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
1003 $arr = ['zrl' => $my_url, 'url' => $a->cmd];
1004 Addon::callHooks('zrl_init', $arr);
1008 public static function zrl($s, $force = false)
1013 if ((!strpos($s, '/profile/')) && (!$force)) {
1016 if ($force && substr($s, -1, 1) !== '/') {
1019 $achar = strpos($s, '?') ? '&' : '?';
1020 $mine = self::getMyURL();
1021 if ($mine && !link_compare($mine, $s)) {
1022 return $s . $achar . 'zrl=' . urlencode($mine);
1028 * Get the user ID of the page owner.
1030 * Used from within PCSS themes to set theme parameters. If there's a
1031 * puid request variable, that is the "page owner" and normally their theme
1032 * settings take precedence; unless a local user sets the "always_my_theme"
1033 * system pconfig, which means they don't want to see anybody else's theme
1034 * settings except their own while on this site.
1036 * @brief Get the user ID of the page owner
1037 * @return int user ID
1039 * @note Returns local_user instead of user ID if "always_my_theme"
1042 public static function getThemeUid()
1044 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
1045 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
1046 return local_user();