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

NEW ODT generators can set meta properties of ODT file

parent a66bcf19
Branches
Tags
No related merge requests found
...@@ -409,6 +409,16 @@ class doc_generic_odt extends ModeleThirdPartyDoc ...@@ -409,6 +409,16 @@ class doc_generic_odt extends ModeleThirdPartyDoc
} }
else { else {
try { try {
$odfHandler->creator = $user->getFullName($outputlangs);
$odfHandler->title = $object->builddoc_filename;
$odfHandler->subject = $object->builddoc_filename;
if (! empty($conf->global->ODT_ADD_DOLIBARR_ID))
{
$odfHandler->userdefined['dol_id'] = $object->id;
$odfHandler->userdefined['dol_element'] = $object->element;
}
$odfHandler->saveToDisk($file); $odfHandler->saveToDisk($file);
}catch (Exception $e){ }catch (Exception $e){
$this->error=$e->getMessage(); $this->error=$e->getMessage();
......
...@@ -6,7 +6,6 @@ class SegmentException extends Exception ...@@ -6,7 +6,6 @@ class SegmentException extends Exception
* Class for handling templating segments with odt files * Class for handling templating segments with odt files
* You need PHP 5.2 at least * You need PHP 5.2 at least
* You need Zip Extension or PclZip library * You need Zip Extension or PclZip library
* Encoding : ISO-8859-1
* *
* @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com) * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
* @copyright GPL License 2012 - Stephen Larroque - lrq3000@gmail.com * @copyright GPL License 2012 - Stephen Larroque - lrq3000@gmail.com
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* Segments iterator * Segments iterator
* You need PHP 5.2 at least * You need PHP 5.2 at least
* You need Zip Extension or PclZip library * You need Zip Extension or PclZip library
* Encoding : ISO-8859-1
* *
* @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com) * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
* @license http://www.gnu.org/copyleft/gpl.html GPL License * @license http://www.gnu.org/copyleft/gpl.html GPL License
......
...@@ -6,14 +6,13 @@ class OdfException extends Exception ...@@ -6,14 +6,13 @@ class OdfException extends Exception
* Templating class for odt file * Templating class for odt file
* You need PHP 5.2 at least * You need PHP 5.2 at least
* You need Zip Extension or PclZip library * You need Zip Extension or PclZip library
* Encoding : ISO-8859-1
* *
* @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com) * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
* @copyright GPL License 2010 - Laurent Destailleur - eldy@users.sourceforge.net * @copyright GPL License 2010-2015 - Laurent Destailleur - eldy@users.sourceforge.net
* @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com * @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
* @copyright GPL License 2012 - Stephen Larroque - lrq3000@gmail.com * @copyright GPL License 2012 - Stephen Larroque - lrq3000@gmail.com
* @license http://www.gnu.org/copyleft/gpl.html GPL License * @license http://www.gnu.org/copyleft/gpl.html GPL License
* @version 1.4.6 (last update 2013-04-07) * @version 1.5.0
*/ */
class Odf class Odf
{ {
...@@ -25,6 +24,7 @@ class Odf ...@@ -25,6 +24,7 @@ class Odf
); );
protected $file; protected $file;
protected $contentXml; // To store content of content.xml file protected $contentXml; // To store content of content.xml file
protected $metaXml; // To store content of meta.xml file
protected $stylesXml; // To store content of styles.xml file protected $stylesXml; // To store content of styles.xml file
protected $manifestXml; // To store content of META-INF/manifest.xml file protected $manifestXml; // To store content of META-INF/manifest.xml file
protected $tmpfile; protected $tmpfile;
...@@ -32,6 +32,12 @@ class Odf ...@@ -32,6 +32,12 @@ class Odf
protected $images = array(); protected $images = array();
protected $vars = array(); protected $vars = array();
protected $segments = array(); protected $segments = array();
public $creator;
public $title;
public $subject;
public $userdefined=array();
const PIXEL_TO_CM = 0.026458333; const PIXEL_TO_CM = 0.026458333;
/** /**
* Class constructor * Class constructor
...@@ -86,6 +92,9 @@ class Odf ...@@ -86,6 +92,9 @@ class Odf
if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) { if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) {
throw new OdfException("Something is wrong with META-INF/manifest.xml in source file '$filename'"); throw new OdfException("Something is wrong with META-INF/manifest.xml in source file '$filename'");
} }
if (($this->metaXml = $this->file->getFromName('meta.xml')) === false) {
throw new OdfException("Nothing to parse - Check that the meta.xml file is correctly formed in source file '$filename'");
}
if (($this->stylesXml = $this->file->getFromName('styles.xml')) === false) { if (($this->stylesXml = $this->file->getFromName('styles.xml')) === false) {
throw new OdfException("Nothing to parse - Check that the styles.xml file is correctly formed in source file '$filename'"); throw new OdfException("Nothing to parse - Check that the styles.xml file is correctly formed in source file '$filename'");
} }
...@@ -187,6 +196,7 @@ class Odf ...@@ -187,6 +196,7 @@ class Odf
/** /**
* 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
* *
* @return int 0
*/ */
public function phpEval() public function phpEval()
{ {
...@@ -268,13 +278,13 @@ IMG; ...@@ -268,13 +278,13 @@ IMG;
* Merge template variables * Merge template variables
* Called automatically for a save * Called automatically for a save
* *
* @param string $type 'content' or 'styles' * @param string $type 'content', 'styles' or 'meta'
* @return void * @return void
*/ */
private function _parse($type='content') private function _parse($type='content')
{ {
// Conditionals substitution // Conditionals substitution
// Note: must be done before content substitution, else the variable will be replaced by its value and the conditional won't work anymore // Note: must be done before static substitution, else the variable will be replaced by its value and the conditional won't work anymore
foreach($this->vars as $key => $value) foreach($this->vars as $key => $value)
{ {
// If value is true (not 0 nor false nor null nor empty string) // If value is true (not 0 nor false nor null nor empty string)
...@@ -300,10 +310,10 @@ IMG; ...@@ -300,10 +310,10 @@ IMG;
} }
} }
// Content (variable) substitution // Static substitution
if ($type == 'content') $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml); if ($type == 'content') $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml);
// Styles substitution
if ($type == 'styles') $this->stylesXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->stylesXml); if ($type == 'styles') $this->stylesXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->stylesXml);
if ($type == 'meta') $this->metaXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->metaXml);
} }
...@@ -408,13 +418,21 @@ IMG; ...@@ -408,13 +418,21 @@ IMG;
$res=$this->file->open($this->tmpfile); // tmpfile is odt template $res=$this->file->open($this->tmpfile); // tmpfile is odt template
$this->_parse('content'); $this->_parse('content');
$this->_parse('styles'); $this->_parse('styles');
$this->_parse('meta');
$this->setMetaData();
//print $this->metaXml;exit;
if (! $this->file->addFromString('content.xml', $this->contentXml)) { if (! $this->file->addFromString('content.xml', $this->contentXml)) {
throw new OdfException('Error during file export addFromString'); throw new OdfException('Error during file export addFromString content');
}
if (! $this->file->addFromString('meta.xml', $this->metaXml)) {
throw new OdfException('Error during file export addFromString meta');
} }
if (! $this->file->addFromString('styles.xml', $this->stylesXml)) { if (! $this->file->addFromString('styles.xml', $this->stylesXml)) {
throw new OdfException('Error during file export addFromString'); throw new OdfException('Error during file export addFromString styles');
} }
foreach ($this->images as $imageKey => $imageValue) { foreach ($this->images as $imageKey => $imageValue) {
// Add the image inside the ODT document // Add the image inside the ODT document
$this->file->addFile($imageKey, 'Pictures/' . $imageValue); $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
...@@ -427,10 +445,37 @@ IMG; ...@@ -427,10 +445,37 @@ IMG;
$this->file->close(); $this->file->close();
} }
/**
* Update Meta information
* <dc:date>2013-03-16T14:06:25</dc:date>
*
* @return void
*/
public function setMetaData()
{
if (empty($this->creator)) $this->creator='';
$this->metaXml = preg_replace('/<dc:date>.*<\/dc:date>/', '<dc:date>'.gmdate("Y-m-d\TH:i:s").'</dc:date>', $this->metaXml);
$this->metaXml = preg_replace('/<dc:creator>.*<\/dc:creator>/', '<dc:creator>'.htmlspecialchars($this->creator).'</dc:creator>', $this->metaXml);
$this->metaXml = preg_replace('/<dc:title>.*<\/dc:title>/', '<dc:title>'.htmlspecialchars($this->title).'</dc:title>', $this->metaXml);
$this->metaXml = preg_replace('/<dc:subject>.*<\/dc:subject>/', '<dc:subject>'.htmlspecialchars($this->subject).'</dc:subject>', $this->metaXml);
if (count($this->userdefined))
{
foreach($this->userdefined as $key => $val)
{
$this->metaXml = preg_replace('<meta:user-defined meta:name="'.$key.'"/>', '', $this->metaXml);
$this->metaXml = preg_replace('/<meta:user-defined meta:name="'.$key.'">.*<\/meta:user-defined>/', '', $this->metaXml);
$this->metaXml = str_replace('</office:meta>', '<meta:user-defined meta:name="'.$key.'">'.htmlspecialchars($val).'</meta:user-defined></office:meta>', $this->metaXml);
}
}
}
/** /**
* Update Manifest file according to added image files * Update Manifest file according to added image files
* *
* @param string $file Image file to add into manifest content * @param string $file Image file to add into manifest content
* @return void
*/ */
public function addImageToManifest($file) public function addImageToManifest($file)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment