Do full URL redirection instead of Location: ?...
[banana.git] / banana / banana.inc.php.in
index a8a42d7..4f4a076 100644 (file)
@@ -24,7 +24,10 @@ class Banana
     var $can_attach  = true;
     /** Maximum allowed file size for attachment
      */
-    var $maxfilesize = 100000;  
+    var $maxfilesize = 100000;
+    /** Indicate wether x-face should be skinned as specials data or not
+     */
+    var $formatxface = true;
 
     /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
      * ex : '^xorg\..*' for xorg.*
@@ -47,7 +50,7 @@ class Banana
      *   $matches[2] = "http://www.polytechnique.org"
      *   $matches[3] = "]"
      */
-    var $url_regexp  = '(["\[])?((?:https?|ftp|news)://(?:&|[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
+    var $url_regexp  = '(["\[])?((?:https?|ftp|news)://(?:&|,?[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
 
     
     /** Boundary for multipart messages
@@ -84,6 +87,9 @@ class Banana
         $this->_require('NetNNTP');
         setlocale(LC_ALL,  $this->profile['locale']);
         $this->nntp = new nntp($this->host);
+        if (!$this->nntp || !$this->nntp->valid) {
+            $this->nntp = null;
+        }
     }
 
     function run($class = 'Banana')
@@ -199,7 +205,9 @@ class Banana
 
     function action_showThread($group, $first)
     {
-        $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
+        if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) {
+            return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
+        }
 
         if ($first > count($this->spool->overview)) {
             $first = count($this->spool->overview);
@@ -219,9 +227,11 @@ class Banana
 
     function action_showArticle($group, $id, $part)
     {
-        $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
-        $this->_newPost($id);
-        if (!$this->post) {
+        if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) {
+            return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
+        }
+
+        if (!$this->_newPost($id)) {
             if ($this->nntp->lasterrorcode == "423") {
                 $this->spool->delid($id);
             }
@@ -240,9 +250,11 @@ class Banana
 
     function action_getAttachment($group, $id, $pjid, $action)
     {
-        $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
-        $this->_newPost($id);
-        if (!$this->post) {
+        if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) {
+            return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
+        }
+
+        if (!$this->_newPost($id)) {
             if ($this->nntp->lasterrorcode == "423") {
                 $this->spool->delid($id);
             }
@@ -260,8 +272,13 @@ class Banana
 
     function action_cancelArticle($group, $id)
     {
-        $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
-        $this->_newPost($id);
+        if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) {
+            return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
+        }
+
+        if (!$this->_newPost($id)) {
+            return '<p class="error">'._b_('Impossible de trouver le message à annuler').'</p>';
+        }
         $mid  = array_search($id, $this->spool->ids);
 
         if (!$this->post->checkcancel()) {
@@ -277,7 +294,7 @@ class Banana
         if ($this->nntp->post($msg)) {
             $this->spool->delid($id);
             $this->nntp->quit();
-            header("Location: ?group=$group&amp;first=$id");
+            redirect('group=' . $group . '&amp;first=' . $id);
         } else {
             return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
         }
@@ -290,8 +307,7 @@ class Banana
         
         if ($id > 0) {
             $this->nntp->group($group);
-            $this->_newPost($id);
-            if ($this->post) {
+            if ($this->_newPost($id)) {
                 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post->headers['subject']);
                 $body    = utf8_encode($this->post->name." "._b_("a écrit"))." :\n".wrap($this->post->get_body(), "> ");
                 $target  = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups'];
@@ -323,7 +339,7 @@ class Banana
             $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
         }
         $html .= '<input type="hidden" name="action" value="new" />';
-       $html .= '<input type="submit" /></th></tr>';
+       $html .= '<input type="submit" value="Envoyer le message" /></th></tr>';
         $html .= '</table></form>';
 
         return $html.$cuts;
@@ -338,18 +354,33 @@ class Banana
                 $_POST[$key] = utf8_encode($_POST[$key]);
             }
         }
-        
-        $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']);
+       
+               $forums = preg_split('/\s*(,|;)\s*/', $_POST['newsgroups']);
+               $fup    = $_POST['followup'];
+               if (sizeof($forums) > 1) {
+                       if (empty($fup)) {
+                               $fup = $forums[0];
+                       }
+               }
+               $to     = implode(',', $forums);
+               
+        if (!$this->_newSpool($group, $this->profile['display'], $this->profile['lastnews'])) {
+            return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
+        }
+               
         $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
-        $msg  = 'From: '.$this->profile['name']."\n"
-              . "Newsgroups: ".$_POST['newsgroups']."\n"
-              . "Subject: ".headerEncode($_POST['subject'], 128)."\n"
+        $msg  = 'From: ' . $this->profile['name'] . "\n"
+              . "Newsgroups: ". $to . "\n"
+              . "Subject: " . headerEncode($_POST['subject'], 128) . "\n"
               . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n")
-              . (empty($_POST['followup'])    ? '' : 'Followup-To: '.$_POST['followup']."\n");
+              . (empty($fup) ? '' : 'Followup-To: ' . $fup . "\n");
 
         if ($artid != -1) {
             $this->_require('post');
             $post = new BananaPost($artid);
+            if (!$post || !$post->valid) {
+                return '<p class="error">'._b_('Impossible charger le message d\'origine').'</p>';
+            }
             $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" );
             $msg .= "References: $refs{$post->headers['message-id']}\n";
         }
@@ -394,7 +425,7 @@ class Banana
         $msg .= $this->custom.$this->profile['customhdr']."\n".$body;
 
         if ($this->nntp->post($msg)) {
-            header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid"));
+            redirect('group=' . $group . ($artid == -1 ? '' : '&first=' . $artid));
         } else {
             return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
         }
@@ -408,13 +439,23 @@ class Banana
         $this->_require('spool');
         if (!$this->spool || $this->spool->group != $group) {
             $this->spool = new BananaSpool($group, $disp, $since);
+            if (!$this->spool || !$this->spool->valid) {
+                $this->spool = null;
+                return false;
+            }
         }
+        return true;
     }
 
     function _newPost($id)
     {
         $this->_require('post');
         $this->post = new BananaPost($id);
+        if (!$this->post || !$this->post->valid) {
+            $this->post = null;
+            return false;
+        }
+        return true;
     }
 
     function _newGroup()