"- added existens check for ZipArchive class (RHEL5 contains zip extension without that class!)

- only fix zip files if php version < 5.3.1 (which claims to fix the issue)
- fix mimetype of msword xml format truncated to 64 chars"
This commit is contained in:
Ralf Becker 2009-08-03 11:44:45 +00:00
parent 96c5f58a49
commit b49d561491

View File

@ -46,6 +46,12 @@ class addressbook_merge // extends bo_merge
*/
static function is_implemented($mimetype,$extension=null)
{
static $zip_available;
if (is_null($zip_available))
{
$zip_available = check_load_extension('zip') &&
class_exists('ZipArchive'); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
}
switch ($mimetype)
{
case 'application/msword':
@ -54,11 +60,11 @@ class addressbook_merge // extends bo_merge
case 'text/rtf':
return true; // rtf files
case 'application/vnd.oasis.opendocument.text':
if (!check_load_extension('zip')) break;
if (!$zip_available) break;
return true; // open office write xml files
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars
if (!check_load_extension('zip')) break;
if (!$zip_available) break;
return true; // ms word xml format
default:
if (substr($mimetype,0,5) == 'text/')
@ -269,8 +275,9 @@ class addressbook_merge // extends bo_merge
return false;
}
list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
if ($mimetype == 'application/vnd.oasis.opendocument.text' && count($ids) > 1) {
//for odt files we have to slpitt the content and add a style for page break to the style area
if ($mimetype == 'application/vnd.oasis.opendocument.text' && count($ids) > 1)
{
//for odt files we have to slpit the content and add a style for page break to the style area
list($contentstart,$contentrepeat,$contentend) = preg_split('/office:body>/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat
$contentstart = substr($contentstart,0,strlen($contentstart)-1); //remove "<"
$contentrepeat = substr($contentrepeat,0,strlen($contentrepeat)-2); //remove "</";
@ -418,8 +425,9 @@ class addressbook_merge // extends bo_merge
copy($content_url,$archive);
$content_url = 'zip://'.$archive.'#'.($content_file = 'content.xml');
break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars
$mime_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
$archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.dotx').'-').'.dotx';
copy($content_url,$archive);
$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
@ -437,7 +445,7 @@ class addressbook_merge // extends bo_merge
if ($zip->close() !== true) throw new Exception("!ZipArchive::close()");
unset($zip);
unset($merged);
if (file_exists('/usr/bin/zip')) // fix broken zip archives generated by current php
if (file_exists('/usr/bin/zip') && version_compare(PHP_VERSION,'5.3.1','<')) // fix broken zip archives generated by current php
{
exec('/usr/bin/zip -F '.escapeshellarg($archive));
}