Skip to content

Commit

Permalink
Add support for 'actionbuttons' hooks in the plugin architecture.
Browse files Browse the repository at this point in the history
By Leonardo Sapiras during the GSoC 2011. Reviewed, massively patched,
fixed, integrated and commited by ioguix
  • Loading branch information
leonardosapiras authored and ioguix committed Aug 22, 2012
1 parent f5892dd commit 4f77054
Show file tree
Hide file tree
Showing 35 changed files with 1,059 additions and 399 deletions.
36 changes: 24 additions & 12 deletions admin.php
Expand Up @@ -628,23 +628,35 @@ function enlight($f, $p) {


$actions = array( $actions = array(
'edit' => array( 'edit' => array(
'title' => $lang['stredit'], 'content' => $lang['stredit'],
'url' => "{$script}?action=confeditautovac&{$misc->href}&subject={$type}&", 'attr'=> array (
'vars' => array( 'href' => array (
'schema' => 'nspname', 'url' => $script,
'table' => 'relname' 'urlvars' => array (
'subject' => $type,
'action' => 'confeditautovac',
'schema' => field('nspname'),
'table' => field('relname')
)
)
) )
), ),
'delete' => array( 'delete' => array(
'title' => $lang['strdelete'], 'content' => $lang['strdelete'],
'url' => "{$script}?action=confdelautovac&{$misc->href}&subject={$type}&", 'attr'=> array (
'vars' => array( 'href' => array (
'schema' => 'nspname', 'url' => $script,
'table' => 'relname' 'urlvars' => array (
'subject' => $type,
'action' => 'confdelautovac',
'schema' => field('nspname'),
'table' => field('relname')
)
)
) )
) )
); );

if ($type == 'table') { if ($type == 'table') {
unset($actions['edit']['vars']['schema'], unset($actions['edit']['vars']['schema'],
$actions['delete']['vars']['schema'], $actions['delete']['vars']['schema'],
Expand All @@ -653,7 +665,7 @@ function enlight($f, $p) {
); );
} }


$misc->printTable($autovac, $columns, $actions, $lang['strnovacuumconf']); $misc->printTable($autovac, $columns, $actions, 'admin-admin', $lang['strnovacuumconf']);


if (($type == 'table') and ($autovac->recordCount() == 0)) { if (($type == 'table') and ($autovac->recordCount() == 0)) {
echo "<br />"; echo "<br />";
Expand Down
30 changes: 23 additions & 7 deletions aggregates.php
Expand Up @@ -344,19 +344,35 @@ function doDefault($msg = '') {


$actions = array( $actions = array(
'alter' => array( 'alter' => array(
'title' => $lang['stralter'], 'content' => $lang['stralter'],
'url' => "aggregates.php?action=alter&amp;{$misc->href}&amp;", 'attr'=> array (
'vars' => array('aggrname' => 'proname', 'aggrtype' => 'proargtypes'), 'href' => array (
'url' => 'aggregates.php',
'urlvars' => array (
'action' => 'alter',
'aggrname' => field('proname'),
'aggrtype' => field('proargtypes')
)
)
)
), ),
'drop' => array( 'drop' => array(
'title' => $lang['strdrop'], 'content' => $lang['strdrop'],
'url' => "aggregates.php?action=confirm_drop&amp;{$misc->href}&amp;", 'attr'=> array (
'vars' => array('aggrname' => 'proname', 'aggrtype' => 'proargtypes'), 'href' => array (
'url' => 'aggregates.php',
'urlvars' => array (
'action' => 'confirm_drop',
'aggrname' => field('proname'),
'aggrtype' => field('proargtypes')
)
)
)
) )
); );


if (!$data->hasAlterAggregate()) unset($actions['alter']); if (!$data->hasAlterAggregate()) unset($actions['alter']);
$misc->printTable($aggregates, $columns, $actions, $lang['strnoaggregates']); $misc->printTable($aggregates, $columns, $actions, 'aggregates-aggregates', $lang['strnoaggregates']);


$navlinks = array ( $navlinks = array (
array ( array (
Expand Down
55 changes: 39 additions & 16 deletions all_db.php
Expand Up @@ -393,36 +393,59 @@ function doDefault($msg = '') {


$actions = array( $actions = array(
'multiactions' => array( 'multiactions' => array(
'keycols' => array('database' => 'datname'), 'keycols' => array('database' => 'datname'),
'url' => 'all_db.php', 'url' => 'all_db.php',
'default' => null, 'default' => null,
), ),
'drop' => array( 'drop' => array(
'title' => $lang['strdrop'], 'content' => $lang['strdrop'],
'url' => "all_db.php?action=confirm_drop&amp;subject=database&amp;{$misc->href}&amp;", 'attr'=> array (
'vars' => array('dropdatabase' => 'datname'), 'href' => array (
'multiaction' => 'confirm_drop', 'url' => 'all_db.php',
'urlvars' => array (
'subject' => 'database',
'action' => 'confirm_drop',
'dropdatabase' => field('datname')
)
)
),
'multiaction' => 'confirm_drop',
), ),
'privileges' => array( 'privileges' => array(
'title' => $lang['strprivileges'], 'content' => $lang['strprivileges'],
'url' => "privileges.php?subject=database&amp;{$misc->href}&amp;", 'attr'=> array (
'vars' => array('database' => 'datname'), 'href' => array (
'url' => 'privileges.php',
'urlvars' => array (
'subject' => 'database',
'database' => field('datname')
)
)
)
) )
); );
if ($data->hasAlterDatabase() ) { if ($data->hasAlterDatabase() ) {
$actions['alter'] = array( $actions['alter'] = array(
'title' => $lang['stralter'], 'content' => $lang['stralter'],
'url' => "all_db.php?action=confirm_alter&amp;subject=database&amp;{$misc->href}&amp;", 'attr'=> array (
'vars' => array('alterdatabase' => 'datname') 'href' => array (
); 'url' => 'all_db.php',
'urlvars' => array (
'subject' => 'database',
'action' => 'confirm_alter',
'alterdatabase' => field('datname')
)
)
)
);
} }


if (!$data->hasTablespaces()) unset($columns['tablespace']); if (!$data->hasTablespaces()) unset($columns['tablespace']);
if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']); if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']);
if (!$data->hasDatabaseCollation()) unset($columns['lc_collate'], $columns['lc_ctype']); if (!$data->hasDatabaseCollation()) unset($columns['lc_collate'], $columns['lc_ctype']);
if (!isset($data->privlist['database'])) unset($actions['privileges']); if (!isset($data->privlist['database'])) unset($actions['privileges']);


$misc->printTable($databases, $columns, $actions, $lang['strnodatabases']); $misc->printTable($databases, $columns, $actions, 'all_db-databases', $lang['strnodatabases']);


$navlinks = array ( $navlinks = array (
array ( array (
Expand Down
2 changes: 1 addition & 1 deletion casts.php
Expand Up @@ -62,7 +62,7 @@ function renderCastContext($val) {


$actions = array(); $actions = array();


$misc->printTable($casts, $columns, $actions, $lang['strnocasts']); $misc->printTable($casts, $columns, $actions, 'casts-casts', $lang['strnocasts']);
} }


/** /**
Expand Down
84 changes: 52 additions & 32 deletions classes/Misc.php
Expand Up @@ -594,35 +594,46 @@ function printReload($database) {
} }


/** /**
* Display a list of links * Display a link
* @param $links An associative array of links to print * @param $link An associative array of link parameters to print
* links = array( * link = array(
* 'attr' => array( // list of A tag attribute * 'attr' => array( // list of A tag attribute
* 'attrname' => attribute value * 'attrname' => attribute value
* ... * ...
* ), * ),
* 'content' => The link text * 'content' => The link text
* 'fields' => the data from which content and attr's values are obtained * 'fields' => (optionnal) the data from which content and attr's values are obtained
* ); * );
* the special attribute 'href' might be a string or an array. If href is an array it * the special attribute 'href' might be a string or an array. If href is an array it
* will be generated by getActionUrl. See getActionUrl comment for array format. * will be generated by getActionUrl. See getActionUrl comment for array format.
*/
function printLink($link) {
$tag = "<a ";
foreach ($link['attr'] as $attr => $value) {
if ($attr == 'href' and is_array($value)) {
$tag.= 'href="'. htmlentities($this->getActionUrl($value, $link['fields'])).'" ';
}
else {
$tag.= htmlentities($attr).'="'. value($value, $link['fields'], 'html') .'" ';
}
}
$tag.= ">". value($link['content'], $link['fields'], 'html') ."</a>\n";
echo $tag;
}

/**
* Display a list of links
* @param $links An associative array of links to print. See printLink function for
* the links array format.
* @param $class An optional class or list of classes seprated by a space * @param $class An optional class or list of classes seprated by a space
* WARNING: This field is NOT escaped! No user should be able to inject something here, use with care. * WARNING: This field is NOT escaped! No user should be able to inject something here, use with care.
*/ */
function printLinksList($links, $class='') { function printLinksList($links, $class='') {
echo "<ul class=\"{$class}\">\n"; echo "<ul class=\"{$class}\">\n";
foreach ($links as $link) { foreach ($links as $link) {
$tag = "\t<li><a "; echo "\t<li>";
foreach ($link['attr'] as $attr => $value) { $this->printLink($link);
if ($attr == 'href' and is_array($value)) { echo "</li>\n";
$tag.= 'href="'. htmlentities($this->getActionUrl($value, $link['fields'])).'" ';
}
else {
$tag.= htmlentities($attr).'="'. value($value, $link['fields'], 'html') .'" ';
}
}
$tag.= ">". value($link['content'], $link['fields'], 'html') ."</a></li>\n";
echo $tag;
} }
echo "</ul>\n"; echo "</ul>\n";
} }
Expand Down Expand Up @@ -1723,15 +1734,18 @@ function getActionUrl(&$action, &$fields) {
$urlvars = array(); $urlvars = array();
} }


if (isset($urlvars['subject'])) { /* set server, database and schema parameter if not presents */
if (isset($urlvars['subject']))
$subject = value($urlvars['subject'], $fields); $subject = value($urlvars['subject'], $fields);
if (isset($_REQUEST['server']) && $subject != 'root') { else
$urlvars['server'] = $_REQUEST['server']; $subject = '';
if (isset($_REQUEST['database']) && $subject != 'server') {
$urlvars['database'] = $_REQUEST['database']; if (isset($_REQUEST['server']) and !isset($urlvars['server']) and $subject != 'root') {
if (isset($_REQUEST['schema']) && $subject != 'database') { $urlvars['server'] = $_REQUEST['server'];
$urlvars['schema'] = $_REQUEST['schema']; if (isset($_REQUEST['database']) and !isset($urlvars['database']) and $subject != 'server') {
} $urlvars['database'] = $_REQUEST['database'];
if (isset($_REQUEST['schema']) and !isset($urlvars['schema']) and $subject != 'database') {
$urlvars['schema'] = $_REQUEST['schema'];
} }
} }
} }
Expand Down Expand Up @@ -1798,6 +1812,8 @@ function printUrlVars(&$vars, &$fields) {
* Add this action to the multi action form * Add this action to the multi action form
* ), ... * ), ...
* ); * );
* @param $place Place where the $actions are displayed. Like 'display-browse', where 'display' is the file (display.php)
* and 'browse' is the place inside that code (doBrowse).
* @param $nodata (optional) Message to display if data set is empty. * @param $nodata (optional) Message to display if data set is empty.
* @param $pre_fn (optional) Name of a function to call for each row, * @param $pre_fn (optional) Name of a function to call for each row,
* it will be passed two params: $rowdata and $actions, * it will be passed two params: $rowdata and $actions,
Expand All @@ -1808,8 +1824,15 @@ function printUrlVars(&$vars, &$fields) {
* The function must not must not store urls because * The function must not must not store urls because
* they are relative and won't work out of context. * they are relative and won't work out of context.
*/ */
function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) { function printTable(&$tabledata, &$columns, &$actions, $place, $nodata = null, $pre_fn = null) {
global $data, $conf, $misc, $lang; global $data, $conf, $misc, $lang, $plugin_manager;

// Action buttons hook's place
$plugin_functions_parameters = array(
'actionbuttons' => &$actions,
'place' => $place
);
$plugin_manager->do_hook('actionbuttons', $plugin_functions_parameters);


if ($has_ma = isset($actions['multiactions'])) if ($has_ma = isset($actions['multiactions']))
$ma = $actions['multiactions']; $ma = $actions['multiactions'];
Expand Down Expand Up @@ -1887,12 +1910,9 @@ function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn =
echo "<td></td>\n"; echo "<td></td>\n";
} else { } else {
echo "<td class=\"opbutton{$id}\">"; echo "<td class=\"opbutton{$id}\">";
echo "<a href=\"{$action['url']}"; $action['fields'] = $tabledata->fields;
if ($action['url'] === '') echo '?'; $this->printLink($action);
$misc->printUrlVars($action['vars'], $tabledata->fields); echo "</td>\n";
if (isset($action['target']))
echo "\" target=\"{$action['target']}";
echo "\">{$action['title']}</a></td>\n";
} }
} }
break; break;
Expand Down Expand Up @@ -1943,7 +1963,7 @@ function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn =
echo "\t\t<option value=\"\">--</option>\n"; echo "\t\t<option value=\"\">--</option>\n";
foreach($actions as $k => $a) foreach($actions as $k => $a)
if (isset($a['multiaction'])) if (isset($a['multiaction']))
echo "\t\t<option value=\"{$a['multiaction']}\"", ($ma['default'] == $k? ' selected="selected"': ''), ">{$a['title']}</option>\n"; echo "\t\t<option value=\"{$a['multiaction']}\"", ($ma['default'] == $k? ' selected="selected"': ''), ">{$a['content']}</option>\n";
echo "\t</select>\n"; echo "\t</select>\n";
echo "<input type=\"submit\" value=\"{$lang['strexecute']}\" />\n"; echo "<input type=\"submit\" value=\"{$lang['strexecute']}\" />\n";
echo $misc->form; echo $misc->form;
Expand Down
2 changes: 1 addition & 1 deletion classes/PluginManager.php
Expand Up @@ -10,7 +10,7 @@ class PluginManager {
* Attributes * Attributes
*/ */
private $plugins_list = array(); private $plugins_list = array();
private $available_hooks = array('toplinks', 'tabs', 'trail', 'navlinks' /* wip, more hooks to come in next commits */); private $available_hooks = array('toplinks', 'tabs', 'trail', 'navlinks', 'actionbuttons' /* wip, more hooks to come in next commits */);
private $actions = array(); private $actions = array();
private $hooks = array(); private $hooks = array();


Expand Down
2 changes: 1 addition & 1 deletion colproperties.php
Expand Up @@ -226,7 +226,7 @@ function attPre(&$rowdata) {
} }


$actions=array(); $actions=array();
$misc->printTable($attrs, $column, $actions, null, 'attPre'); $misc->printTable($attrs, $column, $actions, 'colproperties-colproperties', null, 'attPre');


echo "<br />\n"; echo "<br />\n";


Expand Down
19 changes: 14 additions & 5 deletions constraints.php
Expand Up @@ -464,13 +464,22 @@ function cnPre(&$rowdata) {


$actions = array( $actions = array(
'drop' => array( 'drop' => array(
'title' => $lang['strdrop'], 'content' => $lang['strdrop'],
'url' => "constraints.php?action=confirm_drop&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;", 'attr'=> array (
'vars' => array('constraint' => 'conname', 'type' => 'contype'), 'href' => array (
), 'url' => 'constraints.php',
'urlvars' => array (
'action' => 'confirm_drop',
'table' => $_REQUEST['table'],
'constraint' => field('conname'),
'type' => field('contype')
)
)
)
)
); );


$misc->printTable($constraints, $columns, $actions, $lang['strnoconstraints'], 'cnPre'); $misc->printTable($constraints, $columns, $actions, 'constraints-constraints', $lang['strnoconstraints'], 'cnPre');


$navlinks = array ( $navlinks = array (
array ( array (
Expand Down
2 changes: 1 addition & 1 deletion conversions.php
Expand Up @@ -51,7 +51,7 @@ function doDefault($msg = '') {


$actions = array(); $actions = array();


$misc->printTable($conversions, $columns, $actions, $lang['strnoconversions']); $misc->printTable($conversions, $columns, $actions, 'conversions-conversions', $lang['strnoconversions']);
} }


/** /**
Expand Down

0 comments on commit 4f77054

Please sign in to comment.