3 tons or rewrite
authorx2000habouzit <x2000habouzit>
Mon, 3 Jan 2005 08:47:25 +0000 (08:47 +0000)
committerx2000habouzit <x2000habouzit>
Mon, 3 Jan 2005 08:47:25 +0000 (08:47 +0000)
20 files changed:
article.php
disconnect.php
include/.cvsignore
include/NetNNTP.inc.php
include/banana.inc.php.in [new file with mode: 0644]
include/config.inc.php.in [deleted file]
include/groups.inc.php
include/misc.inc.php
include/post.inc.php
include/spool.inc.php
index.php
install.d/error.inc.php [deleted file]
install.d/format.inc.php
install.d/password.inc.php [deleted file]
install.d/profile.inc.php [deleted file]
post.php
scripts/spoolgen.php
subscribe.php
thread.php
xface.php

index a62311c..bca83a1 100644 (file)
@@ -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);
 
 ?>
-<h1>
-  <?php echo _b_('Message'); ?>
-</h1>
+<h1><?php echo _b_('Message'); ?></h1>
 
 <?php
 if (isset($_GET['type']) && ($_GET['type']=='cancel') && (checkcancel($post->headers))) {
@@ -60,9 +40,8 @@ if (isset($_GET['type']) && ($_GET['type']=='cancel') && (checkcancel($post->hea
   <?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="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>
@@ -80,11 +59,11 @@ summary="<?php echo _b_('Contenu du message'); ?>">
     </th>
   </tr>
 <?php
-    foreach ($news['headdisp'] as $nick) {
-        if (isset($post->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 "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($nick)."</td>"
+                echo "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($hdr)."</td>"
                     ."<td>$res</td></tr>\n";
         }
     }
@@ -109,7 +88,7 @@ summary="<?php echo _b_('Contenu du message'); ?>">
       <table class="<?php echo $css['overview']?>" cellpadding="0" 
       cellspacing="0" summary="overview">
 <?php
-$spool->disp($ndx-$news['threadtop'],$ndx+$news['threadbottom'],$ndx);
+$banana->spool->disp($ndx-$banana->tbefore,$ndx+$banana->tafter,$ndx);
 ?>
       </table>
     </td>
index ad08ba7..28b2b55 100644 (file)
@@ -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();
 
index 3e32076..c8cf4f6 100644 (file)
@@ -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
index c7a592d..2e8cf0f 100644 (file)
@@ -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 <br />\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 (file)
index 0000000..cbe4d6d
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+/********************************************************************************
+* install.d/config.inc.php : configuration file
+* --------------------------
+*
+* This file is part of the banana distribution
+* Copyright: See COPYING files that comes with this distribution
+********************************************************************************/
+
+require_once("include/session.inc.php");
+require_once("include/misc.inc.php");
+require_once("include/groups.inc.php");
+require_once("include/format.inc.php");
+require_once("include/error.inc.php");
+require_once("include/post.inc.php");
+
+class Banana
+{
+    var $maxspool  = 3000;
+
+    var $hdecode   = array('from','name','organization','subject');
+    var $parse_hdr = array('content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
+            'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
+    var $show_hdr  = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
+
+
+    var $tbefore   = 5;
+    var $tafter    = 5;
+    var $tmax      = 50;
+
+    var $wrap      = 74;
+
+    var $custom    = "Content-Type: text/plain; charset=iso-8859-15\nMime-Version: 1.0\nContent-Transfer-Encoding: 8bit\nUser-Agent: Banana @VERSION@\n";
+
+    var $host      = 'news://localhost:119/';
+
+    var $profile   = Array( 'name' => 'Anonymous <anonymouse@example.com', 'sig'  => '', '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 (file)
index 9d475dd..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/********************************************************************************
-* install.d/config.inc.php : configuration file
-* --------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-// spool config in spool.inc.php
-$news['maxspool'] = 3000;
-
-// encoded headers
-$news['hdecode'] = array('from','name','organization','subject');
-
-// headers in article.php
-$news['head'] = array('content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
-        'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
-
-$news['headdisp'] = array('date', 'followup-to', 'from', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
-
-// overview configuration in article.php
-$news['threadtop'] = 5;
-$news['threadbottom'] = 5;
-
-// wordwrap configuration
-$news['wrap'] = 74;
-
-// overview configuration in thread.php
-$news['max'] = 50;
-
-// custom headers in post.php
-$news['customhdr'] = "Content-Type: text/plain; charset=iso-8859-15\n"
-."Mime-Version: 1.0\n"
-."Content-Transfer-Encoding: 8bit\n"
-."HTTP-Posting-Host: ".gethostbyname($_SERVER['REMOTE_ADDR'])."\n"
-."User-Agent: Banana @VERSION@\n";
-
-$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'
-        );
-?>
index d34c96f..f5828ed 100644 (file)
@@ -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];
         }
index 2c31e9c..767d739 100644 (file)
@@ -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.="<a href='thread.php?group=$g'>$g</a>, ";
+            }
+            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 .= "<a href=\"article.php?group={$banana->spool->group}&amp;id=$p\">$ndx</a> ";
+                $ndx++;
+            }
+            return $rsl;
+
+        case "x-face":
+            return '<img src="xface.php?face='.base64_encode($_text).'"  alt="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("/(&lt;|&gt;|&quot;)/", " \\1 ", $res);
     $res  = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
     $res  = preg_replace("/ (&lt;|&gt;|&quot;) /", "\\1", $res);
index 259eb18..c63fcc8 100644 (file)
@@ -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]);
             }
index 1a0a7ba..fdea6bf 100644 (file)
@@ -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;
index 38a0de2..973e4db 100644 (file)
--- 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);
+
 ?>
 
 <h1>
@@ -60,9 +47,9 @@ displayshortcuts();
 <?php
 $pair = true;
 foreach ($groups->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);
 ?>
   <tr class="<?php echo ($pair?$css["pair"]:$css["impair"]);?>" >
     <td class="<?php echo $css["total"]; ?>">
@@ -83,7 +70,7 @@ foreach ($groups->overview as $g => $d) {
 ?>
 </table>
 <?php
-if (count($newgroups->overview) and count($profile['subscribe'])) {
+if (count($newgroups->overview) and count($banana->profile['subscribe'])) {
 ?>
 <p class="normal">
 <?php echo _b_('Les forums suivants ont été créés depuis ton dernier passage :'); ?>
@@ -101,10 +88,10 @@ if (count($newgroups->overview) and count($profile['subscribe'])) {
     </th>
   </tr>
 <?php
-  $pair = true;
-  foreach ($newgroups->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);
 ?>
   <tr class="<?php echo ($pair?$css["pair"]:$css["impair"]);?>" >
     <td class="<?php echo $css["total"]; ?>">
@@ -118,7 +105,7 @@ if (count($newgroups->overview) and count($profile['subscribe'])) {
     </td>
   </tr>
 <?php
-  } //foreach
+    } //foreach
 ?>
 </table>
 <?php
@@ -126,6 +113,6 @@ if (count($newgroups->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 (file)
index 2c66ba0..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-/********************************************************************************
-* install.d/error.inc.php : central NNTP error messages
-* -------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-/** outputs HTML error page
- * @param $_type STRING error type
- */
-function error($_type) {
-    global $css, $group;
-    switch ($_type) {
-        case "nntpsock":
-            echo '<p class="error">'._b_('Impossible de se connecter au serveur de forums').'</p>';
-            require_once("include/footer.inc.php");
-            exit;
-
-        case "nntpauth":
-            echo '<p class="error">'._b_('L\'authentification sur le serveur de forums a échoué').'</p>';
-            require_once("include/footer.inc.php");
-            exit;
-
-        case "nntpgroups":
-            echo "<p class=\"{$css['normal']}\">";
-            echo _b_('Il n\'y a pas de forum sur ce serveur').'</p>';
-            require_once("include/footer.inc.php");
-            exit;
-
-        case "nntpspool":
-            echo "<div class=\"{$css['bananashortcuts']}\">\n";
-            echo "[<a href=\"index.php\">Liste des forums</a>]\n";
-            echo "</div>\n";
-            echo '<p class="error">'._b_('Impossible d\'accéder au forum').'</p>';
-            require_once("footer.inc.php");
-            exit;
-
-        case "nntpart":
-            echo "<div class=\"{$css['bananashortcuts']}\">\n";
-            echo "[<a href=\"index.php\">Liste des forums</a>] \n";
-            echo "[<a href=\"thread.php?group=$group\">$group</a>] \n";
-            echo "</div>\n";
-            echo '<p class="error">'._b_('Impossible d\'accéder au message.  Le message a peut-être été annulé').'</p>';
-            require_once("footer.inc.php");
-            exit;
-    }
-}
-
-?>
index cfd7d6c..1991bec 100644 (file)
@@ -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.='<a href="thread.php?group='.$g.'">'.$g.'</a>, ';
-            }
-            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 .= "<a href=\"article.php?group={$_spool->group}"
-                    ."&amp;id=$p\">$ndx</a> ";
-                $_spool->overview[$p]->desc++;
-                $p = $_spool->overview[$p]->parent;
-                $ndx++;
-            }
-            return $rsl;
-
-        case "x-face":
-            return '<img src="xface.php?face='.base64_encode($_text)
-            .'"  alt="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 '<div class="shortcuts">';
@@ -70,13 +22,13 @@ function displayshortcuts() {
         case 'thread.php' :
             echo '[<a href="index.php">'._b_('Liste des forums').'</a>] ';
             echo "[<a href=\"post.php?group=$group\">"._b_('Nouveau message')."</a>] ";
-            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 "[<a href=\"".$_SERVER['PHP_SELF']."?group=$group&amp;first="
-                            ."$ndx\">$ndx-".min($ndx+$news['max']-1,sizeof($spool->overview))
+                            ."$ndx\">$ndx-".min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))
                             ."</a>] ";
                     }
                 }
diff --git a/install.d/password.inc.php b/install.d/password.inc.php
deleted file mode 100644 (file)
index a68be19..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-/********************************************************************************
-* install.d/password.inc.php : NNTP credentials 
-* ----------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-$news['server']="localhost:119";
-$news["user"]=$_SESSION['login'];
-$news["pass"]=$_SESSION['passwd'];
-?>
diff --git a/install.d/profile.inc.php b/install.d/profile.inc.php
deleted file mode 100644 (file)
index 5f5951b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-/********************************************************************************
-* install.d/profile.inc.php : class for posts
-* -----------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-/** checkcancel : sets cancel rights
- * @param $_headers OBJECT headers of message to cancel
- * @return BOOLEAN true if user has right to cancel message
- */
-function checkcancel($_headers) {
-    return ($_headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">");
-}
-
-/** 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;
-}
-?>
index b15ab66..fc741e7 100644 (file)
--- 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();
 ?>
 <h1>
   <?php echo _b_('Nouveau message'); ?>
@@ -85,7 +55,7 @@ displayshortcuts();
       <?php echo _b_('Nom'); ?>
     </td>
     <td>
-      <?php echo htmlentities($profile['name']); ?>
+      <?php echo htmlentities($banana->profile['name']); ?>
     </td>
   </tr>
   <tr>
@@ -93,8 +63,7 @@ displayshortcuts();
       <?php echo _b_('Sujet'); ?>
     </td>
     <td>
-      <input type="text" name="subject" value="<?php echo 
-        (isset($subject)?$subject:"");?>" />
+      <input type="text" name="subject" value="<?php if (isset($subject)) echo $subject; ?>" />
     </td>
   </tr>
   <tr>
@@ -102,8 +71,7 @@ displayshortcuts();
       <?php echo _b_('Forums'); ?>
     </td>
     <td>
-      <input type="text" name="newsgroups" value="<?php echo
-      (isset($target)?$target:"");?>" />
+      <input type="text" name="newsgroups" value="<?php if (isset($target)) echo $target; ?>" />
     </td>
   </tr>
   <tr>
@@ -119,7 +87,7 @@ displayshortcuts();
       <?php echo _b_('Organisation'); ?>
     </td>
     <td>
-      <?php echo $profile['org']; ?>
+      <?php echo $banana->profile['org']; ?>
     </td>
   </tr>
   <tr>
@@ -129,9 +97,10 @@ displayshortcuts();
   </tr>
   <tr>
     <td class="<?php echo $css['bicolvpadd'];?>" colspan="2">
-      <textarea name="body" cols="90" rows="16"><?php echo 
-      (isset($body)?htmlentities($body):"").
-      ($profile['sig']!=''?"\n\n-- \n".htmlentities($profile['sig']):"");?></textarea>
+      <textarea name="body" cols="90" rows="16"><?php
+      echo htmlentities($body);
+      if ($banana->profile['sig']) echo "\n\n-- \n".htmlentities($banana->profile['sig']);
+      ?></textarea>
     </td>
   </tr>
   <tr>
index 25cb05d..5a11304 100644 (file)
@@ -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();
 ?>
index 6f421e6..1892545 100644 (file)
@@ -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);
 ?>
 
 <h1>
@@ -36,10 +19,9 @@ $groups = new BananaGroups($nntp,2);
 
 <?php
 
-if (isset($_POST['subscribe']) && isset($_POST['action']) 
-  && $_POST['action']=="OK") {
-  update_subscriptions($_POST['subscribe']);
-  $profile['subscribe']=$_POST['subscribe'];
+if (isset($_POST['subscribe']) && isset($_POST['action']) && $_POST['action']=="OK") {
+    update_subscriptions($_POST['subscribe']);
+    $banana->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);
 ?>
   <tr class="<?php echo ($pair?$css["pair"]:$css["impair"]);?>" >
     <td class="<?php echo $css["total"]; ?>">
@@ -76,8 +58,7 @@ foreach ($groups->overview as $g => $d) {
     </td>
     <td class="<?php echo $css["unread"]; ?>">
       <input type="checkbox" name="subscribe[]" value="<?php echo $g;?>"
-      <?php echo (in_array($g,$profile['subscribe'])?'checked="checked"'
-      :'');?> />
+      <?php if (in_array($g,$banana->profile['subscribe']) echo 'checked="checked"'; ?> />
     </td>
     <td class="<?php echo $css["group"]; ?>">
       <?php echo "<a href=\"thread.php?group=$g\">$g</a>";?>
@@ -100,6 +81,6 @@ foreach ($groups->overview as $g => $d) {
 
 displayshortcuts();
 
-$nntp->quit();
+$banana->nntp->quit();
 require_once("include/footer.inc.php");
 ?>
index 4f9e53b..0d52e6a 100644 (file)
 * 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 = "<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;
 
-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 = "<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: '.$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="<p class=\"normal\">"._b_('Message posté')."</p>";
-      } else {
-        $text="<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
-      }
-      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="<p class=\"normal\">"._b_('Message posté')."</p>";
-      } else {
-        $text="<p class=\"error\">"._b_('Impossible de poster le message')."</p>";
-      }
-      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 = "<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']);
+}
 
 ?>
-<h1>
-  <?php echo $group; ?>
-</h1>
+<h1><?php echo $group; ?></h1>
 <?php
-if (isset($text)) {
-    echo $text;
-}
+if (isset($text)) { echo $text; }
 displayshortcuts();
 
 ?>
@@ -152,8 +124,8 @@ displayshortcuts();
     </th>
   </tr>
 <?php
-$spool->disp($first,$last);
-$nntp->quit();
+$banana->spool->disp($first, $last);
+$banana->nntp->quit();
 echo "</table>";
 
 displayshortcuts();
index 98078c3..802254e 100644 (file)
--- a/xface.php
+++ b/xface.php
@@ -1,9 +1,5 @@
 <?php
 
-$face = base64_decode($_REQUEST['face']);
-$face = escapeshellarg($face);
-
-header("Content-Type: image/png");
-passthru("echo $face|uncompface -X |convert xbm:- png:-");
+passthru('echo '.escapeshellarg(base64_decode($_REQUEST['face'])).'|uncompface -X |convert xbm:- png:-');
 
 ?>