1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_Tree_Flist extends Horde_Tree_Renderer_Select
25: {
26: 27: 28: 29: 30:
31: protected $_filter = array();
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60:
61: public function __construct(Horde_Tree $tree, array $params = array())
62: {
63: $params = array_merge(array(
64: 'abbrev' => 30
65: ), $params);
66:
67: parent::__construct($tree, $params);
68: }
69:
70: 71: 72:
73: public function getTree($static = false)
74: {
75: global $conf, $injector, $registry;
76:
77: $this->_nodes = $this->_tree->getNodes();
78:
79: $filter = $injector->createInstance('Horde_Text_Filter');
80:
81: $view = new Horde_View(array(
82: 'templatePath' => IMP_TEMPLATES . '/basic/flist'
83: ));
84: $view->addHelper('FormTag');
85: $view->addHelper('Tag');
86:
87: $view->optgroup = $this->getOption('optgroup');
88:
89:
90: if ($customhtml = $this->getOption('customhtml')) {
91: $view->customhtml = $customhtml;
92: }
93:
94:
95: if (($heading = $this->getOption('heading')) &&
96: (strlen($heading) > 0)) {
97: $view->heading = $heading;
98: }
99:
100:
101: if ($this->getOption('new_mbox')) {
102: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
103: if ($imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX) &&
104: $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX)) {
105: $view->new_mbox = true;
106: }
107: }
108:
109:
110: if ($this->getOption('inc_vfolder')) {
111: $iterator = IMP_Search_IteratorFilter::create(
112: IMP_Search_IteratorFilter::VFOLDER
113: );
114: $vfolder_list = array();
115:
116: foreach ($iterator as $val) {
117: $form_to = IMP_Mailbox::formTo($val);
118: $vfolder_list[] = array(
119: 'l' => $filter->filter($val->label, 'space2html', array('encode' => true)),
120: 'sel' => !empty($this->_nodes[$form_to]['selected']),
121: 'v' => $form_to
122: );
123: }
124:
125: if (!empty($vfolder_list)) {
126: $view->vfolder = $vfolder_list;
127: }
128: }
129:
130:
131: if ($this->getOption('inc_tasklists') &&
132: $conf['tasklist']['use_tasklist'] &&
133: $registry->hasMethod('tasks/listTasklists')) {
134: try {
135: $tasklists = $registry->call('tasks/listTasklists', array(false, Horde_Perms::EDIT));
136:
137: if (count($tasklists)) {
138: $tasklist_list = array();
139: foreach ($tasklists as $id => $tasklist) {
140: $tasklist_list[] = array(
141: 'l' => $filter->filter($tasklist->get('name'), 'space2html', array('encode' => true)),
142: 'v' => IMP_Mailbox::formTo(IMP::TASKLIST_EDIT . $id)
143: );
144: }
145: $view->tasklist = $tasklist_list;
146: }
147: } catch (Horde_Exception $e) {}
148: }
149:
150:
151: if ($this->getOption('inc_notepads') &&
152: $conf['notepad']['use_notepad'] &&
153: $registry->hasMethod('notes/listNotepads')) {
154: try {
155: $notepads = $registry->call('notes/listNotepads', array(false, Horde_Perms::EDIT));
156:
157: if (count($notepads)) {
158: foreach ($notepads as $id => $notepad) {
159: $notepad_list[] = array(
160: 'l' => $filter->filter($notepad->get('name'), 'space2html', array('encode' => true)),
161: 'v' => IMP_Mailbox::formTo(IMP::NOTEPAD_EDIT . $id)
162: );
163: }
164: $view->notepad = $notepad_list;
165: }
166: } catch (Horde_Exception $e) {}
167: }
168:
169:
170: $this->_filter = ($filter = $this->getOption('filter'))
171: ? array_flip($filter)
172: : array();
173:
174: $tree = '';
175: foreach ($this->_tree->getRootNodes() as $node_id) {
176: $tree .= $this->_buildTree($node_id);
177: }
178: $view->tree = $tree;
179:
180: return $view->render('flist');
181: }
182:
183: 184:
185: protected function _buildTree($node_id)
186: {
187: if (isset($this->_filter[$node_id])) {
188: return '';
189: }
190:
191: $node = &$this->_nodes[$node_id];
192:
193: if ($abbrev = $this->getOption('abbrev')) {
194: $orig_label = $node['label'];
195: $node['label'] = Horde_String::abbreviate($node['orig_label'], $abbrev - ($node['indent'] * 2));
196: } else {
197: $orig_label = null;
198: }
199:
200:
201: if (!$this->getOption('container_select') &&
202: !empty($node['container'])) {
203: if (!empty($node['vfolder'])) {
204: return '';
205: }
206: $node_id = '';
207: $this->_nodes[$node_id] = $node;
208: }
209:
210: $out = parent::_buildTree($node_id);
211:
212: if ($orig_label) {
213: $node['label'] = $orig_label;
214: }
215:
216: return $out;
217: }
218:
219: }
220: