+++ /dev/null
-<?php
-/********************************************************************************
-* article.php : article page
-* -------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once("include/banana.inc.php");
-require_once("include/header.inc.php");
-
-if (isset($_REQUEST['group'])) {
- $group = htmlentities(strtolower($_REQUEST['group']));
-}
-if (isset($_REQUEST['id'])) {
- $id = htmlentities(strtolower($_REQUEST['id']));
-}
-
-echo $banana->action_showArticle($group, $id);
-
-if (isset($_GET['type']) && $_GET['type']=='cancel' && $banana->post->checkcancel()) {
-?>
-<p class="error">
- <?php echo _b_('Voulez-vous vraiment annuler ce message ?'); ?>
-</p>
-<form action="thread.php" method="post">
- <input type="hidden" name="group" value="<?php echo $group; ?>" />
- <input type="hidden" name="id" value="<?php echo $id; ?>" />
- <input type="hidden" name="type" value="cancel" />
- <input type="submit" name="action" value="<?php echo _b_('OK'); ?>" />
-</form>
-<?
-}
-
-require_once("include/footer.inc.php");
-?>
banana.inc.php
-error.inc.php
footer.inc.php
-format.inc.php
header.inc.php
profile_form.inc.php
profile.inc.php
* 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;
var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', '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;
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 = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
+ . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
+ . '<input type="hidden" name="action" value="cancel" />'
+ . '<input type="submit" value="Annuler !" />'
+ . '</p></form>';
+ return $form.$res;
+ }
+ return $res;
+
+ case 'new':
+ return $banana->action_newFup($group, $artid);
+ }
+ }
+ return $res . $banana->action_showArticle($group, $artid);
+ }
}
/**************************************************************************/
function action_listGroups()
{
- $this->newGroup();
+ $this->_newGroup();
$cuts = displayshortcuts();
$res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups->to_html();
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);
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);
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 '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
+ }
+ $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 '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
+ }
+ }
+
function action_newFup($group, $id = -1)
{
$subject = $body = '';
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, "> ");
$cuts = displayshortcuts();
$html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
- $html .= '<form action="?" method="post">';
+ $html .= '<form action="?group='.$group.'" method="post">';
$html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
$html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
$html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile['name']).'</td></tr>';
$html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
$html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
- $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="newsgroups" value="" size="60" /></td></tr>';
+ $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
$html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile['org'].'</td></tr>';
$html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
$html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
.htmlentities($body).($this->profile['sig'] ? "\n\n-- \n".htmlentities($this->profile['sig']) : '').'</textarea></td></th>';
- $html .= '<tr><td colspan="2"><input type="hidden" name="group" value="'.$group.'" />';
+ $html .= '<tr><td colspan="2">';
if ($id > 0) {
- $html .= '<input type="hidden" name="id" value="'.$id.'" />';
+ $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
}
+ $html .= '<input type="hidden" name="action" value="new" />';
$html .= '<input type="submit" /></td></tr>';
$html .= '</table></form>';
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 "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$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);
}
}
- /**************************************************************************/
- /* */
- /**************************************************************************/
-
function _setupProfile()
{
if (function_exists('hook_getprofile')) {
}
}
-$banana = new Banana;
-
?>
} elseif ($this->type == BANANA_GROUP_SUB) {
$html .= '<td class="new">'.($new ? $new : '-').'</td>';
}
- $html .= "<td class='grp'><a href='thread.php?group=$g'>$g</a></td><td class='dsc'>{$d[0]}</td></tr>";
+ $html .= "<td class='grp'><a href='?group=$g'>$g</a></td><td class='dsc'>{$d[0]}</td></tr>";
}
$html .= '</table>';
* 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))); }
/********************************************************************************
$res = "";
$groups = preg_split("/[\t ]*,[\t ]*/",$_text);
foreach ($groups as $g) {
- $res.="<a href='thread.php?group=$g'>$g</a>, ";
+ $res.="<a href='?group=$g'>$g</a>, ";
}
return substr($res,0, -2);
$p = $banana->spool->overview[$p]->parent;
}
foreach (array_reverse($par_ok) as $p) {
- $rsl .= "<a href=\"article.php?group={$banana->spool->group}&id=$p\">$ndx</a> ";
+ $rsl .= "<a href=\"?group={$banana->spool->group}&artid=$p\">$ndx</a> ";
$ndx++;
}
return $rsl;
function displayshortcuts($first = -1) {
global $banana;
- $sname = basename($_SERVER['SCRIPT_NAME']);
$res = '<div class="banana_scuts">';
$res .= hook_displayshortcuts($sname, $first);
}
- switch ($sname) {
- case 'thread.php' :
- $res .= '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
- $res .= "[<a href=\"post.php?group={$banana->spool->group}\">"._b_('Nouveau message')."</a>] ";
- 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 .= "[<a href=\"?group={$banana->spool->group}&first="
- ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))
- ."</a>] ";
- }
+ extract($banana->state);
+
+ $res .= '[<a href="?">'._b_('Liste des forums').'</a>] ';
+ if (is_null($group)) {
+ return $res.'</div>';
+ }
+
+ $res .= "[<a href=\"?group=$group\">$group</a>] ";
+
+ if (is_null($artid)) {
+ $res .= "[<a href=\"?group=$group&action=new\">"._b_('Nouveau message')."</a>] ";
+ if (sizeof($banana->spool->overview)>$banana->tmax) {
+ $res .= '<br />';
+ $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 = "[<a href=\"?group=$group&first=$ndx\">%0{$n}u-%0{$n}u</a>] ";
}
+ $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
}
- break;
- case 'article.php' :
- $res .= '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
- $res .= "[<a href=\"thread.php?group={$banana->spool->group}\">{$banana->spool->group}</a>] ";
- $res .= "[<a href=\"post.php?group={$banana->spool->group}&id={$banana->post->id}&type=followup\">"
- ._b_('Répondre')."</a>] ";
- if ($banana->post->checkcancel()) {
- $res .= "[<a href=\"article.php?group={$banana->spool->group}&id={$banana->post->id}&type=cancel\">"
- ._b_('Annuler ce message')."</a>] ";
- }
- break;
- case 'post.php' :
- $res .= '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
- $res .= "[<a href=\"thread.php?group={$banana->spool->group}\">{$banana->spool->group}</a>]";
- break;
+ }
+ } else {
+ $res .= "[<a href=\"?group=$group&artid=$artid&action=new\">"
+ ._b_('Répondre')."</a>] ";
+ if ($banana->post->checkcancel()) {
+ $res .= "[<a href=\"?group=$group&artid=$artid&action=cancel\">"
+ ._b_('Annuler ce message')."</a>] ";
+ }
}
- $res .= '</div>';
-
- return $res;
+ return $res.'</div>';
}
/********************************************************************************
$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'])) {
function checkcancel()
{
+ return true;
if (function_exists('hook_checkcancel')) {
return hook_checkcancel($this->headers);
}
if ($_index == $_ref) {
$res .= '<span class="cur">'.htmlentities($this->overview[$_id]->subject).'</span>';
} else {
- $res .= "<a href='article.php?group={$this->group}&id=$_id'>".htmlentities($this->overview[$_id]->subject).'</a>';
+ $res .= "<a href='?group={$this->group}&artid=$_id'>".htmlentities($this->overview[$_id]->subject).'</a>';
}
$res .= "</td>\n<td class='from'>".formatFrom($this->overview[$_id]->from)."</td>\n</tr>";
********************************************************************************/
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");
?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;
+ charset=iso-8859-1">
+ <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">
+ <title>
+ Banana, a NNTP<->Web Gateway
+ </title>
+ </head>
+ <body>
+ <div class="bloc">
+<?php echo $res; ?>
+ <div class="foot">
+ <em>Banana</em>, a Web interface for a NNTP Server<br />
+ Developed under GPL License for <a href="http://www.polytechnique.org">Polytechnique.org</a>
+ </div>
+ </div>
+ </body>
+</html>
+++ /dev/null
-<?php
-/********************************************************************************
-* install.d/footer.inc.php : HTML default footer
-* --------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-?>
- </div>
- <p class="footer">
- <i>Banana</i>, a Web interface for a NNTP Server<br />
- Developed under GPL License for <a href="http://www.polytechnique.org">Polytechnique.org</a>
- </p>
- </body>
-</html>
+++ /dev/null
-<?php
-/********************************************************************************
-* install.d/header.inc.php : HTML default header
-* --------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;
- charset=iso-8859-1">
- <meta name="description" content="WebForum2/Banana">
- <link href="css/style.css" type="text/css" rel="stylesheet"
- media="screen">
- <title>
- Banana, a NNTP<->Web Gateway
- </title>
- </head>
- <body>
- <div class="bloc">
+++ /dev/null
-<?php
-/********************************************************************************
-* post.php : posting page
-* ----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once("include/banana.inc.php");
-require_once("include/header.inc.php");
-
-if (isset($_REQUEST['group'])) {
- $group = htmlentities(strtolower($_REQUEST['group']));
-}
-
-$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : -1;
-
-echo $banana->action_newFup($group, $id);
-
-require_once("include/footer.inc.php");
-?>
+++ /dev/null
-<?php
-/********************************************************************************
-* thread.php : group overview
-* ------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once("include/banana.inc.php");
-require_once("include/header.inc.php");
-
-if (isset($_REQUEST['group'])) {
- $group = htmlentities(strtolower($_REQUEST['group']));
-} else {
- $group = htmlentities(strtolower(strtok(str_replace(" ","",$_REQUEST['newsgroups']),",")));
-}
-
-if (isset($_REQUEST['id'])) {
- $id=htmlentities(strtolower($_REQUEST['id']));
-}
-
-echo $banana->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 = "<p class=\"normal\">"._b_('Message annulé')."</p>";
- } else {
- $text = "<p class=\"error\">"._b_('Impossible d\'annuler le message')."</p>";
- }
- } else {
- $text = "<p class=\"error\">\n\t"._b_('Vous n\'avez pas les permissions pour annuler ce message')."\n</p>";
- }
- 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 = "<p class=\"normal\">"._b_('Message posté')."</p>";
- } else {
- $text = "<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
- }
- 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 = "<p class=\"normal\">"._b_('Message posté')."</p>";
- } else {
- $text = "<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
- }
- break;
- }
- $_SESSION['bananapostok']=false;
- $banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']);
-}
-
-require_once("include/footer.inc.php");
-?>