/usr/share/php/Horde/Tree/Renderer/Base.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 | <?php
/**
* The Horde_Tree_Renderer_Base class provides the abstract interface
* that all drivers must derive from.
*
* Copyright 2010-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 Michael Slusarz <slusarz@horde.org>
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Tree
*/
abstract class Horde_Tree_Renderer_Base
{
/**
* The tree object.
*
* @var Horde_Tree
*/
protected $_tree;
/**
* Hash with header information.
*
* @var array
*/
protected $_header = array();
/**
* An array containing all the tree nodes.
*
* @var array
*/
protected $_nodes = array();
/**
* An array containing extra columns for the tree nodes.
*
* @var array
*/
protected $_extra = array();
/**
* Keep count of how many extra columns there are on the left side
* of the node.
*
* @var integer
*/
protected $_colsLeft = 0;
/**
* Keep count of how many extra columns there are on the right side
* of the node.
*
* @var integer
*/
protected $_colsRight = 0;
/**
* Option values.
*
* @var array
*/
protected $_options = array(
'lines' => true
);
/**
* Stores the sorting criteria temporarily.
*
* @var string
*/
protected $_sortCriteria;
/**
* Should the tree be rendered statically?
*
* @var boolean
*/
protected $_static = false;
/**
* Constructor.
*
* @param Horde_Tree $tree A tree object.
* @param array $params Additional parameters.
*/
public function __construct(Horde_Tree $tree, array $params = array())
{
$this->_tree = $tree;
$this->setOption($params);
}
/**
* Provide a simpler renderer to fallback to.
*
* @return string The next best renderer.
* @throws Horde_Tree_Exception
*/
public function fallback()
{
throw new Horde_Tree_Exception('No fallback renderer found.');
}
/**
* Returns the tree.
*
* @param boolean $static If true the tree nodes can't be expanded and
* collapsed and the tree gets rendered expanded.
* This option has no effect in this driver.
*
* @return string The HTML code of the rendered tree.
*/
public function getTree($static = false)
{
$this->_nodes = $this->_tree->getNodes();
$tree = '';
foreach ($this->_tree->getRootNodes() as $node_id) {
$tree .= $this->_buildTree($node_id);
}
return $tree;
}
/**
* Recursive function to walk through the tree array and build the output.
*
* Should be overwritten by a sub-class if it doesn't implement
* its own getTree() method.
*
* @param string $node_id The Node ID.
*
* @return string The tree rendering.
*/
protected function _buildTree($id)
{
return '';
}
/**
* Renders the tree.
*
* @param boolean $static If true the tree nodes can't be expanded and
* collapsed and the tree gets rendered expanded.
*/
public function renderTree($static = false)
{
echo $this->getTree($static);
}
/**
* Sets an option.
*
* @param mixed $option The option name -or- an array of option
* name/value pairs. See constructor for available
* options.
* @param mixed $value The option's value.
*/
public function setOption($options, $value = null)
{
if (!is_array($options)) {
$options = array($options => $value);
}
foreach ($options as $option => $value) {
$this->_options[$option] = $value;
}
}
/**
* Gets an option's value.
*
* @param string $option The name of the option to fetch.
*
* @return mixed The option's value.
*/
public function getOption($option)
{
return isset($this->_options[$option])
? $this->_options[$option]
: null;
}
/**
* Adds a node to the node tree array.
*
* @param array $node A hash with node properties:
* - id: (string) The unique node id.
* - parent: (string) The parent's unique node id.
* - label: (string) The text label for the node.
* - expanded: (boolean) Is this level expanded or not.
* - params: (array) Any other parameters to set
* (see addNodeParams() of the renderers
* for full details).
*/
public function addNode($node)
{
$this->_tree->addNode($node);
/* If any extra columns included here add them now. */
if (!empty($node['right'])) {
$this->addNodeExtra($node['id'],
Horde_Tree_Renderer::EXTRA_RIGHT,
$node['right']);
}
if (!empty($node['left'])) {
$this->addNodeExtra($node['id'],
Horde_Tree_Renderer::EXTRA_LEFT,
$node['left']);
}
}
/**
* Adds additional parameters to a node.
*
* @param string $id The unique node id.
* @param array $params Parameters to set (key/value pairs).
*/
public function addNodeParams($id, $params = array())
{
$this->_tree->addNodeParams($id, $params);
}
/**
* Adds extra columns to be displayed to the side of the node.
*
* @param mixed $id The unique node id.
* @param integer $side Which side to place the extra columns on.
* @param array $extra Extra columns to display.
*/
public function addNodeExtra($id, $side, $extra)
{
$id = $this->_tree->nodeId($id);
if (!is_array($extra)) {
$extra = array($extra);
}
$col_count = count($extra);
switch ($side) {
case Horde_Tree_Renderer::EXTRA_LEFT:
$this->_extra[$id][Horde_Tree_Renderer::EXTRA_LEFT] = $extra;
if ($col_count > $this->_colsLeft) {
$this->_colsLeft = $col_count;
}
break;
case Horde_Tree_Renderer::EXTRA_RIGHT:
$this->_extra[$id][Horde_Tree_Renderer::EXTRA_RIGHT] = $extra;
if ($col_count > $this->_colsRight) {
$this->_colsRight = $col_count;
}
break;
}
}
/**
* Adds column headers to the tree table.
*
* @param array $header An array containing hashes with header
* information.
*/
public function setHeader($header)
{
$this->_header = $header;
}
/**
* Sorts the tree by the specified node property.
*
* @param string $criteria The node property to sort by.
*/
public function sort($criteria)
{
return $this->_tree->sort($criteria);
}
/**
* Check the current environment to see if we can render the tree.
*
* @return boolean Whether or not this backend will function.
*/
public function isSupported()
{
return true;
}
}
|