Rework Module\ToggleMobile to check for local links
- Remove dependency on DI class - Remove dependency on request/session superglobals - Remove dependency on App class
This commit is contained in:
parent
148c1c7e1a
commit
8c06f96531
1 changed files with 26 additions and 15 deletions
|
@ -21,32 +21,43 @@
|
||||||
|
|
||||||
namespace Friendica\Module;
|
namespace Friendica\Module;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\BaseModule;
|
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)
|
* Toggles the mobile view (on/off)
|
||||||
*/
|
*/
|
||||||
class ToggleMobile extends BaseModule
|
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'])) {
|
$this->session = $session;
|
||||||
$_SESSION['show-mobile'] = false;
|
}
|
||||||
} else {
|
|
||||||
$_SESSION['show-mobile'] = true;
|
protected function rawContent(array $request = [])
|
||||||
|
{
|
||||||
|
$address = $request['address'] ?? '' ?: $this->baseUrl;
|
||||||
|
|
||||||
|
$uri = new Uri($address);
|
||||||
|
|
||||||
|
if (!$this->baseUrl->isLocalUri($uri)) {
|
||||||
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET['address'])) {
|
$this->session->set('show-mobile', !isset($request['off']));
|
||||||
$address = $_GET['address'];
|
|
||||||
} else {
|
|
||||||
$address = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$a->redirect($address);
|
System::externalRedirect((string)$uri);
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue