Fix cache issues
[banana.git] / banana / spool.inc.php
index 00f787c..c7a7dae 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,23 +96,30 @@ 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 && is_array($this->overview)) {
-            if (count($this->overview)) {
-                for ($id = min(array_keys($this->overview)); $id<$first; $id++) { 
+        $first   = $banana->maxspool ? max($groupinfo[2] - $banana->maxspool, $groupinfo[1]) : $groupinfo[1];
+        $last    = $groupinfo[2]; 
+
+               if ($this->version == BANANA_SPOOL_VERSION && is_array($this->overview)) {
+                       $mids = array_keys($this->overview);
+                       foreach ($mids as $id) {
+                               if (($first <= $last && ($id < $first || $id > $last))
+                                               || ($first > $last && $id < $first && $id > $last))
+                               {
                     $this->delid($id, false);
                     $do_save = true;
                 }
             }
             if (!empty($this->overview)) {
                 $first = max(array_keys($this->overview))+1;
-            }
+                       }
         } else {
             unset($this->overview, $this->ids);
             $this->version = BANANA_SPOOL_VERSION;
@@ -130,7 +139,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;
+            }
         }
     }
 
@@ -333,7 +345,9 @@ class BananaSpool
             if ($_index == $_ref) {
                 $res .= '<span class="cur">'.htmlentities($subject).'</span>';
             } else {
-                $res .= "<a href='?group={$this->group}&amp;artid=$_id'>".htmlentities($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>";