From 0e25d15dfb73aa6769f8b0d136974f36f1b3619f Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Tue, 9 Jan 2007 17:01:31 +0000 Subject: [PATCH] Some improvements, and fix spoolgen.php git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@148 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/banana.inc.php.in | 6 +++--- banana/mbox.inc.php | 11 ++++------- banana/nntp.inc.php | 24 +++++++++++------------- banana/protocoleinterface.inc.php | 2 +- examples/index.php | 9 +++++---- examples/spoolgen.php | 35 ++++++++++++++++++++++------------- 6 files changed, 46 insertions(+), 41 deletions(-) diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index fadd3a7..d3e983e 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -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']) { diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index c36bb5c..c2f7d4a 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -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 diff --git a/banana/nntp.inc.php b/banana/nntp.inc.php index f1dde9d..51c5716 100644 --- a/banana/nntp.inc.php +++ b/banana/nntp.inc.php @@ -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); diff --git a/banana/protocoleinterface.inc.php b/banana/protocoleinterface.inc.php index 5962e5a..bc3e1db 100644 --- a/banana/protocoleinterface.inc.php +++ b/banana/protocoleinterface.inc.php @@ -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 */ diff --git a/examples/index.php b/examples/index.php index f05b2e5..5b19df9 100644 --- a/examples/index.php +++ b/examples/index.php @@ -8,15 +8,16 @@ ********************************************************************************/ require_once("banana/banana.inc.php"); -$res = Banana::run(); +$banana = new Banana(); +$res = $banana->run(); if ($res != "") { ?> - - + + + charset=UTF-8"> diff --git a/examples/spoolgen.php b/examples/spoolgen.php index 0ad6b52..6c2c7da 100644 --- a/examples/spoolgen.php +++ b/examples/spoolgen.php @@ -1,4 +1,4 @@ -#! /usr/bin/php4 +#!/usr/bin/php5 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(); } } -- 2.1.4