Much better html rendering with css support and style inliner
[banana.git] / banana / spool.inc.php
index 9de8df8..361a43c 100644 (file)
@@ -49,7 +49,7 @@ class BananaSpoolHead
     public function __construct(array &$message)
     {
         $this->date       = $message['date'];
-        $this->subject    = stripslashes($message['subject']);
+        $this->subject    = $message['subject'];
         $this->from       = $message['from'];
         $this->desc       = 1;
         $this->isread     = true;
@@ -85,10 +85,10 @@ class BananaSpool
         $this->group      = $group;
     }
 
-    public static function getSpool($group, $since = 0)
+    public static function getSpool($group, $since = 0, $clean = false)
     {
         if (!is_null(Banana::$spool) && Banana::$spool->group == $group) {
-            $spool = Banana::$spool;
+            $spool =& Banana::$spool;
         } else {
             $spool = BananaSpool::readFromFile($group);
         }        
@@ -97,6 +97,9 @@ class BananaSpool
         }
         Banana::$spool =& $spool;
         $spool->build();
+        if ($clean) {
+            $spool->markAllAsRead();
+        }
         $spool->updateUnread($since);
         return $spool;
     }
@@ -206,6 +209,9 @@ class BananaSpool
             $this->ids[$message['message-id']] = $id;
         }
 
+        if (!is_array($this->overview)) {
+            $this->overview = array();
+        }
         foreach ($messages as $id=>&$message) {
             if (!isset($this->overview[$id])) {
                 $this->overview[$id] = new BananaSpoolHead($message);
@@ -243,7 +249,7 @@ class BananaSpool
         }
 
         $newpostsids = Banana::$protocole->getNewIndexes($since);
-        
+
         if (empty($newpostsids)) {
             return;
         }
@@ -300,6 +306,9 @@ class BananaSpool
         if (is_null($array)) {
             $array =& $this->roots;
         }
+        if (!is_array($this->roots)) {
+            return;
+        }
         foreach ($array as $id) {
             if (!$this->overview[$id]->isread) {
                 $this->markAsRead($id);
@@ -360,6 +369,7 @@ class BananaSpool
             }
             
             if ($write) {
+                $this->markAllAsRead();
                 $this->saveToFile();
             }
         }
@@ -392,9 +402,7 @@ class BananaSpool
      * @param $_pfx_end STRING prefix used for children of current node
      * @param $_head BOOLEAN true if first post in thread
      *
-     * If you want to analyse subject, you can define the function hook_getSubject(&$subject) which
-     * take the subject as a reference parameter, transform this subject to be displaid in the spool
-     * view and return a string. This string will be put after the subject.
+     * If you want to analyse subject, you can define the function hook_formatDisplayHeader
      */
     private function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
     {
@@ -426,14 +434,15 @@ class BananaSpool
             $res .= '<td class="subj' . ($_index == $_ref ? ' cur' : '') . '">'
                 . $_pfx_node .($hc ? ($_head ? $spfx_f : ($overview->parent_direct ? $spfx_s : $spfx_snd)) : $spfx_n);
             $subject = $overview->subject;
+            if (function_exists('hook_formatDisplayHeader')) {
+                list($subject, $link) = hook_formatDisplayHeader('subject', $subject, true);
+            } else {
+                $subject = banana_catchFormats(banana_htmlentities(stripslashes($subject)));
+                $link = null;
+            }
             if (empty($subject)) {
                 $subject = _b_('(pas de sujet)');
             }
-            $link = null;
-            if (function_exists('hook_getSubject')) {
-                $link = hook_getSubject($subject);
-            }
-            $subject = banana_catchFormats($subject);
             if ($_index != $_ref) {
                 $subject = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $_id,
                                                     'text'  => $subject, 'popup' => $subject));