Skip to content

Commit

Permalink
Merge pull request #78 from franzholz/develop
Browse files Browse the repository at this point in the history
compatibility TYPO3 12 and 13 issues
  • Loading branch information
franzholz authored Aug 21, 2024
2 parents 83b8a65 + fd8995f commit 28bccfb
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 95 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@


2024-08-19 Franz Holzinger <franz@ttproducts.de>
* 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
* compatibility: new method JambageCom\Div2007\Api\FrontendApi::getParameterMerged as
replacement for GeneralUtility::_GP

2024-08-09 Franz Holzinger <franz@ttproducts.de>
* add class JambageCom\Div2007\Compatibility\AbstractPlugin as replacement for
TYPO3\CMS\Frontend\Plugin\AbstractPlugin
Expand Down
21 changes: 6 additions & 15 deletions Classes/Api/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -59,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');
}

/**
Expand Down Expand Up @@ -130,15 +128,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::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
Expand Down
100 changes: 77 additions & 23 deletions Classes/Api/FrontendApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,38 +42,22 @@ 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)
{
$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) {
Expand Down Expand Up @@ -124,4 +109,73 @@ 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;
}

/**
* 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'])) {
$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;
}
}
44 changes: 26 additions & 18 deletions Classes/Base/TranslationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

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;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
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;


Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions Classes/Captcha/Freecap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down
9 changes: 6 additions & 3 deletions Classes/Compatibility/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions Classes/Database/CoreQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
22 changes: 9 additions & 13 deletions Classes/SessionHandler/Typo3SessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

/**
Expand Down
Loading

0 comments on commit 28bccfb

Please sign in to comment.