Look improvements. Can identify unread message and switch from a message to
[banana.git] / banana / spool.inc.php
index 4213e5b..6ce1751 100644 (file)
@@ -9,7 +9,7 @@
 
 require_once dirname(__FILE__) . '/banana.inc.php';
 
-define('BANANA_SPOOL_VERSION', '0.5');
+define('BANANA_SPOOL_VERSION', '0.5.1');
 
 /** Class spoolhead
  *  class used in thread overviews
@@ -22,6 +22,7 @@ class BananaSpoolHead
     public $subject;
     /** author */
     public $from;
+    public $color;
     /** reference of parent */
     public $parent = null;
     /** paren is direct */
@@ -51,6 +52,7 @@ class BananaSpoolHead
         $this->date       = $message['date'];
         $this->subject    = $message['subject'];
         $this->from       = $message['from'];
+        $this->color      = sprintf('#%06x', abs(crc32($this->from) % 0xffffff));
         $this->desc       = 1;
         $this->isread     = true;
         $this->descunread = 0;
@@ -538,6 +540,70 @@ class BananaSpool
         return $res;
     }
 
+
+    public function _buildTree($id, BananaSpoolHead &$head, $current) {
+        static $t_e, $u_h, $u_ht, $u_vt, $u_l, $u_f, $r_h, $r_ht, $r_vt, $r_l, $r_f;
+        if (!isset($spfx_f)) {
+            $t_e   = Banana::$page->makeImg(Array('img' => 'e',  'alt' => ' ', 'height' => 18,  'width' => 14));
+            $u_h   = Banana::$page->makeImg(Array('img' => 'h2', 'alt' => '-', 'height' => 18,  'width' => 14));
+            $u_ht  = Banana::$page->makeImg(Array('img' => 'T2', 'alt' => '+', 'height' => 18, 'width' => 14));
+            $u_vt  = Banana::$page->makeImg(Array('img' => 't2', 'alt' => '`', 'height' => 18, 'width' => 14));
+            $u_l   = Banana::$page->makeImg(Array('img' => 'l2', 'alt' => '|', 'height' => 18, 'width' => 14));
+            $u_f   = Banana::$page->makeImg(Array('img' => 'f2', 'alt' => 't', 'height' => 18, 'width' => 14));
+            $r_h   = Banana::$page->makeImg(Array('img' => 'h2r', 'alt' => '-', 'height' => 18,  'width' => 14));
+            $r_ht  = Banana::$page->makeImg(Array('img' => 'T2r', 'alt' => '+', 'height' => 18, 'width' => 14));
+            $r_vt  = Banana::$page->makeImg(Array('img' => 't2r', 'alt' => '`', 'height' => 18, 'width' => 14));
+            $r_l   = Banana::$page->makeImg(Array('img' => 'l2r', 'alt' => '|', 'height' => 18, 'width' => 14));
+            $r_f   = Banana::$page->makeImg(Array('img' => 'f2r', 'alt' => 't', 'height' => 18, 'width' => 14));
+        }
+        $style = 'background-color:' . $head->color . '; text-decoration: none';
+        $prof  = 1;
+        $text = '<span style="' . $style . '" title="' . banana_entities($head->from) . '">' .
+                '<input type="radio" name="banana_tree" '. ($id == $current ? 'checked="checked" ' : ' ' ) .
+                (Banana::$msgshow_javascript ? 'onchange="window.location=\'' .
+                    Banana::$page->makeURL(array('group' => $this->group, 'artid' => $id)) . '\'"' : ' disabled="disabled"')
+                .' />' .
+                '</span>';
+        $array = array($text);
+        foreach ($head->children as $key=>&$child) {
+            $msg =& $this->overview[$child];
+            list($tpr, $tree) = $this->_buildTree($child, $msg, $current);
+            $last = $key == count($head->children) - 1;
+            foreach ($tree as $kt=>&$line) {
+                if ($kt == 0 && $key == 0 && !$last) {
+                    $array[0] .= ($msg->isread ? $r_ht : $u_ht) . $line;
+                } else if($kt == 0 && $key == 0) {
+                    $array[0] .= ($msg->isread ? $r_h : $u_h)  . $line;
+                } else if ($kt == 0 && $last) {
+                    $array[] = $t_e . ($msg->isread ? $r_vt : $u_vt) . $line;
+                } else if ($kt == 0) {
+                    $array[] = $t_e . ($msg->isread ? $r_f : $u_f) . $line;
+                } else if ($last) {
+                    $array[] = $t_e . $t_e . $line;
+                } else {
+                    $array[] = $t_e . ($msg->isread ? $r_l : $u_l) . $line;
+                }
+            }
+            if ($tpr > $prof) {
+                $prof = $tpr + 1;
+            }
+        }
+        return array($prof, $array);
+    }
+
+    /** build the spool tree associated with the given message
+     */
+    public function buildTree($id) {
+        $pos      =  $id;
+        $overview =& $this->overview[$id];
+        while (!is_null($overview->parent)) {
+            $pos = $overview->parent;
+            $overview =& $this->overview[$pos];
+        }
+        list($prof, $tree) = $this->_buildTree($pos, $overview, $id);
+        return implode("\n", $tree);
+    }
+
     /** computes linear post index
      * @param $_id INTEGER MSGNUM of post
      * @return INTEGER linear index of post