From: Jehan-Guillaume (ioguix) de Rorthais Date: Fri, 23 Mar 2012 16:40:53 +0000 (+0100) Subject: Add support for 'tree' hooks in the plugin architecture. X-Git-Tag: REL_5-1-0~66 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=2820a9812c17eaed93b88d12a35588d4baeea770;p=phppgadmin.git Add support for 'tree' hooks in the plugin architecture. --- diff --git a/aggregates.php b/aggregates.php index 6970d338..1e839d6e 100644 --- a/aggregates.php +++ b/aggregates.php @@ -418,7 +418,7 @@ ) ); - $misc->printTreeXML($aggregates, $attrs); + $misc->printTree($aggregates, $attrs, 'aggregates'); exit; } diff --git a/all_db.php b/all_db.php index 41585fba..110ba96b 100644 --- a/all_db.php +++ b/all_db.php @@ -488,7 +488,7 @@ ), ); - $misc->printTreeXML($databases, $attrs); + $misc->printTree($databases, $attrs, 'databases'); exit; } diff --git a/casts.php b/casts.php index 257df6a3..2be86b4f 100644 --- a/casts.php +++ b/casts.php @@ -80,7 +80,7 @@ 'icon' => 'Cast' ); - $misc->printTreeXML($casts, $attrs); + $misc->printTree($casts, $attrs, 'casts'); exit; } diff --git a/classes/Misc.php b/classes/Misc.php index 84c8be8e..44e395ff 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -1994,24 +1994,55 @@ * 'branch' - URL for child nodes (tree XML) * 'expand' - the action to return XML for the subtree * 'nodata' - message to display when node has no children - * 'nohead' - suppress headers and opening tag - * 'nofoot' - suppress closing tag + * @param $section The section where the branch is linked in the tree + */ + function printTree(&$_treedata, &$attrs, $section) { + global $plugin_manager; + + $treedata = array(); + + if ($_treedata->recordCount() > 0) { + while (!$_treedata->EOF) { + $treedata[] = $_treedata->fields; + $_treedata->moveNext(); + } + } + + $plugin_functions_parameters = array( + 'treedata' => &$treedata, + 'attrs' => &$attrs, + 'section' => $section + ); + $plugin_manager->do_hook('tree', $plugin_functions_parameters); + + $this->printTreeXML($treedata, $attrs); + } + + /** Produce XML data for the browser tree + * @param $treedata A set of records to populate the tree. + * @param $attrs Attributes for tree items + * 'text' - the text for the tree node + * 'icon' - an icon for node + * 'openIcon' - an alternative icon when the node is expanded + * 'toolTip' - tool tip text for the node + * 'action' - URL to visit when single clicking the node + * 'iconAction' - URL to visit when single clicking the icon node + * 'branch' - URL for child nodes (tree XML) + * 'expand' - the action to return XML for the subtree + * 'nodata' - message to display when node has no children */ function printTreeXML(&$treedata, &$attrs) { global $conf, $lang; - if (!isset($attrs['nohead']) || $attrs['nohead'] === false) { - header("Content-Type: text/xml; charset=UTF-8"); - header("Cache-Control: no-cache"); + header("Content-Type: text/xml; charset=UTF-8"); + header("Cache-Control: no-cache"); - echo "\n"; + echo "\n"; - echo "\n"; - } + echo "\n"; - if ($treedata->recordCount() > 0) { - while (!$treedata->EOF) { - $rec =& $treedata->fields; + if (count($treedata) > 0) { + foreach($treedata as $rec) { echo "\n"; - - $treedata->moveNext(); } } else { $msg = isset($attrs['nodata']) ? $attrs['nodata'] : $lang['strnoobjects']; echo "icon('ObjectNotFound'), "\" />\n"; } - if (!isset($attrs['nofoot']) || $attrs['nofoot'] === false) { - echo "\n"; - } + echo "\n"; } function adjustTabsForTree(&$tabs) { diff --git a/classes/PluginManager.php b/classes/PluginManager.php index e2a97c92..1f01390f 100644 --- a/classes/PluginManager.php +++ b/classes/PluginManager.php @@ -10,7 +10,14 @@ class PluginManager { * Attributes */ private $plugins_list = array(); - private $available_hooks = array('toplinks', 'tabs', 'trail', 'navlinks', 'actionbuttons' /* wip, more hooks to come in next commits */); + private $available_hooks = array( + 'toplinks', + 'tabs', + 'trail', + 'navlinks', + 'actionbuttons', + 'tree' + ); private $actions = array(); private $hooks = array(); diff --git a/constraints.php b/constraints.php index 5aa7462f..526e7b7d 100644 --- a/constraints.php +++ b/constraints.php @@ -572,7 +572,7 @@ 'icon' => callback('getIcon'), ); - $misc->printTreeXML($constraints, $attrs); + $misc->printTree($constraints, $attrs, 'constraints'); exit; } diff --git a/conversions.php b/conversions.php index 8b5ab7c4..32def8d7 100644 --- a/conversions.php +++ b/conversions.php @@ -68,7 +68,7 @@ 'toolTip'=> field('concomment') ); - $misc->printTreeXML($conversions, $attrs); + $misc->printTree($conversions, $attrs, 'conversions'); exit; } diff --git a/database.php b/database.php index 5a655780..8221237b 100755 --- a/database.php +++ b/database.php @@ -630,7 +630,7 @@ ), ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, 'database'); exit; } diff --git a/domains.php b/domains.php index 633535a0..c7e3e79f 100644 --- a/domains.php +++ b/domains.php @@ -531,7 +531,7 @@ ) ); - $misc->printTreeXML($domains, $attrs); + $misc->printTree($domains, $attrs, 'domains'); exit; } diff --git a/fulltext.php b/fulltext.php index b6bb9e70..cdc6a2ec 100644 --- a/fulltext.php +++ b/fulltext.php @@ -997,7 +997,7 @@ ), ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, 'fts'); exit; } @@ -1044,7 +1044,7 @@ ), ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, strtolower($what)); exit; } diff --git a/functions.php b/functions.php index cd36244b..fc0522c8 100644 --- a/functions.php +++ b/functions.php @@ -966,7 +966,7 @@ ) ); - $misc->printTreeXML($funcs, $attrs); + $misc->printTree($funcs, $attrs, 'functions'); exit; } diff --git a/indexes.php b/indexes.php index 113a26d4..fefe1a60 100644 --- a/indexes.php +++ b/indexes.php @@ -374,7 +374,7 @@ 'icon' => callback('getIcon'), ); - $misc->printTreeXML($indexes, $attrs); + $misc->printTree($indexes, $attrs, 'indexes'); exit; } diff --git a/languages.php b/languages.php index c201aba7..b337638b 100644 --- a/languages.php +++ b/languages.php @@ -59,7 +59,7 @@ 'icon' => 'Language' ); - $misc->printTreeXML($languages, $attrs); + $misc->printTree($languages, $attrs, 'languages'); exit; } diff --git a/opclasses.php b/opclasses.php index 9446dbad..f0e399f2 100644 --- a/opclasses.php +++ b/opclasses.php @@ -71,7 +71,7 @@ 'toolTip'=> field('opccomment'), ); - $misc->printTreeXML($opclasses, $attrs); + $misc->printTree($opclasses, $attrs, 'opclasses'); exit; } diff --git a/operators.php b/operators.php index 4aa0b10b..c3be64fb 100644 --- a/operators.php +++ b/operators.php @@ -211,7 +211,7 @@ ) ); - $misc->printTreeXML($operators, $attrs); + $misc->printTree($operators, $attrs, 'operators'); exit; } diff --git a/rules.php b/rules.php index ffe88157..6f0f3d86 100644 --- a/rules.php +++ b/rules.php @@ -197,7 +197,7 @@ 'icon' => 'Rule', ); - $misc->printTreeXML($rules, $attrs); + $misc->printTree($rules, $attrs, 'rules'); exit; } diff --git a/schemas.php b/schemas.php index 73b74b77..750d3737 100755 --- a/schemas.php +++ b/schemas.php @@ -414,7 +414,7 @@ ), ); - $misc->printTreeXML($schemas, $attrs); + $misc->printTree($schemas, $attrs, 'schemas'); exit; } @@ -442,7 +442,7 @@ ) ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, 'schema'); exit; } diff --git a/sequences.php b/sequences.php index 5d72e575..223a8c8d 100644 --- a/sequences.php +++ b/sequences.php @@ -132,7 +132,7 @@ ) ); - $misc->printTreeXML($sequences, $attrs); + $misc->printTree($sequences, $attrs, 'sequences'); exit; } diff --git a/servers.php b/servers.php index ae8647a8..603dd2ed 100644 --- a/servers.php +++ b/servers.php @@ -148,11 +148,15 @@ 'branch' => field('branch'), ); - $misc->printTreeXML($nodes, $attrs); + $misc->printTree($servers, $attrs, 'servers'); exit; } - if ($action == 'tree') doTree(); + + if ($action == 'tree') { + if (isset($_GET['group'])) doTree($_GET['group']); + else doTree(false); + } $misc->printHeader($lang['strservers']); $misc->printBody(); diff --git a/tables.php b/tables.php index caf59cb4..f94ce63c 100644 --- a/tables.php +++ b/tables.php @@ -960,7 +960,7 @@ ) ); - $misc->printTreeXML($tables, $attrs); + $misc->printTree($tables, $attrs, 'tables'); exit; } @@ -992,7 +992,7 @@ ), ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, 'table'); exit; } diff --git a/tblproperties.php b/tblproperties.php index dcb67f0d..37bcc728 100644 --- a/tblproperties.php +++ b/tblproperties.php @@ -425,7 +425,7 @@ 'toolTip'=> field('comment') ); - $misc->printTreeXML($columns, $attrs); + $misc->printTree($columns, $attrs, 'tblcolumns'); exit; } diff --git a/triggers.php b/triggers.php index cd8fb31b..fbe81058 100644 --- a/triggers.php +++ b/triggers.php @@ -393,7 +393,7 @@ 'icon' => 'Trigger', ); - $misc->printTreeXML($triggers, $attrs); + $misc->printTree($triggers, $attrs, 'triggers'); exit; } diff --git a/types.php b/types.php index 8d23edf4..159ee1a0 100644 --- a/types.php +++ b/types.php @@ -669,7 +669,7 @@ ) ); - $misc->printTreeXML($types, $attrs); + $misc->printTree($types, $attrs, 'types'); exit; } diff --git a/viewproperties.php b/viewproperties.php index 531d7613..d13a4f39 100755 --- a/viewproperties.php +++ b/viewproperties.php @@ -376,7 +376,7 @@ 'toolTip'=> field('comment') ); - $misc->printTreeXML($columns, $attrs); + $misc->printTree($columns, $attrs, 'viewcolumns'); exit; } diff --git a/views.php b/views.php index a271d282..be8c88d0 100644 --- a/views.php +++ b/views.php @@ -705,7 +705,7 @@ ) ); - $misc->printTreeXML($views, $attrs); + $misc->printTree($views, $attrs, 'views'); exit; } @@ -730,7 +730,7 @@ ), ); - $misc->printTreeXML($items, $attrs); + $misc->printTree($items, $attrs, 'view'); exit; }