Use css padding instead of line breaks in body
[banana.git] / banana / NetNNTP.inc.php
index 13e574a..c6d5c4e 100644 (file)
@@ -20,6 +20,8 @@ class nntp
     var $lasterrorcode;
     /** last NNTP error text */
     var $lasterrortext;
+    /** test validity */
+    var $valid = true;
 
     /** constructor
      * @param $_host STRING NNTP host
@@ -33,8 +35,8 @@ class nntp
         $url         = parse_url($_url);
         $this->ns    = fsockopen($url['host'], $url['port'], $errno, $errstr, $_timeout);
         if (!$this->ns) {
-            $this = false;
-            return false;
+            $this->valid = false;
+            return null;
         }
 
         $result        = $this->gline(); 
@@ -44,7 +46,7 @@ class nntp
             $result        = $this->gline();
             $this->posting = ($result{0}=="200");
         }
-        if ($result{0}=="2" && $url['user'] && $url['user']!='anonymous') {
+        if ($result{0}=="2" && isset($url['user']) && $url['user'] != 'anonymous') {
             return $this->authinfo($url['user'], $url['pass']);
         }
         return ($result{0}=="2");
@@ -305,6 +307,29 @@ class nntp
         return ($this->posting);
     }
 
+    /** retreive the group list
+     * @return ARRAY group name => (MSGNUM of first article, MSGNUM of last article, NNTP flags)
+     * @see newgroups, liste
+     */
+    function _grouplist()
+    {
+        global $banana;
+
+        if (substr($this->gline(), 0, 1)!="2") {
+            return false;
+        }
+        $result = $this->gline();
+        $array  = Array();
+        while ($result != ".") {
+            preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs);
+            if (!isset($banana->grp_pattern) || preg_match('@'.$banana->grp_pattern.'@', $regs[1])) {
+                $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4]));
+            }
+            $result = $this->gline();
+        }
+        return $array;                                                                                                                                        
+    }
+
     /** gets information about all active newsgroups
      * @return ARRAY group name => (MSGNUM of first article, MSGNUM of last article, NNTP flags)
      * @see newgroups
@@ -313,15 +338,7 @@ class nntp
     function liste()
     {
         $this->pline("LIST\r\n");
-        if (substr($this->gline(), 0, 1)!="2") return false;
-        $result = $this->gline();
-        $array = Array();
-        while ($result != ".") {
-            preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs);
-            $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4]));
-            $result          = $this->gline();
-        }
-        return $array;
+        return $this->_grouplist();
     }
 
     /** get information about recent newsgroups 
@@ -338,17 +355,7 @@ class nntp
         $distributions = preg_replace("/(\r|\n)/", "", $_distributions);
         $this->pline("NEWGROUPS ".gmdate("ymd His", $_since)
                 ." GMT $distributions\r\n");
-        if (substr($this->gline(), 0, 1)!="2") {
-            return false;
-        }
-        $result = $this->gline();
-        $array  = array();
-        while ($result != ".") {
-            preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs);
-            $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4]));
-            $result          = $this->gline();
-        }
-        return $array;
+        return $this->_grouplist();
     }
 
     /** gets a list of new articles
@@ -500,4 +507,5 @@ class nntp
     }
 }
 
+// vim:set et sw=4 sts=4 ts=4 
 ?>