FIX a case of corrupted ODT by Word that insert <text:s> when it should
not.
This commit is contained in:
parent
386b19d4b1
commit
f514400d87
@ -39,6 +39,7 @@ class Odf
|
|||||||
public $userdefined=array();
|
public $userdefined=array();
|
||||||
|
|
||||||
const PIXEL_TO_CM = 0.026458333;
|
const PIXEL_TO_CM = 0.026458333;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
*
|
*
|
||||||
@ -107,6 +108,7 @@ class Odf
|
|||||||
|
|
||||||
copy($filename, $this->tmpfile);
|
copy($filename, $this->tmpfile);
|
||||||
|
|
||||||
|
// Clean file to have tags for line corrected
|
||||||
$this->_moveRowSegments();
|
$this->_moveRowSegments();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +203,9 @@ class Odf
|
|||||||
public function phpEval()
|
public function phpEval()
|
||||||
{
|
{
|
||||||
preg_match_all('/[\{\<]\?(php)?\s+(?P<content>.+)\?[\}\>]/iU',$this->contentXml, $matches); // detecting all {?php code ?} or <?php code ? >
|
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 {
|
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
|
$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];
|
$code = $matches['content'][$i];
|
||||||
@ -247,13 +251,18 @@ IMG;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Move segment tags for lines of tables
|
* 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
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function _moveRowSegments()
|
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";
|
$reg1 = "#<table:table-row[^>]*>(.*)</table:table-row>#smU";
|
||||||
preg_match_all($reg1, $this->contentXml, $matches);
|
preg_match_all($reg1, $this->contentXml, $matches);
|
||||||
for ($i = 0, $size = count($matches[0]); $i < $size; $i++) {
|
for ($i = 0, $size = count($matches[0]); $i < $size; $i++) {
|
||||||
@ -333,7 +342,7 @@ IMG;
|
|||||||
/**
|
/**
|
||||||
* Add the merged segment to the document
|
* Add the merged segment to the document
|
||||||
*
|
*
|
||||||
* @param Segment $segment
|
* @param Segment $segment Segment
|
||||||
* @throws OdfException
|
* @throws OdfException
|
||||||
* @return odf
|
* @return odf
|
||||||
*/
|
*/
|
||||||
@ -383,7 +392,7 @@ IMG;
|
|||||||
/**
|
/**
|
||||||
* Declare a segment in order to use it in a loop
|
* Declare a segment in order to use it in a loop
|
||||||
*
|
*
|
||||||
* @param string $segment
|
* @param string $segment Segment
|
||||||
* @throws OdfException
|
* @throws OdfException
|
||||||
* @return Segment
|
* @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--\]<\/text:p>(.*)<text:p\s.*>\[!--\sEND\s$segment\s--\]#sm";
|
||||||
$reg = "#\[!--\sBEGIN\s$segment\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) {
|
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);
|
$this->segments[$segment] = new Segment($segment, $m[1], $this);
|
||||||
return $this->segments[$segment];
|
return $this->segments[$segment];
|
||||||
@ -674,9 +683,9 @@ IMG;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* return the value present on odt in [valuename][/valuename]
|
* 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)
|
public function getvalue($valuename)
|
||||||
{
|
{
|
||||||
@ -688,4 +697,3 @@ IMG;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user