From 47f1b351d4c4a11828faa5349afaf76006857254 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 9 Nov 2008 23:42:43 -0700 Subject: [PATCH] Updates from my local tree. --- framework/Mime/lib/Horde/Mime/Viewer.php | 115 +++++++----------------- framework/Mime/lib/Horde/Mime/Viewer/Driver.php | 10 ++- framework/Mime/lib/Horde/Mime/Viewer/html.php | 42 ++++++--- framework/Mime/lib/Horde/Mime/Viewer/plain.php | 10 ++- 4 files changed, 75 insertions(+), 102 deletions(-) diff --git a/framework/Mime/lib/Horde/Mime/Viewer.php b/framework/Mime/lib/Horde/Mime/Viewer.php index 4772d9013..e45018976 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer.php +++ b/framework/Mime/lib/Horde/Mime/Viewer.php @@ -25,7 +25,8 @@ class Horde_Mime_Viewer static protected $_config = array(); /** - * The driver cache array. + * The driver cache array. This array is shared between all instances of + * Horde_MIME_Viewer. * * @var array */ @@ -53,6 +54,36 @@ class Horde_Mime_Viewer } /** + * 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. * @@ -191,88 +222,6 @@ class Horde_Mime_Viewer } /** - * Prints out the status message for a given MIME Part. - * - * @param string $msg The message to output. - * @param string $img An image link to add to the beginning of the - * message. - * @param string $class An optional style for the status box. - * - * @return string The formatted status message string. - */ - static public function formatStatusMsg($msg, $img = null, $class = null) - { - if (empty($msg)) { - return ''; - } - - if (!is_array($msg)) { - $msg = array($msg); - } - - /* If we are viewing as an attachment, don't print HTML code. */ - if (self::viewAsAttachment()) { - return implode("\n", $msg); - } - - if (is_null($class)) { - $class = 'mimeStatusMessage'; - } - $text = ''; - - /* If no image, simply print out the message. */ - if (is_null($img)) { - foreach ($msg as $val) { - $text .= '' . "\n"; - } - } else { - $text .= '' . "\n"; - } - - return $text . '
' . $val . '
' . $img . ''; - if (count($msg) == 1) { - $text .= $msg[0]; - } else { - $text .= ''; - foreach ($msg as $val) { - $text .= '' . "\n"; - } - $text .= '
' . $val . '
'; - } - $text .= '
'; - } - - /** - * 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 an input MIME type and app, this function returns the URL of an * icon that can be associated with it * diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php index e441e2713..f12bc56b2 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Driver.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Driver.php @@ -14,6 +14,10 @@ */ class Horde_MIME_Viewer_Driver { + /* 'type' constants for status info. */ + const WARNING = 1; + const INFO = 2; + /** * Viewer configuration. * @@ -86,7 +90,7 @@ class Horde_MIME_Viewer_Driver public function render() { return (is_null($this->_mimepart) || !$this->canDisplay()) - ? array('data' => '', 'type' => 'text/plain') + ? array('data' => '', 'status' => array(), 'type' => 'text/plain') : $this->_render(); } @@ -107,7 +111,7 @@ class Horde_MIME_Viewer_Driver public function renderInline() { return (is_null($this->_mimepart) || !$this->canDisplayInline()) - ? '' + ? array('data' => '', 'status' => array()), : $this->_renderInline(); } @@ -128,7 +132,7 @@ class Horde_MIME_Viewer_Driver public function renderInfo() { return (is_null($this->_mimepart) || !$this->canDisplayInfo()) - ? '' + ? array('data' => '', 'status' => array()), : $this->_renderInfo(); } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/html.php b/framework/Mime/lib/Horde/Mime/Viewer/html.php index b8317b7c8..946718713 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/html.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/html.php @@ -33,7 +33,13 @@ class Horde_MIME_Viewer_html extends Horde_MIME_Viewer_Driver */ public function _render() { - return array('data' => $this->_cleanHTML($this->_mimepart->getContents(), false), 'type' => $this->_mimepart->getType(true)); + $html = $this->_cleanHTML($this->_mimepart->getContents(), false); + + return array( + 'data' => $html['data'], + 'status' => $html['status'], + 'type' => $this->_mimepart->getType(true) + ); } /** @@ -41,7 +47,12 @@ class Horde_MIME_Viewer_html extends Horde_MIME_Viewer_Driver */ public function _renderInline() { - return String::convertCharset($this->_cleanHTML($this->_mimepart->getContents(), true), $this->_mimepart->getCharset()); + $html = $this->_cleanHTML($this->_mimepart->getContents(), true); + + return array( + 'data' => String::convertCharset($html['data'], $this->_mimepart->getCharset()), + 'status' => $html['status'] + ); } /** @@ -54,7 +65,7 @@ class Horde_MIME_Viewer_html extends Horde_MIME_Viewer_Driver * @param string $data The HTML data. * @param boolean $inline Are we viewing inline? * - * @return string The cleaned HTML data. + * @return array Two elements: 'html' and 'status'. */ protected function _cleanHTML($data, $inline) { @@ -136,30 +147,33 @@ class Horde_MIME_Viewer_html extends Horde_MIME_Viewer_Driver } /* Try to derefer all external references. */ - $data = preg_replace_callback('/href\s*=\s*(["\'])?((?(1)[^\1]*?|[^\s>]+))(?(1)\1|)/i', - array($this, '_dereferExternalReferencesCallback'), - $data); + $data = preg_replace_callback('/href\s*=\s*(["\'])?((?(1)[^\1]*?|[^\s>]+))(?(1)\1|)/i', array($this, '_dereferCallback'), $data); - /* Prepend phishing warning. */ + /* Get phishing warning. */ + $status = array(); if ($phish_warn) { $phish_warning = sprintf(_("%s: This message may not be from whom it claims to be. Beware of following any links in it or of providing the sender with any personal information.") . ' ' . _("The links that caused this warning have the same background color as this message."), _("Warning")); if (!$inline) { - $phish_warning = '' . String::convertCharset($phish_warning, NLS::getCharset(), $this->_mimepart->getCharset()) . '
'; + $phish_warning = String::convertCharset($phish_warning, NLS::getCharset(), $this->_mimepart->getCharset()); } - $phish_warning = $this->formatStatusMsg($phish_warning, null, 'mimeStatusWarning'); - $data = (stristr($data, ')(.*)/i', '$1' . $phish_warning . '$2', $data); + $status[] = array( + 'text' => $phish_warning, + 'type' => self::WARNING + ); } - return $data; + return array('html' => $data, 'status' => $status); } /** * TODO + * + * @param string $m TODO + * + * @return string TODO */ - protected function _dereferExternalReferencesCallback($m) + protected function _dereferCallback($m) { return 'href="' . Horde::externalUrl($m[2]) . '"'; } diff --git a/framework/Mime/lib/Horde/Mime/Viewer/plain.php b/framework/Mime/lib/Horde/Mime/Viewer/plain.php index ad0aa17b7..202f5ccaa 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/plain.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/plain.php @@ -43,7 +43,8 @@ class Horde_MIME_Viewer_plain extends Horde_MIME_Viewer_Driver require_once 'Horde/Text/Filter.php'; return array( 'data' => '' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '', - 'type' => 'text/html; charset=' . $charset; + 'status' => array(), + 'type' => 'text/html; charset=' . $charset ); } @@ -57,9 +58,14 @@ class Horde_MIME_Viewer_plain extends Horde_MIME_Viewer_Driver $text = String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset()); /* Check for 'flowed' text data. */ - return ($this->_mimepart->getContentTypeParameter('format') == 'flowed') + $data = ($this->_mimepart->getContentTypeParameter('format') == 'flowed') ? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')) : $text; + + return array( + 'data' => $data, + 'status' => array() + ); } /** -- 2.11.0