1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
/**
* The MIME_Viewer_ooo class renders out OpenOffice.org
* documents in HTML format.
*
* $Horde: framework/MIME/MIME/Viewer/ooo.php,v 1.14.10.7 2006/01/01 21:28:25 jan Exp $
*
* Copyright 2003-2006 Marko Djukic <marko@oblo.com>
* Copyright 2003-2006 Jan Schneider <jan@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Marko Djukic <marko@oblo.com>
* @author Jan Schneider <jan@horde.org>
* @since Horde 3.0
* @package Horde_MIME_Viewer
*/
class MIME_Viewer_ooo extends MIME_Viewer {
/**
* Render out the current data.
*
* @param array $params Any parameters the Viewer may need.
*
* @return string The rendered contents.
*/
function render($params = array())
{
$use_xslt = Util::extensionExists('xslt') || function_exists('domxml_xslt_stylesheet_file');
if ($use_xslt) {
$tmpdir = Util::createTempDir(true);
}
require_once 'Horde/Compress.php';
$xml_tags = array('text:p', 'table:table ', 'table:table-row', 'table:table-cell', 'table:number-columns-spanned=');
$html_tags = array('p', 'table border="0" cellspacing="1" cellpadding="0" ', 'tr bgcolor="#cccccc"', 'td', 'colspan=');
$zip = &Horde_Compress::singleton('zip');
$list = $zip->decompress($this->mime_part->getContents(),
array('action' => HORDE_COMPRESS_ZIP_LIST));
foreach ($list as $key => $file) {
if ($file['name'] == 'content.xml' ||
$file['name'] == 'styles.xml' ||
$file['name'] == 'meta.xml') {
$content = $zip->decompress($this->mime_part->getContents(),
array('action' => HORDE_COMPRESS_ZIP_DATA,
'info' => $list,
'key' => $key));
if ($use_xslt) {
$fp = fopen($tmpdir . $file['name'], 'w');
fwrite($fp, $content);
fclose($fp);
} elseif ($file['name'] == 'content.xml') {
$content = str_replace($xml_tags, $html_tags, $content);
return $content;
}
}
}
if (!Util::extensionExists('xslt')) {
return;
}
if (function_exists('domxml_xslt_stylesheet_file')) {
// Use DOMXML
$xslt = domxml_xslt_stylesheet_file(dirname(__FILE__) . '/ooo/main_html.xsl');
$dom = domxml_open_file($tmpdir . 'content.xml');
$result = @$xslt->process($dom, array('metaFileURL' => $tmpdir . 'meta.xml', 'stylesFileURL' => $tmpdir . 'styles.xml', 'disableJava' => true));
return String::convertCharset($xslt->result_dump_mem($result), 'UTF-8', NLS::getCharset());
} else {
// Use XSLT
$xslt = xslt_create();
$result = @xslt_process($xslt, $tmpdir . 'content.xml',
dirname(__FILE__) . '/ooo/main_html.xsl', null, null,
array('metaFileURL' => $tmpdir . 'meta.xml', 'stylesFileURL' => $tmpdir . 'styles.xml', 'disableJava' => true));
if (!$result) {
$result = xslt_error($xslt);
}
xslt_free($xslt);
return String::convertCharset($result, 'UTF-8', NLS::getCharset());
}
}
/**
* Return the MIME content type of the rendered content.
*
* @return string The content type of the output.
*/
function getType()
{
return 'text/html; charset=' . NLS::getCharset();
}
}
|