1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
18: {
19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: public function __construct($name, array $params = array())
30: {
31: parent::__construct($name, $params);
32:
33: Horde::addScriptFile('hordetree.js', 'horde');
34:
35:
36: if (($session = $this->getOption('session')) &&
37: isset($_COOKIE[$this->_instance . '_expanded'])) {
38:
39: $curr = call_user_func($session['get'], $this->_instance, '', Horde_Session::TYPE_ARRAY);
40:
41:
42: $exp = explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3));
43:
44:
45: foreach (array_filter($exp) as $val) {
46: call_user_func($session['set'], $this->_instance, $val, true);
47: }
48:
49:
50: foreach (array_diff(array_keys($curr), $exp) as $val) {
51: call_user_func($session['set'], $this->_instance, $val, false);
52: }
53: }
54: }
55:
56: 57: 58: 59: 60:
61: public function fallback()
62: {
63: return 'Horde_Core_Tree_Html';
64: }
65:
66: 67: 68: 69: 70: 71: 72: 73:
74: public function getTree($static = false)
75: {
76: $this->_static = $static;
77:
78: $opts = array(
79: 'extraColsLeft' => $this->_colsLeft,
80: 'extraColsRight' => $this->_colsRight,
81: 'header' => $this->_header,
82: 'nocookie' => !$this->getOption('session'),
83: 'options' => $this->_options,
84: 'target' => $this->_instance,
85:
86: 'cookieDomain' => $GLOBALS['conf']['cookie']['domain'],
87: 'cookiePath' => $GLOBALS['conf']['cookie']['path'],
88:
89: 'imgBlank' => $this->_images['blank'],
90: 'imgFolder' => $this->_images['folder'],
91: 'imgFolderOpen' => $this->_images['folderopen'],
92: 'imgLine' => $this->_images['line'],
93: 'imgJoin' => $this->_images['join'],
94: 'imgJoinBottom' => $this->_images['join_bottom'],
95: 'imgJoinTop' => $this->_images['join_top'],
96: 'imgPlus' => $this->_images['plus'],
97: 'imgPlusBottom' => $this->_images['plus_bottom'],
98: 'imgPlusOnly' => $this->_images['plus_only'],
99: 'imgMinus' => $this->_images['minus'],
100: 'imgMinusBottom' => $this->_images['minus_bottom'],
101: 'imgMinusOnly' => $this->_images['minus_only'],
102: 'imgNullOnly' => $this->_images['null_only'],
103: 'imgLeaf' => $this->_images['leaf'],
104:
105: 'initTree' => $this->renderNodeDefinitions()
106: );
107:
108: if (!($js_var = $this->getOption('jsvar'))) {
109: $js_var = $this->_instance;
110: }
111:
112: Horde::addInlineScript(array(
113: 'window.' . $js_var . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')'
114: ), 'dom');
115:
116: return '<div id="' . $this->_instance . '"></div>';
117: }
118:
119: 120: 121: 122: 123: 124:
125: public function isSupported()
126: {
127: return $GLOBALS['browser']->hasFeature('dom');
128: }
129:
130: 131: 132: 133: 134: 135:
136: public function renderNodeDefinitions()
137: {
138: $this->_buildIndents($this->_root_nodes);
139:
140: $result = new stdClass;
141: $result->is_static = intval($this->_static);
142: $result->nodes = $this->_nodes;
143: $result->root_nodes = $this->_root_nodes;
144: $result->files = array();
145:
146: foreach ($GLOBALS['injector']->getInstance('Horde_Script_Files')->listFiles() as $apps) {
147: foreach ($apps as $file) {
148: 149:
150: if ($file['f'] == 'prototype.js' ||
151: $file['f'] == 'hordetree.js' ||
152: $file['f'] == 'accesskeys.js') {
153: continue;
154: }
155: $result->files[] = (string)$file['u'];
156: }
157: }
158:
159: return $result;
160: }
161: }
162: