patch_for_odtphp_1.0.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. diff --git odtphp/library/Segment.php odtphp/library/Segment.php
  2. index c0ff220..20f4760 100644
  3. --- odtphp/library/Segment.php
  4. +++ odtphp/library/Segment.php
  5. @@ -96,11 +96,14 @@ class Segment implements IteratorAggregate, Countable
  6. $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
  7. $this->file->open($this->odf->getTmpfile());
  8. foreach ($this->images as $imageKey => $imageValue) {
  9. - if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
  10. - $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
  11. - }
  12. + if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
  13. + $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
  14. + }
  15. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
  16. + $this->odf->addImageToManifest($imageValue);
  17. + // /MODIF
  18. }
  19. - $this->file->close();
  20. + $this->file->close();
  21. return $this->xmlParsed;
  22. }
  23. /**
  24. diff --git odtphp/library/odf.php odtphp/library/odf.php
  25. index 36f894e..c7423e2 100644
  26. --- odtphp/library/odf.php
  27. +++ odtphp/library/odf.php
  28. @@ -32,6 +32,10 @@ class Odf
  29. protected $images = array();
  30. protected $vars = array();
  31. protected $segments = array();
  32. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
  33. + // http://www.odtphp.com/forum/viewtopic.php?f=5&t=147
  34. + protected $manifestXml;
  35. + // /MODIF
  36. const PIXEL_TO_CM = 0.026458333;
  37. /**
  38. * Class constructor
  39. @@ -60,9 +64,15 @@ class Odf
  40. if (($this->contentXml = $this->file->getFromName('content.xml')) === false) {
  41. throw new OdfException("Nothing to parse - check that the content.xml file is correctly formed");
  42. }
  43. +
  44. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images
  45. + if (($this->manifestXml = $this->file->getFromName('META-INF/manifest.xml')) === false) {
  46. + throw new OdfException("Something is wrong with META-INF/manifest.xml");
  47. + }
  48. + // /MODIF
  49. - $this->file->close();
  50. -
  51. + $this->file->close();
  52. +
  53. $tmp = tempnam($this->config['PATH_TO_TMP'], md5(uniqid()));
  54. copy($filename, $tmp);
  55. $this->tmpfile = $tmp;
  56. @@ -251,9 +261,27 @@ IMG;
  57. }
  58. foreach ($this->images as $imageKey => $imageValue) {
  59. $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
  60. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
  61. + $this->addImageToManifest($imageValue);
  62. + // /MODIF
  63. + }
  64. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
  65. + if (! $this->file->addFromString('./META-INF/manifest.xml', $this->manifestXml)) {
  66. + throw new OdfException('Error during file export: manifest.xml');
  67. }
  68. + // /MODIF
  69. +
  70. $this->file->close(); // seems to bug on windows CLI sometimes
  71. }
  72. + // MODIF YC : fix 'corrupt odt file in OpenOffice 3.2' when inserting images.
  73. + public function addImageToManifest($file)
  74. + {
  75. + $extension = explode('.', $file);
  76. + $replace = '<manifest:file-entry manifest:media-type="image/'.$extension[1].'" manifest:full-path="Pictures/'.$file.'"/></manifest:manifest>';
  77. +
  78. + $this->manifestXml = str_replace('</manifest:manifest>', $replace, $this->manifestXml);
  79. + }
  80. + // /MODIF
  81. /**
  82. * Export the file as attached file by HTTP
  83. *