From 1cecd5d8a0a787eeedf60a26ce38d960bb3e06cd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 10 Aug 2010 12:30:09 -0600 Subject: [PATCH] Load Mime_Viewer through an injector. NOTE: THE FORMAT OF config/mime_drivers.php HAS CHANGED. YOU MUST UPDATE YOUR MIME CONFIGURATION. This change has removed a bunch of complexity from the mime_drivers configuration files (no need to explicit identify the application in the files anymore; removed the 'registered' and 'override' options since they can be handled solely within driver config; made the enable/inline config parameters optional). --- agora/lib/Messages.php | 2 +- chora/browsedir.php | 2 +- chora/config/mime_drivers.php.dist | 26 +- chora/lib/Chora.php | 2 +- .../Core/lib/Horde/Core/Binder/MimeViewer.php | 17 + .../Core/lib/Horde/Core/Factory/MimeViewer.php | 333 +++++++ framework/Core/lib/Horde/Core/Mime/Viewer/Css.php | 63 ++ .../lib/Horde/Core}/Mime/Viewer/Vcard.php | 94 +- framework/Core/lib/Horde/Registry.php | 1 + framework/Core/package.xml | 20 + framework/Mime_Viewer/lib/Horde/Mime/Viewer.php | 280 +----- .../Mime_Viewer/lib/Horde/Mime/Viewer/Base.php | 87 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Css.php | 12 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php | 38 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php | 8 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Html.php | 39 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Images.php | 11 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php | 34 +- .../lib/Horde/Mime/Viewer/Mspowerpoint.php | 31 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php | 38 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php | 30 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Php.php | 2 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php | 6 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php | 72 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Report.php | 30 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php | 6 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php | 4 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php | 39 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php | 33 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Security.php | 31 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php | 2 +- .../lib/Horde/Mime/Viewer/Srchighlite.php | 34 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php | 78 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php | 25 +- .../lib/Horde/Mime/Viewer/Wordperfect.php | 33 +- .../Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php | 61 +- framework/Mime_Viewer/package.xml | 30 +- gollem/config/mime_drivers.php.dist | 37 +- gollem/lib/Mime/Viewer/Images.php | 4 +- gollem/manager.php | 2 +- horde/admin/phpshell.php | 3 +- horde/config/mime_drivers.php.dist | 1010 +++++++++----------- horde/docs/UPGRADING | 2 + imp/compose.php | 3 +- imp/config/mime_drivers.php.dist | 468 ++++----- imp/lib/Application.php | 1 + imp/lib/Contents.php | 50 +- imp/lib/Injector/Binder/MimeViewer.php | 32 + imp/lib/Injector/Factory/MimeViewer.php | 97 ++ imp/lib/Mime/Viewer/Alternative.php | 11 +- imp/lib/Mime/Viewer/Appledouble.php | 13 +- imp/lib/Mime/Viewer/Enriched.php | 4 +- imp/lib/Mime/Viewer/Html.php | 36 +- imp/lib/Mime/Viewer/Images.php | 36 +- imp/lib/Mime/Viewer/Itip.php | 24 +- imp/lib/Mime/Viewer/Mdn.php | 18 +- imp/lib/Mime/Viewer/Partial.php | 8 +- imp/lib/Mime/Viewer/Pdf.php | 12 +- imp/lib/Mime/Viewer/Pgp.php | 30 +- imp/lib/Mime/Viewer/Plain.php | 16 +- imp/lib/Mime/Viewer/Related.php | 11 +- imp/lib/Mime/Viewer/Rfc822.php | 4 +- imp/lib/Mime/Viewer/Smil.php | 13 +- imp/lib/Mime/Viewer/Smime.php | 28 +- imp/lib/Mime/Viewer/Status.php | 20 +- imp/lib/Mime/Viewer/Tnef.php | 22 +- imp/lib/Mime/Viewer/Vcard.php | 6 +- imp/lib/Mime/Viewer/Zip.php | 30 +- imp/lib/Prefs/Ui.php | 2 +- imp/lib/Ui/Message.php | 2 +- imp/view.php | 5 +- luxor/config/mime_drivers.php.dist | 38 +- luxor/lib/Luxor.php | 8 +- luxor/source.php | 2 +- news/files.php | 2 +- news/lib/News.php | 2 +- turba/config/mime_drivers.php.dist | 20 +- turba/lib/Object.php | 4 +- turba/view.php | 3 +- whups/config/mime_drivers.php.dist | 50 +- whups/lib/Mime/Viewer/Zip.php | 28 +- whups/lib/Whups.php | 4 +- whups/view.php | 4 +- wicked/templates/display/standard.inc | 2 +- 84 files changed, 2232 insertions(+), 1649 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/MimeViewer.php create mode 100644 framework/Core/lib/Horde/Core/Factory/MimeViewer.php create mode 100644 framework/Core/lib/Horde/Core/Mime/Viewer/Css.php rename framework/{Mime_Viewer/lib/Horde => Core/lib/Horde/Core}/Mime/Viewer/Vcard.php (85%) create mode 100644 imp/lib/Injector/Binder/MimeViewer.php create mode 100644 imp/lib/Injector/Factory/MimeViewer.php diff --git a/agora/lib/Messages.php b/agora/lib/Messages.php index c08dcaf00..c0c02f5d7 100644 --- a/agora/lib/Messages.php +++ b/agora/lib/Messages.php @@ -1648,7 +1648,7 @@ class Agora_Messages { $html = '
'; $view_url = Horde::applicationUrl('view.php'); foreach ($files as $file_id => $file) { - $mime_icon = Horde_Mime_Viewer::getIcon($file['file_type']); + $mime_icon = $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getIcon($file['file_type']); $title = _("download") . ': ' . $file['file_name']; $tooltip = $title . "\n" . sprintf(_("size: %s"), $this->formatSize($file['file_size'])) . "\n" . sprintf(_("type: %s"), $file['file_type']); $url = Horde_Util::addParameter($view_url, array('forum_id' => $this->_forum_id, diff --git a/chora/browsedir.php b/chora/browsedir.php index b0de3f228..b74924220 100644 --- a/chora/browsedir.php +++ b/chora/browsedir.php @@ -107,7 +107,7 @@ if ($fileList) { $realname = $currFile->queryName(); $mimeType = Horde_Mime_Magic::filenameToMIME($realname); - $icon = Horde_Mime_Viewer::getIcon($mimeType); + $icon = $injector->getInstance('Horde_Mime_Viewer')->getIcon($mimeType); $author = Chora::showAuthorName($lg->queryAuthor()); $filerev = $lg->queryRevision(); diff --git a/chora/config/mime_drivers.php.dist b/chora/config/mime_drivers.php.dist index ad3d5d4d5..e4f9d1ab8 100644 --- a/chora/config/mime_drivers.php.dist +++ b/chora/config/mime_drivers.php.dist @@ -1,25 +1,13 @@ setType($mime_type); $mime->setContents($lns); - return Horde_Mime_Viewer::factory($mime); + return $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getViewer($mime); } /** diff --git a/framework/Core/lib/Horde/Core/Binder/MimeViewer.php b/framework/Core/lib/Horde/Core/Binder/MimeViewer.php new file mode 100644 index 000000000..b87b1b508 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/MimeViewer.php @@ -0,0 +1,17 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_Mime_Viewer factory. + * + * Copyright 2010 The Horde Project (http://www.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. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_MimeViewer +{ + /** + * Driver configuration. + * + * @var array + */ + private $_config = array(); + + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Attempts to return a concrete Horde_Mime_Viewer object based on the + * MIME type. + * + * @param Horde_Mime_Part $mime An object with the data to be rendered. + * @param array $opts Additional options: + *
+     * 'app' - (string) The Horde application to search for drivers in.
+     *         DEFAULT: current app
+     * 'type' - (string) The MIME type to use for loading.
+     *          DEFAULT: Uses MIME type in $mime.
+     * 
+ * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function getViewer(Horde_Mime_Part $mime, array $opts = array()) + { + $app = isset($opts['app']) + ? $opts['app'] + : $GLOBALS['registry']->getApp(); + + $type = isset($opts['type']) + ? $opts['type'] + : $mime->getType(); + + list($driver, $params) = $this->getViewerConfig($type, $app); + + return Horde_Mime_Viewer::factory($driver, $mime, $params); + } + + /** + * Gets the configuration for a MIME type. + * + * @param string $type The MIME type. + * @param string $app The current Horde application. + * + * @return array The driver and a list of configuration parameters. + */ + public function getViewerConfig($type, $app) + { + $config = $this->_getDriver($type, $app); + + $config['driver'] = ucfirst($config['driver']); + $driver = ($config['app'] == 'horde') + ? $config['driver'] + : $config['app'] . '_Mime_Viewer_' . $config['driver']; + + $params = array_merge($config, array( + 'charset' => $GLOBALS['registry']->getCharset(), + // TODO: Logging + // 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), + 'temp_file' => array('Horde', 'getTempFile'), + 'text_filter' => array($this->_injector->getInstance('Horde_Text_Filter'), 'filter') + )); + + switch ($config['driver']) { + case 'Css': + if ($config['app'] == 'horde') { + $driver = 'Horde_Core_Mime_Viewer_Css'; + } + $params['registry'] = $GLOBALS['registry']; + break; + + case 'Deb': + case 'Rpm': + $params['monospace'] = 'fixed'; + break; + + case 'Html': + $params['browser'] = $GLOBALS['browser']; + break; + + case 'Ooo': + $params['zip'] = Horde_Compress::factory('Zip'); + break; + + case 'Rar': + $params['monospace'] = 'fixed'; + $params['rar'] = Horde_Compress::factory('Rar'); + break; + + case 'Report': + case 'Security': + $params['viewer_callback'] = array($this, 'getViewerCallback'); + break; + + case 'Tgz': + $params['gzip'] = Horde_Compress::factory('Gzip'); + $params['monospace'] = 'fixed'; + $params['tar'] = Horde_Compress::factory('Tar'); + break; + + case 'Tnef': + $params['tnef'] = Horde_Compress::factory('Tnef'); + break; + + case 'Vcard': + if ($config['app'] == 'horde') { + $driver = 'Horde_Core_Mime_Viewer_Vcard'; + } + $params['browser'] = $GLOBALS['browser']; + $params['notification'] = $GLOBALS['notification']; + $params['prefs'] = $GLOBALS['prefs']; + $params['registry'] = $GLOBALS['registry']; + break; + + case 'Zip': + $params['monospace'] = 'fixed'; + $params['zip'] = Horde_Compress::factory('Zip'); + break; + } + + return array($driver, $params); + } + + /** + * Callback used to return a MIME Viewer object from within certain + * Viewer drivers. + * + * @param Horde_Mime_Viewer_Base $viewer The MIME Viewer driver + * requesting the new object. + * @param Horde_Mime_Part $mime An object with the data to be + * rendered. + * @param string $type The MIME type to use for + * rendering. + * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function getViewerCallback(Horde_Mime_Viewer_Base $viewer, + Horde_Mime_Part $mime, $type) + { + return $this->getViewer($mime, array('type' => $type)); + } + + /** + * Return the appropriate icon for a MIME object/MIME type. + * + * @param Horde_Mime_Part|string $mime The MIME object or type to query. + * @param array $opts Additional options: + *
+     * 'app' - (string) The Horde application to search for drivers in.
+     *         DEFAULT: current app
+     * 
+ * + * @return Horde_Themes_Image An object which contains the URI + * and filesystem location of the image. + */ + public function getIcon($mime, array $opts = array()) + { + $app = isset($opts['app']) + ? $opts['app'] + : $GLOBALS['registry']->getApp(); + + $type = ($mime instanceof Horde_Mime_Part) + ? $mime->getType() + : $mime; + + $config = $this->_getDriver($type, $app); + + if (!isset($config['icon'])) { + $config['icon'] = array( + 'app' => 'horde', + 'icon' => 'text.png' + ); + } + + return Horde_Themes::img('mime/' . $config['icon']['icon'], $config['icon']['app']); + } + + /** + * Create the driver configuration for an application. + * + * @param string $app The Horde application to search for drivers in. + */ + private function _loadConfig($app) + { + if ($app != 'horde') { + $this->_loadConfig('horde'); + } + + /* Make sure app's config is loaded. There is no requirement that + * an app have a config, so ignore any errors. */ + if (isset($this->_config[$app])) { + return; + } + + try { + $aconfig = Horde::loadConfiguration('mime_drivers.php', 'mime_drivers', $app); + } catch (Horde_Exception $e) { + $aconfig = array(); + } + + $config = array( + 'config' => array(), + 'handles' => array() + ); + + foreach ($aconfig as $key => $val) { + if (empty($val['disable'])) { + if (!empty($val['handles'])) { + $config['handles'] = array_merge($config['handles'], array_fill_keys(array_values($val['handles']), $key)); + unset($val['handles']); + } + + $config['config'][$key] = $val; + } + } + + /* Make sure there is a default entry. */ + if (($app == 'horde') && !isset($config['config']['default'])) { + $config['config']['default'] = array(); + } + + $this->_config[$app] = $config; + } + + /** + * Get the driver config for a MIME type. + * + * @param string $type The MIME type query. + * @param string $app The Horde application to search for drivers in. + * + * @return array The driver config. + */ + private function _getDriver($type, $app) + { + $this->_loadConfig($app); + + /* Start with default driver, and then merge in wildcard and exact + * match configs. */ + $config = array(); + list($ptype,) = explode('/', $type, 2); + $wild = $ptype . '/*'; + + $app_list = array( + array('horde', 'default', 'config'), + array($app, 'default', 'config'), + array('horde', $wild, 'handles'), + array($app, $wild, 'handles'), + array('horde', $type, 'handles'), + array($app, $type, 'handles') + ); + if ($app == 'horde') { + unset($app_list[1], $app_list[3], $app_list[5]); + } + + foreach ($app_list as $val) { + $driver = isset($this->_config[$val[0]][$val[2]][$val[1]]) + ? (($val[1] == 'default') ? 'default' : $this->_config[$val[0]][$val[2]][$val[1]]) + : null; + + if ($driver) { + $tmp = $this->_config[$val[0]]['config'][$driver]; + if (isset($tmp['icons'])) { + foreach (array($type, $wild, 'default') as $val2) { + if (isset($tmp['icons'][$val2])) { + $tmp['icon'] = array( + 'app' => $val[0], + 'icon' => $tmp['icons'][$val2] + ); + break; + } + } + unset($tmp['icons']); + } + + $config = array_merge(Horde_Array::array_merge_recursive_overwrite($config, $tmp), array( + 'app' => $val[0], + 'driver' => $driver + )); + + } + } + + return $config; + } + +} diff --git a/framework/Core/lib/Horde/Core/Mime/Viewer/Css.php b/framework/Core/lib/Horde/Core/Mime/Viewer/Css.php new file mode 100644 index 000000000..4cf88503e --- /dev/null +++ b/framework/Core/lib/Horde/Core/Mime/Viewer/Css.php @@ -0,0 +1,63 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Mime_Viewer_Css extends Horde_Mime_Viewer_Css +{ + /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'registry' - (Horde_Registry) Registry object.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'registry' + )); + + parent::__construct($part, $conf); + } + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See parent::render(). + */ + protected function _render() + { + $ret = $this->_renderInline(); + + // Need Horde headers for CSS tags. + if (!empty($ret)) { + $templates = $this->getConfigParam('registry')->get('templates', 'horde'); + + reset($ret); + Horde::startBuffer(); + require $templates . '/common-header.inc'; + echo $ret[key($ret)]['data']; + require $templates . '/common-footer.inc'; + $ret[key($ret)]['data'] = Horde::endBuffer(); + } + + return $ret; + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php b/framework/Core/lib/Horde/Core/Mime/Viewer/Vcard.php similarity index 85% rename from framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php rename to framework/Core/lib/Horde/Core/Mime/Viewer/Vcard.php index c7c90e4a8..4ce4f5565 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php +++ b/framework/Core/lib/Horde/Core/Mime/Viewer/Vcard.php @@ -1,6 +1,6 @@ * @category Horde * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime_Viewer + * @package Core */ -class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base +class Horde_Core_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base { /** * This driver's display capabilities. @@ -34,6 +34,33 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base protected $_imageUrl; /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'browser' - (Horde_Browser) Browser object.
+     * 'notification' - (Horde_Notification_Base) Notification object.
+     * 'prefs' - (Horde_Prefs) Prefs object.
+     * 'registry' - (Horde_Registry) Registry object.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'browser', + 'notification', + 'prefs', + 'registry' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -43,11 +70,13 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base $ret = $this->_renderInline(); if (!empty($ret)) { + $templates = $this->getConfigParam('registry')->get('templates', 'horde'); + reset($ret); Horde::startBuffer(); - include $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc'; + include $templates . '/common-header.inc'; echo $ret[key($ret)]['data']; - include $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; + include $templates . '/common-footer.inc'; $ret[key($ret)]['data'] = Horde::endBuffer(); } @@ -61,7 +90,10 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base */ protected function _renderInline() { - global $registry, $prefs, $notification; + $browser = $this->getConfigParam('browser'); + $notification = $this->getConfigParam('notification'); + $prefs = $this->getConfigParam('prefs'); + $registry = $this->getConfigParam('registry'); $app = false; $data = $this->_mimepart->getContents(); @@ -116,17 +148,17 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base $html .= $this->_row(_("Name"), $n); } - $aliases = $vc->getAttributeValues('ALIAS'); - if (!is_a($aliases, 'PEAR_Error')) { - $html .= $this->_row(_("Alias"), implode("\n", $aliases)); - } - $birthdays = $vc->getAttributeValues('BDAY'); - if (!is_a($birthdays, 'PEAR_Error')) { + try { + $html .= $this->_row(_("Alias"), implode("\n", $vc->getAttributeValues('ALIAS')); + } catch (Horde_Icalendar_Exception $e) {} + + try { + $birthdays = $vc->getAttributeValues('BDAY'); $birthday = new Horde_Date($birthdays[0]); $html .= $this->_row( _("Birthday"), $birthday->strftime($prefs->getValue('date_format'))); - } + } catch (Horde_Icalendar_Exception $e) {} $photos = $vc->getAllAttributes('PHOTO'); foreach ($photos as $p => $photo) { @@ -138,8 +170,8 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && isset($photo['params']['TYPE'])) { - if ($GLOBALS['browser']->hasFeature('datauri') === true || - $GLOBALS['browser']->hasFeature('datauri') >= strlen($photo['value'])) { + if ($browser->hasFeature('datauri') === true || + $browser->hasFeature('datauri') >= strlen($photo['value'])) { $html .= $this->_row(_("Photo"), '', false); @@ -323,38 +355,38 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base $html .= $this->_row(_("Email"), implode("\n", $emails), false); } - $title = $vc->getAttributeValues('TITLE'); - if (!is_a($title, 'PEAR_Error')) { + try { + $title = $vc->getAttributeValues('TITLE'); $html .= $this->_row(_("Title"), $title[0]); - } + } catch (Horde_Icalendar_Exception $e) {} - $role = $vc->getAttributeValues('ROLE'); - if (!is_a($role, 'PEAR_Error')) { + try { + $role = $vc->getAttributeValues('ROLE'); $html .= $this->_row(_("Role"), $role[0]); - } + } catch (Horde_Icalendar_Exception $e) {} - $org = $vc->getAttributeValues('ORG'); - if (!is_a($org, 'PEAR_Error')) { + try { + $org = $vc->getAttributeValues('ORG'); $html .= $this->_row(_("Company"), $org[0]); if (isset($org[1])) { $html .= $this->_row(_("Department"), $org[1]); } - } + } catch (Horde_Icalendar_Exception $e) {} - $notes = $vc->getAttributeValues('NOTE'); - if (!is_a($notes, 'PEAR_Error')) { + try { + $notes = $vc->getAttributeValues('NOTE'); $html .= $this->_row(_("Notes"), $notes[0]); - } + } catch (Horde_Icalendar_Exception $e) {} - $url = $vc->getAttributeValues('URL'); - if (!is_a($url, 'PEAR_Error')) { + try { + $url = $vc->getAttributeValues('URL'); $html .= $this->_row( _("URL"), '' . htmlspecialchars($url[0]) . '', false); - } + } catch (Horde_Icalendar_Exception $e) {} } if ($registry->hasMethod('contacts/import') && @@ -401,7 +433,7 @@ class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base return $this->_renderReturn( Horde::endBuffer() . $html, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index f8d92d1fd..3ef8f0a43 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -280,6 +280,7 @@ class Horde_Registry 'Horde_LoginTasks' => new Horde_Core_Binder_LoginTasks(), 'Horde_Mail' => new Horde_Core_Binder_Mail(), 'Horde_Memcache' => new Horde_Core_Binder_Memcache(), + 'Horde_Mime_Viewer' => new Horde_Core_Binder_MimeViewer(), 'Horde_Notification' => new Horde_Core_Binder_Notification(), 'Horde_Perms' => new Horde_Core_Binder_Perms(), 'Horde_Prefs' => new Horde_Core_Binder_Prefs(), diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 0c864b03a..c4d43d3fc 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -116,6 +116,7 @@ Application Framework. + @@ -151,6 +152,7 @@ Application Framework. + @@ -166,6 +168,12 @@ Application Framework. + + + + + + @@ -289,6 +297,10 @@ Application Framework. pear.horde.org + Mime + pear.horde.org + + Prefs pear.horde.org @@ -331,6 +343,10 @@ Application Framework. pear.horde.org + Icalendar + pear.horde.org + + Kolab_Server pear.horde.org @@ -403,6 +419,7 @@ Application Framework. + @@ -434,6 +451,7 @@ Application Framework. + @@ -442,6 +460,8 @@ Application Framework. + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php index cf6323f39..fe26afa16 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php @@ -19,269 +19,37 @@ class Horde_Mime_Viewer { /** - * The config array. This array is shared between all instances of - * Horde_Mime_Viewer. - * - * @var array - */ - static protected $_config = array(); - - /** - * The driver cache array. This array is shared between all instances of - * Horde_Mime_Viewer. - * - * @var array - */ - static protected $_drivercache = array(); - - /** - * Attempts to return a concrete Horde_Mime_Viewer_* object based on the - * MIME type. - * - * @param Horde_Mime_Part $mime_part An object with the information to be - * rendered. - * @param string $mime_type The MIME type (overrides the value - * in the MIME part). - * - * @return Horde_Mime_Viewer The Horde_Mime_Viewer object, or false on - * error. - */ - static final public function factory($mime_part, $mime_type = null) - { - if (is_null($mime_type)) { - $mime_type = $mime_part->getType(); - } - - /* Spawn the relevant driver, and return it (or false on failure). */ - if (($ob = self::_getDriver($mime_type, $GLOBALS['registry']->getApp())) && - self::_resolveDriver($ob['driver'], $ob['app']) && - class_exists($ob['class'])) { - $conf = array_merge(self::$_config['mime_drivers'][$ob['app']][$ob['driver']], array('_driver' => $ob['driver'])); - return new $ob['class']($mime_part, $conf); - } - - return false; - } - - /** - * Given a MIME type, this function will return an appropriate icon. - * - * @param string $mime_type The MIME type that we need an icon for. - * - * @return string The URL to the appropriate icon. + * Attempts to return a concrete Horde_Mime_Viewer_Base instance based on + * $driver. + * + * @param string $driver Either a driver name, or the full class + * name to use (class must extend + * Horde_Mime_Viewer_Base). + * @param Horde_Mime_Part $part The MIME part object to display. + * @param array $params A hash containing any additional + * configuration or parameters a subclass + * might need. + * + * @return Horde_Mime_Viewer_Base The newly created concrete instance. + * @throws Horde_Mime_Viewer_Exception */ - static final public function getIcon($mime_type) + static public function factory($driver, $part, array $params = array()) { - $app = $GLOBALS['registry']->getApp(); - $ob = self::_getIcon($mime_type, $app); - - if (is_null($ob)) { - if ($app == 'horde') { - return null; - } - - $obHorde = self::_getIcon($mime_type, 'horde'); - return is_null($obHorde) ? null : $obHorde['url']; - } elseif (($ob['match'] !== 0) && ($app != 'horde')) { - $obHorde = self::_getIcon($mime_type, 'horde'); - if (!is_null($ob['match']) && - ($obHorde['match'] < $ob['match'])) { - return $obHorde['url']; - } - } - - return $ob['url']; - } - - /** - * Given a MIME type and an app name, determine which driver can best - * handle the data. - * - * @param string $mime_type MIME type to resolve. - * @param string $app App in which to search for the driver. - * - * @return mixed Returns false if driver could not be found. Otherwise, - * an array with the following elements: - *
-     * 'app' - (string) The app containing the driver (e.g. 'horde')
-     * 'driver' - (string) Name of driver (e.g. 'enscript')
-     * 'exact' - (boolean) Was the driver and exact match?
-     * 
- */ - static final protected function _getDriver($mime_type, $app = 'horde') - { - $sig = $mime_type . '|' . $app; - if (isset(self::$_drivercache[$sig])) { - return self::$_drivercache[$sig]; - } - - /* Make sure horde config is loaded. */ - if (empty(self::$_config['mime_drivers']['horde'])) { - try { - self::$_config = Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), 'horde'); - } catch (Horde_Exception $e) { - return false; - } - } - - /* Make sure app's config is loaded. There is no requirement that - * an app have a separate config, so ignore any errors. */ - if (($app != 'horde') && empty(self::$_config['mime_drivers'][$app])) { - try { - self::$_config = Horde_Array::array_merge_recursive_overwrite(self::$_config, Horde::loadConfiguration('mime_drivers.php', array('mime_drivers', 'mime_drivers_map'), $app)); - } catch (Horde_Exception $e) {} - } - - $driver = ''; - $exact = false; - - list($primary_type,) = explode('/', $mime_type, 2); - $allSub = $primary_type . '/*'; - - /* If the app doesn't exist in $mime_drivers_map, check for Horde-wide - * viewers. */ - if (!isset(self::$_config['mime_drivers_map'][$app]) && - ($app != 'horde')) { - return self::_getDriver($mime_type, 'horde'); - } - - $dr = isset(self::$_config['mime_drivers'][$app]) ? self::$_config['mime_drivers'][$app] : array(); - $map = self::$_config['mime_drivers_map'][$app]; - - /* If an override exists for this MIME type, then use that */ - if (isset($map['overrides'][$mime_type])) { - $driver = $map['overrides'][$mime_type]; - $exact = true; - } elseif (isset($map['overrides'][$allSub])) { - $driver = $map['overrides'][$allSub]; - $exact = true; - } elseif (isset($map['registered'])) { - /* Iterate through the list of registered drivers, and see if - * this MIME type exists in the MIME types that they claim to - * handle. If the driver handles it, then assign it as the - * rendering driver. If we find a generic handler, keep iterating - * to see if we can find a specific handler. */ - foreach ($map['registered'] as $val) { - if (in_array($mime_type, $dr[$val]['handles'])) { - $driver = $val; - $exact = true; - break; - } elseif (in_array($allSub, $dr[$val]['handles'])) { - $driver = $val; - } - } - } - - /* If this is an application specific app, and an exact match was - not found, search for a Horde-wide specific driver. Only use the - Horde-specific driver if it is NOT the 'default' driver AND the - Horde driver is an exact match. */ - if (!$exact && ($app != 'horde')) { - $ob = self::_getDriver($mime_type, 'horde'); - if (empty($driver) || - (($ob['driver'] != 'default') && $ob['exact'])) { - $driver = $ob['driver']; - $app = 'horde'; - } - } - - /* If the 'default' driver exists in this app, fall back to that. */ - if (empty($driver) && self::_resolveDriver('default', $app)) { - $driver = 'default'; - } - - if (empty($driver)) { - return false; - } - - self::$_drivercache[$sig] = array( - 'app' => $app, - 'class' => (($app == 'horde') ? '' : $app . '_') . 'Horde_Mime_Viewer_' . $driver, - 'driver' => $driver, - 'exact' => $exact, - ); - - return self::$_drivercache[$sig]; - } - - /** - * Given a driver and an application, attempts to load the library file. - * - * @param string $driver Driver name. - * @param string $app Application name. - * - * @return boolean True if library file was loaded. - */ - static final protected function _resolveDriver($driver = 'default', - $app = 'horde') - { - $driver = ucfirst($driver); - - $file = ($app == 'horde') - ? dirname(__FILE__) . '/Viewer/' . $driver . '.php' - : $GLOBALS['registry']->applications[$app]['fileroot'] . '/lib/Mime/Viewer/' . $driver . '.php'; - - return require_once $file; - } - - /** - * Given an input MIME type and app, this function returns the URL of an - * icon that can be associated with it - * - * @param string $mime_type MIME type to get the icon for. - * - * @return mixed Null if not found, or an array with the following keys: - *
-     * 'exact' - (integer) How exact the match is. Null if no match.
-     *           0 - 'exact'
-     *           1 - 'primary'
-     *           2 - 'driver',
-     *           3 - 'default'
-     * 'url' - (string) URL to an icon, or null if none could be found.
-     * 
- */ - static final protected function _getIcon($mime_type, $app = 'horde') - { - if (!($ob = self::_getDriver($mime_type, $app))) { - return null; - } - $driver = $ob['driver']; - - list($primary_type,) = explode('/', $mime_type, 2); - $allSub = $primary_type . '/*'; - $ret = null; - - /* If the app doesn't exist in $mime_drivers, return now. */ - if (!isset(self::$_config['mime_drivers'][$app])) { - return null; - } - - $dr = self::$_config['mime_drivers'][$app]; - - /* If a specific icon for this driver and mimetype is defined, - then use that. */ - if (isset($dr[$driver]['icons'])) { - $icondr = $dr[$driver]['icons']; - $iconList = array($mime_type => 0, $allSub => 1, 'default' => 2); - foreach ($iconList as $key => $val) { - if (isset($icondr[$key])) { - $ret = array('match' => $val, 'url' => $icondr[$key]); - break; - } - } - } + $params['_driver'] = $driver; - /* Try to use a default icon if none already obtained. */ - if (is_null($ret['url']) && - isset($dr['default']['icons']['default'])) { - $ret = array('match' => 3, 'url' => $dr['default']['icons']['default']); + /* Base drivers (in Viewer/ directory). */ + $class = __CLASS__ . '_' . $driver; + if (class_exists($class)) { + return new $class($part, $params); } - if (!is_null($ret)) { - $ret['url'] = Horde_Themes::img('mime/' . $ret['url'], $app); + /* Explicit class name, */ + $class = $driver; + if (class_exists($class)) { + return new $class($part, $params); } - return $ret; + throw new Horde_Mime_Viewer_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.'); } } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Base.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Base.php index 6b540c59a..92641a9da 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Base.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Base.php @@ -30,11 +30,13 @@ class Horde_Mime_Viewer_Base protected $_mimepart = null; /** - * Viewer parameters. + * Required configuration parameters. * * @var array */ - protected $_params = array(); + protected $_required = array( + 'charset' + ); /** * This driver's display capabilities. @@ -67,13 +69,28 @@ class Horde_Mime_Viewer_Base * * @param Horde_Mime_Part $mime_part The object with the data to be * rendered. - * @param array $conf Configuration specific to the - * driver. + * @param array $conf Configuration: + *
+     * 'charset' - (string) The local UI charset. [REQUIRED]
+     * 'temp_file' - (callback) A callback function that returns a temporary
+     *               filename.  Is passed one parameter: a prefix string.
+     *                DEFAULT: Uses Horde_Util::getTempFile().
+     * 'text_filter' - (callback) A callback function used to filter text.
+     *                 Is called the same as Horde_Text_Filter::filter().
+     *                 DEFAULT: Uses Horde_Text_Filter::filter().
+     * 
+ * + * @throws InvalidArgumentException */ - public function __construct(Horde_Mime_Part $mime_part, - array $conf = array()) + public function __construct(Horde_Mime_Part $part, array $conf = array()) { - $this->_mimepart = $mime_part; + foreach ($this->_required as $val) { + if (!isset($conf[$val])) { + throw new InvalidArgumentException(__CLASS__ . ': Missing configuration value (' . $val . ')'); + } + } + + $this->_mimepart = $part; $this->_conf = $conf; } @@ -89,17 +106,6 @@ class Horde_Mime_Viewer_Base } /** - * Set parameters for use with this object. - * - * @param array $params An array of params to add to the internal - * params list. - */ - public function setParams(array $params = array()) - { - $this->_params = array_merge($this->_params, $params); - } - - /** * Return the rendered version of the Horde_Mime_Part object. * * @param string $mode The mode: @@ -313,7 +319,20 @@ class Horde_Mime_Viewer_Base */ public function getConfigParam($param) { - return isset($this->_conf[$param]) ? $this->_conf[$param] : null; + return isset($this->_conf[$param]) + ? $this->_conf[$param] + : null; + } + + /** + * Sets a configuration parameter for the current viewer. + * + * @param string $param The parameter name. + * @param mixed $value The parameter value. + */ + public function setConfigParam($param, $value) + { + $this->_conf[$param] = $value; } /** @@ -323,7 +342,7 @@ class Horde_Mime_Viewer_Base */ public function getDriver() { - return $this->_conf['_driver']; + return $this->getConfigParam('_driver'); } /** @@ -391,4 +410,32 @@ class Horde_Mime_Viewer_Base return $data; } + /** + * Returns a temporary file name. + * + * @return string A temp filename. + */ + protected function _getTempFile() + { + return ($temp_file = $this->getConfigParam('temp_file')) + ? call_user_func($temp_file, __CLASS__) + : Horde_Util::getTempFile(__CLASS__); + } + + /** + * Filter text. + * + * @param string $text TODO + * @param mixed $driver TODO + * @param array $params TODO + * + * @return string The filtered text. + */ + protected function _textFilter($text, $driver, array $params = array()) + { + return ($text_filter = $this->getConfigParam('text_filter')) + ? call_user_func($text_filter, $text, $driver, $params) + : Horde_Text_Filter::filter($text, $driver, $params); + } + } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php index 87754c762..e58c5ff99 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php @@ -70,17 +70,7 @@ class Horde_Mime_Viewer_Css extends Horde_Mime_Viewer_Source */ protected function _render() { - $ret = $this->_renderInline(); - - // Need Horde headers for CSS tags. - reset($ret); - Horde::startBuffer(); - require $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc'; - echo $ret[key($ret)]['data']; - require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; - $ret[key($ret)]['data'] = Horde::endBuffer(); - - return $ret; + return $this->_renderFullReturn($this->_renderInline()); } /** diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php index 00b2b1c6f..154d08688 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php @@ -39,6 +39,29 @@ class Horde_Mime_Viewer_Deb extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the dpkg binary [REQUIRED].
+     * 'monospace' - (string) A class to use to display monospace text inline.
+     *               DEFAULT: Uses style="font-family:monospace"
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -56,25 +79,28 @@ class Horde_Mime_Viewer_Deb extends Horde_Mime_Viewer_Base protected function _renderInfo() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } $data = ''; - $tmpin = Horde::getTempFile('horde_deb'); file_put_contents($tmp_deb, $this->_mimepart->getContents()); - $fh = popen($this->_conf['location'] . " -f $tmpin 2>&1", 'r'); + $fh = popen($location . ' -f ' . $this->_getTempFile() . ' 2>&1', 'r'); while ($rc = fgets($fh, 8192)) { $data .= $rc; } pclose($fh); + $monospace = $this->getConfigParam('monospace'); + return $this->_renderReturn( - '
' . htmlspecialchars($data) . '
', - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + '' : 'style="font-family:monospace">') . + htmlspecialchars($data) . '', + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php index e6f137f59..954dded2d 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php @@ -60,8 +60,8 @@ class Horde_Mime_Viewer_Enriched extends Horde_Mime_Viewer_Base protected function _renderInline() { return $this->_renderReturn( - Horde_String::convertCharset($this->_toHTML(true), $this->_mimepart->getCharset()), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + Horde_String::convertCharset($this->_toHTML(true), $this->_mimepart->getCharset(), $this->getConfigParam('charset')), + 'text/html; charset=' . $this->getConfigParam('charset') ); } @@ -168,9 +168,7 @@ class Horde_Mime_Viewer_Enriched extends Horde_Mime_Viewer_Base $text = preg_replace('/^ (.*) $/s', '\1', $text); // Make URLs clickable. - $text = Horde_Text_Filter::filter($text, 'linkurls', array( - 'callback' => 'Horde::externalUrl' - )); + $text = $this->_textFilter($text, 'linkurls'); /* Wordwrap -- note this could impact on our above RFC compliance *IF* * we honored nofill tags (which we don't yet). */ diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php index 157a868e8..6bf1b1eba 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php @@ -51,6 +51,27 @@ class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Base protected $_tmp = array(); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'browser' - (Horde_Browser) A browser object.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'browser' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -76,9 +97,9 @@ class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Base return array( $this->_mimepart->getMimeId() => array( - 'data' => Horde_String::convertCharset($html['data'], $this->_mimepart->getCharset()), + 'data' => Horde_String::convertCharset($html['data'], $this->_mimepart->getCharset(), $this->getConfigParam('charset')), 'status' => $html['status'], - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -108,17 +129,17 @@ class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Base */ protected function _cleanHTML($data, $options = array()) { - global $browser; - + $browser = $this->getConfigParam('browser'); $charset = isset($options['charset']) ? $options['charset'] : $this->_mimepart->getCharset(); - $strip_style_attributes = (!empty($options['inline']) && - (($browser->isBrowser('mozilla') && - ($browser->getMajor() == 4)) || - $browser->isBrowser('msie'))); + $strip_style_attributes = + (!empty($options['inline']) && + (($browser->isBrowser('mozilla') && + ($browser->getMajor() == 4)) || + $browser->isBrowser('msie'))); - $data = Horde_Text_Filter::filter($data, array('cleanhtml', 'xss'), array( + $data = $this->_textFilter($data, array('cleanhtml', 'xss'), array( array( 'charset' => $charset ), diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php index 6f6766380..505c67216 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php @@ -29,14 +29,13 @@ class Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Base /** * Constructor. * - * @param Horde_Mime_Part $mime_part Reference to an object with the - * information to be rendered. - * @param array $conf Configuration specific to the - * driver. + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration. */ - public function __construct($mime_part, $conf = array()) + public function __construct(Horde_Mime_Part $part, array $conf = array()) { - parent::__construct($mime_part, $conf); + parent::__construct($part, $conf); /* TODO: Are there other image types that are compressed? */ $this->_metadata['compressed'] = in_array($this->_getType(), array('image/gif', 'image/jpeg', 'image/png')); diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php index c51be43e8..7bc225fe2 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php @@ -29,6 +29,27 @@ class Horde_Mime_Viewer_Msexcel extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the gnumeric binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -36,22 +57,21 @@ class Horde_Mime_Viewer_Msexcel extends Horde_Mime_Viewer_Base protected function _render() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } - $tmp_in = Horde::getTempFile('horde_msexcel'); - $tmp_out = Horde::getTempFile('horde_msexcel'); + $tmp_in = $this->_getTempFile(); + $tmp_out = $this->_getTempFile(); file_put_contents($tmp_in, $this->_mimepart->getContents()); - $args = ' -E Gnumeric_Excel:excel_dsf -T Gnumeric_html:html40 ' . $tmp_in . ' ' . $tmp_out; - exec($this->_conf['location'] . $args); + exec($location . ' -E Gnumeric_Excel:excel_dsf -T Gnumeric_html:html40 ' . $tmp_in . ' ' . $tmp_out); return $this->_renderReturn( file_get_contents($tmp_out), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php index 424535509..336f95f53 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php @@ -28,6 +28,27 @@ class Horde_Mime_Viewer_Mspowerpoint extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the ppthtml binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -35,17 +56,17 @@ class Horde_Mime_Viewer_Mspowerpoint extends Horde_Mime_Viewer_Base protected function _render() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } $data = ''; - $tmp_ppt = Horde::getTempFile('horde_mspowerpoint'); + $tmp_ppt = $this->_getTempFile(); file_put_contents($tmp_ppt, $this->_mimepart->getContents()); - $fh = popen($this->_conf['location'] . " $tmp_ppt 2>&1", 'r'); + $fh = popen($location . ' ' . $tmp_ppt . ' 2>&1', 'r'); while (($rc = fgets($fh, 8192))) { $data .= $rc; } @@ -53,7 +74,7 @@ class Horde_Mime_Viewer_Mspowerpoint extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php index c28287dd6..d08254853 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php @@ -29,6 +29,27 @@ class Horde_Mime_Viewer_Msword extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the abiword binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -36,21 +57,20 @@ class Horde_Mime_Viewer_Msword extends Horde_Mime_Viewer_Base protected function _render() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } - $tmp_in = Horde::getTempFile('msword'); - $tmp_out = Horde::getTempFile('msword'); + $tmp_in = $this->_getTempFile(); + $tmp_out = $this->_getTempFile(); file_put_contents($tmp_in, $this->_mimepart->getContents()); - $args = ' --to=html --to-name=' . $tmp_out . ' ' . $tmp_in; - exec($this->_conf['location'] . $args); + exec($location . ' --to=html --to-name=' . $tmp_out . ' ' . $tmp_in); - if (file_exists($tmp_output)) { - $data = file_get_contents($tmp_output); + if (file_exists($tmp_out)) { + $data = file_get_contents($tmp_out); $type = 'text/html'; } else { $data = _("Unable to translate this Word document"); @@ -59,7 +79,7 @@ class Horde_Mime_Viewer_Msword extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - $type . '; charset=' . $GLOBALS['registry']->getCharset() + $type . '; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php index ea7a42c88..99d65635b 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php @@ -42,6 +42,21 @@ class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'zip' - (Horde_Compress_Zip) A zip object.
+     * 
+ */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -64,8 +79,10 @@ class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base 'table:number-columns-spanned=' => 'colspan=' ); - $zip = Horde_Compress::factory('zip'); - $list = $zip->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST)); + if (!$this->getConfigParam('zip')) { + $this->setConfigParam('zip', Horde_Compress::factory('Zip')); + } + $list = $this->getConfigParam('zip')->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST)); foreach ($list as $key => $file) { if (in_array($file['name'], $fnames)) { @@ -102,8 +119,8 @@ class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base $result = @$xslt->process($dom, array( 'metaFileURL' => $tmpdir . 'meta.xml', 'stylesFileURL' => $tmpdir . 'styles.xml', - 'disableJava' => true) - ); + 'disableJava' => true + )); $result = $xslt->result_dump_mem($result); } else { // Use XSLT @@ -111,8 +128,8 @@ class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base $result = @xslt_process($xslt, $tmpdir . 'content.xml', $xsl_file, null, null, array( 'metaFileURL' => $tmpdir . 'meta.xml', 'stylesFileURL' => $tmpdir . 'styles.xml', - 'disableJava' => true) - ); + 'disableJava' => true + )); if (!$result) { $result = xslt_error($xslt); } @@ -127,4 +144,5 @@ class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Base ) ); } + } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php index 636bf2da0..722ee2c31 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php @@ -52,7 +52,7 @@ class Horde_Mime_Viewer_Php extends Horde_Mime_Viewer_Source return $this->_renderReturn( $this->_lineNumber(trim(str_replace(array("\n", '
'), array('', "\n"), $text))), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php index 9d25aa2a8..4dca5d3e7 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php @@ -43,7 +43,7 @@ class Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Base $text = $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')); } - $text = '' . Horde_Text_Filter::filter($text, 'text2html', array( + $text = '' . $this->_textFilter($text, 'Text2html', array( 'charset' => $charset, 'parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL )) . ''; @@ -61,7 +61,7 @@ class Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Base */ protected function _renderInline() { - $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()); + $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), $this->getConfigParam('charset')); /* Check for 'flowed' text data. */ $data = ($this->_mimepart->getContentTypeParameter('format') == 'flowed') @@ -70,7 +70,7 @@ class Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php index 2ef0d23e0..2e84aff68 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php @@ -39,6 +39,23 @@ class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Base 'forceinline' => false ); + /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'monospace' - (string) A class to use to display monospace text inline.
+     *               DEFAULT: Uses style="font-family:monospace"
+     * 'rar' - (Horde_Compress_Rar) A zip object.
+     * 
+ */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + /** * Return the full rendered version of the Horde_Mime_Part object. * @@ -57,12 +74,13 @@ class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Base */ protected function _renderInfo() { + $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); - $rar = Horde_Compress::factory('rar'); - $rarData = $rar->decompress($contents); - - $charset = $GLOBALS['registry']->getCharset(); + if (!$this->getConfigParam('rar')) { + $this->setConfigParam('rar', Horde_Compress::factory('rar')); + } + $rarData = $this->getConfigParam('rar')->decompress($contents); $fileCount = count($rarData); $name = $this->_mimepart->getName(true); @@ -70,13 +88,30 @@ class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Base $name = _("unnamed"); } - $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ":\n" . - '
' .
-            Horde_Text_Filter::filter(_("Archive Name") . ':  ' . $name, 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" .
-            Horde_Text_Filter::filter(_("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" .
-            Horde_Text_Filter::filter(sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) .
+        $monospace = $this->getConfigParam('monospace');
+
+        $text = '' .
+            htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) .
+            ":\n" .
+            '
' : 'style="font-family:monospace">') . + $this->_textFilter(_("Archive Name") . ': ' . $name, 'space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n" . + $this->_textFilter(_("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n" . + $this->_textFilter(sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n\n" . - Horde_Text_Filter::filter( + $this->_textFilter( Horde_String::pad(_("File Name"), 50, ' ', STR_PAD_RIGHT) . Horde_String::pad(_("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(_("Size"), 10, ' ', STR_PAD_LEFT) . @@ -84,15 +119,19 @@ class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Base Horde_String::pad(_("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(_("Ratio"), 10, ' ', STR_PAD_LEFT), 'space2html', - array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" . - str_repeat('-', 109) . "\n"; + array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + ) + ) . "\n" . str_repeat('-', 109) . "\n"; foreach ($rarData as $val) { $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']); - $text .= Horde_Text_Filter::filter( + $text .= $this->_textFilter( Horde_String::pad($val['name'], 50, ' ', STR_PAD_RIGHT) . Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT) . @@ -100,12 +139,15 @@ class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Base Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT) . Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT), 'space2html', - array('encode' => true, 'encode_all' => true) + array( + 'encode' => true, + 'encode_all' => true + ) ) . "\n"; } return $this->_renderReturn( - nl2br($text . str_repeat('-', 106) . "\n
"), + nl2br($text . str_repeat('-', 106) . "\n
"), 'text/html; charset=' . $charset ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Report.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Report.php index 6581675b4..7fc1eadb0 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Report.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Report.php @@ -16,12 +16,35 @@ class Horde_Mime_Viewer_Report extends Horde_Mime_Viewer_Base { /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'viewer_callback' - (callback) A callback to a factory that will
+     *                     return the appropriate viewer for the embedded
+     *                     MIME type. Is passed three parameters: the
+     *                     current driver object, the MIME part object, and
+     *                     the MIME type to use.
+     * 
+ */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + + /** * Return the underlying MIME Viewer for this part. * * @return mixed A Horde_Mime_Viewer object, or false if not found. */ protected function _getViewer() { + if (!($callback = $this->getConfigParam('viewer_callback'))) { + return false; + } + if (!($type = $this->_mimepart->getContentTypeParameter('report-type'))) { /* This is a broken RFC 3462 message, since 'report-type' is * mandatory. Try to determine the report-type by looking at the @@ -33,12 +56,7 @@ class Horde_Mime_Viewer_Report extends Horde_Mime_Viewer_Base $type = $parts[1]->getSubType(); } - $viewer = Horde_Mime_Viewer::factory($this->_mimepart, 'message/' . Horde_String::lower($type)); - if ($viewer) { - $viewer->setParams($this->_params); - } - - return $viewer; + return call_user_func($callback, $this, $this->_mimepart, 'message/' . Horde_String::lower($type)); } } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php index 1d53c3954..dd670314b 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php @@ -36,7 +36,7 @@ class Horde_Mime_Viewer_Rfc822 extends Horde_Mime_Viewer_Base { return $this->_renderReturn( null, - 'text/plain; charset=' . $GLOBALS['registry']->getCharset() + 'text/plain; charset=' . $this->getConfigParam('charset') ); } @@ -81,8 +81,8 @@ class Horde_Mime_Viewer_Rfc822 extends Horde_Mime_Viewer_Base } return $this->_renderReturn( - (empty($header_output) ? '' : ('
' . Horde_Text_Filter::filter(implode("
\n", $header_output), 'emails') . '
')), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + (empty($header_output) ? '' : ('
' . $this->_textFilter(implode("
\n", $header_output), 'emails') . '
')), + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php index 628649ca6..d2122d974 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php @@ -70,8 +70,8 @@ class Horde_Mime_Viewer_Richtext extends Horde_Mime_Viewer_Base protected function _renderInline() { return $this->_renderReturn( - Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset(), $this->getConfigParam('charset')), + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php index 4abd20c09..3427ada69 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php @@ -38,6 +38,29 @@ class Horde_Mime_Viewer_Rpm extends Horde_Mime_Viewer_Base 'forceinline' => false ); + /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) The location of the rpm binary [REQUIRED].
+     * 'monospace' - (string) A class to use to display monospace text inline.
+     *               DEFAULT: Uses style="font-family:monospace"
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + /** * Return the full rendered version of the Horde_Mime_Part object. * @@ -56,25 +79,29 @@ class Horde_Mime_Viewer_Rpm extends Horde_Mime_Viewer_Base protected function _renderInfo() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } $data = ''; - $tmp_rpm = Horde::getTempFile('horde_rpm'); + $tmp_rpm = $this->_getTempFile(); file_put_contents($tmp_rpm, $this->_mimepart->getContents()); - $fh = popen($this->_conf['location'] . " -qip $tmp_rpm 2>&1", 'r'); + $fh = popen($location . ' -qip ' . $tmp_rpm . ' 2>&1', 'r'); while (($rc = fgets($fh, 8192))) { $data .= $rc; } pclose($fh); + $monospace = $this->getConfigParam('monospace'); + return $this->_renderReturn( - '
' . htmlspecialchars($data) . '
', - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + '' : 'style="font-family:monospace">') . + htmlspecialchars($data) . '', + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php index 89ae1a60e..4c2c341f4 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php @@ -29,6 +29,27 @@ class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Base 'raw' => false ); + /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the unrtf binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + /** * Return the full rendered version of the Horde_Mime_Part object. * @@ -37,17 +58,17 @@ class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Base protected function _render() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } - $tmp_rtf = Horde::getTempFile('rtf'); - $tmp_output = Horde::getTempFile('rtf'); + $tmp_rtf = $this->_getTempFile(); + $tmp_output = $this->_getTempFile(); file_put_contents($tmp_rtf, $this->_mimepart->getContents()); - exec($this->_conf['location'] . " $tmp_rtf > $tmp_output"); + exec($location . ' ' . $tmp_rtf . ' > ' . $tmp_output); $data = file_exists($tmp_output) ? file_get_contents($tmp_output) @@ -55,7 +76,7 @@ class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php index 8e3d03e40..5ae2fe7ea 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php @@ -17,22 +17,37 @@ class Horde_Mime_Viewer_Security extends Horde_Mime_Viewer_Base { /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'viewer_callback' - (callback) A callback to a factory that will
+     *                     return the appropriate viewer for the embedded
+     *                     MIME type. Is passed three parameters: the
+     *                     current driver object, the MIME part object, and
+     *                     the MIME type to use.
+     * 
+ */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + + /** * Return the underlying MIME Viewer for this part. * * @return mixed A Horde_Mime_Viewer object, or false if not found. */ protected function _getViewer() { - if (!($protocol = $this->_mimepart->getContentTypeParameter('protocol'))) { - return false; - } - - $viewer = Horde_Mime_Viewer::factory($this->_mimepart, $protocol); - if ($viewer) { - $viewer->setParams($this->_params); + if (($callback = $this->getConfigParam('viewer_callback')) && + ($protocol = $this->_mimepart->getContentTypeParameter('protocol'))) { + return call_user_func($callback, $this, $this->_mimepart, $protocol); } - return $viewer; + return false; } } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php index a5c2f0c5f..542bc1c35 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php @@ -70,7 +70,7 @@ class Horde_Mime_Viewer_Smil extends Horde_Mime_Viewer_Base return $this->_renderReturn( $this->_content, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php index 9a0cc632d..dfbb61415 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php @@ -32,6 +32,27 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the source-highlight binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -49,14 +70,13 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Base protected function _renderInline() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } - /* Create temporary files for Webcpp. */ - $tmpin = Horde::getTempFile('SrcIn'); - $tmpout = Horde::getTempFile('SrcOut'); + $tmpin = $this->_getTempFile(); + $tmpout = $this->_getTempFile(); /* Write the contents of our buffer to the temporary input file. */ file_put_contents($tmpin, $this->_mimepart->getContents()); @@ -65,13 +85,13 @@ class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Base $lang = $this->_typeToLang($this->_mimepart->getType()); /* Execute Source-Highlite. */ - exec($this->_conf['location'] . " --src-lang $lang --out-format html --input $tmpin --output $tmpout"); + exec($location . ' --src-lang ' . escapeshellarg($lang) . ' --out-format html --input ' . $tmpin . ' --output ' . $tmpout); $results = file_get_contents($tmpout); unlink($tmpout); return $this->_renderReturn( $results, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php index cfa3b0f99..e7a4a56eb 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php @@ -41,16 +41,21 @@ class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Base /** * Constructor. * - * @param Horde_Mime_Part $mime_part Reference to an object with the - * information to be rendered. - * @param array $conf Configuration specific to the - * driver. + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'gzip' - (Horde_Compress_Gzip) A gzip object.
+     * 'monospace' - (string) A class to use to display monospace text inline.
+     *               DEFAULT: Uses style="font-family:monospace"
+     * 'tar' - (Horde_Compress_Tar) A tar object.
+     * 
*/ - public function __construct($mime_part, $conf = array()) + public function __construct(Horde_Mime_Part $part, array $conf = array()) { - parent::__construct($mime_part, $conf); + parent::__construct($part, $conf); - $this->_metadata['compressed'] = in_array($mime_part->getSubType(), $this->_gzipSubtypes); + $this->_metadata['compressed'] = in_array($part->getSubType(), $this->_gzipSubtypes); } /** @@ -78,19 +83,23 @@ class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Base return array(); } + $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); /* Decompress gzipped files. */ if (in_array($subtype, $this->_gzipSubtypes)) { - $gzip = Horde_Compress::factory('gzip'); - $contents = $gzip->decompress($contents); + if (!$this->getConfigParam('gzip')) { + $this->setConfigParam('gzip', Horde_Compress::factory('Gzip')); + } + $contents = $this->getConfigParam('gzip')->decompress($contents); } /* Obtain the list of files/data in the tar file. */ - $tar = Horde_Compress::factory('tar'); - $tarData = $tar->decompress($contents); + if (!$this->getConfigParam('tar')) { + $this->setConfigParam('tar', Horde_Compress::factory('Tar')); + } + $tarData = $this->getConfigParam('tar')->decompress($contents); - $charset = $GLOBALS['registry']->getCharset(); $fileCount = count($tarData); $name = $this->_mimepart->getName(true); @@ -98,35 +107,58 @@ class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Base $name = _("unnamed"); } + $monospace = $this->getConfigParam('monospace'); + $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ":\n" . - '
' .
-            Horde_Text_Filter::filter(_("Archive Name") . ':  ' . $name, 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" .
-            Horde_Text_Filter::filter(_("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . "\n" .
-            Horde_Text_Filter::filter(sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) .
+            '
' : 'style="font-family:monospace">') . + $this->_textFilter(_("Archive Name") . ': ' . $name, 'Space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n" . + $this->_textFilter(_("Archive File Size") . ': ' . strlen($contents) . ' bytes', 'Space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n" . + $this->_textFilter(sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount), 'Space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )) . "\n\n" . - Horde_Text_Filter::filter( + $this->_textFilter( str_pad(_("File Name"), 62, ' ', STR_PAD_RIGHT) . str_pad(_("Attributes"), 15, ' ', STR_PAD_LEFT) . str_pad(_("Size"), 10, ' ', STR_PAD_LEFT) . str_pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT), - 'space2html', - array('charset' => $charset, 'encode' => true, 'encode_all' => true) + 'Space2html', + array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + ) ) . "\n" . str_repeat('-', 106) . "\n"; foreach ($tarData as $val) { - $text .= Horde_Text_Filter::filter( + $text .= $this->_textFilter( str_pad($val['name'], 62, ' ', STR_PAD_RIGHT) . str_pad($val['attr'], 15, ' ', STR_PAD_LEFT) . str_pad($val['size'], 10, ' ', STR_PAD_LEFT) . str_pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT), - 'space2html', - array('charset' => $charset, 'encode' => true, 'encode_all' => true) + 'Space2html', + array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + ) ) . "\n"; } return $this->_renderReturn( - nl2br($text . str_repeat('-', 106) . "\n
"), + nl2br($text . str_repeat('-', 106) . "\n
"), 'text/html; charset=' . $charset ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php index 46c2cd5cc..91a237e00 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php @@ -40,6 +40,23 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'tnef' - (Horde_Compress_Tnef) TNEF object.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -58,8 +75,10 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base */ protected function _renderInfo() { - $tnef = Horde_Compress::factory('tnef'); - $info = $tnef->decompress($this->_mimepart->getContents()); + if (!$this->getConfigParam('tnef')) { + $this->setConfigParam('tnef', Horde_Compress::factory('Tnef')); + } + $info = $this->getConfigParam('tnef')->decompress($this->_mimepart->getContents()); $data = ''; if (empty($info)) { @@ -74,7 +93,7 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php index 7e6522c4b..a7aee8660 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php @@ -30,6 +30,27 @@ class Horde_Mime_Viewer_Wordperfect extends Horde_Mime_Viewer_Base ); /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'location' - (string) Location of the wpd2html binary.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + $this->_required = array_merge($this->_required, array( + 'location' + )); + + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -37,17 +58,17 @@ class Horde_Mime_Viewer_Wordperfect extends Horde_Mime_Viewer_Base protected function _render() { /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { + if (!($location = $this->getConfigParam('location')) || + !file_exists($location)) { return array(); } - $tmp_wpd = Horde::getTempFile('wpd'); - $tmp_output = Horde::getTempFile('wpd'); + $tmp_wpd = $this->_getTempFile(); + $tmp_output = $this->_getTempFile(); file_put_contents($tmp_wpd, $this->_mimepart->getContents()); - exec($this->_conf['location'] . " $tmp_wpd > $tmp_output"); + exec($location . ' ' . $tmp_wpd . ' > ' . $tmp_output); $data = file_exists($tmp_output) ? file_get_contents($tmp_output) @@ -55,7 +76,7 @@ class Horde_Mime_Viewer_Wordperfect extends Horde_Mime_Viewer_Base return $this->_renderReturn( $data, - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $this->getConfigParam('charset') ); } diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php index be2c0b7ef..b7c9a874f 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php @@ -47,6 +47,25 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base protected $_callback = null; /** + * Constructor. + * + * @param Horde_Mime_Part $mime_part The object with the data to be + * rendered. + * @param array $conf Configuration: + *
+     * 'monospace' - (string) A class to use to display monospace text inline.
+     *               DEFAULT: Uses style="font-family:monospace"
+     * 'zip' - (Horde_Compress_Zip) Zip object.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(Horde_Mime_Part $part, array $conf = array()) + { + parent::__construct($part, $conf); + } + + /** * Return the full rendered version of the Horde_Mime_Part object. * * @return array See parent::render(). @@ -76,10 +95,15 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base */ protected function _toHTML() { + $charset = $this->getConfigParam('charset'); $contents = $this->_mimepart->getContents(); - $zip = Horde_Compress::factory('zip'); - $zipInfo = $zip->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST)); + if (!$this->getConfigParam('zip')) { + $this->setConfigParam('zip', Horde_Compress::factory('Zip')); + } + $zipInfo = $this->getConfigParam('zip')->decompress($contents, array( + 'action' => Horde_Compress_Zip::ZIP_LIST + )); $fileCount = count($zipInfo); @@ -95,9 +119,12 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base $name = _("unnamed"); } + $monospace = $this->getConfigParam('monospace'); + $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ":\n" . - '
' . - Horde_Text_Filter::filter( + '
' : 'style="font-family:monospace">') . + $this->_textFilter( _("Archive Name") . ': ' . $name . "\n" . _("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . @@ -110,8 +137,12 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base Horde_String::pad(_("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(_("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", - 'space2html', - array('charset' => $GLOBALS['registry']->getCharset(), 'encode' => true, 'encode_all' => true) + 'Space2html', + array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + ) ) . str_repeat('-', 59 + $maxlen) . "\n"; foreach ($zipInfo as $key => $val) { @@ -119,16 +150,20 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base ? 0 : 100 * ($val['csize'] / $val['size']); - $val['name'] = Horde_String::pad($val['name'], $maxlen, ' ', STR_PAD_RIGHT); - $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT); - $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT); - $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT); + $val['name'] = Horde_String::pad($val['name'], $maxlen, ' ', STR_PAD_RIGHT); + $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT); + $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT); + $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT); $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT); - $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT); + $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT); reset($val); while (list($k, $v) = each($val)) { - $val[$k] = Horde_Text_Filter::filter($v, 'space2html', array('charset' => $GLOBALS['registry']->getCharset(), 'encode' => true, 'encode_all' => true)); + $val[$k] = $this->_textFilter($v, 'Space2html', array( + 'charset' => $charset, + 'encode' => true, + 'encode_all' => true + )); } if (!is_null($this->_callback)) { @@ -142,7 +177,7 @@ class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Base return $this->_renderReturn( nl2br($text . str_repeat('-', 59 + $maxlen) . "\n
"), - 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'text/html; charset=' . $charset ); } diff --git a/framework/Mime_Viewer/package.xml b/framework/Mime_Viewer/package.xml index 1a85f0ca8..c0d445c28 100644 --- a/framework/Mime_Viewer/package.xml +++ b/framework/Mime_Viewer/package.xml @@ -74,7 +74,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -103,43 +102,37 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.5.4 - Core + Browser pear.horde.org - Exception + Compress pear.horde.org - Mime + Exception pear.horde.org - Util - pear.horde.org - - - gettext - - - - - Browser + Mime pear.horde.org - Compress + Text_Filter pear.horde.org - Icalendar + Text_Flowed pear.horde.org - Text_Filter + Util pear.horde.org - + + gettext + + @@ -183,7 +176,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/gollem/config/mime_drivers.php.dist b/gollem/config/mime_drivers.php.dist index 71db5d49a..74d0e40fa 100644 --- a/gollem/config/mime_drivers.php.dist +++ b/gollem/config/mime_drivers.php.dist @@ -1,35 +1,20 @@ true, - 'handles' => array( - 'image/*' +$mime_drivers = array( + /* Image viewing. Gollem can display images inline. */ + 'images' => array( + 'inline' => true, + 'handles' => array( + 'image/*' + ) ) ); diff --git a/gollem/lib/Mime/Viewer/Images.php b/gollem/lib/Mime/Viewer/Images.php index 711b1868a..3c8c08d6e 100644 --- a/gollem/lib/Mime/Viewer/Images.php +++ b/gollem/lib/Mime/Viewer/Images.php @@ -1,6 +1,6 @@ * @package Horde_Mime */ -class Gollem_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images +class Gollem_Mime_Viewer_Images extends Horde_Mime_Viewer_Images { /** * Can this driver render various views? diff --git a/gollem/manager.php b/gollem/manager.php index a03075c6b..1348e5422 100644 --- a/gollem/manager.php +++ b/gollem/manager.php @@ -389,7 +389,7 @@ if (is_array($list) && $numitem && $read_perms) { $item['graphic'] = $folder_img; } else { if (empty($icon_cache[$val['type']])) { - $icon_cache[$val['type']] = Horde::img(Horde_Mime_Viewer::getIcon(Horde_Mime_Magic::extToMime($val['type'])), '', '', ''); + $icon_cache[$val['type']] = Horde::img($injector->getInstance('Horde_Mime_Viewer')->getIcon(Horde_Mime_Magic::extToMime($val['type'])), '', '', ''); } $item['graphic'] = $icon_cache[$val['type']]; } diff --git a/horde/admin/phpshell.php b/horde/admin/phpshell.php index b2a346863..c8b3c1fa0 100644 --- a/horde/admin/phpshell.php +++ b/horde/admin/phpshell.php @@ -66,8 +66,7 @@ if ($command) { $part->setType('application/x-httpd-phps'); $part->buildMimeIds(); - $viewer = Horde_Mime_Viewer::factory($part); - $pretty = $viewer->render('inline'); + $pretty = $injector->getInstance('Horde_Mime_Viewer')->getViewer($part)->render('inline'); echo '

' . _("PHP Code") . '

' . $pretty[1]['data'] . diff --git a/horde/config/mime_drivers.php.dist b/horde/config/mime_drivers.php.dist index f87b23a72..1f8bca25d 100644 --- a/horde/config/mime_drivers.php.dist +++ b/horde/config/mime_drivers.php.dist @@ -1,75 +1,10 @@ 'text.png', - 'message/*' => 'mail.png', - 'unknown/*' => 'binary.png', - 'video/*' => 'video.png', - 'application/pgp-signature' => 'encryption.png', - 'application/x-pkcs7-signature' => 'encryption.png', - 'application/octet-stream' => 'binary.png' -); - - -/** - * Default text driver settings - */ -$mime_drivers['horde']['simple'] = array( - 'inline' => false, - 'handles' => array( - 'text/*' +$mime_drivers = array( + /* Default driver. */ + 'default' => array( + 'icons' => array( + 'default' => 'text.png', + 'message/*' => 'mail.png', + 'unknown/*' => 'binary.png', + 'video/*' => 'video.png', + 'application/pgp-signature' => 'encryption.png', + 'application/x-pkcs7-signature' => 'encryption.png', + 'application/octet-stream' => 'binary.png' + ) ), - 'icons' => array( - 'default' => 'text.png' - ) -); - -/** - * Plain text driver settings - */ -$mime_drivers['horde']['plain'] = array( - 'inline' => true, - 'handles' => array( - 'text/plain' + /* Default text driver. */ + 'simple' => array( + 'handles' => array( + 'text/*' + ), + 'icons' => array( + 'default' => 'text.png' + ) ), - 'icons' => array( - 'default' => 'text.png' - ) -); - -/** - * Default audio driver settings - */ -$mime_drivers['horde']['audio'] = array( - 'inline' => false, - 'handles' => array( - 'audio/*' + /* Plain text driver. */ + 'plain' => array( + 'inline' => true, + 'handles' => array( + 'text/plain' + ), + 'icons' => array( + 'default' => 'text.png' + ) ), - 'icons' => array( - 'default' => 'audio.png' - ) -); - -/** - * Default smil driver settings - */ -$mime_drivers['horde']['smil'] = array( - 'inline' => true, - 'handles' => array( - 'application/smil' + /* Default audio driver. */ + 'audio' => array( + 'handles' => array( + 'audio/*' + ), + 'icons' => array( + 'default' => 'audio.png' + ) ), - 'icons' => array( - 'default' => 'video.png' - ) -); - -/** - * PHP driver settings - */ -$mime_drivers['horde']['php'] = array( - 'inline' => true, - 'handles' => array( - 'application/x-php', - 'x-extension/phps', - 'x-extension/php3s', - 'application/x-httpd-php', - 'application/x-httpd-php3', - 'application/x-httpd-phps' + /* Default smil driver. */ + 'smil' => array( + 'inline' => true, + 'handles' => array( + 'application/smil' + ), + 'icons' => array( + 'default' => 'video.png' + ) ), - 'icons' => array( - 'default' => 'php.png' - ) -); - -/** - * CSS driver settings - */ -$mime_drivers['horde']['css'] = array( - 'inline' => true, - 'handles' => array( - 'text/css', - 'x-extension/css' + /* PHP pretty-print code display. */ + 'php' => array( + 'inline' => true, + 'handles' => array( + 'application/x-php', + 'x-extension/phps', + 'x-extension/php3s', + 'application/x-httpd-php', + 'application/x-httpd-php3', + 'application/x-httpd-phps' + ), + 'icons' => array( + 'default' => 'php.png' + ) ), - 'icons' => array( - 'default' => 'html.png' - ) -); - -/** - * HTML text driver settings - */ -$mime_drivers['horde']['html'] = array( - // NOTE: Inline HTML viewing is DISABLED by default. - 'inline' => false, - 'handles' => array( - 'text/html' - ), - 'icons' => array( - 'default' => 'html.png' + /* CSS pretty-print display. */ + 'css' => array( + 'inline' => true, + 'handles' => array( + 'text/css', + 'x-extension/css' + ), + 'icons' => array( + 'default' => 'html.png' + ) ), - // Check for phishing exploits? - 'phishing_check' => true -); - -/** - * Enriched text driver settings - */ -$mime_drivers['horde']['enriched'] = array( - 'inline' => true, - 'handles' => array( - 'text/enriched' + /* HTML display. */ + 'html' => array( + // NOTE: Inline HTML viewing is DISABLED by default. + 'inline' => false, + 'handles' => array( + 'text/html' + ), + 'icons' => array( + 'default' => 'html.png' + ), + + // Check for phishing exploits? + 'phishing_check' => true ), - 'icons' => array( - 'default' => 'text.png' - ) -); - -/** - * Richtext text driver settings - */ -$mime_drivers['horde']['richtext'] = array( - 'inline' => true, - 'handles' => array( - 'text/richtext' + /* Enriched text display. */ + 'enriched' => array( + 'inline' => true, + 'handles' => array( + 'text/enriched' + ), + 'icons' => array( + 'default' => 'text.png' + ) ), - 'icons' => array( - 'default' => 'text.png' - ) -); - -/** - * Source-Highlight driver settings - * http://www.gnu.org/software/src-highlite/ - */ -$mime_drivers['horde']['srchighlite'] = array( - 'location' => '/usr/bin/source-highlight', - 'inline' => true, - 'handles' => array( - 'application/x-httpd-php', - 'application/x-httpd-php3', - 'application/x-httpd-phps', - 'application/x-javascript', - 'application/x-perl', - 'application/x-php', - 'application/x-python', - 'application/x-ruby', - 'application/x-sh', - 'application/x-shellscript', - 'application/x-tcl', - 'application/xml', - 'text/cpp', - 'text/css', - 'text/diff', - 'text/x-c++hdr', - 'text/x-c++src', - 'text/x-chdr', - 'text/x-csrc', - 'text/x-diff', - 'text/x-emacs-lisp', - 'text/x-fortran', - 'text/x-java', - 'text/x-pascal', - 'text/x-patch', - 'text/x-sql', - 'text/x-tex', - 'text/xml', - 'x-extension/asm', - 'x-extension/bat', - 'x-extension/cs', - 'x-extension/css', - 'x-extension/f77', - 'x-extension/f90', - 'x-extension/for', - 'x-extension/ftn', - 'x-extension/php3s', - 'x-extension/phps', - 'x-extension/rc', - 'x-extension/vb', - 'x-extension/vba' + /* Richtext display. */ + 'richtext' => array( + 'inline' => true, + 'handles' => array( + 'text/richtext' + ), + 'icons' => array( + 'default' => 'text.png' + ) ), - 'icons' => array( - 'default' => 'text.png', - 'application/x-httpd-php' => 'php.png', - 'application/x-httpd-php3' => 'php.png', - 'application/x-httpd-phps' => 'php.png', - 'application/x-javascript' => 'script-js.png', - 'application/x-php' => 'php.png', - 'application/x-python' => 'source-python.png', - 'application/x-sh' => 'shell.png', - 'application/x-shellscript' => 'shell.png', - 'application/xml' => 'xml.png', - 'text/cpp' => 'source-c.png', - 'text/css' => 'html.png', - 'text/x-c++hdr' => 'source-c.png', - 'text/x-c++src' => 'source-c.png', - 'text/x-chdr' => 'source-h.png', - 'text/x-csrc' => 'source-c.png', - 'text/x-java' => 'source-java.png', - 'text/x-sql' => 'sql.png', - 'text/xml' => 'xml.png', - 'x-extension/css' => 'html.png', - 'x-extension/php3s' => 'php.png', - 'x-extension/phps' => 'php.png', - 'x-extension/rc' => 'xml.png' - ) -); - -/** - * Tar driver settings - * To access gzipped files, the zlib library must have been built into PHP - * (with the --with-zlib option). - */ -$mime_drivers['horde']['tgz'] = array( - 'inline' => true, - 'handles' => array( - 'application/gzip', - 'application/x-compressed-tar', - 'application/x-gtar', - 'application/x-gzip', - 'application/x-gzip-compressed', - 'application/x-tar', - 'application/x-tgz' + /* Source-highlight driver. + * http://www.gnu.org/software/src-highlite/ */ + 'srchighlite' => array( + // Disabled by default + 'disable' => true, + 'inline' => true, + 'handles' => array( + 'application/x-httpd-php', + 'application/x-httpd-php3', + 'application/x-httpd-phps', + 'application/x-javascript', + 'application/x-perl', + 'application/x-php', + 'application/x-python', + 'application/x-ruby', + 'application/x-sh', + 'application/x-shellscript', + 'application/x-tcl', + 'application/xml', + 'text/cpp', + 'text/css', + 'text/diff', + 'text/x-c++hdr', + 'text/x-c++src', + 'text/x-chdr', + 'text/x-csrc', + 'text/x-diff', + 'text/x-emacs-lisp', + 'text/x-fortran', + 'text/x-java', + 'text/x-pascal', + 'text/x-patch', + 'text/x-sql', + 'text/x-tex', + 'text/xml', + 'x-extension/asm', + 'x-extension/bat', + 'x-extension/cs', + 'x-extension/css', + 'x-extension/f77', + 'x-extension/f90', + 'x-extension/for', + 'x-extension/ftn', + 'x-extension/php3s', + 'x-extension/phps', + 'x-extension/rc', + 'x-extension/vb', + 'x-extension/vba' + ), + 'icons' => array( + 'default' => 'text.png', + 'application/x-httpd-php' => 'php.png', + 'application/x-httpd-php3' => 'php.png', + 'application/x-httpd-phps' => 'php.png', + 'application/x-javascript' => 'script-js.png', + 'application/x-php' => 'php.png', + 'application/x-python' => 'source-python.png', + 'application/x-sh' => 'shell.png', + 'application/x-shellscript' => 'shell.png', + 'application/xml' => 'xml.png', + 'text/cpp' => 'source-c.png', + 'text/css' => 'html.png', + 'text/x-c++hdr' => 'source-c.png', + 'text/x-c++src' => 'source-c.png', + 'text/x-chdr' => 'source-h.png', + 'text/x-csrc' => 'source-c.png', + 'text/x-java' => 'source-java.png', + 'text/x-sql' => 'sql.png', + 'text/xml' => 'xml.png', + 'x-extension/css' => 'html.png', + 'x-extension/php3s' => 'php.png', + 'x-extension/phps' => 'php.png', + 'x-extension/rc' => 'xml.png' + ), + + // REQUIRED: Location of the source-highlight binary + 'location' => '/usr/bin/source-highlight' ), - 'icons' => array( - 'default' => 'compressed.png' - ) -); - -/** - * Zip file driver settings - */ -$mime_drivers['horde']['zip'] = array( - 'inline' => true, - 'handles' => array( - 'application/x-compressed', - 'application/x-zip-compressed', - 'application/zip' + /* Tar file display. + * To access gzipped files, the zlib library must have been built into PHP + * (with the --with-zlib option). */ + 'tgz' => array( + 'inline' => true, + 'handles' => array( + 'application/gzip', + 'application/x-compressed-tar', + 'application/x-gtar', + 'application/x-gzip', + 'application/x-gzip-compressed', + 'application/x-tar', + 'application/x-tgz' + ), + 'icons' => array( + 'default' => 'compressed.png' + ) ), - 'icons' => array( - 'default' => 'compressed.png' - ) -); - -/** - * RAR archive driver settings - */ -$mime_drivers['horde']['rar'] = array( - 'inline' => true, - 'handles' => array( - 'application/x-rar', - 'application/x-rar-compressed' + /* Zip file display. */ + 'zip' => array( + 'inline' => true, + 'handles' => array( + 'application/x-compressed', + 'application/x-zip-compressed', + 'application/zip' + ), + 'icons' => array( + 'default' => 'compressed.png' + ) ), - 'icons' => array( - 'default' => 'compressed.png' - ) -); - -/** - * MS Word driver settings - * This driver requires AbiWord to be installed. - * AbiWord homepage: http://www.abisource.com/ - */ -$mime_drivers['horde']['msword'] = array( - 'location' => '/usr/bin/abiword', - 'inline' => false, - 'handles' => array( - 'application/msword', - 'application/vnd.ms-word' + /* RAR archive display. */ + 'rar' => array( + 'inline' => true, + 'handles' => array( + 'application/x-rar', + 'application/x-rar-compressed' + ), + 'icons' => array( + 'default' => 'compressed.png' + ) ), - 'icons' => array( - 'default' => 'msword.png' - ) -); - -/** - * MS Excel driver settings - * This driver requires Gnumeric to be installed. - * Gnumeric homepage: http://projects.gnome.org/gnumeric/ - */ -$mime_drivers['horde']['msexcel'] = array( - 'location' => '/usr/bin/ssconvert', - 'inline' => false, - 'handles' => array( - 'application/msexcel', - 'application/x-msexcel', - 'application/vnd.ms-excel' + /* MS Word display. + * This driver requires AbiWord to be installed. + * AbiWord homepage: http://www.abisource.com/ */ + 'msword' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/msword', + 'application/vnd.ms-word' + ), + 'icons' => array( + 'default' => 'msword.png' + ), + + // REQUIRED: Location of the AbiWord binary + 'location' => '/usr/bin/abiword' ), - 'icons' => array( - 'default' => 'msexcel.png' - ) -); - -/** - * MS Powerpoint driver settings - * This driver requires ppthtml, included with xlhtml, to be installed. - * xlhtml homepage: http://chicago.sourceforge.net/xlhtml/ - */ -$mime_drivers['horde']['mspowerpoint'] = array( - 'location' => '/usr/bin/ppthtml', - 'inline' => false, - 'handles' => array( - 'application/mspowerpoint', - 'application/vnd.ms-powerpoint' + /* MS Excel display. + * This driver requires Gnumeric to be installed. + * Gnumeric homepage: http://projects.gnome.org/gnumeric/ */ + 'msexcel' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/msexcel', + 'application/x-msexcel', + 'application/vnd.ms-excel' + ), + 'icons' => array( + 'default' => 'msexcel.png' + ), + + // REQUIRED: Location of the ssconvert binary + 'location' => '/usr/bin/ssconvert' ), - 'icons' => array( - 'default' => 'mspowerpoint.png' - ) -); - -/** - * vCard driver settings - */ -$mime_drivers['horde']['vcard'] = array( - 'handles' => array( - 'text/directory', - 'text/vcard', - 'text/x-vcard' + /* MS Powerpoint display. + * This driver requires ppthtml, included with xlhtml, to be installed. + * xlhtml homepage: http://chicago.sourceforge.net/xlhtml/ */ + 'mspowerpoint' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/mspowerpoint', + 'application/vnd.ms-powerpoint' + ), + 'icons' => array( + 'default' => 'mspowerpoint.png' + ), + + // REQUIRED: Location of the ppthtml binary + 'location' => '/usr/bin/ppthtml' ), - 'icons' => array( - 'default' => 'vcard.png' - ) -); - -/** - * RPM driver settings - */ -$mime_drivers['horde']['rpm'] = array( - 'location' => '/usr/bin/rpm', - 'inline' => false, - 'handles' => array( - 'application/x-rpm' + /* vCard display. */ + 'vcard' => array( + 'inline' => true, + 'handles' => array( + 'text/directory', + 'text/vcard', + 'text/x-vcard' + ), + 'icons' => array( + 'default' => 'vcard.png' + ) ), - 'icons' => array( - 'default' => 'rpm.png' - ) -); - -/** - * Debian package driver settings - */ -$mime_drivers['horde']['deb'] = array( - 'location' => '/usr/bin/dpkg', - 'inline' => false, - 'handles' => array( - 'application/x-deb', - 'application/x-debian-package' + /* RPM archive display. */ + 'rpm' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/x-rpm' + ), + 'icons' => array( + 'default' => 'rpm.png' + ), + + // REQUIRED: Location of the rpm binary + 'location' => '/usr/bin/rpm' ), - 'icons' => array( - 'default' => 'deb.png' - ) -); - -/** - * Secure multiparts (RFC 1847) - */ -$mime_drivers['horde']['security'] = array( - 'inline' => true, - 'handles' => array( - 'multipart/encrypted', - 'multipart/signed' + /* Debian archive display. */ + 'deb' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/x-deb', + 'application/x-debian-package' + ), + 'icons' => array( + 'default' => 'deb.png' + ), + + // REQUIRED: Location of the dpkg binary + 'location' => '/usr/bin/dpkg' ), - 'icons' => array( - 'default' => 'encryption.png' - ) -); - -/** - * Image settings - */ -$mime_drivers['horde']['images'] = array( - 'inline' => false, - 'handles' => array( - 'image/*' + /* Secure multipart (RFC 1847) display. */ + 'security' => array( + 'inline' => true, + 'handles' => array( + 'multipart/encrypted', + 'multipart/signed' + ), + 'icons' => array( + 'default' => 'encryption.png' + ) ), - 'icons' => array( - 'default' => 'image.png' - ) -); - -/** - * MS-TNEF Attachment (application/ms-tnef) settings - */ -$mime_drivers['horde']['tnef'] = array( - 'inline' => false, - 'handles' => array( - 'application/ms-tnef' + /* Image display. */ + 'images' => array( + 'handles' => array( + 'image/*' + ), + 'icons' => array( + 'default' => 'image.png' + ) ), - 'icons' => array( - 'default' => 'binary.png' - ) -); - -/** - * Digest message (RFC 2046 [5.2.1]) settings - */ -$mime_drivers['horde']['rfc822'] = array( - 'inline' => false, - 'handles' => array( - 'message/rfc822', - 'x-extension/eml' + /* MS-TNEF Attachment display. */ + 'tnef' => array( + 'handles' => array( + 'application/ms-tnef' + ), + 'icons' => array( + 'default' => 'binary.png' + ) ), - 'icons' => array( - 'default' => 'mail.png' - ) -); - -/** - * Report messages (RFC 3452) - */ -$mime_drivers['horde']['report'] = array( - 'inline' => true, - 'handles' => array( - 'multipart/report' + /* Digest message (RFC 2046 [5.2.1]) display. */ + 'rfc822' => array( + 'handles' => array( + 'message/rfc822', + 'x-extension/eml' + ), + 'icons' => array( + 'default' => 'mail.png' + ) ), - 'icons' => array( - 'default' => 'mail.png' - ) -); - -/** - * OpenOffice.org/StarOffice settings - */ -$mime_drivers['horde']['ooo'] = array( - 'inline' => false, - 'handles' => array( - 'application/vnd.stardivision.calc', - 'application/vnd.stardivision.draw', - 'application/vnd.stardivision.impress', - 'application/vnd.stardivision.math', - 'application/vnd.stardivision.writer', - 'application/vnd.sun.xml.calc', - 'application/vnd.sun.xml.calc.template', - 'application/vnd.sun.xml.draw', - 'application/vnd.sun.xml.draw.template', - 'application/vnd.sun.xml.impress', - 'application/vnd.sun.xml.impress.template', - 'application/vnd.sun.xml.math', - 'application/vnd.sun.xml.writer', - 'application/vnd.sun.xml.writer.global', - 'application/vnd.sun.xml.writer.template', - 'application/vnd.oasis.opendocument.presentation', - 'application/vnd.oasis.opendocument.spreadsheet', - 'application/vnd.oasis.opendocument.text' + /* Mail report messages (RFC 3452) display. */ + 'report' => array( + 'inline' => true, + 'handles' => array( + 'multipart/report' + ), + 'icons' => array( + 'default' => 'mail.png' + ) ), - 'icons' => array( - 'default' => 'ooo_calc.png', - 'application/vnd.stardivision.calc' => 'ooo_calc.png', - 'application/vnd.stardivision.draw' => 'ooo_draw.png', - 'application/vnd.stardivision.impress' => 'ooo_impress.png', - 'application/vnd.stardivision.math' => 'ooo_math.png', - 'application/vnd.stardivision.writer' => 'ooo_writer.png', - 'application/vnd.sun.xml.calc' => 'ooo_calc.png', - 'application/vnd.sun.xml.calc.template' => 'ooo_calc.png', - 'application/vnd.sun.xml.draw' => 'ooo_draw.png', - 'application/vnd.sun.xml.draw.template' => 'ooo_draw.png', - 'application/vnd.sun.xml.impress' => 'ooo_impress.png', - 'application/vnd.sun.xml.impress.template' => 'ooo_impress.png', - 'application/vnd.sun.xml.math' => 'ooo_math.png', - 'application/vnd.sun.xml.writer' => 'ooo_writer.png', - 'application/vnd.sun.xml.writer.global' => 'ooo_writer.png', - 'application/vnd.sun.xml.writer.template' => 'ooo_writer.png', - 'application/vnd.oasis.opendocument.presentation' => 'ooo_impress.png', - 'application/vnd.oasis.opendocument.spreadsheet' => 'ooo_calc.png', - 'application/vnd.oasis.opendocument.text' => 'ooo_writer.png' - ) -); - -/** - * Portable Document Format (PDF) files - */ -$mime_drivers['horde']['pdf'] = array( - /* This setting is irrelevant - PDF files can not be displayed inline. */ - 'inline' => false, - 'handles' => array( - 'application/pdf', - 'application/x-pdf', - 'image/pdf' + /* OpenOffice.org/StarOffice document display. */ + 'ooo' => array( + 'handles' => array( + 'application/vnd.stardivision.calc', + 'application/vnd.stardivision.draw', + 'application/vnd.stardivision.impress', + 'application/vnd.stardivision.math', + 'application/vnd.stardivision.writer', + 'application/vnd.sun.xml.calc', + 'application/vnd.sun.xml.calc.template', + 'application/vnd.sun.xml.draw', + 'application/vnd.sun.xml.draw.template', + 'application/vnd.sun.xml.impress', + 'application/vnd.sun.xml.impress.template', + 'application/vnd.sun.xml.math', + 'application/vnd.sun.xml.writer', + 'application/vnd.sun.xml.writer.global', + 'application/vnd.sun.xml.writer.template', + 'application/vnd.oasis.opendocument.presentation', + 'application/vnd.oasis.opendocument.spreadsheet', + 'application/vnd.oasis.opendocument.text' + ), + 'icons' => array( + 'default' => 'ooo_calc.png', + 'application/vnd.stardivision.calc' => 'ooo_calc.png', + 'application/vnd.stardivision.draw' => 'ooo_draw.png', + 'application/vnd.stardivision.impress' => 'ooo_impress.png', + 'application/vnd.stardivision.math' => 'ooo_math.png', + 'application/vnd.stardivision.writer' => 'ooo_writer.png', + 'application/vnd.sun.xml.calc' => 'ooo_calc.png', + 'application/vnd.sun.xml.calc.template' => 'ooo_calc.png', + 'application/vnd.sun.xml.draw' => 'ooo_draw.png', + 'application/vnd.sun.xml.draw.template' => 'ooo_draw.png', + 'application/vnd.sun.xml.impress' => 'ooo_impress.png', + 'application/vnd.sun.xml.impress.template' => 'ooo_impress.png', + 'application/vnd.sun.xml.math' => 'ooo_math.png', + 'application/vnd.sun.xml.writer' => 'ooo_writer.png', + 'application/vnd.sun.xml.writer.global' => 'ooo_writer.png', + 'application/vnd.sun.xml.writer.template' => 'ooo_writer.png', + 'application/vnd.oasis.opendocument.presentation' => 'ooo_impress.png', + 'application/vnd.oasis.opendocument.spreadsheet' => 'ooo_calc.png', + 'application/vnd.oasis.opendocument.text' => 'ooo_writer.png' + ) ), - 'icons' => array( - 'default' => 'pdf.png' - ) -); - -/** - * RTF driver settings - * This driver requires UnRTF to be installed. - * UnRTF homepage: http://www.gnu.org/software/unrtf/unrtf.html - */ -$mime_drivers['horde']['rtf'] = array( - 'location' => '/usr/bin/unrtf', - 'inline' => false, - 'handles' => array( - 'application/rtf', - 'text/rtf' + /* Portable Document Format (PDF) display. */ + 'pdf' => array( + 'handles' => array( + 'application/pdf', + 'application/x-pdf', + 'image/pdf' + ), + 'icons' => array( + 'default' => 'pdf.png' + ) ), - 'icons' => array( - 'default' => 'text.png' - ) -); - -/** - * WordPerfect driver settings - * This driver requires wpd2html to be installed. - * libwpd homepage: http://libwpd.sourceforge.net/ - */ -$mime_drivers['horde']['wordperfect'] = array( - 'location' => '/usr/bin/wpd2html', - 'inline' => false, - 'handles' => array( - 'application/vnd.wordperfect', - 'application/wordperf', - 'application/wordperfect', - 'application/wpd', - 'application/x-wpwin' + /* RTF display. + * This driver requires UnRTF to be installed. + * UnRTF homepage: http://www.gnu.org/software/unrtf/unrtf.html */ + 'rtf' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/rtf', + 'text/rtf' + ), + 'icons' => array( + 'default' => 'text.png' + ), + + // REQUIRED: location of the unrtf binary + 'location' => '/usr/bin/unrtf' ), - 'icons' => array( - 'default' => 'wordperfect.png' + + /* WordPerfect document display. + * This driver requires wpd2html to be installed. + * libwpd homepage: http://libwpd.sourceforge.net/ */ + 'wordperfect' => array( + // Disabled by default + 'disable' => true, + 'handles' => array( + 'application/vnd.wordperfect', + 'application/wordperf', + 'application/wordperfect', + 'application/wpd', + 'application/x-wpwin' + ), + 'icons' => array( + 'default' => 'wordperfect.png' + ), + + // REQUIRED: location of the wpd2html binary + 'location' => '/usr/bin/wpd2html' ) ); diff --git a/horde/docs/UPGRADING b/horde/docs/UPGRADING index a2240a9ed..bba56698a 100644 --- a/horde/docs/UPGRADING +++ b/horde/docs/UPGRADING @@ -39,6 +39,8 @@ The following hooks have changed: * username_tobackend, username_frombackend (combined and renamed to authusername). +The format for the config/mime_drivers.php configuration files has changed. + Horde_Alarm is using UTC dates now. Crypt_Blowfish is required. diff --git a/imp/compose.php b/imp/compose.php index d724f2f25..224782751 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -1003,13 +1003,14 @@ if ($redirect) { $t->set('numberattach', $imp_compose->numberOfAttachments()); if ($t->get('numberattach')) { $atc = array(); + $v = $injector->getInstance('Horde_Mime_Viewer'); foreach ($imp_compose->getAttachments() as $atc_num => $data) { $mime = $data['part']; $type = $mime->getType(); $entry = array( 'name' => $mime->getName(true), - 'icon' => Horde_Mime_Viewer::getIcon($type), + 'icon' => $v->getIcon($type), 'number' => $atc_num, 'type' => $type, 'size' => $mime->getSize(), diff --git a/imp/config/mime_drivers.php.dist b/imp/config/mime_drivers.php.dist index 013ef973b..7a357e25c 100644 --- a/imp/config/mime_drivers.php.dist +++ b/imp/config/mime_drivers.php.dist @@ -1,6 +1,7 @@ true, - 'handles' => array( - 'text/plain', 'text/rfc822-headers', 'application/pgp' +$mime_drivers = array( + /* Plain text viewer. */ + 'plain' => array( + 'inline' => true, + 'handles' => array( + 'application/pgp', + 'text/plain', + 'text/rfc822-headers' + ), + + /* If you want to limit the display of message data inline for large + * messages, set the maximum size of the displayed message here (in + * bytes). If exceeded, the user will only be able to download the + * part. Set to 0 to disable this check. */ + 'limit_inline_size' => 1048576, + + /* If you want to scan ALL incoming text/plain messages for UUencoded + * data, set the following to true. This is very performance intensive + * and can take a long time for large messages. It is not recommended + * (as UUencoded data is rare these days) and is disabled by + * default. */ + 'uudecode' => false ), - /* If you want to limit the display of message data inline for large - * messages, set the maximum size of the displayed message here (in - * bytes). If exceeded, the user will only be able to download the part. - * Set to 0 to disable this check. */ - 'limit_inline_size' => 1048576, - /* If you want to scan ALL incoming text/plain messages for UUencoded - * data, set the following to true. This is very performance intensive and - * can take a long time for large messages. It is not recommended (as - * UUencoded data is very rare anymore) and is disabled by default. */ - 'uudecode' => false -); -/** - * HTML driver settings - */ -$mime_drivers['imp']['html'] = array( - /* NOTE: Inline HTML display is turned OFF by default. */ - 'inline' => false, - 'handles' => array( - 'text/html' + /* HTML driver settings */ + 'html' => array( + /* NOTE: Inline HTML display is turned OFF by default. */ + 'inline' => false, + 'handles' => array( + 'text/html' + ), + 'icons' => array( + 'default' => 'html.png' + ), + + /* If you want to limit the display of message data inline for large + * messages, set the maximum size of the displayed message here (in + * bytes). If exceeded, the user will only be able to download the + * part. Set to 0 to disable this check. */ + 'limit_inline_size' => 1048576, + + /* Check for phishing exploits? */ + 'phishing_check' => true, + + /* A list of from e-mail addresses that are considered "safe" for + * purposes of image blocking (if image blocking is enabled in the + * preferences). */ + 'safe_addrs' => array() ), - 'icons' => array( - 'default' => 'html.png' + + /* Default smil driver. */ + 'smil' => array( + 'inline' => true, + 'handles' => array( + 'application/smil' + ) ), - /* If you want to limit the display of message data inline for large - * messages, set the maximum size of the displayed message here (in - * bytes). If exceeded, the user will only be able to download the part. - * Set to 0 to disable this check. */ - 'limit_inline_size' => 1048576, - /* Check for phishing exploits? */ - 'phishing_check' => true, - /* A list of from e-mail addresses that are considered "safe" for purposes - * of image blocking (if enabled). */ - 'safe_addrs' => array() -); -/** - * Default smil driver settings - */ -$mime_drivers['imp']['smil'] = array( - 'inline' => true, - 'handles' => array( - 'application/smil' - ) -); + /* Image display. */ + 'images' => array( + 'inline' => true, + 'handles' => array( + 'image/*' + ), -/** - * Image driver settings - */ -$mime_drivers['imp']['images'] = array( - 'inline' => true, - 'handles' => array( - 'image/*' - ), - /* Display thumbnails for all images, not just large images? */ - 'allthumbs' => true, - /* Display images inline that are less than this size (in bytes). */ - 'inlinesize' => 262144 -); + /* Display thumbnails for all images, not just large images? */ + 'allthumbs' => true, -/** - * Enriched text driver settings - */ -$mime_drivers['imp']['enriched'] = array( - 'inline' => true, - 'handles' => array( - 'text/enriched' + /* Display images inline that are less than this size (in bytes). */ + 'inlinesize' => 262144 ), - 'icons' => array( - 'default' => 'text.png' - ) -); -/** - * PDF settings - */ -$mime_drivers['imp']['pdf'] = array( - 'inline' => false, - 'handles' => array( - 'application/pdf', 'application/x-pdf', 'image/pdf' + /* Enriched text display. */ + 'enriched' => array( + 'inline' => true, + 'handles' => array( + 'text/enriched' + ), + 'icons' => array( + 'default' => 'text.png' + ) ), - 'icons' => array( - 'default' => 'pdf.png' - ) -); -/** - * PGP settings - */ -$mime_drivers['imp']['pgp'] = array( - 'inline' => true, - 'handles' => array( - 'application/pgp-encrypted', 'application/pgp-keys', - 'application/pgp-signature' + /* PDF display. */ + 'pdf' => array( + 'handles' => array( + 'application/pdf', + 'application/x-pdf', + 'image/pdf' + ), + 'icons' => array( + 'default' => 'pdf.png' + ) ), - 'icons' => array( - 'default' => 'encryption.png' - ) -); -/** - * S/MIME settings - */ -$mime_drivers['imp']['smime'] = array( - 'inline' => true, - 'handles' => array( - 'application/x-pkcs7-signature', 'application/x-pkcs7-mime', - 'application/pkcs7-signature', 'application/pkcs7-mime' + /* PGP (Pretty Good Privacy) display. */ + 'pgp' => array( + 'inline' => true, + 'handles' => array( + 'application/pgp-encrypted', + 'application/pgp-keys', + 'application/pgp-signature' + ), + 'icons' => array( + 'default' => 'encryption.png' + ) ), - 'icons' => array( - 'default' => 'encryption.png' - ) -); -/** - * vCard driver settings - */ -$mime_drivers['imp']['vcard'] = array( - 'handles' => array( - 'text/vcard', 'text/x-vcard', 'text/directory' + /* S/MIME display. */ + 'smime' => array( + 'inline' => true, + 'handles' => array( + 'application/x-pkcs7-signature', + 'application/x-pkcs7-mime', + 'application/pkcs7-signature', + 'application/pkcs7-mime' + ), + 'icons' => array( + 'default' => 'encryption.png' + ) ), - 'icons' => array( - 'default' => 'vcard.png' - ) -); -/** - * Zip File Attachments settings - */ -$mime_drivers['imp']['zip'] = array( - 'inline' => false, - 'handles' => array( - 'application/zip', 'application/x-compressed', - 'application/x-zip-compressed' + /* vCard display. */ + 'vcard' => array( + 'handles' => array( + 'text/directory', + 'text/vcard', + 'text/x-vcard' + ), + 'icons' => array( + 'default' => 'vcard.png' + ) ), - 'icons' => array( - 'default' => 'compressed.png' - ) -); -/** - * Delivery Status messages settings - */ -$mime_drivers['imp']['status'] = array( - 'inline' => true, - 'handles' => array( - 'message/delivery-status' - ) -); + /* Zip file display. */ + 'zip' => array( + 'handles' => array( + 'application/x-compressed', + 'application/x-zip-compressed', + 'application/zip' + ), + 'icons' => array( + 'default' => 'compressed.png' + ) + ), -/** - * Disposition Notification message settings - */ -$mime_drivers['imp']['mdn'] = array( - 'inline' => true, - 'handles' => array( - 'message/disposition-notification' - ) -); + /* Delivery status messages display. */ + 'status' => array( + 'inline' => true, + 'handles' => array( + 'message/delivery-status' + ) + ), -/** - * multipart/appledouble settings - */ -$mime_drivers['imp']['appledouble'] = array( - 'inline' => true, - 'handles' => array( - 'multipart/appledouble' + /* Message Disposition Notification (MDN) display. */ + 'mdn' => array( + 'inline' => true, + 'handles' => array( + 'message/disposition-notification' + ) ), - 'icons' => array( - 'default' => 'apple.png' - ) -); -/** - * iCalendar Transport-Independent Interoperability Protocol - */ -$mime_drivers['imp']['itip'] = array( - 'inline' => true, - 'handles' => array( - 'text/calendar', 'text/x-vcalendar' + /* Appledouble message display. */ + 'appledouble' => array( + 'inline' => true, + 'handles' => array( + 'multipart/appledouble' + ), + 'icons' => array( + 'default' => 'apple.png' + ) ), - 'icons' => array( - 'default' => 'itip.png' - ) -); -/** - * multipart/alternative settings - */ -$mime_drivers['imp']['alternative'] = array( - /* The 'inline' setting should normally not be changed. */ - 'inline' => true, - 'handles' => array( - 'multipart/alternative' - ) -); + /* ITIP (iCalendar Transport-Independent Interoperability Protocol) + * display. */ + 'itip' => array( + 'inline' => true, + 'handles' => array( + 'text/calendar', + 'text/x-vcalendar' + ), + 'icons' => array( + 'default' => 'itip.png' + ) + ), -/** - * multipart/related settings - * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. - */ -$mime_drivers['imp']['related'] = array( - 'inline' => true, - 'handles' => array( - 'multipart/related' + /* Alternative part display. + * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */ + 'alternative' => array( + 'inline' => true, + 'handles' => array( + 'multipart/alternative' + ) ), - 'icons' => array( - 'default' => 'html.png' - ) -); -/** - * message/partial settings - * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. - */ -$mime_drivers['imp']['partial'] = array( - 'handles' => array( - 'message/partial' - ) -); + /* Related part display. + * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */ + 'related' => array( + 'inline' => true, + 'handles' => array( + 'multipart/related' + ), + 'icons' => array( + 'default' => 'html.png' + ) + ), -/** - * Digest message (RFC 2046 [5.2.1]) settings - * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. - */ -$mime_drivers['imp']['rfc822'] = array( - 'inline' => false, - 'handles' => array( - 'message/rfc822', 'x-extension/eml' - ) -); + /* Partial parts display. + * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */ + 'partial' => array( + 'handles' => array( + 'message/partial' + ) + ), -/** - * MS-TNEF Attachment (application/ms-tnef) settings - * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. - */ -$mime_drivers['imp']['tnef'] = array( - 'inline' => false, - 'handles' => array( - 'application/ms-tnef' + /* Digest message (RFC 2046 [5.2.1]) display. + * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */ + 'rfc822' => array( + 'handles' => array( + 'message/rfc822', + 'x-extension/eml' + ) ), - 'icons' => array( - 'default' => 'binary.png' + + /* MS-TNEF Attachment display. + * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */ + 'tnef' => array( + 'inline' => false, + 'handles' => array( + 'application/ms-tnef' + ), + 'icons' => array( + 'default' => 'binary.png' + ) ) ); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 7856a6c78..ef1f7e481 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -101,6 +101,7 @@ class IMP_Application extends Horde_Registry_Application 'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(), 'IMP_Mail' => new IMP_Injector_Binder_Mail(), 'IMP_Mailbox' => new IMP_Injector_Binder_Mailbox(), + 'IMP_Mime_Viewer' => new IMP_Injector_Binder_MimeViewer(), 'IMP_Quota' => new IMP_Injector_Binder_Quota(), 'IMP_Search' => new IMP_Injector_Binder_Search(), 'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail() diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index bc9f016f7..ad3ce2a1d 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -38,6 +38,7 @@ class IMP_Contents const RENDER_INFO = 8; const RENDER_INLINE_AUTO = 16; const RENDER_RAW = 32; + const RENDER_RAW_FALLBACK = 64; /** * Flag to indicate whether the last call to getBodypart() returned @@ -348,9 +349,6 @@ class IMP_Contents * @param array $options Additional options: *
      * 'mime_part' - (Horde_Mime_Part) The MIME part to render.
-     * 'params' - (array) Additional params to set. Special params:
-     *            'raw' - The calling code wants display of the raw data,
-     *            without any additional formatting.
      * 'type' - (string) Use this MIME type instead of the MIME type
      *          identified in the MIME part.
      * 
@@ -375,14 +373,10 @@ class IMP_Contents ? $this->getMIMEPart($mime_id) : $options['mime_part']; $type = empty($options['type']) - ? $mime_part->getType() + ? null : $options['type']; - $viewer = Horde_Mime_Viewer::factory($mime_part, $type); - $viewer->setParams(array('contents' => $this)); - if (!empty($options['params'])) { - $viewer->setParams($options['params']); - } + $viewer = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($mime_part, $this, $type); switch ($mode) { case self::RENDER_FULL: @@ -430,6 +424,12 @@ class IMP_Contents case self::RENDER_RAW: $textmode = 'raw'; break; + + case self::RENDER_RAW_FALLBACK: + $textmode = $viewer->canRender('raw') + ? 'raw' + : 'full'; + break; } $ret = $viewer->render($textmode); @@ -625,7 +625,7 @@ class IMP_Contents } /* Get part's icon. */ - $part['icon'] = ($mask & self::SUMMARY_ICON) ? Horde::img(Horde_Mime_Viewer::getIcon($mime_type), '', array('title' => $mime_type), '') : null; + $part['icon'] = ($mask & self::SUMMARY_ICON) ? Horde::img($GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getIcon($mime_type), '', array('title' => $mime_type), '') : null; /* Get part's description. */ $description = $mime_part->getDescription(true); @@ -658,7 +658,7 @@ class IMP_Contents if ($is_atc && $download_zip && ($part['bytes'] > 204800)) { - $viewer = Horde_Mime_Viewer::factory($mime_part, $mime_type); + $viewer = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($mime_part, $this, $mime_type); if (!$viewer->getMetadata('compressed')) { $part['download_zip'] = $this->linkView($mime_part, 'download_attach', null, array('class' => 'downloadZipAtc', 'dload' => true, 'jstext' => sprintf(_("Download %s in .zip Format"), $mime_part->getDescription(true)), 'params' => array('zip' => 1))); } @@ -871,11 +871,10 @@ class IMP_Contents $last_id = null; $mime_part = $this->getMIMEPart($id, array('nocontents' => true)); - $viewer = Horde_Mime_Viewer::factory($mime_part); + $viewer = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($mime_part, $this); if ($viewer->embeddedMimeParts()) { $mime_part = $this->getMIMEPart($id); $viewer->setMIMEPart($mime_part); - $viewer->setParams(array('contents' => $this)); $new_part = $viewer->getEmbeddedMimeParts(); if (!is_null($new_part)) { $this->_embedded[] = $id; @@ -907,7 +906,7 @@ class IMP_Contents if (!is_object($part)) { $part = $this->getMIMEPart($part, array('nocontents' => true)); } - $viewer = Horde_Mime_Viewer::factory($part, $type); + $viewer = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($part, $this, $type); if ($mask & self::RENDER_INLINE_AUTO) { $mask |= self::RENDER_INLINE | self::RENDER_INFO; @@ -1018,4 +1017,27 @@ class IMP_Contents return false; } + /** + * Find a MIME type in parent parts. + * + * @param string $id The MIME ID to begin the search at. + * @param string $type The MIME type to search for. + * + * @return mixed Either the requested MIME part, or null if not found. + */ + public function findMimeType($id, $type) + { + $id = Horde_Mime::mimeIdArithmetic($id, 'up'); + + while (!is_null($id)) { + if (($part = $this->getMIMEPart($id, array('nocontents' => true))) && + ($part->getType() == $type)) { + return $part; + } + $id = Horde_Mime::mimeIdArithmetic($id, 'up'); + } + + return null; + } + } diff --git a/imp/lib/Injector/Binder/MimeViewer.php b/imp/lib/Injector/Binder/MimeViewer.php new file mode 100644 index 000000000..f9eb0a111 --- /dev/null +++ b/imp/lib/Injector/Binder/MimeViewer.php @@ -0,0 +1,32 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ +class IMP_Injector_Binder_MimeViewer implements Horde_Injector_Binder +{ + /** + */ + public function create(Horde_Injector $injector) + { + return new IMP_Injector_Factory_MimeViewer($injector); + } + + /** + */ + public function equals(Horde_Injector_Binder $binder) + { + return false; + } + +} diff --git a/imp/lib/Injector/Factory/MimeViewer.php b/imp/lib/Injector/Factory/MimeViewer.php new file mode 100644 index 000000000..7add9a4ea --- /dev/null +++ b/imp/lib/Injector/Factory/MimeViewer.php @@ -0,0 +1,97 @@ + + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + */ + +/** + * A Horde_Injector:: based Horde_Mime_Viewer factory for IMP drivers. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @category Horde + * @package IMP + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @link http://pear.horde.org/index.php?package=IMP + */ +class IMP_Injector_Factory_MimeViewer +{ + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Attempts to return a concrete Horde_Mime_Viewer object based on the + * MIME type. + * + * @param Horde_Mime_Part $mime An object with the data to be rendered. + * @param IMP_Contents $contents The IMP_Contents object associated with + * $mime. + * @param string $type The MIME type to use for loading. + * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function getViewer(Horde_Mime_Part $mime, + IMP_Contents $contents = null, + $type = null) + { + list($driver, $params) = $this->_injector->getInstance('Horde_Mime_Viewer')->getViewerConfig($type ? $type : $mime->getType(), 'imp'); + + switch ($driver) { + case 'Report': + case 'Security': + $params['viewer_callback'] = array($this, 'getViewerCallback'); + break; + } + + $params['imp_contents'] = $contents; + + return Horde_Mime_Viewer::factory($driver, $mime, $params); + } + + /** + * Callback used to return a MIME Viewer object from within certain + * Viewer drivers. + * + * @param Horde_Mime_Viewer_Base $viewer The MIME Viewer driver + * requesting the new object. + * @param Horde_Mime_Part $mime An object with the data to be + * rendered. + * @param string $type The MIME type to use for + * rendering. + * + * @return Horde_Mime_Viewer_Base The newly created instance. + * @throws Horde_Mime_Viewer_Exception + */ + public function getViewerCallback(Horde_Mime_Viewer_Base $viewer, + Horde_Mime_Part $mime, $type) + { + return $this->getViewer($mime, $viewer->getConfigParam('imp_contents'), $type); + } + +} diff --git a/imp/lib/Mime/Viewer/Alternative.php b/imp/lib/Mime/Viewer/Alternative.php index b65797b83..f5f42b993 100644 --- a/imp/lib/Mime/Viewer/Alternative.php +++ b/imp/lib/Mime/Viewer/Alternative.php @@ -1,6 +1,6 @@ $type) { $ret[$mime_id] = null; if ((strcmp($base_id, $mime_id) !== 0) && - $this->_params['contents']->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL)) { + $this->getConfigParam('imp_contents')->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL)) { if (!$is_mimp || !$prefer_plain || ($type == 'text/plain')) { @@ -107,7 +107,7 @@ class IMP_Horde_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base 'type' => 'info' ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ); return $ret; } @@ -128,7 +128,7 @@ class IMP_Horde_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base $render_part = $this->_mimepart->getPart($disp_id); foreach (array_keys($render_part->contentTypeMap()) as $val) { if (isset($display_ids[$val])) { - $render = $this->_params['contents']->renderMIMEPart($val, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL, array('params' => $this->_params)); + $render = $this->getConfigParam('imp_contents')->renderMIMEPart($val, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL); foreach (array_keys($render) as $id) { unset($display_ids[$id]); if (!$inline) { @@ -155,4 +155,5 @@ class IMP_Horde_Mime_Viewer_Alternative extends Horde_Mime_Viewer_Base ? $ret : null; } + } diff --git a/imp/lib/Mime/Viewer/Appledouble.php b/imp/lib/Mime/Viewer/Appledouble.php index 26221a0a0..1fd2940a9 100644 --- a/imp/lib/Mime/Viewer/Appledouble.php +++ b/imp/lib/Mime/Viewer/Appledouble.php @@ -1,6 +1,6 @@ Horde::img('mime/apple.png', _("Macintosh File")), 'text' => array( sprintf(_("This message contains a Macintosh file (named \"%s\")."), $data_name), - sprintf(_("The Macintosh resource fork can be downloaded %s."), $this->_params['contents']->linkViewJS($applefile_part, 'download_attach', _("HERE"), array('jstext' => _("The Macintosh resource fork")))) + sprintf(_("The Macintosh resource fork can be downloaded %s."), $this->getConfigParam('imp_contents')->linkViewJS($applefile_part, 'download_attach', _("HERE"), array('jstext' => _("The Macintosh resource fork")))) ) ); /* For inline viewing, attempt to display the data inline. */ $ret = array(); - if ($inline && (($disp = $this->_params['contents']->canDisplay($data_part, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO)))) { - $ret = $this->_params['contents']->renderMIMEPart($data_id, $disp, array('params' => $this->_params)); + if ($inline && (($disp = $this->getConfigParam('imp_contents')->canDisplay($data_part, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO)))) { + $ret = $this->getConfigParam('imp_contents')->renderMIMEPart($data_id, $disp); } foreach ($parts_list as $val) { @@ -108,7 +108,7 @@ class IMP_Horde_Mime_Viewer_Appledouble extends Horde_Mime_Viewer_Base ? array( 'data' => '', 'status' => array($status), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap' ) : null; @@ -119,4 +119,5 @@ class IMP_Horde_Mime_Viewer_Appledouble extends Horde_Mime_Viewer_Base return $ret; } + } diff --git a/imp/lib/Mime/Viewer/Enriched.php b/imp/lib/Mime/Viewer/Enriched.php index a9d8e684f..7b0d9a9fa 100644 --- a/imp/lib/Mime/Viewer/Enriched.php +++ b/imp/lib/Mime/Viewer/Enriched.php @@ -1,6 +1,6 @@ hasFeature('javascript')) { + if (!$this->getConfigParam('browser')->hasFeature('javascript')) { return array( $this->_mimepart->getMimeId() => array( 'data' => '', @@ -66,11 +66,11 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html 'icon' => Horde::img('mime/html.png'), 'text' => array( _("This message part contains HTML data, but this data can not be displayed inline."), - $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")), + $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")), ) ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -113,12 +113,12 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html 'icon' => Horde::img('mime/html.png', _("HTML data")), 'text' => array( _("This message part contains HTML data, but inline HTML display is disabled."), - $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")), - $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("Convert HTML data to plain text and view in new window."), array('params' => array('convert_text' => 1))) + $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")), + $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("Convert HTML data to plain text and view in new window."), array('params' => array('convert_text' => 1))) ) ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -156,10 +156,10 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html /* Search for inlined images that we can display * (multipart/related parts) - see RFC 2392. */ - if (isset($this->_params['related_id'])) { + if ($related_part = $this->getConfigParam('imp_contents')->findMimeType($this->_mimepart->getMimeId(), 'multipart/related')) { $cid_replace = array(); - foreach ($this->_params['related_cids'] as $mime_id => $cid) { + foreach ($related_part->getMetadata('related_cids') as $mime_id => $cid) { if ($cid = trim($cid, '<>')) { $cid_replace['cid:' . $cid] = $mime_id; } @@ -191,13 +191,15 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html /* We are done processing if in mimp mode, or we are converting to * text. */ if (is_null($this->_imptmp)) { - $data = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($data, 'Html2text', array('wrap' => false)); + $data = $this->_textFilter($data, 'Html2text', array( + 'wrap' => false + )); // Filter bad language. return array( 'data' => IMP::filterText($data), 'status' => array(), - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/plain; charset=' . $this->getConfigParam('charset') ); } @@ -223,7 +225,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html } if (!empty($filters)) { - $data = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($data, array_keys($filters), array(array_values($filters))); + $data = $this->_textFilter($data, array_keys($filters), array(array_values($filters))); } /* Filter bad language. */ @@ -243,11 +245,11 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html */ protected function _inAddressBook() { - if (empty($this->_params['contents'])) { + if (!$this->getConfigParam('imp_contents')) { return false; } - $from = Horde_Mime_Address::bareAddress($this->_params['contents']->getHeaderOb()->getValue('from')); + $from = Horde_Mime_Address::bareAddress($this->getConfigParam('imp_contents')->getHeaderOb()->getValue('from')); if ($GLOBALS['prefs']->getValue('html_image_addrbook') && $GLOBALS['registry']->hasMethod('contacts/getField')) { @@ -305,9 +307,9 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html if (($tag == 'img') && $this->_imptmp['cid'] && isset($this->_imptmp['cid'][$val])) { - $val = $this->_params['contents']->urlView(null, 'view_attach', array('params' => array( + $val = $this->getConfigParam('imp_contents')->urlView(null, 'view_attach', array('params' => array( 'id' => $this->_imptmp['cid'][$val], - 'related_data' => 1 + 'imp_img_view' => 'data' ))); $node->setAttribute('src', $val); } diff --git a/imp/lib/Mime/Viewer/Images.php b/imp/lib/Mime/Viewer/Images.php index 8cf3d0d8c..f14baa080 100644 --- a/imp/lib/Mime/Viewer/Images.php +++ b/imp/lib/Mime/Viewer/Images.php @@ -1,6 +1,6 @@ true, 'info' => true, 'inline' => true, - 'raw' => false + 'raw' => true ); /** @@ -44,10 +44,6 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images protected function _render() { $view = Horde_Util::getFormData('imp_img_view'); - if (Horde_Util::getFormData('related_data') || - !empty($this->_params['raw'])) { - $view = 'data'; - } switch ($view) { case 'data': @@ -93,7 +89,7 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images $this->_mimepart->getMimeId() => array( 'data' => $this->_outputImgTag('data', $this->_mimepart->getName(true)), 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } else { @@ -110,7 +106,7 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images $img = $this->_getHordeImageOb(false); if ($img && $GLOBALS['browser']->isViewable($img->getContentType())) { - $convert_link = $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("HERE"), array('params' => array('imp_img_view' => 'load_convert'))); + $convert_link = $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("HERE"), array('params' => array('imp_img_view' => 'load_convert'))); $status[] = sprintf(_("Click %s to convert the image file into a format your browser can attempt to view."), $convert_link); } } @@ -123,7 +119,7 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images 'text' => $status ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -147,9 +143,9 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images $status = array(_("This is a thumbnail of an image attached to this message.")); if ($GLOBALS['browser']->hasFeature('javascript')) { - $status[] = $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag('view_thumbnail', _("View Attachment")), null, null, null); + $status[] = $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag('view_thumbnail', _("View Attachment")), null, null, null); } else { - $status[] = Horde::link($this->_params['contents']->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag('view_thumbnail', _("View Attachment")) . ''; + $status[] = Horde::link($this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag('view_thumbnail', _("View Attachment")) . ''; } return array( @@ -161,12 +157,22 @@ class IMP_Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Images 'text' => $status ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See parent::render(). + */ + protected function _renderRaw() + { + return parent::_render(); + } + + /** * Generate the HTML output for the JS auto-resize view window. * * @return string The HTML output. @@ -202,7 +208,7 @@ EOD; $this->_mimepart->getMimeId() => array( 'data' => $str, 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -293,7 +299,7 @@ EOD; */ protected function _outputImgTag($type, $alt) { - return '' . htmlspecialchars($alt, ENT_COMPAT, $GLOBALS['registry']->getCharset()) . ''; + return '' . htmlspecialchars($alt, ENT_COMPAT, $this->getConfigParam('charset')) . ''; } } diff --git a/imp/lib/Mime/Viewer/Itip.php b/imp/lib/Mime/Viewer/Itip.php index a6f806351..58b3740a3 100644 --- a/imp/lib/Mime/Viewer/Itip.php +++ b/imp/lib/Mime/Viewer/Itip.php @@ -1,6 +1,6 @@ _renderInline(true); if (!empty($ret)) { + $templates = $GLOBALS['registry']->get('templates', 'horde'); + reset($ret); Horde::startBuffer(); - include $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc'; + include $templates . '/common-header.inc'; echo $ret[key($ret)]['data']; - include $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; + include $templates . '/common-footer.inc'; $ret[key($ret)]['data'] = Horde::endBuffer(); } @@ -75,7 +77,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base { global $registry; - $charset = $GLOBALS['registry']->getCharset(); + $charset = $this->getConfigParam('charset'); $data = $this->_mimepart->getContents(); $mime_id = $this->_mimepart->getMimeId(); @@ -94,7 +96,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base // Check if we got vcard data with the wrong vcalendar mime type. $c = $vCal->getComponentClasses(); if ((count($c) == 1) && !empty($c['horde_icalendar_vcard'])) { - return $this->_params['contents']->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE, array('type' => 'text/x-vcard')); + return $this->getConfigParam('imp_contents')->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE, array('type' => 'text/x-vcard')); } // Get the method type. @@ -138,7 +140,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base // vEvent reply. if ($registry->hasMethod('calendar/updateAttendee')) { try { - $hdrs = $this->_params['contents']->getHeaderOb(); + $hdrs = $this->getConfigParam('imp_contents')->getHeaderOb(); $event = $registry->call('calendar/updateAttendee', array('response' => $components[$key], 'sender' => $hdrs->getValue('From'))); $msgs[] = array('success', _("Respondent Status Updated.")); } catch (Horde_Exception $e) { @@ -498,7 +500,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base } return array( $mime_id => array( - 'data' => Horde_String::convertCharset(Horde::escapeJson(Horde::prepareResponse(null, true), array('charset' => $GLOBALS['registry']->getCharset())), $GLOBALS['registry']->getCharset(), 'UTF-8'), + 'data' => Horde_String::convertCharset(Horde::escapeJson(Horde::prepareResponse(null, true), array('charset' => $this->getConfigParam('charset'))), $this->getConfigParam('charset'), 'UTF-8'), 'status' => array(), 'name' => null, 'type' => 'application/json' @@ -508,7 +510,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base // Create the HTML to display the iCal file. if ($_SESSION['imp']['view'] != 'imp' && !$full) { - $url = $this->_params['contents']->urlView($this->_mimepart, 'view_attach', array('params' => array('ajax' => 1, 'mode' => IMP_Contents::RENDER_INLINE))); + $url = $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach', array('params' => array('ajax' => 1, 'mode' => IMP_Contents::RENDER_INLINE))); $onsubmit = ' onsubmit="DimpCore.submitForm(\'impMimeViewerItip\');return false"'; } else { $url = IMP::selfUrl(); @@ -567,7 +569,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base break; case 'REQUEST': - $hdrs = $this->_params['contents']->getHeaderOb(); + $hdrs = $this->getConfigParam('imp_contents')->getHeaderOb(); $sender = $hdrs->getValue('From'); $desc = _("%s requests your free/busy information."); break; @@ -717,7 +719,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Base break; case 'REPLY': - $hdrs = $this->_params['contents']->getHeaderOb(); + $hdrs = $this->getConfigParam('imp_contents')->getHeaderOb(); $desc = _("%s has replied to the invitation to \"%s\"."); $sender = $hdrs->getValue('From'); if ($registry->hasMethod('calendar/updateAttendee')) { diff --git a/imp/lib/Mime/Viewer/Mdn.php b/imp/lib/Mime/Viewer/Mdn.php index 873a19bd0..a0326257e 100644 --- a/imp/lib/Mime/Viewer/Mdn.php +++ b/imp/lib/Mime/Viewer/Mdn.php @@ -1,6 +1,6 @@ _mimepart->getType() == 'message/disposition-notification') { - return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain', 'params' => $this->_params)); + return $this->getConfigParam('imp_contents')->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain')); } return $this->_renderInfo(); @@ -80,21 +80,21 @@ class IMP_Horde_Mime_Viewer_Mdn extends Horde_Mime_Viewer_Base /* Print the human readable message. */ reset($parts); $curr_id = $first_id = next($parts); - $first_part = $this->_params['contents']->renderMIMEPart($curr_id, IMP_Contents::RENDER_INLINE_AUTO, array('params' => $this->_params)); + $first_part = $this->getConfigParam('imp_contents')->renderMIMEPart($curr_id, IMP_Contents::RENDER_INLINE_AUTO); /* Display a link to more detailed message. */ $curr_id = Horde_Mime::mimeIdArithmetic($curr_id, 'next'); - $part = $this->_params['contents']->getMIMEPart($curr_id); + $part = $this->getConfigParam('imp_contents')->getMIMEPart($curr_id); if ($part) { - $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))); + $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))); } /* Display a link to the sent message. Try to download the text of the message/rfc822 part first, if it exists. */ $curr_id = Horde_Mime::mimeIdArithmetic($curr_id, 'next'); - $part = $this->_params['contents']->getMIMEPart($curr_id); + $part = $this->getConfigParam('imp_contents')->getMIMEPart($curr_id); if ($part) { - $status[0]['text'][] = sprintf(_("The text of the sent message can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("The text of the sent message")))); + $status[0]['text'][] = sprintf(_("The text of the sent message can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("The text of the sent message")))); } if (empty($first_part)) { @@ -109,7 +109,7 @@ class IMP_Horde_Mime_Viewer_Mdn extends Horde_Mime_Viewer_Base $ret[$mdn_id] = array( 'data' => $data, 'status' => $status, - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap' ); diff --git a/imp/lib/Mime/Viewer/Partial.php b/imp/lib/Mime/Viewer/Partial.php index c0052ae8f..08e02d1b2 100644 --- a/imp/lib/Mime/Viewer/Partial.php +++ b/imp/lib/Mime/Viewer/Partial.php @@ -1,6 +1,6 @@ array( 'data' => null, 'status' => array(self::$_statuscache[$id]), - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/plain; charset=' . $this->getConfigParam('charset') ) ); } else { @@ -87,7 +87,7 @@ class IMP_Horde_Mime_Viewer_Partial extends Horde_Mime_Viewer_Base /* Perform the search to find the other parts of the message. */ $query = new Horde_Imap_Client_Search_Query(); $query->headerText('Content-Type', $id); - $indices = $GLOBALS['injector']->getInstance('IMP_Search')->runSearchQuery($query, $this->_params['contents']->getMailbox()); + $indices = $GLOBALS['injector']->getInstance('IMP_Search')->runSearchQuery($query, $this->getConfigParam('imp_contents')->getMailbox()); /* If not able to find the other parts of the message, prepare a * status message. */ diff --git a/imp/lib/Mime/Viewer/Pdf.php b/imp/lib/Mime/Viewer/Pdf.php index 751cf48fe..2ec340e23 100644 --- a/imp/lib/Mime/Viewer/Pdf.php +++ b/imp/lib/Mime/Viewer/Pdf.php @@ -1,6 +1,6 @@ hasFeature('javascript')) { - $status[] = $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag(), null, null, null); + $status[] = $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag(), null, null, null); } else { - $status[] = Horde::link($this->_params['contents']->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag() . ''; + $status[] = Horde::link($this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag() . ''; } return array( @@ -95,7 +95,7 @@ class IMP_Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Pdf 'text' => $status ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -149,7 +149,7 @@ class IMP_Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Pdf */ protected function _outputImgTag() { - return '' . htmlspecialchars(_(getCharset()) . '" />'; + return '' . htmlspecialchars(_(getConfigParam('charset')) . '" />'; } } diff --git a/imp/lib/Mime/Viewer/Pgp.php b/imp/lib/Mime/Viewer/Pgp.php index 7d672b065..7755e2cf1 100644 --- a/imp/lib/Mime/Viewer/Pgp.php +++ b/imp/lib/Mime/Viewer/Pgp.php @@ -1,6 +1,6 @@ array( 'data' => '', 'status' => array(), - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/plain; charset=' . $this->getConfigParam('charset') ) ); @@ -113,7 +113,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base /* Determine the address of the sender. */ if (is_null($this->_address)) { - $headers = $this->_params['contents']->getHeaderOb(); + $headers = $this->getConfigParam('imp_contents')->getHeaderOb(); $this->_address = Horde_Mime_Address::bareAddress($headers->getValue('from')); } @@ -130,7 +130,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base $id => array( 'data' => null, 'status' => self::$_cache[$id]['status'], - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/plain; charset=' . $this->getConfigParam('charset'), 'wrap' => self::$_cache[$id]['wrap'] ) ), self::$_cache[$id]['other']); @@ -187,7 +187,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base /* PGP version information appears in the first MIME subpart. We * don't currently need to do anything with this information. The * encrypted data appears in the second MIME subpart. */ - $encrypted_part = $this->_params['contents']->getMIMEPart($data_id); + $encrypted_part = $this->getConfigParam('imp_contents')->getMIMEPart($data_id); $encrypted_data = $encrypted_part->getContents(); $symmetric_pass = $personal_pass = null; @@ -304,9 +304,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base if ($GLOBALS['prefs']->getValue('use_pgp') && $GLOBALS['prefs']->getValue('add_source') && $GLOBALS['registry']->hasMethod('contacts/addField')) { - $status['text'][] = Horde::link('#', '', '', '', $imp_pgp->savePublicKeyURL($this->_params['contents']->getMailbox(), $this->_params['contents']->getUid(), $mime_id) . 'return false;') . _("Save the key to your address book.") . ''; + $status['text'][] = Horde::link('#', '', '', '', $imp_pgp->savePublicKeyURL($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $mime_id) . 'return false;') . _("Save the key to your address book.") . ''; } - $status['text'][] = $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View the raw text of the Public Key."), array('jstext' => _("View Public Key"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE, 'rawpgpkey' => 1))); + $status['text'][] = $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View the raw text of the Public Key."), array('jstext' => _("View Public Key"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE, 'rawpgpkey' => 1))); try { $data = '' . nl2br(str_replace(' ', ' ', $imp_pgp->pgpPrettyKey($this->_mimepart->getContents()))) . ''; @@ -318,7 +318,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base $mime_id => array( 'data' => $data, 'status' => array($status), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } @@ -344,7 +344,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base 'text' => array() ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap' ), $sig_id => null @@ -363,13 +363,13 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base if ($GLOBALS['prefs']->getValue('pgp_verify') || Horde_Util::getFormData('pgp_verify_msg')) { - $sig_part = $this->_params['contents']->getMIMEPart($sig_id); + $sig_part = $this->getConfigParam('imp_contents')->getMIMEPart($sig_id); try { $imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp'); $sig_result = $sig_part->getMetadata('imp-pgp-signature') ? $imp_pgp->verifySignature($sig_part->getContents(array('canonical' => true)), $this->_address) - : $imp_pgp->verifySignature($sig_part->replaceEOL($this->_params['contents']->getBodyPart($signed_id, array('mimeheaders' => true)), Horde_Mime_Part::RFC_EOL), $this->_address, $sig_part->getContents()); + : $imp_pgp->verifySignature($sig_part->replaceEOL($this->getConfigParam('imp_contents')->getBodyPart($signed_id, array('mimeheaders' => true)), Horde_Mime_Part::RFC_EOL), $this->_address, $sig_part->getContents()); $icon = Horde::img('alerts/success.png', _("Success")); $sig_text = $sig_result->message; @@ -384,7 +384,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base 'icon' => $icon, 'success' => $success, 'text' => array( - $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($sig_text, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::NOHTML)) + $this->_textFilter($sig_text, 'text2html', array( + 'parselevel' => Horde_Text_Filter_Text2html::NOHTML + )) ) ); @@ -413,7 +415,7 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Base */ protected function _getSymmetricID() { - return $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->getSymmetricID($this->_params['contents']->getMailbox(), $this->_params['contents']->getUid(), $this->_mimepart->getMimeId()); + return $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->getSymmetricID($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $this->_mimepart->getMimeId()); } /** diff --git a/imp/lib/Mime/Viewer/Plain.php b/imp/lib/Mime/Viewer/Plain.php index 9e45bac9c..1234427c7 100644 --- a/imp/lib/Mime/Viewer/Plain.php +++ b/imp/lib/Mime/Viewer/Plain.php @@ -1,6 +1,6 @@ getCharset(); + $text = Horde_String::convertCharset($text, $charset, $this->getConfigParam('charset')); + $charset = $this->getConfigParam('charset'); } $type = 'text/html; charset=' . $charset; @@ -124,7 +124,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain (($show == 'hidden') || (($show == 'thread') && (basename(Horde::selfUrl()) == 'thread.php'))); if (!$hideBlocks && in_array($show, array('list', 'listthread'))) { - $header = $this->_params['contents']->getHeaderOb(); + $header = $this->getConfigParam('imp_contents')->getHeaderOb(); $imp_ui = new IMP_Ui_Message(); $list_info = $imp_ui->getListInformation($header); $hideBlocks = $list_info['exists']; @@ -147,7 +147,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain } // Run filters. - $text = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter($text, array_keys($filters), array_values($filters)); + $text = $this->_textFilter($text, array_keys($filters), array_values($filters)); // Wordwrap. $text = str_replace(array(' ', "\n "), array('  ', "\n "), $text); @@ -317,7 +317,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain $text_part = new Horde_Mime_Part(); $text_part->setType('text/plain'); - $text_part->setCharset($GLOBALS['registry']->getCharset()); + $text_part->setCharset($this->getConfigParam('charset')); $text_part->setContents(preg_replace("/begin [0-7]{3} .+\r?\n.+\r?\nend/Us", "\n", $text)); $new_part->addPart($text_part); @@ -353,7 +353,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain ); return '
' . - $GLOBALS['injector']->getInstance('Horde_Text_Filter')->filter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset()), array_keys($filters), array_values($filters)) . + $this->_textFilter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset(), $this->getConfigParam('charset')), array_keys($filters), array_values($filters)) . ' [...]
'; } diff --git a/imp/lib/Mime/Viewer/Related.php b/imp/lib/Mime/Viewer/Related.php index 523e26bd0..678595105 100644 --- a/imp/lib/Mime/Viewer/Related.php +++ b/imp/lib/Mime/Viewer/Related.php @@ -1,6 +1,6 @@ _params['contents']->canDisplay($id, IMP_Contents::RENDER_INLINE)) { + !$this->getConfigParam('imp_contents')->canDisplay($id, IMP_Contents::RENDER_INLINE)) { return array(); } - $render = $this->_params['contents']->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL, array('params' => array_merge($this->_params, array('related_id' => $related_id, 'related_cids' => $cids)))); + /* Set related information in message metadata. */ + $this->_mimepart->setMetadata('related_cids', $cids); + + $render = $this->getConfigParam('imp_contents')->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL); if (!$inline) { foreach (array_keys($render) as $key) { diff --git a/imp/lib/Mime/Viewer/Rfc822.php b/imp/lib/Mime/Viewer/Rfc822.php index 5d4621582..1dfbbb634 100644 --- a/imp/lib/Mime/Viewer/Rfc822.php +++ b/imp/lib/Mime/Viewer/Rfc822.php @@ -1,6 +1,6 @@ _getRelatedLink($attrs['SRC'])) !== false)) { - $this->_content .= '
'; + $this->_content .= '
'; } break; @@ -50,11 +50,12 @@ class IMP_Horde_Mime_Viewer_Smil extends Horde_Mime_Viewer_Smil */ protected function _getRelatedLink($cid) { - if (isset($this->_params['related_id']) && - (($key = array_search(trim($cid, '<>', $this->_params['related_cids']))) !== false)) { - return $this->_param['contents']->getMIMEPart($key); + if ($related_part = $this->findMimeType($this->_mimepart->getMimeId(), 'multipart/related') && + (($key = array_search(trim($cid, '<>', $related_part->getMetadata('related_cids')))) !== false)) { + return $this->getConfigParam('imp_contents')->getMIMEPart($key); } return false; } + } diff --git a/imp/lib/Mime/Viewer/Smime.php b/imp/lib/Mime/Viewer/Smime.php index 92d3ca96e..cd5358d4a 100644 --- a/imp/lib/Mime/Viewer/Smime.php +++ b/imp/lib/Mime/Viewer/Smime.php @@ -1,6 +1,6 @@ array( 'data' => null, 'status' => self::$_cache[$id]['status'], - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/plain; charset=' . $this->getConfigParam('charset'), 'wrap' => self::$_cache[$id]['wrap'] ) ); @@ -205,8 +205,8 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base } $raw_text = $this->_mimepart->getMimeId() - ? $this->_params['contents']->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true, 'stream' => true)) - : $this->_params['contents']->fullMessageText(); + ? $this->getConfigParam('imp_contents')->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true, 'stream' => true)) + : $this->getConfigParam('imp_contents')->fullMessageText(); try { $decrypted_data = $this->_impsmime->decryptMessage($this->_mimepart->replaceEOL($raw_text, Horde_Mime_Part::RFC_EOL)); @@ -219,7 +219,7 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base $new_part = Horde_Mime_Part::parseMessage($decrypted_data, array('forcemime' => true)); - $hdrs = $this->_params['contents']->getHeaderOb(); + $hdrs = $this->getConfigParam('imp_contents')->getHeaderOb(); $new_part->setMetadata('imp-smime-from', $hdrs->getValue('from')); return $new_part; @@ -256,14 +256,14 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base return null; } - if ($this->_params['contents']->isEmbedded($base_id)) { + if ($this->getConfigParam('imp_contents')->isEmbedded($base_id)) { $hdrs = new Horde_Mime_Headers(); $hdrs->addHeader('From', $this->_mimepart->getMetadata('imp-smime-from')); $stream = $this->_mimepart->toString(array('headers' => $hdrs, 'stream' => true)); } else { $stream = $base_id - ? $this->_params['contents']->getBodyPart($base_id, array('mimeheaders' => true, 'stream' => true)) - : $this->_params['contents']->fullMessageText(array('stream' => true)); + ? $this->getConfigParam('imp_contents')->getBodyPart($base_id, array('mimeheaders' => true, 'stream' => true)) + : $this->getConfigParam('imp_contents')->fullMessageText(array('stream' => true)); } $raw_text = $this->_mimepart->replaceEOL($stream, Horde_Mime_Part::RFC_EOL); @@ -300,7 +300,7 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base isset($sig_result->email) && $GLOBALS['registry']->hasMethod('contacts/addField') && $GLOBALS['prefs']->getValue('add_source')) { - $status[] = '[' . $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View Certificate"), array('params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1))) . '] [' . Horde::link('#', '', null, null, $this->_impsmime->savePublicKeyURL($sig_result->cert, $this->_params['contents']->getUid(), $sig_id) . ' return false;') . _("Save Certificate in your Address Book") . ']'; + $status[] = '[' . $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View Certificate"), array('params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1))) . '] [' . Horde::link('#', '', null, null, $this->_impsmime->savePublicKeyURL($sig_result->cert, $this->getConfigParam('imp_contents')->getUid(), $sig_id) . ' return false;') . _("Save Certificate in your Address Book") . ']'; } } catch (Horde_Exception $e) { self::$_cache[$base_id]['status'][0]['icon'] = ($e->getCode() == 'horde.warning') @@ -325,7 +325,7 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base return; } - $subpart = $this->_params['contents']->getMIMEPart($sig_id); + $subpart = $this->getConfigParam('imp_contents')->getMIMEPart($sig_id); if (empty($subpart)) { try { $msg_data = $this->_impsmime->extractSignedContents($raw_text); @@ -351,8 +351,8 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base } $raw_text = $this->_mimepart->getMimeId() - ? $this->_params['contents']->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true, 'stream' => true)) - : $this->_params['contents']->fullMessageText(); + ? $this->getConfigParam('imp_contents')->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true, 'stream' => true)) + : $this->getConfigParam('imp_contents')->fullMessageText(); try { $sig_result = $this->_impsmime->verifySignature($this->_mimepart->replaceEOL($raw_text, Horde_Mime_Part::RFC_EOL)); @@ -364,7 +364,7 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base $this->_mimepart->getMimeId() => array( 'data' => $this->_impsmime->certToHTML($sig_result->cert), 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } diff --git a/imp/lib/Mime/Viewer/Status.php b/imp/lib/Mime/Viewer/Status.php index 64279f3e8..3e285b3a0 100644 --- a/imp/lib/Mime/Viewer/Status.php +++ b/imp/lib/Mime/Viewer/Status.php @@ -1,6 +1,6 @@ _mimepart->getType() == 'message/delivery-status') { - return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain', 'params' => $this->_params)); + return $this->getConfigParam('imp_contents')->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain')); } return $this->_renderInfo(); @@ -80,7 +80,7 @@ class IMP_Horde_Mime_Viewer_Status extends Horde_Mime_Viewer_Base /* Get the action first - it appears in the second part. */ $action = null; - $part2 = $this->_params['contents']->getMIMEPart($part2_id); + $part2 = $this->getConfigParam('imp_contents')->getMIMEPart($part2_id); foreach (explode("\n", $part2->getContents()) as $line) { if (stristr($line, 'Action:') !== false) { @@ -105,7 +105,7 @@ class IMP_Horde_Mime_Viewer_Status extends Horde_Mime_Viewer_Base 'icon' => Horde::img('alerts/error.png', _("Error")), 'text' => array( _("ERROR: Your message could not be delivered."), - sprintf(_("Additional error message details can be viewed %s."), $this->_params['contents']->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Additional message details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))) + sprintf(_("Additional error message details can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Additional message details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))) ) ) ); @@ -121,7 +121,7 @@ class IMP_Horde_Mime_Viewer_Status extends Horde_Mime_Viewer_Base 'icon' => Horde::img('alerts/success.png', _("Success")), 'text' => array( _("Your message was successfully delivered."), - sprintf(_("Additional message details can be viewed %s."), $this->_params['contents']->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Additional message details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))) + sprintf(_("Additional message details can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Additional message details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE)))) ) ) ); @@ -131,12 +131,12 @@ class IMP_Horde_Mime_Viewer_Status extends Horde_Mime_Viewer_Base } /* Print the human readable message. */ - $first_part = $this->_params['contents']->renderMIMEPart($part1_id, IMP_Contents::RENDER_INLINE_AUTO, array('params' => $this->_params)); + $first_part = $this->getConfigParam('imp_contents')->renderMIMEPart($part1_id, IMP_Contents::RENDER_INLINE_AUTO); /* Display a link to the returned message, if it exists. */ - $part3 = $this->_params['contents']->getMIMEPart($part3_id); + $part3 = $this->getConfigParam('imp_contents')->getMIMEPart($part3_id); if ($part3) { - $status[0]['text'][] = sprintf($msg_link, $this->_params['contents']->linkViewJS($part3, 'view_attach', _("HERE"), array('jstext' => $msg_link_status, 'ctype' => 'message/rfc822'))); + $status[0]['text'][] = sprintf($msg_link, $this->getConfigParam('imp_contents')->linkViewJS($part3, 'view_attach', _("HERE"), array('jstext' => $msg_link_status, 'ctype' => 'message/rfc822'))); } if (empty($first_part)) { @@ -152,7 +152,7 @@ class IMP_Horde_Mime_Viewer_Status extends Horde_Mime_Viewer_Base $ret[$this->_mimepart->getMimeId()] = array( 'data' => $data, 'status' => $status, - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset(), + 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap' ); diff --git a/imp/lib/Mime/Viewer/Tnef.php b/imp/lib/Mime/Viewer/Tnef.php index 017bca182..f0788619e 100644 --- a/imp/lib/Mime/Viewer/Tnef.php +++ b/imp/lib/Mime/Viewer/Tnef.php @@ -1,6 +1,6 @@ _renderInfo(); reset($ret); $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; @@ -59,12 +59,15 @@ class IMP_Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Tnef } /* Get the data from the attachment. */ - $tnef = Horde_Compress::factory('tnef'); + if (!($tnef = $this->getConfigParam('tnef'))) { + $tnef = Horde_Compress::factory('Tnef'); + $this->setConfigParam('tnef', $tnef); + } $tnefData = $tnef->decompress($this->_mimepart->getContents()); /* Display the requested file. Its position in the $tnefData * array can be found in 'tnef_attachment'. */ - $tnefKey = Horde_Util::getFormData('tnef_attachment') - 1; + $tnefKey = $tnef_atc - 1; /* Verify that the requested file exists. */ if (isset($tnefData[$tnefKey])) { @@ -94,7 +97,10 @@ class IMP_Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Tnef protected function _renderInfo() { /* Get the data from the attachment. */ - $tnef = Horde_Compress::factory('tnef'); + if (!($tnef = $this->getConfigParam('tnef'))) { + $tnef = Horde_Compress::factory('Tnef'); + $this->setConfigParam('tnef', $tnef); + } $tnefData = $tnef->decompress($this->_mimepart->getContents()); if (!count($tnefData)) { @@ -120,7 +126,7 @@ class IMP_Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Tnef } $temp_part->setType($type); - $link = $this->_params['contents']->linkView($temp_part, 'view_attach', htmlspecialchars($data['name']), array('jstext' => sprintf(_("View %s"), $data['name']), 'params' => array('tnef_attachment' => $key + 1))); + $link = $this->getConfigParam('imp_contents')->linkView($temp_part, 'view_attach', htmlspecialchars($data['name']), array('jstext' => sprintf(_("View %s"), $data['name']), 'params' => array('tnef_attachment' => $key + 1))); $text .= _("Attached File:") . '  ' . $link . '  (' . $data['type'] . '/' . $data['subtype'] . ")
\n"; } @@ -132,7 +138,7 @@ class IMP_Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Tnef 'text' => array(_("The following files were attached to this part:")) ) ), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + 'type' => 'text/html; charset=' . $this->getConfigParam('charset') ) ); } diff --git a/imp/lib/Mime/Viewer/Vcard.php b/imp/lib/Mime/Viewer/Vcard.php index e8cd4f217..8a5d97109 100644 --- a/imp/lib/Mime/Viewer/Vcard.php +++ b/imp/lib/Mime/Viewer/Vcard.php @@ -1,6 +1,6 @@ _imageUrl = $this->_params['contents']->urlView($this->_mimepart, 'download_render'); + $this->_imageUrl = $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'download_render'); return parent::_render(); } diff --git a/imp/lib/Mime/Viewer/Zip.php b/imp/lib/Mime/Viewer/Zip.php index f8ed42495..1e5e10588 100644 --- a/imp/lib/Mime/Viewer/Zip.php +++ b/imp/lib/Mime/Viewer/Zip.php @@ -1,6 +1,6 @@ _callback = array(&$this, '_IMPcallback'); + if (!($zip_atc = Horde_Util::getFormData('zip_attachment'))) { + $this->_callback = array($this, '_IMPcallback'); return parent::_render(); } /* Send the requested file. Its position in the zip archive is located * in 'zip_attachment'. */ $data = $this->_mimepart->getContents(); - $zip = Horde_Compress::factory('zip'); - $fileKey = Horde_Util::getFormData('zip_attachment') - 1; - $zipInfo = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST)); + $fileKey = $zip_atc - 1; + + if (!($zip = $this->getConfigParam('zip'))) { + $zip = Horde_Compress::factory('Zip'); + $this->setConfigParam('zip', $zip); + } + $zipInfo = $zip->decompress($data, array( + 'action' => Horde_Compress_Zip::ZIP_LIST + )); /* Verify that the requested file exists. */ if (isset($zipInfo[$fileKey])) { - $text = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => $zipInfo, 'key' => $fileKey)); + $text = $zip->decompress($data, array( + 'action' => Horde_Compress_Zip::ZIP_DATA, + 'info' => $zipInfo, + 'key' => $fileKey + )); if (!empty($text)) { return array( $this->_mimepart->getMimeId() => array( @@ -67,7 +77,7 @@ class IMP_Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Zip */ protected function _renderInfo() { - $this->_callback = array(&$this, '_IMPcallback'); + $this->_callback = array($this, '_IMPcallback'); return parent::_renderInfo(); } @@ -88,7 +98,7 @@ class IMP_Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Zip ($val['method'] == 0x0))) { $mime_part = $this->_mimepart; $mime_part->setName(basename($name)); - $val['name'] = str_replace($name, $this->_params['contents']->linkView($mime_part, 'download_render', $name, array('jstext' => sprintf(_("View %s"), str_replace(' ', ' ', $name)), 'class' => 'fixed', 'params' => array('zip_attachment' => urlencode($key) + 1))), $val['name']); + $val['name'] = str_replace($name, $this->getConfigParam('imp_contents')->linkView($mime_part, 'download_render', $name, array('jstext' => sprintf(_("View %s"), str_replace(' ', ' ', $name)), 'class' => 'fixed', 'params' => array('zip_attachment' => urlencode($key) + 1))), $val['name']); } return $val; diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 43b3f3e5a..aed3c7a70 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -272,7 +272,7 @@ class IMP_Prefs_Ui $mock_part = new Horde_Mime_Part(); $mock_part->setType('text/html'); - $v = Horde_Mime_Viewer::factory($mock_part); + $v = $GLOBALS['injector']->getInstance('IMP_Mime_Viewer')->getViewer($mock_part); if (!$v->canRender('inline')) { $ui->suppress[] = 'html_image_replacement'; diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index 1f882b023..eff16dced 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -429,7 +429,7 @@ class IMP_Ui_Message * Prints out a MIME status message (in HTML). * * @param array $data An array of information (as returned from - Horde_Mime_Viewer::render()). + Horde_Mime_Viewer_Base::render()). * * @return string The formatted status message string. */ diff --git a/imp/view.php b/imp/view.php index 4b7700f1d..4be0a0e26 100644 --- a/imp/view.php +++ b/imp/view.php @@ -154,7 +154,10 @@ case 'download_render': case 'compose_attach_preview': case 'view_attach': - $render = $contents->renderMIMEPart($vars->id, isset($vars->mode) ? $vars->mode : IMP_Contents::RENDER_FULL, array('params' => array('raw' => ($vars->actionID == 'compose_attach_preview'), 'type' => $vars->ctype))); + $render_mode = ($vars->actionID == 'compose_attach_preview') + ? IMP_Contents::RENDER_RAW_FALLBACK + : (isset($vars->mode) ? $vars->mode : IMP_Contents::RENDER_FULL); + $render = $contents->renderMIMEPart($vars->id, $render_mode, array('type' => $vars->ctype)); if (!empty($render)) { reset($render); $key = key($render); diff --git a/luxor/config/mime_drivers.php.dist b/luxor/config/mime_drivers.php.dist index 6d3519150..4b716a9b1 100644 --- a/luxor/config/mime_drivers.php.dist +++ b/luxor/config/mime_drivers.php.dist @@ -1,37 +1,13 @@ getInstance('Horde_Mime_Viewer')->getIcon(Horde_Mime_Magic::filenameToMime($node)), '', '', ''); $filesize = $files->getFilesize($dir . $node); if ($filesize < 1 << 10) { $bytes = _("bytes"); @@ -206,8 +206,10 @@ class Luxor $mime_part = new Horde_Mime_Part('text/plain', $contents); $mime_part->setName('README'); - $viewer = Horde_Mime_Viewer::factory($mime_part); - return $table_head . $viewer->render() . $table_foot; + + return $table_head . + $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getViewer($mime_part)->render() . + $table_foot; } } diff --git a/luxor/source.php b/luxor/source.php index c81516c88..8185610cc 100644 --- a/luxor/source.php +++ b/luxor/source.php @@ -109,7 +109,7 @@ function printfile_raw($pathname) $mime_part = new Horde_Mime_Part(Horde_Mime_Magic::filenameToMime($pathname), $data); $mime_part->setName($pathname); - $viewer = Horde_Mime_Viewer::factory($mime_part); + $viewer = $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getViewer($mime_part); if ($viewer->getType() == 'text/plain') { return '
' . htmlspecialchars($viewer->render()) . '
'; diff --git a/news/files.php b/news/files.php index b3403539e..749e00aea 100644 --- a/news/files.php +++ b/news/files.php @@ -60,7 +60,7 @@ case 'view_file': $mime_part->setType($file_type); $mime_part->setContents($data); - $viewer = Horde_Mime_Viewer::factory($mime_part); + $viewer = $injector->getInstance('Horde_Mime_Viewer')->getViewer($mime_part); if ($viewer) { $render = $viewer->render('full'); if (!empty($render)) { diff --git a/news/lib/News.php b/news/lib/News.php index 10e702ae9..eb283ae52 100644 --- a/news/lib/News.php +++ b/news/lib/News.php @@ -210,7 +210,7 @@ class News { $html .= Horde::link(Horde_Util::addParameter($view_url, 'actionID', 'download_zip'), sprintf(_("Compress and dowload %s"), $file['file_name'])) . $dowload_zip . ' ' . "\n"; $html .= Horde::link(Horde_Util::addParameter($view_url, 'actionID', 'download_file'), sprintf(_("Dowload %s"), $file['file_name'])) . $dowload_img . ' ' . "\n"; $html .= Horde::link(Horde_Util::addParameter($view_url, 'actionID', 'view_file'), sprintf(_("Preview %s"), $file['file_name']), '', '_file_view'); - $html .= Horde::img(Horde_Mime_Viewer::getIcon($file['file_type']), $file['file_name'], 'width="16" height="16"', '') . ' '; + $html .= Horde::img($GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getIcon($file['file_type']), $file['file_name'], 'width="16" height="16"', '') . ' '; if ($GLOBALS['registry']->isAdmin(array('permission' => 'news:admin'))) { $html .= Horde::link(Horde_Util::addParameter($delete_url, $file), sprintf(_("Delete %s"), $file['file_name'])) . $delete_img . ' ' . "\n"; } diff --git a/turba/config/mime_drivers.php.dist b/turba/config/mime_drivers.php.dist index fad1b9b7c..530185ac0 100644 --- a/turba/config/mime_drivers.php.dist +++ b/turba/config/mime_drivers.php.dist @@ -1,21 +1,13 @@ setType(Horde_Mime_Magic::extToMime($file['type'])); - $viewer = Horde_Mime_Viewer::factory($mime_part); + $viewer = $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getViewer($mime_part); // We can always download files. $url_params = array('actionID' => 'download_file', @@ -434,7 +434,7 @@ class Turba_Object { $dl = Horde::link(Horde::downloadUrl($file['name'], $url_params), $file['name']) . Horde::img('download.png', _("Download")) . ''; // Let's see if we can view this one, too. - if ($viewer && !is_a($viewer, 'Horde_Mime_Viewer_default')) { + if ($viewer && !($viewer instanceof Horde_Mime_Viewer_Default)) { $url = Horde::applicationUrl('view.php')->add('actionID', 'view_file'); $link = Horde::link($url, $file['name'], null, '_blank') . $file['name'] . ''; } else { diff --git a/turba/view.php b/turba/view.php index 323215036..25390cc9e 100644 --- a/turba/view.php +++ b/turba/view.php @@ -64,9 +64,8 @@ case 'view_file': $mime_part->setContents($data); $mime_part->setName($filename); $mime_part->buildMimeIds(); - $viewer = Horde_Mime_Viewer::factory($mime_part); - $content = $viewer->render('full'); + $content = $injector->getInstance('Horde_Mime_Viewer')->getViewer($mime_part)->render('full'); $body = $content[1]['data']; $browser->downloadHeaders($filename, $content[1]['type'], true, strlen($body)); diff --git a/whups/config/mime_drivers.php.dist b/whups/config/mime_drivers.php.dist index 9df7bcfeb..c8cd2ab16 100644 --- a/whups/config/mime_drivers.php.dist +++ b/whups/config/mime_drivers.php.dist @@ -1,37 +1,25 @@ 'compressed.png'); +$mime_drivers = array( + /* Zip File archive viewer. */ + 'zip' => array( + 'handles' = array( + 'application/x-compressed', + 'application/x-zip-compressed', + 'application/zip', + 'x-extension/zip', + ), + 'icons' => array( + 'default' => 'compressed.png' + ) + ) +); diff --git a/whups/lib/Mime/Viewer/Zip.php b/whups/lib/Mime/Viewer/Zip.php index b66e328da..400fb05b9 100644 --- a/whups/lib/Mime/Viewer/Zip.php +++ b/whups/lib/Mime/Viewer/Zip.php @@ -1,6 +1,6 @@ * @package Horde_MIME_Viewer */ -class Whups_Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip +class Whups_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip { /** * Return the full rendered version of the Horde_Mime_Part object. @@ -27,7 +27,7 @@ class Whups_Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip */ protected function _render() { - if (!Horde_Util::getFormData('zip_attachment')) { + if (!($zip_atc = Horde_Util::getFormData('zip_attachment'))) { $this->_callback = array($this, '_whupsCallback'); return parent::_render(); } @@ -35,13 +35,24 @@ class Whups_Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip /* Send the requested file. Its position in the zip archive is located * in 'zip_attachment'. */ $data = $this->_mimepart->getContents(); - $zip = Horde_Compress::factory('zip'); - $fileKey = Horde_Util::getFormData('zip_attachment') - 1; - $zipInfo = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_LIST)); + + if (!($zip = $this->getConfigParam('zip'))) { + $zip = Horde_Compress::factory('zip'); + $this->setConfigParam('zip', $zip); + } + + $fileKey = $zip_atc - 1; + $zipInfo = $zip->decompress($data, array( + 'action' => Horde_Compress_Zip::ZIP_LIST + )); /* Verify that the requested file exists. */ if (isset($zipInfo[$fileKey])) { - $text = $zip->decompress($data, array('action' => Horde_Compress_Zip::ZIP_DATA, 'info' => &$zipInfo, 'key' => $fileKey)); + $text = $zip->decompress($data, array( + 'action' => Horde_Compress_Zip::ZIP_DATA, + 'info' => &$zipInfo, + 'key' => $fileKey + )); if (!empty($text)) { return array( $this->_mimepart->getMimeId() => array( @@ -53,6 +64,7 @@ class Whups_Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip ); } } + // TODO: Error reporting return array(); } @@ -85,7 +97,7 @@ class Whups_Horde_Mime_Viewer_zip extends Horde_Mime_Viewer_Zip ($val['method'] == 0x0))) { $mime_part = $this->_mimepart; $mime_part->setName(basename($name)); - $val['name'] = str_replace($name, Horde::link(Horde_Util::addParameter(Horde::applicationUrl('view.php'), array('actionID' => 'view_file', 'type' => Horde_Util::getFormData('type'), 'file' => Horde_Util::getFormData('file'), 'ticket' => Horde_Util::getFormData('ticket'), 'zip_attachment' => $key + 1))) . $name . '', $val['name']); + $val['name'] = str_replace($name, Horde::applicationUrl('view.php')->add(array('actionID' => 'view_file', 'type' => Horde_Util::getFormData('type'), 'file' => Horde_Util::getFormData('file'), 'ticket' => Horde_Util::getFormData('ticket'), 'zip_attachment' => $key + 1))->link() . $name . '', $val['name']); } return $val; diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index 5b88390c1..596b7b933 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -821,8 +821,8 @@ class Whups { // Can we view the attachment online? $mime_part = new Horde_Mime_Part(); $mime_part->setType(Horde_Mime_Magic::extToMime($file['type'])); - $viewer = Horde_Mime_Viewer::factory($mime_part); - if ($viewer && !is_a($viewer, 'Horde_Mime_Viewer_Default')) { + $viewer = $GLOBALS['injector']->getInstance('Horde_Mime_Viewer')->getViewer($mime_part); + if ($viewer && !($viewer instanceof Horde_Mime_Viewer_Default)) { $url = Horde_Util::addParameter(Horde::applicationUrl('view.php'), array('actionID' => 'view_file', 'type' => $file['type'], diff --git a/whups/view.php b/whups/view.php index a90fee505..7e9063cfe 100644 --- a/whups/view.php +++ b/whups/view.php @@ -61,9 +61,7 @@ case 'view_file': $mime_part->setContents($data); $mime_part->setName($filename); - $viewer = Horde_Mime_Viewer::factory($mime_part); - - $ret = $viewer->render('full'); + $ret = $injector->getInstance('Horde_Mime_Viewer')->getViewer($mime_part)->render('full'); reset($ret); $key = key($ret); diff --git a/wicked/templates/display/standard.inc b/wicked/templates/display/standard.inc index 5c1a4fbb6..bec922082 100644 --- a/wicked/templates/display/standard.inc +++ b/wicked/templates/display/standard.inc @@ -124,7 +124,7 @@ foreach ($attachments as $attachment) { array('page' => $this->pageName(), 'file' => $attachment['attachment_name'], 'version' => $attachment['attachment_majorversion'] . '.' . $attachment['attachment_minorversion'])); - $icon = Horde_Mime_Viewer::getIcon(Horde_Mime_Magic::filenameToMime($attachment['attachment_name'])); + $icon = $injector->getInstance('Horde_Mime_Viewer')->getIcon(Horde_Mime_Magic::filenameToMime($attachment['attachment_name'])); echo Horde::link($url) . ' ' . htmlspecialchars($attachment['attachment_name']) . '
'; -- 2.11.0