From 48ac9db5e2ec873a063d2ebfe774c2cd24a74b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Sat, 20 Mar 2021 14:13:52 +0100 Subject: [PATCH 1/8] [BUGFIX] Break out of loop on first template found Resolves: #10 --- Classes/Service/TsTCPDF.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/Service/TsTCPDF.php b/Classes/Service/TsTCPDF.php index ee17f4f..4e75fc7 100644 --- a/Classes/Service/TsTCPDF.php +++ b/Classes/Service/TsTCPDF.php @@ -239,6 +239,7 @@ public function getStandaloneView(string $templatePath, string $templateFileName $completePath = $templateRootPath . $templatePathAndFileName; if (file_exists($completePath)) { $view->setTemplatePathAndFilename($completePath); + break; } } } From a1ceacae7d19da6b69a10880b252798e6d3d0d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Sat, 20 Mar 2021 14:14:44 +0100 Subject: [PATCH 2/8] [BUGFIX] Only try to fix an image file path if it cannot be read Resolves: #11 --- Resources/Private/Library/tcpdf/tcpdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Private/Library/tcpdf/tcpdf.php b/Resources/Private/Library/tcpdf/tcpdf.php index 8b7d812..940b46c 100644 --- a/Resources/Private/Library/tcpdf/tcpdf.php +++ b/Resources/Private/Library/tcpdf/tcpdf.php @@ -18885,7 +18885,7 @@ protected function openHTMLTagHandler($dom, $key, $cell) { // data stream $imgsrc = '@'.base64_decode(substr($imgsrc, 1)); $type = ''; - } else { + } elseif (!file_exists($imgsrc)) { if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) { // fix image path $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']); From c6a4b3ea1991bf67a03ce070d945180ff66c1d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Wed, 10 May 2023 14:51:23 +0200 Subject: [PATCH 3/8] [TASK] Prepare PHP 8 compatibilty --- composer.json | 4 ++-- ext_emconf.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f61d13b..3cd89aa 100644 --- a/composer.json +++ b/composer.json @@ -55,8 +55,8 @@ ] }, "require": { - "php": ">=7.2.0 <7.5", - "typo3/cms-core": "^10.4" + "php": ">=7.2.0 <9", + "typo3/cms-core": "^10.4, ^11.5" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", diff --git a/ext_emconf.php b/ext_emconf.php index d5d471d..d865f1c 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -20,7 +20,7 @@ 'version' => '3.0.1', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-10.4.99' + 'typo3' => '10.4.0-11.5.999' ], 'conflicts' => [], 'suggests' => [], From 101818678793033309b068ab98f3b40fd0e230e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Wed, 10 May 2023 15:00:06 +0200 Subject: [PATCH 4/8] [TASK] Update composer settings --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3cd89aa..dab1766 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ }, "require": { "php": ">=7.2.0 <9", - "typo3/cms-core": "^10.4, ^11.5" + "typo3/cms-core": "^10.4 || ^11.5" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", From fef74278430bc8a42d257e7e1c7a150cec2e246b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Thu, 11 May 2023 10:47:14 +0200 Subject: [PATCH 5/8] [BUGFIX] Fix undefined array index and type errors --- Classes/Service/TsTCPDF.php | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Classes/Service/TsTCPDF.php b/Classes/Service/TsTCPDF.php index 4e75fc7..3aae183 100644 --- a/Classes/Service/TsTCPDF.php +++ b/Classes/Service/TsTCPDF.php @@ -57,13 +57,13 @@ public function setSettings(array $settings) public function header() { - if ($this->pdfSettings[$this->pdfType]) { - if ($this->pdfSettings[$this->pdfType]['header']) { - if ($this->pdfSettings[$this->pdfType]['fontSize']) { + if (!empty($this->pdfSettings[$this->pdfType])) { + if (!empty($this->pdfSettings[$this->pdfType]['header'])) { + if (!empty($this->pdfSettings[$this->pdfType]['fontSize'])) { $this->SetFontSize($this->pdfSettings[$this->pdfType]['fontSize']); } - if ($this->pdfSettings[$this->pdfType]['header']['html']) { + if (is_array($this->pdfSettings[$this->pdfType]['header']['html'] ?? null)) { foreach ($this->pdfSettings[$this->pdfType]['header']['html'] as $partName => $partConfig) { $this->renderStandaloneView( $this->pdfSettings[$this->pdfType]['header']['html'][$partName]['templatePath'], @@ -73,7 +73,7 @@ public function header() } } - if ($this->pdfSettings[$this->pdfType]['header']['line']) { + if (is_array($this->pdfSettings[$this->pdfType]['header']['line'] ?? null)) { foreach ($this->pdfSettings[$this->pdfType]['header']['line'] as $partName => $partConfig) { $this->Line( $partConfig['x1'], @@ -90,13 +90,13 @@ public function header() public function footer() { - if ($this->pdfSettings[$this->pdfType]) { - if ($this->pdfSettings[$this->pdfType]['footer']) { - if ($this->pdfSettings[$this->pdfType]['fontSize']) { + if (!empty($this->pdfSettings[$this->pdfType])) { + if (!empty($this->pdfSettings[$this->pdfType]['footer'])) { + if (!empty($this->pdfSettings[$this->pdfType]['fontSize'])) { $this->SetFontSize($this->pdfSettings[$this->pdfType]['fontSize']); } - if ($this->pdfSettings[$this->pdfType]['footer']['html']) { + if (is_array($this->pdfSettings[$this->pdfType]['footer']['html'] ?? null)) { foreach ($this->pdfSettings[$this->pdfType]['footer']['html'] as $partName => $partConfig) { $this->renderStandaloneView( $this->pdfSettings[$this->pdfType]['footer']['html'][$partName]['templatePath'], @@ -106,7 +106,7 @@ public function footer() } } - if ($this->pdfSettings[$this->pdfType]['footer']['line']) { + if (is_array($this->pdfSettings[$this->pdfType]['footer']['line'] ?? null)) { foreach ($this->pdfSettings[$this->pdfType]['footer']['line'] as $partName => $partConfig) { $this->Line( $partConfig['x1'], @@ -137,15 +137,15 @@ public function renderStandaloneView( ) { $view = $this->getStandaloneView($templatePath, ucfirst($type)); - if ($config['file']) { + if (!empty($config['file'])) { $file = GeneralUtility::getFileAbsFileName( $config['file'] ); $view->assign('file', $file); - if ($config['width']) { + if (!empty($config['width'])) { $view->assign('width', $config['width']); } - if ($config['height']) { + if (!empty($config['height'])) { $view->assign('heigth', $config['heigth']); } } @@ -172,21 +172,21 @@ public function writeHtmlCellWithConfig(string $content, array $config) { $width = $config['width']; $height = 0; - if ($config['height']) { - $height = $config['height']; + if (!empty($config['height'])) { + $height = (int)$config['height']; } - $positionX = $config['positionX']; - $positionY = $config['positionY']; + $positionX = $config['positionX'] ?? '0'; + $positionY = $config['positionY'] ?? '0'; $align = 'L'; - if ($config['align']) { + if (!empty($config['align'])) { $align = $config['align']; } $oldFontSize = $this->getFontSizePt(); - if ($config['fontSize']) { + if (!empty($config['fontSize'])) { $this->SetFontSize($config['fontSize']); } - if ($config['spacingY']) { + if (!empty($config['spacingY'])) { $this->setY($this->getY() + $config['spacingY']); } @@ -204,7 +204,7 @@ public function writeHtmlCellWithConfig(string $content, array $config) true ); - if ($config['fontSize']) { + if (!empty($config['fontSize'])) { $this->SetFontSize($oldFontSize); } } @@ -230,7 +230,7 @@ public function getStandaloneView(string $templatePath, string $templateFileName $view->setLayoutRootPaths($this->pdfSettings['view']['layoutRootPaths']); $view->setPartialRootPaths($this->pdfSettings['view']['partialRootPaths']); - if ($this->pdfSettings['view']['templateRootPaths']) { + if (is_array($this->pdfSettings['view']['templateRootPaths'] ?? null)) { foreach ($this->pdfSettings['view']['templateRootPaths'] as $pathNameKey => $pathNameValue) { $templateRootPath = GeneralUtility::getFileAbsFileName( $pathNameValue From 9382409df84f439a3bd6ed7ec12f0d4c06af93b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Thu, 11 May 2023 13:35:24 +0200 Subject: [PATCH 6/8] [TASK] Update path resolution --- Classes/Service/TsTCPDF.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Service/TsTCPDF.php b/Classes/Service/TsTCPDF.php index 3aae183..09fc969 100644 --- a/Classes/Service/TsTCPDF.php +++ b/Classes/Service/TsTCPDF.php @@ -231,12 +231,14 @@ public function getStandaloneView(string $templatePath, string $templateFileName $view->setPartialRootPaths($this->pdfSettings['view']['partialRootPaths']); if (is_array($this->pdfSettings['view']['templateRootPaths'] ?? null)) { - foreach ($this->pdfSettings['view']['templateRootPaths'] as $pathNameKey => $pathNameValue) { - $templateRootPath = GeneralUtility::getFileAbsFileName( - $pathNameValue - ); + $paths = $this->pdfSettings['view']['templateRootPaths']; + ksort($paths); + $paths = array_reverse($paths); + foreach ($paths as $pathNameValue) { + $templateRootPath = GeneralUtility::getFileAbsFileName($pathNameValue); $completePath = $templateRootPath . $templatePathAndFileName; + if (file_exists($completePath)) { $view->setTemplatePathAndFilename($completePath); break; @@ -246,9 +248,7 @@ public function getStandaloneView(string $templatePath, string $templateFileName } if (!$view->getTemplatePathAndFilename()) { - $logManager = GeneralUtility::makeInstance( - \TYPO3\CMS\Core\Log\LogManagerInterface::class - ); + $logManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class); $logger = $logManager->getLogger(__CLASS__); $logger->error( 'Cannot find Template for PdfService', From bf075c495d574d09b51ffe877e4b2f574f6b7058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Thu, 11 May 2023 13:35:45 +0200 Subject: [PATCH 7/8] [BUGFIX] Fix handling of possibly undefined variables --- Resources/Private/Library/tcpdf/tcpdf.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/Private/Library/tcpdf/tcpdf.php b/Resources/Private/Library/tcpdf/tcpdf.php index 940b46c..36e6e6d 100644 --- a/Resources/Private/Library/tcpdf/tcpdf.php +++ b/Resources/Private/Library/tcpdf/tcpdf.php @@ -7178,7 +7178,7 @@ public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $alig } else { $ximg = $x; } - + if ($ismask OR $hidden) { // image is not displayed return $info['i']; @@ -18974,9 +18974,9 @@ protected function openHTMLTagHandler($dom, $key, $cell) { if (isset($tag['height'])) { $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k), 'px', false); } - if (($type == 'eps') OR ($type == 'ai')) { + if (isset($type) && ($type == 'eps' || $type == 'ai')) { $this->ImageEps($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, true, $align, '', $border, true); - } elseif ($type == 'svg') { + } elseif (isset($type) && $type == 'svg') { $this->ImageSVG($imgsrc, $xpos, $this->y, $iw, $ih, $imglink, $align, '', $border, true); } else { $this->Image($imgsrc, $xpos, $this->y, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true); From b970da6ab39aec0a9b39a722741de09ed51049fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Gro=C3=9Fberger?= Date: Fri, 12 May 2023 09:42:13 +0200 Subject: [PATCH 8/8] [TASK] Ensure preg_replace subject is always a string --- Classes/Service/TsTCPDF.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Service/TsTCPDF.php b/Classes/Service/TsTCPDF.php index 09fc969..b1d9aa6 100644 --- a/Classes/Service/TsTCPDF.php +++ b/Classes/Service/TsTCPDF.php @@ -156,7 +156,7 @@ public function renderStandaloneView( $view->assignMultiple($assignToView); - $content = $view->render(); + $content = (string)$view->render(); $content = trim(preg_replace('~[\n]+~', '', $content)); $this->writeHtmlCellWithConfig($content, $config);