From: x2003bruneau Date: Wed, 31 Oct 2007 22:38:19 +0000 (+0000) Subject: New storage format of the tree. X-Git-Tag: 1.8~16 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e3bc13e0686193f289c7995723cd5b673d74cce3;hp=1d521296445b60b0bf8f654509cb1ca5847d93df;p=banana.git New storage format of the tree. Signed-off-by: Florent Bruneau git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@295 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/tree.inc.php b/banana/tree.inc.php index 6db3c44..4e6fd8a 100644 --- a/banana/tree.inc.php +++ b/banana/tree.inc.php @@ -8,7 +8,7 @@ ********************************************************************************/ -define('BANANA_TREE_VERSION', '0.1'); +define('BANANA_TREE_VERSION', '0.1.2'); /** * Class representing a thread tree @@ -29,7 +29,14 @@ class BananaTree /** Data */ - public $data; + public $data = array(); + + /** Data caching + */ + private $urls = array(); + private $title = array(); + + private $displaid = null; /** Construct a new tree from a given root */ @@ -38,10 +45,7 @@ class BananaTree if (empty($root->children)) { $this->data = null; } else { - $tree =& $this->builder($root); - $this->data = '
' - . implode("
\n
", $tree) - . '
'; + $this->data =& $this->builder($root); } $this->time = time(); $this->version = BANANA_TREE_VERSION; @@ -50,44 +54,26 @@ class BananaTree private function &builder(BananaSpoolHead &$head) { - 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'; - $text = ''; - $array = array($text); + $array = array(array($head->id)); + $this->urls[$head->id] = banana_entities(Banana::$page->makeURL(array('group' => Banana::$group, + 'artid' => $head->id))); + $this->title[$head->id] = banana_entities($head->name . ', ' . Banana::$spool->formatDate($head)); foreach ($head->children as $key=>&$msg) { $tree =& $this->builder($msg); $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; + $array[0] = array_merge($array[0], array('+'), $line); } else if($kt === 0 && $key === 0) { - $array[0] .= ($msg->isread ? $r_h : $u_h) . $line; + $array[0] = array_merge($array[0], array('-'), $line); } else if ($kt === 0 && $last) { - $array[] = $t_e . ($msg->isread ? $r_vt : $u_vt) . $line; + $array[] = array_merge(array(' ', '`'), $line); } else if ($kt === 0) { - $array[] = $t_e . ($msg->isread ? $r_f : $u_f) . $line; + $array[] = array_merge(array(' ', 't'), $line); } else if ($last) { - $array[] = $t_e . $t_e . $line; + $array[] = array_merge(array(' ', ' '), $line); } else { - $array[] = $t_e . ($msg->isread ? $r_l : $u_l) . $line; + $array[] = array_merge(array(' ', '|'), $line); } } unset($tree); @@ -106,7 +92,55 @@ class BananaTree */ public function &show() { - return $this->data; + if (!is_null($this->displaid)) { + return $this->displaid; + } + 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($t_e)) { + $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)); + } + $text = '
'; + foreach ($this->data as &$line) { + $text .= '
'; + foreach ($line as &$item) { + switch ($item) { + case ' ': $text .= $t_e; break; + case '+': $text .= $u_ht; break; + case '-': $text .= $u_h; break; + case '|': $text .= $u_l; break; + case '`': $text .= $u_vt; break; + case 't': $text .= $u_f; break; + default: + $head =& Banana::$spool->overview[$item]; + $text .= '' + . 'urls[$item] . '\'"'; + } else { + $text .= ' disabled="disabled"'; + } + if (Banana::$artid == $item) { + $text .= ' checked="checked"'; + } + $text .= '/>'; + } + } + $text .= "
\n"; + } + $text .= '
'; + $this->displaid =& $text; + return $text; } /** Get filename