From 8517605baef1c3849c1e0f4c2ea856f1b5dd8516 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Sat, 17 Aug 2024 21:15:26 +0200 Subject: [PATCH 1/5] compatibility TYPO3 12 and 13 --- ChangeLog | 4 ++ Classes/Base/TranslationBase.php | 44 +++++++++++-------- .../SessionHandler/Typo3SessionHandler.php | 22 ++++------ ext_emconf.php | 2 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d52c88d..a82ace95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ +2024-08-17 Franz Holzinger + * TYPO3 13 does not allow to set the property dontSetCookie of frontend.user + * TYPO3 13 demands frontend.typoscript + 2024-08-09 Franz Holzinger * add class JambageCom\Div2007\Compatibility\AbstractPlugin as replacement for TYPO3\CMS\Frontend\Plugin\AbstractPlugin diff --git a/Classes/Base/TranslationBase.php b/Classes/Base/TranslationBase.php index 1512dc26..6220bf4c 100644 --- a/Classes/Base/TranslationBase.php +++ b/Classes/Base/TranslationBase.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Http\ApplicationType; +use TYPO3\CMS\Core\Localization\Locales; use TYPO3\CMS\Core\Localization\LocalizationFactory; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Site\Entity\Site; @@ -26,6 +27,7 @@ use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -65,21 +67,28 @@ public function init( ): void { $conf = []; $typo3Language = $this->getLanguage(); + $this->setLocalLangKey($typo3Language); $isFrontend = (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()); if ($isFrontend) { - $tsfe = $this->getTypoScriptFrontendController(); - if ( - $tsfe instanceof TypoScriptFrontendController && - $tsfe->tmpl instanceof TemplateService && - is_array($tsfe->tmpl->setup) - ) { - $conf = $tsfe->tmpl->setup['lib.']['div2007.'] ?? ''; + $typo3VersionArray = + VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $typo3VersionMain = $typo3VersionArray['version_main']; + $conf = []; + if ($typo3VersionMain < 12) { + $tsfe = $this->getTypoScriptFrontendController(); + if ( + $tsfe instanceof TypoScriptFrontendController && + $tsfe->tmpl instanceof TemplateService && + is_array($tsfe->tmpl->setup) + ) { + $conf = $tsfe->tmpl->setup['lib.']['div2007.'] ?? ''; + } + } else { + $conf = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray()['plugin.']['div2007.'] ?? []; } } - $this->setLocalLangKey($typo3Language); - if ($extensionKey != '') { $this->extensionKey = $extensionKey; } @@ -191,21 +200,20 @@ public function needsInit() public function getLanguage() { $typo3Language = 'en'; - $isFrontend = (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()); + $request = $GLOBALS['TYPO3_REQUEST']; + $isFrontend = (ApplicationType::fromRequest($request)->isFrontend()); if ($isFrontend) { - $tsfe = $this->getTypoScriptFrontendController(); - if ( - $tsfe instanceof TypoScriptFrontendController - ) { - $typo3Language = $tsfe->getLanguage()->getTwoLetterIsoCode(); + $language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage(); + if ($language->hasCustomTypo3Language()) { + $locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language()); + } else { + $locale = $language->getLocale(); } + $typo3Language = $locale->getLanguageCode(); } else { $currentSite = $this->getCurrentSite(); $currentSiteLanguage = $this->getCurrentSiteLanguage() ?? $currentSite?->getDefaultLanguage(); - debug (get_class($currentSiteLanguage), 'Klasse von $currentSiteLanguage'); - // $targetLanguageId = $currentSiteLanguage?->getLanguageId() ?? 0; $typo3Language = $currentSiteLanguage?->getTypo3Language(); - debug ($typo3Language, 'getLanguage +++ $typo3Language'); } return $typo3Language; diff --git a/Classes/SessionHandler/Typo3SessionHandler.php b/Classes/SessionHandler/Typo3SessionHandler.php index 6b6ac9f8..2bbe0039 100644 --- a/Classes/SessionHandler/Typo3SessionHandler.php +++ b/Classes/SessionHandler/Typo3SessionHandler.php @@ -43,18 +43,10 @@ class Typo3SessionHandler extends AbstractSessionHandler implements SessionHandl public function __construct($setCookie = true) { if (basename($_SERVER['PHP_SELF']) !== 'phpunit') { - if ( - isset($GLOBALS['TSFE']) && - is_object($GLOBALS['TSFE']) && - isset($GLOBALS['TSFE']->fe_user) - ) { - $this->frontendUser = $GLOBALS['TSFE']->fe_user; - } else { - $detail = ''; - if (isset($GLOBALS['TSFE'])) { - $detail = '->fe_user'; - } - throw new \RuntimeException('Extension ' . DIV2007_EXT . ' Typo3SessionHandler: Empty $GLOBALS[\'TSFE\']' . $detail . ' ', 1612216764); + $this->frontendUser = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); + + if (empty($this->frontendUser)) { + throw new \RuntimeException('Extension ' . DIV2007_EXT . ' Typo3SessionHandler: Empty attribute frontend.user' . $detail . ' ', 1612216764); } if ($setCookie) { @@ -65,7 +57,11 @@ public function __construct($setCookie = true) public function allowCookie(): void { - $this->frontendUser->dontSetCookie = false; + $vars = get_class_vars(get_class($this->frontendUser)); + + if (isset($vars['dontSetCookie'])) { + $this->frontendUser->dontSetCookie = false; + } } /** diff --git a/ext_emconf.php b/ext_emconf.php index 31914d8a..1d7e60a1 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -6,7 +6,7 @@ 'title' => 'Extension Library since 2007', 'description' => 'This library offers classes and functions to other TYPO3 extensions. Replacement for tslib_pibase methods.', 'category' => 'misc', - 'version' => '2.2.1', + 'version' => '2.2.2', 'state' => 'stable', 'author' => 'Franz Holzinger', 'author_email' => 'franz@ttproducts.de', From 8deacd96591c62e7083af2e0c5567638d4330a11 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Mon, 19 Aug 2024 15:47:09 +0200 Subject: [PATCH 2/5] use getAttribute('frontend.user') --- ChangeLog | 4 +++- Classes/Captcha/Freecap.php | 5 +++-- Classes/Database/CoreQuery.php | 6 ++++-- Classes/Utility/SystemUtility.php | 7 +++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index a82ace95..ff1e7a67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ -2024-08-17 Franz Holzinger + +2024-08-19 Franz Holzinger + * TYPO3 12: use $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); * TYPO3 13 does not allow to set the property dontSetCookie of frontend.user * TYPO3 13 demands frontend.typoscript diff --git a/Classes/Captcha/Freecap.php b/Classes/Captcha/Freecap.php index 6fa52ee3..f6916457 100644 --- a/Classes/Captcha/Freecap.php +++ b/Classes/Captcha/Freecap.php @@ -165,8 +165,9 @@ protected function initialize() */ protected function getFrontendUser() { - if ($GLOBALS['TSFE']->fe_user) { - return $GLOBALS['TSFE']->fe_user; + $frontendUser = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); + if ($frontendUser) { + return $frontendUser; } throw new SessionNotFoundException('No frontend user found in session!'); } diff --git a/Classes/Database/CoreQuery.php b/Classes/Database/CoreQuery.php index 589e2ac7..bb3cc4e9 100644 --- a/Classes/Database/CoreQuery.php +++ b/Classes/Database/CoreQuery.php @@ -190,7 +190,8 @@ public static function DBgetInsert($table, $pid, array $dataArray, $fieldList, $ * * @param string $table The table name, found in $GLOBALS['TCA'] * @param array $row The record data array for the record in question - * @param array $feUserRow The array of the fe_user which is evaluated, typ. $GLOBALS['TSFE']->fe_user->user + * @param array $feUserRow The array of the fe_user which is evaluated, typ. + * $frontendUser = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); * @param string $allowedGroups Commalist of the only fe_groups uids which may edit the record. If not set, then the usergroup field of the fe_user is used. * @param bool|int $feEditSelf TRUE, if the fe_user may edit his own fe_user record * @@ -232,7 +233,8 @@ public static function DBmayFEUserEdit($table, $row, $feUserRow, $allowedGroups * rather for a select query selecting all records which the user HAS access to. * * @param string $table The table name - * @param array $feUserRow The array of the fe_user which is evaluated, typ. $GLOBALS['TSFE']->fe_user->user + * @param array $feUserRow The array of the fe_user which is evaluated, typ. + * $frontendUser = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); * @param string $allowedGroups Commalist of the only fe_groups uids which may edit the record. If not set, then the usergroup field of the fe_user is used. * @param bool|int $feEditSelf TRUE, if the fe_user may edit his own fe_user record * diff --git a/Classes/Utility/SystemUtility.php b/Classes/Utility/SystemUtility.php index 43849e37..ce63426e 100644 --- a/Classes/Utility/SystemUtility.php +++ b/Classes/Utility/SystemUtility.php @@ -91,13 +91,12 @@ public static function userProcess( public static function fetchFeGroups() { $result = []; + $feUserRecord = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user')->user; if ( - isset($GLOBALS['TSFE']->fe_user) && - isset($GLOBALS['TSFE']->fe_user->user) && - isset($GLOBALS['TSFE']->fe_user->user['usergroup']) + isset($feUserRecord['usergroup']) ) { - $result = explode(',', $GLOBALS['TSFE']->fe_user->user['usergroup']); + $result = explode(',', $feUserRecord['usergroup']); } return $result; From 2f0041ee3440514fdc960aeb429292b6451c9ecc Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Mon, 19 Aug 2024 16:39:13 +0200 Subject: [PATCH 3/5] add removed method getTreeList to class FrontendUtility --- ChangeLog | 2 +- Classes/Utility/FrontendUtility.php | 55 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ff1e7a67..1debff77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,10 @@ - 2024-08-19 Franz Holzinger * TYPO3 12: use $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user'); * TYPO3 13 does not allow to set the property dontSetCookie of frontend.user * TYPO3 13 demands frontend.typoscript + * TYPO3 13: add removed method getTreeList to class FrontendUtility 2024-08-09 Franz Holzinger * add class JambageCom\Div2007\Compatibility\AbstractPlugin as replacement for diff --git a/Classes/Utility/FrontendUtility.php b/Classes/Utility/FrontendUtility.php index cdeef96d..d7e5fee3 100644 --- a/Classes/Utility/FrontendUtility.php +++ b/Classes/Utility/FrontendUtility.php @@ -1358,6 +1358,61 @@ public static function getBorderAttribute($borderAttr) return ''; } + /*********************************************** + * + * Database functions, making of queries + * + ***********************************************/ + /** + * Generates a list of Page-uid's from $id. List does not include $id itself + * (unless the id specified is negative in which case it does!) + * The only pages WHICH PREVENTS DECENDING in a branch are + * - deleted pages, + * - pages in a recycler (doktype = 255) or of the Backend User Section (doktpe = 6) type + * - pages that has the extendToSubpages set, WHERE start/endtime, hidden + * and fe_users would hide the records. + * Apart from that, pages with enable-fields excluding them, will also be + * removed. HOWEVER $dontCheckEnableFields set will allow + * enableFields-excluded pages to be included anyway - including + * extendToSubpages sections! + * Mount Pages are also descended but notice that these ID numbers are not + * useful for links unless the correct MPvar is set. + * + * @param int $id The id of the start page from which point in the page tree to descend. IF NEGATIVE the id itself is included in the end of the list (only if $begin is 0) AND the output does NOT contain a last comma. Recommended since it will resolve the input ID for mount pages correctly and also check if the start ID actually exists! + * @param int $depth The number of levels to descend. If you want to descend infinitely, just set this to 100 or so. Should be at least "1" since zero will just make the function return (no descend...) + * @param int $begin Is an optional integer that determines at which level in the tree to start collecting uid's. Zero means 'start right away', 1 = 'next level and out' + * @param bool $dontCheckEnableFields See function description + * @param string $addSelectFields Additional fields to select. Syntax: ",[fieldname],[fieldname],... + * @param string $moreWhereClauses Additional where clauses. Syntax: " AND [fieldname]=[value] AND ... + * @param array $prevId_array array of IDs from previous recursions. In order to prevent infinite loops with mount pages. + * @param int $recursionLevel Internal: Zero for the first recursion, incremented for each recursive call. + * @return string Returns the list of ids as a comma separated string + */ + public static function getTreeList($id, $depth, $begin = 0, $dontCheckEnableFields = false, $addSelectFields = '', $moreWhereClauses = '', array $prevId_array = [], $recursionLevel = 0) + { + $addCurrentPageId = false; + $id = (int)$id; + if ($id < 0) { + $id = abs($id); + $addCurrentPageId = true; + } + $cObj = static::getContentObjectRenderer(); + + $pageRepository = static::getTypoScriptFrontendController()->sys_page; + if ($dontCheckEnableFields) { + $backupEnableFields = $pageRepository->where_hid_del; + $pageRepository->where_hid_del = ''; + } + $result = $pageRepository->getDescendantPageIdsRecursive($id, (int)$depth, (int)$begin, [], (bool)$dontCheckEnableFields); + if ($dontCheckEnableFields) { + $pageRepository->where_hid_del = $backupEnableFields; + } + if ($addCurrentPageId) { + $result = array_merge([$id], $result); + } + return implode(',', $result); + } + public static function setTypoScriptFrontendController(TypoScriptFrontendController $typoScriptFrontendController): void { static::$typoScriptFrontendController = $typoScriptFrontendController; From ca7c79c20beb7541d84434004130b6c3e99c6bb5 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Mon, 19 Aug 2024 18:20:26 +0200 Subject: [PATCH 4/5] replacement for GeneralUtility::_GP --- ChangeLog | 2 + Classes/Api/Frontend.php | 13 ++---- Classes/Api/FrontendApi.php | 65 ++++++++++++++++++++--------- Classes/Utility/ControlUtility.php | 10 +++-- Classes/Utility/FrontendUtility.php | 17 ++++---- 5 files changed, 66 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1debff77..22a9abdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * TYPO3 13 does not allow to set the property dontSetCookie of frontend.user * TYPO3 13 demands frontend.typoscript * TYPO3 13: add removed method getTreeList to class FrontendUtility + * compatibility: new method JambageCom\Div2007\Api\FrontendApi::getParameter as + replacement for GeneralUtility::_GP 2024-08-09 Franz Holzinger * add class JambageCom\Div2007\Compatibility\AbstractPlugin as replacement for diff --git a/Classes/Api/Frontend.php b/Classes/Api/Frontend.php index 4d67ad30..476774d2 100644 --- a/Classes/Api/Frontend.php +++ b/Classes/Api/Frontend.php @@ -34,6 +34,8 @@ use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use JambageCom\Div2007\Api\FrontendApi; + class Frontend implements SingletonInterface { /** @@ -130,15 +132,8 @@ public function getTypoScriptFrontendController() return $this->typoScriptFrontendController; } - $id = ''; - if (method_exists(GeneralUtility::class, '_GP')) { - $id = (int)GeneralUtility::_GP('id'); - } - - $type = ''; - if (method_exists(GeneralUtility::class, '_GP')) { - $type = (int)GeneralUtility::_GP('type'); - } + $id = (int) FrontendApi::getParameter('id'); + $type = (int) FrontendApi::getParameter('type'); // This usually happens when typolink is created by the TYPO3 Backend, where no TSFE object // is there. This functionality is currently completely internal, as these links cannot be diff --git a/Classes/Api/FrontendApi.php b/Classes/Api/FrontendApi.php index a7c87e0b..314bc893 100644 --- a/Classes/Api/FrontendApi.php +++ b/Classes/Api/FrontendApi.php @@ -41,6 +41,8 @@ class FrontendApi * This method is needed only for Ajax calls. * You can use $GLOBALS['TSFE']->id or $GLOBALS['TSFE']->determineId($request) instead of this method. * + * The first parameter can be the request object + * * @return int */ public static function getPageId(...$params) @@ -48,31 +50,13 @@ public static function getPageId(...$params) $request = null; $site = null; $result = 0; - - if (method_exists(GeneralUtility::class, '_GP')) { - $result = (int)GeneralUtility::_GP('id'); - if ( - $result - ) { - return $result; - } - } - if ( isset($params[0]) && $params[0] instanceof ServerRequestInterface ) { $request = $params[0]; - } elseif (isset($GLOBALS['TYPO3_REQUEST'])) { - $request = $GLOBALS['TYPO3_REQUEST']; - } - - if ( - $request === null && - isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']) && - is_object($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']) - ) { - $request = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']; + } else { + $request = static::getGlobalRequestObject(); } if ($request instanceof ServerRequestInterface) { @@ -124,4 +108,45 @@ public static function getStandaloneView($extensionKey, $templateNameAndPath): S return $view; } + + /** + * Read the parameter. Replacement for GeneralUtility::_GP. + * + * The second parameter can be the request object + * + * @return string + */ + public static function getParameter($param, ...$params) + { + $result = null; + $request = null; + if ( + isset($params[0]) && + $params[0] instanceof ServerRequestInterface + ) { + $request = $params[0]; + } else { + $request = static::getGlobalRequestObject(); + } + + if (is_object($request)) { + $result = $request->getParsedBody()[$param] ?? $request->getQueryParams()[$param] ?? null; + } + return $result; + } + + public static getGlobalRequestObject() + { + $request = null; + if (isset($GLOBALS['TYPO3_REQUEST'])) { + $request = $GLOBALS['TYPO3_REQUEST']; + } elseif ( + isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']) && + is_object($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']) && + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST'] instanceof ServerRequestInterface + ) { + $request = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][DIV2007_EXT]['TYPO3_REQUEST']; + } + return $request; + } } diff --git a/Classes/Utility/ControlUtility.php b/Classes/Utility/ControlUtility.php index 1bf35fcc..8bac2a3b 100644 --- a/Classes/Utility/ControlUtility.php +++ b/Classes/Utility/ControlUtility.php @@ -26,11 +26,13 @@ * @package TYPO3 * @subpackage div2007 */ -use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use JambageCom\Div2007\Api\FrontendApi; + class ControlUtility { /** @@ -46,7 +48,7 @@ public static function readGP($variable, $prefixId = '', $htmlSpecialChars = tru $variable != '' ) { if ($prefixId != '') { - $value = GeneralUtility::_GP($prefixId); + $value = FrontendApi::getParameter($prefixId); if ( isset($value) && is_array($value) && @@ -55,10 +57,10 @@ public static function readGP($variable, $prefixId = '', $htmlSpecialChars = tru $result = $value[$variable]; } } else { - $result = GeneralUtility::_GP($variable); + $result = FrontendApi::getParameter($variable); } } elseif ($prefixId != '') { - $result = GeneralUtility::_GP($prefixId); + $result = FrontendApi::getParameter($prefixId); } if ($htmlSpecialChars && isset($result)) { diff --git a/Classes/Utility/FrontendUtility.php b/Classes/Utility/FrontendUtility.php index d7e5fee3..005064b9 100644 --- a/Classes/Utility/FrontendUtility.php +++ b/Classes/Utility/FrontendUtility.php @@ -24,20 +24,21 @@ * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use JambageCom\Div2007\Api\FrontendApi; -use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Core\Environment; -use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; -use JambageCom\Div2007\Base\BrowserBase; -use JambageCom\Div2007\Base\TranslationBase; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; -use JambageCom\Div2007\Api\Frontend; -use TYPO3\CMS\Frontend\Resource\FilePathSanitizer; -use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; +use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\Resource\FilePathSanitizer; + +use JambageCom\Div2007\Api\Frontend; +use JambageCom\Div2007\Api\FrontendApi; +use JambageCom\Div2007\Base\BrowserBase; +use JambageCom\Div2007\Base\TranslationBase; /** * front end functions. From fd8995f89ca990e845ae8ab806d8357b7eb5cef9 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Wed, 21 Aug 2024 23:05:23 +0200 Subject: [PATCH 5/5] use lastTypoLinkResult instead of lastTypoLinkUrl --- ChangeLog | 2 +- Classes/Api/Frontend.php | 12 +++----- Classes/Api/FrontendApi.php | 37 +++++++++++++++++++++--- Classes/Compatibility/AbstractPlugin.php | 9 ++++-- Classes/Utility/ControlUtility.php | 6 ++-- Classes/Utility/FrontendUtility.php | 4 +-- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22a9abdb..e282654b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,7 @@ * TYPO3 13 does not allow to set the property dontSetCookie of frontend.user * TYPO3 13 demands frontend.typoscript * TYPO3 13: add removed method getTreeList to class FrontendUtility - * compatibility: new method JambageCom\Div2007\Api\FrontendApi::getParameter as + * compatibility: new method JambageCom\Div2007\Api\FrontendApi::getParameterMerged as replacement for GeneralUtility::_GP 2024-08-09 Franz Holzinger diff --git a/Classes/Api/Frontend.php b/Classes/Api/Frontend.php index 476774d2..814a805a 100644 --- a/Classes/Api/Frontend.php +++ b/Classes/Api/Frontend.php @@ -61,12 +61,8 @@ public function __construct($typoScriptFrontendController = '') $this->typoScriptFrontendController = $GLOBALS['TSFE']; } - if ( - !empty($this->typoScriptFrontendController) && - $this->typoScriptFrontendController instanceof TypoScriptFrontendController - ) { - $this->frontendUser = $this->typoScriptFrontendController->fe_user; - } + $request = FrontendApi::getGlobalRequestObject(); + $this->frontendUser = $request->getAttribute('frontend.user'); } /** @@ -132,8 +128,8 @@ public function getTypoScriptFrontendController() return $this->typoScriptFrontendController; } - $id = (int) FrontendApi::getParameter('id'); - $type = (int) FrontendApi::getParameter('type'); + $id = (int) FrontendApi::getParameterMerged('id'); + $type = (int) FrontendApi::getParameterMerged('type'); // This usually happens when typolink is created by the TYPO3 Backend, where no TSFE object // is there. This functionality is currently completely internal, as these links cannot be diff --git a/Classes/Api/FrontendApi.php b/Classes/Api/FrontendApi.php index 314bc893..7174f8aa 100644 --- a/Classes/Api/FrontendApi.php +++ b/Classes/Api/FrontendApi.php @@ -27,11 +27,12 @@ * @subpackage div2007 */ use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Routing\SiteMatcher; -use TYPO3\CMS\Core\Site\SiteFinder; +use TYPO3\CMS\Core\Routing\RouteNotFoundException; use TYPO3\CMS\Core\Routing\SiteRouteResult; +use TYPO3\CMS\Core\Routing\SiteMatcher; use TYPO3\CMS\Core\Site\Entity\Site; -use TYPO3\CMS\Core\Routing\RouteNotFoundException; +use TYPO3\CMS\Core\Site\SiteFinder; +use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -135,7 +136,35 @@ public static function getParameter($param, ...$params) return $result; } - public static getGlobalRequestObject() + /** + * Read the parameter. Replacement for GeneralUtility::_GP. + * + * The second parameter can be the request object + * + * @return string + */ + public static function getParameterMerged($param, ...$params) + { + $getMergedWithPost = null; + $request = null; + if ( + isset($params[0]) && + $params[0] instanceof ServerRequestInterface + ) { + $request = $params[0]; + } else { + $request = static::getGlobalRequestObject(); + } + + if (is_object($request)) { + $getMergedWithPost = $request->getQueryParams()[$param] ?? []; + ArrayUtility::mergeRecursiveWithOverrule($getMergedWithPost, $request->getParsedBody()[$param] ?? []); + } + return $getMergedWithPost; + } + + + public static function getGlobalRequestObject() { $request = null; if (isset($GLOBALS['TYPO3_REQUEST'])) { diff --git a/Classes/Compatibility/AbstractPlugin.php b/Classes/Compatibility/AbstractPlugin.php index 5e5ca971..f14fc029 100644 --- a/Classes/Compatibility/AbstractPlugin.php +++ b/Classes/Compatibility/AbstractPlugin.php @@ -226,13 +226,13 @@ class AbstractPlugin */ public function __construct($_ = null, TypoScriptFrontendController $frontendController = null) { + $request = $GLOBALS['TYPO3_REQUEST']; $this->frontendController = $frontendController ?: $GLOBALS['TSFE']; $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); // Setting piVars: if ($this->prefixId) { $this->piVars = self::getRequestPostOverGetParameterWithPrefix($this->prefixId); } - $request = $GLOBALS['TYPO3_REQUEST']; $language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage(); if ($language->hasCustomTypo3Language()) { $locale = GeneralUtility::makeInstance(Locales::class)->createLocale($language->getTypo3Language()); @@ -1376,8 +1376,11 @@ public function pi_getFFvalueFromSheetArray($sheetArray, $fieldNameArr, $value) */ private static function getRequestPostOverGetParameterWithPrefix($parameter) { - $postParameter = isset($_POST[$parameter]) && is_array($_POST[$parameter]) ? $_POST[$parameter] : []; - $getParameter = isset($_GET[$parameter]) && is_array($_GET[$parameter]) ? $_GET[$parameter] : []; + $request = $GLOBALS['TYPO3_REQUEST']; + $postParameter = $request->getParsedBody()[$parameter] ?? []; + $postParameter = is_array($postParameter) ? $postParameter : []; + $getParameter = $request->getQueryParams()[$parameter] ?? []; + $getParameter = is_array($getParameter) ? $getParameter : []; $mergedParameters = $getParameter; ArrayUtility::mergeRecursiveWithOverrule($mergedParameters, $postParameter); return $mergedParameters; diff --git a/Classes/Utility/ControlUtility.php b/Classes/Utility/ControlUtility.php index 8bac2a3b..ad81ba26 100644 --- a/Classes/Utility/ControlUtility.php +++ b/Classes/Utility/ControlUtility.php @@ -48,7 +48,7 @@ public static function readGP($variable, $prefixId = '', $htmlSpecialChars = tru $variable != '' ) { if ($prefixId != '') { - $value = FrontendApi::getParameter($prefixId); + $value = FrontendApi::getParameterMerged($prefixId); if ( isset($value) && is_array($value) && @@ -57,10 +57,10 @@ public static function readGP($variable, $prefixId = '', $htmlSpecialChars = tru $result = $value[$variable]; } } else { - $result = FrontendApi::getParameter($variable); + $result = FrontendApi::getParameterMerged($variable); } } elseif ($prefixId != '') { - $result = FrontendApi::getParameter($prefixId); + $result = FrontendApi::getParameterMerged($prefixId); } if ($htmlSpecialChars && isset($result)) { diff --git a/Classes/Utility/FrontendUtility.php b/Classes/Utility/FrontendUtility.php index 005064b9..a85ed60f 100644 --- a/Classes/Utility/FrontendUtility.php +++ b/Classes/Utility/FrontendUtility.php @@ -1067,7 +1067,7 @@ public static function getTypoLink( $paramsNew = $urlParameters; } $conf['additionalParams'] = $paramsOld . $paramsNew; - $result = $cObj->typolink($label, $conf); + $result = $cObj->typoLink($label, $conf); } else { $result = 'error in call of \JambageCom\Div2007\Utility\FrontendUtility::getTypoLink: parameter $cObj is not an object'; } @@ -1108,7 +1108,7 @@ public static function getTypoLink_URL( ); if ($result !== false) { - $result = $cObj->lastTypoLinkUrl; + $result = $cObj->lastTypoLinkResult; } } else { $out = 'error in call of \JambageCom\Div2007\Utility\FrontendUtility::getTypoLink_URL: parameter $cObj is not an object';