Skip to content

PHP compatiblity #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions Classes/Service/TsTCPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand Down Expand Up @@ -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']);
}
}
Expand All @@ -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);
Expand All @@ -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']);
}

Expand All @@ -204,7 +204,7 @@ public function writeHtmlCellWithConfig(string $content, array $config)
true
);

if ($config['fontSize']) {
if (!empty($config['fontSize'])) {
$this->SetFontSize($oldFontSize);
}
}
Expand All @@ -230,24 +230,25 @@ public function getStandaloneView(string $templatePath, string $templateFileName
$view->setLayoutRootPaths($this->pdfSettings['view']['layoutRootPaths']);
$view->setPartialRootPaths($this->pdfSettings['view']['partialRootPaths']);

if ($this->pdfSettings['view']['templateRootPaths']) {
foreach ($this->pdfSettings['view']['templateRootPaths'] as $pathNameKey => $pathNameValue) {
$templateRootPath = GeneralUtility::getFileAbsFileName(
$pathNameValue
);
if (is_array($this->pdfSettings['view']['templateRootPaths'] ?? null)) {
$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;
}
}
}
}

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',
Expand Down
8 changes: 4 additions & 4 deletions Resources/Private/Library/tcpdf/tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down