Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(TB Export Xls) allow extended twig templates in xls
Browse files Browse the repository at this point in the history
 
Change-Id: Ib4710c3d872b3bcec47bbcbdb6ec5e2e22f33280
Reviewed-on: http://gerrit.tine20.com/customers/19119
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
  • Loading branch information
paulmhh committed Feb 16, 2021
1 parent 78785ce commit 8c34b3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Binary file not shown.
7 changes: 6 additions & 1 deletion tine20/Tinebase/Export/Abstract.php
Expand Up @@ -779,7 +779,12 @@ protected function _loadTwig()

$this->_extendTwigSetup();

$this->_twigTemplate = $this->_twig->load($this->_templateFileName);
try {
$this->_twigTemplate = $this->_twig->load($this->_templateFileName);
} catch (Twig_Error $e) {
throw new Tinebase_Exception_Backend('twig error: ' . $e->getMessage() . ' for twig source: ' .
$this->_getTwigSource());
}
}

protected function _extendTwigSetup()
Expand Down
18 changes: 11 additions & 7 deletions tine20/Tinebase/Export/Xls.php
Expand Up @@ -405,10 +405,12 @@ public function _getTwigSource()
/** @var Cell $cell */
foreach($cellIter as $cell) {
if (false !== strpos($cell->getValue(), '${twig:') &&
preg_match_all('/\${twig:([^}]+?)}/s', $cell->getValue(), $matches, PREG_SET_ORDER)) {
preg_match_all('/(\${twig:(.+?[^}%])})([^}]|$)/s', $cell->getValue(), $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
$this->_twigMapping[$i] = $match[0];
$source .= ($i === 0 ? '' : ',') . '{{' . $match[1] . '}}';
$this->_twigMapping[$i] = $match[1];
$source .= ($i === 0 ? '' : ',') .
(strpos($match[2], '{{') !== false || strpos($match[2], '{%') !== false ? $match[2]
: '{{' . $match[2] . '}}');
++$i;
}
}
Expand All @@ -418,11 +420,13 @@ public function _getTwigSource()
foreach($this->_spreadsheet->getActiveSheet()->getDrawingCollection() as $drawing) {
$desc = $drawing->getDescription();
if (false !== strpos($desc, '${twig:') &&
preg_match_all('/\${twig:([^}]+?)}/s', $desc, $matches, PREG_SET_ORDER)
preg_match_all('/(\${twig:(.+?[^}%])})([^}]|$)/s', $desc, $matches, PREG_SET_ORDER)
) {
foreach ($matches as $match) {
$this->_twigMapping[$i] = $match[0];
$source .= ($i === 0 ? '' : ',') . '{{' . $match[1] . '}}';
$this->_twigMapping[$i] = $match[1];
$source .= ($i === 0 ? '' : ',') .
(strpos($match[2], '{{') !== false || strpos($match[2], '{%') !== false ? $match[2]
: '{{' . $match[2] . '}}');
++$i;
}
}
Expand Down Expand Up @@ -702,4 +706,4 @@ function convert($to, $from = null)
return null;
}
}
}
}

0 comments on commit 8c34b3a

Please sign in to comment.