diff --git a/mod/item.php b/mod/item.php index 6af1e2d221..1f826a42d0 100644 --- a/mod/item.php +++ b/mod/item.php @@ -45,7 +45,7 @@ use Friendica\Model\Post; use Friendica\Network\HTTPException; use Friendica\Util\DateTimeFormat; -function item_post(App $a) +function item_post() { $uid = DI::userSession()->getLocalUserId(); diff --git a/src/App.php b/src/App.php index 2e19841a1b..e10fb44d2d 100644 --- a/src/App.php +++ b/src/App.php @@ -134,42 +134,6 @@ class App */ private $session; - /** - * @deprecated 2022.03 - * @see IHandleUserSessions::isAuthenticated() - */ - public function isLoggedIn(): bool - { - return $this->session->isAuthenticated(); - } - - /** - * @deprecated 2022.03 - * @see IHandleUserSessions::isSiteAdmin() - */ - public function isSiteAdmin(): bool - { - return $this->session->isSiteAdmin(); - } - - /** - * @deprecated 2022.03 - * @see IHandleUserSessions::getLocalUserId() - */ - public function getLoggedInUserId(): int - { - return $this->session->getLocalUserId(); - } - - /** - * @deprecated 2022.03 - * @see IHandleUserSessions::getLocalUserNickname() - */ - public function getLoggedInUserNickname(): string - { - return $this->session->getLocalUserNickname(); - } - /** * Set the profile owner ID * @@ -716,7 +680,7 @@ class App // Wrapping HTML responses in the theme template if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { - $response = $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId()); + $response = $page->run($this, $this->session, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId()); } $this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $server['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $server['HTTP_REFERER'] ?? '', 'user-agent' => $server['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]); diff --git a/src/App/Page.php b/src/App/Page.php index de170f0411..ab0c95d97c 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -32,6 +32,7 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; +use Friendica\Core\Session\Model\UserSession; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Module\Response; @@ -325,13 +326,13 @@ class Page implements ArrayAccess * * @throws HTTPException\InternalServerErrorException */ - private function initFooter(App $app, Mode $mode, L10n $l10n) + private function initFooter(UserSession $session, Mode $mode, L10n $l10n) { // If you're just visiting, let javascript take you home if (!empty($_SESSION['visitor_home'])) { $homebase = $_SESSION['visitor_home']; - } elseif (!empty($app->getLoggedInUserNickname())) { - $homebase = 'profile/' . $app->getLoggedInUserNickname(); + } elseif (!empty($session->getLocalUserNickname())) { + $homebase = 'profile/' . $session->getLocalUserNickname(); } if (isset($homebase)) { @@ -420,7 +421,7 @@ class Page implements ArrayAccess * @throws HTTPException\InternalServerErrorException * @throws HTTPException\ServiceUnavailableException */ - public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, Nav $nav, int $localUID) + public function run(App $app, UserSession $session, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig, Nav $nav, int $localUID) { $moduleName = $args->getModuleName(); @@ -459,7 +460,7 @@ class Page implements ArrayAccess /* Build the page ending -- this is stuff that goes right before * the closing tag */ - $this->initFooter($app, $mode, $l10n); + $this->initFooter($session, $mode, $l10n); $profiler->set(microtime(true) - $timestamp, 'aftermath'); diff --git a/src/BaseModule.php b/src/BaseModule.php index 0cf7f514a3..2f511bc547 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -356,7 +356,7 @@ abstract class BaseModule implements ICanHandleRequests */ public static function getFormSecurityToken(string $typename = ''): string { - $user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']); + $user = User::getById(DI::userSession()->getLocalUserId(), ['guid', 'prvkey']); $timestamp = time(); $sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename); @@ -390,7 +390,7 @@ abstract class BaseModule implements ICanHandleRequests $max_livetime = 10800; // 3 hours - $user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']); + $user = User::getById(DI::userSession()->getLocalUserId(), ['guid', 'prvkey']); $x = explode('.', $hash); if (time() > (intval($x[0]) + $max_livetime)) { diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php index 1c5182cc8a..1979d41a63 100644 --- a/src/Content/Conversation.php +++ b/src/Content/Conversation.php @@ -308,7 +308,7 @@ class Conversation public function statusEditor(array $x = [], int $notes_cid = 0, bool $popup = false): string { - $user = User::getById($this->app->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']); + $user = User::getById($this->session->getLocalUserId(), ['uid', 'nickname', 'allow_location', 'default-location']); if (empty($user['uid'])) { return ''; } diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 35455de30a..8550e44a5e 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -67,7 +67,7 @@ class Widget if (DI::config()->get('system', 'invitation_only')) { $x = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining')); - if ($x || DI::app()->isSiteAdmin()) { + if ($x || DI::userSession()->isSiteAdmin()) { DI::page()['aside'] .= ''; diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 11a7d0a2d6..45c8383eeb 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -87,7 +87,7 @@ class Renderer $output = $t->replaceMacros($template, $vars); } catch (Exception $e) { DI::logger()->critical($e->getMessage(), ['template' => $template, 'vars' => $vars]); - $message = DI::app()->isSiteAdmin() ? + $message = DI::userSession()->isSiteAdmin() ? $e->getMessage() : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); throw new ServiceUnavailableException($message); @@ -116,7 +116,7 @@ class Renderer $template = $t->getTemplateFile($file, $subDir); } catch (Exception $e) { DI::logger()->critical($e->getMessage(), ['file' => $file, 'subDir' => $subDir]); - $message = DI::app()->isSiteAdmin() ? + $message = DI::userSession()->isSiteAdmin() ? $e->getMessage() : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); throw new ServiceUnavailableException($message); @@ -145,7 +145,7 @@ class Renderer } else { $admin_message = DI::l10n()->t('template engine cannot be registered without a name.'); DI::logger()->critical($admin_message, ['class' => $class]); - $message = DI::app()->isSiteAdmin() ? + $message = DI::userSession()->isSiteAdmin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); throw new ServiceUnavailableException($message); @@ -179,7 +179,7 @@ class Renderer $admin_message = DI::l10n()->t('template engine is not registered!'); DI::logger()->critical($admin_message, ['template_engine' => $template_engine]); - $message = DI::app()->isSiteAdmin() ? + $message = DI::userSession()->isSiteAdmin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); throw new ServiceUnavailableException($message); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 7a83d01a0e..d6dfd7b275 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -113,15 +113,6 @@ class Contact * @} */ - /** @deprecated Use Entity\LocalRelationship::MIRROR_DEACTIVATED instead */ - const MIRROR_DEACTIVATED = LocalRelationship::MIRROR_DEACTIVATED; - /** @deprecated Now does the same as MIRROR_OWN_POST */ - const MIRROR_FORWARDED = 1; - /** @deprecated Use Entity\LocalRelationship::MIRROR_OWN_POST instead */ - const MIRROR_OWN_POST = LocalRelationship::MIRROR_OWN_POST; - /** @deprecated Use Entity\LocalRelationship::MIRROR_NATIVE_RESHARE instead */ - const MIRROR_NATIVE_RESHARE = LocalRelationship::MIRROR_NATIVE_RESHARE; - /** * @param array $fields Array of selected fields, empty for all * @param array $condition Array of fields for condition diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 4daf77278a..3cc1b816e2 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -297,7 +297,7 @@ class Profile if (DI::userSession()->getLocalUserId() && ($profile['uid'] ?? 0) != DI::userSession()->getLocalUserId()) { $profile_contact = Contact::getByURL($profile['nurl'], null, [], DI::userSession()->getLocalUserId()); } - if (!empty($profile['cid']) && self::getMyURL()) { + if (!empty($profile['cid']) && DI::userSession()->getMyUrl()) { $profile_contact = Contact::selectFirst([], ['id' => $profile['cid']]); } @@ -322,19 +322,19 @@ class Profile // Who is the logged-in user to this profile? $visitor_contact = []; - if (!empty($profile['uid']) && self::getMyURL()) { - $visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(self::getMyURL())]); + if (!empty($profile['uid']) && DI::userSession()->getMyUrl()) { + $visitor_contact = Contact::selectFirst(['rel'], ['uid' => $profile['uid'], 'nurl' => Strings::normaliseLink(DI::userSession()->getMyUrl())]); } - $local_user_is_self = self::getMyURL() && ($profile['url'] == self::getMyURL()); - $visitor_is_authenticated = (bool)self::getMyURL(); + $local_user_is_self = DI::userSession()->getMyUrl() && ($profile['url'] == DI::userSession()->getMyUrl()); + $visitor_is_authenticated = (bool)DI::userSession()->getMyUrl(); $visitor_is_following = in_array($visitor_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]) || in_array($profile_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]); $visitor_is_followed = in_array($visitor_contact['rel'] ?? 0, [Contact::SHARING, Contact::FRIEND]) || in_array($profile_contact['rel'] ?? 0, [Contact::FOLLOWER, Contact::FRIEND]); - $visitor_base_path = self::getMyURL() ? preg_replace('=/profile/(.*)=ism', '', self::getMyURL()) : ''; + $visitor_base_path = DI::userSession()->getMyUrl() ? preg_replace('=/profile/(.*)=ism', '', DI::userSession()->getMyUrl()) : ''; if (!$local_user_is_self) { if (!$visitor_is_authenticated) { @@ -696,17 +696,6 @@ class Profile ]); } - /** - * Retrieves the my_url session variable - * - * @return string - * @deprecated since version 2022.12, please use UserSession->getMyUrl instead - */ - public static function getMyURL(): string - { - return DI::userSession()->getMyUrl(); - } - /** * Process the 'zrl' parameter and initiate the remote authentication. * @@ -730,7 +719,7 @@ class Profile */ public static function zrlInit(App $a) { - $my_url = self::getMyURL(); + $my_url = DI::userSession()->getMyUrl(); $my_url = Network::isUrlValid($my_url); if (empty($my_url) || DI::userSession()->getLocalUserId()) { @@ -916,7 +905,7 @@ class Profile } $achar = strpos($url, '?') ? '&' : '?'; - $mine = self::getMyURL(); + $mine = DI::userSession()->getMyUrl(); if ($mine && !Strings::compareLink($mine, $url)) { return $url . $achar . 'zrl=' . urlencode($mine); diff --git a/src/Module/BaseAdmin.php b/src/Module/BaseAdmin.php index bdcead545f..590c9f708a 100644 --- a/src/Module/BaseAdmin.php +++ b/src/Module/BaseAdmin.php @@ -59,7 +59,7 @@ abstract class BaseAdmin extends BaseModule } } - if (!DI::app()->isSiteAdmin()) { + if (!DI::userSession()->isSiteAdmin()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.')); } diff --git a/src/Module/Contact/Profile.php b/src/Module/Contact/Profile.php index aee08977f8..fbbf88d5c6 100644 --- a/src/Module/Contact/Profile.php +++ b/src/Module/Contact/Profile.php @@ -24,6 +24,7 @@ namespace Friendica\Module\Contact; use Friendica\App; use Friendica\BaseModule; use Friendica\Contact\LocalRelationship; +use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity; use Friendica\Content\ContactSelector; use Friendica\Content\Nav; use Friendica\Content\Text\BBCode; @@ -323,24 +324,24 @@ class Profile extends BaseModule if ($contact['network'] == Protocol::FEED) { $remote_self_options = [ - Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'), - Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting') + LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'), + LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting') ]; } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { $remote_self_options = [ - Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'), - Contact::MIRROR_NATIVE_RESHARE => $this->t('Native reshare') + LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'), + LocalRelationshipEntity::MIRROR_NATIVE_RESHARE => $this->t('Native reshare') ]; } elseif ($contact['network'] == Protocol::DFRN) { $remote_self_options = [ - Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'), - Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting'), - Contact::MIRROR_NATIVE_RESHARE => $this->t('Native reshare') + LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'), + LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting'), + LocalRelationshipEntity::MIRROR_NATIVE_RESHARE => $this->t('Native reshare') ]; } else { $remote_self_options = [ - Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'), - Contact::MIRROR_OWN_POST => $this->t('Mirror as my own posting') + LocalRelationshipEntity::MIRROR_DEACTIVATED => $this->t('No mirroring'), + LocalRelationshipEntity::MIRROR_OWN_POST => $this->t('Mirror as my own posting') ]; } diff --git a/src/Module/Invite.php b/src/Module/Invite.php index 8e0cff268e..350ee6beed 100644 --- a/src/Module/Invite.php +++ b/src/Module/Invite.php @@ -68,7 +68,7 @@ class Invite extends BaseModule if ($config->get('system', 'invitation_only')) { $invitation_only = true; $invites_remaining = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining'); - if ((!$invites_remaining) && (!$app->isSiteAdmin())) { + if ((!$invites_remaining) && (!DI::userSession()->isSiteAdmin())) { throw new HTTPException\ForbiddenException(); } } @@ -83,11 +83,11 @@ class Invite extends BaseModule continue; } - if ($invitation_only && ($invites_remaining || $app->isSiteAdmin())) { + if ($invitation_only && ($invites_remaining || DI::userSession()->isSiteAdmin())) { $code = Model\Register::createForInvitation(); $nmessage = str_replace('$invite_code', $code, $message); - if (!$app->isSiteAdmin()) { + if (!DI::userSession()->isSiteAdmin()) { $invites_remaining--; if ($invites_remaining >= 0) { DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining', $invites_remaining); @@ -139,7 +139,7 @@ class Invite extends BaseModule if ($config->get('system', 'invitation_only')) { $inviteOnly = true; $x = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'invites_remaining'); - if ((!$x) && (!$app->isSiteAdmin())) { + if ((!$x) && (!DI::userSession()->isSiteAdmin())) { throw new HTTPException\ForbiddenException(DI::l10n()->t('You have no more invitations available')); } } @@ -172,7 +172,7 @@ class Invite extends BaseModule DI::l10n()->t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n" . $linkTxt . "\r\n" . "\r\n" . (($inviteOnly) ? DI::l10n()->t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . DI::l10n()->t('Once you have registered, please connect with me via my profile page at:') - . "\r\n" . "\r\n" . DI::baseUrl() . '/profile/' . $app->getLoggedInUserNickname() + . "\r\n" . "\r\n" . DI::baseUrl() . '/profile/' . DI::userSession()->getLocalUserNickname() . "\r\n" . "\r\n" . DI::l10n()->t('For more information about the Friendica project and why we feel it is important, please visit http://friendi.ca') . "\r\n" . "\r\n", ], '$submit' => DI::l10n()->t('Submit') diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index 80879273e2..5bb2fc73d5 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -31,9 +31,9 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; +use Friendica\Core\Session\Model\UserSession; use Friendica\Core\Theme; use Friendica\Database\DBA; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\User; @@ -64,7 +64,14 @@ class Compose extends BaseModule /** @var IManageConfigValues */ private $config; - public function __construct(IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) + /** @var UserSession */ + private $session; + + /** @var App */ + private $app; + + + public function __construct(App $app, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); @@ -73,6 +80,8 @@ class Compose extends BaseModule $this->page = $page; $this->pConfig = $pConfig; $this->config = $config; + $this->session = $session; + $this->app = $app; } protected function post(array $request = []) @@ -80,7 +89,7 @@ class Compose extends BaseModule if (!empty($_REQUEST['body'])) { $_REQUEST['return'] = 'network'; require_once 'mod/item.php'; - item_post(DI::app()); + item_post(); } else { $this->systemMessages->addNotice($this->l10n->t('Please enter a post body.')); } @@ -88,13 +97,11 @@ class Compose extends BaseModule protected function content(array $request = []): string { - if (!DI::userSession()->getLocalUserId()) { + if (!$this->session->getLocalUserId()) { return Login::form('compose'); } - $a = DI::app(); - - if ($a->getCurrentTheme() !== 'frio') { + if ($this->app->getCurrentTheme() !== 'frio') { throw new NotImplementedException($this->l10n->t('This feature is only available with the frio theme.')); } @@ -110,7 +117,7 @@ class Compose extends BaseModule } } - $user = User::getById(DI::userSession()->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']); + $user = User::getById($this->session->getLocalUserId(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'default-location']); $contact_allow_list = $this->ACLFormatter->expand($user['allow_cid']); $circle_allow_list = $this->ACLFormatter->expand($user['allow_gid']); @@ -122,7 +129,7 @@ class Compose extends BaseModule $compose_title = $this->l10n->t('Compose new personal note'); $type = 'note'; $doesFederate = false; - $contact_allow_list = [$a->getContactId()]; + $contact_allow_list = [$this->app->getContactId()]; $circle_allow_list = []; $contact_deny_list = []; $circle_deny_list = []; @@ -165,9 +172,9 @@ class Compose extends BaseModule $this->page->registerFooterScript(Theme::getPathForFile('js/linkPreview.js')); $this->page->registerFooterScript(Theme::getPathForFile('js/compose.js')); - $contact = Contact::getById($a->getContactId()); + $contact = Contact::getById($this->app->getContactId()); - if ($this->pConfig->get(DI::userSession()->getLocalUserId(), 'system', 'set_creation_date')) { + if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'set_creation_date')) { $created_at = Temporal::getDateTimeField( new \DateTime(DBA::NULL_DATETIME), new \DateTime('now'), @@ -205,8 +212,8 @@ class Compose extends BaseModule 'location_disabled' => $this->l10n->t('Location services are disabled. Please check the website\'s permissions on your device'), 'wait' => $this->l10n->t('Please wait'), 'placeholdertitle' => $this->l10n->t('Set title'), - 'placeholdercategory' => Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '', - 'always_open_compose' => $this->pConfig->get(DI::userSession()->getLocalUserId(), 'frio', 'always_open_compose', + 'placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '', + 'always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', $this->config->get('frio', 'always_open_compose', false)) ? '' : $this->l10n->t('You can make this page always open when you use the New Post button in the Theme Customization settings.'), ], @@ -237,7 +244,7 @@ class Compose extends BaseModule '$jotplugins' => $jotplugins, '$rand_num' => Crypto::randomDigits(12), - '$acl_selector' => ACL::getFullSelectorHTML($this->page, $a->getLoggedInUserId(), $doesFederate, [ + '$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [ 'allow_cid' => $contact_allow_list, 'allow_gid' => $circle_allow_list, 'deny_cid' => $contact_deny_list, diff --git a/src/Module/Item/Display.php b/src/Module/Item/Display.php index 30aff85b41..f2c22c3090 100644 --- a/src/Module/Item/Display.php +++ b/src/Module/Item/Display.php @@ -188,7 +188,7 @@ class Display extends BaseModule $author = Contact::getById($item['author-id']); } - if (Network::isLocalLink($author['url'])) { + if ($this->baseUrl->isLocalUrl($author['url'])) { Profile::load($this->app, $author['nick'], false); } else { $this->page['aside'] = Widget\VCard::getHTML($author); diff --git a/src/Module/Moderation/Blocklist/Contact.php b/src/Module/Moderation/Blocklist/Contact.php index d726b4d9b3..fd3161a1a5 100644 --- a/src/Module/Moderation/Blocklist/Contact.php +++ b/src/Module/Moderation/Blocklist/Contact.php @@ -66,7 +66,7 @@ class Contact extends BaseModeration $this->baseUrl->redirect('moderation/blocklist/contact'); } - if (Network::isLocalLink($contact['nurl'])) { + if ($this->baseUrl->isLocalUrl($contact['nurl'])) { $this->systemMessages->addNotice($this->t('You can\'t block a local contact, please block the user instead')); $this->baseUrl->redirect('moderation/blocklist/contact'); } diff --git a/src/Module/Moderation/Report/Create.php b/src/Module/Moderation/Report/Create.php index a7326fa0fa..c2dd4929af 100644 --- a/src/Module/Moderation/Report/Create.php +++ b/src/Module/Moderation/Report/Create.php @@ -293,7 +293,7 @@ class Create extends BaseModule '$ignore' => ['contact_action', $this->t('Ignore contact'), self::CONTACT_ACTION_IGNORE, $this->t("Their posts won't appear in your Network page anymore, but their replies can appear in forum threads. They still can follow you.")], '$block' => ['contact_action', $this->t('Block contact'), self::CONTACT_ACTION_BLOCK, $this->t("Their posts won't appear in your Network page anymore, but their replies can appear in forum threads, with their content collapsed by default. They cannot follow you but still can have access to your public posts by other means.")], - '$display_forward' => !Network::isLocalLink($contact['url']), + '$display_forward' => !$this->baseUrl->isLocalUrl($contact['url']), '$forward' => ['report_forward', $this->t('Forward report'), self::CONTACT_ACTION_BLOCK, $this->t('Would you ike to forward this report to the remote server?')], '$summary' => $this->getAside($request), diff --git a/src/Module/Profile/Conversations.php b/src/Module/Profile/Conversations.php index 3053f07cb1..41203fecbd 100644 --- a/src/Module/Profile/Conversations.php +++ b/src/Module/Profile/Conversations.php @@ -157,7 +157,7 @@ class Conversations extends BaseProfile 'allow_location' => ($is_owner || $commvisitor) && $profile['allow_location'], 'default_location' => $is_owner ? $profile['default-location'] : '', 'nickname' => $profile['nickname'], - 'acl' => $is_owner ? ACL::getFullSelectorHTML($this->page, $this->app->getLoggedInUserId(), true) : '', + 'acl' => $is_owner ? ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), true) : '', 'visitor' => $is_owner || $commvisitor ? 'block' : 'none', 'profile_uid' => $profile['uid'], ]; diff --git a/src/Module/Security/Logout.php b/src/Module/Security/Logout.php index 37f4cab371..9ec0fa677d 100644 --- a/src/Module/Security/Logout.php +++ b/src/Module/Security/Logout.php @@ -64,7 +64,7 @@ class Logout extends BaseModule { $visitor_home = null; if ($this->session->getRemoteUserId()) { - $visitor_home = Profile::getMyURL(); + $visitor_home = $this->session->getMyUrl(); $this->cache->delete('zrlInit:' . $visitor_home); } diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index 37a39d5569..c0aa864632 100644 --- a/src/Module/Security/TwoFactor/Recovery.php +++ b/src/Module/Security/TwoFactor/Recovery.php @@ -73,7 +73,7 @@ class Recovery extends BaseModule $this->session->set('2fa', true); DI::sysmsg()->addInfo($this->t('Remaining recovery codes: %d', RecoveryCode::countValidForUser($this->session->getLocalUserId()))); - $this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true); + $this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true); $this->baseUrl->redirect($this->session->pop('return_path', '')); } else { diff --git a/src/Module/Security/TwoFactor/Trust.php b/src/Module/Security/TwoFactor/Trust.php index 3cb821da4a..55c7fd6e86 100644 --- a/src/Module/Security/TwoFactor/Trust.php +++ b/src/Module/Security/TwoFactor/Trust.php @@ -102,13 +102,13 @@ class Trust extends BaseModule } try { - $this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true); + $this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true); $this->baseUrl->redirect($this->session->pop('return_path', '')); } catch (FoundException | TemporaryRedirectException | MovedPermanentlyException $e) { // exception wanted! throw $e; } catch (\Exception $e) { - $this->logger->warning('Unexpected error during authentication.', ['user' => $this->app->getLoggedInUserId(), 'exception' => $exception]); + $this->logger->warning('Unexpected error during authentication.', ['user' => $this->session->getLocalUserId(), 'exception' => $exception]); } } } @@ -123,15 +123,15 @@ class Trust extends BaseModule try { $trustedBrowser = $this->trustedBrowserRepository->selectOneByHash($this->cookie->get('2fa_cookie_hash')); if (!$trustedBrowser->trusted) { - $this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true); + $this->auth->setForUser($this->app, User::getById($this->session->getLocalUserId()), true, true); $this->baseUrl->redirect($this->session->pop('return_path', '')); } } catch (TrustedBrowserNotFoundException $exception) { - $this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); + $this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]); } catch (TrustedBrowserPersistenceException $exception) { - $this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); + $this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]); } catch (\Exception $exception) { - $this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); + $this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->session->getLocalUserId(), 'exception' => $exception]); } } diff --git a/src/Module/Settings/Account.php b/src/Module/Settings/Account.php index 804cec8325..93c10b0240 100644 --- a/src/Module/Settings/Account.php +++ b/src/Module/Settings/Account.php @@ -46,7 +46,7 @@ class Account extends BaseSettings { protected function post(array $request = []) { - if (!DI::app()->isLoggedIn()) { + if (!DI::userSession()->isAuthenticated()) { throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); } @@ -56,7 +56,7 @@ class Account extends BaseSettings $a = DI::app(); - $user = User::getById($a->getLoggedInUserId()); + $user = User::getById($this->session->getLocalUserId()); if (!empty($request['password-submit'])) { $newpass = $request['password']; @@ -394,7 +394,7 @@ class Account extends BaseSettings $a = DI::app(); - $user = User::getById($a->getLoggedInUserId()); + $user = User::getById($this->session->getLocalUserId()); $username = $user['username']; $email = $user['email']; @@ -591,7 +591,7 @@ class Account extends BaseSettings '$circle_select' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), $user['def_gid'], 'circle-selection', DI::l10n()->t('Default privacy circle for new contacts')), '$circle_select_group' => Circle::getSelectorHTML(DI::userSession()->getLocalUserId(), DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'default-group-gid', $user['def_gid']), 'circle-selection-group', DI::l10n()->t('Default privacy circle for new group contacts')), '$permissions' => DI::l10n()->t('Default Post Permissions'), - '$aclselect' => ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()), + '$aclselect' => ACL::getFullSelectorHTML(DI::page(), $this->session->getLocalUserId()), '$expire' => [ 'label' => DI::l10n()->t('Expiration settings'), diff --git a/src/Module/User/Import.php b/src/Module/User/Import.php index d6c54a08ae..f3255cc929 100644 --- a/src/Module/User/Import.php +++ b/src/Module/User/Import.php @@ -27,6 +27,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Protocol; use Friendica\Core\Renderer; +use Friendica\Core\Session\Model\UserSession; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\Database; @@ -48,9 +49,6 @@ class Import extends \Friendica\BaseModule { const IMPORT_DEBUG = false; - /** @var App */ - private $app; - /** @var IManageConfigValues */ private $config; @@ -66,21 +64,24 @@ class Import extends \Friendica\BaseModule /** @var PermissionSet */ private $permissionSet; - public function __construct(PermissionSet $permissionSet, IManagePersonalConfigValues $pconfig, Database $database, SystemMessages $systemMessages, IManageConfigValues $config, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) + /** @var UserSession */ + private $session; + + public function __construct(UserSession $session, PermissionSet $permissionSet, IManagePersonalConfigValues $pconfig, Database $database, SystemMessages $systemMessages, IManageConfigValues $config, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - $this->app = $app; $this->config = $config; $this->pconfig = $pconfig; $this->systemMessages = $systemMessages; $this->database = $database; $this->permissionSet = $permissionSet; + $this->session = $session; } protected function post(array $request = []) { - if (\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN && !$this->app->isSiteAdmin()) { + if (\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN && !$this->session->isSiteAdmin()) { throw new HttpException\ForbiddenException($this->t('Permission denied.')); } @@ -99,7 +100,7 @@ class Import extends \Friendica\BaseModule protected function content(array $request = []): string { - if ((\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN) && !$this->app->isSiteAdmin()) { + if ((\Friendica\Module\Register::getPolicy() !== \Friendica\Module\Register::OPEN) && !$this->session->isSiteAdmin()) { $this->systemMessages->addNotice($this->t('User imports on closed servers can only be done by an administrator.')); } diff --git a/src/Network/HTTPClient/Client/HttpClient.php b/src/Network/HTTPClient/Client/HttpClient.php index 934fe56d93..f6669a20bf 100644 --- a/src/Network/HTTPClient/Client/HttpClient.php +++ b/src/Network/HTTPClient/Client/HttpClient.php @@ -83,7 +83,7 @@ class HttpClient implements ICanSendHttpRequests return CurlResult::createErrorCurl($this->logger, $url); } - if (Network::isLocalLink($url)) { + if ($this->baseUrl->isLocalUrl($url)) { $this->logger->info('Local link', ['url' => $url]); } @@ -249,7 +249,7 @@ class HttpClient implements ICanSendHttpRequests { $this->profiler->startRecording('network'); - if (Network::isLocalLink($url)) { + if ($this->baseUrl->isLocalUrl($url)) { $this->logger->debug('Local link', ['url' => $url]); } diff --git a/src/Object/EMail/ItemCCEMail.php b/src/Object/EMail/ItemCCEMail.php index e6991df8c1..253af96e72 100644 --- a/src/Object/EMail/ItemCCEMail.php +++ b/src/Object/EMail/ItemCCEMail.php @@ -25,30 +25,30 @@ use Friendica\App; use Friendica\App\BaseURL; use Friendica\Content\Text\HTML; use Friendica\Core\L10n; +use Friendica\Core\Session\Model\UserSession; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Object\Email; -use Friendica\Protocol\Email as EmailProtocol; /** * Class for creating CC emails based on a received item */ class ItemCCEMail extends Email { - public function __construct(App $a, L10n $l10n, BaseURL $baseUrl, array $item, string $toAddress, string $authorThumb) + public function __construct(UserSession $session, L10n $l10n, BaseURL $baseUrl, array $item, string $toAddress, string $authorThumb) { - $user = User::getById($a->getLoggedInUserId()); + $user = User::getById($session->getLocalUserId()); $disclaimer = '
' . $l10n->t('This message was sent to you by %s, a member of the Friendica social network.', $user['username']) . '
'; - $disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $a->getLoggedInUserNickname()) . '
'; + $disclaimer .= $l10n->t('You may visit them online at %s', $baseUrl . '/profile/' . $session->getLocalUserNickname()) . '
'; $disclaimer .= $l10n->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . '
'; if (!$item['title'] == '') { $subject = $item['title']; } else { $subject = '[Friendica]' . ' ' . $l10n->t('%s posted an update.', $user['username']); } - $link = '' . $user['username'] . '

'; + $link = '' . $user['username'] . '

'; $html = Item::prepareBody($item); $message = '' . $link . $html . $disclaimer . '';; diff --git a/src/Object/Post.php b/src/Object/Post.php index b341612e8c..cb686840fa 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -1071,13 +1071,11 @@ class Post */ private function getDefaultText(): string { - $a = DI::app(); - if (!DI::userSession()->getLocalUserId()) { return ''; } - $owner = User::getOwnerDataById($a->getLoggedInUserId()); + $owner = User::getOwnerDataById(DI::userSession()->getLocalUserId()); $item = $this->getData(); if (!empty($item['content-warning']) && Feature::isEnabled(DI::userSession()->getLocalUserId(), Feature::ADD_ABSTRACT)) { @@ -1124,8 +1122,6 @@ class Post */ private function getCommentBox(string $indent) { - $a = DI::app(); - $comment_box = ''; $conv = $this->getThread(); @@ -1144,7 +1140,7 @@ class Post $uid = $conv->getProfileOwner(); $parent_uid = $this->getDataValue('uid'); - $owner = User::getOwnerDataById($a->getLoggedInUserId()); + $owner = User::getOwnerDataById(DI::userSession()->getLocalUserId()); $default_text = $this->getDefaultText(); diff --git a/src/Render/FriendicaSmartyEngine.php b/src/Render/FriendicaSmartyEngine.php index 61dec3c011..8ead65d0e5 100644 --- a/src/Render/FriendicaSmartyEngine.php +++ b/src/Render/FriendicaSmartyEngine.php @@ -55,7 +55,7 @@ final class FriendicaSmartyEngine extends TemplateEngine if (!is_writable($work_dir)) { $admin_message = DI::l10n()->t('The folder %s must be writable by webserver.', $work_dir); DI::logger()->critical($admin_message); - $message = DI::app()->isSiteAdmin() ? + $message = DI::userSession()->isSiteAdmin() ? $admin_message : DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.'); throw new ServiceUnavailableException($message); diff --git a/src/Util/Network.php b/src/Util/Network.php index 1c2b3c8e5c..54eb13bd12 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -648,19 +648,6 @@ class Network } } - /** - * Check if the given URL is a local link - * - * @param string $url - * - * @return bool - * @deprecated since 2023.09, please use BaseUrl->isLocalUrl or BaseUrl->isLocalUri instead. - */ - public static function isLocalLink(string $url): bool - { - return DI::baseUrl()->isLocalUrl($url); - } - /** * Check if the given URL is a valid HTTP/HTTPS URL * diff --git a/update.php b/update.php index f4c491521d..03a95fb145 100644 --- a/update.php +++ b/update.php @@ -40,6 +40,7 @@ * If you need to run a script before the database update, name the function "pre_update_4712()" */ +use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; use Friendica\Core\Config\ValueObject\Cache; use Friendica\Core\Logger; use Friendica\Core\Protocol; @@ -1133,7 +1134,7 @@ function update_1481() function update_1491() { - DBA::update('contact', ['remote_self' => Contact::MIRROR_OWN_POST], ['remote_self' => Contact::MIRROR_FORWARDED]); + DBA::update('contact', ['remote_self' => LocalRelationship::MIRROR_OWN_POST], ['remote_self' => 1]); return Update::SUCCESS; } diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index 62969badeb..d7755f8293 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -57,9 +57,9 @@ function theme_post(App $a) } } -function theme_admin_post(App $a) +function theme_admin_post() { - if (!$a->isSiteAdmin()) { + if (!DI::userSession()->isSiteAdmin()) { return; } diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index c316f8dbf5..a1c40b3b92 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -199,7 +199,7 @@ function frio_remote_nav(array &$nav_info) { if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { // get the homelink from $_SESSION - $homelink = Profile::getMyURL(); + $homelink = DI::userSession()->getMyUrl(); if (!$homelink) { $homelink = DI::session()->get('visitor_home', ''); } @@ -212,7 +212,7 @@ function frio_remote_nav(array &$nav_info) } elseif (!DI::userSession()->getLocalUserId() && DI::userSession()->getRemoteUserId()) { $remoteUser = Contact::getById(DI::userSession()->getRemoteUserId(), $fields); $nav_info['nav']['remote'] = DI::l10n()->t('Guest'); - } elseif (Profile::getMyURL()) { + } elseif (DI::userSession()->getMyUrl()) { $remoteUser = Contact::getByURL($homelink, null, $fields); $nav_info['nav']['remote'] = DI::l10n()->t('Visitor'); } else {