Fixes deprecated features in PHP 5.3.x.
[banana.git] / banana / banana.inc.php.in
index fde1931..73f5801 100644 (file)
@@ -26,16 +26,21 @@ class Banana
                                     'autoup' => 1);
     static public $boxpattern;
     static public $withtabs = true;
+    static public $baseurl   = null;
     static public $mimeparts = array();
 
 ### Spool ###
     static public $spool_root    = '/var/spool/banana';
     static public $spool_max     = 3000;
     static public $spool_tbefore = 5;
-    static public $spool_tafter  = 5;
-    static public $spool_tmax    = 50;
+    static public $spool_tcontext= 10;
+    static public $spool_tmax    = 10;
     static public $spool_boxlist = true;
 
+### Tree options ###
+    static public $tree_read  = 'dg';
+    static public $tree_unread = 'b';
+
 ### Message processing ###
     static public $msgparse_headers = array('content-disposition', 'content-transfer-encoding',
                                        'content-type', 'content-id', 'date', 'followup-to',
@@ -45,14 +50,19 @@ 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', 
+                                             'organization', 'date');
+    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      = 80;
     static public $msgshow_externalimages = false;
     static public $msgshow_hasextimages   = false;
     static public $msgshow_withthread = true;
+    static public $msgshow_javascript = true;
+
+    static public $msgshow_pgpcheck   = true;
+    static public $msgshow_pgppath    = 'gpg';
+    static public $msgshow_pgpoptions = '';
 
     /** Match an url
      * Should be included in a regexp delimited using /, !, , or @ (eg: "/$url_regexp/ui")
@@ -65,7 +75,7 @@ class Banana
      *   $matches[2] = "http://www.polytechnique.org"
      *   $matches[3] = "]"
      */
-    static public $msgshow_url     = '(["\[])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!\:]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]])?';
+    static public $msgshow_url     = '(["\[\<])?((?:[a-z]+:\/\/|www\.)(?:[\.\,\;\!\:]*[a-z\@0-9~%$£µ&i#\-+=_\/\?]+)+)(["\]\>])?';
 
 ### Message edition ###
     static public $msgedit_canattach  = true;
@@ -81,7 +91,9 @@ class Banana
     static public $feed_active         = true;
     static public $feed_format         = 'rss2';
     static public $feed_updateOnDemand = false; // Update the feed each time sbd check it
-    static public $feed_copyright      = null;
+    static public $feed_copyright      = null;  // Global copyright informations
+    static public $feed_generator      = 'Banana @VERSION@'; // Feed generator
+    static public $feed_email          = null;  // Admin e-mail
     static public $feed_namePrefix     = 'Banana :: ';
     static public $feed_size           = 15;    // Number of messages in the feed
 
@@ -101,7 +113,7 @@ class Banana
 
 #######
 # Constants
-#######    
+#######
 
     // Actions
     const ACTION_BOX_NEEDED = 1; // mask
@@ -165,7 +177,7 @@ class Banana
         $classname = 'Banana' . $protocole;
         if (!class_exists($classname)) {
             Banana::load($protocole);
-        }    
+        }
         Banana::$protocole = new $classname(Banana::$group);
 
         // build the page
@@ -189,6 +201,11 @@ class Banana
      */
     protected function loadParams()
     {
+        foreach ($this->params as &$value) {
+            if ($value === "") {
+                $value = null;
+            }
+        }
         Banana::$group = isset($this->params['group']) ? $this->params['group'] : null;
         Banana::$artid = isset($this->params['artid']) ? $this->params['artid'] : null;
         Banana::$first = isset($this->params['first']) ? $this->params['first'] : null;
@@ -203,7 +220,7 @@ class Banana
             Banana::$action = Banana::ACTION_BOX_FEED;
             return;
         }
-    
+
         // Look for the action to execute
         if (is_null(Banana::$group)) {
             if ($action  == 'subscribe') {
@@ -213,7 +230,7 @@ class Banana
             }
             return;
         }
-        
+
         if (is_null(Banana::$artid)) {
             if ($action == 'new') {
                 Banana::$action = Banana::ACTION_MSG_NEW;
@@ -244,7 +261,7 @@ class Banana
     {
         // Configure locales
         setlocale(LC_ALL,  Banana::$profile['locale']);
-        
+
         // Check if the state is valid
         if (Banana::$protocole->lastErrNo()) {
             return Banana::$page->kill(_b_('Une erreur a été rencontrée lors de la connexion au serveur') . '<br />'
@@ -254,8 +271,8 @@ class Banana
             return Banana::$page->kill(_b_('Connexion non-valide'));
         }
         if (Banana::$action & Banana::ACTION_BOX_NEEDED) {
-            if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', $group)) {
-                Banana::$page->setPage('group');        
+            if(Banana::$boxpattern && !preg_match('/' . Banana::$boxpattern . '/i', Banana::$group)) {
+                Banana::$page->setPage('group');
                 return Banana::$page->kill(_b_("Ce newsgroup n'existe pas ou vous n'avez pas l'autorisation d'y accéder"));
             }
         }
@@ -269,7 +286,8 @@ class Banana
             $error = $this->action_listBoxes();
             break;
           case Banana::ACTION_BOX_FEED:
-            return $this->action_feed(); // generate its own xml
+            $this->action_feed(); // generate its own xml
+            break;
           case Banana::ACTION_MSG_LIST:
             $error = $this->action_showThread(Banana::$group, Banana::$first);
             break;
@@ -295,6 +313,27 @@ class Banana
         return Banana::$page->run();
     }
 
+    /** Build and post a new message
+     * @return postid (or -1 if the message has not been found)
+     */
+    public function post($dest, $reply, $subject, $body)
+    {
+        $hdrs = Banana::$protocole->requestedHeaders();
+        $headers                 = Banana::$profile['headers'];
+        $headers[$hdrs['dest']]  = $dest;
+        if ($reply) {
+            $headers[$hdrs['reply']] = $reply;
+        }
+        $headers['Subject']      = $subject;
+        $msg = BananaMessage::newMessage($headers, $body);
+        if (Banana::$protocole->send($msg)) {
+            Banana::$group = ($reply ? $reply : $dest);
+            $this->loadSpool(Banana::$group);
+            return Banana::$spool->getPostId($subject);
+        }
+        return -1;
+    }
+
     /** Return the CSS code to include in the headers
      */
     public function css()
@@ -359,8 +398,11 @@ class Banana
     {
         Banana::load('feed');
         if (Banana::$group) {
+            if (Banana::$feed_updateOnDemand) {
+                $this->loadSpool(Banana::$group);
+            }
             $feed =& BananaFeed::getFeed();
-            return $feed->toXML();
+            $feed->toXML();
         }
         if (Banana::$profile['subscribe']) {
             $subfeed = null;
@@ -372,9 +414,9 @@ class Banana
                 $feed =& BananaFeed::getFeed();
                 $subfeed =& BananaFeed::merge($subfeed, $feed, _b_('Abonnements'), _b_('Mes abonnements Banana'));
             }
-            return $subfeed->toXML();
+            $subfeed->toXML();
         }
-        return Banana::$page->feed();
+        Banana::$page->feed();
     }
 
     protected function action_showThread($group, $first)
@@ -437,7 +479,7 @@ class Banana
         if (Banana::$spool_boxlist) {
             $groups    = Banana::$protocole->getBoxList(Banana::BOXES_SUB, Banana::$profile['lastnews'], true);
             Banana::$page->assign('groups', $groups);
-        }    
+        }
         Banana::$page->assign_by_ref('message', $msg);
         Banana::$page->assign('extimages', Banana::$msgshow_hasextimages);
         Banana::$page->assign('headers', Banana::$msgshow_headers);
@@ -463,16 +505,24 @@ class Banana
             $hdr_values = array();
             foreach ($hdrs as $header) {
                 $hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header];
+                if (!is_utf8($hdr_values[$header])) {
+                    $hdr_values[$header] = utf8_encode($hdr_values[$header]);
+                }
             }
-            if ($artid) {
+            $values = preg_split('[,; ]', $hdr_values[$hdrs['dest']]);
+            $hdr_values[$hdrs['dest']] = preg_replace('/,+/', ',', implode(',', $values));
+            if (!is_null($artid)) {
                 $old =& $this->loadMessage($group, $artid);
-                $hdr_values['References'] = $old->getHeaderValue('references') . $old->getHeaderValue('message-id');
+                $hdr_values['References'] = $old->getHeaderValue('references') . ' ' . $old->getHeaderValue('message-id');
             }
             $msg = null;
+            if (isset($_POST['body']) && !is_utf8($_POST['body'])) {
+                $_POST['body'] = utf8_encode($_POST['body']);
+            }
             if (empty($hdr_values['Subject'])) {
                 Banana::$page->trig(_b_('Le message doit avoir un sujet'));
-            } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment'])) {
-                $uploaded = $_FILES['attachment'];
+            } elseif (Banana::$msgedit_canattach && isset($_FILES['attachment']) && $_FILES['attachment']['name']) {
+                $uploaded =& $_FILES['attachment'];
                 if (!is_uploaded_file($uploaded['tmp_name'])) {
                     Banana::$page->trig(_b_('Une erreur est survenue lors du téléchargement du fichier'));
                 } else {
@@ -483,10 +533,14 @@ class Banana
             }
             if (!is_null($msg)) {
                 if (Banana::$protocole->send($msg)) {
-                    Banana::$page->redirect(array('group' => $group, 'artid' => $artid));
-                }
-                Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
+                    $this->loadSpool($group);
+                    $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
+                    Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
+                } else {
+                    Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
                                    . Banana::$protocole->lastError());
+                    $body = $_POST['body'];
+                }
             }
         } else {
             if (!is_null($artid)) {
@@ -506,8 +560,8 @@ class Banana
             if (Banana::$profile['signature']) {
                 $body .=  "\n\n-- \n" . Banana::$profile['signature'];
             }
-            Banana::$page->assign('body', $body);
         }
+        Banana::$page->assign('body', $body);
 
         Banana::$page->assign('maxfilesize', Banana::$msgedit_maxfilesize);
         Banana::$page->assign('can_attach', Banana::$msgedit_canattach);
@@ -524,16 +578,12 @@ class Banana
         }
         if (isset($_POST['cancel'])) {
             $this->loadSpool($group);
-            $ndx = Banana::$spool->getNdX($id) - 1;
             if (!Banana::$protocole->cancel($msg)) {
                 return _b_('Une erreur s\'est produite lors de l\'annulation du message :') . '<br />'
                        . Banana::$protocole->lastError();
             }
-            if ($ndx < 50) {
-                 $ndx = 0;
-            }
             $this->removeMessage($group, $artid);
-            Banana::$page->redirect(Array('group' => $group, 'first' => $ndx));
+            Banana::$page->redirect(Array('group' => $group));
         }
 
         Banana::$page->assign_by_ref('message', $msg);
@@ -618,7 +668,7 @@ class Banana
             print "\n";
         }
     }
+
     /**************************************************************************/
     /* Private functions                                                      */
     /**************************************************************************/
@@ -627,21 +677,7 @@ class Banana
     {
         Banana::load('spool');
         if (!Banana::$spool || Banana::$spool->group != $group) {
-            $clean = false;
-            if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
-                Banana::$spool = unserialize($_SESSION['banana_spool']);
-                $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
-            } else {
-                unset($_SESSION['banana_message']);
-                unset($_SESSION['banana_artid']);
-                unset($_SESSION['banana_showhdr']);
-            }
-            BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean);
-            $_SESSION['banana_group'] = $group;
-            if (!Banana::$profile['display']) {
-                $_SESSION['banana_spool'] = serialize(Banana::$spool);
-                $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
-            }
+            BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup']);
             Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
         }
         return true;
@@ -682,7 +718,7 @@ class Banana
         return true;
     }
 
-    static private function load($file)
+    static public function load($file)
     {
         $file = strtolower($file) . '.inc.php';
         if (!@include_once dirname(__FILE__) . "/$file") {