Skip to content
Snippets Groups Projects
Commit f514400d authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

FIX a case of corrupted ODT by Word that insert <text:s> when it should

not.
parent 386b19d4
No related branches found
No related tags found
No related merge requests found
......@@ -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<content>.+)\?[\}\>]/iU',$this->contentXml, $matches); // detecting all {?php code ?} or <?php code ? >
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 BEGIN<text:s/>xxx into BEGIN xxx
$this->contentXml = preg_replace('/\[!--\sBEGIN<text:s[^>]>(row.[\S]*)\s--\]/sm', '[!-- BEGIN \\1 --]', $this->contentXml);
// Replace END<text:s/>xxx into END xxx
$this->contentXml = preg_replace('/\[!--\sEND<text:s[^>]>(row.[\S]*)\s--\]/sm', '[!-- END \\1 --]', $this->contentXml);
// Search all possible rows in the document
$reg1 = "#<table:table-row[^>]*>(.*)</table:table-row>#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>(.*)<text:p\s.*>\[!--\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;
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment