From: Michael M Slusarz Date: Wed, 12 Nov 2008 23:41:52 +0000 (-0700) Subject: Tweak output from render(). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ae7c941a556c40bbebce79b754ada26cb0083aaf;p=horde.git Tweak output from render(). Return data by ID - allows us to chain MIME drivers. Also, always return all information by default, for ease of handling the return value further down the chain. --- diff --git a/framework/Mime/lib/Horde/Mime/Viewer.php b/framework/Mime/lib/Horde/Mime/Viewer.php index b2d5bae82..9397a411f 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer.php +++ b/framework/Mime/lib/Horde/Mime/Viewer.php @@ -54,7 +54,8 @@ class Horde_Mime_Viewer 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; diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php index dc469215d..4cbd4f596 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php @@ -100,12 +100,13 @@ class Horde_Mime_Viewer_Driver * subparts may also independently be viewed inline. * * - * @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: *
      * '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.
@@ -116,33 +117,20 @@ class Horde_Mime_Viewer_Driver
      */
     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);
     }
 
     /**
@@ -216,7 +204,7 @@ class Horde_Mime_Viewer_Driver
      */
     public function getEmbeddedMimeParts()
     {
-        return (!is_null($this->_mimepart) || $this->_embeddedMimeParts())
+        return $this->_embeddedMimeParts()
             ? $this->_getEmbeddedMimeParts()
             : null;
     }
@@ -245,4 +233,14 @@ class Horde_Mime_Viewer_Driver
     {
         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'];
+    }
 }
diff --git a/framework/Mime/lib/Horde/Mime/Viewer/audio.php b/framework/Mime/lib/Horde/Mime/Viewer/audio.php
index c9c2879e3..8a905703a 100644
--- a/framework/Mime/lib/Horde/Mime/Viewer/audio.php
+++ b/framework/Mime/lib/Horde/Mime/Viewer/audio.php
@@ -33,8 +33,11 @@ class Horde_Mime_Viewer_audio extends Horde_Mime_Viewer_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()
+            )
         );
     }
 }
diff --git a/framework/Mime/lib/Horde/Mime/Viewer/css.php b/framework/Mime/lib/Horde/Mime/Viewer/css.php
index 35d247def..6404476f6 100644
--- a/framework/Mime/lib/Horde/Mime/Viewer/css.php
+++ b/framework/Mime/lib/Horde/Mime/Viewer/css.php
@@ -74,8 +74,9 @@ class Horde_Mime_Viewer_css extends Horde_Mime_Viewer_source
         $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;
@@ -92,8 +93,11 @@ class Horde_Mime_Viewer_css extends Horde_Mime_Viewer_source
         $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()
+            )
         );
     }
 
diff --git a/framework/Mime/lib/Horde/Mime/Viewer/deb.php b/framework/Mime/lib/Horde/Mime/Viewer/deb.php
index 233f48a2e..59fe12559 100644
--- a/framework/Mime/lib/Horde/Mime/Viewer/deb.php
+++ b/framework/Mime/lib/Horde/Mime/Viewer/deb.php
@@ -34,7 +34,8 @@ class Horde_Mime_Viewer_deb extends Horde_Mime_Viewer_Driver
     {
         $ret = $this->_renderInline();
         if (!empty($ret)) {
-            $ret['data'] = '' . $ret['data'] . '';
+            reset($ret);
+            $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . '';
         }
         return $ret;
     }
