Files
adminer/adminer/include/plugins.inc.php

442 lines
11 KiB
PHP
Raw Normal View History

2011-02-09 17:57:10 +01:00
<?php
namespace Adminer;
2011-02-09 17:57:10 +01:00
class Plugins extends Adminer {
2025-03-18 22:18:17 +01:00
public $plugins; ///< @var protected(set)
2025-03-20 11:54:39 +01:00
public $error = ''; ///< @var protected(set)
2025-02-21 13:53:18 +01:00
2011-03-27 09:20:07 +02:00
/** Register plugins
* @param array object instances or null to autoload plugins from adminer-plugins/
2011-02-09 17:57:10 +01:00
*/
2015-08-15 17:04:21 +02:00
function __construct($plugins) {
if ($plugins === null) {
$plugins = array();
$basename = "adminer-plugins";
if (is_dir($basename)) {
foreach (glob("$basename/*.php") as $filename) {
$include = include_once "./$filename";
}
}
if (file_exists("$basename.php")) {
$include = include_once "./$basename.php"; // example: return array(new AdminerLoginOtp($secret))
2025-03-20 11:54:39 +01:00
if (is_array($include)) {
foreach ($include as $plugin) {
$plugins[get_class($plugin)] = $plugin;
}
} else {
$this->error .= lang('<b>%s</b> must return an array.', "$basename.php") . "<br>";
}
}
foreach (get_declared_classes() as $class) {
if (!$plugins[$class] && preg_match('~^Adminer\w~i', $class)) {
2025-03-20 11:54:39 +01:00
$reflection = new \ReflectionClass($class);
$constructor = $reflection->getConstructor();
if ($constructor && $constructor->getNumberOfRequiredParameters()) {
$this->error .= lang('Configure <b>%s</b> in <b>%s</b>.', $class, "$basename.php") . "<br>";
} else {
$plugins[$class] = new $class;
}
}
}
}
2011-02-09 17:57:10 +01:00
$this->plugins = $plugins;
}
2025-02-21 13:53:18 +01:00
2025-03-11 07:56:28 +01:00
private function callParent($function, $args) {
2013-08-08 17:16:04 -07:00
return call_user_func_array(array('parent', $function), $args);
}
2025-02-21 13:53:18 +01:00
2025-03-11 07:56:28 +01:00
private function applyPlugin($function, $args) {
2011-02-09 17:57:10 +01:00
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
2011-02-14 12:08:36 +01:00
switch (count($args)) { // call_user_func_array() doesn't work well with references
2025-03-05 09:14:49 +01:00
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;
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;
default:
trigger_error('Too many parameters.', E_USER_WARNING);
2011-02-09 17:57:10 +01:00
}
2012-05-13 23:54:07 -07:00
if ($return !== null) {
2011-02-09 17:57:10 +01:00
return $return;
}
}
}
2025-03-11 07:56:28 +01:00
return $this->callParent($function, $args);
2011-02-09 17:57:10 +01:00
}
2025-02-21 13:53:18 +01:00
2025-03-11 07:56:28 +01:00
private function appendPlugin($function, $args) {
$return = $this->callParent($function, $args);
2011-02-09 17:57:10 +01:00
foreach ($this->plugins as $plugin) {
if (method_exists($plugin, $function)) {
2018-02-09 13:48:50 +01:00
$value = call_user_func_array(array($plugin, $function), $args);
if ($value) {
$return += $value;
}
2011-02-09 17:57:10 +01:00
}
}
return $return;
}
2025-02-21 13:53:18 +01:00
2011-02-09 17:57:10 +01:00
// appendPlugin
2025-02-21 13:53:18 +01:00
2011-02-09 17:57:10 +01:00
function dumpFormat() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->appendPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2025-02-21 13:53:18 +01:00
2011-02-09 17:57:10 +01:00
function dumpOutput() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->appendPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function editRowPrint($table, $fields, $row, $update) {
2021-03-03 18:23:37 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->appendPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function editFunctions($field) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->appendPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
// applyPlugin
2025-02-21 13:53:18 +01:00
2011-02-09 17:57:10 +01:00
function name() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function credentials() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2018-02-07 12:13:58 +01:00
function connectSsl() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2018-02-07 12:13:58 +01:00
}
2015-08-15 17:16:15 +02:00
function permanentLogin($create = false) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function bruteForceKey() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
function serverName($server) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2011-02-09 17:57:10 +01:00
function database() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2013-10-24 22:16:24 -07:00
}
function schemas() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function databases($flush = true) {
2012-02-23 22:54:48 -08:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2012-02-23 22:54:48 -08:00
}
2012-09-01 08:47:16 -07:00
function queryTimeout() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2012-09-01 08:47:16 -07:00
}
2011-02-09 17:57:10 +01:00
function headers() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2018-01-09 18:53:17 +01:00
function csp() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2018-01-09 18:53:17 +01:00
}
function head($dark = null) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2018-01-23 12:15:38 +01:00
function css() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2018-01-23 12:15:38 +01:00
}
2011-02-09 17:57:10 +01:00
function loginForm() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function loginFormField($name, $heading, $value) {
2018-02-22 11:36:11 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2018-02-22 11:36:11 +01:00
}
2015-08-15 17:16:15 +02:00
function login($login, $password) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function tableName($tableStatus) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function fieldName($field, $order = 0) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectLinks($tableStatus, $set = "") {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function foreignKeys($table) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function backwardKeys($table, $tableName) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function backwardKeysPrint($backwardKeys, $row) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function selectQuery($query, $start, $failed = false) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-03-11 17:52:11 +01:00
function sqlCommandQuery($query) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2015-03-11 17:52:11 +01:00
}
2015-08-15 17:16:15 +02:00
function rowDescription($table) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function rowDescriptions($rows, $foreignKeys) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectLink($val, $field) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function selectVal($val, $link, $field, $original) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function editVal($val, $field) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function tableStructurePrint($fields, $tableStatus = null) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
function tableIndexesPrint($indexes) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function selectColumnsPrint($select, $columns) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectSearchPrint($where, $columns, $indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectOrderPrint($order, $columns, $indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectLimitPrint($limit) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectLengthPrint($text_length) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectActionPrint($indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function selectCommandPrint() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
function selectImportPrint() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function selectEmailPrint($emailFields, $columns) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectColumnsProcess($columns, $indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectSearchProcess($fields, $indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectOrderProcess($fields, $indexes) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function selectLimitProcess() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function selectLengthProcess() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectEmailProcess($where, $foreignKeys) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function selectQueryBuild($select, $where, $group, $order, $limit, $page) {
2012-09-01 08:47:16 -07:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2012-09-01 08:47:16 -07:00
}
function messageQuery($query, $time, $failed = false) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function editInput($table, $field, $attrs, $value) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function editHint($table, $field, $value) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function processInput($field, $value, $function = "") {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function dumpDatabase($db) {
2013-04-03 18:49:05 -07:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2013-04-03 18:49:05 -07:00
}
2015-08-15 17:16:15 +02:00
function dumpTable($table, $style, $is_view = 0) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function dumpData($table, $style, $query) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function dumpFilename($identifier) {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function dumpHeaders($identifier, $multi_table = false) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2025-03-11 08:59:38 +01:00
function dumpFooter() {
$args = func_get_args();
return $this->applyPlugin(__FUNCTION__, $args);
}
function importServerPath() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
}
2011-02-09 17:57:10 +01:00
function homepage() {
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
2015-08-15 17:16:15 +02:00
function navigation($missing) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
function syntaxHighlighting($tables) {
$args = func_get_args();
return $this->applyPlugin(__FUNCTION__, $args);
}
2015-08-15 17:16:15 +02:00
function databasesPrint($missing) {
2012-09-01 08:47:16 -07:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2012-09-01 08:47:16 -07:00
}
2015-08-15 17:16:15 +02:00
function tablesPrint($tables) {
2011-02-09 17:57:10 +01:00
$args = func_get_args();
2025-03-11 07:56:28 +01:00
return $this->applyPlugin(__FUNCTION__, $args);
2011-02-09 17:57:10 +01:00
}
}