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
*/
}
/**
+ * 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.
*
}
/**
- * 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 = '<table class="' . $class . '">';
-
- /* If no image, simply print out the message. */
- if (is_null($img)) {
- foreach ($msg as $val) {
- $text .= '<tr><td>' . $val . '</td></tr>' . "\n";
- }
- } else {
- $text .= '<tr><td class="mimeStatusIcon">' . $img . '</td><td>';
- if (count($msg) == 1) {
- $text .= $msg[0];
- } else {
- $text .= '<table>';
- foreach ($msg as $val) {
- $text .= '<tr><td>' . $val . '</td></tr>' . "\n";
- }
- $text .= '</table>';
- }
- $text .= '</td></tr>' . "\n";
- }
-
- return $text . '</table>';
- }
-
- /**
- * 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
*
*/
class Horde_MIME_Viewer_Driver
{
+ /* 'type' constants for status info. */
+ const WARNING = 1;
+ const INFO = 2;
+
/**
* Viewer configuration.
*
public function render()
{
return (is_null($this->_mimepart) || !$this->canDisplay())
- ? array('data' => '', 'type' => 'text/plain')
+ ? array('data' => '', 'status' => array(), 'type' => 'text/plain')
: $this->_render();
}
public function renderInline()
{
return (is_null($this->_mimepart) || !$this->canDisplayInline())
- ? ''
+ ? array('data' => '', 'status' => array()),
: $this->_renderInline();
}
public function renderInfo()
{
return (is_null($this->_mimepart) || !$this->canDisplayInfo())
- ? ''
+ ? array('data' => '', 'status' => array()),
: $this->_renderInfo();
}
*/
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)
+ );
}
/**
*/
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']
+ );
}
/**
* @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)
{
}
/* 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 = '<span style="background-color:#ffd0af;color:black">' . String::convertCharset($phish_warning, NLS::getCharset(), $this->_mimepart->getCharset()) . '</span><br />';
+ $phish_warning = String::convertCharset($phish_warning, NLS::getCharset(), $this->_mimepart->getCharset());
}
- $phish_warning = $this->formatStatusMsg($phish_warning, null, 'mimeStatusWarning');
- $data = (stristr($data, '<body') === false)
- ? $phish_warning . $data
- : preg_replace('/(.*<body.*?>)(.*)/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]) . '"';
}
require_once 'Horde/Text/Filter.php';
return array(
'data' => '<html><body><tt>' . Text_Filter::filter($text, 'text2html', array('parselevel' => TEXT_HTML_MICRO, 'charset' => $charset, 'class' => null)) . '</tt></body></html>',
- 'type' => 'text/html; charset=' . $charset;
+ 'status' => array(),
+ 'type' => 'text/html; charset=' . $charset
);
}
$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()
+ );
}
/**