adminerevo/plugins/plugin.php

409 lines
10 KiB
PHP
Raw Normal View History

2011-02-09 16:57:10 +00:00
<?php
/** Adminer customization allowing usage of plugins
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
2011-02-09 16:57:10 +00:00
*/
class AdminerPlugin extends Adminer {
2011-08-11 15:06:42 +00:00
/** @access protected */
2011-02-09 16:57:10 +00:00
var $plugins;
2011-04-03 15:17:33 +00:00
function _findRootClass($class) { // is_subclass_of(string, string) is available since PHP 5.0.3
do {
$return = $class;
} while ($class = get_parent_class($class));
return $return;
}
2011-03-27 07:20:07 +00:00
/** Register plugins
* @param array object instances or null to register all classes starting by 'Adminer'
2011-02-09 16:57:10 +00:00
*/
2015-08-15 15:04:21 +00:00
function __construct($plugins) {
2012-05-14 06:54:07 +00:00
if ($plugins === null) {
2011-03-27 07:20:07 +00:00
$plugins = array();
foreach (get_declared_classes() as $class) {
2013-08-09 00:16:04 +00:00
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface
2011-03-27 07:20:07 +00:00
$plugins[$class] = new $class;
}
}
}
2011-02-09 16:57:10 +00:00
$this->plugins = $plugins;
2013-08-09 00:16:04 +00:00
//! it is possible to use ReflectionObject to find out which plugins defines which methods at once
2011-02-09 16:57:10 +00:00
}
function _callParent($function, $args) {
2013-08-09 00:16:04 +00:00
return call_user_func_array(array('parent', $function), $args);
}
2011-02-09 16:57:10 +00:00
function _applyPlugin($function, $args) {
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
2011-02-14 11:08:36 +00:00
switch (count($args)) { // call_user_func_array() doesn't work well with references
case 0: $return = $plugin->$function(); break;
case 1: $return = $plugin->$function($args[0]); break;
case 2: $return = $plugin->$function($args[0], $args[1]); break;
case 3: $return = $plugin->$function($args[0], $args[1], $args[2]); break;
case 4: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3]); break;
2012-09-01 15:47:16 +00:00
case 5: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4]); break;
case 6: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break;
2011-02-14 11:08:36 +00:00
default: trigger_error('Too many parameters.', E_USER_WARNING);
2011-02-09 16:57:10 +00:00
}
2012-05-14 06:54:07 +00:00
if ($return !== null) {
2011-02-09 16:57:10 +00:00
return $return;
}
}
}
return $this->_callParent($function, $args);
2011-02-09 16:57:10 +00:00
}
function _appendPlugin($function, $args) {
$return = $this->_callParent($function, $args);
2011-02-09 16:57:10 +00:00
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
2018-02-09 12:48:50 +00:00
$value = call_user_func_array(array($plugin, $function), $args);
if ($value) {
$return += $value;
}
2011-02-09 16:57:10 +00:00
}
}
return $return;
}
// appendPlugin
function dumpFormat() {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
function dumpOutput() {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
function editRowPrint($table, $fields, $row, $update) {
2021-03-03 17:23:37 +00:00
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function editFunctions($field) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}
// applyPlugin
function name() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function credentials() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2018-02-07 11:13:58 +00:00
function connectSsl() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function permanentLogin($create = false) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function bruteForceKey() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function serverName($server) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2011-02-09 16:57:10 +00:00
function database() {
$args = func_get_args();
2013-10-25 05:16:24 +00:00
return $this->_applyPlugin(__FUNCTION__, $args);
}
function schemas() {
$args = func_get_args();
2011-02-09 16:57:10 +00:00
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function databases($flush = true) {
2012-02-24 06:54:48 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2012-09-01 15:47:16 +00:00
function queryTimeout() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2011-02-09 16:57:10 +00:00
function headers() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2018-01-09 17:53:17 +00:00
function csp() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function head() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2018-01-23 11:15:38 +00:00
function css() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2011-02-09 16:57:10 +00:00
function loginForm() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function loginFormField($name, $heading, $value) {
2018-02-22 10:36:11 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function login($login, $password) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function tableName($tableStatus) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function fieldName($field, $order = 0) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectLinks($tableStatus, $set = "") {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function foreignKeys($table) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function backwardKeys($table, $tableName) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function backwardKeysPrint($backwardKeys, $row) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectQuery($query, $start, $failed = false) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-03-11 16:52:11 +00:00
function sqlCommandQuery($query) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function rowDescription($table) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function rowDescriptions($rows, $foreignKeys) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectLink($val, $field) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectVal($val, $link, $field, $original) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function editVal($val, $field) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function tableStructurePrint($fields) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function tableIndexesPrint($indexes) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectColumnsPrint($select, $columns) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectSearchPrint($where, $columns, $indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectOrderPrint($order, $columns, $indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectLimitPrint($limit) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectLengthPrint($text_length) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectActionPrint($indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectCommandPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectImportPrint() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectEmailPrint($emailFields, $columns) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectColumnsProcess($columns, $indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectSearchProcess($fields, $indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectOrderProcess($fields, $indexes) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLimitProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function selectLengthProcess() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectEmailProcess($where, $foreignKeys) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function selectQueryBuild($select, $where, $group, $order, $limit, $page) {
2012-09-01 15:47:16 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function messageQuery($query, $time, $failed = false) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function editInput($table, $field, $attrs, $value) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function editHint($table, $field, $value) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function processInput($field, $value, $function = "") {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function dumpDatabase($db) {
2013-04-04 01:49:05 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function dumpTable($table, $style, $is_view = 0) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function dumpData($table, $style, $query) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function dumpFilename($identifier) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function dumpHeaders($identifier, $multi_table = false) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
function importServerPath() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2011-02-09 16:57:10 +00:00
function homepage() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function navigation($missing) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function databasesPrint($missing) {
2012-09-01 15:47:16 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
2015-08-15 15:16:15 +00:00
function tablesPrint($tables) {
2011-02-09 16:57:10 +00:00
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
}