From: Michael M Slusarz Date: Mon, 26 Jul 2010 19:49:29 +0000 (-0600) Subject: Move Mime Viewer code to horde/Mime_Viewer package X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=976f8044b7cb1e484382ca0676122458e0d0b715;p=horde.git Move Mime Viewer code to horde/Mime_Viewer package --- diff --git a/framework/Mime/lib/Horde/Mime/Exception.php b/framework/Mime/lib/Horde/Mime/Exception.php index 70f70b4ad..bbad39c96 100644 --- a/framework/Mime/lib/Horde/Mime/Exception.php +++ b/framework/Mime/lib/Horde/Mime/Exception.php @@ -1,6 +1,6 @@ - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -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. - */ - static final public function getIcon($mime_type) - { - $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; - } - } - } - - /* 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']); - } - - if (!is_null($ret)) { - $ret['url'] = Horde_Themes::img('mime/' . $ret['url'], $app); - } - - return $ret; - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Audio.php b/framework/Mime/lib/Horde/Mime/Viewer/Audio.php deleted file mode 100644 index 40678e881..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Audio.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Audio extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_mimepart->getContents(), - 'status' => array(), - 'type' => $this->_mimepart->getType() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Css.php b/framework/Mime/lib/Horde/Mime/Viewer/Css.php deleted file mode 100644 index 07fbd9bb2..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Css.php +++ /dev/null @@ -1,130 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Css extends Horde_Mime_Viewer_Source -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * Attribute preg patterns. - * - * @var array - */ - protected $_attrPatterns = array( - // Attributes - '!([-\w]+\s*):!s' => '\\1:', - // Values - '!:(\s*)(.+?)(\s*;)!s' => ':\\1\\2\\3', - // URLs - '!(url\([\'"]?)(.*?)([\'"]?\))!s' => '\\1\\2\\3', - // Colors - '!(#[[:xdigit:]]{3,6})!s' => '\\1', - // Parentheses - '!({|})!s' => '\\1', - // Unity - '!(em|px|%)\b!s' => '\\1' - ); - - /** - * Handles preg patterns. - * - * @var array - */ - protected $_handlesPatterns = array( - // HTML Tags - '!\b(body|h\d|a|span|div|acronym|small|strong|em|pre|ul|ol|li|p)\b!s' => '\\1\\2', - // IDs - '!(#[-\w]+)!s' => '\\1', - // Class - '!(\.[-\w]+)\b!s' => '\\1', - // METAs - '!(:link|:visited|:hover|:active|:first-letter)!s' => '\\1' - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - 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 the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - $css = preg_replace_callback('!(}|\*/).*?({|/\*)!s', array($this, '_handles'), htmlspecialchars($this->_mimepart->getContents(), ENT_NOQUOTES)); - $css = preg_replace_callback('!{[^}]*}!s', array($this, '_attributes'), $css); - $css = preg_replace_callback('!/\*.*?\*/!s', array($this, '_comments'), $css); - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_lineNumber(trim($css)), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * TODO - */ - protected function _comments($matches) - { - return '' . - preg_replace('!(http://[/\w-.]+)!s', '\\1', $matches[0]) . - ''; - } - - /** - * TODO - */ - protected function _attributes($matches) - { - return preg_replace(array_keys($this->_attrPatterns), array_values($this->_attrPatterns), $matches[0]); - } - - /** - * TODO - */ - protected function _handles($matches) - { - return preg_replace(array_keys($this->_handlesPatterns), array_values($this->_handlesPatterns), $matches[0]); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Deb.php b/framework/Mime/lib/Horde/Mime/Viewer/Deb.php deleted file mode 100644 index bf4450833..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Deb.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Deb extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $ret = $this->_renderInfo(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInfo() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $tmp_deb = Horde::getTempFile('horde_deb'); - - file_put_contents($tmp_deb, $this->_mimepart->getContents()); - - $fh = popen($this->_conf['location'] . " -f $tmp_deb 2>&1", 'r'); - while (($rc = fgets($fh, 8192))) { - $data .= $rc; - } - pclose($fh); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => '
' . htmlspecialchars($data) . '
', - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Default.php b/framework/Mime/lib/Horde/Mime/Viewer/Default.php deleted file mode 100644 index e2d9be9df..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Default.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Default extends Horde_Mime_Viewer_Driver -{ -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php deleted file mode 100644 index ea5947265..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php +++ /dev/null @@ -1,353 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Driver -{ - /** - * Viewer configuration. - * - * @var array - */ - protected $_conf = array(); - - /** - * The Horde_Mime_Part object to render. - * - * @var Horde_Mime_Part - */ - protected $_mimepart = null; - - /** - * Viewer parameters. - * - * @var array - */ - protected $_params = array(); - - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => false, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - // Is the part *data* compressed (not the rendered data)? - 'compressed' => false, - // Does this part contain emebedded MIME data? - 'embedded' => false, - // Force inline display of this part? - 'forceinline' => false - ); - - /** - * 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. - */ - public function __construct($mime_part, $conf = array()) - { - $this->_mimepart = $mime_part; - $this->_conf = $conf; - } - - /** - * Sets the Horde_Mime_Part object for the class. - * - * @param Horde_Mime_Part $mime_part The object with the information to - * be rendered. - */ - public function setMIMEPart($mime_part) - { - $this->_mimepart = $mime_part; - } - - /** - * Set parameters for use with this object. - * - * @param array $params An array of params to add to the internal - * params list. - */ - public function setParams($params = array()) - { - $this->_params = array_merge($this->_params, $params); - } - - /** - * Return the rendered version of the Horde_Mime_Part object. - * - * @param string $mode The mode: - *
-     * 'full' - A full representation of the MIME part, for use in a view
-     *          where the output to the browser can be set to the value
-     *          returned in 'type'. This mode should only return a single
-     *          MIME ID entry for viewing and should not return any status
-     *          information.
-     * 'inline' - A representation of the MIME part that can be viewed inline
-     *            on a text/html page that may contain other HTML elements.
-     * 'info' - A representation of the MIME part that can be viewed inline
-     *          on an text/html page that may contain other HTML elements.
-     *          This view is not a full view, but rather a condensed view of
-     *          the contents of the MIME part. This view is intended to be
-     *          displayed to the user with the intention that this MIME part's
-     *          subparts may also independently be viewed inline.
-     * 'raw' - The raw data of the MIME part, generally useful for downloading
-     *         a part. This view exists in case this raw data needs to be
-     *         altered in any way.
-     * 
- * - * @return array An array. The keys are the MIME parts that were handled - * by the driver. The values are either null (which - * indicates the driver is recommending that this - * particular MIME ID should not be displayed) or an array - * with the following keys: - *
-     * 'data' - (string) The rendered data.
-     * 'status' - (array) An array of status information to be displayed to
-     *            the user.  Consists of arrays with the following keys:
-     *            'class' - (string) The class to use for display.
-     *            'img' - (string) An image to display.
-     *            'text' - (array) The text to display.
-     * 'type' - (string) The MIME type of the rendered data.
-     * 
- */ - public function render($mode) - { - switch ($mode) { - case 'full': - try { - return $this->_render(); - } catch (Horde_Exception $e) { - $error = $e; - } - break; - - case 'inline': - try { - return $this->_renderInline(); - } catch (Horde_Exception $e) { - $error = $e; - } - - case 'info': - try { - return $this->_renderInfo(); - } catch (Horde_Exception $e) { - $error = $e; - } - - case 'raw': - try { - return $this->_renderRaw(); - } catch (Horde_Exception $e) { - $error = $e; - } - } - - // TODO: Error handling - } - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _render() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->render('full') - : array(); - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInline() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->render('inline') - : array(); - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInfo() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->render('info') - : array(); - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderRaw() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->render('raw') - : array(); - } - - /** - * Can this driver render the the data? - * - * @param string $mode The mode. Either 'full', 'inline', 'info', or - * 'raw'. - * - * @return boolean True if the driver can render the data for the given - * view. - */ - public function canRender($mode) - { - $viewer = $this->_getViewer(); - if ($viewer) { - return $viewer->canRender($mode); - } - - switch ($mode) { - case 'full': - case 'info': - case 'raw': - return $this->_capability[$mode]; - - case 'inline': - return $this->getConfigParam('inline') && - ($this->_metadata['forceinline'] || - ($this->_capability['inline'] && - ($this->_mimepart->getDisposition() != 'attachment'))); - - default: - return false; - } - } - - /** - * Does this MIME part possibly contain embedded MIME parts? - * - * @return boolean True if this driver supports parsing embedded MIME - * parts. - */ - public function embeddedMimeParts() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->embeddedMimeParts() - : $this->_metadata['embedded']; - } - - /** - * If this MIME part can contain embedded MIME part(s), and those part(s) - * exist, return a representation of that data. - * - * @return mixed A Horde_Mime_Part object representing the embedded data. - * Returns null if no embedded MIME part(s) exist. - */ - public function getEmbeddedMimeParts() - { - $viewer = $this->_getViewer(); - return $viewer - ? $viewer->getEmbeddedMimeParts() - : $this->_getEmbeddedMimeParts(); - } - - /** - * If this MIME part can contain embedded MIME part(s), and those part(s) - * exist, return a representation of that data. - * - * @return mixed A Horde_Mime_Part object representing the embedded data. - * Returns null if no embedded MIME part(s) exist. - */ - protected function _getEmbeddedMimeParts() - { - return null; - } - - /** - * Return a configuration parameter for the current viewer. - * - * @param string $param The parameter name. - * - * @return mixed The value of the parameter; returns null if the - * parameter doesn't exist. - */ - public function getConfigParam($param) - { - return isset($this->_conf[$param]) ? $this->_conf[$param] : null; - } - - /** - * Returns the driver name for the current object. - * - * @return string The driver name. - */ - public function getDriver() - { - return $this->_conf['_driver']; - } - - /** - * Returns metadata information on the viewer/data. - * - * @param string $data The metadata key. - * - * @return mixed The requested information, or null if the key doesn't - * exist. - */ - public function getMetadata($data) - { - return isset($this->_metadata[$data]) - ? $this->_metadata[$data] - : null; - } - - /** - * Return the underlying MIME Viewer for this part. - * - * @return mixed A Horde_Mime_Viewer object, or false if not found. - */ - protected function _getViewer() - { - return false; - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php b/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php deleted file mode 100644 index 5eff41f82..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php +++ /dev/null @@ -1,202 +0,0 @@ - command and the next balancing - * removes all other formatting commands (all text enclosed - * in angle brackets), and outside of environments converts - * any series of n CRLFs to n-1 CRLFs, and converts any lone CRLF - * pairs to SPACE. - * - * We don't qualify as we don't currently track the - * environment, that is we do CRLF conversion even if is - * specified in the text, but we're close at least. - * - * Copyright 2001-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. - * - * @author Eric Rostetter - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Enriched extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => '' . $this->_toHTML(false) . '', - 'status' => array(), - 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() - ) - ); - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => Horde_String::convertCharset($this->_toHTML(true), $this->_mimepart->getCharset()), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Convert the enriched text to HTML. - * - * @param string $inline Rendered inline? - * - * @return string The HTML-ified version of the MIME part contents. - */ - protected function _toHTML($inline) - { - $text = trim($this->_mimepart->getContents()); - if (!strlen($text)) { - return array(); - } - - // We add space at the beginning and end of the string as it will - // make some regular expression checks later much easier (so we - // don't have to worry about start/end of line characters) - $text = ' ' . $text . ' '; - - // We need to preserve << tags, so map them to ascii 1 or ascii 255 - // We make the assumption here that there would never be an ascii - // 1 in an email, which may not be valid, but seems reasonable... - // ascii 255 would work if for some reason you don't like ascii 1 - // ascii 0 does NOT seem to work for this, though I'm not sure why - $text = str_replace('<<', chr(1), $text); - - // Remove any unrecognized tags in the text (via RFC minimal specs) - // any tags we just don't want to implement can also be removed here - // Note that this will remove any html links, but this is intended - $implementedTags = '' . - '
' . - ''; - // $unImplementedTags = ''; - $text = strip_tags($text, $implementedTags); - - // restore the << tags as < tags now... - $text = str_replace(chr(1), '<<', $text); - // $text = str_replace(chr(255), '<', $text); - - $replace = array( - // Get color parameters into a more useable format. - '/([\da-fA-F]+),([\da-fA-F]+),([\da-fA-F]+)<\/param>/Uis' => '', - '/(red|blue|green|yellow|cyan|magenta|black|white)<\/param>/Uis' => '', - - // Get font family parameters into a more useable format. - '/(\w+)<\/param>/Uis' => '', - - /* Just remove any remaining parameters -- we won't use them. - * Any tags with parameters that we want to implement will have - * come before this. Someday we hope to use these tags (e.g. for - * tags). */ - '/.*<\/param>/Uis' => '', - - /* Single line breaks become spaces, double line breaks are a - * real break. This needs to do tracking to be compliant - * but we don't want to deal with state at this time, so we fake - * it some day we should rewrite this to handle - * correctly. */ - '/([^\n])\r\n([^\r])/' => '\1 \2', - '/(\r\n)\r\n/' => '\1' - ); - $text = preg_replace(array_keys($replace), array_values($replace), $text); - - // We try to protect against bad stuff here. - $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset()); - - // Now convert the known tags to html. Try to remove any tag - // parameters to stop people from trying to pull a fast one - $replace = array( - '/(? '\1', - '/(? '\1', - '/(? '\1' - ); - $text = preg_replace(array_keys($replace), array_values($replace), $text); - - $text = preg_replace_callback('/(? '\2', - '/(? '\1', - '/(? '\2', - '/(? '', - '/(? '', - '/(? '', - '/(? '', - '/(? '\1', - '/(? '
\1
', - '/(? '
\1
', - '/(? '
\1
', - '/(? '
\1
', - '/(? '
\1
', - '/(? '
\1
' - ); - $text = preg_replace(array_keys($replace), array_values($replace), $text); - - // Replace << with < now (from translated HTML form). - $text = str_replace('<<', '<', $text); - - // Now we remove the leading/trailing space we added at the - // start. - $text = preg_replace('/^ (.*) $/s', '\1', $text); - - // Make URLs clickable. - $text = Horde_Text_Filter::filter($text, 'linkurls', array( - 'callback' => 'Horde::externalUrl' - )); - - /* Wordwrap -- note this could impact on our above RFC compliance *IF* - * we honored nofill tags (which we don't yet). */ - $text = str_replace(array("\t", ' ', "\n "), array(' ', '  ', "\n "), $text); - - if ($text[0] == ' ') { - $text = ' ' . substr($text, 1); - } - - return '

' . nl2br($text) . '

'; - } - - /** - * TODO - */ - public function colorize($colors) - { - for ($i = 1; $i < 4; $i++) { - $colors[$i] = sprintf('%02X', round(hexdec($colors[$i]) / 255)); - } - return '' . $colors[4] . ''; - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Html.php b/framework/Mime/lib/Horde/Mime/Viewer/Html.php deleted file mode 100644 index 120738d9c..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Html.php +++ /dev/null @@ -1,287 +0,0 @@ - - * @author Jon Parise - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * The CSS used to display the phishing warning. - * - * @var string - */ - protected $_phishCss = 'padding: 1px;margin-bottom: 3px;font-size: 90%;border: 1px solid #800;background: #e81222;color: #fff;width: 100%;'; - - /** - * Phishing status of last call to _phishingCheck(). - * - * @var boolean - */ - protected $_phishWarn = false; - - /** - * Temp array for storing data when parsing the HTML document. - * - * @var array - */ - protected $_tmp = array(); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $html = $this->_cleanHTML($this->_mimepart->getContents(), array('inline' => false)); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $html['html'], - 'status' => array(), - 'type' => $this->_mimepart->getType(true) - ) - ); - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - $html = $this->_cleanHTML($this->_mimepart->getContents(), array('inline' => true)); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => Horde_String::convertCharset($html['data'], $this->_mimepart->getCharset()), - 'status' => $html['status'], - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Filters active content, dereferences external links, detects phishing, - * etc. - * - * @todo Use IP checks from - * http://lxr.mozilla.org/mailnews/source/mail/base/content/phishingDetector.js. - * - * @param string $data The HTML data. - * @param array $options Additional options: - *
-     * 'charset' - (string) The charset of $data.
-     *             DEFAULT: The base part charset.
-     * 'inline' - (boolean) Are we viewing inline?
-     *            DEFAULT: false
-     * 'noprefetch' - (boolean) Disable DNS prefetching?
-     *                DEFAULT: false
-     * 'phishing' - (boolean) Do phishing highlighting even if not viewing
-     *              inline.
-     *              DEFAULT: false.
-     * 
- * - * @return string The cleaned HTML string. - */ - protected function _cleanHTML($data, $options = array()) - { - global $browser; - - $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( - array( - 'charset' => isset($options['charset']) ? $options['charset'] : $this->_mimepart->getCharset() - ), - array( - 'noprefetch' => !empty($options['noprefetch']), - 'return_dom' => true, - 'strip_styles' => (!empty($options['inline']) || $strip_style_attributes), - 'strip_style_attributes' => $strip_style_attributes - ) - )); - - $this->_tmp = array( - 'base' => null, - 'inline' => !empty($options['inline']), - 'phish' => ((!empty($options['inline']) || !empty($options['phishing'])) && $this->getConfigParam('phishing_check')) - ); - $this->_phishWarn = false; - - $this->_node($data, $data); - - return $data->saveHTML(); - } - - /** - * Process DOM node. - * - * @param DOMDocument $doc Document node. - * @param DOMNode $node Node. - */ - protected function _node($doc, $node) - { - if ($node->hasChildNodes()) { - foreach ($node->childNodes as $child) { - if ($child instanceof DOMElement) { - switch (strtolower($child->tagName)) { - case 'base': - /* Deal with tags in the HTML, since they will - * screw up our own relative paths. */ - if ($this->_tmp['inline'] && - $child->hasAttribute('href')) { - $base = $child->getAttribute('href'); - if (substr($base, -1) != '/') { - $base .= '/'; - } - - $this->_tmp['base'] = $base; - $child->removeAttribute('href'); - } - break; - } - - foreach ($child->attributes as $val) { - /* Attempt to fix paths that were relying on a - * tag. */ - if (!is_null($this->_tmp['base']) && - in_array($val->name, array('href', 'src'))) { - $child->setAttribute($val->name, $this->_tmp['base'] . ltrim($val->value, '/')); - } - - if ($val->name == 'href') { - if ($this->_tmp['phish'] && - $this->_phishingCheck($val->value, $child->textContent)) { - $this->_phishWarn = true; - $child->setAttribute('style', ($child->hasAttribute('style') ? rtrim($child->getAttribute('style'), '; ') . ';' : '') . $this->_phishCss); - } - - /* Try to derefer all external references. */ - $child->setAttribute('href', Horde::externalUrl($val->value)); - } - } - } - - $this->_nodeCallback($doc, $child); - $this->_node($doc, $child); - } - } - } - - /** - * Process DOM node (callback). - * - * @param DOMDocument $doc Document node. - * @param DOMNode $node Node. - */ - protected function _nodeCallback($doc, $node) - { - } - - /** - * Check for phishing exploits. - * - * @param string $href The HREF value. - * @param string $text The text value of the link. - * - * @return boolean True if phishing is detected. - */ - protected function _phishingCheck($href, $text) - { - /* For phishing, we are checking whether the displayable text URL is - * the same as the HREF URL. If we can't parse the text URL, then we - * can't do phishing checks. */ - $text_url = @parse_url($text); - if (!$text_url) { - return false; - } - - $href_url = parse_url($href); - - /* Only concern ourselves with HTTP and FTP links. */ - if (!isset($href_url['scheme']) || - !in_array($href_url['scheme'], array('ftp', 'http', 'https'))) { - return false; - } - - /* Check for case where text is just the domain name. */ - if (!isset($text_url['host'])) { - if (!isset($text_url['path']) || - !preg_match("/^[^\.\s]+(?:\.[^\.\s]+)+$/", $text_url['path'])) { - return false; - } - - $text_url['host'] = $text_url['path']; - } - - /* If port exists on link, and text link has scheme or port defined, - * do extra checks: - * 1. If port exists on text link, and doesn't match, this is - * phishing. - * 2. If port doesn't exist on text link, and port does not match - * defaults, this is phishing. */ - if (isset($href_url['port']) && - (isset($text_url['scheme']) || isset($text_url['port']))) { - if (!isset($text_url['port'])) { - switch ($text_url['scheme']) { - case 'ftp': - $text_url['port'] = 25; - break; - - case 'http': - $text_url['port'] = 80; - break; - - case 'https': - $text_url['port'] = 443; - break; - } - } - - if ($href_url['port'] != $text_url['port']) { - return false; - } - } - - if (strcasecmp($href_url['host'], $text_url['host']) === 0) { - return false; - } - - /* Don't consider the link a phishing link if the domain is the same - * on both links (e.g. adtracking.example.com & www.example.com). */ - $host1 = explode('.', $href_url['host']); - $host2 = explode('.', $text_url['host']); - - return (strcasecmp(implode('.', array_slice($host1, -2)), implode('.', array_slice($host2, -2))) !== 0); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Images.php b/framework/Mime/lib/Horde/Mime/Viewer/Images.php deleted file mode 100644 index 2b29af879..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Images.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * 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. - */ - public function __construct($mime_part, $conf = array()) - { - parent::__construct($mime_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')); - } - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_mimepart->getContents(), - 'status' => array(), - 'type' => $this->_getType() - ) - ); - } - - /** - * Return the content-type to use for the image. - * - * @return string The content-type of the image. - */ - protected function _getType() - { - $type = $this->_mimepart->getType(); - - switch ($type) { - case 'image/pjpeg': - /* image/jpeg and image/pjpeg *appear* to be the same entity, but - * Mozilla (for one) don't seem to want to accept the latter. */ - return 'image/jpeg'; - - case 'image/x-png': - /* image/x-png == image/png. */ - return 'image/png'; - - default: - return $type; - } - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Msexcel.php b/framework/Mime/lib/Horde/Mime/Viewer/Msexcel.php deleted file mode 100644 index 24151f02c..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Msexcel.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Msexcel extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $tmp_xls = Horde::getTempFile('horde_msexcel'); - $tmp_out = Horde::getTempFile('horde_msexcel'); - - file_put_contents($tmp_xls, $this->_mimepart->getContents()); - $args = ' -E Gnumeric_Excel:excel_dsf -T Gnumeric_html:html40 ' . $tmp_xls . ' ' . $tmp_out; - - exec($this->_conf['location'] . $args); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => file_get_contents($tmp_out), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Mspowerpoint.php b/framework/Mime/lib/Horde/Mime/Viewer/Mspowerpoint.php deleted file mode 100644 index 238d3f0db..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Mspowerpoint.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Mspowerpoint extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $data = ''; - $tmp_ppt = Horde::getTempFile('horde_mspowerpoint'); - - file_put_contents($tmp_ppt, $this->_mimepart->getContents()); - - $fh = popen($this->_conf['location'] . " $tmp_ppt 2>&1", 'r'); - while (($rc = fgets($fh, 8192))) { - $data .= $rc; - } - pclose($fh); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Msword.php b/framework/Mime/lib/Horde/Mime/Viewer/Msword.php deleted file mode 100644 index 4b1171b20..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Msword.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Msword extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $tmp_word = Horde::getTempFile('msword'); - $tmp_output = Horde::getTempFile('msword'); - $tmp_file = str_replace(Horde::getTempDir() . '/', '', $tmp_output); - - file_put_contents($tmp_word, $this->_mimepart->getContents()); - $args = ' --to=html --to-name=' . $tmp_output . ' ' . $tmp_word; - - exec($this->_conf['location'] . $args); - - if (file_exists($tmp_output)) { - $data = file_get_contents($tmp_output); - $type = 'text/html'; - } else { - $data = _("Unable to translate this Word document"); - $type = 'text/plain'; - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => $type . '; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo.php b/framework/Mime/lib/Horde/Mime/Viewer/Ooo.php deleted file mode 100644 index a229c7c36..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo.php +++ /dev/null @@ -1,130 +0,0 @@ - - * @author Jan Schneider - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - /* At this point assume that the document takes advantage of ZIP - * compression. */ - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _render() - { - $has_xslt = Horde_Util::extensionExists('xslt'); - $has_ssfile = function_exists('domxml_xslt_stylesheet_file'); - if (($use_xslt = $has_xslt || $has_ssfile)) { - $tmpdir = Horde_Util::createTempDir(true); - } - - $fnames = array('content.xml', 'styles.xml', 'meta.xml'); - $tags = array( - 'text:p' => 'p', - 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ', - 'table:table-row' => 'tr bgcolor="#cccccc"', - 'table:table-cell' => 'td', - 'table:number-columns-spanned=' => 'colspan=' - ); - - $zip = Horde_Compress::factory('zip'); - $list = $zip->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST)); - - foreach ($list as $key => $file) { - if (in_array($file['name'], $fnames)) { - $content = $zip->decompress($this->_mimepart->getContents(), array( - 'action' => Horde_Compress_Zip::ZIP_DATA, - 'info' => $list, - 'key' => $key - )); - - if ($use_xslt) { - file_put_contents($tmpdir . $file['name'], $content); - } elseif ($file['name'] == 'content.xml') { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => str_replace(array_keys($tags), array_values($tags), $content), - 'status' => array(), - 'type' => 'text/html; charset=UTF-8' - ) - ); - } - } - } - - if (!Horde_Util::extensionExists('xslt')) { - return array(); - } - - $xsl_file = dirname(__FILE__) . '/Ooo/main_html.xsl'; - - if ($has_ssfile) { - /* Use DOMXML */ - $xslt = domxml_xslt_stylesheet_file($xsl_file); - $dom = domxml_open_file($tmpdir . 'content.xml'); - $result = @$xslt->process($dom, array( - 'metaFileURL' => $tmpdir . 'meta.xml', - 'stylesFileURL' => $tmpdir . 'styles.xml', - 'disableJava' => true) - ); - $result = $xslt->result_dump_mem($result); - } else { - // Use XSLT - $xslt = xslt_create(); - $result = @xslt_process($xslt, $tmpdir . 'content.xml', $xsl_file, null, null, array( - 'metaFileURL' => $tmpdir . 'meta.xml', - 'stylesFileURL' => $tmpdir . 'styles.xml', - 'disableJava' => true) - ); - if (!$result) { - $result = xslt_error($xslt); - } - xslt_free($xslt); - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $result, - 'status' => array(), - 'type' => 'text/html; charset=UTF-8' - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/common.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/common.xsl deleted file mode 100644 index 943a5b995..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/common.xsl +++ /dev/null @@ -1,1165 +0,0 @@ - - - - - - - - - - - - - - - - - - = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - height: ; - - - width: ; - - - height: ; - width: ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - margin-left:; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -     - - - - - - - - - - - - - - - - - - - - - - - -     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * - * - - - - - - - - - - - - * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/global_document.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/global_document.xsl deleted file mode 100644 index fc4579ef3..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/global_document.xsl +++ /dev/null @@ -1,1674 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Matching child document header No. - absolute-chapter-level: - encodedTitle: - globalDocumentRefToCurrentFile: - *** - - - - - - + - - - - - - - - - - - - - - - - - - Matching global document header No. - absolute-chapter-level: - encodedTitle: - contentTableURL: - *** - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - Creation of global document helper variable for the content table.... - - - - - - - - - - - - - - - - - Finished the Creation of global document helper variable for the content table! - - - - - Creation of global document helper variable for the child documents.... - - - - - - Finished the Creation of global document helper variable for the child documents! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - level: - title: - encoded-title: - file-url: - header-no: - ** - - ** - ** - - - childrenHeadings/heading-count: - - # - title: - ** - - - - - - - - - - - - - - - - - - Creating global document variable for chapter relations.... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Finished global document variable for chapter relations! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *** new heading - currentChapterID: - currentChapterTitle: - currentChapterID: - currentHeadingNo: - headingTitle: - headingLevel: - headingNo: - newChildURL: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - only a heading, but not a chapter - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - All child documents have been walked through without finding the chapter name! - childrenHeadings/heading-count: - currentHeadingNo: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Parsing the global document... - - - - - - - - Parsing the child documents... - - - - - - - - - - - - - Starting the child transformations... - - - - - - Contentable data exists as global data! - - - No Contentable global data exists! - - - - - - - - - - - - - Java method transformChildren to transform all children of a global document could not be found. Be sure to use the XT processor. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Previous document - - - | - - - - - - - - - - - - - - - - - - # - - - - - - Content Table - - - - - - | - - - - - - - - - - - - - - - - - - - - - Next document - - - ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - **** THE HEADING VARIABLE **** - content-table-url: - - - **** new heading: - content-table-id: - child-document-no: - file-url: - out-file-url: - level: - title: - encoded-title: - absolute-chapter-level: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - width: - - - - - - - - - - - - - - - - - - - - - - - - - - - - align: right - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/main_html.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/main_html.xsl deleted file mode 100644 index 443182a3e..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/main_html.xsl +++ /dev/null @@ -1,462 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CSS helper variable will be created.... - - CSS variable ready, header will be created.... - - - CSS header creation finished! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - description - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Creating the inline styles.... - - - - - Time for instantiating style variable: ms - - - - - - Creating the inline styles.... - - - - - Time for instantiating style variable: ms - - - - - - - - - - - Parameter dpi: - Parameter metaFileURL: - Parameter stylesFileURL: - Parameter absoluteSourceDirRef: - Parameter precedingChapterLevel1 : - Parameter precedingChapterLevel2 : - Parameter precedingChapterLevel3 : - Parameter precedingChapterLevel4 : - Parameter precedingChapterLevel5 : - Parameter precedingChapterLevel6 : - Parameter precedingChapterLevel7 : - Parameter precedingChapterLevel8 : - Parameter precedingChapterLevel9 : - Parameter precedingChapterLevel10: - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/palm.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/palm.xsl deleted file mode 100644 index 212edb167..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/palm.xsl +++ /dev/null @@ -1,404 +0,0 @@ - - - - - - - - - - - - - PalmComputingPlatform - true - - - HandheldFriendly - true - - - HistoryListText - Dateimanager : &date &time - - - description - StarPortal - - - keywords - starportal, staroffice, software - - - Content-Type - text/html; charset=iso-8859-1 - - - - - - - - - - - - - - - - - left - - - right - - - center - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - left - - - right - - - center - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #000000 - - - #FFFFFF - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #000000 - - - #FFFFFF - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_header.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_header.xsl deleted file mode 100644 index eeb0c204a..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_header.xsl +++ /dev/null @@ -1,379 +0,0 @@ - - - - - - - - - - - - - The CSS style header method for setting styles - - - text/css - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - - - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.OOo_defaults - - - , - - - - - , - - - - { - margin-top:0cm; margin-bottom:0cm; } - - - - - - - - - - - - - - - - - - - - - - , - - - - - , - - - - - - - - - - - - - - { - - - } - - - - - - - - - - - - - - - - - - - - - - - - , - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl deleted file mode 100644 index 19159958c..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl +++ /dev/null @@ -1,398 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl deleted file mode 100644 index a9a858dc0..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl +++ /dev/null @@ -1,660 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - float: right; - - - float: left; - - - - - - - - align: left; - - - align: right; - - - align: center; - - - - - - - - padding: - - ; - - - - - - - - - border-width:; - border-style:; - border-color:; - - - border-width:; - border-style:; - border-color:; - - - border-width:; - border-style:; - border-color:; - - - - - border-top: ; - - - border-bottom: ; - - - border-left: ; - - - border-right: ; - - - - - - width:; - - - width:; - - - - - - - - height:; - - - height:; - - - - - - - - width:; - - - width:; - - - - - - :; - - - font-family: - - - ; - - font-style:italic; - - - font-weight:bold; - - - - :; - - - :; - - - :; - - - :; - - - :; - - - :; - - - :; - - - :; - - - :; - - - - - - text-align:left ! important; - - - text-align:right ! important; - - - text-align: ! important; - - - - - :; - - - background-color:; - - - background-color:; - - - background-image:url(); - - - background-repeat:repeat; - - - background-repeat:no-repeat; - - - - - - :; - - - - text-decoration:line-through; - - - - - text-decoration:underline; - - - - - vertical-align:sub; - - - vertical-align:sup; - - - - - - - - - - - - - - - - - - - italic, - - - - - - - bold, - - - - - - underline, - - - - - - - align:left, - - - align:right, - - - align:center, - - - - - - - strike, - - - - - size::size, - - - - - - - color:#FFFFFF, - - - color:#000000, - - - - - - - - size::size, - - - - - - width::width, - - - width::width; - - - - - - - - height::height; - - - height::height; - - - - - - - - width::width; - - - width::width; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table.xsl deleted file mode 100644 index 36339ed73..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table.xsl +++ /dev/null @@ -1,328 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - left - - - right - - - center - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - maxRowLength: - - numberOfHiddenColumns: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - #000000 - 2 - 0 - page-break-inside:avoid - - - - - - - - - - - - - - - - Time for checking BorderStyle: ms - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl deleted file mode 100644 index 4671ea96f..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl +++ /dev/null @@ -1,484 +0,0 @@ - - - - - - - - - - - - - - - - - - ---------------> table:table-cell has been entered with node value: - table:number-columns-repeated: -- - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NEW VALUE: column-position: -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +++++++++ starting cell writing +++++++++ - number-columns-repeated: -- - maxRowLength: -- - column-position: -- - - - - - - - - - - - - +++++++++ cell repetition +++++++++ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WriteTest -> If nothing between '-' write cell -- - - - - - TABLE COLUMN is hidden! - - - - - - - - TABLE COLUMN is hidden! - - - - - - - - - - - th - - - td - - - - - - - - - - - -*****************************************'' element has been added! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text-align:right; - text-align:left; - - - - - - - - - - - - - - - - - - - - text-align:right; - - - text-align:left; - - - - - - - - - -   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text-align:right; - - - text-align:left; - - - - - -   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - , - - - - - - ; - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl deleted file mode 100644 index a9a907ff8..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DebugInformation: For each 'column-style-entry' of the 'allColumnStyleEntries' variable the style-name is given out. - In case of 'column-hidden-flag' attribute the text 'column is hidden' is given out. - - - - - column is hidden - - - - = - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl b/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl deleted file mode 100644 index 6f7d17d62..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*************************'tr' element has been added! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Pdf.php b/framework/Mime/lib/Horde/Mime/Viewer/Pdf.php deleted file mode 100644 index f0d97c9e0..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Pdf.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_mimepart->getContents(), - 'status' => array(), - 'type' => 'application/pdf' - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Php.php b/framework/Mime/lib/Horde/Mime/Viewer/Php.php deleted file mode 100644 index fe86866cc..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Php.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Php extends Horde_Mime_Viewer_Source -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - 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 the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - $code = $this->_mimepart->getContents(); - if (strpos($code, ''), array('', "\n"), $text)); - $text = $this->_lineNumber($text); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $text, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Plain.php b/framework/Mime/lib/Horde/Mime/Viewer/Plain.php deleted file mode 100644 index 3aeb4e564..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Plain.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $text = $this->_mimepart->getContents(); - $charset = $this->_mimepart->getCharset(); - - /* Check for 'flowed' text data. */ - if ($this->_mimepart->getContentTypeParameter('format') == 'flowed') { - $text = $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')); - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => '' . Horde_Text_Filter::filter($text, 'text2html', array( - 'charset' => $charset, - 'parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL - )) . '', - 'status' => array(), - 'type' => 'text/html; charset=' . $charset - ) - ); - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()); - - /* Check for 'flowed' text data. */ - $data = ($this->_mimepart->getContentTypeParameter('format') == 'flowed') - ? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')) - : $text; - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Format flowed text for HTML output. - * - * @param string $text The text to format. - * @param boolean $delsp Was text created with DelSp formatting? - * - * @return string The formatted text. - */ - protected function _formatFlowed($text, $delsp = null) - { - $flowed = new Horde_Text_Flowed($this->_mimepart->replaceEOL($text, "\n"), $this->_mimepart->getCharset()); - $flowed->setMaxLength(0); - if (!is_null($delsp)) { - $flowed->setDelSp($delsp); - } - return $flowed->toFixed(); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Rar.php b/framework/Mime/lib/Horde/Mime/Viewer/Rar.php deleted file mode 100644 index 615c3ab32..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Rar.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @author Michael Cochrane - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $ret = $this->_renderInfo(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInfo() - { - $contents = $this->_mimepart->getContents(); - - $rar = Horde_Compress::factory('rar'); - $rarData = $rar->decompress($contents); - - $charset = $GLOBALS['registry']->getCharset(); - $fileCount = count($rarData); - - $name = $this->_mimepart->getName(true); - if (empty($name)) { - $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)) .
-            "\n\n" .
-            Horde_Text_Filter::filter(
-                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) .
-                Horde_String::pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) .
-                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";
-
-        foreach ($rarData as $val) {
-            $ratio = empty($val['size'])
-                ? 0
-                : 100 * ($val['csize'] / $val['size']);
-
-            $text .= Horde_Text_Filter::filter(
-                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) .
-                Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) .
-                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)
-            ) . "\n";
-        }
-
-        return array(
-            $this->_mimepart->getMimeId() => array(
-                'data' => nl2br($text . str_repeat('-', 106) . "\n
"), - 'status' => array(), - 'type' => 'text/html; charset=' . $charset - ) - ); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Report.php b/framework/Mime/lib/Horde/Mime/Viewer/Report.php deleted file mode 100644 index 817b65dd8..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Report.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Report extends Horde_Mime_Viewer_Driver -{ - /** - * Return the underlying MIME Viewer for this part. - * - * @return mixed A Horde_Mime_Viewer object, or false if not found. - */ - protected function _getViewer() - { - 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 - * sub-type of the second body part. */ - $parts = $this->_mimepart->getParts(); - if (!isset($parts[1])) { - return false; - } - $type = $parts[1]->getSubType(); - } - - $viewer = Horde_Mime_Viewer::factory($this->_mimepart, 'message/' . Horde_String::lower($type)); - if ($viewer) { - $viewer->setParams($this->_params); - } - - return $viewer; - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Rfc822.php b/framework/Mime/lib/Horde/Mime/Viewer/Rfc822.php deleted file mode 100644 index eb3ef2fbe..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Rfc822.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Rfc822 extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_mimepart->getContents(), - 'status' => array(), - 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInfo() - { - /* Get the text of the part. Since we need to look for the end of - * the headers by searching for the CRLFCRLF sequence, use - * getCanonicalContents() to make sure we are getting the text with - * CRLF's. */ - $text = $this->_mimepart->getContents(array('canonical' => true)); - if (empty($text)) { - return array(); - } - - /* Search for the end of the header text (CRLFCRLF). */ - $text = substr($text, 0, strpos($text, "\r\n\r\n")); - - /* Get the list of headers now. */ - $headers = Horde_Mime_Headers::parseHeaders($text); - - $header_array = array( - 'date' => _("Date"), - 'from' => _("From"), - 'to' => _("To"), - 'cc' => _("Cc"), - 'bcc' => _("Bcc"), - 'reply-to' => _("Reply-To"), - 'subject' => _("Subject") - ); - $header_output = array(); - - foreach ($header_array as $key => $val) { - $hdr = $headers->getValue($key); - if (!empty($hdr)) { - $header_output[] = '' . $val . ': ' . htmlspecialchars($hdr); - } - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => empty($header_output) ? '' : ('
' . Horde_Text_Filter::filter(implode("
\n", $header_output), 'emails') . '
'), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Richtext.php b/framework/Mime/lib/Horde/Mime/Viewer/Richtext.php deleted file mode 100644 index 48c5fad96..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Richtext.php +++ /dev/null @@ -1,153 +0,0 @@ -" to - * "<", converts CRLFs to SPACE, converts to a newline according to - * local newline convention, removes everything between a command - * and the next balancing command, and removes all other - * formatting commands (all text enclosed in angle brackets). - * - * We implement the following tags: - * , , , , , ,
, - * , , , , , , - * , , , , - * - * The following tags are implemented differently than described in the RFC - * (due to limitations in HTML output): - * - Output as centered, bold text. - * - Output as centered, bold text. - * - Output as paragraph break. - * - * The following tags are NOT implemented: - * , , , , , - * , - * - * Copyright 2004-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. - * - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Richtext extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_toHTML(), - 'status' => array(), - 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() - ) - ); - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Convert richtext to HTML. - * - * @return string The converted HTML string. - */ - protected function _toHTML() - { - $text = trim($this->_mimepart->getContents()); - if ($text == '') { - return array(); - } - - /* We add space at the beginning and end of the string as it will - * make some regular expression checks later much easier (so we - * don't have to worry about start/end of line characters). */ - $text = ' ' . $text . ' '; - - /* Remove everything between tags. */ - $text = preg_replace('/.*<\/comment>/Uis', '', $text); - - /* Remove any unrecognized tags in the text. We don't need - * in $tags since it doesn't do anything anyway. All tags - * have already been removed. */ - $tags = '
'; - $text = strip_tags($text, $tags); - - /* becomes a '<'. CRLF becomes a SPACE. */ - $text = str_ireplace(array('', "\r\n"), array('<', ' '), $text); - - /* We try to protect against bad stuff here. */ - $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset()); - - /* becomes a newline (
); - * becomes a paragraph break (

). */ - $text = str_ireplace(array('<nl>', '<np>'), array('
', '

'), $text); - - /* Now convert the known tags to html. Try to remove any tag - * parameters to stop people from trying to pull a fast one. */ - $replace = array( - '/(? '\1', - '/(? '\1', - '/(? '\1', - '/(? '\1', - '/(? '\1', - '/(? '\1', - '/(? '

\1
', - '/(? '
\1
', - '/(? '
\1
', - '/(? '
\1
', - '/(? '\1', - '/(? '\1', - '/(? '\1', - '/(? '
\1

', - '/(? '
\1

', - '/(? '

\1

', - '/(? '
\1
' - ); - $text = preg_replace(array_keys($replace), array_values($replace), $text); - - /* Now we remove the leading/trailing space we added at the start. */ - $text = substr($text, 1, -1); - - /* Wordwrap. */ - $text = str_replace(array("\t", ' ', "\n "), array(' ', '  ', "\n "), $text); - if ($text[0] == ' ') { - $text = ' ' . substr($text, 1); - } - - return '

' . nl2br($text) . '

'; - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Rpm.php b/framework/Mime/lib/Horde/Mime/Viewer/Rpm.php deleted file mode 100644 index c8d0d48bb..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Rpm.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Rpm extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $ret = $this->_renderInfo(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInfo() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $data = ''; - $tmp_rpm = Horde::getTempFile('horde_rpm'); - - file_put_contents($tmp_rpm, $this->_mimepart->getContents()); - - $fh = popen($this->_conf['location'] . " -qip $tmp_rpm 2>&1", 'r'); - while (($rc = fgets($fh, 8192))) { - $data .= $rc; - } - pclose($fh); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => '
' . htmlentities($data) . '
', - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Rtf.php b/framework/Mime/lib/Horde/Mime/Viewer/Rtf.php deleted file mode 100644 index a515d5594..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Rtf.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @author Duck - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $tmp_rtf = Horde::getTempFile('rtf'); - $tmp_output = Horde::getTempFile('rtf'); - - file_put_contents($tmp_rtf, $this->_mimepart->getContents()); - - exec($this->_conf['location'] . " $tmp_rtf > $tmp_output"); - - if (file_exists($tmp_output)) { - $data = file_get_contents($tmp_output); - } else { - $data = _("Unable to translate this RTF document"); - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Security.php b/framework/Mime/lib/Horde/Mime/Viewer/Security.php deleted file mode 100644 index 6b7ca62ca..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Security.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Security extends Horde_Mime_Viewer_Driver -{ - /** - * 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); - } - return $viewer; - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Simple.php b/framework/Mime/lib/Horde/Mime/Viewer/Simple.php deleted file mode 100644 index a3e9c9e15..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Simple.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Simple extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_mimepart->getContents(), - 'status' => array(), - 'type' => 'text/plain; charset=' . $this->_mimepart->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Smil.php b/framework/Mime/lib/Horde/Mime/Viewer/Smil.php deleted file mode 100644 index df0d42877..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Smil.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Smil extends Horde_Mime_Viewer_Driver -{ - /** - * Handle for the XML parser object. - * - * @var resource - */ - protected $_parser; - - /** - * String buffer to hold the generated content - * - * @var string - */ - protected $_content; - - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => false, - 'embedded' => false, - 'forceinline' => true - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $this->_content = ''; - - /* Create a new parser and set its default properties. */ - $this->_parser = xml_parser_create(); - xml_set_object($this->_parser, $this); - xml_set_element_handler($this->_parser, '_startElement', '_endElement'); - xml_set_character_data_handler($this->_parser, '_defaultHandler'); - xml_parse($this->_parser, $this->_mimepart->getContents(), true); - xml_parser_free($this->_parser); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $this->_content, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * User-defined function callback for start elements. - * - * @param object $parser Handle to the parser instance. - * @param string $name The name of this XML element. - * @param array $attrs List of this element's attributes. - */ - protected function _startElement($parser, $name, $attrs) - { - switch ($name) { - case 'IMG': - if (isset($attrs['SRC'])) { - $this->_content .= ''; - } - break; - } - } - - /** - * User-defined function callback for end elements. - * - * @param object $parser Handle to the parser instance. - * @param string $name The name of this XML element. - */ - protected function _endElement($parser, $name) - { - } - - /** - * User-defined function callback for character data. - * - * @param object $parser Handle to the parser instance. - * @param string $data String of character data. - */ - protected function _defaultHandler($parser, $data) - { - $data = trim($data); - if (!empty($data)) { - $this->_content .= ' ' . htmlspecialchars($data); - } - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Source.php b/framework/Mime/lib/Horde/Mime/Viewer/Source.php deleted file mode 100644 index 7d481ce60..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Source.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Source extends Horde_Mime_Viewer_Driver -{ - /** - * Add line numbers to a block of code. - * - * @param string $code The code to number. - * - * @return string The code with line numbers added. - */ - protected function _lineNumber($code, $linebreak = "\n") - { - $html = array('
'); - for ($l = 1, $lines = substr_count($code, $linebreak) + 1; $l <= $lines; ++$l) { - $html[] = sprintf('%s
', $l, $l, $l); - } - return implode("\n", $html) . '
' . $code . '
'; - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php b/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php deleted file mode 100644 index 35949a0d9..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Srchighlite.php +++ /dev/null @@ -1,185 +0,0 @@ - - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $ret = $this->_renderInline(); - - reset($ret); - $ret[key($ret)]['data'] = '' . - $ret[key($ret)]['data'] . - ''; - - return $ret; - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - /* Create temporary files for Webcpp. */ - $tmpin = Horde::getTempFile('SrcIn'); - $tmpout = Horde::getTempFile('SrcOut', false); - - /* Write the contents of our buffer to the temporary input file. */ - file_put_contents($tmpin, $this->_mimepart->getContents()); - - /* Determine the language from the mime type. */ - $lang = $this->_typeToLang($this->_mimepart->getType()); - - /* Execute Source-Highlite. */ - exec($this->_conf['location'] . " --src-lang $lang --out-format html --input $tmpin --output $tmpout"); - $results = file_get_contents($tmpout); - unlink($tmpout); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $results, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * Attempts to determine what mode to use for the source-highlight - * program from a MIME type. - * - * @param string $type The MIME type. - * - * @return string The mode to use. - */ - protected function _typeToLang($type) - { - switch ($type) { - case 'application/x-javascript': - return 'js'; - - case 'application/x-perl': - return 'perl'; - - case 'application/x-php': - case 'x-extension/phps': - case 'x-extension/php3s': - case 'application/x-httpd-php': - case 'application/x-httpd-php3': - case 'application/x-httpd-phps': - return 'php'; - - case 'application/x-python': - return 'python'; - - case 'application/x-ruby': - return 'ruby'; - - case 'application/x-sh': - case 'application/x-shellscript': - return 'sh'; - - case 'application/x-tcl': - return 'tcl'; - - case 'application/xml': - case 'text/xml': - return 'xml'; - - case 'text/cpp': - case 'text/x-c++src': - case 'text/x-c++hdr': - return 'cpp'; - - case 'text/css': - case 'x-extension/css': - return 'css'; - - case 'text/diff': - case 'text/x-diff': - case 'text/x-patch': - return 'diff'; - - case 'text/x-chdr': - case 'text/x-csrc': - return 'c'; - - case 'text/x-emacs-lisp': - return 'lisp'; - - case 'text/x-fortran': - case 'x-extension/f77': - case 'x-extension/f90': - case 'x-extension/for': - case 'x-extension/ftn': - return 'fortran'; - - case 'text/x-java': - return 'java'; - - case 'text/x-pascal': - return 'pascal'; - - case 'text/x-sql': - return 'sql'; - - case 'text/x-tex': - return 'tex'; - - case 'x-extension/asm': - return 'asm'; - - case 'x-extension/bat': - return 'batch'; - - case 'x-extension/cs': - return 'csharp'; - - case 'x-extension/vb': - case 'x-extension/vba': - return 'vbs'; - } - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Tgz.php b/framework/Mime/lib/Horde/Mime/Viewer/Tgz.php deleted file mode 100644 index dd451a1c3..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Tgz.php +++ /dev/null @@ -1,141 +0,0 @@ - - * @author Michael Cochrane - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * The list of compressed subtypes. - * - * @var array - */ - protected $_gzipSubtypes = array( - 'x-compressed-tar', 'tgz', 'x-tgz', 'gzip', 'x-gzip', - 'x-gzip-compressed', 'x-gtar' - ); - - /** - * 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. - */ - public function __construct($mime_part, $conf = array()) - { - parent::__construct($mime_part, $conf); - - $this->_metadata['compressed'] = in_array($mime_part->getSubType(), $this->_gzipSubtypes); - } - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _render() - { - $ret = $this->_renderInfo(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . - ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInfo() - { - /* Currently, can't do anything without tar file. */ - $subtype = $this->_mimepart->getSubType(); - if (in_array($subtype, array('gzip', 'x-gzip', 'x-gzip-compressed'))) { - return array(); - } - - $contents = $this->_mimepart->getContents(); - - /* Decompress gzipped files. */ - if (in_array($subtype, $this->_gzipSubtypes)) { - $gzip = Horde_Compress::factory('gzip'); - $contents = $gzip->decompress($contents); - } - - /* Obtain the list of files/data in the tar file. */ - $tar = Horde_Compress::factory('tar'); - $tarData = $tar->decompress($contents); - - $charset = $GLOBALS['registry']->getCharset(); - $fileCount = count($tarData); - - $name = $this->_mimepart->getName(true); - if (empty($name)) { - $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)) .
-            "\n\n" .
-            Horde_Text_Filter::filter(
-                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)
-            ) . "\n" .
-            str_repeat('-', 106) . "\n";
-
-        foreach ($tarData as $val) {
-            $text .= Horde_Text_Filter::filter(
-                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)
-            ) . "\n";
-        }
-
-        return array(
-            $this->_mimepart->getMimeId() => array(
-                'data' => nl2br($text . str_repeat('-', 106) . "\n
"), - 'status' => array(), - 'type' => 'text/html; charset=' . $charset - ) - ); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Tnef.php b/framework/Mime/lib/Horde/Mime/Viewer/Tnef.php deleted file mode 100644 index 22a40bf1b..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Tnef.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @author Michael Slusarz - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _render() - { - $ret = $this->_renderInfo(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInfo() - { - $tnef = Horde_Compress::factory('tnef'); - $info = $tnef->decompress($this->_mimepart->getContents()); - - $data = ''; - if (empty($info)) { - $data .= ''; - } else { - $data .= ''; - foreach ($info as $part) { - $data .= ''; - } - } - $data .= '
' . _("MS-TNEF Attachment contained no data.") . '
' . _("Name") . '' . _("Mime Type") . '
' . $part['name'] . '' . $part['type'] . '/' . $part['subtype'] . '
'; - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php b/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php deleted file mode 100644 index 047435edf..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Vcard.php +++ /dev/null @@ -1,424 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => true, - 'raw' => false - ); - - /** - * URL that can be used as a callback for displaying images. - * - * @var Horde_Url - */ - protected $_imageUrl; - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - $ret = $this->_renderInline(); - - if (!empty($ret)) { - reset($ret); - Horde::startBuffer(); - include $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc'; - echo $ret[key($ret)]['data']; - include $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; - $ret[key($ret)]['data'] = Horde::endBuffer(); - } - - return $ret; - } - - /** - * Return the rendered inline version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _renderInline() - { - global $registry, $prefs, $notification; - - $app = false; - $data = $this->_mimepart->getContents(); - $html = ''; - $import_msg = null; - $title = _("vCard"); - - $iCal = new Horde_iCalendar(); - if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { - $notification->push(_("There was an error reading the contact data."), 'horde.error'); - } - - if (Horde_Util::getFormData('import') && - Horde_Util::getFormData('source') && - $registry->hasMethod('contacts/import')) { - $source = Horde_Util::getFormData('source'); - $count = 0; - foreach ($iCal->getComponents() as $c) { - if ($c instanceof Horde_iCalendar_vcard) { - try { - $contacts = $registry->call('contacts/import', array($c, null, $source)); - ++$count; - } catch (Horde_Exception $e) { - $notification->push(_("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error'); - } - } - } - $notification->push(sprintf(ngettext( - "%d contact was successfully added to your address book.", - "%d contacts were successfully added to your address book.", - $count), - $count), - 'horde.success'); - } - - $html .= ''; - - foreach ($iCal->getComponents() as $i => $vc) { - if ($i > 0) { - $html .= ''; - } - - $html .= ''; - - $n = $vc->printableName(); - if (!empty($n)) { - $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')) { - $birthday = new Horde_Date($birthdays[0]); - $html .= $this->_row( - _("Birthday"), - $birthday->strftime($prefs->getValue('date_format'))); - } - - $photos = $vc->getAllAttributes('PHOTO'); - foreach ($photos as $p => $photo) { - if (isset($photo['params']['VALUE']) && - Horde_String::upper($photo['params']['VALUE']) == 'URI') { - $html .= $this->_row(_("Photo"), - '', - false); - } 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'])) { - $html .= $this->_row(_("Photo"), - '', - false); - } elseif ($this->_imageUrl) { - $html .= $this->_row(_("Photo"), - '', - false); - } - } - } - - $labels = $vc->getAllAttributes('LABEL'); - foreach ($labels as $label) { - if (isset($label['params']['TYPE'])) { - if (!is_array($label['params']['TYPE'])) { - $label['params']['TYPE'] = array($label['params']['TYPE']); - } - } else { - $label['params']['TYPE'] = array_keys($label['params']); - } - $types = array(); - foreach ($label['params']['TYPE'] as $type) { - switch(Horde_String::upper($type)) { - case 'HOME': - $types[] = _("Home Address"); - break; - - case 'WORK': - $types[] = _("Work Address"); - break; - - case 'DOM': - $types[] = _("Domestic Address"); - break; - - case 'INTL': - $types[] = _("International Address"); - break; - - case 'POSTAL': - $types[] = _("Postal Address"); - break; - - case 'PARCEL': - $types[] = _("Parcel Address"); - break; - - case 'PREF': - $types[] = _("Preferred Address"); - break; - } - } - if (!count($types)) { - $types = array(_("Address")); - } - $html .= $this->_row(implode('/', $types), $label['value']); - } - - $adrs = $vc->getAllAttributes('ADR'); - foreach ($adrs as $item) { - if (isset($item['params']['TYPE'])) { - if (!is_array($item['params']['TYPE'])) { - $item['params']['TYPE'] = array($item['params']['TYPE']); - } - } else { - $item['params']['TYPE'] = array_keys($item['params']); - } - $address = $item['values']; - $a = array(); - if (isset($address[VCARD_ADR_STREET])) { - $a[] = $address[VCARD_ADR_STREET]; - } - if (isset($address[VCARD_ADR_LOCALITY])) { - $a[] = $address[VCARD_ADR_LOCALITY]; - } - if (isset($address[VCARD_ADR_REGION])) { - $a[] = $address[VCARD_ADR_REGION]; - } - if (isset($address[VCARD_ADR_POSTCODE])) { - $a[] = $address[VCARD_ADR_POSTCODE]; - } - if (isset($address[VCARD_ADR_COUNTRY])) { - $a[] = $address[VCARD_ADR_COUNTRY]; - } - $types = array(); - foreach ($item['params']['TYPE'] as $type) { - switch(Horde_String::upper($type)) { - case 'HOME': - $types[] = _("Home Address"); - break; - - case 'WORK': - $types[] = _("Work Address"); - break; - - case 'DOM': - $types[] = _("Domestic Address"); - break; - - case 'INTL': - $types[] = _("International Address"); - break; - - case 'POSTAL': - $types[] = _("Postal Address"); - break; - - case 'PARCEL': - $types[] = _("Parcel Address"); - break; - - case 'PREF': - $types[] = _("Preferred Address"); - break; - } - } - if (!count($types)) { - $types = array(_("Address")); - } - $html .= $this->_row(implode('/', $types), implode("\n", $a)); - } - - $numbers = $vc->getAllAttributes('TEL'); - - foreach ($numbers as $number) { - if (isset($number['params']['TYPE'])) { - if (!is_array($number['params']['TYPE'])) { - $number['params']['TYPE'] = array($number['params']['TYPE']); - } - foreach ($number['params']['TYPE'] as $type) { - $number['params'][Horde_String::upper($type)] = true; - } - } - if (isset($number['params']['FAX'])) { - $html .= $this->_row(_("Fax"), $number['value']); - } else { - if (isset($number['params']['HOME'])) { - $html .= $this->_row(_("Home Phone"), - $number['value']); - } elseif (isset($number['params']['WORK'])) { - $html .= $this->_row(_("Work Phone"), - $number['value']); - } elseif (isset($number['params']['CELL'])) { - $html .= $this->_row(_("Cell Phone"), - $number['value']); - } else { - $html .= $this->_row(_("Phone"), - $number['value']); - } - } - } - - $addresses = $vc->getAllAttributes('EMAIL'); - $emails = array(); - foreach ($addresses as $address) { - if (isset($address['params']['TYPE'])) { - if (!is_array($address['params']['TYPE'])) { - $address['params']['TYPE'] = array($address['params']['TYPE']); - } - foreach ($address['params']['TYPE'] as $type) { - $address['params'][Horde_String::upper($type)] = true; - } - } - $email = '' . htmlspecialchars($address['value']) . ''; - if (isset($address['params']['PREF'])) { - array_unshift($emails, $email); - } else { - $emails[] = $email; - } - } - - if (count($emails)) { - $html .= $this->_row(_("Email"), implode("\n", $emails), false); - } - - $title = $vc->getAttributeValues('TITLE'); - if (!is_a($title, 'PEAR_Error')) { - $html .= $this->_row(_("Title"), $title[0]); - } - - $role = $vc->getAttributeValues('ROLE'); - if (!is_a($role, 'PEAR_Error')) { - $html .= $this->_row(_("Role"), $role[0]); - } - - $org = $vc->getAttributeValues('ORG'); - if (!is_a($org, 'PEAR_Error')) { - $html .= $this->_row(_("Company"), $org[0]); - if (isset($org[1])) { - $html .= $this->_row(_("Department"), $org[1]); - } - } - - $notes = $vc->getAttributeValues('NOTE'); - if (!is_a($notes, 'PEAR_Error')) { - $html .= $this->_row(_("Notes"), $notes[0]); - } - - $url = $vc->getAttributeValues('URL'); - if (!is_a($url, 'PEAR_Error')) { - $html .= $this->_row( - _("URL"), - '' . htmlspecialchars($url[0]) - . '', - false); - } - } - - if ($registry->hasMethod('contacts/import') && - $registry->hasMethod('contacts/sources')) { - $html .= ''; - } - - $html .= '
 
'; - $fullname = $vc->getAttributeDefault('FN', false); - if ($fullname !== false) { - $html .= $fullname; - } - $html .= '
' - . Horde_Util::formInput(); - foreach ($_GET as $key => $val) { - $html .= ''; - } - - $sources = $registry->call('contacts/sources', array(true)); - if (count($sources) > 1) { - $html .= - '' - . '' - . '' - . ''; - } - - $html .= '
 
'; - - Horde::startBuffer(); - $notification->notify(array('listeners' => 'status')); - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => Horde::endBuffer() . $html, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } - - /** - * TODO - */ - protected function _row($label, $value, $encode = true) - { - if ($encode) { - $label = htmlspecialchars($label); - $value = htmlspecialchars($value); - } - return '' . $label . - '' . nl2br($value) . - "\n"; - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Wordperfect.php b/framework/Mime/lib/Horde/Mime/Viewer/Wordperfect.php deleted file mode 100644 index 485bc3c04..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Wordperfect.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Wordperfect extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => false, - 'inline' => false, - 'raw' => false - ); - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - */ - protected function _render() - { - /* Check to make sure the viewer program exists. */ - if (!isset($this->_conf['location']) || - !file_exists($this->_conf['location'])) { - return array(); - } - - $tmp_wpd = Horde::getTempFile('wpd'); - $tmp_output = Horde::getTempFile('wpd'); - - file_put_contents($tmp_wpd, $this->_mimepart->getContents()); - - exec($this->_conf['location'] . " $tmp_wpd > $tmp_output"); - - if (file_exists($tmp_output)) { - $data = file_get_contents($tmp_output); - } else { - $data = _("Unable to translate this WordPerfect document"); - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => $data, - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Zip.php b/framework/Mime/lib/Horde/Mime/Viewer/Zip.php deleted file mode 100644 index 701dcc57c..000000000 --- a/framework/Mime/lib/Horde/Mime/Viewer/Zip.php +++ /dev/null @@ -1,156 +0,0 @@ - - * @author Michael Cochrane - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Mime - */ -class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Driver -{ - /** - * This driver's display capabilities. - * - * @var array - */ - protected $_capability = array( - 'full' => true, - 'info' => true, - 'inline' => false, - 'raw' => false - ); - - /** - * Metadata for the current viewer/data. - * - * @var array - */ - protected $_metadata = array( - 'compressed' => true, - 'embedded' => false, - 'forceinline' => false - ); - - /** - * A callback function to use in _toHTML(). - * - * @var callback - */ - protected $_callback = null; - - /** - * Return the full rendered version of the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _render() - { - $ret = $this->_toHTML(); - if (!empty($ret)) { - reset($ret); - $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; - } - return $ret; - } - - /** - * Return the rendered information about the Horde_Mime_Part object. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _renderInfo() - { - return $this->_toHTML(); - } - - /** - * Converts the ZIP file to an HTML display. - * - * @return array See Horde_Mime_Viewer_Driver::render(). - * @throws Horde_Exception - */ - protected function _toHTML() - { - $contents = $this->_mimepart->getContents(); - - $zip = Horde_Compress::factory('zip'); - $zipInfo = $zip->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST)); - - $fileCount = count($zipInfo); - - /* Determine maximum file name length. */ - $max_array = array(); - foreach ($zipInfo as $val) { - $max_array[] = strlen($val['name']); - } - $maxlen = empty($max_array) ? 0 : max($max_array); - - $name = $this->_mimepart->getName(true); - if (empty($name)) { - $name = _("unnamed"); - } - - $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ":\n" . - '
' . - Horde_Text_Filter::filter( - _("Archive Name") . ': ' . $name . "\n" . - _("Archive File Size") . ': ' . strlen($contents) . - " bytes\n" . - sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . - "\n\n" . - Horde_String::pad(_("File Name"), $maxlen, ' ', STR_PAD_RIGHT) . - Horde_String::pad(_("Attributes"), 10, ' ', STR_PAD_LEFT) . - Horde_String::pad(_("Size"), 10, ' ', STR_PAD_LEFT) . - Horde_String::pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) . - 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) - ) . str_repeat('-', 59 + $maxlen) . "\n"; - - foreach ($zipInfo as $key => $val) { - $ratio = (empty($val['size'])) - ? 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['method'] = Horde_String::pad($val['method'], 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)); - } - - if (!is_null($this->_callback)) { - $val = call_user_func($this->_callback, $key, $val); - } - - $text .= $val['name'] . $val['attr'] . $val['size'] . - $val['date'] . $val['method'] . $val['ratio'] . - "\n"; - } - - return array( - $this->_mimepart->getMimeId() => array( - 'data' => nl2br($text . str_repeat('-', 59 + $maxlen) . "\n
"), - 'status' => array(), - 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() - ) - ); - } -} diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index 706ecaa39..a500d28fd 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -6,7 +6,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> Mime pear.horde.org Horde MIME Library - The Horde_Mime:: class provides methods for dealing with MIME (RFC 2045) and related e-mail (RFC 822/2822/5322) standards. + Provides methods for dealing with MIME (RFC 2045) and related e-mail (RFC 822/2822/5322) standards. Chuck Hagenbuch @@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Removed Webcpp and Enscript viewers. Source code highlighting is now + * Moved viewer code to horde/Mime_Viewer package. + * Removed Webcpp and Enscript viewers. Source code highlighting is now exclusively handled by the Srchighlight driver. * No need to generate Content-Transfer-Encoding header if part data is 7bit. * Default disposition should be empty by default, not inline (RFC 2183 [2]). @@ -50,52 +51,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -103,7 +58,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -116,13 +70,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - @@ -141,8 +88,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - @@ -157,10 +102,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.5.4 - Core - pear.horde.org - - Exception pear.horde.org @@ -186,27 +127,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> pecl.php.net - Browser - pear.horde.org - - - Compress - pear.horde.org - - - iCalendar - pear.horde.org - - Net_SMTP pear.php.net 1.3.0 - Prefs - pear.horde.org - - Text_Filter pear.horde.org @@ -214,48 +139,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -263,7 +146,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/framework/Mime/test/Horde/Mime/fixtures/url1.html b/framework/Mime/test/Horde/Mime/fixtures/url1.html deleted file mode 100644 index 0c88c1490..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url1.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url2.html b/framework/Mime/test/Horde/Mime/fixtures/url2.html deleted file mode 100644 index 94c45a2ca..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url2.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url3.html b/framework/Mime/test/Horde/Mime/fixtures/url3.html deleted file mode 100644 index 4c7eafed9..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url3.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url4.html b/framework/Mime/test/Horde/Mime/fixtures/url4.html deleted file mode 100644 index 935612578..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url4.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url5.html b/framework/Mime/test/Horde/Mime/fixtures/url5.html deleted file mode 100644 index 89dfbc68d..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url5.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url6.html b/framework/Mime/test/Horde/Mime/fixtures/url6.html deleted file mode 100644 index 73ad9fc17..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url6.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/fixtures/url7.html b/framework/Mime/test/Horde/Mime/fixtures/url7.html deleted file mode 100644 index cb5c80040..000000000 --- a/framework/Mime/test/Horde/Mime/fixtures/url7.html +++ /dev/null @@ -1 +0,0 @@ -link diff --git a/framework/Mime/test/Horde/Mime/url.phpt b/framework/Mime/test/Horde/Mime/url.phpt deleted file mode 100644 index eb08ae29f..000000000 --- a/framework/Mime/test/Horde/Mime/url.phpt +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -Horde_Mime_Viewer_html: URL dereferer tests ---SKIPIF-- -skip: Horde_Mime_Viewer has too many dependencies. ---FILE-- - array( - 'name' => 'www.example.com', - 'port' => 80 - ), - 'use_ssl' => 0 -); -$registry = new Registry(); -$browser = new Browser(); - -for ($i = 1; $i <= 7; $i++) { - $part = new Horde_Mime_Part(); - $part->setType('text/html'); - $part->setContents(file_get_contents($dirname . '/fixtures/url' . $i . '.html')); - $viewer = Horde_Mime_Viewer::factory($part, 'text/html'); - echo $viewer->render(); -} - -?> ---EXPECT-- -link -link -link -link -link -link -link diff --git a/framework/Mime/test/Horde/Mime/viewer_php.phpt b/framework/Mime/test/Horde/Mime/viewer_php.phpt deleted file mode 100644 index 6314c708e..000000000 --- a/framework/Mime/test/Horde/Mime/viewer_php.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -PHP source viewer ---SKIPIF-- -skip: Horde_Mime_Viewer has too many dependencies. ---FILE-- -setType('application/x-php'); -$part->setContents(str_replace('<?php ', '', highlight_string('render(); -?> ---EXPECT-- -
    -
  1. highlight_file(__FILE__);
  2. -
diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php new file mode 100644 index 000000000..cf6323f39 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer.php @@ -0,0 +1,287 @@ + + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +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. + */ + static final public function getIcon($mime_type) + { + $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; + } + } + } + + /* 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']); + } + + if (!is_null($ret)) { + $ret['url'] = Horde_Themes::img('mime/' . $ret['url'], $app); + } + + return $ret; + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Audio.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Audio.php new file mode 100644 index 000000000..5d9da64e7 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Audio.php @@ -0,0 +1,45 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Audio extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_mimepart->getContents(), + 'status' => array(), + 'type' => $this->_mimepart->getType() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php new file mode 100644 index 000000000..d9e1a0b62 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Css.php @@ -0,0 +1,130 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Css extends Horde_Mime_Viewer_Source +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * Attribute preg patterns. + * + * @var array + */ + protected $_attrPatterns = array( + // Attributes + '!([-\w]+\s*):!s' => '\\1:', + // Values + '!:(\s*)(.+?)(\s*;)!s' => ':\\1\\2\\3', + // URLs + '!(url\([\'"]?)(.*?)([\'"]?\))!s' => '\\1\\2\\3', + // Colors + '!(#[[:xdigit:]]{3,6})!s' => '\\1', + // Parentheses + '!({|})!s' => '\\1', + // Unity + '!(em|px|%)\b!s' => '\\1' + ); + + /** + * Handles preg patterns. + * + * @var array + */ + protected $_handlesPatterns = array( + // HTML Tags + '!\b(body|h\d|a|span|div|acronym|small|strong|em|pre|ul|ol|li|p)\b!s' => '\\1\\2', + // IDs + '!(#[-\w]+)!s' => '\\1', + // Class + '!(\.[-\w]+)\b!s' => '\\1', + // METAs + '!(:link|:visited|:hover|:active|:first-letter)!s' => '\\1' + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + 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 the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + $css = preg_replace_callback('!(}|\*/).*?({|/\*)!s', array($this, '_handles'), htmlspecialchars($this->_mimepart->getContents(), ENT_NOQUOTES)); + $css = preg_replace_callback('!{[^}]*}!s', array($this, '_attributes'), $css); + $css = preg_replace_callback('!/\*.*?\*/!s', array($this, '_comments'), $css); + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_lineNumber(trim($css)), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * TODO + */ + protected function _comments($matches) + { + return '' . + preg_replace('!(http://[/\w-.]+)!s', '\\1', $matches[0]) . + ''; + } + + /** + * TODO + */ + protected function _attributes($matches) + { + return preg_replace(array_keys($this->_attrPatterns), array_values($this->_attrPatterns), $matches[0]); + } + + /** + * TODO + */ + protected function _handles($matches) + { + return preg_replace(array_keys($this->_handlesPatterns), array_values($this->_handlesPatterns), $matches[0]); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php new file mode 100644 index 000000000..193163a76 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Deb.php @@ -0,0 +1,87 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Deb extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInfo(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInfo() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $tmp_deb = Horde::getTempFile('horde_deb'); + + file_put_contents($tmp_deb, $this->_mimepart->getContents()); + + $fh = popen($this->_conf['location'] . " -f $tmp_deb 2>&1", 'r'); + while (($rc = fgets($fh, 8192))) { + $data .= $rc; + } + pclose($fh); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => '
' . htmlspecialchars($data) . '
', + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Default.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Default.php new file mode 100644 index 000000000..6c2c01dd6 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Default.php @@ -0,0 +1,19 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Default extends Horde_Mime_Viewer_Driver +{ +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Driver.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Driver.php new file mode 100644 index 000000000..6b2c17aef --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Driver.php @@ -0,0 +1,353 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Driver +{ + /** + * Viewer configuration. + * + * @var array + */ + protected $_conf = array(); + + /** + * The Horde_Mime_Part object to render. + * + * @var Horde_Mime_Part + */ + protected $_mimepart = null; + + /** + * Viewer parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => false, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + // Is the part *data* compressed (not the rendered data)? + 'compressed' => false, + // Does this part contain emebedded MIME data? + 'embedded' => false, + // Force inline display of this part? + 'forceinline' => false + ); + + /** + * 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. + */ + public function __construct($mime_part, $conf = array()) + { + $this->_mimepart = $mime_part; + $this->_conf = $conf; + } + + /** + * Sets the Horde_Mime_Part object for the class. + * + * @param Horde_Mime_Part $mime_part The object with the information to + * be rendered. + */ + public function setMIMEPart($mime_part) + { + $this->_mimepart = $mime_part; + } + + /** + * Set parameters for use with this object. + * + * @param array $params An array of params to add to the internal + * params list. + */ + public function setParams($params = array()) + { + $this->_params = array_merge($this->_params, $params); + } + + /** + * Return the rendered version of the Horde_Mime_Part object. + * + * @param string $mode The mode: + *
+     * 'full' - A full representation of the MIME part, for use in a view
+     *          where the output to the browser can be set to the value
+     *          returned in 'type'. This mode should only return a single
+     *          MIME ID entry for viewing and should not return any status
+     *          information.
+     * 'inline' - A representation of the MIME part that can be viewed inline
+     *            on a text/html page that may contain other HTML elements.
+     * 'info' - A representation of the MIME part that can be viewed inline
+     *          on an text/html page that may contain other HTML elements.
+     *          This view is not a full view, but rather a condensed view of
+     *          the contents of the MIME part. This view is intended to be
+     *          displayed to the user with the intention that this MIME part's
+     *          subparts may also independently be viewed inline.
+     * 'raw' - The raw data of the MIME part, generally useful for downloading
+     *         a part. This view exists in case this raw data needs to be
+     *         altered in any way.
+     * 
+ * + * @return array An array. The keys are the MIME parts that were handled + * by the driver. The values are either null (which + * indicates the driver is recommending that this + * particular MIME ID should not be displayed) or an array + * with the following keys: + *
+     * 'data' - (string) The rendered data.
+     * 'status' - (array) An array of status information to be displayed to
+     *            the user.  Consists of arrays with the following keys:
+     *            'class' - (string) The class to use for display.
+     *            'img' - (string) An image to display.
+     *            'text' - (array) The text to display.
+     * 'type' - (string) The MIME type of the rendered data.
+     * 
+ */ + public function render($mode) + { + switch ($mode) { + case 'full': + try { + return $this->_render(); + } catch (Horde_Exception $e) { + $error = $e; + } + break; + + case 'inline': + try { + return $this->_renderInline(); + } catch (Horde_Exception $e) { + $error = $e; + } + + case 'info': + try { + return $this->_renderInfo(); + } catch (Horde_Exception $e) { + $error = $e; + } + + case 'raw': + try { + return $this->_renderRaw(); + } catch (Horde_Exception $e) { + $error = $e; + } + } + + // TODO: Error handling + } + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->render('full') + : array(); + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInline() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->render('inline') + : array(); + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInfo() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->render('info') + : array(); + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderRaw() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->render('raw') + : array(); + } + + /** + * Can this driver render the the data? + * + * @param string $mode The mode. Either 'full', 'inline', 'info', or + * 'raw'. + * + * @return boolean True if the driver can render the data for the given + * view. + */ + public function canRender($mode) + { + $viewer = $this->_getViewer(); + if ($viewer) { + return $viewer->canRender($mode); + } + + switch ($mode) { + case 'full': + case 'info': + case 'raw': + return $this->_capability[$mode]; + + case 'inline': + return $this->getConfigParam('inline') && + ($this->_metadata['forceinline'] || + ($this->_capability['inline'] && + ($this->_mimepart->getDisposition() != 'attachment'))); + + default: + return false; + } + } + + /** + * Does this MIME part possibly contain embedded MIME parts? + * + * @return boolean True if this driver supports parsing embedded MIME + * parts. + */ + public function embeddedMimeParts() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->embeddedMimeParts() + : $this->_metadata['embedded']; + } + + /** + * If this MIME part can contain embedded MIME part(s), and those part(s) + * exist, return a representation of that data. + * + * @return mixed A Horde_Mime_Part object representing the embedded data. + * Returns null if no embedded MIME part(s) exist. + */ + public function getEmbeddedMimeParts() + { + $viewer = $this->_getViewer(); + return $viewer + ? $viewer->getEmbeddedMimeParts() + : $this->_getEmbeddedMimeParts(); + } + + /** + * If this MIME part can contain embedded MIME part(s), and those part(s) + * exist, return a representation of that data. + * + * @return mixed A Horde_Mime_Part object representing the embedded data. + * Returns null if no embedded MIME part(s) exist. + */ + protected function _getEmbeddedMimeParts() + { + return null; + } + + /** + * Return a configuration parameter for the current viewer. + * + * @param string $param The parameter name. + * + * @return mixed The value of the parameter; returns null if the + * parameter doesn't exist. + */ + public function getConfigParam($param) + { + return isset($this->_conf[$param]) ? $this->_conf[$param] : null; + } + + /** + * Returns the driver name for the current object. + * + * @return string The driver name. + */ + public function getDriver() + { + return $this->_conf['_driver']; + } + + /** + * Returns metadata information on the viewer/data. + * + * @param string $data The metadata key. + * + * @return mixed The requested information, or null if the key doesn't + * exist. + */ + public function getMetadata($data) + { + return isset($this->_metadata[$data]) + ? $this->_metadata[$data] + : null; + } + + /** + * Return the underlying MIME Viewer for this part. + * + * @return mixed A Horde_Mime_Viewer object, or false if not found. + */ + protected function _getViewer() + { + return false; + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php new file mode 100644 index 000000000..f0375e52f --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Enriched.php @@ -0,0 +1,202 @@ + command and the next balancing + * removes all other formatting commands (all text enclosed + * in angle brackets), and outside of environments converts + * any series of n CRLFs to n-1 CRLFs, and converts any lone CRLF + * pairs to SPACE. + * + * We don't qualify as we don't currently track the + * environment, that is we do CRLF conversion even if is + * specified in the text, but we're close at least. + * + * Copyright 2001-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. + * + * @author Eric Rostetter + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Enriched extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => '' . $this->_toHTML(false) . '', + 'status' => array(), + 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() + ) + ); + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => Horde_String::convertCharset($this->_toHTML(true), $this->_mimepart->getCharset()), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Convert the enriched text to HTML. + * + * @param string $inline Rendered inline? + * + * @return string The HTML-ified version of the MIME part contents. + */ + protected function _toHTML($inline) + { + $text = trim($this->_mimepart->getContents()); + if (!strlen($text)) { + return array(); + } + + // We add space at the beginning and end of the string as it will + // make some regular expression checks later much easier (so we + // don't have to worry about start/end of line characters) + $text = ' ' . $text . ' '; + + // We need to preserve << tags, so map them to ascii 1 or ascii 255 + // We make the assumption here that there would never be an ascii + // 1 in an email, which may not be valid, but seems reasonable... + // ascii 255 would work if for some reason you don't like ascii 1 + // ascii 0 does NOT seem to work for this, though I'm not sure why + $text = str_replace('<<', chr(1), $text); + + // Remove any unrecognized tags in the text (via RFC minimal specs) + // any tags we just don't want to implement can also be removed here + // Note that this will remove any html links, but this is intended + $implementedTags = '' . + '
' . + ''; + // $unImplementedTags = ''; + $text = strip_tags($text, $implementedTags); + + // restore the << tags as < tags now... + $text = str_replace(chr(1), '<<', $text); + // $text = str_replace(chr(255), '<', $text); + + $replace = array( + // Get color parameters into a more useable format. + '/([\da-fA-F]+),([\da-fA-F]+),([\da-fA-F]+)<\/param>/Uis' => '', + '/(red|blue|green|yellow|cyan|magenta|black|white)<\/param>/Uis' => '', + + // Get font family parameters into a more useable format. + '/(\w+)<\/param>/Uis' => '', + + /* Just remove any remaining parameters -- we won't use them. + * Any tags with parameters that we want to implement will have + * come before this. Someday we hope to use these tags (e.g. for + * tags). */ + '/.*<\/param>/Uis' => '', + + /* Single line breaks become spaces, double line breaks are a + * real break. This needs to do tracking to be compliant + * but we don't want to deal with state at this time, so we fake + * it some day we should rewrite this to handle + * correctly. */ + '/([^\n])\r\n([^\r])/' => '\1 \2', + '/(\r\n)\r\n/' => '\1' + ); + $text = preg_replace(array_keys($replace), array_values($replace), $text); + + // We try to protect against bad stuff here. + $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset()); + + // Now convert the known tags to html. Try to remove any tag + // parameters to stop people from trying to pull a fast one + $replace = array( + '/(? '\1', + '/(? '\1', + '/(? '\1' + ); + $text = preg_replace(array_keys($replace), array_values($replace), $text); + + $text = preg_replace_callback('/(? '\2', + '/(? '\1', + '/(? '\2', + '/(? '', + '/(? '', + '/(? '', + '/(? '', + '/(? '\1', + '/(? '
\1
', + '/(? '
\1
', + '/(? '
\1
', + '/(? '
\1
', + '/(? '
\1
', + '/(? '
\1
' + ); + $text = preg_replace(array_keys($replace), array_values($replace), $text); + + // Replace << with < now (from translated HTML form). + $text = str_replace('<<', '<', $text); + + // Now we remove the leading/trailing space we added at the + // start. + $text = preg_replace('/^ (.*) $/s', '\1', $text); + + // Make URLs clickable. + $text = Horde_Text_Filter::filter($text, 'linkurls', array( + 'callback' => 'Horde::externalUrl' + )); + + /* Wordwrap -- note this could impact on our above RFC compliance *IF* + * we honored nofill tags (which we don't yet). */ + $text = str_replace(array("\t", ' ', "\n "), array(' ', '  ', "\n "), $text); + + if ($text[0] == ' ') { + $text = ' ' . substr($text, 1); + } + + return '

' . nl2br($text) . '

'; + } + + /** + * TODO + */ + public function colorize($colors) + { + for ($i = 1; $i < 4; $i++) { + $colors[$i] = sprintf('%02X', round(hexdec($colors[$i]) / 255)); + } + return '' . $colors[4] . ''; + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php new file mode 100644 index 000000000..88bd2a41b --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Html.php @@ -0,0 +1,287 @@ + + * @author Jon Parise + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * The CSS used to display the phishing warning. + * + * @var string + */ + protected $_phishCss = 'padding: 1px;margin-bottom: 3px;font-size: 90%;border: 1px solid #800;background: #e81222;color: #fff;width: 100%;'; + + /** + * Phishing status of last call to _phishingCheck(). + * + * @var boolean + */ + protected $_phishWarn = false; + + /** + * Temp array for storing data when parsing the HTML document. + * + * @var array + */ + protected $_tmp = array(); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $html = $this->_cleanHTML($this->_mimepart->getContents(), array('inline' => false)); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $html['html'], + 'status' => array(), + 'type' => $this->_mimepart->getType(true) + ) + ); + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + $html = $this->_cleanHTML($this->_mimepart->getContents(), array('inline' => true)); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => Horde_String::convertCharset($html['data'], $this->_mimepart->getCharset()), + 'status' => $html['status'], + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Filters active content, dereferences external links, detects phishing, + * etc. + * + * @todo Use IP checks from + * http://lxr.mozilla.org/mailnews/source/mail/base/content/phishingDetector.js. + * + * @param string $data The HTML data. + * @param array $options Additional options: + *
+     * 'charset' - (string) The charset of $data.
+     *             DEFAULT: The base part charset.
+     * 'inline' - (boolean) Are we viewing inline?
+     *            DEFAULT: false
+     * 'noprefetch' - (boolean) Disable DNS prefetching?
+     *                DEFAULT: false
+     * 'phishing' - (boolean) Do phishing highlighting even if not viewing
+     *              inline.
+     *              DEFAULT: false.
+     * 
+ * + * @return string The cleaned HTML string. + */ + protected function _cleanHTML($data, $options = array()) + { + global $browser; + + $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( + array( + 'charset' => isset($options['charset']) ? $options['charset'] : $this->_mimepart->getCharset() + ), + array( + 'noprefetch' => !empty($options['noprefetch']), + 'return_dom' => true, + 'strip_styles' => (!empty($options['inline']) || $strip_style_attributes), + 'strip_style_attributes' => $strip_style_attributes + ) + )); + + $this->_tmp = array( + 'base' => null, + 'inline' => !empty($options['inline']), + 'phish' => ((!empty($options['inline']) || !empty($options['phishing'])) && $this->getConfigParam('phishing_check')) + ); + $this->_phishWarn = false; + + $this->_node($data, $data); + + return $data->saveHTML(); + } + + /** + * Process DOM node. + * + * @param DOMDocument $doc Document node. + * @param DOMNode $node Node. + */ + protected function _node($doc, $node) + { + if ($node->hasChildNodes()) { + foreach ($node->childNodes as $child) { + if ($child instanceof DOMElement) { + switch (strtolower($child->tagName)) { + case 'base': + /* Deal with tags in the HTML, since they will + * screw up our own relative paths. */ + if ($this->_tmp['inline'] && + $child->hasAttribute('href')) { + $base = $child->getAttribute('href'); + if (substr($base, -1) != '/') { + $base .= '/'; + } + + $this->_tmp['base'] = $base; + $child->removeAttribute('href'); + } + break; + } + + foreach ($child->attributes as $val) { + /* Attempt to fix paths that were relying on a + * tag. */ + if (!is_null($this->_tmp['base']) && + in_array($val->name, array('href', 'src'))) { + $child->setAttribute($val->name, $this->_tmp['base'] . ltrim($val->value, '/')); + } + + if ($val->name == 'href') { + if ($this->_tmp['phish'] && + $this->_phishingCheck($val->value, $child->textContent)) { + $this->_phishWarn = true; + $child->setAttribute('style', ($child->hasAttribute('style') ? rtrim($child->getAttribute('style'), '; ') . ';' : '') . $this->_phishCss); + } + + /* Try to derefer all external references. */ + $child->setAttribute('href', Horde::externalUrl($val->value)); + } + } + } + + $this->_nodeCallback($doc, $child); + $this->_node($doc, $child); + } + } + } + + /** + * Process DOM node (callback). + * + * @param DOMDocument $doc Document node. + * @param DOMNode $node Node. + */ + protected function _nodeCallback($doc, $node) + { + } + + /** + * Check for phishing exploits. + * + * @param string $href The HREF value. + * @param string $text The text value of the link. + * + * @return boolean True if phishing is detected. + */ + protected function _phishingCheck($href, $text) + { + /* For phishing, we are checking whether the displayable text URL is + * the same as the HREF URL. If we can't parse the text URL, then we + * can't do phishing checks. */ + $text_url = @parse_url($text); + if (!$text_url) { + return false; + } + + $href_url = parse_url($href); + + /* Only concern ourselves with HTTP and FTP links. */ + if (!isset($href_url['scheme']) || + !in_array($href_url['scheme'], array('ftp', 'http', 'https'))) { + return false; + } + + /* Check for case where text is just the domain name. */ + if (!isset($text_url['host'])) { + if (!isset($text_url['path']) || + !preg_match("/^[^\.\s]+(?:\.[^\.\s]+)+$/", $text_url['path'])) { + return false; + } + + $text_url['host'] = $text_url['path']; + } + + /* If port exists on link, and text link has scheme or port defined, + * do extra checks: + * 1. If port exists on text link, and doesn't match, this is + * phishing. + * 2. If port doesn't exist on text link, and port does not match + * defaults, this is phishing. */ + if (isset($href_url['port']) && + (isset($text_url['scheme']) || isset($text_url['port']))) { + if (!isset($text_url['port'])) { + switch ($text_url['scheme']) { + case 'ftp': + $text_url['port'] = 25; + break; + + case 'http': + $text_url['port'] = 80; + break; + + case 'https': + $text_url['port'] = 443; + break; + } + } + + if ($href_url['port'] != $text_url['port']) { + return false; + } + } + + if (strcasecmp($href_url['host'], $text_url['host']) === 0) { + return false; + } + + /* Don't consider the link a phishing link if the domain is the same + * on both links (e.g. adtracking.example.com & www.example.com). */ + $host1 = explode('.', $href_url['host']); + $host2 = explode('.', $text_url['host']); + + return (strcasecmp(implode('.', array_slice($host1, -2)), implode('.', array_slice($host2, -2))) !== 0); + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php new file mode 100644 index 000000000..154ffb734 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Images.php @@ -0,0 +1,84 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Images extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * 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. + */ + public function __construct($mime_part, $conf = array()) + { + parent::__construct($mime_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')); + } + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_mimepart->getContents(), + 'status' => array(), + 'type' => $this->_getType() + ) + ); + } + + /** + * Return the content-type to use for the image. + * + * @return string The content-type of the image. + */ + protected function _getType() + { + $type = $this->_mimepart->getType(); + + switch ($type) { + case 'image/pjpeg': + /* image/jpeg and image/pjpeg *appear* to be the same entity, but + * Mozilla (for one) don't seem to want to accept the latter. */ + return 'image/jpeg'; + + case 'image/x-png': + /* image/x-png == image/png. */ + return 'image/png'; + + default: + return $type; + } + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php new file mode 100644 index 000000000..5257f1463 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msexcel.php @@ -0,0 +1,59 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Msexcel extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $tmp_xls = Horde::getTempFile('horde_msexcel'); + $tmp_out = Horde::getTempFile('horde_msexcel'); + + file_put_contents($tmp_xls, $this->_mimepart->getContents()); + $args = ' -E Gnumeric_Excel:excel_dsf -T Gnumeric_html:html40 ' . $tmp_xls . ' ' . $tmp_out; + + exec($this->_conf['location'] . $args); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => file_get_contents($tmp_out), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php new file mode 100644 index 000000000..7d1e381e4 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Mspowerpoint.php @@ -0,0 +1,62 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Mspowerpoint extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $data = ''; + $tmp_ppt = Horde::getTempFile('horde_mspowerpoint'); + + file_put_contents($tmp_ppt, $this->_mimepart->getContents()); + + $fh = popen($this->_conf['location'] . " $tmp_ppt 2>&1", 'r'); + while (($rc = fgets($fh, 8192))) { + $data .= $rc; + } + pclose($fh); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php new file mode 100644 index 000000000..1c67f2f72 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Msword.php @@ -0,0 +1,68 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Msword extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $tmp_word = Horde::getTempFile('msword'); + $tmp_output = Horde::getTempFile('msword'); + $tmp_file = str_replace(Horde::getTempDir() . '/', '', $tmp_output); + + file_put_contents($tmp_word, $this->_mimepart->getContents()); + $args = ' --to=html --to-name=' . $tmp_output . ' ' . $tmp_word; + + exec($this->_conf['location'] . $args); + + if (file_exists($tmp_output)) { + $data = file_get_contents($tmp_output); + $type = 'text/html'; + } else { + $data = _("Unable to translate this Word document"); + $type = 'text/plain'; + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => $type . '; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php new file mode 100644 index 000000000..9f780ac61 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo.php @@ -0,0 +1,130 @@ + + * @author Jan Schneider + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Ooo extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + /* At this point assume that the document takes advantage of ZIP + * compression. */ + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + $has_xslt = Horde_Util::extensionExists('xslt'); + $has_ssfile = function_exists('domxml_xslt_stylesheet_file'); + if (($use_xslt = $has_xslt || $has_ssfile)) { + $tmpdir = Horde_Util::createTempDir(true); + } + + $fnames = array('content.xml', 'styles.xml', 'meta.xml'); + $tags = array( + 'text:p' => 'p', + 'table:table' => 'table border="0" cellspacing="1" cellpadding="0" ', + 'table:table-row' => 'tr bgcolor="#cccccc"', + 'table:table-cell' => 'td', + 'table:number-columns-spanned=' => 'colspan=' + ); + + $zip = Horde_Compress::factory('zip'); + $list = $zip->decompress($this->_mimepart->getContents(), array('action' => Horde_Compress_Zip::ZIP_LIST)); + + foreach ($list as $key => $file) { + if (in_array($file['name'], $fnames)) { + $content = $zip->decompress($this->_mimepart->getContents(), array( + 'action' => Horde_Compress_Zip::ZIP_DATA, + 'info' => $list, + 'key' => $key + )); + + if ($use_xslt) { + file_put_contents($tmpdir . $file['name'], $content); + } elseif ($file['name'] == 'content.xml') { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => str_replace(array_keys($tags), array_values($tags), $content), + 'status' => array(), + 'type' => 'text/html; charset=UTF-8' + ) + ); + } + } + } + + if (!Horde_Util::extensionExists('xslt')) { + return array(); + } + + $xsl_file = dirname(__FILE__) . '/Ooo/main_html.xsl'; + + if ($has_ssfile) { + /* Use DOMXML */ + $xslt = domxml_xslt_stylesheet_file($xsl_file); + $dom = domxml_open_file($tmpdir . 'content.xml'); + $result = @$xslt->process($dom, array( + 'metaFileURL' => $tmpdir . 'meta.xml', + 'stylesFileURL' => $tmpdir . 'styles.xml', + 'disableJava' => true) + ); + $result = $xslt->result_dump_mem($result); + } else { + // Use XSLT + $xslt = xslt_create(); + $result = @xslt_process($xslt, $tmpdir . 'content.xml', $xsl_file, null, null, array( + 'metaFileURL' => $tmpdir . 'meta.xml', + 'stylesFileURL' => $tmpdir . 'styles.xml', + 'disableJava' => true) + ); + if (!$result) { + $result = xslt_error($xslt); + } + xslt_free($xslt); + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $result, + 'status' => array(), + 'type' => 'text/html; charset=UTF-8' + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/common.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/common.xsl new file mode 100644 index 000000000..943a5b995 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/common.xsl @@ -0,0 +1,1165 @@ + + + + + + + + + + + + + + + + + + = + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + height: ; + + + width: ; + + + height: ; + width: ; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + margin-left:; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +     + + + + + + + + + + + + + + + + + + + + + + + +     + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +     + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + * + + + + + + + + + + + + * + * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/global_document.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/global_document.xsl new file mode 100644 index 000000000..fc4579ef3 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/global_document.xsl @@ -0,0 +1,1674 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Matching child document header No. + absolute-chapter-level: + encodedTitle: + globalDocumentRefToCurrentFile: + *** + + + + + + + + + + + + + + + + + + + + + + + + + Matching global document header No. + absolute-chapter-level: + encodedTitle: + contentTableURL: + *** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Creation of global document helper variable for the content table.... + + + + + + + + + + + + + + + + + Finished the Creation of global document helper variable for the content table! + + + + + Creation of global document helper variable for the child documents.... + + + + + + Finished the Creation of global document helper variable for the child documents! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # + level: + title: + encoded-title: + file-url: + header-no: + ** + + ** + ** + + + childrenHeadings/heading-count: + + # + title: + ** + + + + + + + + + + + + + + + + + + Creating global document variable for chapter relations.... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Finished global document variable for chapter relations! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *** new heading + currentChapterID: + currentChapterTitle: + currentChapterID: + currentHeadingNo: + headingTitle: + headingLevel: + headingNo: + newChildURL: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + only a heading, but not a chapter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + All child documents have been walked through without finding the chapter name! + childrenHeadings/heading-count: + currentHeadingNo: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Parsing the global document... + + + + + + + + Parsing the child documents... + + + + + + + + + + + + + Starting the child transformations... + + + + + + Contentable data exists as global data! + + + No Contentable global data exists! + + + + + + + + + + + + + Java method transformChildren to transform all children of a global document could not be found. Be sure to use the XT processor. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Previous document + + + | + + + + + + + + + + + + + + + + + + # + + + + + + Content Table + + + + + + | + + + + + + + + + + + + + + + + + + + + + Next document + + + ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + **** THE HEADING VARIABLE **** + content-table-url: + + + **** new heading: + content-table-id: + child-document-no: + file-url: + out-file-url: + level: + title: + encoded-title: + absolute-chapter-level: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + width: + + + + + + + + + + + + + + + + + + + + + + + + + + + + align: right + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/main_html.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/main_html.xsl new file mode 100644 index 000000000..443182a3e --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/main_html.xsl @@ -0,0 +1,462 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CSS helper variable will be created.... + + CSS variable ready, header will be created.... + + + CSS header creation finished! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Creating the inline styles.... + + + + + Time for instantiating style variable: ms + + + + + + Creating the inline styles.... + + + + + Time for instantiating style variable: ms + + + + + + + + + + + Parameter dpi: + Parameter metaFileURL: + Parameter stylesFileURL: + Parameter absoluteSourceDirRef: + Parameter precedingChapterLevel1 : + Parameter precedingChapterLevel2 : + Parameter precedingChapterLevel3 : + Parameter precedingChapterLevel4 : + Parameter precedingChapterLevel5 : + Parameter precedingChapterLevel6 : + Parameter precedingChapterLevel7 : + Parameter precedingChapterLevel8 : + Parameter precedingChapterLevel9 : + Parameter precedingChapterLevel10: + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/palm.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/palm.xsl new file mode 100644 index 000000000..212edb167 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/palm.xsl @@ -0,0 +1,404 @@ + + + + + + + + + + + + + PalmComputingPlatform + true + + + HandheldFriendly + true + + + HistoryListText + Dateimanager : &date &time + + + description + StarPortal + + + keywords + starportal, staroffice, software + + + Content-Type + text/html; charset=iso-8859-1 + + + + + + + + + + + + + + + + + left + + + right + + + center + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + left + + + right + + + center + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #000000 + + + #FFFFFF + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #000000 + + + #FFFFFF + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_header.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_header.xsl new file mode 100644 index 000000000..eeb0c204a --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_header.xsl @@ -0,0 +1,379 @@ + + + + + + + + + + + + + The CSS style header method for setting styles + + + text/css + + + + + + + + + + + + + + + + + + + + + + + + + + + // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *.OOo_defaults + + + , + + + + + , + + + + { + margin-top:0cm; margin-bottom:0cm; } + + + + + + + + + + + + + + + + + + + + + + , + + + + + , + + + + + + + + + + + + + + { + + + } + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl new file mode 100644 index 000000000..19159958c --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_inlined.xsl @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl new file mode 100644 index 000000000..a9a858dc0 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/style_mapping.xsl @@ -0,0 +1,660 @@ + + + + + + + + + + + + + + + + + + + + + + + + float: right; + + + float: left; + + + + + + + + align: left; + + + align: right; + + + align: center; + + + + + + + + padding: + + ; + + + + + + + + + border-width:; + border-style:; + border-color:; + + + border-width:; + border-style:; + border-color:; + + + border-width:; + border-style:; + border-color:; + + + + + border-top: ; + + + border-bottom: ; + + + border-left: ; + + + border-right: ; + + + + + + width:; + + + width:; + + + + + + + + height:; + + + height:; + + + + + + + + width:; + + + width:; + + + + + + :; + + + font-family: + + + ; + + font-style:italic; + + + font-weight:bold; + + + + :; + + + :; + + + :; + + + :; + + + :; + + + :; + + + :; + + + :; + + + :; + + + + + + text-align:left ! important; + + + text-align:right ! important; + + + text-align: ! important; + + + + + :; + + + background-color:; + + + background-color:; + + + background-image:url(); + + + background-repeat:repeat; + + + background-repeat:no-repeat; + + + + + + :; + + + + text-decoration:line-through; + + + + + text-decoration:underline; + + + + + vertical-align:sub; + + + vertical-align:sup; + + + + + + + + + + + + + + + + + + + italic, + + + + + + + bold, + + + + + + underline, + + + + + + + align:left, + + + align:right, + + + align:center, + + + + + + + strike, + + + + + size::size, + + + + + + + color:#FFFFFF, + + + color:#000000, + + + + + + + + size::size, + + + + + + width::width, + + + width::width; + + + + + + + + height::height; + + + height::height; + + + + + + + + width::width; + + + width::width; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table.xsl new file mode 100644 index 000000000..36339ed73 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table.xsl @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + left + + + right + + + center + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + maxRowLength: + + numberOfHiddenColumns: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + #000000 + 2 + 0 + page-break-inside:avoid + + + + + + + + + + + + + + + + Time for checking BorderStyle: ms + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl new file mode 100644 index 000000000..4671ea96f --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_cells.xsl @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + +--------------> table:table-cell has been entered with node value: + table:number-columns-repeated: -- + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NEW VALUE: column-position: -- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +++++++++ starting cell writing +++++++++ + number-columns-repeated: -- + maxRowLength: -- + column-position: -- + + + + + + + + + + + + +++++++++ cell repetition +++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WriteTest -> If nothing between '-' write cell -- + + + + + TABLE COLUMN is hidden! + + + + + + + + TABLE COLUMN is hidden! + + + + + + + + + + + th + + + td + + + + + + + + + + + +*****************************************'' element has been added! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text-align:right; + text-align:left; + + + + + + + + + + + + + + + + + + + + text-align:right; + + + text-align:left; + + + + + + + + + +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text-align:right; + + + text-align:left; + + + + + +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + ; + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl new file mode 100644 index 000000000..a9a907ff8 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_columns.xsl @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DebugInformation: For each 'column-style-entry' of the 'allColumnStyleEntries' variable the style-name is given out. + In case of 'column-hidden-flag' attribute the text 'column is hidden' is given out. + + + + + column is hidden + + + + = + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl new file mode 100644 index 000000000..6f7d17d62 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Ooo/table_rows.xsl @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*************************'tr' element has been added! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Pdf.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Pdf.php new file mode 100644 index 000000000..8ce2e9d6b --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Pdf.php @@ -0,0 +1,46 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_mimepart->getContents(), + 'status' => array(), + 'type' => 'application/pdf' + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php new file mode 100644 index 000000000..d1738f98e --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Php.php @@ -0,0 +1,74 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Php extends Horde_Mime_Viewer_Source +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + 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 the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + $code = $this->_mimepart->getContents(); + if (strpos($code, ''), array('', "\n"), $text)); + $text = $this->_lineNumber($text); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $text, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php new file mode 100644 index 000000000..bbe89c976 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Plain.php @@ -0,0 +1,98 @@ + + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $text = $this->_mimepart->getContents(); + $charset = $this->_mimepart->getCharset(); + + /* Check for 'flowed' text data. */ + if ($this->_mimepart->getContentTypeParameter('format') == 'flowed') { + $text = $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')); + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => '' . Horde_Text_Filter::filter($text, 'text2html', array( + 'charset' => $charset, + 'parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL + )) . '', + 'status' => array(), + 'type' => 'text/html; charset=' . $charset + ) + ); + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()); + + /* Check for 'flowed' text data. */ + $data = ($this->_mimepart->getContentTypeParameter('format') == 'flowed') + ? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')) + : $text; + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Format flowed text for HTML output. + * + * @param string $text The text to format. + * @param boolean $delsp Was text created with DelSp formatting? + * + * @return string The formatted text. + */ + protected function _formatFlowed($text, $delsp = null) + { + $flowed = new Horde_Text_Flowed($this->_mimepart->replaceEOL($text, "\n"), $this->_mimepart->getCharset()); + $flowed->setMaxLength(0); + if (!is_null($delsp)) { + $flowed->setDelSp($delsp); + } + return $flowed->toFixed(); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php new file mode 100644 index 000000000..720cc82c8 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rar.php @@ -0,0 +1,121 @@ + + * @author Michael Cochrane + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Rar extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInfo(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInfo() + { + $contents = $this->_mimepart->getContents(); + + $rar = Horde_Compress::factory('rar'); + $rarData = $rar->decompress($contents); + + $charset = $GLOBALS['registry']->getCharset(); + $fileCount = count($rarData); + + $name = $this->_mimepart->getName(true); + if (empty($name)) { + $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)) .
+            "\n\n" .
+            Horde_Text_Filter::filter(
+                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) .
+                Horde_String::pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) .
+                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";
+
+        foreach ($rarData as $val) {
+            $ratio = empty($val['size'])
+                ? 0
+                : 100 * ($val['csize'] / $val['size']);
+
+            $text .= Horde_Text_Filter::filter(
+                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) .
+                Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT) .
+                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)
+            ) . "\n";
+        }
+
+        return array(
+            $this->_mimepart->getMimeId() => array(
+                'data' => nl2br($text . str_repeat('-', 106) . "\n
"), + 'status' => array(), + 'type' => '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 new file mode 100644 index 000000000..1deeb5c31 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Report.php @@ -0,0 +1,43 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Report extends Horde_Mime_Viewer_Driver +{ + /** + * Return the underlying MIME Viewer for this part. + * + * @return mixed A Horde_Mime_Viewer object, or false if not found. + */ + protected function _getViewer() + { + 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 + * sub-type of the second body part. */ + $parts = $this->_mimepart->getParts(); + if (!isset($parts[1])) { + return false; + } + $type = $parts[1]->getSubType(); + } + + $viewer = Horde_Mime_Viewer::factory($this->_mimepart, 'message/' . Horde_String::lower($type)); + if ($viewer) { + $viewer->setParams($this->_params); + } + + return $viewer; + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php new file mode 100644 index 000000000..a2876ed7e --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rfc822.php @@ -0,0 +1,94 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Rfc822 extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_mimepart->getContents(), + 'status' => array(), + 'type' => 'text/plain; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInfo() + { + /* Get the text of the part. Since we need to look for the end of + * the headers by searching for the CRLFCRLF sequence, use + * getCanonicalContents() to make sure we are getting the text with + * CRLF's. */ + $text = $this->_mimepart->getContents(array('canonical' => true)); + if (empty($text)) { + return array(); + } + + /* Search for the end of the header text (CRLFCRLF). */ + $text = substr($text, 0, strpos($text, "\r\n\r\n")); + + /* Get the list of headers now. */ + $headers = Horde_Mime_Headers::parseHeaders($text); + + $header_array = array( + 'date' => _("Date"), + 'from' => _("From"), + 'to' => _("To"), + 'cc' => _("Cc"), + 'bcc' => _("Bcc"), + 'reply-to' => _("Reply-To"), + 'subject' => _("Subject") + ); + $header_output = array(); + + foreach ($header_array as $key => $val) { + $hdr = $headers->getValue($key); + if (!empty($hdr)) { + $header_output[] = '' . $val . ': ' . htmlspecialchars($hdr); + } + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => empty($header_output) ? '' : ('
' . Horde_Text_Filter::filter(implode("
\n", $header_output), 'emails') . '
'), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php new file mode 100644 index 000000000..f60ec2b48 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Richtext.php @@ -0,0 +1,153 @@ +" to + * "<", converts CRLFs to SPACE, converts to a newline according to + * local newline convention, removes everything between a command + * and the next balancing command, and removes all other + * formatting commands (all text enclosed in angle brackets). + * + * We implement the following tags: + * , , , , , ,
, + * , , , , , , + * , , , , + * + * The following tags are implemented differently than described in the RFC + * (due to limitations in HTML output): + * - Output as centered, bold text. + * - Output as centered, bold text. + * - Output as paragraph break. + * + * The following tags are NOT implemented: + * , , , , , + * , + * + * Copyright 2004-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. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Richtext extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_toHTML(), + 'status' => array(), + 'type' => 'text/html; charset=' . $this->_mimepart->getCharset() + ) + ); + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset()), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Convert richtext to HTML. + * + * @return string The converted HTML string. + */ + protected function _toHTML() + { + $text = trim($this->_mimepart->getContents()); + if ($text == '') { + return array(); + } + + /* We add space at the beginning and end of the string as it will + * make some regular expression checks later much easier (so we + * don't have to worry about start/end of line characters). */ + $text = ' ' . $text . ' '; + + /* Remove everything between tags. */ + $text = preg_replace('/.*<\/comment>/Uis', '', $text); + + /* Remove any unrecognized tags in the text. We don't need + * in $tags since it doesn't do anything anyway. All tags + * have already been removed. */ + $tags = '
'; + $text = strip_tags($text, $tags); + + /* becomes a '<'. CRLF becomes a SPACE. */ + $text = str_ireplace(array('', "\r\n"), array('<', ' '), $text); + + /* We try to protect against bad stuff here. */ + $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset()); + + /* becomes a newline (
); + * becomes a paragraph break (

). */ + $text = str_ireplace(array('<nl>', '<np>'), array('
', '

'), $text); + + /* Now convert the known tags to html. Try to remove any tag + * parameters to stop people from trying to pull a fast one. */ + $replace = array( + '/(? '\1', + '/(? '\1', + '/(? '\1', + '/(? '\1', + '/(? '\1', + '/(? '\1', + '/(? '

\1
', + '/(? '
\1
', + '/(? '
\1
', + '/(? '
\1
', + '/(? '\1', + '/(? '\1', + '/(? '\1', + '/(? '
\1

', + '/(? '
\1

', + '/(? '

\1

', + '/(? '
\1
' + ); + $text = preg_replace(array_keys($replace), array_values($replace), $text); + + /* Now we remove the leading/trailing space we added at the start. */ + $text = substr($text, 1, -1); + + /* Wordwrap. */ + $text = str_replace(array("\t", ' ', "\n "), array(' ', '  ', "\n "), $text); + if ($text[0] == ' ') { + $text = ' ' . substr($text, 1); + } + + return '

' . nl2br($text) . '

'; + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php new file mode 100644 index 000000000..f1ddb13dc --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rpm.php @@ -0,0 +1,89 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Rpm extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInfo(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInfo() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $data = ''; + $tmp_rpm = Horde::getTempFile('horde_rpm'); + + file_put_contents($tmp_rpm, $this->_mimepart->getContents()); + + $fh = popen($this->_conf['location'] . " -qip $tmp_rpm 2>&1", 'r'); + while (($rc = fgets($fh, 8192))) { + $data .= $rc; + } + pclose($fh); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => '
' . htmlentities($data) . '
', + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php new file mode 100644 index 000000000..c89bfde8a --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Rtf.php @@ -0,0 +1,66 @@ + + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @author Duck + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $tmp_rtf = Horde::getTempFile('rtf'); + $tmp_output = Horde::getTempFile('rtf'); + + file_put_contents($tmp_rtf, $this->_mimepart->getContents()); + + exec($this->_conf['location'] . " $tmp_rtf > $tmp_output"); + + if (file_exists($tmp_output)) { + $data = file_get_contents($tmp_output); + } else { + $data = _("Unable to translate this RTF document"); + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php new file mode 100644 index 000000000..107d2acfa --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Security.php @@ -0,0 +1,36 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Security extends Horde_Mime_Viewer_Driver +{ + /** + * 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); + } + return $viewer; + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Simple.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Simple.php new file mode 100644 index 000000000..fbd06f55e --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Simple.php @@ -0,0 +1,45 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Simple extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_mimepart->getContents(), + 'status' => array(), + 'type' => 'text/plain; charset=' . $this->_mimepart->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php new file mode 100644 index 000000000..c20d7ba92 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Smil.php @@ -0,0 +1,121 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Smil extends Horde_Mime_Viewer_Driver +{ + /** + * Handle for the XML parser object. + * + * @var resource + */ + protected $_parser; + + /** + * String buffer to hold the generated content + * + * @var string + */ + protected $_content; + + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => false, + 'embedded' => false, + 'forceinline' => true + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $this->_content = ''; + + /* Create a new parser and set its default properties. */ + $this->_parser = xml_parser_create(); + xml_set_object($this->_parser, $this); + xml_set_element_handler($this->_parser, '_startElement', '_endElement'); + xml_set_character_data_handler($this->_parser, '_defaultHandler'); + xml_parse($this->_parser, $this->_mimepart->getContents(), true); + xml_parser_free($this->_parser); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $this->_content, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * User-defined function callback for start elements. + * + * @param object $parser Handle to the parser instance. + * @param string $name The name of this XML element. + * @param array $attrs List of this element's attributes. + */ + protected function _startElement($parser, $name, $attrs) + { + switch ($name) { + case 'IMG': + if (isset($attrs['SRC'])) { + $this->_content .= ''; + } + break; + } + } + + /** + * User-defined function callback for end elements. + * + * @param object $parser Handle to the parser instance. + * @param string $name The name of this XML element. + */ + protected function _endElement($parser, $name) + { + } + + /** + * User-defined function callback for character data. + * + * @param object $parser Handle to the parser instance. + * @param string $data String of character data. + */ + protected function _defaultHandler($parser, $data) + { + $data = trim($data); + if (!empty($data)) { + $this->_content .= ' ' . htmlspecialchars($data); + } + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Source.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Source.php new file mode 100644 index 000000000..ad0e1834a --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Source.php @@ -0,0 +1,34 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Source extends Horde_Mime_Viewer_Driver +{ + /** + * Add line numbers to a block of code. + * + * @param string $code The code to number. + * + * @return string The code with line numbers added. + */ + protected function _lineNumber($code, $linebreak = "\n") + { + $html = array('
'); + for ($l = 1, $lines = substr_count($code, $linebreak) + 1; $l <= $lines; ++$l) { + $html[] = sprintf('%s
', $l, $l, $l); + } + return implode("\n", $html) . '
' . $code . '
'; + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php new file mode 100644 index 000000000..0fcabafc8 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Srchighlite.php @@ -0,0 +1,185 @@ + + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Srchighlite extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInline(); + + reset($ret); + $ret[key($ret)]['data'] = '' . + $ret[key($ret)]['data'] . + ''; + + return $ret; + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + /* Create temporary files for Webcpp. */ + $tmpin = Horde::getTempFile('SrcIn'); + $tmpout = Horde::getTempFile('SrcOut', false); + + /* Write the contents of our buffer to the temporary input file. */ + file_put_contents($tmpin, $this->_mimepart->getContents()); + + /* Determine the language from the mime type. */ + $lang = $this->_typeToLang($this->_mimepart->getType()); + + /* Execute Source-Highlite. */ + exec($this->_conf['location'] . " --src-lang $lang --out-format html --input $tmpin --output $tmpout"); + $results = file_get_contents($tmpout); + unlink($tmpout); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $results, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * Attempts to determine what mode to use for the source-highlight + * program from a MIME type. + * + * @param string $type The MIME type. + * + * @return string The mode to use. + */ + protected function _typeToLang($type) + { + switch ($type) { + case 'application/x-javascript': + return 'js'; + + case 'application/x-perl': + return 'perl'; + + case 'application/x-php': + case 'x-extension/phps': + case 'x-extension/php3s': + case 'application/x-httpd-php': + case 'application/x-httpd-php3': + case 'application/x-httpd-phps': + return 'php'; + + case 'application/x-python': + return 'python'; + + case 'application/x-ruby': + return 'ruby'; + + case 'application/x-sh': + case 'application/x-shellscript': + return 'sh'; + + case 'application/x-tcl': + return 'tcl'; + + case 'application/xml': + case 'text/xml': + return 'xml'; + + case 'text/cpp': + case 'text/x-c++src': + case 'text/x-c++hdr': + return 'cpp'; + + case 'text/css': + case 'x-extension/css': + return 'css'; + + case 'text/diff': + case 'text/x-diff': + case 'text/x-patch': + return 'diff'; + + case 'text/x-chdr': + case 'text/x-csrc': + return 'c'; + + case 'text/x-emacs-lisp': + return 'lisp'; + + case 'text/x-fortran': + case 'x-extension/f77': + case 'x-extension/f90': + case 'x-extension/for': + case 'x-extension/ftn': + return 'fortran'; + + case 'text/x-java': + return 'java'; + + case 'text/x-pascal': + return 'pascal'; + + case 'text/x-sql': + return 'sql'; + + case 'text/x-tex': + return 'tex'; + + case 'x-extension/asm': + return 'asm'; + + case 'x-extension/bat': + return 'batch'; + + case 'x-extension/cs': + return 'csharp'; + + case 'x-extension/vb': + case 'x-extension/vba': + return 'vbs'; + } + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php new file mode 100644 index 000000000..e341a2b23 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tgz.php @@ -0,0 +1,141 @@ + + * @author Michael Cochrane + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Tgz extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * The list of compressed subtypes. + * + * @var array + */ + protected $_gzipSubtypes = array( + 'x-compressed-tar', 'tgz', 'x-tgz', 'gzip', 'x-gzip', + 'x-gzip-compressed', 'x-gtar' + ); + + /** + * 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. + */ + public function __construct($mime_part, $conf = array()) + { + parent::__construct($mime_part, $conf); + + $this->_metadata['compressed'] = in_array($mime_part->getSubType(), $this->_gzipSubtypes); + } + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + $ret = $this->_renderInfo(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . + ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInfo() + { + /* Currently, can't do anything without tar file. */ + $subtype = $this->_mimepart->getSubType(); + if (in_array($subtype, array('gzip', 'x-gzip', 'x-gzip-compressed'))) { + return array(); + } + + $contents = $this->_mimepart->getContents(); + + /* Decompress gzipped files. */ + if (in_array($subtype, $this->_gzipSubtypes)) { + $gzip = Horde_Compress::factory('gzip'); + $contents = $gzip->decompress($contents); + } + + /* Obtain the list of files/data in the tar file. */ + $tar = Horde_Compress::factory('tar'); + $tarData = $tar->decompress($contents); + + $charset = $GLOBALS['registry']->getCharset(); + $fileCount = count($tarData); + + $name = $this->_mimepart->getName(true); + if (empty($name)) { + $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)) .
+            "\n\n" .
+            Horde_Text_Filter::filter(
+                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)
+            ) . "\n" .
+            str_repeat('-', 106) . "\n";
+
+        foreach ($tarData as $val) {
+            $text .= Horde_Text_Filter::filter(
+                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)
+            ) . "\n";
+        }
+
+        return array(
+            $this->_mimepart->getMimeId() => array(
+                'data' => nl2br($text . str_repeat('-', 106) . "\n
"), + 'status' => array(), + 'type' => '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 new file mode 100644 index 000000000..dc22d0951 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php @@ -0,0 +1,89 @@ + + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + $ret = $this->_renderInfo(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInfo() + { + $tnef = Horde_Compress::factory('tnef'); + $info = $tnef->decompress($this->_mimepart->getContents()); + + $data = ''; + if (empty($info)) { + $data .= ''; + } else { + $data .= ''; + foreach ($info as $part) { + $data .= ''; + } + } + $data .= '
' . _("MS-TNEF Attachment contained no data.") . '
' . _("Name") . '' . _("Mime Type") . '
' . $part['name'] . '' . $part['type'] . '/' . $part['subtype'] . '
'; + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php new file mode 100644 index 000000000..db78704a8 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Vcard.php @@ -0,0 +1,424 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => true, + 'raw' => false + ); + + /** + * URL that can be used as a callback for displaying images. + * + * @var Horde_Url + */ + protected $_imageUrl; + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + $ret = $this->_renderInline(); + + if (!empty($ret)) { + reset($ret); + Horde::startBuffer(); + include $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc'; + echo $ret[key($ret)]['data']; + include $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc'; + $ret[key($ret)]['data'] = Horde::endBuffer(); + } + + return $ret; + } + + /** + * Return the rendered inline version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderInline() + { + global $registry, $prefs, $notification; + + $app = false; + $data = $this->_mimepart->getContents(); + $html = ''; + $import_msg = null; + $title = _("vCard"); + + $iCal = new Horde_iCalendar(); + if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { + $notification->push(_("There was an error reading the contact data."), 'horde.error'); + } + + if (Horde_Util::getFormData('import') && + Horde_Util::getFormData('source') && + $registry->hasMethod('contacts/import')) { + $source = Horde_Util::getFormData('source'); + $count = 0; + foreach ($iCal->getComponents() as $c) { + if ($c instanceof Horde_iCalendar_vcard) { + try { + $contacts = $registry->call('contacts/import', array($c, null, $source)); + ++$count; + } catch (Horde_Exception $e) { + $notification->push(_("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error'); + } + } + } + $notification->push(sprintf(ngettext( + "%d contact was successfully added to your address book.", + "%d contacts were successfully added to your address book.", + $count), + $count), + 'horde.success'); + } + + $html .= ''; + + foreach ($iCal->getComponents() as $i => $vc) { + if ($i > 0) { + $html .= ''; + } + + $html .= ''; + + $n = $vc->printableName(); + if (!empty($n)) { + $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')) { + $birthday = new Horde_Date($birthdays[0]); + $html .= $this->_row( + _("Birthday"), + $birthday->strftime($prefs->getValue('date_format'))); + } + + $photos = $vc->getAllAttributes('PHOTO'); + foreach ($photos as $p => $photo) { + if (isset($photo['params']['VALUE']) && + Horde_String::upper($photo['params']['VALUE']) == 'URI') { + $html .= $this->_row(_("Photo"), + '', + false); + } 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'])) { + $html .= $this->_row(_("Photo"), + '', + false); + } elseif ($this->_imageUrl) { + $html .= $this->_row(_("Photo"), + '', + false); + } + } + } + + $labels = $vc->getAllAttributes('LABEL'); + foreach ($labels as $label) { + if (isset($label['params']['TYPE'])) { + if (!is_array($label['params']['TYPE'])) { + $label['params']['TYPE'] = array($label['params']['TYPE']); + } + } else { + $label['params']['TYPE'] = array_keys($label['params']); + } + $types = array(); + foreach ($label['params']['TYPE'] as $type) { + switch(Horde_String::upper($type)) { + case 'HOME': + $types[] = _("Home Address"); + break; + + case 'WORK': + $types[] = _("Work Address"); + break; + + case 'DOM': + $types[] = _("Domestic Address"); + break; + + case 'INTL': + $types[] = _("International Address"); + break; + + case 'POSTAL': + $types[] = _("Postal Address"); + break; + + case 'PARCEL': + $types[] = _("Parcel Address"); + break; + + case 'PREF': + $types[] = _("Preferred Address"); + break; + } + } + if (!count($types)) { + $types = array(_("Address")); + } + $html .= $this->_row(implode('/', $types), $label['value']); + } + + $adrs = $vc->getAllAttributes('ADR'); + foreach ($adrs as $item) { + if (isset($item['params']['TYPE'])) { + if (!is_array($item['params']['TYPE'])) { + $item['params']['TYPE'] = array($item['params']['TYPE']); + } + } else { + $item['params']['TYPE'] = array_keys($item['params']); + } + $address = $item['values']; + $a = array(); + if (isset($address[VCARD_ADR_STREET])) { + $a[] = $address[VCARD_ADR_STREET]; + } + if (isset($address[VCARD_ADR_LOCALITY])) { + $a[] = $address[VCARD_ADR_LOCALITY]; + } + if (isset($address[VCARD_ADR_REGION])) { + $a[] = $address[VCARD_ADR_REGION]; + } + if (isset($address[VCARD_ADR_POSTCODE])) { + $a[] = $address[VCARD_ADR_POSTCODE]; + } + if (isset($address[VCARD_ADR_COUNTRY])) { + $a[] = $address[VCARD_ADR_COUNTRY]; + } + $types = array(); + foreach ($item['params']['TYPE'] as $type) { + switch(Horde_String::upper($type)) { + case 'HOME': + $types[] = _("Home Address"); + break; + + case 'WORK': + $types[] = _("Work Address"); + break; + + case 'DOM': + $types[] = _("Domestic Address"); + break; + + case 'INTL': + $types[] = _("International Address"); + break; + + case 'POSTAL': + $types[] = _("Postal Address"); + break; + + case 'PARCEL': + $types[] = _("Parcel Address"); + break; + + case 'PREF': + $types[] = _("Preferred Address"); + break; + } + } + if (!count($types)) { + $types = array(_("Address")); + } + $html .= $this->_row(implode('/', $types), implode("\n", $a)); + } + + $numbers = $vc->getAllAttributes('TEL'); + + foreach ($numbers as $number) { + if (isset($number['params']['TYPE'])) { + if (!is_array($number['params']['TYPE'])) { + $number['params']['TYPE'] = array($number['params']['TYPE']); + } + foreach ($number['params']['TYPE'] as $type) { + $number['params'][Horde_String::upper($type)] = true; + } + } + if (isset($number['params']['FAX'])) { + $html .= $this->_row(_("Fax"), $number['value']); + } else { + if (isset($number['params']['HOME'])) { + $html .= $this->_row(_("Home Phone"), + $number['value']); + } elseif (isset($number['params']['WORK'])) { + $html .= $this->_row(_("Work Phone"), + $number['value']); + } elseif (isset($number['params']['CELL'])) { + $html .= $this->_row(_("Cell Phone"), + $number['value']); + } else { + $html .= $this->_row(_("Phone"), + $number['value']); + } + } + } + + $addresses = $vc->getAllAttributes('EMAIL'); + $emails = array(); + foreach ($addresses as $address) { + if (isset($address['params']['TYPE'])) { + if (!is_array($address['params']['TYPE'])) { + $address['params']['TYPE'] = array($address['params']['TYPE']); + } + foreach ($address['params']['TYPE'] as $type) { + $address['params'][Horde_String::upper($type)] = true; + } + } + $email = '' . htmlspecialchars($address['value']) . ''; + if (isset($address['params']['PREF'])) { + array_unshift($emails, $email); + } else { + $emails[] = $email; + } + } + + if (count($emails)) { + $html .= $this->_row(_("Email"), implode("\n", $emails), false); + } + + $title = $vc->getAttributeValues('TITLE'); + if (!is_a($title, 'PEAR_Error')) { + $html .= $this->_row(_("Title"), $title[0]); + } + + $role = $vc->getAttributeValues('ROLE'); + if (!is_a($role, 'PEAR_Error')) { + $html .= $this->_row(_("Role"), $role[0]); + } + + $org = $vc->getAttributeValues('ORG'); + if (!is_a($org, 'PEAR_Error')) { + $html .= $this->_row(_("Company"), $org[0]); + if (isset($org[1])) { + $html .= $this->_row(_("Department"), $org[1]); + } + } + + $notes = $vc->getAttributeValues('NOTE'); + if (!is_a($notes, 'PEAR_Error')) { + $html .= $this->_row(_("Notes"), $notes[0]); + } + + $url = $vc->getAttributeValues('URL'); + if (!is_a($url, 'PEAR_Error')) { + $html .= $this->_row( + _("URL"), + '' . htmlspecialchars($url[0]) + . '', + false); + } + } + + if ($registry->hasMethod('contacts/import') && + $registry->hasMethod('contacts/sources')) { + $html .= ''; + } + + $html .= '
 
'; + $fullname = $vc->getAttributeDefault('FN', false); + if ($fullname !== false) { + $html .= $fullname; + } + $html .= '
' + . Horde_Util::formInput(); + foreach ($_GET as $key => $val) { + $html .= ''; + } + + $sources = $registry->call('contacts/sources', array(true)); + if (count($sources) > 1) { + $html .= + '' + . '' + . '' + . ''; + } + + $html .= '
 
'; + + Horde::startBuffer(); + $notification->notify(array('listeners' => 'status')); + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => Horde::endBuffer() . $html, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } + + /** + * TODO + */ + protected function _row($label, $value, $encode = true) + { + if ($encode) { + $label = htmlspecialchars($label); + $value = htmlspecialchars($value); + } + return '' . $label . + '' . nl2br($value) . + "\n"; + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php new file mode 100644 index 000000000..b573cbaac --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Wordperfect.php @@ -0,0 +1,66 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Wordperfect extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => false, + 'inline' => false, + 'raw' => false + ); + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _render() + { + /* Check to make sure the viewer program exists. */ + if (!isset($this->_conf['location']) || + !file_exists($this->_conf['location'])) { + return array(); + } + + $tmp_wpd = Horde::getTempFile('wpd'); + $tmp_output = Horde::getTempFile('wpd'); + + file_put_contents($tmp_wpd, $this->_mimepart->getContents()); + + exec($this->_conf['location'] . " $tmp_wpd > $tmp_output"); + + if (file_exists($tmp_output)) { + $data = file_get_contents($tmp_output); + } else { + $data = _("Unable to translate this WordPerfect document"); + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => $data, + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php new file mode 100644 index 000000000..41b7d1fc3 --- /dev/null +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Zip.php @@ -0,0 +1,156 @@ + + * @author Michael Cochrane + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Mime_Viewer + */ +class Horde_Mime_Viewer_Zip extends Horde_Mime_Viewer_Driver +{ + /** + * This driver's display capabilities. + * + * @var array + */ + protected $_capability = array( + 'full' => true, + 'info' => true, + 'inline' => false, + 'raw' => false + ); + + /** + * Metadata for the current viewer/data. + * + * @var array + */ + protected $_metadata = array( + 'compressed' => true, + 'embedded' => false, + 'forceinline' => false + ); + + /** + * A callback function to use in _toHTML(). + * + * @var callback + */ + protected $_callback = null; + + /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _render() + { + $ret = $this->_toHTML(); + if (!empty($ret)) { + reset($ret); + $ret[key($ret)]['data'] = '' . $ret[key($ret)]['data'] . ''; + } + return $ret; + } + + /** + * Return the rendered information about the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _renderInfo() + { + return $this->_toHTML(); + } + + /** + * Converts the ZIP file to an HTML display. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + * @throws Horde_Exception + */ + protected function _toHTML() + { + $contents = $this->_mimepart->getContents(); + + $zip = Horde_Compress::factory('zip'); + $zipInfo = $zip->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST)); + + $fileCount = count($zipInfo); + + /* Determine maximum file name length. */ + $max_array = array(); + foreach ($zipInfo as $val) { + $max_array[] = strlen($val['name']); + } + $maxlen = empty($max_array) ? 0 : max($max_array); + + $name = $this->_mimepart->getName(true); + if (empty($name)) { + $name = _("unnamed"); + } + + $text = '' . htmlspecialchars(sprintf(_("Contents of \"%s\""), $name)) . ":\n" . + '
' . + Horde_Text_Filter::filter( + _("Archive Name") . ': ' . $name . "\n" . + _("Archive File Size") . ': ' . strlen($contents) . + " bytes\n" . + sprintf(ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . + "\n\n" . + Horde_String::pad(_("File Name"), $maxlen, ' ', STR_PAD_RIGHT) . + Horde_String::pad(_("Attributes"), 10, ' ', STR_PAD_LEFT) . + Horde_String::pad(_("Size"), 10, ' ', STR_PAD_LEFT) . + Horde_String::pad(_("Modified Date"), 19, ' ', STR_PAD_LEFT) . + 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) + ) . str_repeat('-', 59 + $maxlen) . "\n"; + + foreach ($zipInfo as $key => $val) { + $ratio = (empty($val['size'])) + ? 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['method'] = Horde_String::pad($val['method'], 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)); + } + + if (!is_null($this->_callback)) { + $val = call_user_func($this->_callback, $key, $val); + } + + $text .= $val['name'] . $val['attr'] . $val['size'] . + $val['date'] . $val['method'] . $val['ratio'] . + "\n"; + } + + return array( + $this->_mimepart->getMimeId() => array( + 'data' => nl2br($text . str_repeat('-', 59 + $maxlen) . "\n
"), + 'status' => array(), + 'type' => 'text/html; charset=' . $GLOBALS['registry']->getCharset() + ) + ); + } +} diff --git a/framework/Mime_Viewer/package.xml b/framework/Mime_Viewer/package.xml new file mode 100644 index 000000000..c7906a306 --- /dev/null +++ b/framework/Mime_Viewer/package.xml @@ -0,0 +1,192 @@ + + + Mime_Viewer + pear.horde.org + Horde MIME Viewer Library + Provides rendering drivers for MIME data. + + + Michael Slusarz + slusarz + slusarz@horde.org + yes + + 2010-07-25 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial package. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.5.4 + + + Core + pear.horde.org + + + Exception + pear.horde.org + + + Mime + pear.horde.org + + + Util + pear.horde.org + + + gettext + + + + + Browser + pear.horde.org + + + Compress + pear.horde.org + + + iCalendar + pear.horde.org + + + Text_Filter + pear.horde.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/Mime_Viewer/test/Horde/Mime/Viewer/url.phpt b/framework/Mime_Viewer/test/Horde/Mime/Viewer/url.phpt new file mode 100644 index 000000000..0fec4dbcb --- /dev/null +++ b/framework/Mime_Viewer/test/Horde/Mime/Viewer/url.phpt @@ -0,0 +1,66 @@ +--TEST-- +Horde_Mime_Viewer_html: URL dereferer tests +--SKIPIF-- +skip: Horde_Mime_Viewer has too many dependencies. +--FILE-- + array( + 'name' => 'www.example.com', + 'port' => 80 + ), + 'use_ssl' => 0 +); +$registry = new Registry(); +$browser = new Browser(); + +$tests = array( + 'link', + 'link', + 'link', + 'link', + 'link', + 'link', + 'link' +); + +foreach ($tests as $val) { + $part = new Horde_Mime_Part(); + $part->setType('text/html'); + $part->setContents($val); + $viewer = Horde_Mime_Viewer::factory($part, 'text/html'); + echo $viewer->render(); +} + +?> +--EXPECT-- +link +link +link +link +link +link +link diff --git a/framework/Mime_Viewer/test/Horde/Mime/Viewer/viewer_php.phpt b/framework/Mime_Viewer/test/Horde/Mime/Viewer/viewer_php.phpt new file mode 100644 index 000000000..6314c708e --- /dev/null +++ b/framework/Mime_Viewer/test/Horde/Mime/Viewer/viewer_php.phpt @@ -0,0 +1,27 @@ +--TEST-- +PHP source viewer +--SKIPIF-- +skip: Horde_Mime_Viewer has too many dependencies. +--FILE-- +setType('application/x-php'); +$part->setContents(str_replace('<?php ', '', highlight_string('render(); +?> +--EXPECT-- +
    +
  1. highlight_file(__FILE__);
  2. +