diff --git a/Classes/Integration/CoolPageResolver.php b/Classes/Integration/CoolPageResolver.php new file mode 100644 index 0000000..48be2f5 --- /dev/null +++ b/Classes/Integration/CoolPageResolver.php @@ -0,0 +1,70 @@ + + * 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); + } +} diff --git a/Classes/Integration/CoolUri.php b/Classes/Integration/CoolUri.php index 64b7fb1..e4f0061 100644 --- a/Classes/Integration/CoolUri.php +++ b/Classes/Integration/CoolUri.php @@ -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(); @@ -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'])) { @@ -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; } /** diff --git a/Configuration/RequestMiddlewares.php b/Configuration/RequestMiddlewares.php new file mode 100644 index 0000000..feb2517 --- /dev/null +++ b/Configuration/RequestMiddlewares.php @@ -0,0 +1,24 @@ + [ + * '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', + ] + ], + ] +]; diff --git a/ext_emconf.php b/ext_emconf.php index 528c026..e53561d 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -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', diff --git a/ext_localconf.php b/ext_localconf.php index 514c019..2b1ad17 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -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'; @@ -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' -); \ No newline at end of file +); diff --git a/test/class.tx_cooluritest_pi1.php b/test/class.tx_cooluritest_pi1.php deleted file mode 100644 index 9e31a9b..0000000 --- a/test/class.tx_cooluritest_pi1.php +++ /dev/null @@ -1,102 +0,0 @@ - - * 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! - ***************************************************************/ - -if (!class_exists('tslib_pibase')) { - require_once(PATH_tslib . 'class.tslib_pibase.php'); -} - -class tx_cooluritest_pi1 extends tslib_pibase { - - var $URLS = Array( - Array(22,'¶mD=100',Array()), - Array(24,'',Array()), - Array(22,'',Array('paramZ'=>100)), - Array(22,'',Array('paramZ'=>200)), - Array(24,'&array[k1]=foo¶mE=removed',Array('array'=>array('k3'=>'foo','k2'=>'bar','k5'=>123345))), - Array(23,'&L=1',Array('add'=>1)), - Array(23,'&L=1',Array('add'=>2)), - Array(25,'¶mD=view-list|page_id-142',Array('paramD'=>'view-list|page_id-142')), - Array(25,'&atParam[@atValue]=ATVAL',Array('atParam' => array('@atValue' => 'ATVAL'))), - Array(22,'¶mA=0¶mD=0',Array('paramA'=>'0','paramD'=>'0')), - Array(25,'¶mX=view-list|page_id-142',Array('paramX'=>'view-list|page_id-142')), - Array(25,'¶mA=FOO¶mB=6666'), - Array(22,'&tx_news_pi1[@widget_0][currentPage]=123') - ); - - function main($content, $conf) { - $GLOBALS['TSFE']->set_no_cache(); - - $GLOBALS['TYPO3_DB']->exec_DELETEquery('link_cache','1=1'); - $GLOBALS['TYPO3_DB']->exec_DELETEquery('link_oldlinks','1=1'); - - $lt = Link_Translate::getInstance(dirname(__FILE__).'/CoolUriConf.xml'); - $_SESSION['coolUriTransformerInstance'] = $lt; - - $links = Array(); - $links2 = Array(); - $links3 = Array(); - foreach ($this->URLS as $url) { - $links[] = $this->cObj->typolink_URL(Array('parameter'=>$url[0],'additionalParams'=>$url[1].$this->getToQS($url[2]))); - $t = $this->pi_linkToPage("foo",$url[0],'',$url[2]); - $links2[] = preg_replace('~.*href="([^"]+)".*~','\\1',$t); - $links3[] = $this->cObj->typolink('Foo',Array('parameter'=>$url[0],'additionalParams'=>$url[1].$this->getToQS($url[2]))); - } - $content = implode('
',$links); - $content .= '

'; - $content .= implode('
',$links2); - $content .= '

'; - $content .= implode('
',$links3); - - $params = array(); - foreach ($links as $i=>$l) { - - if (!empty($GLOBALS['TSFE']->config['config']['absRefPrefix'])) { - $l = preg_replace('!^'.$GLOBALS['TSFE']->config['config']['absRefPrefix'].'!','',$l); - } - - $cu = new tx_cooluri(); - $p = Array(); - $p['pObj'] = $GLOBALS['TSFE']; - $_SERVER['REQUEST_URI'] = $l; - $p['pObj']->siteScript = $l; - $curGet = $_GET; - $_GET = $this->URLS[$i][2]; - $cu->cool2params($p,$GLOBALS['TSFE']); - $r = print_r($_GET,true); - $params[] = htmlspecialchars($r); - $_GET = $curGet; - } - $content .= '

'.implode('
',$params); - - return $content; - } - - function getToQS($p) { - if (!$p) return ''; - return '&'.http_build_query($p); - } - -} - -?> \ No newline at end of file