@@ -63,8 +64,11 @@ class Horde_Mime_Viewer_deb extends Horde_Mime_Viewer_Driver
         pclose($fh);
 
         return array(
-            'data' => '
' . htmlspecialchars($data) . '
', - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => '
' . htmlspecialchars($data) . '
', + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/enriched.php b/framework/Mime/lib/Horde/Mime/Viewer/enriched.php index 1165c2eb0..b0912e442 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/enriched.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/enriched.php @@ -45,8 +45,11 @@ class Horde_Mime_Viewer_enriched extends Horde_Mime_Viewer_Driver protected function _render() { return array( - 'data' => '' . $this->_toHTML() . '', - 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => '' . $this->_toHTML() . '', + 'status' => array(), + 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() + ) ); } @@ -58,8 +61,11 @@ class Horde_Mime_Viewer_enriched extends Horde_Mime_Viewer_Driver 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/enscript.php b/framework/Mime/lib/Horde/Mime/Viewer/enscript.php index c63132d60..a21d390d4 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/enscript.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/enscript.php @@ -36,8 +36,11 @@ class Horde_Mime_Viewer_enscript extends Horde_Mime_Viewer_source 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() + ) ); } @@ -49,8 +52,11 @@ class Horde_Mime_Viewer_enscript extends Horde_Mime_Viewer_source 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/html.php b/framework/Mime/lib/Horde/Mime/Viewer/html.php index 7dd3f7cfa..ea7a246ba 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/html.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/html.php @@ -37,9 +37,11 @@ class Horde_Mime_Viewer_html extends Horde_Mime_Viewer_Driver $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) + ) ); } @@ -53,8 +55,11 @@ class Horde_Mime_Viewer_html extends Horde_Mime_Viewer_Driver $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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/images.php b/framework/Mime/lib/Horde/Mime/Viewer/images.php index cb72df398..ae8fc0782 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/images.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/images.php @@ -32,8 +32,11 @@ class Horde_Mime_Viewer_images extends Horde_Mime_Viewer_Driver 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/msexcel.php b/framework/Mime/lib/Horde/Mime/Viewer/msexcel.php index 654bb5220..4293447ad 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/msexcel.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/msexcel.php @@ -50,8 +50,11 @@ class Horde_Mime_Viewer_msexcel extends Horde_Mime_Viewer_Driver 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() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/mspowerpoint.php b/framework/Mime/lib/Horde/Mime/Viewer/mspowerpoint.php index 8a623089a..1101c3eb5 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/mspowerpoint.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/mspowerpoint.php @@ -50,8 +50,11 @@ class Horde_Mime_Viewer_mspowerpoint extends Horde_Mime_Viewer_Driver 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() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/msword.php b/framework/Mime/lib/Horde/Mime/Viewer/msword.php index 6a981380d..deeb51184 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/msword.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/msword.php @@ -59,16 +59,22 @@ class Horde_Mime_Viewer_msword extends Horde_Mime_Viewer_Driver 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 + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/ooo.php b/framework/Mime/lib/Horde/Mime/Viewer/ooo.php index 39feee3d5..b4b43e006 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/ooo.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/ooo.php @@ -63,13 +63,19 @@ class Horde_Mime_Viewer_ooo extends Horde_Mime_Viewer_Driver 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'; @@ -99,8 +105,11 @@ class Horde_Mime_Viewer_ooo extends Horde_Mime_Viewer_Driver } return array( - 'data' => $result, - 'type' => 'text/html; charset=UTF-8' + $this->_mimepart->getMimeId() => array( + 'data' => $result, + 'status' => array(), + 'type' => 'text/html; charset=UTF-8' + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/pdf.php b/framework/Mime/lib/Horde/Mime/Viewer/pdf.php index f44506dad..a38693b1f 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/pdf.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/pdf.php @@ -34,8 +34,11 @@ class Horde_Mime_Viewer_pdf extends Horde_Mime_Viewer_Driver 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' + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/php.php b/framework/Mime/lib/Horde/Mime/Viewer/php.php index 8de75c2d2..2d10bd1f1 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/php.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/php.php @@ -35,8 +35,9 @@ class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_Driver $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; @@ -61,8 +62,11 @@ class Horde_Mime_Viewer_php extends Horde_Mime_Viewer_Driver : $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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/plain.php b/framework/Mime/lib/Horde/Mime/Viewer/plain.php index 0963a5556..88a9eb7be 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/plain.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/plain.php @@ -43,8 +43,11 @@ class Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_Driver require_once 'Horde/Text/Filter.php'; return array( - 'data' => '' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '', - 'type' => 'text/html; charset=' . $charset + $this->_mimepart->getMimeId() => array( + 'data' => '' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '', + 'status' => array(), + 'type' => 'text/html; charset=' . $charset + ) ); } @@ -62,7 +65,13 @@ class Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_Driver ? $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() + ) + ); } /** diff --git a/framework/Mime/lib/Horde/Mime/Viewer/rar.php b/framework/Mime/lib/Horde/Mime/Viewer/rar.php index 96751eab3..c4cb7ffd8 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/rar.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/rar.php @@ -35,7 +35,8 @@ class Horde_Mime_Viewer_rar extends Horde_Mime_Viewer_Driver { $ret = $this->_renderInline(); if (!empty($ret)) { - $ret['data'] = '' . $ret['data'] . ''; + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; } return $ret; } @@ -65,7 +66,6 @@ class Horde_Mime_Viewer_rar extends Horde_Mime_Viewer_Driver $name = _("unnamed"); } - $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ':' . "\n" . '
' . Text::htmlAllSpaces(_("Archive Name") . ': ' . $name) . "\n" . @@ -98,8 +98,11 @@ class Horde_Mime_Viewer_rar extends Horde_Mime_Viewer_Driver } return array( - 'data' => nl2br($text . str_repeat('-', 106) . "\n" . '
'), - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => nl2br($text . str_repeat('-', 106) . "\n" . ''), + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/report.php b/framework/Mime/lib/Horde/Mime/Viewer/report.php index 2393f9e27..5c5df062d 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/report.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/report.php @@ -71,7 +71,7 @@ class Horde_Mime_Viewer_report extends Horde_Mime_Viewer_Driver $viewer = $this->_getViewer(); return $viewer ? $viewer->render($inline ? 'inline' : 'full') - : false; + : array(); } /** diff --git a/framework/Mime/lib/Horde/Mime/Viewer/rfc822.php b/framework/Mime/lib/Horde/Mime/Viewer/rfc822.php index c1fdd7932..d025b63f6 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/rfc822.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/rfc822.php @@ -33,8 +33,11 @@ class Horde_Mime_Viewer_rfc822 extends Horde_Mime_Viewer_Driver 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() + ) ); } @@ -80,7 +83,11 @@ class Horde_Mime_Viewer_rfc822 extends Horde_Mime_Viewer_Driver require_once 'Horde/Text/Filter.php'; return array( - 'data' => '
' . Text_Filter::filter(implode("
\n", $header_output), 'emails') . '
' + $this->_mimepart->getMimeId() => array( + 'data' => '
' . Text_Filter::filter(implode("
\n", $header_output), 'emails') . '
', + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/richtext.php b/framework/Mime/lib/Horde/Mime/Viewer/richtext.php index deb391c74..1bd329c11 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/richtext.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/richtext.php @@ -53,7 +53,13 @@ class Horde_Mime_Viewer_richtext extends Horde_Mime_Viewer_Driver */ 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() + ) + ); } /** @@ -63,25 +69,27 @@ class Horde_Mime_Viewer_richtext extends Horde_Mime_Viewer_Driver */ 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). */ @@ -100,7 +108,7 @@ class Horde_Mime_Viewer_richtext extends Horde_Mime_Viewer_Driver $text = str_ireplace(array('', "\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()); /* becomes a newline (
); * becomes a paragraph break (

). */ @@ -138,18 +146,6 @@ class Horde_Mime_Viewer_richtext extends Horde_Mime_Viewer_Driver $text = ' ' . substr($text, 1); } - $text = '

