break;
}
+ $params['session'] = 'horde_tree';
+
$this->_instances[$id] = Horde_Tree::factory($name, $renderer, $params);
}
{
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) {
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);
- }
-
}
Horde::addScriptFile('hordetree.js', 'horde');
/* Check for a javascript session state. */
- if (isset($_COOKIE[$this->_instance . '_expanded'])) {
+ if (!empty($this->_options['session']) &&
+ isset($_COOKIE[$this->_instance . '_expanded'])) {
/* Remove "exp" prefix from cookie value. */
$nodes = explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3));
/* Save nodes to the session. */
- $_SESSION['horde_tree'][$this->_instance]['expanded'] = array_combine(
+ $_SESSION[$this->_options['session']][$this->_instance]['expanded'] = array_combine(
$nodes,
array_fill(0, count($nodes), true)
);
}
/**
- * 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.');
- }
-
- /**
* Constructor.
*
* @param string $name The name of this tree instance.
* use the widths.
* lines - (boolean) Show tree lines?
* multiline - (boolean) Do the node labels contain linebreaks?
+ * session - (string) The name of the session array key to store data.
+ * If this is an empty string, session storage will be disabled.
+ * DEFAULT: No session storage
* </pre>
*/
public function __construct($name, array $params = array())
{
$this->_instance = $name;
$this->setOption($params);
+
+ if (!empty($this->_options['session']) &&
+ !isset($_SESSION[$this->_options['session']][$this->_instance])) {
+ $_SESSION[$this->_options['session']][$this->_instance] = array();
+ }
+ }
+
+ /**
+ * 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.');
}
/**
$expanded = true, $params = array(),
$extra_right = array(), $extra_left = array())
{
+ if (!empty($this->_options['session'])) {
+ $sess = &$_SESSION[$this->_options['session']][$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 = $sess['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];
+ }
+ }
+
$this->_nodes[$id]['label'] = $label;
$this->_nodes[$id]['expanded'] = $expanded;