From: Michael M Slusarz Date: Thu, 13 Nov 2008 06:34:51 +0000 (-0700) Subject: renderMIMEPart() now takes a constant mask value. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a9e318954942a1e7cf5484a78be9fa7026a08296;p=horde.git renderMIMEPart() now takes a constant mask value. --- diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 3f951b94c..cd8568088 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -29,6 +29,7 @@ class IMP_Contents const RENDER_INLINE = 2; const RENDER_INLINE_DISP_NO = 4; const RENDER_INFO = 8; + const RENDER_INLINE_AUTO = 16; /** * The IMAP index of the message. @@ -284,9 +285,7 @@ class IMP_Contents * Render a MIME Part. * * @param string $mime_id The MIME ID to render. - * @param string $mode Either 'full', 'inline', 'info', or - * 'inlineauto' ('inline' and, if not available, - * then 'info'). + * @param integer $mode One of the RENDER_ constants. * @param array $options Additional options: *
      * 'params' - (array) Additional params to set.
@@ -307,11 +306,27 @@ class IMP_Contents
             $viewer->setParams($options['params']);
         }
 
-        $ret = $viewer->render(($mode == 'inlineauto') ? 'inline' : $mode);
+        switch ($mode) {
+        case self::RENDER_FULL:
+            $textmode = 'full';
+            break;
+
+        case self::RENDER_INLINE:
+        case self::RENDER_INLINE_AUTO:
+        case self::RENDER_INLINE_DISP_NO:
+            $textmode = 'inline';
+            break;
+
+        case self::RENDER_INFO:
+            $textmode = 'info';
+            break;
+        }
+
+        $ret = $viewer->render($textmode);
 
         if (empty($ret)) {
-            return ($mode == 'inlineauto')
-                ? $this->renderMIMEPart($mime_id, 'info', $options)
+            return ($mode == self::RENDER_INLINE_AUTO)
+                ? $this->renderMIMEPart($mime_id, self::RENDER_INLINE_INFO, $options)
                 : array();
         }
 
@@ -713,7 +728,7 @@ class IMP_Contents
      * Can this MIME part be displayed in the given mode?
      *
      * @param mixed $id      The MIME part or a MIME ID string.
-     * @param integer $mask  The masks to search for.
+     * @param integer $mask  One of the RENDER_ constants.
      * @param string $type   The type to use (overrides the MIME Id if $id is
      *                       a MIME part).
      *
@@ -726,6 +741,10 @@ class IMP_Contents
         }
         $viewer = Horde_Mime_Viewer::factory($part, $type);
 
+        if ($mask & self::RENDER_INLINE_AUTO) {
+            $mask |= self::RENDER_INLINE | self::RENDER_INFO;
+        }
+
         if (($mask & self::RENDER_FULL) && $viewer->canRender('full')) {
             return self::RENDER_FULL;
         }
diff --git a/imp/lib/Mime/Viewer/alternative.php b/imp/lib/Mime/Viewer/alternative.php
index a5790aeb1..997d4bf60 100644
--- a/imp/lib/Mime/Viewer/alternative.php
+++ b/imp/lib/Mime/Viewer/alternative.php
@@ -90,7 +90,7 @@ class IMP_Horde_Mime_Viewer_alternative extends Horde_Mime_Viewer_Driver
         $render_part = $this->_mimepart->getPart($disp_id);
         foreach (array_keys($render_part->contentTypeMap()) as $val) {
             if (isset($display_ids[$val])) {
-                $render = $this->_params['contents']->renderMIMEPart($val, 'inline', array('params' => $this->_params));
+                $render = $this->_params['contents']->renderMIMEPart($val, IMP_Contents::RENDER_INLINE, array('params' => $this->_params));
                 foreach (array_keys($render) as $id) {
                     $ret[$id] = $render[$id];
                     unset($display_ids[$id]);
diff --git a/imp/lib/Mime/Viewer/mdn.php b/imp/lib/Mime/Viewer/mdn.php
index 459161201..0c8a9147d 100644
--- a/imp/lib/Mime/Viewer/mdn.php
+++ b/imp/lib/Mime/Viewer/mdn.php
@@ -35,7 +35,7 @@ class IMP_Horde_Mime_Viewer_mdn extends Horde_Mime_Viewer_Driver
         /* If this is a straight message/disposition-notification part, just
          * output the text. */
         if ($this->_mimepart->getType() == 'message/disposition-notification') {
-            return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), 'full', array('type' => 'text/plain', 'params' => $this->_params));
+            return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain', 'params' => $this->_params));
         }
 
         return $this->_renderInfo();