' . nl2br($text) . '

'; - - 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 '

' . nl2br($text) . '

'; } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/rpm.php b/framework/Mime/lib/Horde/Mime/Viewer/rpm.php index fcebc8908..6201d9ae8 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/rpm.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/rpm.php @@ -50,8 +50,11 @@ class Horde_Mime_Viewer_rpm extends Horde_Mime_Viewer_Driver pclose($fh); return array( - 'data' => '
' . htmlentities($data) . '
', - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => '
' . htmlentities($data) . '
', + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/rtf.php b/framework/Mime/lib/Horde/Mime/Viewer/rtf.php index e6b7baa7b..129c172f0 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/rtf.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/rtf.php @@ -53,8 +53,11 @@ class Horde_Mime_Viewer_rtf extends Horde_Mime_Viewer_Driver } return array( - 'data' => $data, - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/simple.php b/framework/Mime/lib/Horde/Mime/Viewer/simple.php index c931be290..5d7779b7b 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/simple.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/simple.php @@ -33,8 +33,11 @@ class Horde_Mime_Viewer_simple extends Horde_Mime_Viewer_Driver 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() + ) ); } @@ -46,8 +49,11 @@ class Horde_Mime_Viewer_simple extends Horde_Mime_Viewer_Driver 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() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/smil.php b/framework/Mime/lib/Horde/Mime/Viewer/smil.php index 6138a5c7e..db0b466f2 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/smil.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/smil.php @@ -56,8 +56,11 @@ class Horde_Mime_Viewer_smil extends Horde_Mime_Viewer_Driver 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/srchighlite.php b/framework/Mime/lib/Horde/Mime/Viewer/srchighlite.php index 748ef690c..f55308995 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/srchighlite.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/srchighlite.php @@ -40,8 +40,9 @@ class Horde_Mime_Viewer_srchighlite extends Horde_Mime_Viewer_source $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; @@ -76,8 +77,11 @@ class Horde_Mime_Viewer_srchighlite extends Horde_Mime_Viewer_source 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/tgz.php b/framework/Mime/lib/Horde/Mime/Viewer/tgz.php index 4c8d5c63a..1bb108872 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/tgz.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/tgz.php @@ -43,7 +43,8 @@ class Horde_Mime_Viewer_tgz extends Horde_Mime_Viewer_Driver { $ret = $this->_renderInline(); if (!empty($ret)) { - $ret['data'] = '' . $ret['data'] . ''; + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; } return $ret; } @@ -107,8 +108,11 @@ class Horde_Mime_Viewer_tgz extends Horde_Mime_Viewer_Driver } return array( - 'data' => nl2br($text . str_repeat('-', 106) . "\n" . ''), - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => nl2br($text . str_repeat('-', 106) . "\n" . ''), + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/tnef.php b/framework/Mime/lib/Horde/Mime/Viewer/tnef.php index 224a557e9..101613cee 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/tnef.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/tnef.php @@ -35,7 +35,8 @@ class Horde_Mime_Viewer_tnef extends Horde_Mime_Viewer_Driver { $ret = $this->_renderInline(); if (!empty($ret)) { - $ret['data'] = '' . $ret['data'] . ''; + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; } return $ret; } @@ -63,8 +64,11 @@ class Horde_Mime_Viewer_tnef extends Horde_Mime_Viewer_Driver $data .= ''; return array( - 'data' => $data, - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/vcard.php b/framework/Mime/lib/Horde/Mime/Viewer/vcard.php index 659b764a8..d6e95e390 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/vcard.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/vcard.php @@ -33,8 +33,9 @@ class Horde_Mime_Viewer_vcard extends Horde_Mime_Viewer_Driver { $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; @@ -374,8 +375,11 @@ class Horde_Mime_Viewer_vcard extends Horde_Mime_Viewer_Driver $html .= ''; 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() + ) ); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php b/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php index 0dad46637..d87801351 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/webcpp.php @@ -38,7 +38,8 @@ class Horde_Mime_Viewer_webcpp extends Horde_Mime_Viewer_Driver /* 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; } @@ -51,7 +52,8 @@ class Horde_Mime_Viewer_webcpp extends Horde_Mime_Viewer_Driver 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. */ @@ -63,7 +65,7 @@ class Horde_Mime_Viewer_webcpp extends Horde_Mime_Viewer_Driver $res = preg_split('/\<\/?pre\>/', $data); $body = $res[1]; - $ret['data'] = '
' . $body . '
'; + $ret[key($ret)]['data'] = '
' . $body . '
'; return $ret; } @@ -98,8 +100,11 @@ class Horde_Mime_Viewer_webcpp extends Horde_Mime_Viewer_Driver $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() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/wordperfect.php b/framework/Mime/lib/Horde/Mime/Viewer/wordperfect.php index 3090eb995..adaf44742 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/wordperfect.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/wordperfect.php @@ -54,8 +54,11 @@ class Horde_Mime_Viewer_wordperfect extends Horde_Mime_Viewer_Driver } return array( - 'data' => $data, - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/zip.php b/framework/Mime/lib/Horde/Mime/Viewer/zip.php index f7be97837..d159822e3 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/zip.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/zip.php @@ -42,7 +42,8 @@ class Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Driver { $ret = $this->_toHTML(); if (!empty($ret)) { - $ret['data'] = '' . $ret['data'] . ''; + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; } return $ret; } @@ -136,8 +137,11 @@ class Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Driver } return array( - 'data' => nl2br($text . str_repeat('-', 69 + $maxlen) . "\n" . ''), - 'type' => 'text/html; charset=' . NLS::getCharset() + $this->_mimepart->getMimeId() => array( + 'data' => nl2br($text . str_repeat('-', 69 + $maxlen) . "\n" . ''), + 'status' => array(), + 'type' => 'text/html; charset=' . NLS::getCharset() + ) ); } }