From 2dbc016701058c051e51b949b72f6ff774ba8b8b Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Mon, 3 Jan 2005 08:47:25 +0000 Subject: [PATCH] 3 tons or rewrite --- article.php | 59 +++++-------- disconnect.php | 6 +- include/.cvsignore | 3 +- include/NetNNTP.inc.php | 80 +++++++----------- include/banana.inc.php.in | 97 ++++++++++++++++++++++ include/config.inc.php.in | 61 -------------- include/groups.inc.php | 65 ++++++--------- include/misc.inc.php | 71 ++++++++++++++-- include/post.inc.php | 20 ++--- include/spool.inc.php | 31 +++---- index.php | 47 ++++------- install.d/error.inc.php | 51 ------------ install.d/format.inc.php | 58 ++----------- install.d/password.inc.php | 12 --- install.d/profile.inc.php | 39 --------- post.php | 71 +++++----------- scripts/spoolgen.php | 21 +---- subscribe.php | 37 ++------- thread.php | 200 +++++++++++++++++++-------------------------- xface.php | 6 +- 20 files changed, 405 insertions(+), 630 deletions(-) create mode 100644 include/banana.inc.php.in delete mode 100644 include/config.inc.php.in delete mode 100644 install.d/error.inc.php delete mode 100644 install.d/password.inc.php delete mode 100644 install.d/profile.inc.php diff --git a/article.php b/article.php index a62311c..bca83a1 100644 --- a/article.php +++ b/article.php @@ -7,51 +7,31 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/format.inc.php"); -require_once("include/config.inc.php"); -require_once("include/NetNNTP.inc.php"); -require_once("include/spool.inc.php"); -require_once("include/post.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/password.inc.php"); -require_once("include/error.inc.php"); - -$profile = getprofile(); +require_once("include/banana.inc.php"); require_once("include/header.inc.php"); if (isset($_REQUEST['group'])) { - $group=htmlentities(strtolower($_REQUEST['group'])); + $group = htmlentities(strtolower($_REQUEST['group'])); } if (isset($_REQUEST['id'])) { - $id=htmlentities(strtolower($_REQUEST['id'])); + $id = htmlentities(strtolower($_REQUEST['id'])); } -$nntp = new nntp($news['server']); -if (!$nntp) error("nntpsock"); -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); -} -$spool = new BananaSpool($nntp,$group,$profile['display'],$profile['lastnews']); -if (!$spool) error("nntpspool"); -$nntp->group($group); +$banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); +$banana->nntp->group($group); -$post = new BananaPost($nntp,$id); +$post = new BananaPost($id); if (!$post) { - if ($nntp->lasterrorcode == "423") { - $spool->delid($id); - } - error("nntpart"); + if ($banana->nntp->lasterrorcode == "423") { + $banana->spool->delid($id); + } + error("nntpart"); } -$ndx = $spool->getndx($id); +$ndx = $banana->spool->getndx($id); ?> -

- -

+

headers))) { @@ -60,9 +40,8 @@ if (isset($_GET['type']) && ($_GET['type']=='cancel') && (checkcancel($post->hea

- - + +
@@ -80,11 +59,11 @@ summary=""> headers[$nick])) { - $res = formatdisplayheader($nick,$post->headers[$nick],$spool); + foreach ($banana->show_hdr as $hdr) { + if (isset($post->headers[$hdr])) { + $res = formatdisplayheader($hdr, $post->headers[$hdr]); if ($res) - echo "".header_translate($nick)."" + echo "".header_translate($hdr)."" ."$res\n"; } } @@ -109,7 +88,7 @@ summary=""> disp($ndx-$news['threadtop'],$ndx+$news['threadbottom'],$ndx); +$banana->spool->disp($ndx-$banana->tbefore,$ndx+$banana->tafter,$ndx); ?>
diff --git a/disconnect.php b/disconnect.php index ad08ba7..28b2b55 100644 --- a/disconnect.php +++ b/disconnect.php @@ -7,12 +7,8 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/error.inc.php"); +require_once("include/banana.inc.php"); -$profile=getprofile(); $_SESSION=array(); session_destroy(); diff --git a/include/.cvsignore b/include/.cvsignore index 3e32076..c8cf4f6 100644 --- a/include/.cvsignore +++ b/include/.cvsignore @@ -1,9 +1,8 @@ -config.inc.php +banana.inc.php error.inc.php footer.inc.php format.inc.php header.inc.php -password.inc.php profile_form.inc.php profile.inc.php session.inc.php diff --git a/include/NetNNTP.inc.php b/include/NetNNTP.inc.php index c7a592d..2e8cf0f 100644 --- a/include/NetNNTP.inc.php +++ b/include/NetNNTP.inc.php @@ -14,8 +14,6 @@ class nntp { /** socket filehandle */ var $ns; - /** debug mode */ - var $debug; /** posting allowed */ var $posting; /** last NNTP error code */ @@ -23,61 +21,22 @@ class nntp /** last NNTP error text */ var $lasterrortext; -# Socket functions - - /** get a line from server - * @return STRING - */ - - function gline() - { - if ($this->debug) { - $line = trim(fgets($this->ns, 1200)); - print "NNTP >>>> $line \n"; - return $line; - } - return trim(fgets($this->ns, 1200)); - } - - /** puts a line on server - * @param STRING $_line line to put - */ - - function pline($_line) - { - if ($this->debug) { - $dline = preg_replace("/\r\n$/", "", $_line); - $dline = preg_replace("/(\r|\n|\r\n)/", "\nNNTP <<<< ", $dline); - print "NNTP <<<< $dline \n"; - } - return fputs($this->ns, $_line, strlen($_line)); - } - /** constructor * @param $_host STRING NNTP host * @param $_timeout INTEGER socket timeout - * @param $_debug BOOLEAN debug flag (generates verbose output if on) * @param $_reader BOOLEAN sends a "MODE READER" at connection if true */ - function nntp($_host, $_timeout=120, $_debug=0, $_reader=true) + function nntp($_url, $_timeout=120, $_reader=true) { - if (preg_match("/([^:]+):([^:]+)/", $_host, $regs)) { - $host = $regs[1]; - $port = $regs[2]; - } else { - $host = $_host; - $port = 119; - } - $this->ns = fsockopen($host, $port, $errno, $errstr, $_timeout); - $this->debug = $_debug; + $url['port'] = 119; + $url = parse_url($_url); + $this->ns = fsockopen($url['host'], $url['port'], $errno, $errstr, $_timeout); if (!$this->ns) { - if ($this->debug) { - echo "ERREUR: $errno - $errstr
\n"; - } $this = false; return false; } + $result = $this->gline(); $this->posting = (substr($result, 0, 3)=="200"); if ($_reader && ($result{0}=="2")) { @@ -85,9 +44,32 @@ class nntp $result = $this->gline(); $this->posting = ($result{0}=="200"); } + if ($result{0}=="2" && $url['user'] && $url['user']!='anonymous') { + return $this->authinfo($url['user'], $url['pass']); + } return ($result{0}=="2"); } +# Socket functions + + /** get a line from server + * @return STRING + */ + + function gline() + { + return trim(fgets($this->ns, 1200)); + } + + /** puts a line on server + * @param STRING $_line line to put + */ + + function pline($_line) + { + return fputs($this->ns, $_line, strlen($_line)); + } + # strict NNTP Functions [RFC 977] # see http://www.faqs.org/rfcs/rfc977.html @@ -459,13 +441,13 @@ class nntp function xgtitle($_pattern="*") { - $pattern = preg_replace("/(\r|\n)/", "", $_pattern); + $pattern = preg_replace("/[\r\n]/", "", $_pattern); $this->pline("XGTITLE $pattern \r\n"); if (substr($this->gline(), 0, 1)!="2") return false; $result = $this->gline(); while ($result != ".") { - preg_match("/([^ \t]+)( |\t)+(.+)$/", $result, $regs); - $array[$regs[1]] = $regs[3]; + preg_match("/([^ \t]+)[ \t]+(.+)$/", $result, $regs); + $array[$regs[1]] = $regs[2]; $result = $this->gline(); } return $array; diff --git a/include/banana.inc.php.in b/include/banana.inc.php.in new file mode 100644 index 0000000..cbe4d6d --- /dev/null +++ b/include/banana.inc.php.in @@ -0,0 +1,97 @@ + 'Anonymous '', 'org' => '', + 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'lang' => 'fr', 'subscribe' => array()); + + var $nntp; + var $spool; + + function Banana() + { + if (function_exists('hook_banana')) { + hook_banana($this); + } + $this->_setupProfile(); + require_once('include/NetNNTP.inc.php'); + $this->nntp = new nntp($this->host); + } + + function newSpool($group, $disp=0, $since='') { + require_once('include/spool.inc.php'); + $this->spool = new BananaSpool($group, $disp, $since); + if (!$this->spool) { error('nntpspool'); } + } + + function _setupProfile() + { + if (function_exists('hook_getprofile')) { + $this->profile = hook_getprofile(); + } else { + session_start(); + } + + setlocale(LC_ALL, $this->profile['locale']); + } +} + +$banana = new Banana; + +if (empty($css)) { +$css = array( + 'bananashortcuts' => 'bananashortcuts', + 'bicol' => 'bicol', + 'bicoltitre' => 'bicoltitre', + 'bicolvpadd' => 'bicolvpadd', + 'pair' => 'pair', + 'impair' => 'impair', + 'bouton' => 'bouton', + 'error' => 'error', + 'normal' => 'normal', + 'total' => 'total', + 'unread' => 'unread', + 'group' => 'group', + 'description' => 'description', + 'date' => 'date', + 'subject' => 'subject', + 'from' => 'from', + 'author' => 'author', + 'nopadd' => 'nopadd', + 'overview' => 'overview', + 'tree' => 'tree' + ); +} +?> diff --git a/include/config.inc.php.in b/include/config.inc.php.in deleted file mode 100644 index 9d475dd..0000000 --- a/include/config.inc.php.in +++ /dev/null @@ -1,61 +0,0 @@ - 'bananashortcuts', - 'bicol' => 'bicol', - 'bicoltitre' => 'bicoltitre', - 'bicolvpadd' => 'bicolvpadd', - 'pair' => 'pair', - 'impair' => 'impair', - 'bouton' => 'bouton', - 'error' => 'error', - 'normal' => 'normal', - 'total' => 'total', - 'unread' => 'unread', - 'group' => 'group', - 'description' => 'description', - 'date' => 'date', - 'subject' => 'subject', - 'from' => 'from', - 'author' => 'author', - 'nopadd' => 'nopadd', - 'overview' => 'overview', - 'tree' => 'tree' - ); -?> diff --git a/include/groups.inc.php b/include/groups.inc.php index d34c96f..f5828ed 100644 --- a/include/groups.inc.php +++ b/include/groups.inc.php @@ -17,64 +17,49 @@ class BananaGroups { var $date; /** constructor - * @param $_nntp RESOURCE handle to NNTP socket */ - function BananaGroups(&$_nntp,$_type=0) { - global $profile; - $desc=$_nntp->xgtitle(); + function BananaGroups($_type=0) { + global $banana; + $desc = $banana->nntp->xgtitle(); if ($_type==1) { - $list=$_nntp->newgroups($profile['lastnews']); + $list = $banana->nntp->newgroups($banana->profile['lastnews']); } else { - $list=$_nntp->liste(); + $list = $banana->nntp->liste(); + if ($_type == 0) { + $Mylist = Array(); + foreach ($banana->profile['subscribe'] as $g) { + if (isset($list[$g])) { + $mylist[$g] = $list[$g]; + } + } + $list = $mylist; + } } - if (!$list) { + if (empty($list)) { $this->overview=array(); return false; } - if (isset($desc)) { - foreach ($desc as $g=>$d) { - if ((($_type==0) and (in_array($g,$profile['subscribe']) or !count($profile['subscribe']))) - or (($_type==1) and in_array($g,array_keys($list))) - or ($_type==2)) { - $this->overview[$g][0]=$d; - $this->overview[$g][1]=$list[$g][0]; - } - } - foreach (array_diff(array_keys($list),array_keys($desc)) as $g) { - if ((($_type==0) and (in_array($g,$profile['subscribe']) or !count($profile['subscribe']))) - or (($_type==1) and in_array($g,array_keys($list))) - or ($_type==2)) { - $this->overview[$g][0]="-"; - $this->overview[$g][1]=$list[$g][0]; - } - } - } else { - foreach ($list as $g=>$l) { - if ((($_type==0) and (!count($profile['subscribe']) and in_array($g,$profile['subscribe']))) - or (($_type==1) and in_array($g,array_keys($list))) - or ($_type==2)) { - $this->overview[$g][0]="-"; - $this->overview[$g][1]=$l[0]; - } - } + + foreach ($mylist as $g=>$l) { + $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-'; + $this->overview[$g][1] = $l[0]; } - return true; } /** updates overview - * @param $_nntp RESOURCE handle to NNTP socket * @param date INTEGER date of last update */ - function update(&$_nntp,$_date) { - $serverdate = $_nntp->date(); + function update($_date) { + global $banana; + $serverdate = $banana->nntp->date(); if (!$serverdate) $serverdate=time(); - $newlist = $_nntp->newgroups($_date); + $newlist = $banana->nntp->newgroups($_date); if (!$newlist) return false; $this->date = $serverdate; foreach (array_keys($newlist) as $g) { - $groupstat = $_nntp->group($g); - $groupdesc = $_nntp->xgtitle($g); + $groupstat = $banana->nntp->group($g); + $groupdesc = $banana->nntp->xgtitle($g); $this->overview[$g][0]=($groupdesc?$groupdesc:"-"); $this->overview[$g][1]=$groupstat[0]; } diff --git a/include/misc.inc.php b/include/misc.inc.php index 2c31e9c..767d739 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -8,12 +8,18 @@ ********************************************************************************/ /******************************************************************************** - * I18N + * MISC */ - function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); } +function checkcancel($_headers) { + if (function_exists('hook_checkcancel')) { + return hook_checkcancel($_headers); + } + return ($_headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">"); +} + /******************************************************************************** * HEADER STUFF */ @@ -40,10 +46,60 @@ function header_translate($hdr) { case 'references': return _b_('Références'); case 'x-face': return _b_('Image'); default: + if (function_exists('hook_header_translate')) { + return hook_header_translate($hdr); + } return $hdr; } } +function formatDisplayHeader($_header,$_text) { + global $banana; + switch ($_header) { + case "date": + return formatDate($_text); + + case "followup-to": + case "newsgroups": + $res = ""; + $groups = preg_split("/[\t ]*,[\t ]*/",$_text); + foreach ($groups as $g) { + $res.="$g, "; + } + return substr($res,0, -2); + + case "from": + return formatFrom($_text); + + case "references": + $rsl = ""; + $ndx = 1; + $text = str_replace("><","> <",$_text); + $text = preg_split("/[ \t]/",strtr($text,$banana->spool->ids)); + $parents = preg_grep("/^\d+$/",$text); + $p = array_pop($parents); + + while ($p) { + $valid_parents[]=$p; + $p = $banana->spool->overview[$p]->parent; + } + foreach (array_reverse($valid_parents) as $p) { + $rsl .= "spool->group}&id=$p\">$ndx "; + $ndx++; + } + return $rsl; + + case "x-face": + return 'x-face'; + + default: + if (function_exists('hook_formatDisplayHeader')) { + return hook_formatDisplayHeader($_header, $_text); + } + return htmlentities($_text); + } +} + /******************************************************************************** * FORMATTING STUFF */ @@ -87,7 +143,7 @@ function formatFrom($text) { return preg_replace("/\\\(\(|\))/","\\1",$result); } -function wrap($text, $_prefix="", $_length=72) +function wrap($text, $_prefix="") { $parts = preg_split("/\n-- ?\n/", $text); if (count($parts) >1) { @@ -97,16 +153,17 @@ function wrap($text, $_prefix="", $_length=72) $sign = ''; $text = $text; } - - $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'"; + + global $banana; + $length = $banana->wrap; + $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'"; exec($cmd, $result); return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign); } function formatbody($_text) { - global $news; - $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n"; + $res = "\n\n" . htmlentities(wrap($_text, ""))."\n\n"; $res = preg_replace("/(<|>|")/", " \\1 ", $res); $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1\\2\\4", $res); $res = preg_replace("/ (<|>|") /", "\\1", $res); diff --git a/include/post.inc.php b/include/post.inc.php index 259eb18..c63fcc8 100644 --- a/include/post.inc.php +++ b/include/post.inc.php @@ -21,15 +21,15 @@ class BananaPost var $name; /** constructor - * @param $_nntp RESOURCE handle to NNTP socket * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case) */ - function BananaPost(&$_nntp, $_id) + function BananaPost($_id) { + global $banana; $this->nb = $_id; - $this->_header($_nntp); + $this->_header(); - $this->body = join("\n", $_nntp->body($_id)); + $this->body = join("\n", $banana->nntp->body($_id)); if (isset($this->headers['content-transfer-encoding'])) { if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) { @@ -44,10 +44,10 @@ class BananaPost } } - function _header(&$_nntp) + function _header() { - global $news; - $hdrs = $_nntp->head($this->nb); + global $banana; + $hdrs = $banana->nntp->head($this->nb); if (!$hdrs) { $this = null; return false; @@ -57,19 +57,19 @@ class BananaPost foreach ($hdrs as $line) { if (preg_match("/^[\t\r ]+/", $line)) { $line = ($hdr=="X-Face"?"":" ").ltrim($line); - if (in_array($hdr, $news['head'])) { + if (in_array($hdr, $banana->parse_hdr)) { $this->headers[$hdr] .= $line; } } else { list($hdr, $val) = split(":[ \t\r]*", $line, 2); $hdr = strtolower($hdr); - if (in_array($hdr, $news['head'])) { + if (in_array($hdr, $banana->parse_hdr)) { $this->headers[$hdr] = $val; } } } // decode headers - foreach ($news['hdecode'] as $hdr) { + foreach ($banana->hdecode as $hdr) { if (isset($this->headers[$hdr])) { $this->headers[$hdr] = headerDecode($this->headers[$hdr]); } diff --git a/include/spool.inc.php b/include/spool.inc.php index 1a0a7ba..fdea6bf 100644 --- a/include/spool.inc.php +++ b/include/spool.inc.php @@ -85,22 +85,21 @@ class BananaSpool var $roots; /** constructor - * @param $_nntp RESOURCE NNTP socket filehandle * @param $_group STRING group name * @param $_display INTEGER 1 => all posts, 2 => only threads with new posts * @param $_since INTEGER time stamp (used for read/unread) */ - function BananaSpool(&$_nntp, $_group, $_display=0, $_since="") + function BananaSpool($_group, $_display=0, $_since="") { - global $news; + global $banana; $this->group = $_group; - $groupinfo = $_nntp->group($_group); + $groupinfo = $banana->nntp->group($_group); if (!$groupinfo) { return ($this = null); } $this->_readFromFile(); $do_save = false; - $first = max($groupinfo[2]-$news['maxspool'], $groupinfo[1]); + $first = $banana->maxspool ? max($groupinfo[2]-$banana->maxspool, $groupinfo[1]) : $groupinfo[1]; $last = $groupinfo[2]; if ($this->version == BANANA_SPOOL_VERSION) { for ($id = min(array_keys($this->overview)); $id<$first; $id++) { @@ -115,12 +114,12 @@ class BananaSpool if ($first<=$last && $groupinfo[0]) { $do_save = true; - $this->_updateSpool($_nntp, "$first-$last"); + $this->_updateSpool("$first-$last"); } if ($do_save) { $this->_saveToFile(); } - $this->_updateUnread($_nntp, $_since, $_display); + $this->_updateUnread($_since, $_display); } function _readFromFile() @@ -146,13 +145,14 @@ class BananaSpool file_put_contents($file, serialize($this)); } - function _updateSpool(&$_nntp, $arg) + function _updateSpool($arg) { - $dates = array_map(strtotime, $_nntp->xhdr("Date", $arg)); - $subjects = array_map(headerdecode, $_nntp->xhdr("Subject", $arg)); - $froms = array_map(headerdecode, $_nntp->xhdr("From", $arg)); - $msgids = $_nntp->xhdr("Message-ID", $arg); - $refs = $_nntp->xhdr("References", $arg); + global $banana; + $dates = array_map(strtotime, $banana->nntp->xhdr("Date", $arg)); + $subjects = array_map(headerdecode, $banana->nntp->xhdr("Subject", $arg)); + $froms = array_map(headerdecode, $banana->nntp->xhdr("From", $arg)); + $msgids = $banana->nntp->xhdr("Message-ID", $arg); + $refs = $banana->nntp->xhdr("References", $arg); if (is_array($this->ids)) { $this->ids = array_merge($this->ids, array_flip($msgids)); @@ -188,11 +188,12 @@ class BananaSpool } } - function _updateUnread(&$nntp, $since, $mode) + function _updateUnread($since, $mode) { + global $banana; if (empty($since)) { return; } - if (is_array($newpostsids = $nntp->newnews($since, $this->group))) { + if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) { $newpostsids = array_intersect($newpostsids, array_keys($this->ids)); foreach ($newpostsids as $mid) { $this->overview[$this->ids[$mid]]->isread = false; diff --git a/index.php b/index.php index 38a0de2..973e4db 100644 --- a/index.php +++ b/index.php @@ -7,29 +7,16 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/password.inc.php"); -require_once("include/NetNNTP.inc.php"); -require_once("include/groups.inc.php"); -require_once("include/format.inc.php"); -require_once("include/config.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/error.inc.php"); - -$profile=getprofile(); +require_once("include/banana.inc.php"); require_once("include/header.inc.php"); -$nntp = new nntp($news['server']); -if (!$nntp) error("nntpsock"); -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); +$groups = new BananaGroups(0); +if (!count($groups->overview)) { + $groups = new BananaGroups(2); +} else { + $newgroups = new BananaGroups(1); } -$groups = new BananaGroups($nntp,0); -if (!count($groups->overview)) $groups = new BananaGroups($nntp,2); - -$newgroups = new BananaGroups($nntp,1); + ?>

@@ -60,9 +47,9 @@ displayshortcuts(); overview as $g => $d) { - $pair = !$pair; - $groupinfo = $nntp->group($g); - $newarts = $nntp->newnews($profile['lastnews'],$g); + $pair = !$pair; + $groupinfo = $banana->nntp->group($g); + $newarts = $banana->nntp->newnews($banana->profile['lastnews'],$g); ?> " > "> @@ -83,7 +70,7 @@ foreach ($groups->overview as $g => $d) { ?> overview) and count($profile['subscribe'])) { +if (count($newgroups->overview) and count($banana->profile['subscribe'])) { ?>

@@ -101,10 +88,10 @@ if (count($newgroups->overview) and count($profile['subscribe'])) { overview as $g => $d) { - $pair = !$pair; - $groupinfo = $nntp->group($g); + $pair = true; + foreach ($newgroups->overview as $g => $d) { + $pair = !$pair; + $groupinfo = $banana->nntp->group($g); ?> " > "> @@ -118,7 +105,7 @@ if (count($newgroups->overview) and count($profile['subscribe'])) { overview) and count($profile['subscribe'])) { displayshortcuts(); -$nntp->quit(); +$banana->nntp->quit(); require_once("include/footer.inc.php"); ?> diff --git a/install.d/error.inc.php b/install.d/error.inc.php deleted file mode 100644 index 2c66ba0..0000000 --- a/install.d/error.inc.php +++ /dev/null @@ -1,51 +0,0 @@ -'._b_('Impossible de se connecter au serveur de forums').'

'; - require_once("include/footer.inc.php"); - exit; - - case "nntpauth": - echo '

'._b_('L\'authentification sur le serveur de forums a échoué').'

'; - require_once("include/footer.inc.php"); - exit; - - case "nntpgroups": - echo "

"; - echo _b_('Il n\'y a pas de forum sur ce serveur').'

'; - require_once("include/footer.inc.php"); - exit; - - case "nntpspool": - echo "
\n"; - echo "[Liste des forums]\n"; - echo "
\n"; - echo '

'._b_('Impossible d\'accéder au forum').'

'; - require_once("footer.inc.php"); - exit; - - case "nntpart": - echo "
\n"; - echo "[Liste des forums] \n"; - echo "[$group] \n"; - echo "
\n"; - echo '

'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'

'; - require_once("footer.inc.php"); - exit; - } -} - -?> diff --git a/install.d/format.inc.php b/install.d/format.inc.php index cfd7d6c..1991bec 100644 --- a/install.d/format.inc.php +++ b/install.d/format.inc.php @@ -7,60 +7,12 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -/** produces HTML ouput for header section in post.php - * @param $_header STRING name of the header - * @param $_text STRING value of the header - * @param $_spool OBJECT spool object for building references - * @return STRING HTML output - */ - -function formatDisplayHeader($_header,$_text,$_spool) { - switch ($_header) { - case "date": - return formatDate($_text); - - case "followup-to": - case "newsgroups": - $res = ""; - $groups = preg_split("/(\t| )*,(\t| )*/",$_text); - foreach ($groups as $g) { - $res.=''.$g.', '; - } - return substr($res,0, -2); - - case "from": - return formatFrom($_text); - - case "references": - $rsl = ""; - $ndx = 1; - $text=str_replace("><","> <",$_text); - $text=preg_split("/( |\t)/",strtr($text,$_spool->ids)); - $parents=preg_grep("/^\d+$/",$text); - $p=array_pop($parents); - while ($p) { - $rsl .= "group}" - ."&id=$p\">$ndx "; - $_spool->overview[$p]->desc++; - $p = $_spool->overview[$p]->parent; - $ndx++; - } - return $rsl; - - case "x-face": - return 'x-face'; - - default: - return htmlentities($_text); - } -} /** contextual links * @return STRING HTML output */ function displayshortcuts() { - global $news,$first,$spool,$group,$post,$id; + global $banana,$first,$group,$post,$id; $sname = basename($_SERVER['SCRIPT_NAME']); echo '
'; @@ -70,13 +22,13 @@ function displayshortcuts() { case 'thread.php' : echo '['._b_('Liste des forums').'] '; echo "["._b_('Nouveau message')."] "; - if (sizeof($spool->overview)>$news['max']) { - for ($ndx=1; $ndx<=sizeof($spool->overview); $ndx += $news['max']) { + if (sizeof($banana->spool->overview)>$banana->tmax) { + for ($ndx=1; $ndx<=sizeof($banana->spool->overview); $ndx += $banana->tmax) { if ($first==$ndx) { - echo "[$ndx-".min($ndx+$news['max']-1,sizeof($spool->overview))."] "; + echo "[$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))."] "; } else { echo "[$ndx-".min($ndx+$news['max']-1,sizeof($spool->overview)) + ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)) ."] "; } } diff --git a/install.d/password.inc.php b/install.d/password.inc.php deleted file mode 100644 index a68be19..0000000 --- a/install.d/password.inc.php +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/install.d/profile.inc.php b/install.d/profile.inc.php deleted file mode 100644 index 5f5951b..0000000 --- a/install.d/profile.inc.php +++ /dev/null @@ -1,39 +0,0 @@ -"); -} - -/** getprofile : sets profile variables - * @return ARRAY associative array. Keys are 'name' (name), 'sig' (signature), 'org' - * (organization), 'display' (display threads with new posts only or all threads), - * 'lastnews' (timestamp for empasizing new posts) - */ - -function getprofile() { - $array['name'] = $_SESSION['name']." <".htmlentities($_SESSION['mail']).">"; - $array['sig'] = $_SESSION['sig']; - $array['org'] = $_SESSION['org']; - $array['customhdr'] = ""; - $array['display'] = $_SESSION['displaytype']; - $array['lastnews'] = time()-86400; - $array['locale'] = 'fr'; - $array['subscribe'] = array(); - $array['dropsig'] = true; - - setlocale(LC_MESSAGE, $array['locale']); - setlocale(LC_TIME, $array['locale']); - return $array; -} -?> diff --git a/post.php b/post.php index b15ab66..fc741e7 100644 --- a/post.php +++ b/post.php @@ -7,62 +7,32 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/format.inc.php"); -require_once("include/config.inc.php"); -require_once("include/NetNNTP.inc.php"); -require_once("include/post.inc.php"); -require_once("include/spool.inc.php"); -require_once("include/password.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/error.inc.php"); - -$profile = getprofile(); +require_once("include/banana.inc.php"); require_once("include/header.inc.php"); + if (isset($_REQUEST['group'])) { - $group=htmlentities(strtolower($_REQUEST['group'])); + $group = htmlentities(strtolower($_REQUEST['group'])); } if (isset($_REQUEST['id'])) { - $id=htmlentities(strtolower($_REQUEST['id'])); + $id = htmlentities(strtolower($_REQUEST['id'])); } if (isset($group)) { $target = $group; } -$nntp = new nntp($news['server']); -if (!$nntp) error("nntpsock"); -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); -} - -if (isset($group) && isset($id) && isset($_REQUEST['type']) && - ($_REQUEST['type']=='followup')) { - $rq=$nntp->group($group); - $post = new BananaPost($nntp,$id); +if (isset($group) && isset($id) && isset($_REQUEST['type']) && ($_REQUEST['type']=='followup')) { + $rq = $banana->nntp->group($group); + $post = new BananaPost($id); + $body = ''; if ($post) { - $subject = (preg_match("/^re:/i",$post->headers['subject'])?"":"Re: ").$post->headers['subject']; - if ($profile['dropsig']) { - $cutoff=strpos($post->body,"\n-- \n"); - if ($cutoff) { - $quotetext = substr($post->body,0,strpos($post->body,"\n-- \n")); - } else { - $quotetext = $post->body; - } - } else { - $quotetext = $post->body; - } - $body = $post->name." wrote :\n".wrap($quotetext, "> "); - if (isset($post->headers['followup-to'])) - $target = $post->headers['followup-to']; - else - $target = $post->headers['newsgroups']; + $subject = (preg_match("/^re\s*:\s*/i", $post->headers['subject']) ? '' : 'Re: ').$post->headers['subject']; + $body = $post->name." wrote :\n".wrap($post->body, "> "); + $target = isset($post->headers['followup-to']) ? $post->headers['followup-to'] : $post->headers['newsgroups']; } } -$nntp->quit(); +$banana->nntp->quit(); ?>

@@ -85,7 +55,7 @@ displayshortcuts(); - + profile['name']); ?> @@ -93,8 +63,7 @@ displayshortcuts(); - " /> + @@ -102,8 +71,7 @@ displayshortcuts(); - " /> + @@ -119,7 +87,7 @@ displayshortcuts(); - + profile['org']; ?> @@ -129,9 +97,10 @@ displayshortcuts(); - + diff --git a/scripts/spoolgen.php b/scripts/spoolgen.php index 25cb05d..5a11304 100644 --- a/scripts/spoolgen.php +++ b/scripts/spoolgen.php @@ -19,29 +19,14 @@ require_once("include/spool.inc.php"); require_once("include/password.inc.php"); -$nntp = new nntp($news['server']); -if (!$nntp) { - print "cannot connect to server\n"; - exit; -} - -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) { - print "authentication error\n"; - exit; - } -} -unset($result); - -$groups = new BananaGroups($nntp,2); +$groups = new BananaGroups(2); $list = array_keys($groups->overview); unset($groups); foreach ($list as $g) { print "Generating spool for $g : "; - $spool = new BananaSpool($nntp,$g); + $spool = new BananaSpool($g); print "done.\n"; unset($spool); } -$nntp->quit(); +$banana->nntp->quit(); ?> diff --git a/subscribe.php b/subscribe.php index 6f421e6..1892545 100644 --- a/subscribe.php +++ b/subscribe.php @@ -7,27 +7,10 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/password.inc.php"); -require_once("include/NetNNTP.inc.php"); -require_once("include/groups.inc.php"); -require_once("include/format.inc.php"); -require_once("include/config.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/subscribe.inc.php"); -require_once("include/error.inc.php"); - -$profile=getprofile(); +require_once("include/banana.inc.php"); require_once("include/header.inc.php"); -$nntp = new nntp($news['server']); -if (!$nntp) error("nntpsock"); -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); -} -$groups = new BananaGroups($nntp,2); +$groups = new BananaGroups(2); ?>

@@ -36,10 +19,9 @@ $groups = new BananaGroups($nntp,2); profile['subscribe']=$_POST['subscribe']; } if (!sizeof($groups->overview)) error("nntpgroups"); @@ -67,8 +49,8 @@ displayshortcuts(); $pair = true; foreach ($groups->overview as $g => $d) { $pair = !$pair; - $groupinfo = $nntp->group($g); - $newarts = $nntp->newnews($profile['lastnews'],$g); + $groupinfo = $banana->nntp->group($g); + $newarts = $banana->nntp->newnews($banana->profile['lastnews'], $g); ?> " > "> @@ -76,8 +58,7 @@ foreach ($groups->overview as $g => $d) { "> /> + profile['subscribe']) echo 'checked="checked"'; ?> /> "> $g";?> @@ -100,6 +81,6 @@ foreach ($groups->overview as $g => $d) { displayshortcuts(); -$nntp->quit(); +$banana->nntp->quit(); require_once("include/footer.inc.php"); ?> diff --git a/thread.php b/thread.php index 4f9e53b..0d52e6a 100644 --- a/thread.php +++ b/thread.php @@ -7,134 +7,106 @@ * Copyright: See COPYING files that comes with this distribution ********************************************************************************/ -require_once("include/session.inc.php"); -require_once("include/misc.inc.php"); -require_once("include/format.inc.php"); -require_once("include/config.inc.php"); -require_once("include/NetNNTP.inc.php"); -require_once("include/post.inc.php"); -require_once("include/spool.inc.php"); -require_once("include/password.inc.php"); -require_once("include/profile.inc.php"); -require_once("include/error.inc.php"); - -$profile=getprofile(); +require_once("include/banana.inc.php"); require_once("include/header.inc.php"); if (isset($_REQUEST['group'])) { - $group=htmlentities(strtolower($_REQUEST['group'])); + $group = htmlentities(strtolower($_REQUEST['group'])); } else { - $group=htmlentities(strtolower(strtok(str_replace(" ","",$_REQUEST['newsgroups']),","))); + $group = htmlentities(strtolower(strtok(str_replace(" ","",$_REQUEST['newsgroups']),","))); } if (isset($_REQUEST['id'])) { - $id=htmlentities(strtolower($_REQUEST['id'])); + $id=htmlentities(strtolower($_REQUEST['id'])); } -//$nntp = new nntp($news['server'],120,1); -$nntp = new nntp($news['server']); -if (!$nntp) error("nntpsock"); -if ($news['user']!="anonymous") { - $result = $nntp->authinfo($news["user"],$news["pass"]); - if (!$result) error("nntpauth"); +$banana->newSpool($group, $banana->profile['display'], $banana->profile['lastnews']); +$max = $banana->tmax; +if (isset($_REQUEST['first']) && ($_REQUEST['first']>sizeof($banana->spool->overview))) { + $_REQUEST['first'] = sizeof($banana->spool->overview); } -$spool = new BananaSpool($nntp,$group,$profile['display'], $profile['lastnews']); -if (!$spool) error("nntpspool"); -$max = 50; -if (isset($_REQUEST['first']) && ($_REQUEST['first']>sizeof($spool->overview))) - $_REQUEST['first']=sizeof($spool->overview); -$first = (isset($_REQUEST['first'])? - (floor($_REQUEST['first']/$max)*$max+1):1); -$last = (isset($_REQUEST['first'])? - (floor($_REQUEST['first']/$max+1)*$max):$max); +$first = (isset($_REQUEST['first']) ? (floor($_REQUEST['first']/$max)*$max+1) : 1); +$last = (isset($_REQUEST['first']) ? (floor($_REQUEST['first']/$max+1)*$max) : $max); + +if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) + && (isset($_SESSION['bananapostok'])) && ($_SESSION['bananapostok'])) +{ + switch ($_REQUEST['type']) { + case 'cancel': + $banana->nntp->group($group); + $mid = array_search($id, $banana->spool->ids); + $post = new BananaPost($id); + + if (checkcancel($post->headers)) { + $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; -if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) && -(isset($_SESSION['bananapostok'])) && ($_SESSION['bananapostok'])) { - switch ($_REQUEST['type']) { - case 'cancel': - $mid = array_search($id,$spool->ids); - $nntp->group($group); - $post = new BananaPost($nntp,$id); - - if (checkcancel($post->headers)) { - $message = 'From: '.$profile['name']."\n" - ."Newsgroups: $group\n" - ."Subject: cmsg $mid\n" - .$news['customhdr'] - ."Control: cancel $mid\n" - ."\n" - ."Message canceled with Banana"; - $result = $nntp->post($message); - if ($result) { - $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: '.$profile['name']."\n" - ."Newsgroups: ".str_replace(" ","", $_REQUEST['newsgroups'])."\n" - ."Subject: ".$_REQUEST['subject']."\n" - .(isset($profile['org'])?"Organization: ".$profile['org']."\n":"") - .($_REQUEST['followup']!=''?'Followup-To: ' - .$_REQUEST['followup']."\n":"") - .$news['customhdr'] - ."\n" - .wrap($body,"",$news['wrap']); - $result = $nntp->post($message); - if ($result) { - $text="

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

"; - } else { - $text="

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

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

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

"; - } else { - $text="

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

"; - } - break; - } - $_SESSION['bananapostok']=false; - $spool = new BananaSpool($nntp,$group,$profile['display'], $profile['lastnews']); - if (!$spool) error("nntpspool"); -} + } + $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']); +} ?> -

- -

+

@@ -152,8 +124,8 @@ displayshortcuts(); disp($first,$last); -$nntp->quit(); +$banana->spool->disp($first, $last); +$banana->nntp->quit(); echo ""; displayshortcuts(); diff --git a/xface.php b/xface.php index 98078c3..802254e 100644 --- a/xface.php +++ b/xface.php @@ -1,9 +1,5 @@ -- 2.1.4