@@ -70,13 +70,13 @@ class IMP_Horde_Mime_Viewer_mdn extends Horde_Mime_Viewer_Driver
 
         /* Print the human readable message. */
         $curr_id = $first_id = key($parts);
-        $first_part = $this->_params['contents']->renderMIMEPart($curr_id, 'inlineauto', array('params' => $this->_params));
+        $first_part = $this->_params['contents']->renderMIMEPart($curr_id, IMP_Contents::RENDER_INLINE_AUTO, array('params' => $this->_params));
 
         /* Display a link to more detailed message. */
         $curr_id = Horde_Mime::mimeIdArithmetic($curr_id, 'next');
         $part = $this->_params['contents']->getMIMEPart($curr_id);
         if ($part) {
-            $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => 'inline'))));
+            $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE))));
         }
 
         /* Display a link to the sent message. Try to download the text of
diff --git a/imp/lib/Mime/Viewer/related.php b/imp/lib/Mime/Viewer/related.php
index fd50f0844..fc168c9a6 100644
--- a/imp/lib/Mime/Viewer/related.php
+++ b/imp/lib/Mime/Viewer/related.php
@@ -83,7 +83,7 @@ class IMP_Horde_Mime_Viewer_related extends Horde_Mime_Viewer_Driver
             }
         }
 
-        $render = $this->_params['contents']->renderMIMEPart($id, $inline ? 'inline' : 'full', array('params' => array_merge($this->_params, array('related_id' => $id, 'related_cids' => $cids))));
+        $render = $this->_params['contents']->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL, array('params' => array_merge($this->_params, array('related_id' => $id, 'related_cids' => $cids))));
 
         foreach (array_keys($render) as $val) {
             $ret[$val] = $render[$val];
diff --git a/imp/message.php b/imp/message.php
index 363eabeff..1a02ec8a3 100644
--- a/imp/message.php
+++ b/imp/message.php
@@ -663,20 +663,15 @@ foreach ($parts_list as $mime_id => $mime_type) {
         continue;
     }
 
-    $render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO);
-    if ($render_mode & IMP_Contents::RENDER_INLINE) {
-        $type = 'inline';
-    } elseif ($render_mode & IMP_Contents::RENDER_INFO) {
-        $type = 'info';
-    } else {
+    if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
         if (!$show_all_parts && $imp_contents->isAttachment($mime_type)) {
             $atc_parts[] = $mime_id;
         }
         continue;
     }
 
-    $render_part = $imp_contents->renderMIMEPart($mime_id, $type);
-    if (($type == 'inline') && empty($render_part)) {
+    $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode);
+    if (($render_mode & IMP_Contents::RENDER_INLINE) && empty($render_part)) {
         /* This meant that nothing was rendered - allow this part to appear
          * in the attachment list instead. */
         if (!$show_all_parts) {
diff --git a/imp/thread.php b/imp/thread.php
index 7875fd5cf..3f1247be2 100644
--- a/imp/thread.php
+++ b/imp/thread.php
@@ -98,7 +98,7 @@ foreach ($loop_array as $mbox => $idxlist) {
         $contents = &IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
         $mime_id = $contents->findBody();
         if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) {
-            $curr_msg['body'] = $contents->renderMIMEPart($mime_id);
+            $curr_msg['body'] = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE);
         } else {
             $curr_msg['body'] = '' . _("There is no text that can be displayed inline.") . '';
         }
diff --git a/imp/view.php b/imp/view.php
index 78f81e02d..0334f4397 100644
--- a/imp/view.php
+++ b/imp/view.php
@@ -112,7 +112,7 @@ case 'download_render':
         break;
 
     case 'download_render':
-        $render = $contents->renderMIMEPart($id, Util::getFormData('mode', 'full'), array('type' => $ctype));
+        $render = $contents->renderMIMEPart($id, Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('type' => $ctype));
         $body = $render[$id]['data'];
         $type = $render[$id]['type'];
         $name = $render[$id]['name'];
@@ -135,7 +135,7 @@ case 'download_render':
     exit;
 
 case 'view_attach':
-    $render = $contents->renderMIMEPart($id, Util::getFormData('mode', 'full'), array('type' => $ctype));
+    $render = $contents->renderMIMEPart($id, Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('type' => $ctype));
     $browser->downloadHeaders($render[$id]['name'], $render[$id]['type'], true, strlen($render[$id]['data']));
     echo $render[$id]['data'];
     exit;