From 8d99c68397848a5533731213c76d5ad09acf21ec Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Fri, 7 Jan 2005 14:21:00 +0000 Subject: [PATCH] we are more and more standalone ! --- article.php | 37 ----------- include/.cvsignore | 2 - include/banana.inc.php.in | 157 ++++++++++++++++++++++++++++++++++++++-------- include/groups.inc.php | 2 +- include/misc.inc.php | 74 +++++++++------------- include/post.inc.php | 7 ++- include/spool.inc.php | 2 +- index.php | 27 ++++++-- install.d/footer.inc.php | 16 ----- install.d/header.inc.php | 23 ------- post.php | 22 ------- thread.php | 99 ----------------------------- 12 files changed, 192 insertions(+), 276 deletions(-) delete mode 100644 article.php delete mode 100644 install.d/footer.inc.php delete mode 100644 install.d/header.inc.php delete mode 100644 post.php delete mode 100644 thread.php diff --git a/article.php b/article.php deleted file mode 100644 index d30e4c4..0000000 --- a/article.php +++ /dev/null @@ -1,37 +0,0 @@ -action_showArticle($group, $id); - -if (isset($_GET['type']) && $_GET['type']=='cancel' && $banana->post->checkcancel()) { -?> -

- -

-
- - - - -
- diff --git a/include/.cvsignore b/include/.cvsignore index 84cd208..76fc7d1 100644 --- a/include/.cvsignore +++ b/include/.cvsignore @@ -1,7 +1,5 @@ banana.inc.php -error.inc.php footer.inc.php -format.inc.php header.inc.php profile_form.inc.php profile.inc.php diff --git a/include/banana.inc.php.in b/include/banana.inc.php.in index 3758c20..ba24a05 100644 --- a/include/banana.inc.php.in +++ b/include/banana.inc.php.in @@ -7,9 +7,6 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/misc.inc.php"); -require_once("include/error.inc.php"); - class Banana { var $maxspool = 3000; @@ -33,6 +30,7 @@ class Banana var $profile = Array( 'name' => 'Anonymous ', 'sig' => '', 'org' => '', 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); + var $state = Array('group' => null, 'artid' => null); var $nntp; var $groups; var $newgroups; @@ -41,12 +39,69 @@ class Banana function Banana() { - if (function_exists('hook_banana')) { - hook_banana($this); - } - $this->_setupProfile(); require_once('include/NetNNTP.inc.php'); + $this->_setupProfile(); $this->nntp = new nntp($this->host); + +$this->profile['subscribe'][] = 'xorg.general'; +$this->profile['subscribe'][] = 'xorg.test'; +$this->profile['subscribe'][] = 'xorg.promo.x1970'; +$this->profile['lastnews'] = time() - 24*3600*7; + + } + + function run() + { + require_once("include/misc.inc.php"); + global $banana; + + $banana = new Banana(); + $group = empty($_GET['group']) ? null : strtolower($_GET['group']); + $artid = empty($_GET['artid']) ? null : strtolower($_GET['artid']); + $banana->state = Array ('group' => $group, 'artid' => $artid); + + if (is_null($group)) { + + return $banana->action_listGroups(); + + } elseif (is_null($artid)) { + + if (isset($_POST['action']) && $_POST['action'] == 'new') { + return $banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1); + } elseif (isset($_GET['action']) && $_GET['action'] == 'new') { + return $banana->action_newFup($group); + } else { + return $banana->action_showThread($group, isset($_GET['first']) ? intval($_GET['first']) : 1); + } + + } else { + + if (isset($_POST['action']) && $_POST['action']=='cancel') { + $res = $banana->action_cancelArticle($group, $artid); + } else { + $res = ''; + } + + if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'cancel': + $res .= $banana->action_showArticle($group, $artid); + if ($banana->post->checkcancel()) { + $form = '

'._b_('Voulez-vous vraiment annuler ce message ?').'

' + . "

" + . '' + . '' + . '

'; + return $form.$res; + } + return $res; + + case 'new': + return $banana->action_newFup($group, $artid); + } + } + return $res . $banana->action_showArticle($group, $artid); + } } /**************************************************************************/ @@ -55,7 +110,7 @@ class Banana function action_listGroups() { - $this->newGroup(); + $this->_newGroup(); $cuts = displayshortcuts(); $res = '

'._b_('Les forums de Banana').'

'.$cuts.$this->groups->to_html(); @@ -82,7 +137,7 @@ class Banana function action_showThread($group, $first) { - $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); if ($first > count($this->spool->overview)) { $first = count($this->spool->overview); @@ -102,8 +157,8 @@ class Banana function action_showArticle($group, $id) { - $this->newSpool($group, $this->profile['display'], $this->profile['lastnews']); - $this->newPost($id); + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newPost($id); if (!$this->post) { if ($this->nntp->lasterrorcode == "423") { $this->spool->delid($id); @@ -121,6 +176,31 @@ class Banana return $res.$cuts; } + function action_cancelArticle($group, $id) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newPost($id); + $mid = array_search($id, $this->spool->ids); + + if (!$this->post->checkcancel()) { + return '

'._b_('Vous n\'avez pas les permissions pour annuler ce message').'

