[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Tree_html:: class extends the Horde_Tree class to provide 4 * HTML specific rendering functions. 5 * 6 * Copyright 2003-2006 Marko Djukic <marko@oblo.com> 7 * 8 * See the enclosed file COPYING for license information (LGPL). If you 9 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 10 * 11 * $Horde: framework/Tree/Tree/html.php,v 1.51.2.12 2006/01/15 16:33:29 chuck Exp $ 12 * 13 * @author Marko Djukic <marko@oblo.com> 14 * @package Horde_Tree 15 * @since Horde 3.0 16 */ 17 class Horde_Tree_html extends Horde_Tree { 18 19 /** 20 * Image directory location. 21 * 22 * @var string 23 */ 24 var $_img_dir = ''; 25 26 /** 27 * Default tree graphic for a line. 28 * 29 * @var string 30 */ 31 var $_img_line = 'line.png'; 32 33 /** 34 * Default tree graphic for a blank. 35 * 36 * @var string 37 */ 38 var $_img_blank = 'blank.png'; 39 40 /** 41 * Default tree graphic for a join. 42 * 43 * @var string 44 */ 45 var $_img_join = 'join.png'; 46 47 /** 48 * Default tree graphic for a bottom join. 49 * 50 * @var string 51 */ 52 var $_img_join_bottom = 'joinbottom.png'; 53 54 /** 55 * Default tree graphic for a plus. 56 * 57 * @var string 58 */ 59 var $_img_plus = 'plus.png'; 60 61 /** 62 * Default tree graphic for a bottom plus. 63 * 64 * @var string 65 */ 66 var $_img_plus_bottom = 'plusbottom.png'; 67 68 /** 69 * Default tree graphic for a plus only. 70 * 71 * @var string 72 */ 73 var $_img_plus_only = 'plusonly.png'; 74 75 /** 76 * Default tree graphic for a minus. 77 * 78 * @var string 79 */ 80 var $_img_minus = 'minus.png'; 81 82 /** 83 * Default tree graphic for a bottom minus. 84 * 85 * @var string 86 */ 87 var $_img_minus_bottom = 'minusbottom.png'; 88 89 /** 90 * Default tree graphic for a minus only. 91 * 92 * @var string 93 */ 94 var $_img_minus_only = 'minusonly.png'; 95 96 /** 97 * Default tree graphic for a null only. 98 * 99 * @var string 100 */ 101 var $_img_null_only = 'nullonly.png'; 102 103 /** 104 * Default tree graphic for a folder. 105 * 106 * @var string 107 */ 108 var $_img_folder = 'folder.png'; 109 110 /** 111 * Default tree graphic for an open folder. 112 * 113 * @var string 114 */ 115 var $_img_folder_open = 'folderopen.png'; 116 117 /** 118 * Default tree graphic for a leaf. 119 * 120 * @var string 121 */ 122 var $_img_leaf = 'leaf.png'; 123 124 /** 125 * TODO 126 * 127 * @var array 128 */ 129 var $_nodes = array(); 130 131 /** 132 * TODO 133 * 134 * @var array 135 */ 136 var $_node_pos = array(); 137 138 /** 139 * TODO 140 * 141 * @var array 142 */ 143 var $_dropline = array(); 144 145 /** 146 * Current value of the alt tag count. 147 * 148 * @var integer 149 */ 150 var $_alt_count = 0; 151 152 /** 153 * Constructor 154 */ 155 function Horde_Tree_html($tree_name, $params) 156 { 157 parent::Horde_Tree($tree_name, $params); 158 159 $this->_img_dir = $GLOBALS['registry']->getImageDir('horde') . '/tree'; 160 } 161 162 /** 163 * Returns the tree. 164 * 165 * @param boolean $static If true the tree nodes can't be expanded and 166 * collapsed and the tree gets rendered expanded. 167 * 168 * @return string The HTML code of the rendered tree. 169 */ 170 function getTree($static = false) 171 { 172 $this->_static = $static; 173 $this->_buildIndents($this->_root_nodes); 174 175 $tree = $this->_buildHeader(); 176 foreach ($this->_root_nodes as $node_id) { 177 $tree .= $this->_buildTree($node_id); 178 } 179 return $tree; 180 } 181 182 /** 183 * Check the current environment to see if we can render the HTML 184 * tree. HTML is always renderable, at least until we add a 185 * php-gtk tree backend, in which case this implementation will 186 * actually need a body. 187 * 188 * @static 189 * 190 * @return boolean Whether or not this Tree:: backend will function. 191 */ 192 function isSupported() 193 { 194 return true; 195 } 196 197 /** 198 * Returns just the JS node definitions as a string. This is a 199 * no-op for the HTML renderer. 200 */ 201 function renderNodeDefinitions() 202 { 203 } 204 205 /** 206 * Returns the HTML code for a header row, if necessary. 207 * 208 * @access private 209 * 210 * @return string The HTML code of the header row or an empty string. 211 */ 212 function _buildHeader() 213 { 214 if (!count($this->_header)) { 215 return ''; 216 } 217 218 $html = '<div'; 219 /* If using alternating row shading, work out correct 220 * shade. */ 221 if ($this->getOption('alternate')) { 222 $html .= ' class="item' . $this->_alt_count . '"'; 223 $this->_alt_count = 1 - $this->_alt_count; 224 } 225 $html .= '>'; 226 227 foreach ($this->_header as $header) { 228 $html .= '<div class="leftFloat'; 229 if (!empty($header['class'])) { 230 $html .= ' ' . $header['class']; 231 } 232 $html .= '"'; 233 234 $style = ''; 235 if (!empty($header['width'])) { 236 $style .= 'width:' . $header['width'] . ';'; 237 } 238 if (!empty($header['align'])) { 239 $style .= 'text-align:' . $header['align'] . ';'; 240 } 241 if (!empty($style)) { 242 $html .= ' style="' . $style . '"'; 243 } 244 $html .= '>'; 245 $html .= empty($header['html']) ? ' ' : $header['html']; 246 $html .= '</div>'; 247 } 248 249 return $html . '</div>'; 250 } 251 252 /** 253 * Recursive function to walk through the tree array and build the output. 254 * 255 * @access private 256 * 257 * @param string $node_id The Node ID. 258 * 259 * @return string The tree rendering. 260 */ 261 function _buildTree($node_id) 262 { 263 $output = $this->_buildLine($node_id); 264 265 if (isset($this->_nodes[$node_id]['children']) && 266 $this->_nodes[$node_id]['expanded']) { 267 $num_subnodes = count($this->_nodes[$node_id]['children']); 268 for ($c = 0; $c < $num_subnodes; $c++) { 269 $child_node_id = $this->_nodes[$node_id]['children'][$c]; 270 $this->_node_pos[$child_node_id] = array(); 271 $this->_node_pos[$child_node_id]['pos'] = $c + 1; 272 $this->_node_pos[$child_node_id]['count'] = $num_subnodes; 273 $output .= $this->_buildTree($child_node_id); 274 } 275 } 276 277 return $output; 278 } 279 280 /** 281 * Function to create a single line of the tree. 282 * 283 * @access private 284 * 285 * @param string $node_id The Node ID. 286 * 287 * @return string The rendered line. 288 */ 289 function _buildLine($node_id) 290 { 291 $className = 'treeRow'; 292 if (!empty($this->_nodes[$node_id]['class'])) { 293 $className .= ' ' . $this->_nodes[$node_id]['class']; 294 } 295 /* If using alternating row shading, work out correct 296 * shade. */ 297 if ($this->getOption('alternate')) { 298 $className .= ' item' . $this->_alt_count; 299 $this->_alt_count = 1 - $this->_alt_count; 300 } 301 302 $line = '<div class="' . $className . '">'; 303 304 /* If we have headers, track which logical "column" we're in 305 * for any given cell of content. */ 306 $column = 0; 307 308 if (isset($this->_nodes[$node_id]['extra'][HORDE_TREE_EXTRA_LEFT])) { 309 $extra = $this->_nodes[$node_id]['extra'][HORDE_TREE_EXTRA_LEFT]; 310 $cMax = count($extra); 311 for ($c = 0; $c < $cMax; $c++) { 312 $style = ''; 313 if (isset($this->_header[$column]['width'])) { 314 $style .= 'width:' . $this->_header[$column]['width'] . ';'; 315 } 316 317 $line .= '<div class="leftFloat"'; 318 if (!empty($style)) { 319 $line .= ' style="' . $style . '"'; 320 } 321 $line .= '>' . $extra[$c] . '</div>'; 322 323 $column++; 324 } 325 } 326 327 $style = ''; 328 if (isset($this->_header[$column]['width'])) { 329 $style .= 'width:' . $this->_header[$column]['width'] . ';'; 330 } 331 $line .= '<div class="leftFloat"'; 332 if (!empty($style)) { 333 $line .= ' style="' . $style . '"'; 334 } 335 $line .= '>'; 336 337 if ($this->getOption('multiline')) { 338 $line .= '<table cellspacing="0"><tr><td>'; 339 } 340 341 for ($i = $this->_static ? 1 : 0; $i < $this->_nodes[$node_id]['indent']; $i++) { 342 $line .= '<img src="' . $this->_img_dir . '/'; 343 if ($this->_dropline[$i] && $this->getOption('lines', false, true)) { 344 $line .= $this->_img_line . '" ' 345 . 'alt="| " '; 346 } else { 347 $line .= $this->_img_blank . '" ' 348 . 'alt=" " '; 349 } 350 $line .= 'height="20" width="20" style="vertical-align:middle" />'; 351 } 352 $line .= $this->_setNodeToggle($node_id) . $this->_setNodeIcon($node_id); 353 if ($this->getOption('multiline')) { 354 $line .= '</td><td>'; 355 } 356 $line .= $this->_setLabel($node_id); 357 358 if ($this->getOption('multiline')) { 359 $line .= '</td></tr></table>'; 360 } 361 362 $line .= '</div>'; 363 $column++; 364 365 if (isset($this->_nodes[$node_id]['extra'][HORDE_TREE_EXTRA_RIGHT])) { 366 $extra = $this->_nodes[$node_id]['extra'][HORDE_TREE_EXTRA_RIGHT]; 367 $cMax = count($extra); 368 for ($c = 0; $c < $cMax; $c++) { 369 $style = ''; 370 if (isset($this->_header[$column]['width'])) { 371 $style .= 'width:' . $this->_header[$column]['width'] . ';'; 372 } 373 374 $line .= '<div class="leftFloat"'; 375 if (!empty($style)) { 376 $line .= ' style="' . $style . '"'; 377 } 378 $line .= '>' . $extra[$c] . '</div>'; 379 380 $column++; 381 } 382 } 383 384 return $line . "</div>\n"; 385 } 386 387 /** 388 * Sets the label on the tree line. 389 * 390 * @access private 391 * 392 * @param string $node_id The Node ID. 393 * 394 * @return string The label for the tree line. 395 */ 396 function _setLabel($node_id) 397 { 398 $n = $this->_nodes[$node_id]; 399 400 $output = '<span'; 401 if (!empty($n['onclick'])) { 402 $output .= ' onclick="' . $n['onclick'] . '"'; 403 } 404 $output .= '>'; 405 406 $label = $n['label']; 407 if (!empty($n['url'])) { 408 $target = ''; 409 if (!empty($n['target'])) { 410 $target = ' target="' . $n['target'] . '"'; 411 } elseif ($target = $this->getOption('target')) { 412 $target = ' target="' . $target . '"'; 413 } 414 $output .= '<a' . (!empty($n['urlclass']) ? ' class="' . $n['urlclass'] . '"' : '') . ' href="' . $n['url'] . '"' . $target . '>' . $label . '</a>'; 415 } else { 416 $output .= $label; 417 } 418 419 return $output . '</span>'; 420 } 421 422 /** 423 * Sets the node toggle on the tree line. 424 * 425 * @access private 426 * 427 * @param string $node_id The Node ID. 428 * 429 * @return string The node toggle for the tree line. 430 */ 431 function _setNodeToggle($node_id) 432 { 433 $link_start = ''; 434 435 if (($this->_nodes[$node_id]['indent'] == 0) && 436 isset($this->_nodes[$node_id]['children'])) { 437 /* Top level node with children. */ 438 $this->_dropline[0] = false; 439 if ($this->_static) { 440 return ''; 441 } elseif (!$this->getOption('lines', false, true)) { 442 $img = $this->_img_blank; 443 $alt = ' '; 444 } elseif ($this->_nodes[$node_id]['expanded']) { 445 $img = $this->_img_minus_only; 446 $alt = '-'; 447 } else { 448 $img = $this->_img_plus_only; 449 $alt = '+'; 450 } 451 if (!$this->_static) { 452 $url = Util::addParameter(Horde::selfUrl(), HORDE_TREE_TOGGLE . $this->_instance, $node_id); 453 $link_start = Horde::link($url); 454 } 455 } elseif (($this->_nodes[$node_id]['indent'] != 0) && 456 !isset($this->_nodes[$node_id]['children'])) { 457 /* Node without children. */ 458 if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) { 459 /* Not last node. */ 460 if ($this->getOption('lines', false, true)) { 461 $img = $this->_img_join; 462 $alt = '|-'; 463 } else { 464 $img = $this->_img_blank; 465 $alt = ' '; 466 } 467 $this->_dropline[$this->_nodes[$node_id]['indent']] = true; 468 } else { 469 /* Last node. */ 470 if ($this->getOption('lines', false, true)) { 471 $img = $this->_img_join_bottom; 472 $alt = '`-'; 473 } else { 474 $img = $this->_img_blank; 475 $alt = ' '; 476 } 477 $this->_dropline[$this->_nodes[$node_id]['indent']] = false; 478 } 479 } elseif (isset($this->_nodes[$node_id]['children'])) { 480 /* Node with children. */ 481 if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) { 482 /* Not last node. */ 483 if (!$this->getOption('lines', false, true)) { 484 $img = $this->_img_blank; 485 $alt = ' '; 486 } elseif ($this->_static) { 487 $img = $this->_img_join; 488 $alt = '|-'; 489 } elseif ($this->_nodes[$node_id]['expanded']) { 490 $img = $this->_img_minus; 491 $alt = '-'; 492 } else { 493 $img = $this->_img_plus; 494 $alt = '+'; 495 } 496 $this->_dropline[$this->_nodes[$node_id]['indent']] = true; 497 } else { 498 /* Last node. */ 499 if (!$this->getOption('lines', false, true)) { 500 $img = $this->_img_blank; 501 $alt = ' '; 502 } elseif ($this->_static) { 503 $img = $this->_img_join_bottom; 504 $alt = '`-'; 505 } elseif ($this->_nodes[$node_id]['expanded']) { 506 $img = $this->_img_minus_bottom; 507 $alt = '-'; 508 } else { 509 $img = $this->_img_plus_bottom; 510 $alt = '+'; 511 } 512 $this->_dropline[$this->_nodes[$node_id]['indent']] = false; 513 } 514 if (!$this->_static) { 515 $url = Util::addParameter(Horde::selfUrl(), HORDE_TREE_TOGGLE . $this->_instance, $node_id); 516 $link_start = Horde::link($url); 517 } 518 } else { 519 /* Top level node with no children. */ 520 if ($this->_static) { 521 return ''; 522 } 523 if ($this->getOption('lines', false, true)) { 524 $img = $this->_img_null_only; 525 $alt = ' '; 526 } else { 527 $img = $this->_img_blank; 528 $alt = ' '; 529 } 530 $this->_dropline[0] = false; 531 } 532 533 $link_end = ($link_start) ? '</a>' : ''; 534 535 $img = $link_start . '<img src="' . $this->_img_dir . '/' . $img . '"' 536 . (isset($alt) ? ' alt="' . $alt . '"' : '') 537 . ' height="20" width="20" style="vertical-align:middle" border="0" />' 538 . $link_end; 539 540 return $img; 541 } 542 543 /** 544 * Sets the icon for the node. 545 * 546 * @access private 547 * 548 * @param string $node_id The Node ID. 549 * 550 * @return string The node icon for the tree line. 551 */ 552 function _setNodeIcon($node_id) 553 { 554 $img_dir = isset($this->_nodes[$node_id]['icondir']) ? $this->_nodes[$node_id]['icondir'] : $this->_img_dir; 555 if ($img_dir) { 556 $img_dir .= '/'; 557 } 558 559 if (isset($this->_nodes[$node_id]['icon'])) { 560 if (empty($this->_nodes[$node_id]['icon'])) { 561 return ''; 562 } 563 /* Node has a user defined icon. */ 564 if (isset($this->_nodes[$node_id]['iconopen']) && 565 $this->_nodes[$node_id]['expanded']) { 566 $img = $this->_nodes[$node_id]['iconopen']; 567 } else { 568 $img = $this->_nodes[$node_id]['icon']; 569 } 570 } else { 571 /* Use standard icon set. */ 572 if (isset($this->_nodes[$node_id]['children'])) { 573 /* Node with children. */ 574 $img = ($this->_nodes[$node_id]['expanded']) ? $this->_img_folder_open : $this->_img_folder; 575 } else { 576 /* Leaf node (no children). */ 577 $img = $this->_img_leaf; 578 } 579 } 580 581 $imgtxt = '<img src="' . $img_dir . $img . '"'; 582 583 /* Does the node have user defined alt text? */ 584 if (isset($this->_nodes[$node_id]['iconalt'])) { 585 $imgtxt .= ' alt="' . htmlspecialchars($this->_nodes[$node_id]['iconalt']) . '"'; 586 } 587 588 return $imgtxt . ' />'; 589 } 590 591 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |