Skip to content
Snippets Groups Projects
Commit 9d00dcc3 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] Remove totally stupid frontend link resolver code

parent ac61f97e
No related branches found
No related tags found
1 merge request!19Release 5.0.0
This commit is part of merge request !19. Comments created here will be created in the context of that merge request.
<?php
namespace SGalinski\SgRoutes\Middleware;
/**
*
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use SGalinski\SgRoutes\Service\DemoModeService;
use SGalinski\SgRoutes\Service\LicenceCheckService;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Resolver for generating frontend links
*
* @package SGalinski\SgRoutes\Middleware
* @author Kevin Ditscheid <kevin.ditscheid@sgalinski.de>
*/
class FrontendLinkResolver implements MiddlewareInterface {
/**
* Process an incoming server request.
*
* Processes an incoming server request in order to produce a response.
* If unable to produce the response itself, it may delegate to the provided
* request handler to do so.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
if (!LicenceCheckService::hasValidLicense() && !DemoModeService::isInDemoMode()) {
return $handler->handle($request);
}
$queryParams = $request->getQueryParams();
if (!isset($queryParams['tx_sgroutes_frontendlink'])) {
return $handler->handle($request);
}
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$response = new Response();
$response->getBody()
->write(
$contentObjectRenderer->typoLink(
'',
[
'parameter' => $queryParams['tx_sgroutes_frontendlink']['destination_url'],
'returnLast' => 'url'
]
)
);
return $response;
}
}
......@@ -32,6 +32,7 @@ use TYPO3\CMS\Core\Controller\ErrorPageController;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Http\Request;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
......@@ -39,6 +40,7 @@ use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Class SGalinski\SgRoutes\Service\RoutingService
......@@ -74,7 +76,7 @@ class RoutingService {
foreach ($routes as $route) {
$route['description'] = \trim($route['description']);
if ($route['description']) {
$htaccessEntries .= \preg_replace('/(^)/m', '#$1', $route['description']) . LF;
$htaccessEntries .= \preg_replace('/(^)/m', '# $1', $route['description']) . LF;
}
$directive = 'Redirect';
if ($route['use_regular_expression']) {
......@@ -88,29 +90,19 @@ class RoutingService {
\is_numeric($route['destination_url']) ||
strpos($route['destination_url'], 't3://') === 0
) {
$report = [
'error' => 0
];
$route['destination_url'] = GeneralUtility::getUrl(
GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/?' . HttpUtility::buildQueryString(
[
'tx_sgroutes_frontendlink' => [
'destination_url' => $route['destination_url']
]
]
),
0,
NULL,
$report
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$route['destination_url'] = $contentObjectRenderer->typoLink(
'',
[
'parameter' => $route['destination_url'],
'returnLast' => 'url'
]
);
if ($report['error'] !== 0) {
$route['destination_url'] = '';
}
}
if ($route['destination_url'] !== '') {
// only add the htaccess rule if there is a destination, because otherwise it will be 404 anyway
$htaccessEntries .= $directive . ' ' . $route['redirect_code'] . ' '
. $route['source_url'] . ' ' . $route['destination_url'] . LF;
. $route['source_url'] . ' ' . $route['destination_url'] . LF . LF;
}
}
}
......
......@@ -31,12 +31,6 @@ return [
'before' => [
'typo3/cms-frontend/page-resolver'
]
],
'sgalinski/sg-routes/frontendlink-resolver' => [
'target' => \SGalinski\SgRoutes\Middleware\FrontendLinkResolver::class,
'after' => [
'typo3/cms-frontend/tsfe'
]
]
]
];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment