From f514400d8781406fef3e9a3c2367ba5c75198e1d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 Jun 2016 20:08:29 +0200 Subject: [PATCH] FIX a case of corrupted ODT by Word that insert when it should not. --- htdocs/includes/odtphp/odf.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 52750352afa..a60ed8fe32a 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -39,6 +39,7 @@ class Odf public $userdefined=array(); const PIXEL_TO_CM = 0.026458333; + /** * Class constructor * @@ -107,6 +108,7 @@ class Odf copy($filename, $this->tmpfile); + // Clean file to have tags for line corrected $this->_moveRowSegments(); } @@ -201,7 +203,9 @@ class Odf public function phpEval() { preg_match_all('/[\{\<]\?(php)?\s+(?P.+)\?[\}\>]/iU',$this->contentXml, $matches); // detecting all {?php code ?} or - for ($i=0;$i < count($matches['content']);$i++) { + $nbfound=count($matches['content']); + for ($i=0; $i < $nbfound; $i++) + { try { $ob_output = ''; // flush the output for each code. This var will be filled in by the eval($code) and output buffering : any print or echo or output will be redirected into this variable $code = $matches['content'][$i]; @@ -247,13 +251,18 @@ IMG; /** * Move segment tags for lines of tables - * Called automatically within the constructor + * This function is called automatically within the constructor, so this->contentXml is clean before any other thing * * @return void */ private function _moveRowSegments() { - // Search all possible rows in the document + // Replace BEGINxxx into BEGIN xxx + $this->contentXml = preg_replace('/\[!--\sBEGIN]>(row.[\S]*)\s--\]/sm', '[!-- BEGIN \\1 --]', $this->contentXml); + // Replace ENDxxx into END xxx + $this->contentXml = preg_replace('/\[!--\sEND]>(row.[\S]*)\s--\]/sm', '[!-- END \\1 --]', $this->contentXml); + + // Search all possible rows in the document $reg1 = "#]*>(.*)#smU"; preg_match_all($reg1, $this->contentXml, $matches); for ($i = 0, $size = count($matches[0]); $i < $size; $i++) { @@ -333,7 +342,7 @@ IMG; /** * Add the merged segment to the document * - * @param Segment $segment + * @param Segment $segment Segment * @throws OdfException * @return odf */ @@ -383,7 +392,7 @@ IMG; /** * Declare a segment in order to use it in a loop * - * @param string $segment + * @param string $segment Segment * @throws OdfException * @return Segment */ @@ -395,7 +404,7 @@ IMG; // $reg = "#\[!--\sBEGIN\s$segment\s--\]<\/text:p>(.*)\[!--\sEND\s$segment\s--\]#sm"; $reg = "#\[!--\sBEGIN\s$segment\s--\](.*)\[!--\sEND\s$segment\s--\]#sm"; if (preg_match($reg, html_entity_decode($this->contentXml), $m) == 0) { - throw new OdfException("'$segment' segment not found in the document"); + throw new OdfException("'".$segment."' segment not found in the document. The tag [!-- BEGIN xxx --] or [!-- END xxx --] is not present into content file."); } $this->segments[$segment] = new Segment($segment, $m[1], $this); return $this->segments[$segment]; @@ -674,9 +683,9 @@ IMG; /** * return the value present on odt in [valuename][/valuename] - * @param string $value name balise in the template - * @return string the value inside the balise - * + * + * @param string $value name balise in the template + * @return string the value inside the balise */ public function getvalue($valuename) { @@ -688,4 +697,3 @@ IMG; } -?>