Commit a33d1fc9 authored by Matthias Adrowski's avatar Matthias Adrowski
Browse files

Merge branch 'feature_Upgrade-to-TYPO3-11' into 'master'

Feature upgrade to typo3 11

See merge request !6
parents 693a372e bac23310
......@@ -36,10 +36,8 @@ use SGalinski\ContentReplacer\Service\CustomParserService;
use SGalinski\ContentReplacer\Service\SpanParserService;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\TypoScriptAspect;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Http\StreamFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
......@@ -49,7 +47,6 @@ use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
* @package SGalinski\ContentReplacer\Middleware
*/
class ContentReplacerMiddleware implements MiddlewareInterface {
/**
* Extension Configuration
*
......@@ -67,7 +64,7 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
*
* Note: The extension configuration array consists of the global and typoscript configuration.
*
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Http\ImmediateResponseException
*/
public function __construct() {
$this->extensionConfiguration = $this->prepareConfiguration();
......@@ -79,7 +76,7 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
$response = $handler->handle($request);
if ($this->extensionConfiguration['disable']) {
if (isset($this->extensionConfiguration['disable']) && $this->extensionConfiguration['disable']) {
return $response;
}
......@@ -93,26 +90,19 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
}
// StreamFactory is not available in TYPO3 9 yet.
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '10.0.0', '<')) {
$stream = new Stream('php://temp', 'r+');
if ($content !== '') {
$stream->write($content);
}
} else {
$streamFactory = GeneralUtility::makeInstance(StreamFactory::class);
$stream = $streamFactory->createStream($content);
}
$streamFactory = GeneralUtility::makeInstance(StreamFactory::class);
$stream = $streamFactory->createStream($content);
return $response->withBody($stream);
}
/**
* Returns a span tag parser instance
*
* @return SpanParserService
* @throws \InvalidArgumentException
*/
protected function getSpanParser() {
protected function getSpanParser(): SpanParserService {
$spanParser = GeneralUtility::makeInstance(SpanParserService::class);
$spanParser->setExtensionConfiguration($this->extensionConfiguration);
$spanParser->injectTermRepository($this->termRepository);
......@@ -127,7 +117,7 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
* @return CustomParserService
* @throws \InvalidArgumentException
*/
protected function getCustomParser($specialWrapCharacter) {
protected function getCustomParser(string $specialWrapCharacter): CustomParserService {
$customParser = GeneralUtility::makeInstance(CustomParserService::class);
$customParser->setExtensionConfiguration($this->extensionConfiguration);
$customParser->injectTermRepository($this->termRepository);
......@@ -144,7 +134,7 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
* @param string $content
* @return string
*/
protected function parseAndReplace(AbstractParserService $parser, $content) {
protected function parseAndReplace(AbstractParserService $parser, string $content): string {
$loopCounter = 0;
while (TRUE) {
if ($loopCounter++ > $this->extensionConfiguration['amountOfPasses']) {
......@@ -164,53 +154,27 @@ class ContentReplacerMiddleware implements MiddlewareInterface {
return $content;
}
/**
* Returns the merged extension configuration of the global configuration and the typoscript
* settings.
*
* @return array
* @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
* @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
* @throws \TYPO3\CMS\Core\Http\ImmediateResponseException
*/
public function prepareConfiguration() {
if (TYPO3_MODE === 'BE') {
/** @var TypoScriptFrontendController $typoScriptFrontendController */
$typoScriptFrontendController = $GLOBALS['TSFE'];
if (!($typoScriptFrontendController instanceof TypoScriptFrontendController)) {
$typoScriptFrontendController = $GLOBALS['TSFE'] = new TypoScriptFrontendController(
$GLOBALS['TYPO3_CONF_VARS'], 0, 0
);
}
// required in order to generate the menu links later on
$typoScriptFrontendController->settingLanguage();
$typoScriptFrontendController->newCObj();
}
public function prepareConfiguration(): array {
$extensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['content_replacer'] ?? [];
if (TYPO3_MODE === 'BE') {
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
$typoscriptConfiguration = $extbaseFrameworkConfiguration['plugin.']['tx_content_replacer.'];
} else {
if (empty($GLOBALS['TSFE']->tmpl->setup)) {
// we need the TypoScript configuration here, force parsing
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '>=')) {
GeneralUtility::makeInstance(Context::class)->setAspect(
'typoscript',
GeneralUtility::makeInstance(TypoScriptAspect::class, TRUE)
);
} else {
$GLOBALS['TSFE']->forceTemplateParsing = TRUE;
}
$GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine);
}
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'];
if (empty($GLOBALS['TSFE']->tmpl->setup)) {
// we need the TypoScript configuration here, force parsing
GeneralUtility::makeInstance(Context::class)->setAspect(
'typoscript',
GeneralUtility::makeInstance(TypoScriptAspect::class, TRUE)
);
$GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine);
}
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'];
if (is_array($typoscriptConfiguration)) {
foreach ($typoscriptConfiguration as $key => $value) {
$extensionConfiguration[$key] = $value;
......
......@@ -25,11 +25,10 @@ namespace SGalinski\ContentReplacer\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
* Repository for fetching terms
......@@ -49,7 +48,8 @@ class TermRepository {
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_content_replacer_term');
$queryBuilder->select(
'term.uid',
'term.pid', 'term',
'term.pid',
'term',
'replacement',
'stdWrap',
'category_uid',
......@@ -64,23 +64,26 @@ class TermRepository {
)->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->in(
'term', $queryBuilder->createNamedParameter($filterTerms, Connection::PARAM_STR_ARRAY)
'term',
$queryBuilder->createNamedParameter($filterTerms, Connection::PARAM_STR_ARRAY)
),
$queryBuilder->expr()->in('term.sys_language_uid', [-1, 0]),
$queryBuilder->expr()->eq(
'category', $queryBuilder->createNamedParameter($category)
'category',
$queryBuilder->createNamedParameter($category)
)
)
);
if (count($storagePageIds) > 0) {
$queryBuilder->andWhere(
$queryBuilder->expr()->in(
'term.pid', $queryBuilder->createNamedParameter($storagePageIds, Connection::PARAM_INT_ARRAY)
'term.pid',
$queryBuilder->createNamedParameter($storagePageIds, Connection::PARAM_INT_ARRAY)
)
);
}
$results = $queryBuilder->execute()->fetchAll();
$results = $queryBuilder->execute()->fetchAllAssociative();
$terms = [];
$typoScriptFrontendController = $GLOBALS['TSFE'];
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
......@@ -92,7 +95,10 @@ class TermRepository {
// one single db call instead of looping through found default language records and fetching overlays
// for each of these separately
$term = $typoScriptFrontendController->sys_page->getRecordOverlay(
'tx_content_replacer_term', $term, $sysLanguageId, $sysLanguageOverlay
'tx_content_replacer_term',
$term,
$sysLanguageId,
$sysLanguageOverlay
);
}
......
......@@ -26,6 +26,7 @@ namespace SGalinski\ContentReplacer\Service;
***************************************************************/
use SGalinski\ContentReplacer\Repository\TermRepository;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
......@@ -98,13 +99,6 @@ abstract class AbstractParserService {
*/
protected function prepareReplacementTerm($replacement, $stdWrap, $termName) {
$cObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
if (TYPO3_MODE === 'BE') {
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
$typoscriptConfiguration = $extbaseFrameworkConfiguration['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
} else {
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
}
if ($replacement !== '') {
$replacement = $cObject->parseFunc($replacement, $this->parseFunc);
......@@ -112,6 +106,13 @@ abstract class AbstractParserService {
}
if ($stdWrap !== '') {
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
$extbaseFrameworkConfiguration = $configurationManager->getTypoScriptSetup();
$typoscriptConfiguration = $extbaseFrameworkConfiguration['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
} else {
$typoscriptConfiguration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_content_replacer.'][$stdWrap . '.'];
}
$replacement = $cObject->stdWrap(
($replacement === '' ? $termName : $replacement),
$typoscriptConfiguration
......
......@@ -84,7 +84,7 @@ class SpanParserService extends AbstractParserService {
if ($category === '') {
$logger = GeneralUtility::makeInstance(Logger::class, __CLASS__);
$logger->warning("(content_replacer) Incorrect match: $classes");
$logger->warning('(content_replacer) Incorrect match: ' . implode(' ', $classes));
continue;
}
......
<?php
defined('TYPO3') or die();
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
'content_replacer', 'Configuration/Typoscript/', 'Content Replacer'
'content_replacer',
'Configuration/Typoscript/',
'Content Replacer'
);
<?php
defined('TYPO3') or die();
/**
*
* Copyright notice
......
<?php
defined('TYPO3') or die();
/**
*
* Copyright notice
......
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
if (!defined('TYPO3')) {
die('Access denied.');
}
// Path to the localisation file
$localisationFilePath = 'LLL:EXT:content_replacer/Resources/Private/Language/locallang_db.xml:';
$generalLabelsPrefix = 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.';
/** @var $TCA array */
/** @var array using TCA Notation */
$columns = [
'ctrl' => [
'title' => $localisationFilePath . 'tx_content_replacer_category',
'label' => 'category',
'dividers2tabs' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
......@@ -30,7 +29,7 @@ $columns = [
'interface' => [],
'types' => [
0 => [
'showitem' => 'hidden, --palette--;;1, category, description',
'showitem' => 'hidden,--palette--;;1,category,description',
]
],
'palettes' => [
......@@ -68,8 +67,5 @@ $columns = [
],
],
];
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '10.3.0', '<')) {
$columns['interface']['showRecordFieldList'] = 'hidden, category, description';
}
return $columns;
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
if (!defined('TYPO3')) {
die('Access denied.');
}
// Path to the localisation file
$localisationFilePath = 'LLL:EXT:content_replacer/Resources/Private/Language/locallang_db.xml:';
$generalLabelsPrefix = 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.';
/** @var $TCA array */
/** @var array using TCA Notation */
$columns = [
'ctrl' => [
'title' => $localisationFilePath . 'tx_content_replacer_term',
'label' => 'term',
'label_alt' => 'category_uid',
'label_alt_force' => TRUE,
'dividers2tabs' => TRUE,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
......@@ -37,8 +36,7 @@ $columns = [
'interface' => [],
'types' => [
0 => [
'showitem' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, --palette--;;1, term,
category_uid, stdWrap,replacement,description, starttime, endtime',
'showitem' => 'sys_language_uid,l10n_parent,l10n_diffsource,hidden,--palette--;;1,term,category_uid,stdWrap,replacement,description,starttime,endtime',
],
],
'columns' => [
......@@ -172,8 +170,5 @@ $columns = [
],
],
];
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '10.3.0', '<')) {
$columns['interface']['showRecordFieldList'] = 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, term, category_uid, stdWrap, replacement, description, starttime, endtime';
}
return $columns;
# Version 7 Breaking Changes
- Dropped TYPO3 9 support
- Dropped php 7.3 support
# Version 6 Breaking Changes
- Dropped TYPO3 8 support
{
"name": "sgalinski/content-replacer",
"type": "typo3-cms-extension",
"description": "You need a fast substitution of terms with full support of typoscript, categories and RTE integration? If yes, the extension could be perfectly fit into your project. The performance is gained by wrapping of the replacement terms to simplify the parsing process.",
"homepage": "https://www.sgalinski.de",
"license": [
"GPL-2.0-or-later"
],
"version": "6.0.6",
"support": {
"issues": "https://gitlab.sgalinski.de/typo3/content_replacer/issues"
},
"require": {
"typo3/cms-core": "^9.5.0 || ^10.4.0"
},
"require-dev": {
"roave/security-advisories": "dev-master"
},
"replace": {
"sgalinski/content_replacer": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "content_replacer"
}
},
"autoload": {
"psr-4": {
"SGalinski\\ContentReplacer\\": "Classes/"
}
}
"name": "sgalinski/content-replacer",
"type": "typo3-cms-extension",
"description": "You need a fast substitution of terms with full support of typoscript, categories and RTE integration? If yes, the extension could be perfectly fit into your project. The performance is gained by wrapping of the replacement terms to simplify the parsing process.",
"homepage": "https://www.sgalinski.de",
"license": [
"GPL-2.0-or-later"
],
"support": {
"issues": "https://gitlab.sgalinski.de/typo3/content_replacer/issues"
},
"version": "6.0.6",
"require": {
"typo3/cms-core": "^10.4 || ^11.5"
},
"replace": {
"sgalinski/content_replacer": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "content_replacer"
}
},
"autoload": {
"psr-4": {
"SGalinski\\ContentReplacer\\": "Classes/"
}
}
}
......@@ -24,8 +24,8 @@ $EM_CONF['content_replacer'] = [
'author_company' => 'domainFACTORY',
'constraints' => [
'depends' => [
'typo3' => '9.5.0-10.4.99',
'php' => '7.3.0-7.4.99',
'typo3' => '10.4.99-11.5.99',
'php' => '7.4.99-8.1.99',
],
'conflicts' => [
],
......
<?php
defined('TYPO3') or die();
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_content_replacer_category');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_content_replacer_term');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment