From 4e4cf781c170606b3c1254bbde2a6f6a88ae2f3e Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 14 Jul 2010 13:43:52 -0600 Subject: [PATCH] DataTree browser tweaks. Fix not showing deeper children. Don't use globals. Use Horde_Url. Avoid output buffering. --- horde/admin/datatree.php | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/horde/admin/datatree.php b/horde/admin/datatree.php index 0ecec6f4e..8d3812f43 100644 --- a/horde/admin/datatree.php +++ b/horde/admin/datatree.php @@ -1,27 +1,28 @@ + * @author Jan Schneider + * @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); } } } @@ -30,21 +31,22 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; 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); } } @@ -61,15 +63,11 @@ require HORDE_TEMPLATES . '/admin/menu.inc'; echo '

' . Horde::img('datatree.png') . ' ' . _("DataTree") . '

'; $tree->renderTree(); if ($show) { - echo '
'; - echo "Data:\n"; - ob_start('htmlspecialchars'); - print_r($data); - ob_end_flush(); - echo "\nAttributes:\n"; - ob_start('htmlspecialchars'); - print_r($attributes); - ob_end_flush(); - echo '
'; + echo '
' . + "Data:\n" . + htmlspecialchars(print_r($data, true)) . + "\nAttributes:\n" . + htmlspecialchars(print_r($attributes, true)) . + '
'; } require HORDE_TEMPLATES . '/common-footer.inc'; -- 2.11.0