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;
23 require_once 'include/dba.php';
24 require_once 'include/bbcode.php';
25 require_once 'mod/proxy.php';
30 * @brief Returns a formatted location string from the given profile array
32 * @param array $profile Profile array (Generated from the "profile" table)
34 * @return string Location string
36 public static function formatLocation(array $profile)
40 if ($profile['locality']) {
41 $location .= $profile['locality'];
44 if ($profile['region'] && ($profile['locality'] != $profile['region'])) {
49 $location .= $profile['region'];
52 if ($profile['country-name']) {
57 $location .= $profile['country-name'];
65 * Loads a profile into the page sidebar.
67 * The function requires a writeable copy of the main App structure, and the nickname
68 * of a registered local account.
70 * If the viewer is an authenticated remote viewer, the profile displayed is the
71 * one that has been configured for his/her viewing in the Contact manager.
72 * Passing a non-zero profile ID can also allow a preview of a selected profile
75 * Profile information is placed in the App structure for later retrieval.
76 * Honours the owner's chosen theme for display.
78 * @attention Should only be run in the _init() functions of a module. That ensures that
79 * the theme is chosen before the _init() function of a theme is run, which will usually
80 * load a lot of theme-specific content
82 * @brief Loads a profile into the page sidebar.
83 * @param object $a App
84 * @param string $nickname string
85 * @param int $profile int
86 * @param array $profiledata array
87 * @param boolean $show_connect Show connect link
89 public static function load(App $a, $nickname, $profile = 0, $profiledata = [], $show_connect = true)
91 $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
93 if (!$user && !count($user) && !count($profiledata)) {
94 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
95 notice(L10n::t('Requested account is not available.') . EOL);
100 if (!x($a->page, 'aside')) {
101 $a->page['aside'] = '';
105 $a->page['aside'] .= self::sidebar($profiledata, true, $show_connect);
107 if (!DBM::is_result($user)) {
112 $pdata = self::getByNickname($nickname, $user[0]['uid'], $profile);
114 if (empty($pdata) && empty($profiledata)) {
115 logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
116 notice(L10n::t('Requested profile is not available.') . EOL);
121 // fetch user tags if this isn't the default profile
123 if (!$pdata['is-default']) {
125 "SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
126 intval($pdata['profile_uid'])
128 if ($x && count($x)) {
129 $pdata['pub_keywords'] = $x[0]['pub_keywords'];
133 $a->profile = $pdata;
134 $a->profile_uid = $pdata['profile_uid'];
136 $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme');
137 $a->profile['network'] = NETWORK_DFRN;
139 $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename'];
141 if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
142 $_SESSION['theme'] = $a->profile['theme'];
145 $_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
148 * load/reload current theme info
151 $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
153 $theme_info_file = 'view/theme/' . current_theme() . '/theme.php';
154 if (file_exists($theme_info_file)) {
155 require_once $theme_info_file;
158 if (!x($a->page, 'aside')) {
159 $a->page['aside'] = '';
162 if (local_user() && local_user() == $a->profile['uid'] && $profiledata) {
163 $a->page['aside'] .= replace_macros(
164 get_markup_template('profile_edlink.tpl'),
166 '$editprofile' => L10n::t('Edit profile'),
167 '$profid' => $a->profile['id']
172 $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
176 * By now, the contact block isn't shown, when a different profile is given
177 * But: When this profile was on the same server, then we could display the contacts
180 $a->page['aside'] .= self::sidebar($a->profile, $block, $show_connect);
187 * Get all profile data of a local user
189 * If the viewer is an authenticated remote viewer, the profile displayed is the
190 * one that has been configured for his/her viewing in the Contact manager.
191 * Passing a non-zero profile ID can also allow a preview of a selected profile
194 * Includes all available profile data
196 * @brief Get all profile data of a local user
197 * @param string $nickname nick
198 * @param int $uid uid
199 * @param int $profile_id ID of the profile
202 public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
204 if (remote_user() && count($_SESSION['remote'])) {
205 foreach ($_SESSION['remote'] as $visitor) {
206 if ($visitor['uid'] == $uid) {
207 $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
208 if (DBM::is_result($contact)) {
209 $profile_id = $contact['profile-id'];
219 $profile = dba::fetch_first(
220 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
221 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
222 `profile`.`uid` AS `profile_uid`, `profile`.*,
223 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
225 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
226 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
227 WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
232 if (!DBM::is_result($profile)) {
233 $profile = dba::fetch_first(
234 "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
235 `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
236 `profile`.`uid` AS `profile_uid`, `profile`.*,
237 `contact`.`avatar-date` AS picdate, `contact`.`addr`, `contact`.`url`, `user`.*
239 INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` AND `contact`.`self`
240 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
241 WHERE `user`.`nickname` = ? AND `profile`.`is-default` LIMIT 1",
250 * Formats a profile for display in the sidebar.
252 * It is very difficult to templatise the HTML completely
253 * because of all the conditional logic.
255 * @brief Formats a profile for display in the sidebar.
256 * @param array $profile
258 * @param boolean $show_connect Show connect link
260 * @return HTML string suitable for sidebar inclusion
262 * @note Returns empty string if passed $profile is wrong type or not populated
264 * @hooks 'profile_sidebar_enter'
265 * array $profile - profile data
266 * @hooks 'profile_sidebar'
269 private static function sidebar($profile, $block = 0, $show_connect = true)
276 // This function can also use contact information in $profile
277 $is_contact = x($profile, 'cid');
279 if (!is_array($profile) && !count($profile)) {
283 $profile['picdate'] = urlencode(defaults($profile, 'picdate', ''));
285 if (($profile['network'] != '') && ($profile['network'] != NETWORK_DFRN)) {
286 $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
288 $profile['network_name'] = '';
291 Addon::callHooks('profile_sidebar_enter', $profile);
294 // don't show connect link to yourself
295 $connect = $profile['uid'] != local_user() ? L10n::t('Connect') : false;
297 // don't show connect link to authenticated visitors either
298 if (remote_user() && count($_SESSION['remote'])) {
299 foreach ($_SESSION['remote'] as $visitor) {
300 if ($visitor['uid'] == $profile['uid']) {
307 if (!$show_connect) {
311 // Is the local user already connected to that user?
312 if ($connect && local_user()) {
313 if (isset($profile['url'])) {
314 $profile_url = normalise_link($profile['url']);
316 $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']);
319 if (dba::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) {
324 if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect'])) {
328 $remoteconnect = null;
329 if (isset($profile['remoteconnect'])) {
330 $remoteconnect = $profile['remoteconnect'];
333 if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect)) {
334 $subscribe_feed = L10n::t('Atom feed');
336 $subscribe_feed = false;
339 if (remote_user() || (self::getMyURL() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
340 $wallmessage = L10n::t('Message');
341 $wallmessage_link = 'wallmessage/' . $profile['nickname'];
345 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d",
346 intval($profile['uid']),
347 intval(remote_user()),
348 intval(CONTACT_IS_FRIEND)
352 "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
353 intval($profile['uid']),
354 dbesc(normalise_link(self::getMyURL())),
355 intval(CONTACT_IS_FRIEND)
359 $remote_url = $r[0]['url'];
360 $message_path = preg_replace('=(.*)/profile/(.*)=ism', '$1/message/new/', $remote_url);
361 $wallmessage_link = $message_path . base64_encode($profile['addr']);
364 $wallmessage = false;
365 $wallmessage_link = false;
368 // show edit profile to yourself
369 if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) {
370 $profile['edit'] = [System::baseUrl() . '/profiles', L10n::t('Profiles'), '', L10n::t('Manage/edit profiles')];
372 "SELECT * FROM `profile` WHERE `uid` = %d",
377 'chg_photo' => L10n::t('Change profile photo'),
378 'cr_new' => L10n::t('Create New Profile'),
382 if (DBM::is_result($r)) {
383 foreach ($r as $rr) {
384 $profile['menu']['entries'][] = [
385 'photo' => $rr['thumb'],
387 'alt' => L10n::t('Profile Image'),
388 'profile_name' => $rr['profile-name'],
389 'isdefault' => $rr['is-default'],
390 'visibile_to_everybody' => L10n::t('visible to everybody'),
391 'edit_visibility' => L10n::t('Edit visibility'),
396 if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) {
397 $profile['edit'] = [System::baseUrl() . '/profiles/' . $profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
399 'chg_photo' => L10n::t('Change profile photo'),
405 // Fetch the account type
406 $account_type = Contact::getAccountType($profile);
408 if (x($profile, 'address')
409 || x($profile, 'location')
410 || x($profile, 'locality')
411 || x($profile, 'region')
412 || x($profile, 'postal-code')
413 || x($profile, 'country-name')
415 $location = L10n::t('Location:');
418 $gender = x($profile, 'gender') ? L10n::t('Gender:') : false;
419 $marital = x($profile, 'marital') ? L10n::t('Status:') : false;
420 $homepage = x($profile, 'homepage') ? L10n::t('Homepage:') : false;
421 $about = x($profile, 'about') ? L10n::t('About:') : false;
422 $xmpp = x($profile, 'xmpp') ? L10n::t('XMPP:') : false;
424 if ((x($profile, 'hidewall') || $block) && !local_user() && !remote_user()) {
425 $location = $gender = $marital = $homepage = $about = false;
428 $split_name = Diaspora::splitName($profile['name']);
429 $firstname = $split_name['first'];
430 $lastname = $split_name['last'];
432 if (x($profile, 'guid')) {
434 'guid' => $profile['guid'],
435 'podloc' => System::baseUrl(),
436 'searchable' => (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ),
437 'nickname' => $profile['nickname'],
438 'fullname' => $profile['name'],
439 'firstname' => $firstname,
440 'lastname' => $lastname,
441 'photo300' => $profile['contact_photo'],
442 'photo100' => $profile['contact_thumb'],
443 'photo50' => $profile['contact_micro'],
453 $contact_block = contact_block();
455 if (is_array($a->profile) && !$a->profile['hide-friends']) {
457 "SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
458 intval($a->profile['uid'])
460 if (DBM::is_result($r)) {
461 $updated = date('c', strtotime($r[0]['updated']));
465 "SELECT COUNT(*) AS `total` FROM `contact`
467 AND NOT `self` AND NOT `blocked` AND NOT `pending`
468 AND NOT `hidden` AND NOT `archive`
469 AND `network` IN ('%s', '%s', '%s', '')",
470 intval($profile['uid']),
472 dbesc(NETWORK_DIASPORA),
473 dbesc(NETWORK_OSTATUS)
475 if (DBM::is_result($r)) {
476 $contacts = intval($r[0]['total']);
482 foreach ($profile as $k => $v) {
483 $k = str_replace('-', '_', $k);
487 if (isset($p['about'])) {
488 $p['about'] = bbcode($p['about']);
491 if (isset($p['address'])) {
492 $p['address'] = bbcode($p['address']);
494 $p['address'] = bbcode($p['location']);
497 if (isset($p['photo'])) {
498 $p['photo'] = proxy_url($p['photo'], false, PROXY_SIZE_SMALL);
501 $tpl = get_markup_template('profile_vcard.tpl');
502 $o .= replace_macros($tpl, [
505 '$connect' => $connect,
506 '$remoteconnect' => $remoteconnect,
507 '$subscribe_feed' => $subscribe_feed,
508 '$wallmessage' => $wallmessage,
509 '$wallmessage_link' => $wallmessage_link,
510 '$account_type' => $account_type,
511 '$location' => $location,
512 '$gender' => $gender,
513 '$marital' => $marital,
514 '$homepage' => $homepage,
516 '$network' => L10n::t('Network:'),
517 '$contacts' => $contacts,
518 '$updated' => $updated,
519 '$diaspora' => $diaspora,
520 '$contact_block' => $contact_block,
523 $arr = ['profile' => &$profile, 'entry' => &$o];
525 Addon::callHooks('profile_sidebar', $arr);
530 public static function getBirthdays()
535 if (!local_user() || $a->is_mobile || $a->is_tablet) {
540 * $mobile_detect = new Mobile_Detect();
541 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
546 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
547 $bd_short = L10n::t('F d');
549 $cachekey = 'get_birthdays:' . local_user();
550 $r = Cache::get($cachekey);
553 "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
554 INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
555 WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
556 ORDER BY `start` ASC ",
558 datetime_convert('UTC', 'UTC', 'now + 6 days'),
559 datetime_convert('UTC', 'UTC', 'now')
561 if (DBM::is_result($s)) {
562 $r = dba::inArray($s);
563 Cache::set($cachekey, $r, CACHE_HOUR);
566 if (DBM::is_result($r)) {
568 $now = strtotime('now');
572 foreach ($r as $rr) {
573 if (strlen($rr['name'])) {
576 if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) {
580 $classtoday = $istoday ? ' birthday-today ' : '';
582 foreach ($r as &$rr) {
583 if (!strlen($rr['name'])) {
589 if (in_array($rr['cid'], $cids)) {
592 $cids[] = $rr['cid'];
594 $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
596 if ($rr['network'] === NETWORK_DFRN) {
597 $url = System::baseUrl() . '/redir/' . $rr['cid'];
601 $rr['title'] = $rr['name'];
602 $rr['date'] = day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
603 $rr['startime'] = null;
604 $rr['today'] = $today;
608 $tpl = get_markup_template('birthdays_reminder.tpl');
609 return replace_macros($tpl, [
610 '$baseurl' => System::baseUrl(),
611 '$classtoday' => $classtoday,
613 '$event_reminders' => L10n::t('Birthday Reminders'),
614 '$event_title' => L10n::t('Birthdays this week:'),
616 '$lbr' => '{', // raw brackets mess up if/endif macro processing
621 public static function getEvents()
623 require_once 'include/bbcode.php';
627 if (!local_user() || $a->is_mobile || $a->is_tablet) {
632 * $mobile_detect = new Mobile_Detect();
633 * $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
638 $bd_format = L10n::t('g A l F d'); // 8 AM Friday January 18
642 "SELECT `event`.* FROM `event`
643 WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ?
644 ORDER BY `start` ASC ",
646 datetime_convert('UTC', 'UTC', 'now + 7 days'),
647 datetime_convert('UTC', 'UTC', 'now - 1 days')
652 if (DBM::is_result($s)) {
655 while ($rr = dba::fetch($s)) {
656 if (strlen($rr['name'])) {
660 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
661 if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
665 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
667 if (strlen($title) > 35) {
668 $title = substr($title, 0, 32) . '... ';
671 $description = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
673 $description = L10n::t('[No description]');
676 $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
678 if (substr($strt, 0, 10) < datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
682 $today = ((substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) ? true : false);
684 $rr['title'] = $title;
685 $rr['description'] = $description;
686 $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : '');
687 $rr['startime'] = $strt;
688 $rr['today'] = $today;
693 $classtoday = (($istoday) ? 'event-today' : '');
695 $tpl = get_markup_template('events_reminder.tpl');
696 return replace_macros($tpl, [
697 '$baseurl' => System::baseUrl(),
698 '$classtoday' => $classtoday,
699 '$count' => count($r),
700 '$event_reminders' => L10n::t('Event Reminders'),
701 '$event_title' => L10n::t('Events this week:'),
706 public static function getAdvanced(App $a)
709 $uid = $a->profile['uid'];
711 $o .= replace_macros(
712 get_markup_template('section_title.tpl'),
713 ['$title' => L10n::t('Profile')]
716 if ($a->profile['name']) {
717 $tpl = get_markup_template('profile_advanced.tpl');
721 $profile['fullname'] = [L10n::t('Full Name:'), $a->profile['name']];
723 if ($a->profile['gender']) {
724 $profile['gender'] = [L10n::t('Gender:'), $a->profile['gender']];
727 if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
728 $year_bd_format = L10n::t('j F, Y');
729 $short_bd_format = L10n::t('j F');
731 $val = intval($a->profile['dob']) ?
732 day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format))
733 : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format));
735 $profile['birthday'] = [L10n::t('Birthday:'), $val];
738 if (!empty($a->profile['dob'])
739 && $a->profile['dob'] > '0001-01-01'
740 && $age = age($a->profile['dob'], $a->profile['timezone'], '')
742 $profile['age'] = [L10n::t('Age:'), $age];
745 if ($a->profile['marital']) {
746 $profile['marital'] = [L10n::t('Status:'), $a->profile['marital']];
749 /// @TODO Maybe use x() here, plus below?
750 if ($a->profile['with']) {
751 $profile['marital']['with'] = $a->profile['with'];
754 if (strlen($a->profile['howlong']) && $a->profile['howlong'] >= NULL_DATE) {
755 $profile['howlong'] = relative_date($a->profile['howlong'], L10n::t('for %1$d %2$s'));
758 if ($a->profile['sexual']) {
759 $profile['sexual'] = [L10n::t('Sexual Preference:'), $a->profile['sexual']];
762 if ($a->profile['homepage']) {
763 $profile['homepage'] = [L10n::t('Homepage:'), linkify($a->profile['homepage'])];
766 if ($a->profile['hometown']) {
767 $profile['hometown'] = [L10n::t('Hometown:'), linkify($a->profile['hometown'])];
770 if ($a->profile['pub_keywords']) {
771 $profile['pub_keywords'] = [L10n::t('Tags:'), $a->profile['pub_keywords']];
774 if ($a->profile['politic']) {
775 $profile['politic'] = [L10n::t('Political Views:'), $a->profile['politic']];
778 if ($a->profile['religion']) {
779 $profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
782 if ($txt = prepare_text($a->profile['about'])) {
783 $profile['about'] = [L10n::t('About:'), $txt];
786 if ($txt = prepare_text($a->profile['interest'])) {
787 $profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
790 if ($txt = prepare_text($a->profile['likes'])) {
791 $profile['likes'] = [L10n::t('Likes:'), $txt];
794 if ($txt = prepare_text($a->profile['dislikes'])) {
795 $profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
798 if ($txt = prepare_text($a->profile['contact'])) {
799 $profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
802 if ($txt = prepare_text($a->profile['music'])) {
803 $profile['music'] = [L10n::t('Musical interests:'), $txt];
806 if ($txt = prepare_text($a->profile['book'])) {
807 $profile['book'] = [L10n::t('Books, literature:'), $txt];
810 if ($txt = prepare_text($a->profile['tv'])) {
811 $profile['tv'] = [L10n::t('Television:'), $txt];
814 if ($txt = prepare_text($a->profile['film'])) {
815 $profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
818 if ($txt = prepare_text($a->profile['romance'])) {
819 $profile['romance'] = [L10n::t('Love/Romance:'), $txt];
822 if ($txt = prepare_text($a->profile['work'])) {
823 $profile['work'] = [L10n::t('Work/employment:'), $txt];
826 if ($txt = prepare_text($a->profile['education'])) {
827 $profile['education'] = [L10n::t('School/education:'), $txt];
830 //show subcribed forum if it is enabled in the usersettings
831 if (Feature::isEnabled($uid, 'forumlist_profile')) {
832 $profile['forumlist'] = [L10n::t('Forums:'), ForumManager::profileAdvanced($uid)];
835 if ($a->profile['uid'] == local_user()) {
836 $profile['edit'] = [System::baseUrl() . '/profiles/' . $a->profile['id'], L10n::t('Edit profile'), '', L10n::t('Edit profile')];
839 return replace_macros($tpl, [
840 '$title' => L10n::t('Profile'),
841 '$basic' => L10n::t('Basic'),
842 '$advanced' => L10n::t('Advanced'),
843 '$profile' => $profile
850 public static function getTabs($a, $is_owner = false, $nickname = null)
852 if (is_null($nickname)) {
853 $nickname = $a->user['nickname'];
857 if (x($_GET, 'tab')) {
858 $tab = notags(trim($_GET['tab']));
861 $url = System::baseUrl() . '/profile/' . $nickname;
865 'label' => L10n::t('Status'),
867 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
868 'title' => L10n::t('Status Messages and Posts'),
869 'id' => 'status-tab',
873 'label' => L10n::t('Profile'),
874 'url' => $url . '/?tab=profile',
875 'sel' => $tab == 'profile' ? 'active' : '',
876 'title' => L10n::t('Profile Details'),
877 'id' => 'profile-tab',
881 'label' => L10n::t('Photos'),
882 'url' => System::baseUrl() . '/photos/' . $nickname,
883 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
884 'title' => L10n::t('Photo Albums'),
889 'label' => L10n::t('Videos'),
890 'url' => System::baseUrl() . '/videos/' . $nickname,
891 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
892 'title' => L10n::t('Videos'),
898 // the calendar link for the full featured events calendar
899 if ($is_owner && $a->theme_events_in_profile) {
901 'label' => L10n::t('Events'),
902 'url' => System::baseUrl() . '/events',
903 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
904 'title' => L10n::t('Events and Calendar'),
905 'id' => 'events-tab',
908 // if the user is not the owner of the calendar we only show a calendar
909 // with the public events of the calendar owner
910 } elseif (!$is_owner) {
912 'label' => L10n::t('Events'),
913 'url' => System::baseUrl() . '/cal/' . $nickname,
914 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
915 'title' => L10n::t('Events and Calendar'),
916 'id' => 'events-tab',
923 'label' => L10n::t('Personal Notes'),
924 'url' => System::baseUrl() . '/notes',
925 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
926 'title' => L10n::t('Only You Can See This'),
932 if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
934 'label' => L10n::t('Contacts'),
935 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
936 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
937 'title' => L10n::t('Contacts'),
938 'id' => 'viewcontacts-tab',
943 $arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs];
944 Addon::callHooks('profile_tabs', $arr);
946 $tpl = get_markup_template('common_tabs.tpl');
948 return replace_macros($tpl, ['$tabs' => $arr['tabs']]);
952 * Retrieves the my_url session variable
956 public static function getMyURL()
958 if (x($_SESSION, 'my_url')) {
959 return $_SESSION['my_url'];
964 public static function zrlInit(App $a)
966 $my_url = self::getMyURL();
967 $my_url = Network::isUrlValid($my_url);
969 // Is it a DDoS attempt?
970 // The check fetches the cached value from gprobe to reduce the load for this system
971 $urlparts = parse_url($my_url);
973 $result = Cache::get('gprobe:' . $urlparts['host']);
974 if ((!is_null($result)) && (in_array($result['network'], [NETWORK_FEED, NETWORK_PHANTOM]))) {
975 logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
979 Worker::add(PRIORITY_LOW, 'GProbe', $my_url);
980 $arr = ['zrl' => $my_url, 'url' => $a->cmd];
981 Addon::callHooks('zrl_init', $arr);
985 public static function zrl($s, $force = false)
990 if ((!strpos($s, '/profile/')) && (!$force)) {
993 if ($force && substr($s, -1, 1) !== '/') {
996 $achar = strpos($s, '?') ? '&' : '?';
997 $mine = self::getMyURL();
998 if ($mine && !link_compare($mine, $s)) {
999 return $s . $achar . 'zrl=' . urlencode($mine);
1005 * Get the user ID of the page owner.
1007 * Used from within PCSS themes to set theme parameters. If there's a
1008 * puid request variable, that is the "page owner" and normally their theme
1009 * settings take precedence; unless a local user sets the "always_my_theme"
1010 * system pconfig, which means they don't want to see anybody else's theme
1011 * settings except their own while on this site.
1013 * @brief Get the user ID of the page owner
1014 * @return int user ID
1016 * @note Returns local_user instead of user ID if "always_my_theme"
1019 public static function getThemeUid()
1021 $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
1022 if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
1023 return local_user();