From bd28876619cad63fce11c822413780a3c86d762c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 13 Jul 2010 20:57:00 -0600 Subject: [PATCH] Remove horde/Core dependency in horde/Tree. --- agora/lib/Messages.php | 2 +- ansel/lib/Ansel.php | 5 +- fima/templates/accounts/accounts.inc | 2 +- framework/Core/lib/Horde/Core/Binder/Tree.php | 17 ++ framework/Core/lib/Horde/Core/Factory/Tree.php | 87 +++++++++ framework/Core/lib/Horde/Core/Tree/Html.php | 116 +++++++++++ .../lib/Horde/Core}/Tree/Javascript.php | 49 +++-- framework/Core/lib/Horde/Registry.php | 1 + framework/Core/package.xml | 14 ++ framework/Tree/lib/Horde/Tree.php | 217 ++++++--------------- framework/Tree/lib/Horde/Tree/Exception.php | 17 ++ framework/Tree/lib/Horde/Tree/Html.php | 73 +++++-- framework/Tree/lib/Horde/Tree/Select.php | 24 ++- framework/Tree/package.xml | 13 +- hermes/deliverables.php | 2 +- horde/admin/activesync.php | 3 +- horde/admin/datatree.php | 2 +- horde/admin/groups.php | 2 +- horde/js/hordetree.js | 41 ++-- horde/services/help/index.php | 2 +- horde/themes/screen.css | 6 + trean/lib/Trean.php | 2 +- trean/templates/browse.php | 3 +- 23 files changed, 443 insertions(+), 257 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/Tree.php create mode 100644 framework/Core/lib/Horde/Core/Factory/Tree.php create mode 100644 framework/Core/lib/Horde/Core/Tree/Html.php rename framework/{Tree/lib/Horde => Core/lib/Horde/Core}/Tree/Javascript.php (77%) create mode 100644 framework/Tree/lib/Horde/Tree/Exception.php diff --git a/agora/lib/Messages.php b/agora/lib/Messages.php index 71e973f34..570fbda77 100644 --- a/agora/lib/Messages.php +++ b/agora/lib/Messages.php @@ -1395,7 +1395,7 @@ class Agora_Messages { /* Render threaded lists with Horde_Tree. */ $current = key($threads); if (!$template_file && isset($threads[$current]['indent'])) { - $tree = Horde_Tree::factory('threads', 'html'); + $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('threads', 'Html'); $tree->setOption(array('multiline' => $bodies, 'lines' => !$bodies)); $tree->setHeader(array( diff --git a/ansel/lib/Ansel.php b/ansel/lib/Ansel.php index cd3d8ced2..cf34ee857 100644 --- a/ansel/lib/Ansel.php +++ b/ansel/lib/Ansel.php @@ -86,9 +86,10 @@ class Ansel ->getScope() ->listGalleries($params); - $tree = Horde_Tree::factory('gallery_tree', 'Select'); + $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('gallery_tree', 'Select'); - /* Remove the ignored gallery, make sure it's also not the selected gallery */ + /* Remove the ignored gallery, make sure it's also not the selected + * gallery */ if ($params->ignore) { if ($params->selected == $params->ignore) { $params->selected = null; diff --git a/fima/templates/accounts/accounts.inc b/fima/templates/accounts/accounts.inc index 011753f6b..ff2a56bf0 100644 --- a/fima/templates/accounts/accounts.inc +++ b/fima/templates/accounts/accounts.inc @@ -30,7 +30,7 @@ function Submit(action) Horde_Themes::img(), 'icon' => ''); -$tree = Horde_Tree::factory('account_tree', 'Javascript'); +$tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('account_tree', 'Javascript'); foreach ($accounts as $accountId => $account) { $params['icon'] = $account['icon']; diff --git a/framework/Core/lib/Horde/Core/Binder/Tree.php b/framework/Core/lib/Horde/Core/Binder/Tree.php new file mode 100644 index 000000000..abe00d8c1 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Tree.php @@ -0,0 +1,17 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_Tree:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_Tree +{ + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Singleton instances. + * + * @var array + */ + private $_instances = array(); + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_Tree:: instance. + * + * @param string $name The name of this tree instance. + * @param mixed $renderer The type of tree renderer. + * @param array $params Any additional parameters the constructor + * needs. + * + * @return Horde_Tree The singleton instance. + * @throws Horde_Tree_Exception + */ + public function getTree($name, $renderer, array $params = array()) + { + $renderer = Horde_String::lower($renderer); + $id = $name . '|' . $renderer; + + if (!isset($this->_instances[$id])) { + switch ($renderer) { + case 'html': + $renderer = 'Horde_Core_Tree_Html'; + break; + + case 'javascript': + $renderer = 'Horde_Core_Tree_Javascript'; + break; + } + + $this->_instances[$id] = Horde_Tree::factory($name, $renderer, $params); + } + + return $this->_instances[$id]; + } + +} diff --git a/framework/Core/lib/Horde/Core/Tree/Html.php b/framework/Core/lib/Horde/Core/Tree/Html.php new file mode 100644 index 000000000..003c4cd00 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Tree/Html.php @@ -0,0 +1,116 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Tree_Html extends Horde_Tree_Html +{ + /** + * Images array. + * + * @var array + */ + protected $_images = array( + 'line' => 'line.png', + 'blank' => 'blank.png', + 'join' => 'join.png', + 'join_bottom' => 'joinbottom.png', + 'plus' => 'plus.png', + 'plus_bottom' => 'plusbottom.png', + 'plus_only' => 'plusonly.png', + 'minus' => 'minus.png', + 'minus_bottom' => 'minusbottom.png', + 'minus_only' => 'minusonly.png', + 'null_only' => 'nullonly.png', + 'folder' => 'folder.png', + 'folderopen' => 'folderopen.png', + 'leaf' => 'leaf.png' + ); + + /** + * Constructor. + * + * @param string $name @see parent::__construct(). + * @param array $params @see parent::__construct(). + */ + public function __construct($name, array $params = array()) + { + parent::__construct($name, $params); + + if (!isset($_SESSION['horde_tree'][$this->_instance])) { + $_SESSION['horde_tree'][$this->_instance] = array(); + } + + if (!empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) { + $no_rev = array('blank', 'folder', 'folder_open'); + foreach (array_diff(array_keys($this->_images), $no_rev) as $key) { + $this->_images[$key] = 'rev-' . $this->_images[$key]; + } + } + + foreach (array_keys($this->_images) as $key) { + $this->_images[$key] = strval(Horde_Themes::img('tree/' . $this->_images[$key], array('app' => 'horde'))); + } + } + + /** + * Generate a link URL tag. + * + * @param string $node_id The node ID. + * + * @return string The link tag. + */ + protected function _generateUrlTag($node_id) + { + return Horde::link(Horde::selfUrl()->add(self::TOGGLE . $this->_instance, $node_id)); + } + + /** + * Adds a node to the node tree array. + * + * @param string $id The unique node id. + * @param string $parent The parent's unique node id. + * @param string $label The text label for the node. + * @param string $indent Deprecated, this is calculated automatically + * based on the parent node. + * @param boolean $expanded Is this level expanded or not. + * @param array $params Any other parameters to set (@see + * addNodeParams() for full details). + * @param array $extra_right Any other columns to display to the right of + * the tree. + * @param array $extra_left Any other columns to display to the left of + * the tree. + */ + public function addNode($id, $parent, $label, $indent = null, + $expanded = true, $params = array(), + $extra_right = array(), $extra_left = array()) + { + $sess = $_SESSION['horde_tree'][$this->_instance]; + $toggle_id = Horde_Util::getFormData(self::TOGGLE . $this->_instance); + + if ($id == $toggle_id) { + /* We have a URL toggle request for this node. */ + $expanded = $_SESSION['horde_tree'][$this->_instance]['expanded'][$id] = isset($sess['expanded'][$id]) + /* Use session state if it is set. */ + ? (!$sess['expanded'][$id]) + /* Otherwise use what was passed through the function. */ + : (!$expanded); + } elseif (isset($sess['expanded'][$id])) { + /* If we have a saved session state use it. */ + $expanded = $sess['expanded'][$id]; + } + + parent::addNode($id, $parent, $label, $indent, $expanded, $params, $extra_right, $extra_left); + } + +} diff --git a/framework/Tree/lib/Horde/Tree/Javascript.php b/framework/Core/lib/Horde/Core/Tree/Javascript.php similarity index 77% rename from framework/Tree/lib/Horde/Tree/Javascript.php rename to framework/Core/lib/Horde/Core/Tree/Javascript.php index 1f3436e92..7bb43f791 100644 --- a/framework/Tree/lib/Horde/Tree/Javascript.php +++ b/framework/Core/lib/Horde/Core/Tree/Javascript.php @@ -1,7 +1,7 @@ + * @author Michael Slusarz * @category Horde - * @package Horde_Tree + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core */ -class Horde_Tree_Javascript extends Horde_Tree +class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html { /** * Constructor. * - * @param string $name @see Horde_Tree::__construct(). - * @param array $params @see Horde_Tree::__construct(). + * @param string $name @see parent::__construct(). + * @param array $params @see parent::__construct(). */ - public function __construct($tree_name, $params = array()) + public function __construct($name, array $params = array()) { - parent::__construct($tree_name, $params); + parent::__construct($name, $params); + + Horde::addScriptFile('prototype.js', 'horde'); + Horde::addScriptFile('hordetree.js', 'horde'); /* Check for a javascript session state. */ - if ($this->_usesession && - isset($_COOKIE[$this->_instance . '_expanded'])) { + if (isset($_COOKIE[$this->_instance . '_expanded'])) { /* Remove "exp" prefix from cookie value. */ $nodes = explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3)); - /* Make sure there are no previous nodes stored in the - * session. */ - $_SESSION['horde_tree'][$this->_instance]['expanded'] = array(); - /* Save nodes to the session. */ - foreach ($nodes as $id) { - $_SESSION['horde_tree'][$this->_instance]['expanded'][$id] = true; - } + $_SESSION['horde_tree'][$this->_instance]['expanded'] = array_combine( + $nodes, + array_fill(0, count($nodes), true) + ); } + } - Horde::addScriptFile('prototype.js', 'horde'); - Horde::addScriptFile('hordetree.js', 'horde'); + /** + * Provide a simpler renderer to fallback to. + * + * @return string The next best renderer. + */ + public function fallback() + { + return 'Horde_Core_Tree_Html'; } /** @@ -68,7 +76,6 @@ class Horde_Tree_Javascript extends Horde_Tree 'scrollbar_in_way' => $GLOBALS['browser']->hasQuirk('scrollbar_in_way'), - 'imgDir' => $this->_img_dir, 'imgBlank' => $this->_images['blank'], 'imgFolder' => $this->_images['folder'], 'imgFolderOpen' => $this->_images['folderopen'], @@ -84,7 +91,7 @@ class Horde_Tree_Javascript extends Horde_Tree 'imgNullOnly' => $this->_images['null_only'], 'imgLeaf' => $this->_images['leaf'], - 'floatDir' => empty($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 'float:left;' : 'float:right' + 'floatDir' => (empty($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 'float:left;' : 'float:right') ); Horde::addInlineScript(array( diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 9d56dc820..394da7bb0 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -288,6 +288,7 @@ class Horde_Registry 'Horde_SessionHandler' => new Horde_Core_Binder_SessionHandler(), 'Horde_Share' => new Horde_Core_Binder_Share(), 'Horde_Template' => new Horde_Core_Binder_Template(), + 'Horde_Tree' => new Horde_Core_Binder_Tree(), 'Horde_Token' => new Horde_Core_Binder_Token(), 'Horde_Vfs' => new Horde_Core_Binder_Vfs(), 'Net_DNS_Resolver' => new Horde_Core_Binder_Dns() diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 6263c99c9..ac8826850 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -108,6 +108,7 @@ Application Framework. + @@ -126,6 +127,7 @@ Application Framework. + @@ -154,6 +156,10 @@ Application Framework. + + + + @@ -290,6 +296,10 @@ Application Framework. Text_Filter pear.horde.org + + Tree + pear.horde.org + @@ -342,6 +352,7 @@ Application Framework. + @@ -359,6 +370,7 @@ Application Framework. + @@ -368,6 +380,8 @@ Application Framework. + + diff --git a/framework/Tree/lib/Horde/Tree.php b/framework/Tree/lib/Horde/Tree.php index e5e25e763..6801ba65b 100644 --- a/framework/Tree/lib/Horde/Tree.php +++ b/framework/Tree/lib/Horde/Tree.php @@ -1,7 +1,7 @@ * @category Horde - * @package Horde_Tree + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Tree */ class Horde_Tree { @@ -31,13 +32,6 @@ class Horde_Tree const TOGGLE = 'ht_toggle_'; /** - * Singleton instances. - * - * @var array - */ - static protected $_instances = array(); - - /** * The name of this instance. * * @var string @@ -91,35 +85,6 @@ class Horde_Tree ); /** - * Image directory location. - * - * @var string - */ - protected $_img_dir = ''; - - /** - * Images array. - * - * @var array - */ - protected $_images = array( - 'line' => 'line.png', - 'blank' => 'blank.png', - 'join' => 'join.png', - 'join_bottom' => 'joinbottom.png', - 'plus' => 'plus.png', - 'plus_bottom' => 'plusbottom.png', - 'plus_only' => 'plusonly.png', - 'minus' => 'minus.png', - 'minus_bottom' => 'minusbottom.png', - 'minus_only' => 'minusonly.png', - 'null_only' => 'nullonly.png', - 'folder' => 'folder.png', - 'folderopen' => 'folderopen.png', - 'leaf' => 'leaf.png' - ); - - /** * Stores the sorting criteria temporarily. * * @var string @@ -127,13 +92,6 @@ class Horde_Tree protected $_sortCriteria; /** - * Use session to store cached Tree data? - * - * @var boolean - */ - protected $_usesession = true; - - /** * Should the tree be rendered statically? * * @var boolean @@ -141,112 +99,86 @@ class Horde_Tree protected $_static = false; /** - * Attempts to return a reference to a concrete instance. - * It will only create a new instance if no instance with the same - * parameters currently exists. - * - * This method must be invoked as: - * $var = Horde_Tree::singleton($name[, $renderer[, $params]]); - * - * @param mixed $name @see Horde_Tree::factory. - * @param string $renderer @see Horde_Tree::factory. - * @param array $params @see Horde_Tree::factory. - * - * @return Horde_Tree The concrete instance. - * @throws Horde_Exception - */ - static public function singleton($name, $renderer, $params = array()) - { - ksort($params); - $id = $name . ':' . $renderer . ':' . serialize($params); - - if (!isset(self::$_instances[$id])) { - self::$_instances[$id] = self::factory($name, $renderer, $params); - if (!self::$_instances[$id]->isSupported()) { - $renderer = self::fallback($renderer); - return self::singleton($name, $renderer, $params); - } - } - - return self::$_instances[$id]; - } - - /** * Attempts to return a concrete instance. * - * @param string $name The name of this tree instance. - * @param mixed $renderer The type of concrete subclass to return. This - * is based on the rendering driver. The code is - * dynamically included. - * @param array $params Any additional parameters the constructor - * needs. + * @param string $name The name of this tree instance. + * @param string $renderer Either the tree renderer driver or a full + * class name to use. + * @param array $params Any additional parameters the constructor + * needs. * * @return Horde_Tree The newly created concrete instance. - * @throws Horde_Exception + * @throws Horde_Tree_Exception */ static public function factory($name, $renderer, $params = array()) { + $ob = null; + + /* Base drivers (in Tree/ directory). */ $class = __CLASS__ . '_' . ucfirst($renderer); if (class_exists($class)) { - return new $class($name, $params); + $ob = new $class($name, $params); + } else { + /* Explicit class name, */ + $class = $renderer; + if (class_exists($class)) { + $ob = new $class($name, $params); + } } - throw new Horde_Exception('Horde_Tree renderer not found: ' . $renderer); + if ($ob) { + if ($ob->isSupported()) { + return $ob; + } + + return self::factory($name, $ob->fallback(), $params); + } + + throw new Horde_Tree_Exception(__CLASS__ . ' renderer not found: ' . $renderer); } /** - * Try to fall back to a simpler renderer. - * - * @paran string $renderer The renderer that we can't handle. + * Provide a simpler renderer to fallback to. * * @return string The next best renderer. - * @throws Horde_Exception + * @throws Horde_Tree_Exception */ - public function fallback($renderer) + public function fallback() { - switch ($renderer) { - case 'javascript': - return 'html'; - - case 'html': - throw new Horde_Exception('No fallback renderer found.'); - } + throw new Horde_Tree_Exception('No fallback renderer found.'); } /** * Constructor. * * @param string $name The name of this tree instance. - * @param array $params Additional parameters: + * @param array $params Additional parameters. *
-     * 'nosession' - (boolean) If true, do not store tree data in session.
+     * alternate - (boolean) Alternate shading in the table?
+     * class - (string) The class to use for the table.
+     * hideHeaders - (boolean) Don't render any HTML for the header row, just
+     *               use the widths.
+     * lines - (boolean) Show tree lines?
+     * multiline - (boolean) Do the node labels contain linebreaks?
      * 
*/ - public function __construct($name, $params = array()) + public function __construct($name, array $params = array()) { $this->_instance = $name; - $this->_usesession = empty($params['nosession']); - unset($params['nosession']); $this->setOption($params); + } - /* Set up the session for later to save tree states. */ - if ($this->_usesession && - !isset($_SESSION['horde_tree'][$this->_instance])) { - $_SESSION['horde_tree'][$this->_instance] = array(); - } - - $this->_img_dir = Horde_Themes::img(null, array('app' => 'horde', 'notheme' => true)) . '/tree'; - - if (!empty($GLOBALS['nls']['rtl'][$GLOBALS['language']])) { - $rev_imgs = array( - 'line', 'join', 'join_bottom', 'plus', 'plus_bottom', - 'plus_only', 'minus', 'minus_bottom', 'minus_only', - 'null_only', 'leaf' - ); - foreach ($rev_imgs as $val) { - $this->_images[$val] = 'rev-' . $this->_images[$val]; - } - } + /** + * 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) + { + return ''; } /** @@ -263,16 +195,9 @@ class Horde_Tree /** * Sets an option. * - * @param mixed $option The option name -or- an array of option name/value - * pairs. Available options: - *
-     * alternate - (boolean) Alternate shading in the table?
-     * class - (string) The class to use for the table.
-     * hideHeaders - (boolean) Don't render any HTML for the header row, just
-     *               use the widths.
-     * lines - (boolean) Show tree lines?
-     * multiline - (boolean) Do the node labels contain linebreaks?
-     * 
+ * @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) @@ -338,29 +263,6 @@ class Horde_Tree $extra_right = array(), $extra_left = array()) { $this->_nodes[$id]['label'] = $label; - - if ($this->_usesession) { - $session_state = $_SESSION['horde_tree'][$this->_instance]; - $toggle_id = Horde_Util::getFormData(self::TOGGLE . $this->_instance); - if ($id == $toggle_id) { - /* We have a url toggle request for this node. */ - if (isset($session_state['expanded'][$id])) { - /* Use session state if it is set. */ - $expanded = (!$session_state['expanded'][$id]); - } else { - /* Otherwise use what was passed through the - * function. */ - $expanded = (!$expanded); - } - - /* Save this state to session. */ - $_SESSION['horde_tree'][$this->_instance]['expanded'][$id] = $expanded; - } elseif (isset($session_state['expanded'][$id])) { - /* If we have a saved session state use it. */ - $expanded = $session_state['expanded'][$id]; - } - } - $this->_nodes[$id]['expanded'] = $expanded; /* If any params included here add them now. */ @@ -561,13 +463,4 @@ class Horde_Tree return true; } - /** - * Returns just the JS node definitions as a string. - * - * @return string The Javascript node array definitions. - */ - public function renderNodeDefinitions() - { - } - } diff --git a/framework/Tree/lib/Horde/Tree/Exception.php b/framework/Tree/lib/Horde/Tree/Exception.php new file mode 100644 index 000000000..97068e759 --- /dev/null +++ b/framework/Tree/lib/Horde/Tree/Exception.php @@ -0,0 +1,17 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Tree + */ +class Horde_Tree_Exception extends Horde_Exception_Prior +{ +} diff --git a/framework/Tree/lib/Horde/Tree/Html.php b/framework/Tree/lib/Horde/Tree/Html.php index bba2282e9..8fef934f9 100644 --- a/framework/Tree/lib/Horde/Tree/Html.php +++ b/framework/Tree/lib/Horde/Tree/Html.php @@ -10,26 +10,27 @@ * * @author Marko Djukic * @category Horde - * @package Horde_Tree + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Tree */ class Horde_Tree_Html extends Horde_Tree { /** - * TODO + * Node list. * * @var array */ protected $_nodes = array(); /** - * TODO + * Node position list. * * @var array */ protected $_node_pos = array(); /** - * TODO + * Drop line cache. * * @var array */ @@ -43,6 +44,28 @@ class Horde_Tree_Html extends Horde_Tree protected $_alt_count = 0; /** + * Images array. + * + * @var array + */ + protected $_images = array( + 'line' => null, + 'blank' => null, + 'join' => null, + 'join_bottom' => 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 + ); + + /** * Returns the tree. * * @param boolean $static If true the tree nodes can't be expanded and @@ -193,15 +216,15 @@ class Horde_Tree_Html extends Horde_Tree } for ($i = $this->_static ? 1 : 0; $i < $this->_nodes[$node_id]['indent']; $i++) { - $line .= '_dropline[$i] && $this->getOption('lines', false, true)) { $line .= $this->_images['line'] . '" ' - . 'alt="|   " '; + . 'alt="|   "'; } else { $line .= $this->_images['blank'] . '" ' - . 'alt="   " '; + . 'alt="   "'; } - $line .= 'height="20" width="20" style="vertical-align:middle" />'; + $line .= ' />'; } $line .= $this->_setNodeToggle($node_id) . $this->_setNodeIcon($node_id); if ($this->getOption('multiline')) { @@ -298,9 +321,9 @@ class Horde_Tree_Html extends Horde_Tree $img = $this->_images['plus_only']; $alt = '+'; } + if (!$this->_static) { - $url = Horde_Util::addParameter(Horde::selfUrl(), self::TOGGLE . $this->_instance, $node_id); - $link_start = Horde::link($url); + $link_start = $this->_generateUrlTag($node_id); } } elseif (($this->_nodes[$node_id]['indent'] != 0) && !isset($this->_nodes[$node_id]['children'])) { @@ -361,9 +384,9 @@ class Horde_Tree_Html extends Horde_Tree } $this->_dropline[$this->_nodes[$node_id]['indent']] = false; } + if (!$this->_static) { - $url = Horde_Util::addParameter(Horde::selfUrl(), self::TOGGLE . $this->_instance, $node_id); - $link_start = Horde::link($url); + $link_start = $this->_generateUrlTag($node_id); } } else { /* Top level node with no children. */ @@ -382,15 +405,30 @@ class Horde_Tree_Html extends Horde_Tree $link_end = ($link_start) ? '' : ''; - $img = $link_start . '' . $alt . '' + . ' />' . $link_end; return $img; } /** + * 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']); + $url->add(self::TOGGLE . $this->_instance, $node_id); + + return ''; + } + + /** * Sets the icon for the node. * * @param string $node_id The Node ID. @@ -399,11 +437,6 @@ class Horde_Tree_Html extends Horde_Tree */ protected function _setNodeIcon($node_id) { - $img_dir = isset($this->_nodes[$node_id]['icondir']) ? $this->_nodes[$node_id]['icondir'] : $this->_img_dir; - if ($img_dir) { - $img_dir .= '/'; - } - if (isset($this->_nodes[$node_id]['icon'])) { if (empty($this->_nodes[$node_id]['icon'])) { return ''; @@ -426,7 +459,7 @@ class Horde_Tree_Html extends Horde_Tree } } - $imgtxt = '_nodes[$node_id]['iconalt'])) { diff --git a/framework/Tree/lib/Horde/Tree/Select.php b/framework/Tree/lib/Horde/Tree/Select.php index fa5cb3866..78d0e8093 100644 --- a/framework/Tree/lib/Horde/Tree/Select.php +++ b/framework/Tree/lib/Horde/Tree/Select.php @@ -10,28 +10,24 @@ * * @author Ben Chavet * @category Horde - * @package Horde_Tree + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Tree */ class Horde_Tree_Select extends Horde_Tree { /** - * TODO + * Node list. * * @var array */ protected $_nodes = array(); /** - * Constructor. + * Should the tree be rendered statically? * - * @param string $name @see Horde_Tree::__construct(). - * @param array $params @see Horde_Tree::__construct(). + * @var boolean */ - public function __construct($tree_name, $params = array()) - { - parent::__construct($tree_name, $params); - $this->_static = true; - } + protected $_static = true; /** * Returns the tree. @@ -84,16 +80,18 @@ class Horde_Tree_Select extends Horde_Tree */ protected function _buildTree($node_id) { - $selected = $this->_nodes[$node_id]['selected'] ? ' selected="selected"' : ''; + $selected = $this->_nodes[$node_id]['selected'] + ? ' selected="selected"' + : ''; $output = ''; if (isset($this->_nodes[$node_id]['children']) && $this->_nodes[$node_id]['expanded']) { $num_subnodes = count($this->_nodes[$node_id]['children']); - for ($c = 0; $c < $num_subnodes; $c++) { + for ($c = 0; $c < $num_subnodes; ++$c) { $child_node_id = $this->_nodes[$node_id]['children'][$c]; $output .= $this->_buildTree($child_node_id); } diff --git a/framework/Tree/package.xml b/framework/Tree/package.xml index da0e0f38a..5d985cb8d 100644 --- a/framework/Tree/package.xml +++ b/framework/Tree/package.xml @@ -6,7 +6,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> Tree pear.horde.org Horde Tree API - The Horde_Tree:: class provides a tree view of hierarchical information. It allows for expanding/collapsing of branches and maintains their state. It can work together with javascript code to achieve this in DHTML on supported browsers. + The Horde_Tree:: package provides a tree view of hierarchical information. It allows for expanding/collapsing of branches and maintains their state. Chuck Hagenbuch @@ -30,15 +30,18 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta GPL - * Initial Horde 4 package. + * Remove dependency on horde/Core. + * Move javascript renderer to horde/Core. + * Add Horde_Tree_Exception::. + * Initial Horde 4 package. + - @@ -55,7 +58,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.7.0 - Core + Exception pear.horde.org @@ -71,8 +74,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> + - diff --git a/hermes/deliverables.php b/hermes/deliverables.php index 5a2e8488c..e6721a88e 100644 --- a/hermes/deliverables.php +++ b/hermes/deliverables.php @@ -88,7 +88,7 @@ if ($vars->exists('deliverable_id') || $vars->exists('new')) { Horde::fatal($deliverables, __FILE__, __LINE__); } - $tree = Horde_Tree::factory('deliverables', 'javascript'); + $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('deliverables', 'Javascript'); $tree->setOption(array('class' => 'item', 'alternate' => true)); diff --git a/horde/admin/activesync.php b/horde/admin/activesync.php index a4fdddc04..231c00b36 100644 --- a/horde/admin/activesync.php +++ b/horde/admin/activesync.php @@ -60,7 +60,8 @@ $base_node_params = $icondir + array('icon' => 'administration.png'); $device_node = $icondir + array('icon' => 'mobile.png'); $user_node = $icondir + array('icon' => 'user.png'); $users = array(); -$tree = Horde_Tree::factory('admin_devices', 'Javascript'); + +$tree = $injector->getInstance('Horde_Tree')->getTree('admin_devices', 'Javascript'); $tree->setOption(array('alternate' => true)); $tree->setHeader(array( array('width' => '30%'), diff --git a/horde/admin/datatree.php b/horde/admin/datatree.php index 697bce49a..0ecec6f4e 100644 --- a/horde/admin/datatree.php +++ b/horde/admin/datatree.php @@ -30,7 +30,7 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('horde', array('admin' => true)); require_once 'Horde/DataTree.php'; -$tree = Horde_Tree::factory('datatree', 'Javascript'); +$tree = $injector->getInstance('Horde_Tree')->getTree('datatree', 'Javascript'); $tree->setOption('alternate', true); $driver = $conf['datatree']['driver']; diff --git a/horde/admin/groups.php b/horde/admin/groups.php index b615bf5de..d1cd4d7a3 100644 --- a/horde/admin/groups.php +++ b/horde/admin/groups.php @@ -213,7 +213,7 @@ $edit_img = Horde::img('edit.png', _("Edit Group")); $delete_img = Horde::img('delete.png', _("Delete Group")); /* Set up the tree. */ -$tree = Horde_Tree::factory('admin_groups', 'Javascript'); +$tree = $injector->getInstance('Horde_Tree')->getTree('admin_groups', 'Javascript'); $tree->setOption(array('alternate' => true, 'hideHeaders' => true)); $tree->setHeader(array(array('width' => '50%'))); diff --git a/horde/js/hordetree.js b/horde/js/hordetree.js index 74f182517..6a9f0e745 100644 --- a/horde/js/hordetree.js +++ b/horde/js/hordetree.js @@ -174,13 +174,13 @@ var Horde_Tree = Class.create({ } for (i = this.renderStatic ? 1 : 0; i < node.indent; ++i) { - o.push('|');
             } else {
                 o.push(this.opts.imgBlank + ''); + o.push('   " />'); } o.push(this._setNodeToggle(nodeId)); @@ -284,14 +284,14 @@ var Horde_Tree = Class.create({ if (this.renderStatic) { return ''; } - attrib = ' style="cursor:pointer" onclick="' + this.opts.target + '.toggle(' + nodeId.toJSON().gsub('"', '"') + ')"'; + attrib = ' onclick="' + this.opts.target + '.toggle(' + nodeId.toJSON().gsub('"', '"') + ')"'; } else if (node.indent != '0' && Object.isUndefined(node.children)) { // Node no children. this.dropline[node.indent] = (this.node_pos[nodeId].pos < this.node_pos[nodeId].count); } else if (!Object.isUndefined(node.children)) { this.dropline[node.indent] = (this.node_pos[nodeId].pos < this.node_pos[nodeId].count); if (!this.renderStatic) { - attrib = ' style="cursor:pointer" onclick="' + this.opts.target + '.toggle(' + nodeId.toJSON().gsub('"', '"') + ')"'; + attrib = ' onclick="' + this.opts.target + '.toggle(' + nodeId.toJSON().gsub('"', '"') + ')"'; } } else { // Top level node with no children. @@ -301,11 +301,11 @@ var Horde_Tree = Class.create({ this.dropline[0] = false; } - img.push(''); + img.push(attrib + ' />'); return img.join(''); }, @@ -405,15 +405,11 @@ var Horde_Tree = Class.create({ var img = [], node = this.nodes[nodeId]; - img.push(' '); + img.push(' />'); return img.join(''); }, toggle: function(nodeId) { - var icon, nodeToggle, toggle, children + var icon, nodeToggle, toggle, children, node = this.nodes[nodeId], src = []; @@ -457,17 +453,12 @@ var Horde_Tree = Class.create({ children.setStyle({ display: node.expanded ? 'block' : 'none' }); } - // Toggle the node's icon if it has seperate open and closed + // Toggle the node's icon if it has separate open and closed // icons. - if (!Object.isUndefined(node.iconopen) && - (icon = $('nodeIcon_' + nodeId))) { + if (icon = $('nodeIcon_' + nodeId)) { // Image directory. - if (!Object.isUndefined(node.icondir)) { - if (node.icondir) { - src.push(node.icondir + '/'); - } - } else if (this.opts.imgDir) { - src.push(this.opts.imgDir + '/'); + if (!Object.isUndefined(node.icondir) && node.icondir) { + src.push(node.icondir + '/'); } // Image. @@ -488,7 +479,7 @@ var Horde_Tree = Class.create({ nodeToggle = this._getNodeToggle(nodeId); if (toggle = $('nodeToggle_' + nodeId)) { - toggle.src = this.opts.imgDir + '/' + nodeToggle[0]; + toggle.src = nodeToggle[0]; toggle.alt = nodeToggle[1]; } diff --git a/horde/services/help/index.php b/horde/services/help/index.php index b7ee3a62b..d1a362c12 100644 --- a/horde/services/help/index.php +++ b/horde/services/help/index.php @@ -71,7 +71,7 @@ case 'sidebar': $tabs->addTab(_("Sea_rch"), $sidebar_url, 'search'); /* Set up the tree. */ - $tree = Horde_Tree::factory('horde_menu', 'Javascript'); + $tree = $injector->getInstance('Horde_Tree')->getTree('horde_menu', 'Javascript'); $tree->setOption(array('target' => 'help_main')); $contents = ''; diff --git a/horde/themes/screen.css b/horde/themes/screen.css index 52a10ae18..3150a1261 100644 --- a/horde/themes/screen.css +++ b/horde/themes/screen.css @@ -387,11 +387,17 @@ div.nicetitle { } /* Tree styles. */ +.treeIcon { + padding-right: 5px; +} .treeRow { overflow: hidden; min-height: 20px; clear: both; } +.treeToggle { + cursor: pointer; +} /* Menu styles. */ #menu { diff --git a/trean/lib/Trean.php b/trean/lib/Trean.php index 00dafb8bc..241ce8e1c 100644 --- a/trean/lib/Trean.php +++ b/trean/lib/Trean.php @@ -91,7 +91,7 @@ class Trean $folders = array(); } - $tree = Horde_Tree::factory('folder_select', 'select'); + $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('folder_select', 'Select'); foreach ($folders as $folder_name => $folder) { /* Selected or not? */ diff --git a/trean/templates/browse.php b/trean/templates/browse.php index 76362603c..4b77da32a 100644 --- a/trean/templates/browse.php +++ b/trean/templates/browse.php @@ -118,7 +118,8 @@ $folders = Trean::listFolders(Horde_Perms::READ); if (!is_a($folders, 'PEAR_Error')) { $params = array('icon' => 'folder.png', 'iconopen' => 'folderopen.png'); - $tree = Horde_Tree::factory('folder_tree', 'javascript', array('alternate' => true)); + $tree = $GLOBALS['injector']->getInstance('Horde_Tree')->getTree('folder_tree', 'Javascript'); + $tree->setOption(array('alternate' => true)); $expand = $prefs->getValue('expand_tree'); if ($expand == 'none') { $expand = false; -- 2.11.0