]> git.mxchange.org Git - friendica.git/commitdiff
Rework Module\ToggleMobile to check for local links
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 25 Jul 2023 21:14:15 +0000 (23:14 +0200)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 26 Jul 2023 17:11:39 +0000 (19:11 +0200)
- Remove dependency on DI class
- Remove dependency on request/session superglobals
- Remove dependency on App class

src/Module/ToggleMobile.php

index 2408ef7f3d7b2048e69114caa6315061defa2ed3..193f4566c73aa0390cff4cb4b6403fcfb674b647 100644 (file)
 
 namespace Friendica\Module;
 
+use Friendica\App;
 use Friendica\BaseModule;
-use Friendica\DI;
+use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleSessions;
+use Friendica\Core\System;
+use Friendica\Network\HTTPException\BadRequestException;
+use Friendica\Util;
+use GuzzleHttp\Psr7\Uri;
+use Psr\Log\LoggerInterface;
 
 /**
  * Toggles the mobile view (on/off)
  */
 class ToggleMobile extends BaseModule
 {
-       protected function content(array $request = []): string
+       /** @var IHandleSessions */
+       private $session;
+
+       public function __construct(IHandleSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
        {
-               $a = DI::app();
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               if (isset($_GET['off'])) {
-                       $_SESSION['show-mobile'] = false;
-               } else {
-                       $_SESSION['show-mobile'] = true;
-               }
+               $this->session = $session;
+       }
+
+       protected function rawContent(array $request = [])
+       {
+               $address = $request['address'] ?? '' ?: $this->baseUrl;
+
+               $uri = new Uri($address);
 
-               if (isset($_GET['address'])) {
-                       $address = $_GET['address'];
-               } else {
-                       $address = '';
+               if (!$this->baseUrl->isLocalUri($uri)) {
+                       throw new BadRequestException();
                }
 
-               $a->redirect($address);
+               $this->session->set('show-mobile', !isset($request['off']));
 
-               return '';
+               System::externalRedirect((string)$uri);
        }
 }