/usr/share/php/Horde/Tree/Renderer/Html.php is in php-horde-tree 2.0.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | <?php
/**
* The Horde_Tree_Renderer_Html class provides HTML specific rendering
* functions.
*
* Additional node parameters:
* - class: CSS class to use with this node
* - icon: Icon to display next node
* - iconalt: Alt text to use for the icon
* - iconopen: Icon to indicate this node as expanded
* - url: URL to link the node to
* - urlclass: CSS class for the node's URL
* - target: Target for the 'url' link
* - title: Link tooltip title
*
* Copyright 2003-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Marko Djukic <marko@oblo.com>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Tree
*/
class Horde_Tree_Renderer_Html extends Horde_Tree_Renderer_Base
{
/**
* Node position list.
*
* @var array
*/
protected $_node_pos = array();
/**
* Drop line cache.
*
* @var array
*/
protected $_dropline = array();
/**
* Current value of the alt tag count.
*
* @var integer
*/
protected $_altCount = 0;
/**
* Images array.
*
* @var array
*/
protected $_images = array(
'line' => null,
'blank' => null,
'join' => null,
'join_bottom' => null,
'join_top' => null,
'plus' => null,
'plus_bottom' => null,
'plus_only' => null,
'minus' => null,
'minus_bottom' => null,
'minus_only' => null,
'null_only' => null,
'folder' => null,
'folderopen' => null,
'leaf' => null
);
/**
* Constructor.
*
* @param string $name The name of this tree instance.
* @param array $params Additional parameters:
* <pre>
* alternate - (boolean) Alternate shading in the table?
* DEFAULT: false
* class - (string) The class to use for the table.
* DEFAULT: ''
* hideHeaders - (boolean) Don't render any HTML for the header row, just
* use the widths.
* DEFAULT: false
* lines - (boolean) Show tree lines?
* DEFAULT: true
* lines_base - (boolean) Show tree lines for the base level? Requires
* 'lines' to be true also.
* DEFAULT: false
* multiline - (boolean) Do the node labels contain linebreaks?
* DEFAULT: false
* </pre>
*/
public function __construct($name, array $params = array())
{
$params = array_merge(array(
'lines' => true
), $params);
parent::__construct($name, $params);
}
/**
* Returns the tree.
*
* @param boolean $static If true the tree nodes can't be expanded and
* collapsed and the tree gets rendered expanded.
*
* @return string The HTML code of the rendered tree.
*/
public function getTree($static = false)
{
$this->_static = (bool)$static;
return $this->_buildHeader() . parent::getTree($static);
}
/**
* Adds column headers to the tree table.
*
* @param array $header An array containing hashes with header
* information. The following keys are allowed:
* <pre>
* class - The CSS class of the header cell
* html - The HTML content of the header cell
* </pre>
*/
public function setHeader($header)
{
parent::setHeader($header);
}
/**
* Returns the HTML code for a header row, if necessary.
*
* @return string The HTML code of the header row or an empty string.
*/
protected function _buildHeader()
{
if (!count($this->_header) ||
$this->getOption('hideHeaders')) {
return '';
}
$className = 'horde-tree-row-header';
/* If using alternating row shading, work out correct
* shade. */
if ($this->getOption('alternate')) {
$className .= ' item' . $this->_altCount;
$this->_altCount = 1 - $this->_altCount;
}
$html = '<div class="' . $className . '">';
foreach ($this->_header as $header) {
$html .= '<span';
if (!empty($header['class'])) {
$html .= ' class="' . $header['class'] . '"';
}
$html .= '>' .
(empty($header['html']) ? ' ' : $header['html'])
. '</span>';
}
return $html . '</div>';
}
/**
* Recursive function to walk through the tree array and build the output.
*
* @param string $node_id The Node ID.
*
* @return string The tree rendering.
*/
protected function _buildTree($node_id)
{
$node = $this->_nodes[$node_id];
$output = $this->_buildLine($node_id);
if (isset($node['children']) && $node['expanded']) {
foreach ($node['children'] as $key => $val) {
$this->_node_pos[$val] = array(
'count' => count($node['children']),
'pos' => $key + 1
);
$output .= $this->_buildTree($val);
}
}
return $output;
}
/**
* Function to create a single line of the tree.
*
* @param string $node_id The Node ID.
*
* @return string The rendered line.
*/
protected function _buildLine($node_id)
{
$node = $this->_nodes[$node_id];
$className = 'horde-tree-row';
if (!empty($node['class'])) {
$className .= ' ' . $node['class'];
}
/* If using alternating row shading, work out correct
* shade. */
if ($this->getOption('alternate')) {
$className .= ' item' . $this->_altCount;
$this->_altCount = 1 - $this->_altCount;
}
$line = '<div class="' . $className . '">';
/* If we have headers, track which logical "column" we're in
* for any given cell of content. */
$column = 0;
if (isset($this->_extra[$node_id][Horde_Tree_Renderer::EXTRA_LEFT])) {
$extra = $this->_extra[$node_id][Horde_Tree_Renderer::EXTRA_LEFT];
$cMax = count($extra);
while ($column < $cMax) {
$line .= $this->_addColumn($column) . $extra[$column] . '</span>';
++$column;
}
}
$line .= $this->_addColumn($column++);
if ($this->getOption('multiline')) {
$line .= '<table cellspacing="0"><tr><td>';
}
for ($i = intval($this->_static); $i < $node['indent']; ++$i) {
$line .= $this->_generateImage(($this->_dropline[$i] && $this->getOption('lines')) ? $this->_images['line'] : $this->_images['blank']);
}
$line .= $this->_setNodeToggle($node_id) . $this->_setNodeIcon($node_id);
if ($this->getOption('multiline')) {
$line .= '</td><td>';
}
$line .= $this->_setLabel($node_id);
if ($this->getOption('multiline')) {
$line .= '</td></tr></table>';
}
$line .= '</span>';
if (isset($this->_extra[$node_id][Horde_Tree_Renderer::EXTRA_RIGHT])) {
$extra = $this->_extra[$node_id][Horde_Tree_Renderer::EXTRA_RIGHT];
$cMax = count($extra);
for ($c = 0, $cMax = count($extra); $c < $cMax; ++$c) {
$line .= $this->_addColumn($column++) . $extra[$c] . '</span>';
}
}
return $line . "</div>\n";
}
/**
*/
protected function _addColumn($column)
{
$line = '<span';
if (isset($this->_header[$column]['class'])) {
$line .= ' class="' . $this->_header[$column]['class'] . '"';
}
return $line . '>';
}
/**
* Sets the label on the tree line.
*
* @param string $node_id The Node ID.
*
* @return string The label for the tree line.
*/
protected function _setLabel($node_id)
{
$node = $this->_nodes[$node_id];
$output = '<span>';
$label = $node['label'];
if (!empty($node['url'])) {
$target = '';
if (!empty($node['target'])) {
$target = ' target="' . $node['target'] . '"';
} elseif ($target = $this->getOption('target')) {
$target = ' target="' . $target . '"';
}
$output .= '<a' . (!empty($node['urlclass']) ? ' class="' . $node['urlclass'] . '"' : '') . ' href="' . $node['url'] . '"' . $target . '>' . $label . '</a>';
} else {
$output .= $label;
}
return $output . '</span>';
}
/**
* Sets the node toggle on the tree line.
*
* @param string $node_id The Node ID.
*
* @return string The node toggle for the tree line.
*/
protected function _setNodeToggle($node_id)
{
$link_start = '';
$node = $this->_nodes[$node_id];
/* Top level node. */
if ($node['indent'] == 0) {
$this->_dropline[0] = false;
if ($this->_static) {
return '';
}
/* KEY:
* 0: Only node
* 1: Top node
* 2: Middle node
* 3: Bottom node */
$node_type = 0;
if ($this->getOption('lines_base') &&
(count($this->_root_nodes) > 1)) {
switch (array_search($node_id, $this->_root_nodes)) {
case 0:
$node_type = 1;
$this->_dropline[0] = true;
break;
case (count($this->_root_nodes) - 1):
$node_type = 3;
break;
default:
$node_type = 2;
$this->_dropline[0] = true;
break;
}
}
if (isset($node['children'])) {
if (!$this->getOption('lines')) {
$img = $this->_images['blank'];
} elseif ($node['expanded']) {
$img = $node_type
? (($node_type == 2) ? $this->_images['minus'] : $this->_images['minus_bottom'])
: $this->_images['minus_only'];
} else {
$img = $node_type
? (($node_type == 2) ? $this->_images['plus'] : $this->_images['plus_bottom'])
: $this->_images['plus_only'];
}
$link_start = $this->_generateUrlTag($node_id);
} else {
if ($this->getOption('lines')) {
switch ($node_type) {
case 0:
$img = $this->_images['null_only'];
break;
case 1:
$img = $this->_images['join_top'];
break;
case 2:
$img = $this->_images['join'];
break;
case 3:
$img = $this->_images['join_bottom'];
break;
}
} else {
$img = $this->_images['blank'];
}
}
} elseif (isset($node['children'])) {
/* Node with children. */
if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) {
/* Not last node. */
if (!$this->getOption('lines')) {
$img = $this->_images['blank'];
} elseif ($this->_static) {
$img = $this->_images['join'];
} elseif ($node['expanded']) {
$img = $this->_images['minus'];
} else {
$img = $this->_images['plus'];
}
$this->_dropline[$node['indent']] = true;
} else {
/* Last node. */
if (!$this->getOption('lines')) {
$img = $this->_images['blank'];
} elseif ($this->_static) {
$img = $this->_images['join_bottom'];
} elseif ($node['expanded']) {
$img = $this->_images['minus_bottom'];
} else {
$img = $this->_images['plus_bottom'];
}
$this->_dropline[$node['indent']] = false;
}
if (!$this->_static) {
$link_start = $this->_generateUrlTag($node_id);
}
} else {
/* Node without children. */
if ($this->_node_pos[$node_id]['pos'] < $this->_node_pos[$node_id]['count']) {
/* Not last node. */
$img = $this->getOption('lines')
? $this->_images['join']
: $this->_images['blank'];
$this->_dropline[$node['indent']] = true;
} else {
/* Last node. */
$img = $this->getOption('lines')
? $this->_images['join_bottom']
: $this->_images['blank'];
$this->_dropline[$node['indent']] = false;
}
}
return $link_start .
$this->_generateImage($img, 'horde-tree-toggle') .
($link_start ? '</a>' : '');
}
/**
* Generate a link URL.
*
* @param string $node_id The node ID.
*
* @return string The link tag.
*/
protected function _generateUrlTag($node_id)
{
$url = new Horde_Url($_SERVER['PHP_SELF']);
return $url->add(Horde_Tree::TOGGLE . $this->_tree->instance, $node_id)->link();
}
/**
* Generate the icon image.
*
* @param string $src The source image.
* @param string $class Additional class to add to image.
* @param string $alt Alt text to add to the image.
*
* @return string A HTML tag to display the image.
*/
protected function _generateImage($src, $class = '', $alt = null)
{
$img = '<img src="' . $src . '"';
if ($class) {
$img .= ' class="' . $class . '"';
}
if (!is_null($alt)) {
$img .= ' alt="' . $alt . '"';
}
return $img . ' />';
}
/**
* Sets the icon for the node.
*
* @param string $node_id The Node ID.
*
* @return string The node icon for the tree line.
*/
protected function _setNodeIcon($node_id)
{
$node = $this->_nodes[$node_id];
if (isset($node['icon'])) {
if (empty($node['icon'])) {
return '';
}
/* Node has a user defined icon. */
$img = (isset($node['iconopen']) && $node['expanded'])
? $node['iconopen']
: $node['icon'];
} elseif (isset($node['children'])) {
/* Standard icon set: node with children. */
$img = $node['expanded']
? $this->_images['folderopen']
: $this->_images['folder'];
} else {
/* Standard icon set: leaf node (no children). */
$img = $this->_images['leaf'];
}
return $this->_generateImage($img, 'horde-tree-icon', isset($node['iconalt']) ? htmlspecialchars($node['iconalt']) : null);
}
}
|