Can choose the part of the message to display
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sat, 27 Jan 2007 21:43:14 +0000 (21:43 +0000)
committerx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sat, 27 Jan 2007 21:43:14 +0000 (21:43 +0000)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@180 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/message.inc.php
banana/mimepart.inc.php
banana/templates/banana-message.inc.tpl

index 6bb7103..1c52fc5 100644 (file)
@@ -7,6 +7,8 @@
 * Copyright: See COPYING files that comes with this distribution
 ********************************************************************************/
 
+require_once dirname(__FILE__) . '/text.func.inc.php';
+
 class Banana
 {
 
@@ -24,6 +26,7 @@ class Banana
                                     'autoup' => 1);
     static public $boxpattern;
     static public $withtabs = true;
+    static public $mimeparts = array();
 
 ### Spool ###
     static public $spool_max     = 3000;
@@ -42,7 +45,8 @@ class Banana
 ### Message display ###
     static public $msgshow_headers   = array('from', 'newsgroups', 'followup-to', 'to', 'cc', 'reply-to',
                                        'organization', 'date', 'references', 'in-reply-to');
-    static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', 'text/html', 'text/plain', 'text/enriched', 'text', 'message');
+    static public $msgshow_mimeparts = array('multipart/report', 'multipart/mixed', 
+                                             'text/html', 'text/plain', 'text/enriched', 'text', 'message');
     static public $msgshow_xface     = true;
     static public $msgshow_wrap      = 78;
     static public $msgshow_externalimages = false;
@@ -136,7 +140,6 @@ class Banana
      */
     public function __construct($params = null, $protocole = 'NNTP', $pageclass = 'BananaPage')
     {
-        Banana::load('text.func');
         if (is_null($params)) {
             $this->params = $_GET;
         } else {
@@ -156,6 +159,17 @@ class Banana
             Banana::load('page');
         }
         Banana::$page = new $pageclass;
+
+        $types = array('multipart/report' => _b_('Rapport d\'erreur'),
+                       'multipart/mixed'  => _b_('Composition'),
+                       'text/html'        => _b_('Texte formaté'),
+                       'text/plain'       => _b_('Texte brut'),
+                       'text/enriched'    => _b_('Texte enrichi'),
+                       'text'             => _b_('Texte'),
+                       'message/rfc822'   => _b_('Mail'),
+                       'message'          => _b_('Message'),
+                       'source'           => _b_('Source'));
+        Banana::$mimeparts = array_merge($types, Banana::$mimeparts);
     }
 
     /** Fill state vars (Banana::$group, Banana::$artid, Banana::$action, Banana;:$part, Banana::$first)
@@ -331,7 +345,8 @@ class Banana
             }
             exit;
         } elseif ($partid == 'text') {
-            Banana::$page->assign('body', $msg->getFormattedBody());
+            $partid = null;
+            Banana::$page->assign('body', $msg->getFormattedBody($partid));
         } elseif ($partid == 'source') {
             $text = Banana::$protocole->getMessageSource($artid);
             if (!is_utf8($text)) {
@@ -351,6 +366,7 @@ class Banana
         }    
         Banana::$page->assign_by_ref('message', $msg);
         Banana::$page->assign('headers', Banana::$msgshow_headers);
+        Banana::$page->assign('type', $partid);
         return true;
     }
 
index b3dbc8b..01686a1 100644 (file)
@@ -228,11 +228,11 @@ final class BananaMessage extends BananaMimePart
         exit;
     }
 
-    public function getFormattedBody($type = null)
+    public function getFormattedBody(&$reqtype = null)
     {
         $types = Banana::$msgshow_mimeparts;
-        if (!is_null($type)) {
-            array_unshift($types, $type);
+        if (!is_null($reqtype)) {
+            array_unshift($types, $reqtype);
         }
         foreach ($types as $type) {
             @list($type, $subtype) = explode('/', $type);
@@ -240,6 +240,7 @@ final class BananaMessage extends BananaMimePart
             if (empty($parts)) {
                 continue;
             }
+            $reqtype = implode('/', $parts[0]->getType());
             return $parts[0]->toHtml();
         }
         return null;
index 3f543bc..cf1e94a 100644 (file)
@@ -544,6 +544,43 @@ class BananaMimePart
         return array();
     }
 
+    public function getAlternatives()
+    {
+        $types =& Banana::$msgshow_mimeparts;
+        $names =& Banana::$mimeparts;
+        $source = null;
+        if (in_array('source', $types)) {
+            $source = @$names['source'] ? $names['source'] : 'source';
+        }
+        if (!$this->isType('multipart', 'alternative') && !$this->isType('multipart', 'related')) {
+            if ($source) {
+                $parts = array($this);
+            } else {
+                return array();
+            }
+        } else {
+            $parts =& $this->multipart;
+        }
+        $alt = array();
+        foreach ($parts as &$part) {
+            list($type, $subtype) = $part->getType();
+            $ct = $type . '/' . $subtype;
+            if (in_array($ct, $types) || in_array($type, $types)) {
+                if (isset($names[$ct])) {
+                    $alt[$ct] = $names[$ct];
+                } elseif (isset($names[$type])) {
+                    $alt[$ct] = $names[$type];
+                } else {
+                    $alt[$ct] = $ct;
+                }
+            }
+        }
+        if ($source) {
+            $alt['source'] = $source;
+        }
+        return $alt;
+    }
+
     public function getPartById($id)
     {
         if ($this->id == $id) {
index 2924c6c..f7672b7 100644 (file)
     </td>
   </tr>
   {/if}
+  {assign var=alter value=$message->getAlternatives()}
+  {if $alter|@count}
+  <tr class="pair">
+    <td class="hdr">{"Versions"|b}</td>
+    <td colspan="2">
+      {foreach from=$alter key=ctype item=text name=alter}
+      {if $type eq $ctype}{$text}{else}{link group=$group artid=$artid part=$ctype text=$text}{/if}
+      {if !$smarty.foreach.alter.last}&nbsp;&bull;&nbsp;{/if}
+      {/foreach}
+    </td>
+  </tr>
+  {/if}
   <tr>
     <td colspan="3" class="body">
       {$body}