|
@@ -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;
|
|
@@ -118,7 +128,7 @@ IMG;
|
|
|
* Called automatically within the constructor
|
|
|
*
|
|
|
* @return void
|
|
|
- */
|
|
|
+ */
|
|
|
private function _moveRowSegments()
|
|
|
{
|
|
|
// Search all possible rows in the document
|
|
@@ -171,7 +181,7 @@ IMG;
|
|
|
}
|
|
|
/**
|
|
|
* Display all the current template variables
|
|
|
- *
|
|
|
+ *
|
|
|
* @return string
|
|
|
*/
|
|
|
public function printVars()
|
|
@@ -190,7 +200,7 @@ IMG;
|
|
|
}
|
|
|
/**
|
|
|
* Display loop segments declared with setSegment()
|
|
|
- *
|
|
|
+ *
|
|
|
* @return string
|
|
|
*/
|
|
|
public function printDeclaredSegments()
|
|
@@ -219,7 +229,7 @@ IMG;
|
|
|
}
|
|
|
/**
|
|
|
* Save the odt file on the disk
|
|
|
- *
|
|
|
+ *
|
|
|
* @param string $file name of the desired file
|
|
|
* @throws OdfException
|
|
|
* @return void
|
|
@@ -231,7 +241,7 @@ IMG;
|
|
|
throw new OdfException('Permission denied : can\'t create ' . $file);
|
|
|
}
|
|
|
$this->_save();
|
|
|
- copy($this->tmpfile, $file);
|
|
|
+ copy($this->tmpfile, $file);
|
|
|
} else {
|
|
|
$this->_save();
|
|
|
}
|
|
@@ -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
|
|
|
*
|
|
@@ -267,19 +295,19 @@ IMG;
|
|
|
if (headers_sent($filename, $linenum)) {
|
|
|
throw new OdfException("headers already sent ($filename at $linenum)");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if( $name == "" )
|
|
|
{
|
|
|
$name = md5(uniqid()) . ".odt";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
header('Content-type: application/vnd.oasis.opendocument.text');
|
|
|
header('Content-Disposition: attachment; filename="'.$name.'"');
|
|
|
readfile($this->tmpfile);
|
|
|
}
|
|
|
/**
|
|
|
- * Returns a variable of configuration
|
|
|
- *
|
|
|
+ * Returns a variable of configuration
|
|
|
+ *
|
|
|
* @return string The requested variable of configuration
|
|
|
*/
|
|
|
public function getConfig($configKey)
|
|
@@ -291,7 +319,7 @@ IMG;
|
|
|
}
|
|
|
/**
|
|
|
* Returns the temporary working file
|
|
|
- *
|
|
|
+ *
|
|
|
* @return string le chemin vers le fichier temporaire de travail
|
|
|
*/
|
|
|
public function getTmpfile()
|
|
@@ -300,7 +328,7 @@ IMG;
|
|
|
}
|
|
|
/**
|
|
|
* Delete the temporary file when the object is destroyed
|
|
|
- */
|
|
|
+ */
|
|
|
public function __destruct() {
|
|
|
if (file_exists($this->tmpfile)) {
|
|
|
unlink($this->tmpfile);
|