2 /********************************************************************************
3 * include/tree.inc.php : thread tree
4 * -----------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
11 define('BANANA_TREE_VERSION', '0.1');
14 * Class representing a thread tree
20 static private $cache = array();
26 /** Last update timestamp
34 /** Construct a new tree from a given root
36 public function __construct(BananaSpoolHead
&$root)
38 if (empty($root->children
)) {
41 $tree =& $this->builder($root);
42 $this->data
= '<div class="tree"><div style="height:18px">'
43 . implode("</div>\n<div style=\"height:18px\">", $tree)
47 $this->version
= BANANA_TREE_VERSION
;
48 $this->saveToFile($root->id
);
51 private function &builder(BananaSpoolHead
&$head)
53 static $t_e, $u_h, $u_ht, $u_vt, $u_l, $u_f, $r_h, $r_ht, $r_vt, $r_l, $r_f;
54 if (!isset($spfx_f)) {
55 $t_e = Banana
::$page->makeImg(Array('img' => 'e', 'alt' => ' ', 'height' => 18, 'width' => 14));
56 $u_h = Banana
::$page->makeImg(Array('img' => 'h2', 'alt' => '-', 'height' => 18, 'width' => 14));
57 $u_ht = Banana
::$page->makeImg(Array('img' => 'T2', 'alt' => '+', 'height' => 18, 'width' => 14));
58 $u_vt = Banana
::$page->makeImg(Array('img' => 't2', 'alt' => '`', 'height' => 18, 'width' => 14));
59 $u_l = Banana
::$page->makeImg(Array('img' => 'l2', 'alt' => '|', 'height' => 18, 'width' => 14));
60 $u_f = Banana
::$page->makeImg(Array('img' => 'f2', 'alt' => 't', 'height' => 18, 'width' => 14));
61 $r_h = Banana
::$page->makeImg(Array('img' => 'h2r', 'alt' => '-', 'height' => 18, 'width' => 14));
62 $r_ht = Banana
::$page->makeImg(Array('img' => 'T2r', 'alt' => '+', 'height' => 18, 'width' => 14));
63 $r_vt = Banana
::$page->makeImg(Array('img' => 't2r', 'alt' => '`', 'height' => 18, 'width' => 14));
64 $r_l = Banana
::$page->makeImg(Array('img' => 'l2r', 'alt' => '|', 'height' => 18, 'width' => 14));
65 $r_f = Banana
::$page->makeImg(Array('img' => 'f2r', 'alt' => 't', 'height' => 18, 'width' => 14));
67 $style = 'background-color:' . $head->color
. '; text-decoration: none';
68 $text = '<span style="' . $style . '" title="' . banana_entities($head->name
. ', ' . Banana
::$spool->formatDate($head))
69 . '"><input type="radio" name="banana_tree" '
70 . (Banana
::$msgshow_javascript ?
'onchange="window.location=\'' .
71 banana_entities(Banana
::$page->makeURL(array('group' => Banana
::$spool->group
, 'artid' => $head->id
))) . '\'"'
72 : ' disabled="disabled"')
74 $array = array($text);
75 foreach ($head->children
as $key=>&$msg) {
76 $tree =& $this->builder($msg);
77 $last = $key == count($head->children
) - 1;
78 foreach ($tree as $kt=>&$line) {
79 if ($kt === 0 && $key === 0 && !$last) {
80 $array[0] .= ($msg->isread ?
$r_ht : $u_ht) . $line;
81 } else if($kt === 0 && $key === 0) {
82 $array[0] .= ($msg->isread ?
$r_h : $u_h) . $line;
83 } else if ($kt === 0 && $last) {
84 $array[] = $t_e . ($msg->isread ?
$r_vt : $u_vt) . $line;
85 } else if ($kt === 0) {
86 $array[] = $t_e . ($msg->isread ?
$r_f : $u_f) . $line;
88 $array[] = $t_e . $t_e . $line;
90 $array[] = $t_e . ($msg->isread ?
$r_l : $u_l) . $line;
98 /** Save the content of the tree into a file
100 private function saveToFile($id)
102 file_put_contents(BananaTree
::filename($id), serialize($this));
105 /** Return html to display the tree
107 public function &show()
114 static private function filename($id)
116 return BananaSpool
::getPath('tree_' . $id);
119 /** Read a tree from a file
121 static private function &readFromFile($id)
124 $file = BananaTree
::filename($id);
125 if (!file_exists($file)) {
128 $tree = unserialize(file_get_contents($file));
129 if ($tree->version
!= BANANA_TREE_VERSION
) {
135 /** Build a tree for the given id
137 static public function &build($id)
139 $root =& Banana
::$spool->root($id);
140 if (!isset(BananaTree
::$cache[$root->id
])) {
141 $tree =& BananaTree
::readFromFile($root->id
);
142 if (is_null($tree) ||
$tree->time
< $root->time
) {
143 $tree = new BananaTree($root);
145 BananaTree
::$cache[$root->id
] =& $tree;
147 return BananaTree
::$cache[$root->id
];
150 /** Kill the file associated to the given id
152 static public function kill($id)
154 @unlink
(BananaTree
::filename($id));
157 // vim:set et sw=4 sts=4 ts=4 enc=utf-8: