Place formatting before html conversion of the article in order to avoid // matching...
[banana.git] / banana / spool.inc.php
index 9e078f2..7c70727 100644 (file)
@@ -7,7 +7,7 @@
 * Copyright: See COPYING files that comes with this distribution
 ********************************************************************************/
 
-if(!function_exists('_file_put_contents')) {
+if(!function_exists('file_put_contents')) {
     function file_put_contents($filename, $data)
     {
         $fp = fopen($filename, 'w');
@@ -83,6 +83,8 @@ class BananaSpool
     var $ids;
     /** thread starts */
     var $roots;
+    /** test validity */
+    var $valid = true;
 
     /** constructor
      * @param $_group STRING group name
@@ -94,19 +96,26 @@ class BananaSpool
         global $banana;
         $this->group = $_group;
         $groupinfo   = $banana->nntp->group($_group);
-        if (!$groupinfo) { return ($this = null); }
+        if (!$groupinfo) {
+            $this->valid = false;
+            return null; 
+        }
 
         $this->_readFromFile();
 
         $do_save = false;
         $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++) { 
-                $this->delid($id, false);
-                $do_save = true;
+        $last    = $groupinfo[2];        
+        if ($this->version == BANANA_SPOOL_VERSION && is_array($this->overview)) {
+            if (count($this->overview)) {
+                for ($id = min(array_keys($this->overview)); $id<$first; $id++) { 
+                    $this->delid($id, false);
+                    $do_save = true;
+                }
+            }
+            if (!empty($this->overview)) {
+                $first = max(array_keys($this->overview))+1;
             }
-            $first = max(array_keys($this->overview))+1;
         } else {
             unset($this->overview, $this->ids);
             $this->version = BANANA_SPOOL_VERSION;
@@ -126,7 +135,10 @@ class BananaSpool
     {
         $file = $this->_spoolfile();
         if (file_exists($file)) {
-            $this = unserialize(file_get_contents($file));
+            $temp = unserialize(file_get_contents($file));
+            foreach (get_object_vars($temp) as $key=>$val) {
+                $this->$key = $val;
+            }
         }
     }
 
@@ -141,7 +153,7 @@ class BananaSpool
                 $this->roots[] = $id;
             }
         }
-        
+
         file_put_contents($file, serialize($this));
     }
 
@@ -156,11 +168,11 @@ class BananaSpool
     function _updateSpool($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);
+        $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));
@@ -202,6 +214,7 @@ class BananaSpool
         if (empty($since)) { return; }
 
         if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) {
+            if (!is_array($this->ids)) { $this->ids = array(); }
             $newpostsids = array_intersect($newpostsids, array_keys($this->ids));
             foreach ($newpostsids as $mid) {
                 $this->overview[$this->ids[$mid]]->isread     = false;
@@ -321,10 +334,16 @@ class BananaSpool
             $res .= "<td class='subj'>"
                 ."<div class='tree'>$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n)
                 ."</div>";
+            $subject = $this->overview[$_id]->subject;
+            if (strlen($subject) == 0) {
+                $subject = _b_('(pas de sujet)');
+            }
             if ($_index == $_ref) {
-                $res .= '<span class="cur">'.htmlentities($this->overview[$_id]->subject).'</span>';
+                $res .= '<span class="cur">'.htmlentities($subject).'</span>';
             } else {
-                $res .= "<a href='?group={$this->group}&amp;artid=$_id'>".htmlentities($this->overview[$_id]->subject).'</a>';
+                $res .= makeHREF(Array('group' => $this->group,
+                                                                          'artid' => $_id),
+                                                                htmlentities($subject));
             }
             $res .= "</td>\n<td class='from'>".formatFrom($this->overview[$_id]->from)."</td>\n</tr>";