Skip to content

Commit 72bb29c

Browse files
committed
TYPO3 9 integration fixed
This time it could work.
1 parent 5f8a81f commit 72bb29c

File tree

6 files changed

+108
-130
lines changed

6 files changed

+108
-130
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Bednarik\Cooluri\Integration;
3+
4+
/***************************************************************
5+
* Copyright notice
6+
*
7+
* (c) 2019 Jan Bednarik <info@bednarik.org>
8+
* All rights reserved
9+
*
10+
* This script is part of the TYPO3 project. The TYPO3 project is
11+
* free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* The GNU General Public License can be found at
17+
* http://www.gnu.org/copyleft/gpl.html.
18+
*
19+
* This script is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU General Public License for more details.
23+
*
24+
* This copyright notice MUST APPEAR in all copies of the script!
25+
***************************************************************/
26+
27+
28+
class CoolPageResolver extends \TYPO3\CMS\Frontend\Middleware\PageResolver
29+
{
30+
31+
public function process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface {
32+
$parameters = CoolUri::cool2params();
33+
if ($parameters === false) {
34+
return parent::process($request, $handler);
35+
}
36+
37+
$pageArguments = new \TYPO3\CMS\Core\Routing\PageArguments(
38+
$parameters['id'],
39+
(string)($parameters['type'] ?? '0'),
40+
$parameters,
41+
[],
42+
$request->getQueryParams()
43+
);
44+
45+
$this->controller->id = $pageArguments->getPageId();
46+
$this->controller->type = $pageArguments->getPageType() ?? $this->controller->type;
47+
$this->controller->cHash = $parameters['cHash'];
48+
49+
// merge the PageArguments with the request query parameters
50+
$queryParams = array_replace_recursive($request->getQueryParams(), $pageArguments->getArguments());
51+
$request = $request->withQueryParams($queryParams);
52+
$this->controller->setPageArguments($pageArguments);
53+
54+
// At this point, we later get further route modifiers
55+
// for bw-compat we update $GLOBALS[TYPO3_REQUEST] to be used later in TSFE.
56+
$GLOBALS['TYPO3_REQUEST'] = $request;
57+
58+
$this->controller->determineId();
59+
60+
// No access? Then remove user & Re-evaluate the page-id
61+
if ($this->controller->isBackendUserLoggedIn() && !$GLOBALS['BE_USER']->doesUserHaveAccess($this->controller->page, \TYPO3\CMS\Core\Type\Bitmask\Permission::PAGE_SHOW)) {
62+
unset($GLOBALS['BE_USER']);
63+
// Register an empty backend user as aspect
64+
$this->setBackendUserAspect(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Context::class), null);
65+
$this->controller->determineId();
66+
}
67+
68+
return $handler->handle($request);
69+
}
70+
}

Classes/Integration/CoolUri.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,21 @@ public static function getTranslateInstance()
6969
return $lt;
7070
}
7171

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

76-
if (!empty($params['pObj']->siteScript)) {
77-
$cond = $params['pObj']->siteScript && substr($params['pObj']->siteScript, 0, 9) != 'index.php' && substr($params['pObj']->siteScript, 0, 1) != '?';
78-
$paramsinurl = '/' . $params['pObj']->siteScript;
79-
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('SITESCRIPT: ' . $paramsinurl, 'CoolUri');
80-
} else {
81-
$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) != '?';
82-
$paramsinurl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI');
83-
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('REQUEST_URI: ' . $paramsinurl, 'CoolUri');
84-
}
77+
$siteScript = $request->getAttribute('normalizedParams')->getSiteScript();
78+
79+
$paramsinurl = '/' . $siteScript;
8580

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

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

9388
$lt = self::getTranslateInstance();
9489

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

125-
$pars = $lt->cool2params($paramsinurl);
126-
127-
$params['pObj']->id = $pars['id'];
128-
unset($pars['id']);
129-
$npars = self::extractArraysFromParams($pars);
130-
self::stripSlashesOnArray($npars);
131-
$params['pObj']->mergingWithGetVars($npars);
132-
133-
// Re-create QUERY_STRING from Get vars for use with typoLink()
134-
$_SERVER['QUERY_STRING'] = self::decodeSpURL_createQueryString($pars);
135-
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Resolved QS: ' . $_SERVER['QUERY_STRING'], 'CoolUri');
120+
return self::extractArraysFromParams($lt->cool2params($paramsinurl));
136121
}
122+
return false;
137123
}
138124

139125
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* An array consisting of implementations of middlewares for a middleware stack to be registered
4+
*
5+
* 'stackname' => [
6+
* 'middleware-identifier' => [
7+
* 'target' => classname or callable
8+
* 'before/after' => array of dependencies
9+
* ]
10+
* ]
11+
*/
12+
return [
13+
'frontend' => [
14+
'typo3/cms-frontend/page-resolver' => [
15+
'target' => \Bednarik\Cooluri\Integration\CoolPageResolver::class,
16+
'after' => [
17+
'typo3/cms-frontend/tsfe',
18+
'typo3/cms-frontend/authentication',
19+
'typo3/cms-frontend/backend-user-authentication',
20+
'typo3/cms-frontend/site',
21+
]
22+
],
23+
]
24+
];

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$EM_CONF[$_EXTKEY] = array(
44
'title' => 'CoolUri',
55
'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.',
6-
'version' => '1.2.1',
6+
'version' => '1.2.2',
77
'state' => 'stable',
88
'author' => 'Jan Bednarik',
99
'author_email' => 'info@bednarik.org',

ext_localconf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

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

1010
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']['cooluri'] = 'Bednarik\\Cooluri\\Integration\\BackendUtilityHook';
@@ -19,4 +19,4 @@
1919
'extension' => $_EXTKEY,
2020
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_cool1.xlf:mlang_scheduler_delete',
2121
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_cool1.xlf:mlang_scheduler_delete_desc'
22-
);
22+
);

test/class.tx_cooluritest_pi1.php

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)