'; + } + $msg = 'From: '.$this->profile['name']."\n" + . "Newsgroups: $group\n" + . "Subject: cmsg $mid\n" + . $this->custom + . "Control: cancel $mid\n" + . "\n" + . "Message canceled with Banana"; + if ($this->nntp->post($msg)) { + $this->spool->delid($id); + $this->nntp->quit(); + header("Location: ?group=$group&first=$id"); + } else { + return '

'._b_('Impossible d\'annuler le message').'

'; + } + } + function action_newFup($group, $id = -1) { $subject = $body = ''; @@ -128,7 +208,7 @@ class Banana if ($id > 0) { $this->nntp->group($group); - $this->newPost($id); + $this->_newPost($id); if ($this->post) { $subject = preg_replace("/^re\s*:\s*/i", 'Re: ', $this->post->headers['subject']); $body = $this->post->name." "._b_("a écrit")." :\n".wrap($this->post->body, "> "); @@ -140,43 +220,72 @@ class Banana $cuts = displayshortcuts(); $html = '

'._b_('Nouveau message').'

'.$cuts; - $html .= '
'; + $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; - $html .= ''; + $html .= ''; $html .= ''; $html .= ''; $html .= ''; - $html .= ''; $html .= '
'._b_('En-têtes').'
'._b_('Nom').''.htmlentities($this->profile['name']).'
'._b_('Sujet').'
'._b_('Forums').'
'._b_('Suivi à').'
'._b_('Suivi à').'
'._b_('Organisation').''.$this->profile['org'].'
'._b_('Corps').'
'; + $html .= '
'; if ($id > 0) { - $html .= ''; + $html .= ''; } + $html .= ''; $html .= '
'; return $html.$cuts; } + function action_doFup($group, $artid = -1) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']); + $msg = 'From: '.$this->profile['name']."\n" + . "Newsgroups: ".$_POST['newsgroups']."\n" + . "Subject: ".$_POST['subject']."\n" + . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n") + . (empty($_POST['followup']) ? '' : 'Followup-To: '.$_POST['followup']."\n"); + + if ($artid != -1) { + require_once("include/post.inc.php"); + $post = new BananaPost($artid); + $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" ); + $msg .= "References: $refs{$post->headers['message-id']}\n"; + } + + $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap); + + if ($this->nntp->post($msg)) { + header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid")); + } else { + return "

"._b_('Impossible de poster le message')."

".$this->action_showThread($group, $artid); + } + } + /**************************************************************************/ - /* */ + /* Private functions */ /**************************************************************************/ - function newSpool($group, $disp=0, $since='') { + function _newSpool($group, $disp=0, $since='') { require_once('include/spool.inc.php'); - $this->spool = new BananaSpool($group, $disp, $since); + if (!$this->spool || $this->spool->group != $group) { + $this->spool = new BananaSpool($group, $disp, $since); + } } - function newPost($id) + function _newPost($id) { require_once("include/post.inc.php"); $this->post = new BananaPost($id); } - function newGroup() + function _newGroup() { require_once("include/groups.inc.php"); $this->groups = new BananaGroups(BANANA_GROUP_SUB); @@ -185,10 +294,6 @@ class Banana } } - /**************************************************************************/ - /* */ - /**************************************************************************/ - function _setupProfile() { if (function_exists('hook_getprofile')) { @@ -199,6 +304,4 @@ class Banana } } -$banana = new Banana; - ?> diff --git a/include/groups.inc.php b/include/groups.inc.php index 1ca719d..5f762da 100644 --- a/include/groups.inc.php +++ b/include/groups.inc.php @@ -109,7 +109,7 @@ class BananaGroups { } elseif ($this->type == BANANA_GROUP_SUB) { $html .= ''.($new ? $new : '-').''; } - $html .= "$g{$d[0]}"; + $html .= "$g{$d[0]}"; } $html .= ''; diff --git a/include/misc.inc.php b/include/misc.inc.php index 1d85354..aaad5b0 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -11,15 +11,6 @@ * MISC */ -function mtime() -{ - global $time; - list($usec, $sec) = explode(" ", microtime()); - $time[] = ((float)$usec + (float)$sec); -} - -mtime(); - function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } /******************************************************************************** @@ -66,7 +57,7 @@ function formatDisplayHeader($_header,$_text) { $res = ""; $groups = preg_split("/[\t ]*,[\t ]*/",$_text); foreach ($groups as $g) { - $res.="$g, "; + $res.="$g, "; } return substr($res,0, -2); @@ -87,7 +78,7 @@ function formatDisplayHeader($_header,$_text) { $p = $banana->spool->overview[$p]->parent; } foreach (array_reverse($par_ok) as $p) { - $rsl .= "spool->group}&id=$p\">$ndx "; + $rsl .= "spool->group}&artid=$p\">$ndx "; $ndx++; } return $rsl; @@ -148,7 +139,6 @@ function formatFrom($text) { function displayshortcuts($first = -1) { global $banana; - $sname = basename($_SERVER['SCRIPT_NAME']); $res = '
'; @@ -156,40 +146,38 @@ function displayshortcuts($first = -1) { $res .= hook_displayshortcuts($sname, $first); } - switch ($sname) { - case 'thread.php' : - $res .= '['._b_('Liste des forums').'] '; - $res .= "[spool->group}\">"._b_('Nouveau message')."] "; - if (sizeof($banana->spool->overview)>$banana->tmax) { - for ($ndx=1; $ndx<=sizeof($banana->spool->overview); $ndx += $banana->tmax) { - if ($first==$ndx) { - $res .= "[$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))."] "; - } else { - $res .= "[spool->group}&first=" - ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)) - ."] "; - } + extract($banana->state); + + $res .= '['._b_('Liste des forums').'] '; + if (is_null($group)) { + return $res.'
'; + } + + $res .= "[$group] "; + + if (is_null($artid)) { + $res .= "["._b_('Nouveau message')."] "; + if (sizeof($banana->spool->overview)>$banana->tmax) { + $res .= '
'; + $n = intval(log(count($banana->spool->overview), 10))+1; + for ($ndx=1; $ndx <= sizeof($banana->spool->overview); $ndx += $banana->tmax) { + if ($first==$ndx) { + $fmt = "[%0{$n}u-%0{$n}u] "; + } else { + $fmt = "[%0{$n}u-%0{$n}u] "; } + $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))); } - break; - case 'article.php' : - $res .= '['._b_('Liste des forums').'] '; - $res .= "[spool->group}\">{$banana->spool->group}] "; - $res .= "[spool->group}&id={$banana->post->id}&type=followup\">" - ._b_('Répondre')."] "; - if ($banana->post->checkcancel()) { - $res .= "[spool->group}&id={$banana->post->id}&type=cancel\">" - ._b_('Annuler ce message')."] "; - } - break; - case 'post.php' : - $res .= '['._b_('Liste des forums').'] '; - $res .= "[spool->group}\">{$banana->spool->group}]"; - break; + } + } else { + $res .= "[" + ._b_('Répondre')."] "; + if ($banana->post->checkcancel()) { + $res .= "[" + ._b_('Annuler ce message')."] "; + } } - $res .= ''; - - return $res; + return $res.''; } /******************************************************************************** diff --git a/include/post.inc.php b/include/post.inc.php index b892b1e..4df89da 100644 --- a/include/post.inc.php +++ b/include/post.inc.php @@ -29,7 +29,11 @@ class BananaPost $this->id = $_id; $this->_header(); - $this->body = join("\n", $banana->nntp->body($_id)); + if ($body = $banana->nntp->body($_id)) { + $this->body = join("\n", $body); + } else { + return ($this = null); + } if (isset($this->headers['content-transfer-encoding'])) { if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) { @@ -82,6 +86,7 @@ class BananaPost function checkcancel() { + return true; if (function_exists('hook_checkcancel')) { return hook_checkcancel($this->headers); } diff --git a/include/spool.inc.php b/include/spool.inc.php index f8e6788..f657d55 100644 --- a/include/spool.inc.php +++ b/include/spool.inc.php @@ -316,7 +316,7 @@ class BananaSpool if ($_index == $_ref) { $res .= ''.htmlentities($this->overview[$_id]->subject).''; } else { - $res .= "".htmlentities($this->overview[$_id]->subject).''; + $res .= "".htmlentities($this->overview[$_id]->subject).''; } $res .= "\n".formatFrom($this->overview[$_id]->from)."\n"; diff --git a/index.php b/index.php index 0864b0a..536ad30 100644 --- a/index.php +++ b/index.php @@ -8,9 +8,28 @@ ********************************************************************************/ require_once("include/banana.inc.php"); -require_once("include/header.inc.php"); +$res = Banana::run(); -echo $banana->action_listGroups(); - -require_once("include/footer.inc.php"); ?> + + + + + + + + + Banana, a NNTP<->Web Gateway + + + +
+ +
+ Banana, a Web interface for a NNTP Server
+ Developed under GPL License for Polytechnique.org +
+
+ + diff --git a/install.d/footer.inc.php b/install.d/footer.inc.php deleted file mode 100644 index d8dbd16..0000000 --- a/install.d/footer.inc.php +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/install.d/header.inc.php b/install.d/header.inc.php deleted file mode 100644 index b053b8b..0000000 --- a/install.d/header.inc.php +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - Banana, a NNTP<->Web Gateway - - - -
diff --git a/post.php b/post.php deleted file mode 100644 index ab792cb..0000000 --- a/post.php +++ /dev/null @@ -1,22 +0,0 @@ -action_newFup($group, $id); - -require_once("include/footer.inc.php"); -?> diff --git a/thread.php b/thread.php deleted file mode 100644 index 488e047..0000000 --- a/thread.php +++ /dev/null @@ -1,99 +0,0 @@ -action_showThread($group, $_REQUEST['first'] ? $_REQUEST['first'] : 1); - -if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) - && (isset($_SESSION['bananapostok'])) && ($_SESSION['bananapostok'])) -{ - switch ($_REQUEST['type']) { - case 'cancel': - $mid = array_search($id, $banana->spool->ids); - $banana->newPost($id); - - if ($banana->post && $banana->post->checkcancel()) { - $message = 'From: '.$banana->profile['name']."\n" - ."Newsgroups: $group\n" - ."Subject: cmsg $mid\n" - .$banana->custom - ."Control: cancel $mid\n" - ."\n" - ."Message canceled with Banana"; - if ($banana->nntp->post($message)) { - $banana->spool->delid($id); - $text = "

"._b_('Message annulé')."

"; - } else { - $text = "

"._b_('Impossible d\'annuler le message')."

"; - } - } else { - $text = "

\n\t"._b_('Vous n\'avez pas les permissions pour annuler ce message')."\n

"; - } - break; - - case 'new': - $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",$_REQUEST['body']); - $message = 'From: '.$banana->profile['name']."\n" - ."Newsgroups: ".str_replace(" ","", $_REQUEST['newsgroups'])."\n" - ."Subject: ".$_REQUEST['subject']."\n" - .(isset($banana->profile['org'])?"Organization: ".$banana->profile['org']."\n":"") - .($_REQUEST['followup']!=''?'Followup-To: '.$_REQUEST['followup']."\n":"") - .$banana->custom - ."\n" - .wrap($body, "", $banana->wrap); - if ($banana->nntp->post($message)) { - $text = "

"._b_('Message posté')."

"; - } else { - $text = "

"._b_('Impossible de poster le message')."

"; - } - break; - - case 'followupok': - $banana->newPost($id); - if ($banana->post) { - $refs = (isset($banana->post->headers['references'])? - $banana->post->headers['references']." ":"").$banana->post->headers['message-id']; - } - - $body = preg_replace("/\n\.[ \t\r]*\n/m","\n..\n",$_REQUEST['body']); - $message = 'From: '.$banana->profile['name']."\n" - ."Newsgroups: ".$_REQUEST['newsgroups']."\n" - ."Subject: ".$_REQUEST['subject']."\n" - .(isset($banana->profile['org'])?"Organization: ".$banana->profile['org']."\n":"") - .($_REQUEST['followup']!=''?'Followup-To: '.$_REQUEST['followup']."\n":"") - ."References: $refs\n" - .$banana->custom - .$banana->profile['customhdr'] - ."\n" - .wrap($body, "", $banana->wrap); - if ($banana->nntp->post($message)) { - $text = "

"._b_('Message posté')."

"; - } else { - $text = "

"._b_('Impossible de poster le message')."

"; - } - break; - } - $_SESSION['bananapostok']=false; - $banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); -} - -require_once("include/footer.inc.php"); -?> -- 2.1.4