}
if (empty($params['nosession'])) {
- $params['session'] = 'horde_tree';
+ $params['session'] = array(
+ 'get' => array($this, 'getSession'),
+ 'set' => array($this, 'setSession')
+ );
}
$this->_instances[$id] = Horde_Tree::factory($name, $renderer, $params);
return $this->_instances[$id];
}
+ /**
+ */
+ public function getSession($instance, $id)
+ {
+ return $GLOBALS['session']['horde:tree-' . $instance . '/' . $id];
+ }
+
+ /**
+ */
+ public function setSession($instance, $id, $val)
+ {
+ $GLOBALS['session']['horde:tree-' . $instance . '/' . $id] = $val;
+ }
+
}
if (($session = $this->getOption('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[$session][$this->_instance]['expanded'] = array_combine(
- $nodes,
- array_fill(0, count($nodes), true)
- );
+ foreach (explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3)) as $val) {
+ /* Save nodes to the session. */
+ call_user_func($session['set'], $this->_instance, $val, true);
+ }
}
}
* @param string $name The name of this tree instance.
* @param array $params Additional parameters.
* <pre>
- * session - (string) The name of the session array key to store data.
- * If this is an empty string, session storage will be disabled.
+ * session - (array) Callbacks used to store session data. Must define
+ * two keys: 'get' and 'set'. Function definitions:
+ * (string) = get([string - Instance], [string - ID]);
+ * set([string - Instance], [string - ID], [boolean - value]);
* DEFAULT: No session storage
* </pre>
*/
{
$this->_instance = $name;
$this->setOption($params);
-
- if (($sess = $this->getOption('session')) &&
- !isset($_SESSION[$sess][$this->_instance])) {
- $_SESSION[$sess][$this->_instance] = array();
- }
}
/**
{
$nodeid = $this->_nodeId($id);
- if (($session = $this->getOption('session'))) {
- $sess = &$_SESSION[$session][$this->_instance];
+ if ($session = $this->getOption('session')) {
$toggle_id = Horde_Util::getFormData(Horde_Tree::TOGGLE . $this->_instance);
if ($nodeid == $toggle_id) {
/* We have a URL toggle request for this node. */
- $expanded = $sess['expanded'][$nodeid] = isset($sess['expanded'][$id])
+ $expanded = (call_user_func($session['get'], $this->_instance, $id) !== null)
/* Use session state if it is set. */
- ? (!$sess['expanded'][$nodeid])
+ ? !call_user_func($session['get'], $this->_instance, $nodeid)
/* Otherwise use what was passed through the function. */
- : (!$expanded);
- } elseif (isset($sess['expanded'][$nodeid])) {
+ : !$expanded;
+ call_user_func($session['set'], $this->_instance, $nodeid, $expanded);
+ } elseif (($exp_get = call_user_func($session['get'], $this->_instance, $nodeid)) !== null) {
/* If we have a saved session state use it. */
- $expanded = $sess['expanded'][$nodeid];
+ $expanded = $exp_get;
}
}