if (($ob = self::_getDriver($mime_type, $GLOBALS['registry']->getApp())) &&
self::_resolveDriver($ob['driver'], $ob['app']) &&
class_exists($ob['class'])) {
- return new $ob['class']($mime_part, self::$_config['mime_drivers'][$ob['app']][$ob['driver']]);
+ $conf = array_merge(self::$_config['mime_drivers'][$ob['app']][$ob['driver']], array('_driver' => $ob['driver']));
+ return new $ob['class']($mime_part, $conf);
}
return false;
* subparts may also independently be viewed inline.
* </pre>
*
- * @return array An array with the following elements:
+ * @return array An array. The keys are the MIME parts that were handled
+ * by the driver. The values are either null (which
+ * indicates the driver is recommending that this
+ * particular MIME ID should not be displayed) or an array
+ * with the following keys:
* <pre>
* 'data' - (string) The rendered data.
- * 'ids' - (array) The list of MIME IDs that the rendered data covers
- * (e.g. for multipart parts, the base multipart object may
- * render all the data needed to display all the subparts)
* 'status' - (array) An array of status information to be displayed to
* the user. Consists of arrays with the following keys:
* 'img' - (string) An image to display.
*/
public function render($mode)
{
- $charset = NLS::getCharset();
- $default = array('data' => '', 'status' => array());
- $default['type'] = ($mode == 'full')
- ? 'text/plain; charset=' . $charset
- : 'text/html; charset=' . $charset;
-
- if (is_null($this->_mimepart) || !$this->canRender($mode)) {
- return $default;
+ if (!$this->canRender($mode)) {
+ return array();
}
- $default['ids'] = array($this->_mimepart->getMIMEId());
-
switch ($mode) {
case 'full':
- $ret = $this->_render();
- break;
+ return $this->_render();
case 'inline':
- $ret = $this->_renderInline();
- break;
+ return $this->_renderInline();
case 'info':
- $ret = $this->_renderInfo();
- break;
+ return $this->_renderInfo();
}
-
- return array_merge($default, $ret);
}
/**
*/
public function getEmbeddedMimeParts()
{
- return (!is_null($this->_mimepart) || $this->_embeddedMimeParts())
+ return $this->_embeddedMimeParts()
? $this->_getEmbeddedMimeParts()
: null;
}
{
return isset($this->_conf[$param]) ? $this->_conf[$param] : null;
}
+
+ /**
+ * Returns the driver name for the current object.
+ *
+ * @return string The driver name.
+ */
+ public function getDriver()
+ {
+ return $this->_conf['_driver'];
+ }
}
protected function _render()
{
return array(
- 'data' => $this->_mimepart->getContents(),
- 'type' => $this->_mimepart->getType()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_mimepart->getContents(),
+ 'status' => array(),
+ 'type' => $this->_mimepart->getType()
+ )
);
}
}
$ret = $this->_renderInline();
// Need Horde headers for CSS tags.
- $ret['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
- $ret['data'] .
+ reset($ret);
+ $ret[key($ret)]['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
+ $ret[key($ret)]['data'] .
Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
return $ret;
$css = preg_replace_callback('!{[^}]*}!s', array($this, '_attributes'), $css);
$css = preg_replace_callback('!/\*.*?\*/!s', array($this, '_comments'), $css);
return array(
- 'data' => $this->_lineNumber(trim($css)),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_lineNumber(trim($css)),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
{
$ret = $this->_renderInline();
if (!empty($ret)) {
- $ret['data'] = '<html><body>' . $ret['data'] . '</body></html>';
+ reset($ret);
+ $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
}
return $ret;
}
pclose($fh);
return array(
- 'data' => '<pre>' . htmlspecialchars($data) . '</pre>',
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '<pre>' . htmlspecialchars($data) . '</pre>',
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
protected function _render()
{
return array(
- 'data' => '<html><body>' . $this->_toHTML() . '</body></html>',
- 'type' => 'text/html; charset=' . $this->_mimepart->getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '<html><body>' . $this->_toHTML() . '</body></html>',
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . $this->_mimepart->getCharset()
+ )
);
}
protected function _renderInline()
{
return array(
- 'data' => String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
protected function _render()
{
return array(
- 'data' => $this->_toHTML(false),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_toHTML(false),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
protected function _renderInline()
{
return array(
- 'data' => $this->_toHTML(true),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_toHTML(true),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
$html = $this->_cleanHTML($this->_mimepart->getContents(), false);
return array(
- 'data' => $html['data'],
- 'status' => $html['status'],
- 'type' => $this->_mimepart->getType(true)
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $html['data'],
+ 'status' => $html['status'],
+ 'type' => $this->_mimepart->getType(true)
+ )
);
}
$html = $this->_cleanHTML($this->_mimepart->getContents(), true);
return array(
- 'data' => String::convertCharset($html['data'], $this->_mimepart->getCharset()),
- 'status' => $html['status']
+ $this->_mimepart->getMimeId() => array(
+ 'data' => String::convertCharset($html['data'], $this->_mimepart->getCharset()),
+ 'status' => $html['status'],
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
protected function _render()
{
return array(
- 'data' => $this->_mimepart->getContents(),
- 'type' => $this->_getType()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_mimepart->getContents(),
+ 'status' => array(),
+ 'type' => $this->_getType()
+ )
);
}
pclose($fh);
return array(
- 'data' => $data,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
pclose($fh);
return array(
- 'data' => $data,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
exec($this->_conf['location'] . $args);
- if (!file_exists($tmp_output)) {
+ if (file_exists($tmp_output)) {
return array(
- 'data' => _("Unable to translate this Word document"),
- 'type' => 'text/plain; charset=' . $charset
+ $this->_mimepart->getMimeId() => array(
+ 'data' => file_get_contents($tmp_output),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . $charset
+ )
);
}
return array(
- 'data' => file_get_contents($tmp_output),
- 'type' => 'text/html; charset=' . $charset
+ $this->_mimepart->getMimeId() => array(
+ 'data' => _("Unable to translate this Word document"),
+ 'status' => array(),
+ 'type' => 'text/plain; charset=' . $charset
+ )
);
}
}
if ($use_xslt) {
file_put_contents($tmpdir . $file['name'], $content);
} elseif ($file['name'] == 'content.xml') {
- return str_replace(array_keys($tags), array_values($tags), $content);
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => str_replace(array_keys($tags), array_values($tags), $content),
+ 'status' => array(),
+ 'type' => 'text/html; charset=UTF-8'
+ )
+ );
}
}
}
if (!Util::extensionExists('xslt')) {
- return;
+ return array();
}
$xsl_file = dirname(__FILE__) . '/ooo/main_html.xsl';
}
return array(
- 'data' => $result,
- 'type' => 'text/html; charset=UTF-8'
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $result,
+ 'status' => array(),
+ 'type' => 'text/html; charset=UTF-8'
+ )
);
}
}
protected function _render()
{
return array(
- 'data' => $this->_mimepart->getContents(),
- 'type' => 'application/pdf'
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_mimepart->getContents(),
+ 'status' => array(),
+ 'type' => 'application/pdf'
+ )
);
}
}
$ret = $this->_renderInline();
// Need Horde headers for CSS tags.
- $ret['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
- $ret['data'] .
+ reset($ret);
+ $ret[key($ret)]['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
+ $ret[key($ret)]['data'] .
Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
return $ret;
: $this->_lineNumber(highlight_string($code, true));
return array(
- 'data' => $text,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $text,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
require_once 'Horde/Text/Filter.php';
return array(
- 'data' => '<html><body><tt>' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '</tt></body></html>',
- 'type' => 'text/html; charset=' . $charset
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '<html><body><tt>' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '</tt></body></html>',
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . $charset
+ )
);
}
? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp'))
: $text;
- return array('data' => $data);
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
+ );
}
/**
{
$ret = $this->_renderInline();
if (!empty($ret)) {
- $ret['data'] = '<html><body>' . $ret['data'] . '</body></html>';
+ reset($ret);
+ $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
}
return $ret;
}
$name = _("unnamed");
}
-
$text = '<strong>' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ':</strong>' . "\n" .
'<table><tr><td align="left"><tt><span class="fixed">' .
Text::htmlAllSpaces(_("Archive Name") . ': ' . $name) . "\n" .
}
return array(
- 'data' => nl2br($text . str_repeat('-', 106) . "\n" . '</span></tt></td></tr></table>'),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => nl2br($text . str_repeat('-', 106) . "\n" . '</span></tt></td></tr></table>'),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
$viewer = $this->_getViewer();
return $viewer
? $viewer->render($inline ? 'inline' : 'full')
- : false;
+ : array();
}
/**
protected function _render()
{
return array(
- 'data' => $this->_mimepart->getContents(),
- 'type' => 'text/plain; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_mimepart->getContents(),
+ 'status' => array(),
+ 'type' => 'text/plain; charset=' . NLS::getCharset()
+ )
);
}
require_once 'Horde/Text/Filter.php';
return array(
- 'data' => '<div class="mimeHeaders">' . Text_Filter::filter(implode("<br />\n", $header_output), 'emails') . '</div>'
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '<div class="mimeHeaders">' . Text_Filter::filter(implode("<br />\n", $header_output), 'emails') . '</div>',
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
*/
protected function _render()
{
- return $this->_toHTML(false);
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_toHTML(),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . $this->_mimepart->getCharset()
+ )
+ );
}
/**
*/
protected function _renderInline()
{
- return $this->_toHTML(true);
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
+ );
}
/**
* Convert richtext to HTML.
*
- * @param boolean View inline?
- *
* @return string The converted HTML string.
*/
- protected function _toHTML($inline)
+ protected function _toHTML()
{
$text = trim($this->_mimepart->getContents());
if ($text == '') {
- return $text;
+ return array();
}
- $charset = $this->_mimepart->_getCharset();
-
/* We add space at the beginning and end of the string as it will
* make some regular expression checks later much easier (so we
* don't have to worry about start/end of line characters). */
$text = str_ireplace(array('<lt>', "\r\n"), array('<', ' '), $text);
/* We try to protect against bad stuff here. */
- $text = @htmlspecialchars($text, ENT_QUOTES, $charset);
+ $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset());
/* <nl> becomes a newline (<br />);
* <np> becomes a paragraph break (<p />). */
$text = ' ' . substr($text, 1);
}
- $text = '<p style="font-size:100%;font-family:Lucida Console,Courier,Courier New;">' . nl2br($text) . '</p>';
-
- if ($inline) {
- return array(
- 'data' => String::convertCharset($text, $charset),
- 'type' => 'text/html; charset=' . NLS::getCharset()
- );
- } else {
- return array(
- 'data' => $text,
- 'type' => 'text/html; charset=' . $charset
- );
- }
+ return '<p style="font-size:100%;font-family:Lucida Console,Courier,Courier New;">' . nl2br($text) . '</p>';
}
}
pclose($fh);
return array(
- 'data' => '<html><body><pre>' . htmlentities($data) . '</pre></body></html>',
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '<html><body><pre>' . htmlentities($data) . '</pre></body></html>',
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
}
return array(
- 'data' => $data,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
protected function _render()
{
return array(
- 'data' => $this->_mimepart->getContents(),
- 'type' => 'text/plain; charset=' . $this->_mimepart->getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_mimepart->getContents(),
+ 'status' => array(),
+ 'type' => 'text/plain; charset=' . $this->_mimepart->getCharset()
+ )
);
}
protected function _renderInline()
{
return array(
- 'data' => String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()),
- 'type' => 'text/plain; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()),
+ 'status' => array(),
+ 'type' => 'text/plain; charset=' . NLS::getCharset()
+ )
);
}
}
xml_parser_free($this->_parser);
return array(
- 'data' => $this->_content,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_content,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
$ret = $this->_renderInline();
// Need Horde headers for CSS tags.
- $ret['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
- $ret['data'] .
+ reset($ret);
+ $ret[key($ret)]['data'] = Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
+ $ret[key($ret)]['data'] .
Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
return $ret;
unlink($tmpout);
return array(
- 'data' => $this->_lineNumber($results),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $this->_lineNumber($results),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
{
$ret = $this->_renderInline();
if (!empty($ret)) {
- $ret['data'] = '<html><body>' . $ret['data'] . '</body></html>';
+ reset($ret);
+ $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
}
return $ret;
}
}
return array(
- 'data' => nl2br($text . str_repeat('-', 106) . "\n" . '</span></tt></td></tr></table>'),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => nl2br($text . str_repeat('-', 106) . "\n" . '</span></tt></td></tr></table>'),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
{
$ret = $this->_renderInline();
if (!empty($ret)) {
- $ret['data'] = '<html><body>' . $ret['data'] . '</body></html>';
+ reset($ret);
+ $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
}
return $ret;
}
$data .= '</table>';
return array(
- 'data' => $data,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
{
$ret = $this->_renderInline();
if (!empty($ret)) {
- $ret['data'] = Util::bufferOutput('include', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
- $ret['data'] .
+ reset($ret);
+ $ret[key($ret)]['data'] = Util::bufferOutput('include', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
+ $ret[key($ret)]['data'] .
Util::bufferOutput('include', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
}
return $ret;
$html .= '</table>';
return array(
- 'data' => Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'status')) . $html,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'status')) . $html,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
/* The first 2 lines are the Content-Type line and a blank line so
* remove them before outputting. */
- $ret['data'] = preg_replace("/.*\n.*\n/", '', $ret['data'], 1);
+ reset($ret);
+ $ret[key($ret)]['data'] = preg_replace("/.*\n.*\n/", '', $ret[key($ret)]['data'], 1);
return $ret;
}
protected function _renderInline()
{
$ret = $this->_toHTML();
- $data = $ret['data'];
+ reset($ret);
+ $data = $ret[key($ret)]['data'];
/* Extract the style sheet, removing any global body formatting
* if we're displaying inline. */
$res = preg_split('/\<\/?pre\>/', $data);
$body = $res[1];
- $ret['data'] = '<style>' . $style . '</style><div class="webcpp" style="white-space:pre;font-family:Lucida Console,Courier,monospace;">' . $body . '</div>';
+ $ret[key($ret)]['data'] = '<style>' . $style . '</style><div class="webcpp" style="white-space:pre;font-family:Lucida Console,Courier,monospace;">' . $body . '</div>';
return $ret;
}
$results = file_get_contents($tmpout);
return array(
- 'data' => $results,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $results,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
}
return array(
- 'data' => $data,
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => $data,
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}
{
$ret = $this->_toHTML();
if (!empty($ret)) {
- $ret['data'] = '<html><body>' . $ret['data'] . '</body></html>';
+ reset($ret);
+ $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
}
return $ret;
}
}
return array(
- 'data' => nl2br($text . str_repeat('-', 69 + $maxlen) . "\n" . '</span></tt></td></tr></table>'),
- 'type' => 'text/html; charset=' . NLS::getCharset()
+ $this->_mimepart->getMimeId() => array(
+ 'data' => nl2br($text . str_repeat('-', 69 + $maxlen) . "\n" . '</span></tt></td></tr></table>'),
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . NLS::getCharset()
+ )
);
}
}