rename classes + bugfixes
authorx2000habouzit <x2000habouzit>
Sun, 2 Jan 2005 20:48:12 +0000 (20:48 +0000)
committerx2000habouzit <x2000habouzit>
Sun, 2 Jan 2005 20:48:12 +0000 (20:48 +0000)
article.php
include/NetNNTP.inc.php
include/groups.inc.php
include/misc.inc.php
include/post.inc.php
include/spool.inc.php
index.php
post.php
scripts/spoolgen.php
subscribe.php
thread.php

index d21a290..a62311c 100644 (file)
@@ -34,11 +34,11 @@ if ($news['user']!="anonymous") {
   $result = $nntp->authinfo($news["user"],$news["pass"]);
   if (!$result) error("nntpauth");
 }
-$spool = new spool($nntp,$group,$profile['display'],$profile['lastnews']);
+$spool = new BananaSpool($nntp,$group,$profile['display'],$profile['lastnews']);
 if (!$spool) error("nntpspool");
 $nntp->group($group);
 
-$post = new NNTPPost($nntp,$id);
+$post = new BananaPost($nntp,$id);
 if (!$post) {
   if ($nntp->lasterrorcode == "423") {
     $spool->delid($id);
@@ -80,12 +80,14 @@ summary="<?php echo _b_('Contenu du message'); ?>">
     </th>
   </tr>
 <?php
-foreach ($news['headdisp'] as $nick) {
-  if (isset($post->headers[$nick])) 
-    echo "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($nick)."</td>"
-    ."<td>".formatdisplayheader($nick,$post->headers[$nick],$spool)
-    ."</td></tr>\n";
-}
+    foreach ($news['headdisp'] as $nick) {
+        if (isset($post->headers[$nick])) {
+            $res = formatdisplayheader($nick,$post->headers[$nick],$spool);
+            if ($res)
+                echo "<tr><td class=\"{$css['bicoltitre']}\">".header_translate($nick)."</td>"
+                    ."<td>$res</td></tr>\n";
+        }
+    }
 ?>
   <tr>
     <th colspan="2">
index 9b55740..c7a592d 100644 (file)
@@ -10,7 +10,8 @@
 /** Class NNTP
  *  implements some basic functions for NNTP protocol
  */
-class nntp {
+class nntp
+{
     /** socket filehandle */
     var $ns;
     /** debug mode */
@@ -28,7 +29,8 @@ class nntp {
      * @return STRING 
      */
 
-    function gline() {
+    function gline()
+    {
         if ($this->debug) {
             $line = trim(fgets($this->ns, 1200));
             print "NNTP >>>> $line \n";
@@ -41,7 +43,8 @@ class nntp {
      * @param STRING $_line line to put
      */
 
-    function pline($_line) {
+    function pline($_line)
+    {
         if ($this->debug) {
             $dline = preg_replace("/\r\n$/", "", $_line);
             $dline = preg_replace("/(\r|\n|\r\n)/", "\nNNTP <<<< ", $dline);
@@ -57,7 +60,8 @@ class nntp {
      * @param $_reader BOOLEAN sends a "MODE READER" at connection if true
      */
 
-    function nntp($_host, $_timeout=120, $_debug=0, $_reader=true) {
+    function nntp($_host, $_timeout=120, $_debug=0, $_reader=true)
+    {
         if (preg_match("/([^:]+):([^:]+)/", $_host, $regs)) {
             $host = $regs[1];
             $port = $regs[2];
@@ -93,7 +97,8 @@ class nntp {
      * @return BOOLEAN true if authentication was successful
      */
 
-    function authinfo($_user, $_pass) {
+    function authinfo($_user, $_pass)
+    {
         $user = preg_replace("/(\r|\n)/", "", $_user);
         $pass = preg_replace("/(\r|\n)/", "", $_pass);
         $this->pline("AUTHINFO USER $user\r\n");
@@ -119,7 +124,8 @@ class nntp {
      * @see head
      */
 
-    function article($_msgid="") {
+    function article($_msgid="")
+    {
         $msgid = preg_replace("/(\r|\n)/", "", $_msgid);
         $this->pline("ARTICLE $msgid\r\n");
         $result = $this->gline();
@@ -142,7 +148,8 @@ class nntp {
      * @return STRING MSGID of article 
      */
 
-    function post($_message) {
+    function post($_message)
+    {
         if (is_array($_message)) {
             $message=join("\n", $_message);
         } else {
@@ -180,7 +187,8 @@ class nntp {
      * @see head
      */
 
-    function body($_msgid="") {
+    function body($_msgid="")
+    {
         $msgid = preg_replace("/(\r|\n)/", "", $_msgid);
         $this->pline("BODY $msgid\r\n");
         $result = $this->gline();
@@ -205,7 +213,8 @@ class nntp {
      * @see body
      */
 
-    function head($_msgid="") {
+    function head($_msgid="")
+    {
         $msgid = preg_replace("/(\r|\n)/", "", $_msgid);
         $this->pline("HEAD $msgid\r\n");
         $result = $this->gline();
@@ -227,7 +236,8 @@ class nntp {
      * @return ARRAY array : nb of articles in group, MSGNUM of first article, MSGNUM of last article, and group name
      */
 
-    function group($_group) {
+    function group($_group)
+    {
         $group = preg_replace("/(\r|\n)/", "", $_group);
         $this->pline("GROUP $group\r\n");
         $line = $this->gline();
@@ -247,7 +257,8 @@ class nntp {
      * @see next
      */
 
-    function last() {
+    function last()
+    {
         $this->pline("LAST \r\n");
         $line = $this->gline();
         if ($line{0}!="2") {
@@ -266,7 +277,8 @@ class nntp {
      * @see last
      */
 
-    function next() {
+    function next()
+    {
         $this->pline("NEXT \r\n");
         $line = $this->gline();
         if ($line{0}!="2") {
@@ -287,7 +299,8 @@ class nntp {
      * @see body
      */
 
-    function nntpstat($_msgid) {
+    function nntpstat($_msgid)
+    {
         $msgid = preg_replace("/(\r|\n)/", "", $_msgid);
         $this->pline("STAT $msgid\r\n");
         $line  = $this->gline();
@@ -306,7 +319,8 @@ class nntp {
      * @return BOOLEAN true if posting is allowed lines 
      */
 
-    function postok() {
+    function postok()
+    {
         return ($this->posting);
     }
 
@@ -315,7 +329,8 @@ class nntp {
      * @see newgroups
      */
 
-    function liste() {
+    function liste()
+    {
         $this->pline("LIST\r\n");
         if (substr($this->gline(), 0, 1)!="2") return false;
         $result = $this->gline();
@@ -335,7 +350,8 @@ class nntp {
      * @see liste
      */
 
-    function newgroups($_since, $_distributions="") {
+    function newgroups($_since, $_distributions="")
+    {
 #assume $_since is a unix timestamp
         $distributions = preg_replace("/(\r|\n)/", "", $_distributions);
         $this->pline("NEWGROUPS ".gmdate("ymd His", $_since)
@@ -359,7 +375,8 @@ class nntp {
      * @return ARRAY MSGID of new articles
      */
 
-    function newnews($_since, $_groups="*", $_distributions="") {
+    function newnews($_since, $_groups="*", $_distributions="")
+    {
         $distributions = preg_replace("/(\r|\n)/", "", $_distributions);
         $groups = preg_replace("/(\r|\n)/", "", $_groups);
         $array  = array();
@@ -380,7 +397,8 @@ class nntp {
      * @return BOOLEAN true if sucessful
      */
 
-    function slave() {
+    function slave()
+    {
         $this->pline("SLAVE \r\n");
         return (substr($this->gline(), 0, 1)=="2");
     }
@@ -391,7 +409,8 @@ class nntp {
      * @return BOOLEAN 
      */
 
-    function ihave($_msgid, $_message=false) {
+    function ihave($_msgid, $_message=false)
+    {
         $msgid = preg_replace("/(\r|\n)/", "", $_msgid);
         if (is_array($message)) {
             $message = join("\n", $_message);
@@ -410,7 +429,8 @@ class nntp {
     /** closes connection to server
      */
 
-    function quit() {
+    function quit()
+    {
         $this->pline("QUIT\r\n");
         $this->gline();
         fclose($this->ns);
@@ -422,7 +442,8 @@ class nntp {
      * @return INTEGER timestamp 
      */
 
-    function date() {
+    function date()
+    {
         $this->pline("DATE \r\n");
         $result = $this->gline();
         if (preg_match("/^111 (\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/", $result, $r)) {
@@ -436,7 +457,8 @@ class nntp {
      * @return ARRAY group name => description
      */
 
-    function xgtitle($_pattern="*") {
+    function xgtitle($_pattern="*")
+    {
         $pattern = preg_replace("/(\r|\n)/", "", $_pattern);
         $this->pline("XGTITLE $pattern \r\n");
         if (substr($this->gline(), 0, 1)!="2") return false;
@@ -455,7 +477,8 @@ class nntp {
      * @return ARRAY MSGNUM => header value
      */
 
-    function xhdr($_hdr, $_range="") {
+    function xhdr($_hdr, $_range="")
+    {
         $hdr    = preg_replace("/(\r|\n)/", "", $_hdr);
         $range  = preg_replace("/(\r|\n)/", "", $_range);
         $this->pline("XHDR $hdr $range \r\n");
@@ -478,7 +501,8 @@ class nntp {
      * @return ARRAY MSGNUM => header value
      */
 
-    function xpat($_hdr, $_range, $_pat) {
+    function xpat($_hdr, $_range, $_pat)
+    {
         $hdr   = preg_replace("/(\r|\n)/", "", $_hdr);
         $range = preg_replace("/(\r|\n)/", "", $_range);
         $pat   = preg_replace("/(\r|\n)/", "", $_pat);
index 166ecd8..d34c96f 100644 (file)
 /** class for group lists
  */
 
-class groups {
-  /** group list */
-  var $overview;
-  /** last update */
-  var $date;
-  
-  /** constructor
-   * @param $_nntp RESOURCE handle to NNTP socket
-   */
+class BananaGroups {
+    /** group list */
+    var $overview;
+    /** last update */
+    var $date;
 
-  function groups(&$_nntp,$_type=0) {
-    global $profile;
-    $desc=$_nntp->xgtitle();
-    if ($_type==1) {
-      $list=$_nntp->newgroups($profile['lastnews']);
-    } else {
-      $list=$_nntp->liste();
-    }
-    if (!$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];
+    /** constructor
+     * @param $_nntp RESOURCE handle to NNTP socket
+     */
+
+    function BananaGroups(&$_nntp,$_type=0) {
+        global $profile;
+        $desc=$_nntp->xgtitle();
+        if ($_type==1) {
+            $list=$_nntp->newgroups($profile['lastnews']);
+        } else {
+            $list=$_nntp->liste();
         }
-      }
-      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];
+        if (!$list) {
+            $this->overview=array();
+            return false;
         }
-      }
-    } 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];
+        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];
+                }
+            }
         }
-      }
+        return true;
     }
-    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();
-    if (!$serverdate) $serverdate=time();
-    $newlist = $_nntp->newgroups($_date);
-    if (!$newlist) return false;
-    $this->date = $serverdate;
-    foreach (array_keys($newlist) as $g) {
-      $groupstat = $_nntp->group($g);
-      $groupdesc = $_nntp->xgtitle($g);
-      $this->overview[$g][0]=($groupdesc?$groupdesc:"-");
-      $this->overview[$g][1]=$groupstat[0];
+    /** updates overview 
+     * @param $_nntp RESOURCE handle to NNTP socket
+     * @param date INTEGER date of last update
+     */
+    function update(&$_nntp,$_date) {
+        $serverdate = $_nntp->date();
+        if (!$serverdate) $serverdate=time();
+        $newlist = $_nntp->newgroups($_date);
+        if (!$newlist) return false;
+        $this->date = $serverdate;
+        foreach (array_keys($newlist) as $g) {
+            $groupstat = $_nntp->group($g);
+            $groupdesc = $_nntp->xgtitle($g);
+            $this->overview[$g][0]=($groupdesc?$groupdesc:"-");
+            $this->overview[$g][1]=$groupstat[0];
+        }
+        return true;
     }
-    return true;
-  }
 }
 
 ?>
index 72b32aa..4a0e2dc 100644 (file)
@@ -21,15 +21,15 @@ function headerDecode($value) {
 }
 
 function header_translate($hdr) {
-    switch (strtolower($hdr)) {
+    switch ($hdr) {
         case 'from':            return _b_('De');
         case 'subject':         return _b_('Sujet');
         case 'newsgroups':      return _b_('Forums');
-        case 'followup':        return _b_('Suivi-à');
+        case 'followup-to':     return _b_('Suivi-à');
         case 'date':            return _b_('Date');
         case 'organization':    return _b_('Organisation');
         case 'references':      return _b_('Références');
-        case 'xface':           return _b_('Image');
+        case 'x-face':          return _b_('Image');
         default:
             return $hdr;
     }
index 2e8d8f9..259eb18 100644 (file)
@@ -10,7 +10,8 @@
 /** class for posts
  */
 
-class NNTPPost {
+class BananaPost
+{
     var $nb;
     /** headers */
     var $headers;
@@ -23,7 +24,8 @@ class NNTPPost {
      * @param $_nntp RESOURCE handle to NNTP socket
      * @param $_id STRING MSGNUM or MSGID (a group should be selected in this case)  
      */
-    function NNTPPost(&$_nntp, $_id) {
+    function BananaPost(&$_nntp, $_id)
+    {
         $this->nb = $_id;
         $this->_header($_nntp);
 
@@ -51,7 +53,6 @@ class NNTPPost {
             return false;
         }
 
-        $this->nb = $_id;
         // parse headers
         foreach ($hdrs as $line) {
             if (preg_match("/^[\t\r ]+/", $line)) {
index d7579ce..72d8a62 100644 (file)
@@ -19,12 +19,12 @@ if(!function_exists('_file_put_contents')) {
     }
 }
 
-function spoolcompare($a,$b) { return ($b->date>=$a->date); }
+function spoolCompare($a,$b) { return ($b->date>=$a->date); }
 
 /** Class spoolhead
  *  class used in thread overviews
  */
-class SpoolHead
+class BananaSpoolHead
 {
     /** date (timestamp) */
     var $date;
@@ -54,7 +54,7 @@ class SpoolHead
      * @param $_descunread INTEGER descunread value (0 for a new post)
      */
 
-    function SpoolHead($_date, $_subject, $_from, $_desc=1, $_read=true, $_descunread=0)
+    function BananaSpoolHead($_date, $_subject, $_from, $_desc=1, $_read=true, $_descunread=0)
     {
         $this->date       = $_date;
         $this->subject    = $_subject;
@@ -71,7 +71,7 @@ class SpoolHead
 
 define("BANANA_SPOOL_VERSION", '0.2');
 
-class spool
+class BananaSpool
 {
     var $version;
     /**  spool */
@@ -89,7 +89,7 @@ class spool
      * @param $_display INTEGER 1 => all posts, 2 => only threads with new posts
      * @param $_since INTEGER time stamp (used for read/unread)
      */
-    function spool(&$_nntp, $_group, $_display=0, $_since="")
+    function BananaSpool(&$_nntp, $_group, $_display=0, $_since="")
     {
         global $news;
         $this->group = $_group;
@@ -160,7 +160,7 @@ class spool
         }
 
         foreach ($msgids as $id=>$msgid) {
-            $msg                = new spoolhead($dates[$id], $subjects[$id], $froms[$id]);
+            $msg                = new BananaSpoolHead($dates[$id], $subjects[$id], $froms[$id]);
             $refs[$id]          = str_replace('><', '> <', $refs[$id]);
             $msgrefs            = preg_split("/[ \t]/", strtr($refs[$id], $this->ids));
             $parents            = preg_grep('/^\d+$/', $msgrefs);
@@ -175,7 +175,7 @@ class spool
 
             if ($p = $msg->parent) {
                 if (empty($this->overview[$p])) {
-                    $this->overview[$p] = new spoolhead($dates[$p], $subjects[$p], $froms[$p], 1);
+                    $this->overview[$p] = new BananaSpoolHead($dates[$p], $subjects[$p], $froms[$p], 1);
                 }
                 $this->overview[$p]->children[] = $id;
 
index 82ead51..38a0de2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -26,10 +26,10 @@ if ($news['user']!="anonymous") {
   $result = $nntp->authinfo($news["user"],$news["pass"]);
   if (!$result) error("nntpauth");
 }
-$groups = new groups($nntp,0);
-if (!count($groups->overview)) $groups=new groups($nntp,2);
+$groups = new BananaGroups($nntp,0);
+if (!count($groups->overview)) $groups = new BananaGroups($nntp,2);
     
-$newgroups = new groups($nntp,1);
+$newgroups = new BananaGroups($nntp,1);
 ?>
 
 <h1>
index 5d0dddf..b15ab66 100644 (file)
--- a/post.php
+++ b/post.php
@@ -41,7 +41,7 @@ if ($news['user']!="anonymous") {
 if (isset($group) && isset($id) && isset($_REQUEST['type']) && 
         ($_REQUEST['type']=='followup')) {
     $rq=$nntp->group($group);
-    $post = new NNTPPost($nntp,$id);
+    $post = new BananaPost($nntp,$id);
     if ($post) {
         $subject = (preg_match("/^re:/i",$post->headers['subject'])?"":"Re: ").$post->headers['subject'];
         if ($profile['dropsig']) {
index 9453a50..25cb05d 100644 (file)
@@ -34,12 +34,12 @@ if ($news['user']!="anonymous") {
 }
 unset($result);
 
-$groups = new groups($nntp,2);
+$groups = new BananaGroups($nntp,2);
 $list = array_keys($groups->overview);
 unset($groups);
 foreach ($list as $g) {
     print "Generating spool for $g : ";
-    $spool = new spool($nntp,$g);
+    $spool = new BananaSpool($nntp,$g);
     print "done.\n";
     unset($spool);
 }
index 36be609..6f421e6 100644 (file)
@@ -27,7 +27,7 @@ if ($news['user']!="anonymous") {
   $result = $nntp->authinfo($news["user"],$news["pass"]);
   if (!$result) error("nntpauth");
 }
-$groups = new groups($nntp,2);
+$groups = new BananaGroups($nntp,2);
 ?>
 
 <h1>
index 39c83ff..8eeee78 100644 (file)
@@ -38,7 +38,7 @@ if ($news['user']!="anonymous") {
   $result = $nntp->authinfo($news["user"],$news["pass"]);
   if (!$result) error("nntpauth");
 }
-$spool = new spool($nntp,$group,$profile['display'],
+$spool = new BananaSpool($nntp,$group,$profile['display'],
   $profile['lastnews']);
 if (!$spool) error("nntpspool");
 $max = 50;
@@ -55,7 +55,7 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) &&
     case 'cancel':
       $mid = array_search($id,$spool->ids);
       $nntp->group($group);
-      $post = new NNTPPost($nntp,$id);
+      $post = new BananaPost($nntp,$id);
       
       if (checkcancel($post->headers)) {
         $message = 'From: '.$profile['name']."\n"
@@ -97,7 +97,7 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) &&
       break;
     case 'followupok':
       $rq=$nntp->group($group);
-      $post = new NNTPPost($nntp,$id);
+      $post = new BananaPost($nntp,$id);
       if ($post) {
         $refs = (isset($post->headers['references'])?
                 $post->headers['references']." ":"").$post->headers['message-id'];
@@ -124,7 +124,7 @@ if (isset($_REQUEST['action']) && (isset($_REQUEST['type'])) &&
       break;
   }
   $_SESSION['bananapostok']=false;
-  $spool = new spool($nntp,$group,$profile['display'],
+  $spool = new BananaSpool($nntp,$group,$profile['display'],
     $profile['lastnews']);
   if (!$spool) error("nntpspool");
 }