Dolibarr/dolibarr — pull request #1204 by lrq3000 (2013-08-31 18:34:35+00:00)
Title: add: odtphp can now convert (x)html into ODT automatically

Hi,

This pull request enhances odtphp with automatic conversion of (x)html input into ODT documents, using Aurélien Bompard's library xhtml2odt.

This works for any substitution variable, ie: Public and Private notes are now converted if they contain html (and not just text with line returns), and third-party substitutions get the same advantages.

The conversion will only happen if an html content is detected inside the variable, if not then it will just process the variable as before it did.

Note: it does not yet work for line substitutions, but it should be easy to implement later.

To use the automatic conversion of xhtml2odt, one just need to change this:
$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');

Into this:
$odfHandler->setVars('free_text', $newfreetext, 'auto', 'UTF-8');

We just change $encoding=true into $encoding='auto'.

When true, the encoding will be forced, thus all html will be filtered and unactivated (it also ensures retrocompatibility for modules relying on this behaviour). When false, it will disable any encoding, and the xhtml2odt will work. When 'auto', it will use xhtml2odt for html contents, and encoding for the other ones. All of this is said in the code's comments.

Also synced with the latest odtphp from my repo, while keeping the latest changes Dolibarr made on odt2pdf.

I've put xhtml2odt in its own folder at /htdocs/includes/xhtml2odt/, so that it may later be used for other purposes.

Signed-off-by: Stephen L.