From c21cb85f15e8ce16f48679487e01b3420b38c79f Mon Sep 17 00:00:00 2001 From: mcmulman Date: Sun, 4 Apr 2021 21:54:44 +0200 Subject: [PATCH] [BUGFIX] #112: Remove wrapping p-tag from images --- Classes/Controller/ImageLinkRenderingController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/ImageLinkRenderingController.php b/Classes/Controller/ImageLinkRenderingController.php index 440bf97..2e1d4a7 100755 --- a/Classes/Controller/ImageLinkRenderingController.php +++ b/Classes/Controller/ImageLinkRenderingController.php @@ -69,7 +69,7 @@ public function renderImages($conf) // Get link inner HTML $linkContent = $this->cObj->getCurrentVal(); // Find all images with file-uid attribute - $imgSearchPattern = '//'; + $imgSearchPattern = '/<\/p>/'; $attrSearchPattern = '/([a-zA-Z0-9-]+)=["]([^"]*)"|([a-zA-Z0-9-]+)=[\']([^\']*)\'/'; $passedImages = []; $parsedImages = []; @@ -87,6 +87,8 @@ public function renderImages($conf) preg_match_all($attrSearchPattern, $passedImage, $passedAttributes); $passedAttributes = array_combine($passedAttributes[1], $passedAttributes[2]); + // The image is already parsed by netresearch linkrenderer, which removes custom attributes, so it will never match this condition. + // But we leave this as fallback for older render versions. if (!empty($passedAttributes['data-htmlarea-file-uid'])) { try { $systemImage = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($passedAttributes['data-htmlarea-file-uid']); @@ -127,13 +129,13 @@ public function renderImages($conf) // Image template; empty attributes are removed by 3rd param 'false' $parsedImages[] = ''; } catch (FileDoesNotExistException $fileDoesNotExistException) { - $parsedImages[] = $passedImage; + $parsedImages[] = strip_tags($passedImage , ''); // Log in fact the file could not be retrieved. $message = sprintf('I could not find file with uid "%s"', $passedAttributes['data-htmlarea-file-uid']); $this->getLogger()->log(LogLevel::ERROR,$message); } } else { - $parsedImages[] = $passedImage; + $parsedImages[] = strip_tags($passedImage , ''); } } // Replace original images with parsed