Skip to content

Commit

Permalink
Add support for 'tree' hooks in the plugin architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Aug 22, 2012
1 parent 4f77054 commit 2820a98
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 45 deletions.
2 changes: 1 addition & 1 deletion aggregates.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function doTree() {
)
);

$misc->printTreeXML($aggregates, $attrs);
$misc->printTree($aggregates, $attrs, 'aggregates');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion all_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function doTree() {
),
);

$misc->printTreeXML($databases, $attrs);
$misc->printTree($databases, $attrs, 'databases');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion casts.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function doTree() {
'icon' => 'Cast'
);

$misc->printTreeXML($casts, $attrs);
$misc->printTree($casts, $attrs, 'casts');
exit;
}

Expand Down
59 changes: 43 additions & 16 deletions classes/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1994,24 +1994,55 @@ function printTable(&$tabledata, &$columns, &$actions, $place, $nodata = null, $
* '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 <tree> tag
* 'nofoot' - suppress closing </tree> 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 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

echo "<tree>\n";
}
echo "<tree>\n";

if ($treedata->recordCount() > 0) {
while (!$treedata->EOF) {
$rec =& $treedata->fields;
if (count($treedata) > 0) {
foreach($treedata as $rec) {

echo "<tree";
echo value_xml_attr('text', $attrs['text'], $rec);
Expand All @@ -2030,17 +2061,13 @@ function printTreeXML(&$treedata, &$attrs) {
echo value_xml_attr('tooltip', $attrs['toolTip'], $rec);

echo " />\n";

$treedata->moveNext();
}
} else {
$msg = isset($attrs['nodata']) ? $attrs['nodata'] : $lang['strnoobjects'];
echo "<tree text=\"{$msg}\" onaction=\"tree.getSelected().getParent().reload()\" icon=\"", $this->icon('ObjectNotFound'), "\" />\n";
}

if (!isset($attrs['nofoot']) || $attrs['nofoot'] === false) {
echo "</tree>\n";
}
echo "</tree>\n";
}

function adjustTabsForTree(&$tabs) {
Expand Down
9 changes: 8 additions & 1 deletion classes/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion constraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ function getIcon($f) {
'icon' => callback('getIcon'),
);

$misc->printTreeXML($constraints, $attrs);
$misc->printTree($constraints, $attrs, 'constraints');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion conversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function doTree() {
'toolTip'=> field('concomment')
);

$misc->printTreeXML($conversions, $attrs);
$misc->printTree($conversions, $attrs, 'conversions');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion database.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function doTree() {
),
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, 'database');

exit;
}
Expand Down
2 changes: 1 addition & 1 deletion domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function doTree() {
)
);

$misc->printTreeXML($domains, $attrs);
$misc->printTree($domains, $attrs, 'domains');
exit;
}

Expand Down
4 changes: 2 additions & 2 deletions fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ function doTree() {
),
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, 'fts');

exit;
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ function doSubTree($what) {
),
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, strtolower($what));
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ function doTree() {
)
);

$misc->printTreeXML($funcs, $attrs);
$misc->printTree($funcs, $attrs, 'functions');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ function getIcon($f) {
'icon' => callback('getIcon'),
);

$misc->printTreeXML($indexes, $attrs);
$misc->printTree($indexes, $attrs, 'indexes');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function doTree() {
'icon' => 'Language'
);

$misc->printTreeXML($languages, $attrs);
$misc->printTree($languages, $attrs, 'languages');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion opclasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function doTree() {
'toolTip'=> field('opccomment'),
);

$misc->printTreeXML($opclasses, $attrs);
$misc->printTree($opclasses, $attrs, 'opclasses');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function doTree() {
)
);

$misc->printTreeXML($operators, $attrs);
$misc->printTree($operators, $attrs, 'operators');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function doTree() {
'icon' => 'Rule',
);

$misc->printTreeXML($rules, $attrs);
$misc->printTree($rules, $attrs, 'rules');
exit;
}

Expand Down
4 changes: 2 additions & 2 deletions schemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function doTree() {
),
);

$misc->printTreeXML($schemas, $attrs);
$misc->printTree($schemas, $attrs, 'schemas');

exit;
}
Expand Down Expand Up @@ -442,7 +442,7 @@ function doSubTree() {
)
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, 'schema');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion sequences.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function doTree() {
)
);

$misc->printTreeXML($sequences, $attrs);
$misc->printTree($sequences, $attrs, 'sequences');
exit;
}

Expand Down
8 changes: 6 additions & 2 deletions servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ function doTree() {
'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();
Expand Down
4 changes: 2 additions & 2 deletions tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ function doTree() {
)
);

$misc->printTreeXML($tables, $attrs);
$misc->printTree($tables, $attrs, 'tables');
exit;
}

Expand Down Expand Up @@ -992,7 +992,7 @@ function doSubTree() {
),
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, 'table');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion tblproperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function doTree() {
'toolTip'=> field('comment')
);

$misc->printTreeXML($columns, $attrs);
$misc->printTree($columns, $attrs, 'tblcolumns');

exit;
}
Expand Down
2 changes: 1 addition & 1 deletion triggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function doTree() {
'icon' => 'Trigger',
);

$misc->printTreeXML($triggers, $attrs);
$misc->printTree($triggers, $attrs, 'triggers');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion types.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ function doTree() {
)
);

$misc->printTreeXML($types, $attrs);
$misc->printTree($types, $attrs, 'types');
exit;
}

Expand Down
2 changes: 1 addition & 1 deletion viewproperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function doTree () {
'toolTip'=> field('comment')
);

$misc->printTreeXML($columns, $attrs);
$misc->printTree($columns, $attrs, 'viewcolumns');

exit;
}
Expand Down
4 changes: 2 additions & 2 deletions views.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function doTree() {
)
);

$misc->printTreeXML($views, $attrs);
$misc->printTree($views, $attrs, 'views');
exit;
}

Expand All @@ -730,7 +730,7 @@ function doSubTree() {
),
);

$misc->printTreeXML($items, $attrs);
$misc->printTree($items, $attrs, 'view');
exit;
}

Expand Down

0 comments on commit 2820a98

Please sign in to comment.