diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index af31b713b91a5be78f9761730581cec42dc328b1..95dbdf5436248466734c1f14f46505dc77eb23f7 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -29,6 +29,7 @@ namespace SGalinski\SgNews\Controller; use RuntimeException; use SGalinski\SgNews\Domain\Model\Category; use SGalinski\SgNews\Domain\Model\News; +use SGalinski\SgNews\Utility\ExtensionUtility; use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -59,8 +60,7 @@ abstract class AbstractController extends ActionController { */ public function initializeAction() { $extensionKey = $this->request->getControllerExtensionKey(); - $serializedConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]; - $this->extensionConfiguration = unserialize($serializedConfiguration, [FALSE]); + $this->extensionConfiguration = ExtensionUtility::getExtensionConfiguration($extensionKey); parent::initializeAction(); } diff --git a/Classes/Service/LicensingService.php b/Classes/Service/LicensingService.php index 92b72fefd8732f818548eb7f8bd1ec29fc60bae6..3b9343580f67017205af4545f84dc88a044ac3e2 100644 --- a/Classes/Service/LicensingService.php +++ b/Classes/Service/LicensingService.php @@ -28,6 +28,7 @@ namespace SGalinski\SgNews\Service; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use SGalinski\SgNews\Utility\ExtensionUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -54,7 +55,7 @@ class LicensingService { public static function checkKey(): bool { if (static::$isLicenseKeyValid === NULL) { static::$isLicenseKeyValid = FALSE; - $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY], [FALSE]); + $configuration = ExtensionUtility::getExtensionConfiguration(self::EXTENSION_KEY); if (isset($configuration['key']) && $key = trim($configuration['key'])) { static::$isLicenseKeyValid = (bool) preg_match('/^([A-Z\d]{6}-?){4}$/', $key); } @@ -71,7 +72,7 @@ class LicensingService { */ public static function ping($returnUrl = FALSE): string { try { - $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::EXTENSION_KEY], [FALSE]); + $configuration = ExtensionUtility::getExtensionConfiguration(self::EXTENSION_KEY); $key = ''; if (isset($configuration['key'])) { $key = trim($configuration['key']); diff --git a/Classes/Utility/ExtensionUtility.php b/Classes/Utility/ExtensionUtility.php new file mode 100644 index 0000000000000000000000000000000000000000..65cf527ef8ecea6ca50d5026f4a97099089e3298 --- /dev/null +++ b/Classes/Utility/ExtensionUtility.php @@ -0,0 +1,55 @@ +<?php + +namespace SGalinski\SgNews\Utility; + +/** + * + * Copyright notice + * + * (c) sgalinski Internet Services (https://www.sgalinski.de) + * + * 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 3 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! + */ + +use TYPO3\CMS\Core\Utility\VersionNumberUtility; + +/** + * Class ExtensionUtility + * + * @package SGalinski\SgMail\Utility + * @author Kevin Ditscheid <kevin.ditscheid@sgalinski.de> + */ +class ExtensionUtility { + /** + * Get the extension configuration + * + * @param string $extKey + * @return array + */ + public static function getExtensionConfiguration(string $extKey = 'sg_news'): array { + if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) { + $extConf = \unserialize( + $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extKey], ['allowed_classes' => FALSE] + ); + return is_array($extConf) ? $extConf : []; + } + + return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extKey] ?? []; + } +}