@@ -6,61 +6,61 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RemoveComments implements ManipulationInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Patterns for white-listing comments inside content. |
|
| 11 | - */ |
|
| 12 | - protected array $whiteListCommentsPatterns = []; |
|
| 9 | + /** |
|
| 10 | + * Patterns for white-listing comments inside content. |
|
| 11 | + */ |
|
| 12 | + protected array $whiteListCommentsPatterns = []; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param string $html The original HTML |
|
| 16 | - * @param array $configuration Configuration |
|
| 17 | - * |
|
| 18 | - * @return string the manipulated HTML |
|
| 19 | - */ |
|
| 20 | - public function manipulate(string $html, array $configuration = []): string |
|
| 21 | - { |
|
| 22 | - if (isset($configuration['keep.'])) { |
|
| 23 | - $this->whiteListCommentsPatterns = $configuration['keep.']; |
|
| 24 | - } |
|
| 14 | + /** |
|
| 15 | + * @param string $html The original HTML |
|
| 16 | + * @param array $configuration Configuration |
|
| 17 | + * |
|
| 18 | + * @return string the manipulated HTML |
|
| 19 | + */ |
|
| 20 | + public function manipulate(string $html, array $configuration = []): string |
|
| 21 | + { |
|
| 22 | + if (isset($configuration['keep.'])) { |
|
| 23 | + $this->whiteListCommentsPatterns = $configuration['keep.']; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - // match all comments, styles and scripts |
|
| 27 | - $matches = []; |
|
| 28 | - preg_match_all( |
|
| 29 | - '/(?s)((<!--.*?-->)|(<[ \n\r]*style[^>]*>.*?<[ \n\r]*\/style[^>]*>)|(<[ \n\r]*script[^>]*>.*?<[ \n\r]*\/script[^>]*>))/im', |
|
| 30 | - $html, |
|
| 31 | - $matches |
|
| 32 | - ); |
|
| 33 | - foreach ($matches[0] as $tag) { |
|
| 34 | - if (false === $this->keepComment($tag)) { |
|
| 35 | - $html = str_replace($tag, '', $html); |
|
| 36 | - } |
|
| 37 | - } |
|
| 26 | + // match all comments, styles and scripts |
|
| 27 | + $matches = []; |
|
| 28 | + preg_match_all( |
|
| 29 | + '/(?s)((<!--.*?-->)|(<[ \n\r]*style[^>]*>.*?<[ \n\r]*\/style[^>]*>)|(<[ \n\r]*script[^>]*>.*?<[ \n\r]*\/script[^>]*>))/im', |
|
| 30 | + $html, |
|
| 31 | + $matches |
|
| 32 | + ); |
|
| 33 | + foreach ($matches[0] as $tag) { |
|
| 34 | + if (false === $this->keepComment($tag)) { |
|
| 35 | + $html = str_replace($tag, '', $html); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $html; |
|
| 40 | - } |
|
| 39 | + return $html; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Check if a comment is defined to be kept in a pattern whiteListOfComments. |
|
| 44 | - */ |
|
| 45 | - protected function keepComment(string $commentHtml): bool |
|
| 46 | - { |
|
| 47 | - // if not even a comment, skip this |
|
| 48 | - if (!preg_match('/^\<\!\-\-(.*?)\-\-\>$/usi', $commentHtml)) { |
|
| 49 | - return true; |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Check if a comment is defined to be kept in a pattern whiteListOfComments. |
|
| 44 | + */ |
|
| 45 | + protected function keepComment(string $commentHtml): bool |
|
| 46 | + { |
|
| 47 | + // if not even a comment, skip this |
|
| 48 | + if (!preg_match('/^\<\!\-\-(.*?)\-\-\>$/usi', $commentHtml)) { |
|
| 49 | + return true; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // if not defined in white list |
|
| 53 | - if (!empty($this->whiteListCommentsPatterns)) { |
|
| 54 | - $commentHtml = str_replace('<!--', '', $commentHtml); |
|
| 55 | - $commentHtml = str_replace('-->', '', $commentHtml); |
|
| 56 | - $commentHtml = trim($commentHtml); |
|
| 57 | - foreach ($this->whiteListCommentsPatterns as $pattern) { |
|
| 58 | - if (!empty($pattern) && preg_match($pattern, $commentHtml)) { |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 52 | + // if not defined in white list |
|
| 53 | + if (!empty($this->whiteListCommentsPatterns)) { |
|
| 54 | + $commentHtml = str_replace('<!--', '', $commentHtml); |
|
| 55 | + $commentHtml = str_replace('-->', '', $commentHtml); |
|
| 56 | + $commentHtml = trim($commentHtml); |
|
| 57 | + foreach ($this->whiteListCommentsPatterns as $pattern) { |
|
| 58 | + if (!empty($pattern) && preg_match($pattern, $commentHtml)) { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return false; |
|
| 65 | - } |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | interface ManipulationInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $html The original HTML |
|
| 11 | - * @param array $configuration Configuration |
|
| 12 | - * |
|
| 13 | - * @return string the manipulated HTML |
|
| 14 | - */ |
|
| 15 | - public function manipulate(string $html, array $configuration = []): string; |
|
| 9 | + /** |
|
| 10 | + * @param string $html The original HTML |
|
| 11 | + * @param array $configuration Configuration |
|
| 12 | + * |
|
| 13 | + * @return string the manipulated HTML |
|
| 14 | + */ |
|
| 15 | + public function manipulate(string $html, array $configuration = []): string; |
|
| 16 | 16 | } |
@@ -14,44 +14,44 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class SvgFileRepository |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Retrieves all used SVGs within given storage-array. |
|
| 19 | - */ |
|
| 20 | - public function findAllByStorageUids(array $storageUids): \Traversable |
|
| 21 | - { |
|
| 22 | - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file'); |
|
| 17 | + /** |
|
| 18 | + * Retrieves all used SVGs within given storage-array. |
|
| 19 | + */ |
|
| 20 | + public function findAllByStorageUids(array $storageUids): \Traversable |
|
| 21 | + { |
|
| 22 | + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file'); |
|
| 23 | 23 | |
| 24 | - return $queryBuilder |
|
| 25 | - ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 26 | - ->from('sys_file') |
|
| 27 | - ->innerJoin( |
|
| 28 | - 'sys_file', |
|
| 29 | - 'sys_file_reference', |
|
| 30 | - 'sys_file_reference', |
|
| 31 | - $queryBuilder->expr()->eq( |
|
| 32 | - 'sys_file_reference.uid_local', |
|
| 33 | - $queryBuilder->quoteIdentifier('sys_file.uid') |
|
| 34 | - ) |
|
| 35 | - ) |
|
| 36 | - ->where( |
|
| 37 | - $queryBuilder->expr()->in( |
|
| 38 | - 'sys_file.storage', |
|
| 39 | - $queryBuilder->createNamedParameter($storageUids, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY) |
|
| 40 | - ), |
|
| 41 | - $queryBuilder->expr()->lt( |
|
| 42 | - 'sys_file.size', |
|
| 43 | - $queryBuilder->createNamedParameter((int) $GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'] ?? null, \TYPO3\CMS\Core\Database\Connection::PARAM_INT) |
|
| 44 | - ), |
|
| 45 | - $queryBuilder->expr()->eq( |
|
| 46 | - 'sys_file.mime_type', |
|
| 47 | - $queryBuilder->createNamedParameter('image/svg+xml', \TYPO3\CMS\Core\Database\Connection::PARAM_STR) |
|
| 48 | - ) |
|
| 49 | - ) |
|
| 50 | - ->groupBy('sys_file.uid', 'sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 51 | - ->orderBy('sys_file.storage') |
|
| 52 | - ->addOrderBy('sys_file.identifier') |
|
| 53 | - ->execute() |
|
| 54 | - ->iterateAssociative() |
|
| 55 | - ; |
|
| 56 | - } |
|
| 24 | + return $queryBuilder |
|
| 25 | + ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 26 | + ->from('sys_file') |
|
| 27 | + ->innerJoin( |
|
| 28 | + 'sys_file', |
|
| 29 | + 'sys_file_reference', |
|
| 30 | + 'sys_file_reference', |
|
| 31 | + $queryBuilder->expr()->eq( |
|
| 32 | + 'sys_file_reference.uid_local', |
|
| 33 | + $queryBuilder->quoteIdentifier('sys_file.uid') |
|
| 34 | + ) |
|
| 35 | + ) |
|
| 36 | + ->where( |
|
| 37 | + $queryBuilder->expr()->in( |
|
| 38 | + 'sys_file.storage', |
|
| 39 | + $queryBuilder->createNamedParameter($storageUids, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY) |
|
| 40 | + ), |
|
| 41 | + $queryBuilder->expr()->lt( |
|
| 42 | + 'sys_file.size', |
|
| 43 | + $queryBuilder->createNamedParameter((int) $GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'] ?? null, \TYPO3\CMS\Core\Database\Connection::PARAM_INT) |
|
| 44 | + ), |
|
| 45 | + $queryBuilder->expr()->eq( |
|
| 46 | + 'sys_file.mime_type', |
|
| 47 | + $queryBuilder->createNamedParameter('image/svg+xml', \TYPO3\CMS\Core\Database\Connection::PARAM_STR) |
|
| 48 | + ) |
|
| 49 | + ) |
|
| 50 | + ->groupBy('sys_file.uid', 'sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 51 | + ->orderBy('sys_file.storage') |
|
| 52 | + ->addOrderBy('sys_file.identifier') |
|
| 53 | + ->execute() |
|
| 54 | + ->iterateAssociative() |
|
| 55 | + ; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -13,32 +13,32 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class AbstractMiddleware implements MiddlewareInterface |
| 15 | 15 | { |
| 16 | - protected function responseIsAlterable(ResponseInterface $response): bool |
|
| 17 | - { |
|
| 18 | - if (!$response instanceof NullResponse) { |
|
| 19 | - return false; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { // need for configuration |
|
| 23 | - return false; |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - if ('text/html' !== substr($response->getHeaderLine('Content-Type'), 0, 9)) { |
|
| 27 | - return false; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - if (empty($response->getBody())) { |
|
| 31 | - return false; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return true; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - protected function getStringStream(string $content): StreamInterface |
|
| 38 | - { |
|
| 39 | - $body = new Stream('php://temp', 'rw'); |
|
| 40 | - $body->write($content); |
|
| 41 | - |
|
| 42 | - return $body; |
|
| 43 | - } |
|
| 16 | + protected function responseIsAlterable(ResponseInterface $response): bool |
|
| 17 | + { |
|
| 18 | + if (!$response instanceof NullResponse) { |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + if (!$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) { // need for configuration |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + if ('text/html' !== substr($response->getHeaderLine('Content-Type'), 0, 9)) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + if (empty($response->getBody())) { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return true; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + protected function getStringStream(string $content): StreamInterface |
|
| 38 | + { |
|
| 39 | + $body = new Stream('php://temp', 'rw'); |
|
| 40 | + $body->write($content); |
|
| 41 | + |
|
| 42 | + return $body; |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -6,16 +6,16 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RemoveGenerator implements ManipulationInterface |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $html The original HTML |
|
| 11 | - * @param array $configuration Configuration |
|
| 12 | - * |
|
| 13 | - * @return string the manipulated HTML |
|
| 14 | - */ |
|
| 15 | - public function manipulate(string $html, array $configuration = []): string |
|
| 16 | - { |
|
| 17 | - $regex = '<meta name=["\']?generator["\']? [^>]+>'; |
|
| 9 | + /** |
|
| 10 | + * @param string $html The original HTML |
|
| 11 | + * @param array $configuration Configuration |
|
| 12 | + * |
|
| 13 | + * @return string the manipulated HTML |
|
| 14 | + */ |
|
| 15 | + public function manipulate(string $html, array $configuration = []): string |
|
| 16 | + { |
|
| 17 | + $regex = '<meta name=["\']?generator["\']? [^>]+>'; |
|
| 18 | 18 | |
| 19 | - return (string) preg_replace('/' . $regex . '/is', '', $html); |
|
| 20 | - } |
|
| 19 | + return (string) preg_replace('/' . $regex . '/is', '', $html); |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -16,6 +16,6 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $regex = '<meta name=["\']?generator["\']? [^>]+>'; |
| 18 | 18 | |
| 19 | - return (string) preg_replace('/' . $regex . '/is', '', $html); |
|
| 19 | + return (string) preg_replace('/'.$regex.'/is', '', $html); |
|
| 20 | 20 | } |
| 21 | 21 | } |
@@ -11,20 +11,20 @@ |
||
| 11 | 11 | |
| 12 | 12 | class SvgStoreMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected SvgStoreService $svgStoreService) {} |
|
| 14 | + public function __construct(protected SvgStoreService $svgStoreService) {} |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Search/Extract/Merge SVGs @ HTML output. |
|
| 18 | - */ |
|
| 19 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | - { |
|
| 21 | - $response = $handler->handle($request); |
|
| 16 | + /** |
|
| 17 | + * Search/Extract/Merge SVGs @ HTML output. |
|
| 18 | + */ |
|
| 19 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | + { |
|
| 21 | + $response = $handler->handle($request); |
|
| 22 | 22 | |
| 23 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['svgstore.']['enabled'] ?? false) { |
|
| 24 | - $processedHtml = $this->svgStoreService->process((string) $response->getBody()); |
|
| 25 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 26 | - } |
|
| 23 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['svgstore.']['enabled'] ?? false) { |
|
| 24 | + $processedHtml = $this->svgStoreService->process((string) $response->getBody()); |
|
| 25 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return $response; |
|
| 29 | - } |
|
| 28 | + return $response; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -11,23 +11,23 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CleanHtmlMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected CleanHtmlService $cleanHtmlService) {} |
|
| 14 | + public function __construct(protected CleanHtmlService $cleanHtmlService) {} |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Clean the HTML output. |
|
| 18 | - */ |
|
| 19 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | - { |
|
| 21 | - $response = $handler->handle($request); |
|
| 16 | + /** |
|
| 17 | + * Clean the HTML output. |
|
| 18 | + */ |
|
| 19 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | + { |
|
| 21 | + $response = $handler->handle($request); |
|
| 22 | 22 | |
| 23 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['sourceopt.']['enabled'] ?? false) { |
|
| 24 | - $processedHtml = $this->cleanHtmlService->clean( |
|
| 25 | - (string) $response->getBody(), |
|
| 26 | - (array) $GLOBALS['TSFE']->config['config']['sourceopt.'] |
|
| 27 | - ); |
|
| 28 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 29 | - } |
|
| 23 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['sourceopt.']['enabled'] ?? false) { |
|
| 24 | + $processedHtml = $this->cleanHtmlService->clean( |
|
| 25 | + (string) $response->getBody(), |
|
| 26 | + (array) $GLOBALS['TSFE']->config['config']['sourceopt.'] |
|
| 27 | + ); |
|
| 28 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return $response; |
|
| 32 | - } |
|
| 31 | + return $response; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -11,20 +11,20 @@ |
||
| 11 | 11 | |
| 12 | 12 | class RegExRepMiddleware extends AbstractMiddleware |
| 13 | 13 | { |
| 14 | - public function __construct(protected RegExRepService $regExRepService) {} |
|
| 14 | + public function __construct(protected RegExRepService $regExRepService) {} |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * RegEx search & replace @ HTML output. |
|
| 18 | - */ |
|
| 19 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | - { |
|
| 21 | - $response = $handler->handle($request); |
|
| 16 | + /** |
|
| 17 | + * RegEx search & replace @ HTML output. |
|
| 18 | + */ |
|
| 19 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 20 | + { |
|
| 21 | + $response = $handler->handle($request); |
|
| 22 | 22 | |
| 23 | - if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['replacer.'] ?? false) { |
|
| 24 | - $processedHtml = $this->regExRepService->process((string) $response->getBody()); |
|
| 25 | - $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 26 | - } |
|
| 23 | + if ($this->responseIsAlterable($response) && $GLOBALS['TSFE']->config['config']['replacer.'] ?? false) { |
|
| 24 | + $processedHtml = $this->regExRepService->process((string) $response->getBody()); |
|
| 25 | + $response = $response->withBody($this->getStringStream($processedHtml)); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return $response; |
|
| 29 | - } |
|
| 28 | + return $response; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -16,46 +16,46 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RegExRepService implements SingletonInterface |
| 18 | 18 | { |
| 19 | - public function process(string $html): string |
|
| 20 | - { |
|
| 21 | - $config = $GLOBALS['TSFE']->config['config']['replacer.']; |
|
| 22 | - |
|
| 23 | - foreach (['search.', 'replace.'] as $section) { |
|
| 24 | - if (!isset($config[$section]) || !\is_array($config[$section])) { |
|
| 25 | - throw new \Exception('missing entry @ config.replacer.' . $section); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) { |
|
| 29 | - $cObj ??= $GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class); |
|
| 30 | - |
|
| 31 | - foreach ($matches[1] as $key) { |
|
| 32 | - $config[$section][$key] = $cObj |
|
| 33 | - ->stdWrap( |
|
| 34 | - $config[$section][$key], |
|
| 35 | - $config[$section][$key . '.'] |
|
| 36 | - ) |
|
| 37 | - ; |
|
| 38 | - unset($config[$section][$key . '.']); // keep! |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - ksort($config[$section], \SORT_NATURAL); // safety |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if (Environment::getContext()->isDevelopment()) { |
|
| 46 | - foreach ($config['search.'] as $key => $val) { |
|
| 47 | - if (false === @preg_match($val, '')) { |
|
| 48 | - throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}"); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.'])); |
|
| 54 | - |
|
| 55 | - if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) { |
|
| 56 | - throw new \Exception('config.replacer requests have diverged'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return preg_replace($config['search.'], $config['replace.'], $html); |
|
| 60 | - } |
|
| 19 | + public function process(string $html): string |
|
| 20 | + { |
|
| 21 | + $config = $GLOBALS['TSFE']->config['config']['replacer.']; |
|
| 22 | + |
|
| 23 | + foreach (['search.', 'replace.'] as $section) { |
|
| 24 | + if (!isset($config[$section]) || !\is_array($config[$section])) { |
|
| 25 | + throw new \Exception('missing entry @ config.replacer.' . $section); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) { |
|
| 29 | + $cObj ??= $GLOBALS['TSFE']->cObj ?? GeneralUtility::makeInstance(ContentObjectRenderer::class); |
|
| 30 | + |
|
| 31 | + foreach ($matches[1] as $key) { |
|
| 32 | + $config[$section][$key] = $cObj |
|
| 33 | + ->stdWrap( |
|
| 34 | + $config[$section][$key], |
|
| 35 | + $config[$section][$key . '.'] |
|
| 36 | + ) |
|
| 37 | + ; |
|
| 38 | + unset($config[$section][$key . '.']); // keep! |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + ksort($config[$section], \SORT_NATURAL); // safety |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if (Environment::getContext()->isDevelopment()) { |
|
| 46 | + foreach ($config['search.'] as $key => $val) { |
|
| 47 | + if (false === @preg_match($val, '')) { |
|
| 48 | + throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}"); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $arrIntersectKeysCnt = 2 * \count(array_intersect_key($config['search.'], $config['replace.'])); |
|
| 54 | + |
|
| 55 | + if ((bool) (\count($config['search.']) + \count($config['replace.']) - $arrIntersectKeysCnt)) { |
|
| 56 | + throw new \Exception('config.replacer requests have diverged'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return preg_replace($config['search.'], $config['replace.'], $html); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | foreach (['search.', 'replace.'] as $section) { |
| 24 | 24 | if (!isset($config[$section]) || !\is_array($config[$section])) { |
| 25 | - throw new \Exception('missing entry @ config.replacer.' . $section); |
|
| 25 | + throw new \Exception('missing entry @ config.replacer.'.$section); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | if (preg_match_all('/"([\w\-]+)\.";/', serialize(array_keys($config[$section])), $matches)) { |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | $config[$section][$key] = $cObj |
| 33 | 33 | ->stdWrap( |
| 34 | 34 | $config[$section][$key], |
| 35 | - $config[$section][$key . '.'] |
|
| 35 | + $config[$section][$key.'.'] |
|
| 36 | 36 | ) |
| 37 | 37 | ; |
| 38 | - unset($config[$section][$key . '.']); // keep! |
|
| 38 | + unset($config[$section][$key.'.']); // keep! |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | if (Environment::getContext()->isDevelopment()) { |
| 46 | 46 | foreach ($config['search.'] as $key => $val) { |
| 47 | 47 | if (false === @preg_match($val, '')) { |
| 48 | - throw new \Exception(preg_last_error_msg() . ' : please check your regex syntax @ ' . "{$key} = {$val}"); |
|
| 48 | + throw new \Exception(preg_last_error_msg().' : please check your regex syntax @ '."{$key} = {$val}"); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |