From 3e612d2a9448497c0a304d0f3ae61b2de948e418 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Tue, 29 Sep 2020 12:13:41 +0200 Subject: [PATCH] Added support for styling in lines --- htdocs/core/class/extrafields.class.php | 3 +++ htdocs/includes/odtphp/Segment.php | 10 +++------- htdocs/includes/odtphp/odf.php | 24 ++++++++++++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index b2f8905aba9..dcac977566b 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2097,6 +2097,9 @@ class ExtraFields if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); $value_key = price2num($value_arr); + } elseif (in_array($key_type, array('text'))) { + if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. + $value_key = GETPOST($keysuffix."options_".$key.$keyprefix, 'alpha'); } else { if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. $value_key = GETPOST($keysuffix."options_".$key.$keyprefix); diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index cd8bec8c4ff..ca8797ba577 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -231,14 +231,10 @@ class Segment implements IteratorAggregate, Countable //throw new SegmentException("var $key not found in {$this->getName()}"); } - $value=$this->odf->htmlToUTFAndPreOdf($value); + $tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT'); - $value = $encode ? htmlspecialchars($value) : $value; - $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; - - $value=$this->odf->preOdfToOdf($value); - - $this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = $value; + $this->vars[$tag] = $this->odf->convertVarToOdf($value, $encode, $charset); + return $this; } /** diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 45e442462b4..88341da4adf 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -141,7 +141,23 @@ class Odf //} } + $this->vars[$tag] = $this->convertVarToOdf($value, $encode, $charset); + + return $this; + } + + /** + * Replaces html tags in odt tags and returns a compatible string + * @param string $key Name of the variable within the template + * @param string $value Replacement value + * @param bool $encode If true, special XML characters are encoded + * @param string $charset Charset + * @return string + */ + public function convertVarToOdf($value, $encode = true, $charset = 'ISO-8859') + { $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; + $convertedValue = $value; // Check if the value includes html tags if ($this->_hasHtmlTag($value) === true) { @@ -155,7 +171,7 @@ class Odf '' ); - $this->vars[$tag] = $this->_replaceHtmlWithOdtTag($this->_getDataFromHtml($value), $customStyles, $fontDeclarations); + $convertedValue = $this->_replaceHtmlWithOdtTag($this->_getDataFromHtml($value), $customStyles, $fontDeclarations); foreach ($customStyles as $key => $val) { array_push($automaticStyles, '' . $val . ''); @@ -179,9 +195,9 @@ class Odf } $this->contentXml = str_replace('', $fonts . '', $this->contentXml); } - else $this->vars[$tag] = preg_replace('/(\r\n|\r|\n)/i', "", $value); - - return $this; + else $convertedValue = preg_replace('/(\r\n|\r|\n)/i', "", $value); + + return $convertedValue; } /**