<?php
/**
+ * DataTree browser.
+ *
* Copyright 2004-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.
*
- * @author Jan Schneider <jan@horde.org>
+ * @author Jan Schneider <jan@horde.org>
+ * @category Horde
*/
-function addTree($parent, $parent_id, $indent = 1)
+function _addTree($parent, $parent_id, $datatree, $tree, $indent = 1)
{
- global $datatree, $tree;
-
$nodes = $datatree->getById(DATATREE_FORMAT_FLAT, $parent_id, true, $parent, 1);
- $expanded = $tree->isExpanded($parent);
$url = Horde::url('datatree.php');
+
foreach ($nodes as $id => $node) {
- if ($id == $parent_id) {
- continue;
- }
- $tree->addNode($parent . ':' . $id, $parent, $datatree->getShortName($node), $indent, false, array('url' => Horde_Util::addParameter($url, 'show', $datatree->getParam('group') . ':' . $id) . '#show'));
- if ($expanded) {
- addTree($parent . ':' . $id, $id, $indent + 1);
+ if ($id != $parent_id) {
+ $node_url = $url->copy()->add('show', $datatree->getParam('group') . ':' . $id);
+ $node_url->anchor = 'show';
+
+ $tree->addNode($parent . ':' . $id, $parent, $datatree->getShortName($node), $indent, false, array('url' => strval($node_url)));
+ _addTree($parent . ':' . $id, $id, $datatree, $tree, $indent + 1);
}
}
}
Horde_Registry::appInit('horde', array('admin' => true));
require_once 'Horde/DataTree.php';
-$tree = $injector->getInstance('Horde_Tree')->getTree('datatree', 'Javascript');
-$tree->setOption('alternate', true);
+
+$tree = $injector->getInstance('Horde_Tree')->getTree('datatree', 'Javascript', array(
+ 'alternate' => true
+));
$driver = $conf['datatree']['driver'];
$config = Horde::getDriverConfig('datatree', $conf['datatree']['driver']);
$datatree = DataTree::singleton($conf['datatree']['driver']);
$roots = $datatree->getGroups();
-if (is_a($roots, 'PEAR_Error')) {
+if ($roots instanceof PEAR_Error) {
$notification->push($roots);
} else {
foreach ($roots as $root) {
$tree->addNode($root, null, $root, 0, false);
- $datatree = DataTree::singleton($driver, array_merge($config, array('group' => $root)));
- addTree($root, DATATREE_ROOT);
+ _addTree($root, DATATREE_ROOT, DataTree::singleton($driver, array_merge($config, array('group' => $root))), $tree);
}
}
echo '<h1 class="header">' . Horde::img('datatree.png') . ' ' . _("DataTree") . '</h1>';
$tree->renderTree();
if ($show) {
- echo '<br /><div class="text" style="white-space:pre"><a id="show"></a>';
- echo "<strong>Data:</strong>\n";
- ob_start('htmlspecialchars');
- print_r($data);
- ob_end_flush();
- echo "\n<strong>Attributes:</strong>\n";
- ob_start('htmlspecialchars');
- print_r($attributes);
- ob_end_flush();
- echo '</div>';
+ echo '<br /><div class="text" style="white-space:pre"><a id="show"></a>' .
+ "<strong>Data:</strong>\n" .
+ htmlspecialchars(print_r($data, true)) .
+ "\n<strong>Attributes:</strong>\n" .
+ htmlspecialchars(print_r($attributes, true)) .
+ '</div>';
}
require HORDE_TEMPLATES . '/common-footer.inc';