123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- diff --git odtphp/library/Segment.php odtphp/library/Segment.php
- index c0ff220..20f4760 100644
- --- odtphp/library/Segment.php
- +++ odtphp/library/Segment.php
- @@ -96,11 +96,14 @@ class Segment implements IteratorAggregate, Countable
- $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
- $this->file->open($this->odf->getTmpfile());
- foreach ($this->images as $imageKey => $imageValue) {
- - if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
- - $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
- - }
- + if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
- + $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
- + }
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
- + $this->odf->addImageToManifest($imageValue);
- + // /MODIF
- }
- - $this->file->close();
- + $this->file->close();
- return $this->xmlParsed;
- }
- /**
- diff --git odtphp/library/odf.php odtphp/library/odf.php
- index 36f894e..c7423e2 100644
- --- odtphp/library/odf.php
- +++ odtphp/library/odf.php
- @@ -32,6 +32,10 @@ class Odf
- protected $images = array();
- protected $vars = array();
- protected $segments = array();
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
- + // http://www.odtphp.com/forum/viewtopic.php?f=5&t=147
- + protected $manifestXml;
- + // /MODIF
- const PIXEL_TO_CM = 0.026458333;
- /**
- * Class constructor
- @@ -60,9 +64,15 @@ class Odf
- if (($this->contentXml = $this->file->getFromName('content.xml')) === false) {
- throw new OdfException("Nothing to parse - check that the content.xml file is correctly formed");
- }
- +
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images
- + if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) {
- + throw new OdfException("Something is wrong with META-INF/manifest.xml");
- + }
- + // /MODIF
-
- - $this->file->close();
- -
- + $this->file->close();
- +
- $tmp = tempnam($this->config['PATH_TO_TMP'], md5(uniqid()));
- copy($filename, $tmp);
- $this->tmpfile = $tmp;
- @@ -251,9 +261,27 @@ IMG;
- }
- foreach ($this->images as $imageKey => $imageValue) {
- $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
- + $this->addImageToManifest($imageValue);
- + // /MODIF
- + }
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
- + if (! $this->file->addFromString('./META-INF/manifest.xml', $this->manifestXml)) {
- + throw new OdfException('Error during file export: manifest.xml');
- }
- + // /MODIF
- +
- $this->file->close(); // seems to bug on windows CLI sometimes
- }
- + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
- + public function addImageToManifest($file)
- + {
- + $extension = explode('.', $file);
- + $replace = '<manifest:file-entry manifest:media-type="image/'.$extension[1].'" manifest:full-path="Pictures/'.$file.'"/></manifest:manifest>';
- +
- + $this->manifestXml = str_replace('</manifest:manifest>', $replace, $this->manifestXml);
- + }
- + // /MODIF
- /**
- * Export the file as attached file by HTTP
- *
|