init
This commit is contained in:
345
nv/html/adminer/plugins/plugin.php
Normal file
345
nv/html/adminer/plugins/plugin.php
Normal file
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
/** Adminer customization allowing usage of plugins
|
||||
* @link http://www.adminer.org/plugins/#use
|
||||
* @author Jakub Vrana, http://www.vrana.cz/
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||
*/
|
||||
class AdminerPlugin extends Adminer {
|
||||
/** @access protected */
|
||||
var $plugins;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/** Register plugins
|
||||
* @param array object instances or null to register all classes starting by 'Adminer'
|
||||
*/
|
||||
function AdminerPlugin($plugins) {
|
||||
if ($plugins === null) {
|
||||
$plugins = array();
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface
|
||||
$plugins[$class] = new $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->plugins = $plugins;
|
||||
//! it is possible to use ReflectionObject to find out which plugins defines which methods at once
|
||||
}
|
||||
|
||||
function _callParent($function, $args) {
|
||||
return call_user_func_array(array('parent', $function), $args);
|
||||
}
|
||||
|
||||
function _applyPlugin($function, $args) {
|
||||
foreach ($this->plugins as $plugin) {
|
||||
if (method_exists($plugin, $function)) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
if ($return !== null) {
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_callParent($function, $args);
|
||||
}
|
||||
|
||||
function _appendPlugin($function, $args) {
|
||||
$return = $this->_callParent($function, $args);
|
||||
foreach ($this->plugins as $plugin) {
|
||||
if (method_exists($plugin, $function)) {
|
||||
$return += call_user_func_array(array($plugin, $function), $args);
|
||||
}
|
||||
}
|
||||
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 editFunctions() {
|
||||
$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);
|
||||
}
|
||||
|
||||
function permanentLogin() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function database() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function schemas() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function databases() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function queryTimeout() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function headers() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function head() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function loginForm() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function login() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function tableName() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function fieldName() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectLinks() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function foreignKeys() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function backwardKeys() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function backwardKeysPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectQuery() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function rowDescription() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function rowDescriptions() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectLink() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectVal() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function editVal() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectColumnsPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectSearchPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectOrderPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectLimitPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectLengthPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectActionPrint() {
|
||||
$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);
|
||||
}
|
||||
|
||||
function selectEmailPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectColumnsProcess() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectSearchProcess() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectOrderProcess() {
|
||||
$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);
|
||||
}
|
||||
|
||||
function selectEmailProcess() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function selectQueryBuild() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function messageQuery() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function editInput() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function processInput() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function dumpDatabase() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function dumpTable() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function dumpData() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function dumpFilename() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function dumpHeaders() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function homepage() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function navigation() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function databasesPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
function tablesPrint() {
|
||||
$args = func_get_args();
|
||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||
}
|
||||
|
||||
}
|
||||
40
nv/html/adminer/plugins/pretty-json-column.php
Normal file
40
nv/html/adminer/plugins/pretty-json-column.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/** Pretty print JSON values in edit
|
||||
*/
|
||||
class AdminerPrettyJsonColumn {
|
||||
/** @var AdminerPlugin */
|
||||
protected $adminer;
|
||||
|
||||
public function __construct($adminer) {
|
||||
$this->adminer = $adminer;
|
||||
}
|
||||
|
||||
private function _testJson($value) {
|
||||
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) {
|
||||
return $json;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function editInput($table, $field, $attrs, $value) {
|
||||
$json = $this->_testJson($value);
|
||||
if ($json !== $value) {
|
||||
$jsonText = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
return <<<HTML
|
||||
<textarea $attrs cols="50" rows="20">$jsonText</textarea>
|
||||
HTML;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function processInput($field, $value, $function = '') {
|
||||
if ($function === '') {
|
||||
$json = $this->_testJson($value);
|
||||
if ($json !== $value) {
|
||||
$value = json_encode($json);
|
||||
}
|
||||
}
|
||||
return $this->adminer->_callParent('processInput', array($field, $value, $function));
|
||||
}
|
||||
}
|
||||
69
nv/html/adminer/plugins/tables-filter.php
Normal file
69
nv/html/adminer/plugins/tables-filter.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/** Use filter in tables list
|
||||
* @link https://www.adminer.org/plugins/#use
|
||||
* @author Jakub Vrana, https://www.vrana.cz/
|
||||
* @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)
|
||||
*/
|
||||
class AdminerTablesFilter {
|
||||
function tablesPrint($tables) { ?>
|
||||
<script<?php echo nonce(); ?>>
|
||||
var tablesFilterTimeout = null;
|
||||
var tablesFilterValue = '';
|
||||
|
||||
function tablesFilter(){
|
||||
var value = qs('#filter-field').value.toLowerCase();
|
||||
if (value == tablesFilterValue) {
|
||||
return;
|
||||
}
|
||||
tablesFilterValue = value;
|
||||
if (value != '') {
|
||||
var reg = (value + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
|
||||
reg = new RegExp('('+ reg + ')', 'gi');
|
||||
}
|
||||
if (sessionStorage) {
|
||||
sessionStorage.setItem('adminer_tables_filter', value);
|
||||
}
|
||||
var tables = qsa('li', qs('#tables'));
|
||||
for (var i = 0; i < tables.length; i++) {
|
||||
var a = null;
|
||||
var text = tables[i].getAttribute('data-table-name');
|
||||
if (text == null) {
|
||||
a = qsa('a', tables[i])[1];
|
||||
text = a.innerHTML.trim();
|
||||
|
||||
tables[i].setAttribute('data-table-name', text);
|
||||
a.setAttribute('data-link', 'main');
|
||||
} else {
|
||||
a = qs('a[data-link="main"]', tables[i]);
|
||||
}
|
||||
if (value == '') {
|
||||
tables[i].className = '';
|
||||
a.innerHTML = text;
|
||||
} else {
|
||||
tables[i].className = (text.toLowerCase().indexOf(value) == -1 ? 'hidden' : '');
|
||||
a.innerHTML = text.replace(reg, '<strong>$1</strong>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tablesFilterInput() {
|
||||
window.clearTimeout(tablesFilterTimeout);
|
||||
tablesFilterTimeout = window.setTimeout(tablesFilter, 200);
|
||||
}
|
||||
|
||||
sessionStorage && document.addEventListener('DOMContentLoaded', function () {
|
||||
var db = qs('#dbs').querySelector('select');
|
||||
db = db.options[db.selectedIndex].text;
|
||||
if (db == sessionStorage.getItem('adminer_tables_filter_db') && sessionStorage.getItem('adminer_tables_filter')){
|
||||
qs('#filter-field').value = sessionStorage.getItem('adminer_tables_filter');
|
||||
tablesFilter();
|
||||
}
|
||||
sessionStorage.setItem('adminer_tables_filter_db', db);
|
||||
});
|
||||
</script>
|
||||
<p class="jsonly"><input id="filter-field" autocomplete="off"><?php echo script("qs('#filter-field').oninput = tablesFilterInput;"); ?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user