Fix: [ bug #1366 ] Special characters are HTML encoded with WYSIWYG

module.
This commit is contained in:
Laurent Destailleur 2014-05-07 19:13:02 +02:00
parent 16b3ec8923
commit ac27884b88
2 changed files with 70 additions and 8 deletions

View File

@ -136,9 +136,15 @@ class Segment implements IteratorAggregate, Countable
if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) { if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) {
throw new SegmentException("var $key not found in {$this->getName()}"); throw new SegmentException("var $key not found in {$this->getName()}");
} }
$value=$this->odf->htmlToUTFAndPreOdf($value);
$value = $encode ? htmlspecialchars($value) : $value; $value = $encode ? htmlspecialchars($value) : $value;
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
$this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = str_replace("\n", "<text:line-break/>", $value);
$value=$this->odf->preOdfToOdf($value);
$this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = $value;
return $this; return $this;
} }
/** /**

View File

@ -122,12 +122,68 @@ class Odf
throw new OdfException("var $key not found in the document"); throw new OdfException("var $key not found in the document");
//} //}
} }
$value=$this->htmlToUTFAndPreOdf($value);
$value = $encode ? htmlspecialchars($value) : $value; $value = $encode ? htmlspecialchars($value) : $value;
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
$value=$this->preOdfToOdf($value);
$this->vars[$tag] = $value;
return $this; return $this;
} }
/**
* Function to convert a HTML string into an ODT string
*
* @param string $value String to convert
*/
public function htmlToUTFAndPreOdf($value)
{
// We decode into utf8, entities
$value=dol_html_entity_decode($value, ENT_QUOTES);
// We convert html tags
$ishtml=dol_textishtml($value);
if ($ishtml)
{
// If string is "MYPODUCT - Desc <strong>bold</strong> with &eacute; accent<br />\n<br />\nUn texto en espa&ntilde;ol ?"
// Result after clean must be "MYPODUCT - Desc bold with é accent\n\nUn texto en espa&ntilde;ol ?"
// We want to ignore \n and we want all <br> to be \n
$value=preg_replace('/(\r\n|\r|\n)/i','',$value);
$value=preg_replace('/<br>/i',"\n",$value);
$value=preg_replace('/<br\s+[^<>\/]*>/i',"\n",$value);
$value=preg_replace('/<br\s+[^<>\/]*\/>/i',"\n",$value);
//$value=preg_replace('/<strong>/','__lt__text:p text:style-name=__quot__bold__quot____gt__',$value);
//$value=preg_replace('/<\/strong>/','__lt__/text:p__gt__',$value);
$value=dol_string_nohtmltag($value, 0);
}
return $value;
}
/**
* Function to convert a HTML string into an ODT string
*
* @param string $value String to convert
*/
public function preOdfToOdf($value)
{
$value = str_replace("\n", "<text:line-break/>", $value);
//$value = str_replace("__lt__", "<", $value);
//$value = str_replace("__gt__", ">", $value);
//$value = str_replace("__quot__", '"', $value);
return $value;
}
/** /**
* Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code * Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code
* *