Allow more precise description of the read/unread messages through a
[banana.git] / examples / spoolgen.php
index 6c2c7da..2c017eb 100644 (file)
 
 require_once("banana/banana.inc.php");
 
-$opt = getopt('u:p:h');
+$opt = getopt('u:P:p:hfr:');
 
 if(isset($opt['h'])) {
     echo <<<EOF
-usage: spoolgen.php [ -u user ] [ -p pass ]
+usage: spoolgen.php [-h] [-f] [ -u user ] [ -p pass ] [ -P port ] [ -r spool_root ]
     create all spools, using user user and pass pass
+    if -f is set, also refresh the RSS feed
 EOF;
     exit;
 }
 
-class MyBanana extends Banana
-{
-    public function __construct()
-    {
-        global $opt;
-        Banana::$host = "news://{$opt['u']}:{$opt['p']}@localhost:119/\n";
-        echo Banana::$host;
-        parent::__construct();
-    }
-
-    private function checkErrors()
-    {
-        if (Banana::$protocole->lastErrno()) {
-            echo "\nL'erreur suivante s'est produite : "
-                . Banana::$protocole->lastErrno() . " "
-                . Banana::$protocole->lastError() . "\n";
-            exit;
-        }
-    }
-
-    public function createAllSpool()
-    {
-        $this->checkErrors();
-        $groups = Banana::$protocole->getBoxList();
-        $this->checkErrors();
-
-        foreach (array_keys($groups) as $g) {
-            print "Generating spool for $g : ";
-            Banana::$group = $g;
-            $spool = $this->loadSpool($g);
-            $this->checkErrors();
-            print "done.\n";
-            unset($spool);
-        }
-    }
+if (!isset($opt['P'])) {
+    $opt['P'] = '119';
 }
 
-
-$banana = new MyBanana();
-$banana->createAllSpool();
-
+Banana::$nntp_host = "news://{$opt['u']}:{$opt['p']}@localhost:{$opt['P']}/\n";
+if (isset($opt['r'])) {
+    Banana::$spool_root = $opt['r'];
+}
+if (isset($opt['f'])) {
+    Banana::createAllSpool(array('NNTP'));
+} else {
+    Banana::refreshAllFeeds(array('NNTP'));
+}
 // vim:set et sw=4 sts=4 ts=4
 ?>