First version of a tree representation of the threads
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Tue, 23 Oct 2007 22:04:11 +0000 (22:04 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:50 +0000 (00:35 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@279 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/page.inc.php
banana/spool.inc.php
banana/templates/banana-message.inc.tpl

index ab0954b..620e3c5 100644 (file)
@@ -265,7 +265,7 @@ class BananaPage extends Smarty
      */
     public function makeLink(array $params, &$smarty = null)
     {
-        $catch = array('text', 'popup', 'class', 'accesskey');
+        $catch = array('text', 'popup', 'class', 'accesskey', 'style');
         foreach ($catch as $key) {
             ${$key} = isset($params[$key]) ? $params[$key] : null;
             unset($params[$key]);
@@ -283,11 +283,14 @@ class BananaPage extends Smarty
         if (!is_null($class)) {
             $class = ' class="' . $class . '"';
         }
+        if (!is_null($style)) {
+            $style = ' style="' . $style . '"';
+        }
         if (!is_null($accesskey)) {
             $accesskey = ' accesskey="' . $accesskey . '"';
         }
         return '<a href="' . banana_entities($link) . '"'
-              . $popup . $class . $accesskey
+              . $popup . $class . $style . $accesskey
               . '>' . $text . '</a>';
     }
 
index 4213e5b..2ce0755 100644 (file)
@@ -9,7 +9,7 @@
 
 require_once dirname(__FILE__) . '/banana.inc.php';
 
-define('BANANA_SPOOL_VERSION', '0.5');
+define('BANANA_SPOOL_VERSION', '0.6');
 
 /** 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,54 @@ class BananaSpool
         return $res;
     }
 
+
+    public function _buildTree($id, BananaSpoolHead &$head, $current) {
+        $style = 'color:' . $head->color . '; text-decoration: none';
+        $prof  = 1;
+        if ($id == $current) {
+            $text = "<strong style=\"$style\">0</strong>";
+        } else {
+            $text = Banana::$page->makeLink(Array('group' => $this->group, 'artid' => $id,
+                                                  'text'  => 'o', 'popup' => $head->from,
+                                                  'style' => $style));
+        }
+        $array = array($text);
+        foreach ($head->children as $key=>&$child) {
+            list($tpr, $tree) = $this->_buildTree($child, $this->overview[$child], $current);
+            $last = $key == count($head->children) - 1;
+            foreach ($tree as $kt=>&$line) {
+                if ($kt == 0 && $key == 0) {
+                    $array[0] .= '--' . $line;
+                } else if ($kt == 0 && $last) {
+                    $array[] = ' !-' . $line;
+                } else if ($kt == 0) {
+                    $array[] = ' |-' . $line;
+                } else if ($last) {
+                    $array[] = '   ' . $line;
+                } else {
+                    $array[] = ' | ' . $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
index 8181892..161ccda 100644 (file)
@@ -1,3 +1,7 @@
+<pre>
+{$spool->buildTree($artid)|smarty:nodefaults}
+</pre>
+
 <table class="bicol message">
   <tr>
     <th colspan="3" class="subject">