Skip to content

Commit

Permalink
TYPO3 9 integration fixed
Browse files Browse the repository at this point in the history
This time it could work.
  • Loading branch information
bednee committed Dec 28, 2019
1 parent 5f8a81f commit 72bb29c
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 130 deletions.
70 changes: 70 additions & 0 deletions Classes/Integration/CoolPageResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
namespace Bednarik\Cooluri\Integration;

/***************************************************************
* Copyright notice
*
* (c) 2019 Jan Bednarik <info@bednarik.org>
* 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 2 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!
***************************************************************/


class CoolPageResolver extends \TYPO3\CMS\Frontend\Middleware\PageResolver
{

public function process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface {
$parameters = CoolUri::cool2params();
if ($parameters === false) {
return parent::process($request, $handler);
}

$pageArguments = new \TYPO3\CMS\Core\Routing\PageArguments(
$parameters['id'],
(string)($parameters['type'] ?? '0'),
$parameters,
[],
$request->getQueryParams()
);

$this->controller->id = $pageArguments->getPageId();
$this->controller->type = $pageArguments->getPageType() ?? $this->controller->type;
$this->controller->cHash = $parameters['cHash'];

// merge the PageArguments with the request query parameters
$queryParams = array_replace_recursive($request->getQueryParams(), $pageArguments->getArguments());
$request = $request->withQueryParams($queryParams);
$this->controller->setPageArguments($pageArguments);

// At this point, we later get further route modifiers
// for bw-compat we update $GLOBALS[TYPO3_REQUEST] to be used later in TSFE.
$GLOBALS['TYPO3_REQUEST'] = $request;

$this->controller->determineId();

// No access? Then remove user & Re-evaluate the page-id
if ($this->controller->isBackendUserLoggedIn() && !$GLOBALS['BE_USER']->doesUserHaveAccess($this->controller->page, \TYPO3\CMS\Core\Type\Bitmask\Permission::PAGE_SHOW)) {
unset($GLOBALS['BE_USER']);
// Register an empty backend user as aspect
$this->setBackendUserAspect(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Context::class), null);
$this->controller->determineId();
}

return $handler->handle($request);
}
}
36 changes: 11 additions & 25 deletions Classes/Integration/CoolUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,21 @@ public static function getTranslateInstance()
return $lt;
}

public static function cool2params($params, $ref)
public static function cool2params()
{
self::$pObj = & $ref;
/** @var $request \TYPO3\CMS\Core\Http\ServerRequest */
$request = $GLOBALS['TYPO3_REQUEST'];

if (!empty($params['pObj']->siteScript)) {
$cond = $params['pObj']->siteScript && substr($params['pObj']->siteScript, 0, 9) != 'index.php' && substr($params['pObj']->siteScript, 0, 1) != '?';
$paramsinurl = '/' . $params['pObj']->siteScript;
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('SITESCRIPT: ' . $paramsinurl, 'CoolUri');
} else {
$cond = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') && substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 1, 9) != 'index.php' && substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 1, 1) != '?';
$paramsinurl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI');
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('REQUEST_URI: ' . $paramsinurl, 'CoolUri');
}
$siteScript = $request->getAttribute('normalizedParams')->getSiteScript();

$paramsinurl = '/' . $siteScript;

// check if the only param is the same as the TYPO3 site root
if ($paramsinurl == substr(PATH_site, strlen(preg_replace('~/$~', '', $_SERVER['DOCUMENT_ROOT'])))) {
return;
return false;
}

if ($cond) {
if ($siteScript && substr($siteScript, 0, 9) != 'index.php' && substr($siteScript, 0, 1) != '?') {

$lt = self::getTranslateInstance();

Expand All @@ -99,7 +94,7 @@ public static function cool2params($params, $ref)
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_domain', 'domainName=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($domain, 'sys_domain') . ' AND hidden=0');
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
if (!$row) {
return; // Domain is not available, so no translation
return false; // Domain is not available, so no translation
}
if (empty(\Bednarik\Cooluri\Core\Translate::$conf->cache->prefix)) {
if ($row && !empty($row['redirectTo'])) {
Expand All @@ -122,18 +117,9 @@ public static function cool2params($params, $ref)
}
}

$pars = $lt->cool2params($paramsinurl);

$params['pObj']->id = $pars['id'];
unset($pars['id']);
$npars = self::extractArraysFromParams($pars);
self::stripSlashesOnArray($npars);
$params['pObj']->mergingWithGetVars($npars);

// Re-create QUERY_STRING from Get vars for use with typoLink()
$_SERVER['QUERY_STRING'] = self::decodeSpURL_createQueryString($pars);
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Resolved QS: ' . $_SERVER['QUERY_STRING'], 'CoolUri');
return self::extractArraysFromParams($lt->cool2params($paramsinurl));
}
return false;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* An array consisting of implementations of middlewares for a middleware stack to be registered
*
* 'stackname' => [
* 'middleware-identifier' => [
* 'target' => classname or callable
* 'before/after' => array of dependencies
* ]
* ]
*/
return [
'frontend' => [
'typo3/cms-frontend/page-resolver' => [
'target' => \Bednarik\Cooluri\Integration\CoolPageResolver::class,
'after' => [
'typo3/cms-frontend/tsfe',
'typo3/cms-frontend/authentication',
'typo3/cms-frontend/backend-user-authentication',
'typo3/cms-frontend/site',
]
],
]
];
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$EM_CONF[$_EXTKEY] = array(
'title' => 'CoolUri',
'description' => 'RealURL alternative. Have nice URLs instead of ugly with parameters. CoolUri has user-friendly XML configuration file. For simple setup, just use the one supplied with extension and you are ready to go.',
'version' => '1.2.1',
'version' => '1.2.2',
'state' => 'stable',
'author' => 'Jan Bednarik',
'author_email' => 'info@bednarik.org',
Expand Down
4 changes: 2 additions & 2 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc']['cooluri'] = 'Bednarik\\Cooluri\\Integration\\CoolUri->params2cool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc']['cooluri'] = 'Bednarik\\Cooluri\\Integration\\CoolUri->cool2params';

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc']['cooluri'] = 'Bednarik\\Cooluri\\Integration\\CoolUri->goForRedirect';

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']['cooluri'] = 'Bednarik\\Cooluri\\Integration\\BackendUtilityHook';
Expand All @@ -19,4 +19,4 @@
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_cool1.xlf:mlang_scheduler_delete',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_cool1.xlf:mlang_scheduler_delete_desc'
);
);
102 changes: 0 additions & 102 deletions test/class.tx_cooluritest_pi1.php

This file was deleted.

0 comments on commit 72bb29c

Please sign in to comment.