Ooops: wrong use of preg_split.
[banana.git] / banana / nntpcore.inc.php
index f1cf460..d1b2f19 100644 (file)
@@ -50,7 +50,7 @@ class BananaNNTPCore
         }
 
         $this->checkState();
-        $this->posting = ($this->lastresultcode == '200'); 
+        $this->posting = ($this->lastresultcode == '200');
         if ($reader && $this->posting) {
             $this->execLine('MODE READER');
             $this->posting = ($this->lastresultcode == '200');
@@ -79,7 +79,11 @@ class BananaNNTPCore
 
     public function lastError()
     {
-        return $this->lasterrortext;
+        if (!is_utf8($this->lasterrortext)) {
+            return utf8_encode($this->lasterrortext);
+        } else {
+            return $this->lasterrortext;
+        }
     }
 
     public function backtrace()
@@ -96,34 +100,25 @@ class BananaNNTPCore
     /** get a line from server
      * @return STRING 
      */
-    private function getLine()
+    private function &getLine()
     {
-        return rtrim(fgets($this->ns, 1200));
+        $data = rtrim(@fgets($this->ns, 1200), "\r\n");
+        return $data;
     }
 
     /** fetch data (and on delimitor)
      * @param STRING $delim string indicating and of transmission
      */
-    private function fetchResult($callback = null)
+    private function &fetchResult()
     {
         $array = Array();
-        while (($result = $this->getLine()) != '.') {
-            if (!is_null($callback)) {
-                list($key, $result) = call_user_func($callback, $result);
-                if (is_null($result)) {
-                    continue;
-                }
-                if (is_null($key)) {
-                    $array[] = $result;
-                } else {
-                    $array[$key] = $result;
-                }
-            } else {
-                $array[] = $result;
-            }
+        while (($result =& $this->getLine()) != '.') {
+            $array[] =& $result;
         }
         if ($this->debug && $this->bt) {
-            $this->bt[count($this->bt) - 1]['response'] = count($array);
+            $trace =& $this->bt[count($this->bt) - 1];
+            $trace['response'] = count($array);
+            $trace['time']     = microtime(true) - $trace['start'];
         }
         return $array;
     }
@@ -139,9 +134,9 @@ class BananaNNTPCore
         }
         if ($this->debug) {
             $db_line = preg_replace('/PASS .*/', 'PASS *******', $line);
-            $this->bt[] = array('action' => $db_line, 'time' => microtime(true));
+            $this->bt[] = array('action' => $db_line, 'start' => microtime(true));
         }
-        return fputs($this->ns, $line, strlen($line));
+        return @fputs($this->ns, $line, strlen($line));
     }
 
     /** put a message (multiline)
@@ -180,7 +175,7 @@ class BananaNNTPCore
         $this->lastresulttext = substr($result, 4);
         if ($this->debug && $this->bt) {
             $trace =& $this->bt[count($this->bt) - 1];
-            $trace['time']     = microtime(true) - $trace['time'];
+            $trace['time']     = microtime(true) - $trace['start'];
             $trace['code']     = $this->lastresultcode;
             $trace['message']  = $this->lastresulttext;
             $trace['response'] = 0;
@@ -471,10 +466,10 @@ class BananaNNTPCore
         if (!$this->execLine("XGTITLE $pattern ")) {
             return false;
         }
-        $array  = $this->fetchResult();
+        $array  =& $this->fetchResult();
         $groups = array();
-        foreach ($array as $result) {
-            list($group, $desc) = split("[ \t]", $result, 2);
+        foreach ($array as &$result) {
+            @list($group, $desc) = preg_split('/[ \t]/', $result, 2);
             $groups[$group] = $desc;
         }
         return $groups;
@@ -495,7 +490,7 @@ class BananaNNTPCore
         if (!$this->execLine("XHDR $hdr $range ")) {
             return false;
         }
-        $array   = $this->fetchResult();
+        $array   =& $this->fetchResult();
         $headers = array();
         foreach ($array as &$result) {
             @list($head, $value) = explode(' ', $result, 2);
@@ -515,7 +510,7 @@ class BananaNNTPCore
         if (!$this->execLine("XPAT $hdr $range $pat")) {
             return false;
         }
-        $array   = $this->fetchResult();
+        $array   =& $this->fetchResult();
         $headers = array();
         foreach ($array as &$result) {
             list($head, $value) = explode(' ', $result, 2);