From: Michael M Slusarz Date: Thu, 19 Aug 2010 22:34:24 +0000 (-0600) Subject: Move tree image generation to its own function X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9c8912003a32147e3813a87858bc3289673d9bb2;p=horde.git Move tree image generation to its own function --- diff --git a/framework/Tree/lib/Horde/Tree/Html.php b/framework/Tree/lib/Horde/Tree/Html.php index ceb07ce22..08dce0392 100644 --- a/framework/Tree/lib/Horde/Tree/Html.php +++ b/framework/Tree/lib/Horde/Tree/Html.php @@ -185,7 +185,7 @@ class Horde_Tree_Html extends Horde_Tree if (isset($this->_nodes[$node_id]['extra'][self::EXTRA_LEFT])) { $extra = $this->_nodes[$node_id]['extra'][self::EXTRA_LEFT]; $cMax = count($extra); - for ($c = 0; $c < $cMax; $c++) { + for ($c = 0; $c < $cMax; ++$c) { $style = ''; if (isset($this->_header[$column]['width'])) { $style .= 'width:' . $this->_header[$column]['width'] . ';'; @@ -216,13 +216,7 @@ class Horde_Tree_Html extends Horde_Tree } for ($i = intval($this->_static); $i < $this->_nodes[$node_id]['indent']; ++$i) { - $line .= '_images['blank'] . '"'; - } - $line .= ' />'; + $line .= $this->_generateImage(($this->_dropline[$i] && $this->getOption('lines', false, true)) ? $this->_images['line'] : $this->_images['blank']); } $line .= $this->_setNodeToggle($node_id) . $this->_setNodeIcon($node_id); if ($this->getOption('multiline')) { @@ -235,12 +229,12 @@ class Horde_Tree_Html extends Horde_Tree } $line .= ''; - $column++; + ++$column; if (isset($this->_nodes[$node_id]['extra'][self::EXTRA_RIGHT])) { $extra = $this->_nodes[$node_id]['extra'][self::EXTRA_RIGHT]; $cMax = count($extra); - for ($c = 0; $c < $cMax; $c++) { + for ($c = 0; $c < $cMax; ++$c) { $style = ''; if (isset($this->_header[$column]['width'])) { $style .= 'width:' . $this->_header[$column]['width'] . ';'; @@ -384,11 +378,7 @@ class Horde_Tree_Html extends Horde_Tree $link_end = ($link_start) ? '' : ''; - $img = $link_start . - '' - . $link_end; - - return $img; + return $link_start . $this->_generateImage($img) . $link_end; } /** @@ -401,9 +391,32 @@ class Horde_Tree_Html extends Horde_Tree protected function _generateUrlTag($node_id) { $url = new Horde_Url($_SERVER['PHP_SELF']); - $url->add(self::TOGGLE . $this->_instance, $node_id); + return $url->add(self::TOGGLE . $this->_instance, $node_id)->link(); + } + + /** + * Generate the icon image. + * + * @param string $src The source image. + * @param boolean $icon Is this an icon image? If false, this is a + * tree/line image. + * @param string $alt Alt text to add to the image. + * + * @return string A HTML tag to display the image. + */ + protected function _generateImage($src, $icon = false, $alt = null) + { + $img = ''; + return $img . ' />'; } /** @@ -419,6 +432,7 @@ class Horde_Tree_Html extends Horde_Tree if (empty($this->_nodes[$node_id]['icon'])) { return ''; } + /* Node has a user defined icon. */ if (isset($this->_nodes[$node_id]['iconopen']) && $this->_nodes[$node_id]['expanded']) { @@ -439,14 +453,7 @@ class Horde_Tree_Html extends Horde_Tree } } - $imgtxt = '_nodes[$node_id]['iconalt'])) { - $imgtxt .= ' alt="' . htmlspecialchars($this->_nodes[$node_id]['iconalt']) . '"'; - } - - return $imgtxt . ' />'; + return $this->_generateImage($img, true, isset($this->_nodes[$node_id]['iconalt']) ? htmlspecialchars($this->_nodes[$node_id]['iconalt']) : null); } }