]> git.mxchange.org Git - friendica.git/commitdiff
Move Core\Session::get() to DI::session()->get()
authorPhilipp <admin@philipp.info>
Tue, 18 Oct 2022 19:10:37 +0000 (21:10 +0200)
committerPhilipp <admin@philipp.info>
Tue, 18 Oct 2022 19:10:37 +0000 (21:10 +0200)
15 files changed:
mod/redir.php
src/App.php
src/Content/Conversation.php
src/Content/Nav.php
src/Core/Session.php
src/Model/Profile.php
src/Module/Conversation/Network.php
src/Module/Delegation.php
src/Module/Profile/Status.php
src/Module/Settings/Delegation.php
src/Module/Settings/Display.php
src/Module/Settings/TwoFactor/Verify.php
src/Module/Update/Profile.php
src/Object/Post.php
view/theme/frio/theme.php

index ba1b7e13b6a9f45cfe957c57816e31f553942f56..426abfd49bd5b23985b23e4737b97b05a6315273 100644 (file)
@@ -91,7 +91,7 @@ function redir_init(App $a) {
                // with the local contact. Otherwise the local user would ask the local contact
                // for authentification everytime he/she is visiting a profile page of the local
                // contact.
-               if (($host == $remotehost) && (Session::getRemoteContactID(Session::get('visitor_visiting')) == Session::get('visitor_id'))) {
+               if (($host == $remotehost) && (Session::getRemoteContactID(DI::session()->get('visitor_visiting')) == DI::session()->get('visitor_id'))) {
                        // Remote user is already authenticated.
                        redir_check_url($contact_url, $url);
                        $target_url = $url ?: $contact_url;
index 55b3e72e0eb6ca974e8f06c28ede845c91cf2c90..003ff5658984e3b55685b18ddcdf52cbf0c59592 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\App\Arguments;
 use Friendica\App\BaseURL;
 use Friendica\Capabilities\ICanCreateResponses;
 use Friendica\Core\Config\Factory\Config;
+use Friendica\Core\Session\Capability\IHandleSessions;
 use Friendica\Module\Maintenance;
 use Friendica\Security\Authentication;
 use Friendica\Core\Config\ValueObject\Cache;
@@ -127,6 +128,11 @@ class App
         */
        private $pConfig;
 
+       /**
+        * @var IHandleSessions
+        */
+       private $session;
+
        /**
         * Set the user ID
         *
@@ -328,8 +334,9 @@ class App
         * @param L10n                        $l10n     The translator instance
         * @param App\Arguments               $args     The Friendica Arguments of the call
         * @param IManagePersonalConfigValues $pConfig  Personal configuration
+        * @param IHandleSessions             $session  The Session handler
         */
-       public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig)
+       public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig, IHandleSessions $session)
        {
                $this->database = $database;
                $this->config   = $config;
@@ -340,6 +347,7 @@ class App
                $this->l10n     = $l10n;
                $this->args     = $args;
                $this->pConfig  = $pConfig;
+               $this->session  = $session;
 
                $this->load();
        }
@@ -415,7 +423,7 @@ class App
                }
 
                // Specific mobile theme override
-               if (($this->mode->isMobile() || $this->mode->isTablet()) && Core\Session::get('show-mobile', true)) {
+               if (($this->mode->isMobile() || $this->mode->isTablet()) && $this->session->get('show-mobile', true)) {
                        $user_mobile_theme = $this->getCurrentMobileTheme();
 
                        // --- means same mobile theme as desktop
@@ -496,7 +504,7 @@ class App
                        }
                }
 
-               $theme_name = $page_theme ?: Core\Session::get('theme', $system_theme);
+               $theme_name = $page_theme ?: $this->session->get('theme', $system_theme);
 
                $theme_name = Strings::sanitizeFilePathItem($theme_name);
                if ($theme_name
@@ -528,7 +536,7 @@ class App
                        }
                }
 
-               $mobile_theme_name = $page_mobile_theme ?: Core\Session::get('mobile-theme', $system_mobile_theme);
+               $mobile_theme_name = $page_mobile_theme ?: $this->session->get('mobile-theme', $system_mobile_theme);
 
                $mobile_theme_name = Strings::sanitizeFilePathItem($mobile_theme_name);
                if ($mobile_theme_name == '---'
@@ -625,7 +633,7 @@ class App
                                // Valid profile links contain a path with "/profile/" and no query parameters
                                if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == '') &&
                                        strstr(parse_url($_GET['zrl'], PHP_URL_PATH), '/profile/')) {
-                                       if (Core\Session::get('visitor_home') != $_GET['zrl']) {
+                                       if ($this->session->get('visitor_home') != $_GET['zrl']) {
                                                Core\Session::set('my_url', $_GET['zrl']);
                                                Core\Session::set('authenticated', 0);
 
index 817bc402a844a020f4ea7e5d412b8e1608cd14ce..ede7a56b692db4493b33126f896447e9b0810197 100644 (file)
@@ -32,7 +32,6 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Core\Theme;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
@@ -77,8 +76,10 @@ class Conversation
        private $page;
        /** @var App\Mode */
        private $mode;
+       /** @var Session\Capability\IHandleSessions */
+       private $session;
 
-       public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app)
+       public function __construct(LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\Page $page, App\Mode $mode, App $app, Session\Capability\IHandleSessions $session)
        {
                $this->activity = $activity;
                $this->item     = $item;
@@ -92,6 +93,7 @@ class Conversation
                $this->pConfig  = $pConfig;
                $this->page     = $page;
                $this->app      = $app;
+               $this->session  = $session;
        }
 
        /**
@@ -497,7 +499,7 @@ class Conversation
 
                        if (!$update) {
                                $live_update_div = '<div id="live-display"></div>' . "\r\n"
-                                       . "<script> var profile_uid = " . Session::get('uid', 0) . ";"
+                                       . "<script> var profile_uid = " . $this->session->get('uid', 0) . ";"
                                        . "</script>";
                        }
                } elseif ($mode === 'community') {
index 6861d69e80b8a904794a09793a864613dee83b52..b43e926e8cb453f1bb4a330fc1208bac023d7490 100644 (file)
@@ -208,7 +208,7 @@ class Nav
                // "Home" should also take you home from an authenticated remote profile connection
                $homelink = Profile::getMyURL();
                if (! $homelink) {
-                       $homelink = Session::get('visitor_home', '');
+                       $homelink = DI::session()->get('visitor_home', '');
                }
 
                if ((DI::args()->getModuleName() != 'home') && (! (local_user()))) {
@@ -276,7 +276,7 @@ class Nav
                        $nav['home'] = ['profile/' . $a->getLoggedInUserNickname(), DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')];
 
                        // Don't show notifications for public communities
-                       if (Session::get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
+                       if (DI::session()->get('page_flags', '') != User::PAGE_FLAGS_COMMUNITY) {
                                $nav['introductions'] = ['notifications/intros', DI::l10n()->t('Introductions'), '', DI::l10n()->t('Friend Requests')];
                                $nav['notifications'] = ['notifications',       DI::l10n()->t('Notifications'), '', DI::l10n()->t('Notifications')];
                                $nav['notifications']['all'] = ['notifications/system', DI::l10n()->t('See all notifications'), '', ''];
index 859dd8aa2e5c2e7e8ec579e1cc39e8da575e1c04..7c4d2974d35dc46a7216f2c7614784aeff8d84a7 100644 (file)
@@ -39,11 +39,6 @@ class Session
                return DI::session()->exists($name);
        }
 
-       public static function get($name, $defaults = null)
-       {
-               return DI::session()->get($name, $defaults);
-       }
-
        public static function pop($name, $defaults = null)
        {
                return DI::session()->pop($name, $defaults);
index b58de4efb14b1daf8b427627a6ebc9a7f0483124..d9467471f7489be89afb18ecbdfb8c6c3871a3ee 100644 (file)
@@ -683,7 +683,7 @@ class Profile
         */
        public static function getMyURL(): string
        {
-               return Session::get('my_url') ?? '';
+               return DI::session()->get('my_url') ?? '';
        }
 
        /**
index bfdeb7e5786446fbdcab93f629a002fcb2a129d4..d5f4f6d2fc72396e46a2aae7863dfdd6bcb98a8b 100644 (file)
@@ -307,7 +307,7 @@ class Network extends BaseModule
 
                self::$forumContactId = $this->parameters['contact_id'] ?? 0;
 
-               self::$selectedTab = Session::get('network-tab', DI::pConfig()->get(local_user(), 'network.view', 'selected_tab', ''));
+               self::$selectedTab = DI::session()->get('network-tab', DI::pConfig()->get(local_user(), 'network.view', 'selected_tab', ''));
 
                if (!empty($get['star'])) {
                        self::$selectedTab = 'star';
index 146e9382b8bb5beb24b151e9de4a979d6c9ecf9a..f8aeb4c762a5ed30cd9df63470340d39a8023c35 100644 (file)
@@ -46,8 +46,8 @@ class Delegation extends BaseModule
                $uid = local_user();
                $orig_record = User::getById(DI::app()->getLoggedInUserId());
 
-               if (Session::get('submanage')) {
-                       $user = User::getById(Session::get('submanage'));
+               if (DI::session()->get('submanage')) {
+                       $user = User::getById(DI::session()->get('submanage'));
                        if (DBA::isResult($user)) {
                                $uid = intval($user['uid']);
                                $orig_record = $user;
index 1a313cbfaecde41308109ecb0e1f8664df5756b8..2bf9b429be616c4c3728ef41906d4c41ae68da12 100644 (file)
@@ -139,7 +139,7 @@ class Status extends BaseProfile
                // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
                $condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
 
-               $last_updated_array = Session::get('last_updated', []);
+               $last_updated_array = DI::session()->get('last_updated', []);
 
                if (!empty($category)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
index aeada0871e68e0dc105c2b43c9446725d216e447..a711c674a39853f446f22d8bdef3c64fccd5df28 100644 (file)
@@ -77,7 +77,7 @@ class Delegation extends BaseSettings
                $user_id = $args->get(3);
 
                if ($action === 'add' && $user_id) {
-                       if (Session::get('submanage')) {
+                       if (DI::session()->get('submanage')) {
                                DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
                                DI::baseUrl()->redirect('settings/delegation');
                        }
@@ -99,7 +99,7 @@ class Delegation extends BaseSettings
                }
 
                if ($action === 'remove' && $user_id) {
-                       if (Session::get('submanage')) {
+                       if (DI::session()->get('submanage')) {
                                DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
                                DI::baseUrl()->redirect('settings/delegation');
                        }
index fe42b8718d3720ab5d1abc81786ea564b15a1aa6..81f496eea8a282ca1e365e9952f3715a67da7f6f 100644 (file)
@@ -157,7 +157,7 @@ class Display extends BaseSettings
                }
 
                $theme_selected        = $user['theme'] ?: $default_theme;
-               $mobile_theme_selected = Session::get('mobile-theme', $default_mobile_theme);
+               $mobile_theme_selected = DI::session()->get('mobile-theme', $default_mobile_theme);
 
                $itemspage_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_network'));
                $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : DI::config()->get('system', 'itemspage_network'));
index 3d7db0118077eb03122894a628c64881d492afcd..820f7e255a19f89ecc9dfd5cfaff927218d4ae18 100644 (file)
@@ -106,7 +106,7 @@ class Verify extends BaseSettings
                parent::content();
 
                $company = 'Friendica';
-               $holder = Session::get('my_address');
+               $holder = DI::session()->get('my_address');
                $secret = $this->pConfig->get(local_user(), '2fa', 'secret');
 
                $otpauthUrl = (new Google2FA())->getQRCodeUrl($company, $holder, $secret);
index b7dae9ec11ce2e8bc6a5e0556cdb44938ea77a42..4d6793605e783a39850585bb3af3f03d0d62b1d1 100644 (file)
@@ -66,7 +66,7 @@ class Profile extends BaseModule
                // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
                $sql_extra = Item::getPermissionsSQLByUserId($a->getProfileOwner());
 
-               $last_updated_array = Session::get('last_updated', []);
+               $last_updated_array = DI::session()->get('last_updated', []);
 
                $last_updated = $last_updated_array[$last_updated_key] ?? 0;
 
index 7300fd09b4f7bf99d0a7eb18836e8af4f8a7e6ce..bbce29672712ec7c7d298919541127e360ca462b 100644 (file)
@@ -217,7 +217,7 @@ class Post
                $edpost = false;
 
                if (local_user()) {
-                       if (Strings::compareLink(Session::get('my_url'), $item['author-link'])) {
+                       if (Strings::compareLink(DI::session()->get('my_url'), $item['author-link'])) {
                                if ($item['event-id'] != 0) {
                                        $edpost = ['events/event/' . $item['event-id'], DI::l10n()->t('Edit')];
                                } else {
@@ -434,9 +434,9 @@ class Post
                }
 
                // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
-               if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(Session::get('remote_comment'))) {
+               if (!local_user() && ($item['network'] != Protocol::DIASPORA) && !empty(DI::session()->get('remote_comment'))) {
                        $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('Remote comment'),
-                               str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
+                               str_replace('{uri}', urlencode($item['uri']), DI::session()->get('remote_comment'))];
 
                        // Ensure to either display the remote comment or the local activities
                        $buttons = [];
@@ -507,7 +507,7 @@ class Post
                        'location_html'   => $location_html,
                        'indent'          => $indent,
                        'shiny'           => $shiny,
-                       'owner_self'      => $item['author-link'] == Session::get('my_url'),
+                       'owner_self'      => $item['author-link'] == DI::session()->get('my_url'),
                        'owner_url'       => $this->getOwnerUrl(),
                        'owner_photo'     => DI::baseUrl()->remove(DI::contentItem()->getOwnerAvatar($item)),
                        'owner_name'      => $this->getOwnerName(),
index 863992c40d7803537de17f878ba16c7665884894..2913a1553317d98798ebb6ff41c1237b93de0261 100644 (file)
@@ -207,7 +207,7 @@ function frio_remote_nav(App $a, array &$nav_info)
                // get the homelink from $_SESSION
                $homelink = Profile::getMyURL();
                if (!$homelink) {
-                       $homelink = Session::get('visitor_home', '');
+                       $homelink = DI::session()->get('visitor_home', '');
                }
 
                // since $userinfo isn't available for the hook we write it to the nav array