X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FProfile%2FProfile.php;h=2c680d446785fd0cf3988e3ff6928f03bb3a7599;hb=ae76fa1174f56e3d68473cf2a4b606838b514521;hp=5ed341a8a81a7001bb9609d237bca19508096333;hpb=097620b62799c96d610d73410ec07a6b8cdf82f0;p=friendica.git diff --git a/src/Module/Profile/Profile.php b/src/Module/Profile/Profile.php index 5ed341a8a8..2c680d4467 100644 --- a/src/Module/Profile/Profile.php +++ b/src/Module/Profile/Profile.php @@ -1,6 +1,6 @@ $parameters['nickname']]); + $user = DBA::selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'], 'account_removed' => false]); if (DBA::isResult($user)) { - // The function returns an empty array when the account is removed, expired or blocked - $data = ActivityPub\Transmitter::getProfile($user['uid']); - if (!empty($data)) { + try { + $data = ActivityPub\Transmitter::getProfile($user['uid']); + header('Access-Control-Allow-Origin: *'); + header('Cache-Control: max-age=23200, stale-while-revalidate=23200'); System::jsonExit($data, 'application/activity+json'); + } catch (HTTPException\NotFoundException $e) { + System::jsonError(404, ['error' => 'Record not found']); } } - if (DBA::exists('userd', ['username' => $parameters['nickname']])) { + if (DBA::exists('userd', ['username' => $this->parameters['nickname']])) { // Known deleted user - $data = ActivityPub\Transmitter::getDeletedUser($parameters['nickname']); + $data = ActivityPub\Transmitter::getDeletedUser($this->parameters['nickname']); System::jsonError(410, $data); } else { @@ -70,119 +72,127 @@ class Profile extends BaseProfile } } - public static function content(array $parameters = []) + protected function content(array $request = []): string { $a = DI::app(); - ProfileModel::load($a, $parameters['nickname']); - - if (!$a->profile) { + $profile = ProfileModel::load($a, $this->parameters['nickname'] ?? ''); + if (!$profile) { throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found.')); } - $remote_contact_id = Session::getRemoteContactID($a->profile_uid); + $remote_contact_id = DI::userSession()->getRemoteContactID($profile['uid']); - if (DI::config()->get('system', 'block_public') && !local_user() && !$remote_contact_id) { + if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) { return Login::form(); } - $is_owner = local_user() == $a->profile_uid; - - if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) { - throw new HTTPException\ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.')); + if (!empty($profile['hidewall']) && !DI::userSession()->isAuthenticated()) { + $this->baseUrl->redirect('profile/' . $profile['nickname'] . '/restricted'); } - if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) { + if (!empty($profile['page-flags']) && $profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) { DI::page()['htmlhead'] .= '' . "\n"; } - DI::page()['htmlhead'] .= self::buildHtmlHead($a->profile, $parameters['nickname'], $remote_contact_id); + DI::page()['htmlhead'] .= self::buildHtmlHead($profile, $this->parameters['nickname'], $remote_contact_id); Nav::setSelected('home'); - $is_owner = local_user() == $a->profile['uid']; - $o = self::getTabsHTML($a, 'profile', $is_owner, $a->profile['nickname']); - - if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) { - notice(DI::l10n()->t('Access to this profile has been restricted.')); - return ''; - } + $is_owner = DI::userSession()->getLocalUserId() == $profile['uid']; + $o = self::getTabsHTML('profile', $is_owner, $profile['nickname'], $profile['hide-friends']); $view_as_contacts = []; $view_as_contact_id = 0; + $view_as_contact_alert = ''; if ($is_owner) { $view_as_contact_id = intval($_GET['viewas'] ?? 0); $view_as_contacts = Contact::selectToArray(['id', 'name'], [ - 'uid' => local_user(), + 'uid' => DI::userSession()->getLocalUserId(), 'rel' => [Contact::FOLLOWER, Contact::SHARING, Contact::FRIEND], 'network' => Protocol::DFRN, 'blocked' => false, ]); + $view_as_contact_ids = array_column($view_as_contacts, 'id'); + // User manually provided a contact ID they aren't privy to, silently defaulting to their own view - if (!in_array($view_as_contact_id, array_column($view_as_contacts, 'id'))) { + if (!in_array($view_as_contact_id, $view_as_contact_ids)) { $view_as_contact_id = 0; } + + if (($key = array_search($view_as_contact_id, $view_as_contact_ids)) !== false) { + $view_as_contact_alert = DI::l10n()->t( + 'You\'re currently viewing your profile as %s Cancel', + htmlentities($view_as_contacts[$key]['name'], ENT_COMPAT, 'UTF-8'), + 'profile/' . $this->parameters['nickname'] . '/profile' + ); + } } $basic_fields = []; - $basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $a->profile['name']); + $basic_fields += self::buildField('fullname', DI::l10n()->t('Full Name:'), $profile['name']); - if (Feature::isEnabled($a->profile_uid, 'profile_membersince')) { + if (Feature::isEnabled($profile['uid'], 'profile_membersince')) { $basic_fields += self::buildField( 'membersince', DI::l10n()->t('Member since:'), - DateTimeFormat::local($a->profile['register_date']) + DateTimeFormat::local($profile['register_date']) ); } - if (!empty($a->profile['dob']) && $a->profile['dob'] > DBA::NULL_DATE) { + if (!empty($profile['dob']) && $profile['dob'] > DBA::NULL_DATE) { $year_bd_format = DI::l10n()->t('j F, Y'); $short_bd_format = DI::l10n()->t('j F'); $dob = DI::l10n()->getDay( - intval($a->profile['dob']) ? - DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format) - : DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format) + intval($profile['dob']) ? + DateTimeFormat::utc($profile['dob'] . ' 00:00 +00:00', $year_bd_format) + : DateTimeFormat::utc('2001-' . substr($profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format) ); $basic_fields += self::buildField('dob', DI::l10n()->t('Birthday:'), $dob); - if ($age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'])) { + if ($age = Temporal::getAgeByTimezone($profile['dob'], $profile['timezone'])) { $basic_fields += self::buildField('age', DI::l10n()->t('Age: '), DI::l10n()->tt('%d year old', '%d years old', $age)); } } - if ($a->profile['pdesc']) { - $basic_fields += self::buildField('pdesc', DI::l10n()->t('Description:'), HTML::toLink($a->profile['pdesc'])); + if ($profile['about']) { + $basic_fields += self::buildField('about', DI::l10n()->t('Description:'), BBCode::convertForUriId($profile['uri-id'], $profile['about'])); + } + + if ($profile['xmpp']) { + $basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $profile['xmpp']); } - if ($a->profile['xmpp']) { - $basic_fields += self::buildField('xmpp', DI::l10n()->t('XMPP:'), $a->profile['xmpp']); + if ($profile['matrix']) { + $basic_fields += self::buildField('matrix', DI::l10n()->t('Matrix:'), $profile['matrix']); } - if ($a->profile['homepage']) { - $basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($a->profile['homepage'])); + if ($profile['homepage']) { + $basic_fields += self::buildField('homepage', DI::l10n()->t('Homepage:'), HTML::toLink($profile['homepage'])); } if ( - $a->profile['address'] - || $a->profile['locality'] - || $a->profile['postal-code'] - || $a->profile['region'] - || $a->profile['country-name'] + $profile['address'] + || $profile['locality'] + || $profile['postal-code'] + || $profile['region'] + || $profile['country-name'] ) { - $basic_fields += self::buildField('location', DI::l10n()->t('Location:'), ProfileModel::formatLocation($a->profile)); + $basic_fields += self::buildField('location', DI::l10n()->t('Location:'), ProfileModel::formatLocation($profile)); } - if ($a->profile['pub_keywords']) { + if ($profile['pub_keywords']) { $tags = []; - foreach (explode(',', $a->profile['pub_keywords']) as $tag_label) { + // Separator is defined in Module\Settings\Profile\Index::cleanKeywords + foreach (explode(', ', $profile['pub_keywords']) as $tag_label) { $tags[] = [ 'url' => '/search?tag=' . $tag_label, - 'label' => Term::TAG_CHARACTER[Term::HASHTAG] . $tag_label, + 'label' => Tag::TAG_CHARACTER[Tag::HASHTAG] . $tag_label, ]; } @@ -195,47 +205,55 @@ class Profile extends BaseProfile $contact_id = $view_as_contact_id ?: $remote_contact_id ?: 0; if ($is_owner && $contact_id === 0) { - $profile_fields = DI::profileField()->selectByUserId($a->profile_uid); + $profile_fields = DI::profileField()->selectByUserId($profile['uid']); } else { - $profile_fields = DI::profileField()->selectByContactId($contact_id, $a->profile_uid); + $profile_fields = DI::profileField()->selectByContactId($contact_id, $profile['uid']); } foreach ($profile_fields as $profile_field) { $custom_fields += self::buildField( 'custom_' . $profile_field->order, $profile_field->label, - BBCode::convert($profile_field->value), + BBCode::convertForUriId($profile['uri-id'], $profile_field->value), 'aprofile custom' ); }; //show subcribed forum if it is enabled in the usersettings - if (Feature::isEnabled($a->profile_uid, 'forumlist_profile')) { + if (Feature::isEnabled($profile['uid'], 'forumlist_profile')) { $custom_fields += self::buildField( 'forumlist', DI::l10n()->t('Forums:'), - ForumManager::profileAdvanced($a->profile_uid) + ForumManager::profileAdvanced($profile['uid']) ); } - $tpl = Renderer::getMarkupTemplate('profile/index.tpl'); + $tpl = Renderer::getMarkupTemplate('profile/profile.tpl'); $o .= Renderer::replaceMacros($tpl, [ '$title' => DI::l10n()->t('Profile'), + '$yourself' => DI::l10n()->t('Yourself'), '$view_as_contacts' => $view_as_contacts, '$view_as_contact_id' => $view_as_contact_id, + '$view_as_contact_alert' => $view_as_contact_alert, '$view_as' => DI::l10n()->t('View profile as:'), + '$submit' => DI::l10n()->t('Submit'), '$basic' => DI::l10n()->t('Basic'), '$advanced' => DI::l10n()->t('Advanced'), - '$is_owner' => $a->profile_uid == local_user(), + '$is_owner' => $profile['uid'] == DI::userSession()->getLocalUserId(), '$query_string' => DI::args()->getQueryString(), '$basic_fields' => $basic_fields, '$custom_fields' => $custom_fields, - '$profile' => $a->profile, + '$profile' => $profile, '$edit_link' => [ 'url' => DI::baseUrl() . '/settings/profile', DI::l10n()->t('Edit profile'), 'title' => '', 'label' => DI::l10n()->t('Edit profile') ], + '$viewas_link' => [ + 'url' => DI::args()->getQueryString() . '#viewas', + 'title' => '', + 'label' => DI::l10n()->t('View as') + ], ]); Hook::callAll('profile_advanced', $o); @@ -282,8 +300,8 @@ class Profile extends BaseProfile } // site block - $blocked = !local_user() && !$remote_contact_id && DI::config()->get('system', 'block_public'); - $userblock = !local_user() && !$remote_contact_id && $profile['hidewall']; + $blocked = !DI::userSession()->isAuthenticated() && DI::config()->get('system', 'block_public'); + $userblock = !DI::userSession()->isAuthenticated() && $profile['hidewall']; if (!$blocked && !$userblock) { $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $profile['pub_keywords'] ?? ''); if (strlen($keywords)) { @@ -293,14 +311,14 @@ class Profile extends BaseProfile $htmlhead .= '' . "\n"; - if (!$profile['net-publish'] || $profile['hidewall']) { + if (!$profile['net-publish']) { $htmlhead .= '' . "\n"; } - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; - $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; + $htmlhead .= '' . "\n"; $uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : '')); $htmlhead .= '' . "\n"; header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); @@ -309,7 +327,6 @@ class Profile extends BaseProfile foreach ($dfrn_pages as $dfrn) { $htmlhead .= '' . "\n"; } - $htmlhead .= '' . "\n"; return $htmlhead; }