1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base
18: {
19: 20: 21: 22: 23:
24: protected $_capability = array(
25: 'full' => true,
26: 'info' => false,
27: 'inline' => false,
28: 'raw' => false
29: );
30:
31: 32: 33: 34: 35:
36: protected $_metadata = array(
37: 38:
39: 'compressed' => true,
40: 'embedded' => false,
41: 'forceinline' => false
42: );
43:
44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: public function __construct(Horde_Mime_Part $part, array $conf = array())
55: {
56: parent::__construct($part, $conf);
57: }
58:
59: 60: 61: 62: 63: 64:
65: protected function _render()
66: {
67: $has_xsl = Horde_Util::extensionExists('xsl');
68:
69: $has_xsl = false;
70: if ($has_xsl) {
71: $tmpdir = Horde_Util::createTempDir(true);
72: }
73:
74: $fnames = array('content.xml', 'styles.xml', 'meta.xml');
75: $tags = array(
76: 'text:p' => 'p',
77: 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ',
78: 'table:table-row' => 'tr bgcolor="#cccccc"',
79: 'table:table-cell' => 'td',
80: 'table:number-columns-spanned=' => 'colspan='
81: );
82:
83: if (!$this->getConfigParam('zip')) {
84: $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
85: }
86: $list = $this->getConfigParam('zip')
87: ->decompress($this->_mimepart->getContents(),
88: array('action' => Horde_Compress_Zip::ZIP_LIST));
89:
90: foreach ($list as $key => $file) {
91: if (in_array($file['name'], $fnames)) {
92: $content = $this->getConfigParam('zip')
93: ->decompress($this->_mimepart->getContents(), array(
94: 'action' => Horde_Compress_Zip::ZIP_DATA,
95: 'info' => $list,
96: 'key' => $key
97: ));
98:
99: if ($has_xsl) {
100: file_put_contents($tmpdir . $file['name'], $content);
101: } elseif ($file['name'] == 'content.xml') {
102: return array(
103: $this->_mimepart->getMimeId() => array(
104: 'data' => str_replace(array_keys($tags), array_values($tags), $content),
105: 'status' => array(),
106: 'type' => 'text/html; charset=UTF-8'
107: )
108: );
109: }
110: }
111: }
112:
113: if (!$has_xsl) {
114: return array();
115: }
116:
117: $xslt = new XSLTProcessor();
118: $xsl = new DOMDocument();
119: $xsl->load(realpath(dirname(__FILE__) . '/Ooo/main_html.xsl'));
120: $xslt->importStylesheet($xsl);
121: $xslt->setParameter('http://www.w3.org/1999/XSL/Transform', array(
122: 'metaFileURL' => $tmpdir . 'meta.xml',
123: 'stylesFileURL' => $tmpdir . 'styles.xml',
124: 'disableJava' => true
125: ));
126: $xml = new DOMDocument();
127: $xml->load(realpath($tmpdir . 'content.xml'));
128: $result = $xslt->transformToXml($xml);
129: if (!$result) {
130: $result = libxml_get_last_error()->message;
131: }
132:
133: return array(
134: $this->_mimepart->getMimeId() => array(
135: 'data' => $result,
136: 'status' => array(),
137: 'type' => 'text/html; charset=UTF-8'
138: )
139: );
140: }
141:
142: }
143: