Some improvements, and fix spoolgen.php
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Tue, 9 Jan 2007 17:01:31 +0000 (17:01 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:12 +0000 (00:35 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@148 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/mbox.inc.php
banana/nntp.inc.php
banana/protocoleinterface.inc.php
examples/index.php
examples/spoolgen.php

index fadd3a7..d3e983e 100644 (file)
@@ -422,7 +422,7 @@ class Banana
     /* Private functions                                                      */
     /**************************************************************************/
 
-    private function loadSpool($group)
+    protected function loadSpool($group)
     {
         Banana::load('spool');
         if (!Banana::$spool || Banana::$spool->group != $group) {
@@ -437,7 +437,7 @@ class Banana
         return true;
     }
 
-    private function &loadMessage($group, $artid)
+    protected function &loadMessage($group, $artid)
     {
         Banana::load('message');
         if ($group == @$_SESSION['banana_group'] && $artid == @$_SESSION['banana_artid']
@@ -455,7 +455,7 @@ class Banana
         return $message;
     }
 
-    private function removeMessage($group, $artid)
+    protected function removeMessage($group, $artid)
     {
         Banana::$spool->delId($artid);
         if ($group == $_SESSION['banana_group']) {
index c36bb5c..c2f7d4a 100644 (file)
@@ -13,8 +13,6 @@ require_once dirname(__FILE__) . '/message.inc.php';
 
 class BananaMBox implements BananaProtocoleInterface
 {
-    private $boxname;
-
     private $file         = null;
     private $filesize     = null;
     private $current_id   = null;
@@ -30,10 +28,9 @@ class BananaMBox implements BananaProtocoleInterface
 
     /** Build a protocole handler plugged on the given box
      */
-    public function __construct($box = null)
+    public function __construct()
     {
-        $this->boxname = $box;
-        $filename = $this->getFileName($box);
+        $filename = $this->getFileName(Banana::$group);
         if (is_null($filename)) {
             return;
         }
@@ -61,7 +58,7 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function isValid()
     {
-        return is_null($this->boxname) || !is_null($this->file);
+        return !Banana::$group || $this->file;
     }
     
     /** Indicate last error n°
@@ -93,7 +90,7 @@ class BananaMBox implements BananaProtocoleInterface
      */
     public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false)
     {
-        return array($this->boxname => array('desc' => '', 'msgnum' => 0, 'unread' => 0));
+        return array(Banana::$group => array('desc' => '', 'msgnum' => 0, 'unread' => 0));
     }
 
     /** Return a message
index f1dde9d..51c5716 100644 (file)
@@ -14,7 +14,6 @@ require_once dirname(__FILE__) . '/protocoleinterface.inc.php';
 
 class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 {
-    private $groupname = null;
     private $description = null;
     private $ingroup = null;
 
@@ -23,7 +22,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
 
     /** Build a protocole handler plugged on the given box
      */
-    public function __construct($box = null)
+    public function __construct()
     {
         $url = parse_url(Banana::$host);
         if ($url['scheme'] == 'nntps' || $url['scheme'] == 'snntp') {
@@ -38,7 +37,6 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
             parent::__construct($url['host'], $url['port'], 120, false);
             $this->authinfo($url['user'], $url['pass']);
         }      
-        $this->groupname = $box;
     }
 
     /** Return the descript;ion of the current box
@@ -48,9 +46,9 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         if ($this->description) {
             return $this->description;
         }
-        $descs = $this->xgtitle($this->groupname);
-        if (isset($descs[$this->groupname])) {
-            $this->description = $descs[$this->groupname];
+        $descs = $this->xgtitle(Banana::$group);
+        if (isset($descs[Banana::$group])) {
+            $this->description = $descs[Banana::$group];
         }
         return $this->description;
     }
@@ -107,10 +105,10 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function getMessage($id, array $msg_headers = array(), $is_msgid = false)
     {
-        if (!$is_msgid && $this->groupname != $this->ingroup) {
+        if (!$is_msgid && Banana::$group != $this->ingroup) {
             if (is_null(Banana::$spool)) {
-                $this->group($this->groupname);
-                $this->ingroup = $this->groupname;
+                $this->group(Banana::$group);
+                $this->ingroup = Banana::$group;
             } else {
                 $id = array_search($id, Banana::$spool->ids);
             }
@@ -127,8 +125,8 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function getIndexes()
     {
-        list($msgnum, $first, $last, $groupname) = $this->group($this->groupname);
-        $this->ingroup = $this->groupname;
+        list($msgnum, $first, $last, $groupname) = $this->group(Banana::$group);
+        $this->ingroup = Banana::$group;
         return array($msgnum, $first, $last);
     }
 
@@ -167,7 +165,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
      */
     public function getNewIndexes($since)
     {
-        return $this->newnews($this->groupname, $since);
+        return $this->newnews(Banana::$group, $since);
     }
 
     /** Return true if can post
@@ -204,7 +202,7 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
     public function cancel(BananaMessage &$message)
     {
         $headers = Array('From' => Banana::$profile['From'],
-                         'Newsgroups' => $this->groupname,
+                         'Newsgroups' => Banana::$group,
                          'Subject'    => 'cmsg ' . $message->getHeaderValue('message-id'),
                          'Control'    => 'cancel ' . $message->getHeaderValue('message-id'));
         $headers = array_merge($headers, Banana::$custom_hdr);
index 5962e5a..bc3e1db 100644 (file)
@@ -13,7 +13,7 @@ interface BananaProtocoleInterface
 {
     /** Build a protocole handler plugged on the given box
      */
-    public function __construct($box = null);
+    public function __construct();
 
     /** Indicate if the Protocole handler has been succesfully built
      */
index f05b2e5..5b19df9 100644 (file)
@@ -8,15 +8,16 @@
 ********************************************************************************/
 
 require_once("banana/banana.inc.php");
-$res = Banana::run();
+$banana = new Banana();
+$res = $banana->run();
 
 if ($res != "") {
 ?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <meta http-equiv="Content-Type" content="text/html; 
-    charset=iso-8859-1">
+    charset=UTF-8">
     <meta name="description" content="WebForum2/Banana">
     <link href="css/style.css" type="text/css" rel="stylesheet" media="screen">
     <link href="css/banana.css" type="text/css" rel="stylesheet" media="screen">
index 0ad6b52..6c2c7da 100644 (file)
@@ -1,4 +1,4 @@
-#! /usr/bin/php4
+#!/usr/bin/php5
 <?php
 /********************************************************************************
  * spoolgen.php : spool generation
@@ -22,29 +22,38 @@ EOF;
 
 class MyBanana extends Banana
 {
-    function MyBanana()
+    public function __construct()
     {
         global $opt;
-        $this->host = "http://{$opt['u']}:{$opt['p']}@localhost:119/";
-        echo $this->host;
-        parent::Banana();
+        Banana::$host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
+        echo Banana::$host;
+        parent::__construct();
     }
 
-    function createAllSpool()
+    private function checkErrors()
     {
-        $this->_require('groups');
-        $this->_require('spool');
-        $this->_require('misc');
+        if (Banana::$protocole->lastErrno()) {
+            echo "\nL'erreur suivante s'est produite : "
+                . Banana::$protocole->lastErrno() . " "
+                . Banana::$protocole->lastError() . "\n";
+            exit;
+        }
+    }
 
-        $groups = new BananaGroups(BANANA_GROUP_ALL);
+    public function createAllSpool()
+    {
+        $this->checkErrors();
+        $groups = Banana::$protocole->getBoxList();
+        $this->checkErrors();
 
-        foreach (array_keys($groups->overview) as $g) {
+        foreach (array_keys($groups) as $g) {
             print "Generating spool for $g : ";
-            $spool = new BananaSpool($g);
+            Banana::$group = $g;
+            $spool = $this->loadSpool($g);
+            $this->checkErrors();
             print "done.\n";
             unset($spool);
         }
-        $this->nntp->quit();
     }
 }