update adminer and adapt plugins to new version

This commit is contained in:
Pau Capó 2025-04-06 20:00:30 +02:00
parent 5659ab8524
commit f66a311358
15 changed files with 1411 additions and 1975 deletions

View file

@ -0,0 +1,43 @@
<?php
/** Select foreign key in edit form
* @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 AdminerEditForeign {
var $_limit;
function __construct() {
$this->_limit = 1000;
}
function editInput($table, $field, $attrs, $value) {
static $foreignTables = array();
static $values = array();
$foreignKeys = &$foreignTables[$table];
if ($foreignKeys === null) {
$foreignKeys = Adminer\column_foreign_keys($table);
}
foreach ((array) $foreignKeys[$field["field"]] as $foreignKey) {
if (count($foreignKey["source"]) == 1) {
$target = $foreignKey["table"];
$id = $foreignKey["target"][0];
$options = &$values[$target][$id];
if (!$options) {
$column = Adminer\idf_escape($id);
if (preg_match('~binary~', $field["type"])) {
$column = "HEX($column)";
}
$options = array("" => "") + Adminer\get_vals("SELECT $column FROM " . Adminer\table($target) . " ORDER BY 1" . ($this->_limit ? " LIMIT " . ($this->_limit + 1) : ""));
if ($this->_limit && count($options) - 1 > $this->_limit) {
return;
}
}
return "<select$attrs>" . Adminer\optionlist($options, $value) . "</select>";
}
}
}
}

View file

@ -0,0 +1,40 @@
<?php
/** Use <select><option> for enum edit instead of <input type="radio">
* @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 AdminerEnumOption {
function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") {
$options = array();
$selected = $value;
if (isset($_GET["select"])) {
$options[-1] = Adminer\lang('original');
if ($selected === null) {
$selected = -1;
}
}
if ($field["null"]) {
$options[""] = "NULL";
if ($value === null && !isset($_GET["select"])) {
$selected = "";
}
}
$options[0] = Adminer\lang('empty');
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) {
$val = stripcslashes(str_replace("''", "'", $val));
$options[$i + 1] = $val;
if ($value === $val) {
$selected = $i + 1;
}
}
return "<select$attrs>" . Adminer\optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
}
}
}

View file

@ -0,0 +1,87 @@
<?php
/**
* Faster tables filter plugin
* ===========================
* Useful when there's way too many tables than it shoud be and Adminer Tables Filter is slow
*
* @author Martin Macko, https://github.com/linkedlist
* @license http://http://opensource.org/licenses/MIT, The MIT License (MIT)
*
* Modified 201802 - updated for Adminer 4.6.0 compatibility
*/
class AdminerFasterTablesFilter {
function tablesPrint($tables) { ?>
<p class="jsonly"><input id="filter-field">
<style>
.select-text {
margin-right: 5px;
}
</style>
<p id='tables'></p>
<script<?php echo Adminer\nonce(); ?>>
function readCookie(name) {
name = name.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
var regex = new RegExp('(?:^|;)\\s?' + name + '=(.*?)(?:;|$)','i'),
match = document.cookie.match(regex);
return match && unescape(match[1]);
}
var filterf = function () {
var liProto = document.createElement('li');
var space = document.createTextNode('\u00A0')
var aProto = document.createElement('a');
var tableList = document.getElementById("tables");
function appendTables() {
var fragment = document.createDocumentFragment();
var item;
for (var i = 0, len = tempTables.length; i < len; i++) {
item = tempTables[i];
var li = liProto.cloneNode();
var aSelect = aProto.cloneNode();
aSelect.href = hMe+"select="+item;
aSelect.text = langSelect;
aSelect.className = "select";
var aName = aProto.cloneNode();
aName.href = hMe+"table="+item;
aName.text = item;
li.appendChild(aSelect);
li.appendChild(space.cloneNode());
li.appendChild(aName);
fragment.appendChild(li);
}
tableList.appendChild(fragment);
}
var tables = [<?php foreach($tables as $table => $type) { echo "'".urlencode($table) ."'". ",";}?>];
var tempTables = tables;
var hMe = "<?php echo Adminer\h(Adminer\ME) ?>";
hMe = hMe.replace(/&amp;/g, '&');
var langSelect = "<?php echo Adminer\lang('select');?>";
var filterCookie = readCookie('tableFilter');
var filter = document.getElementById("filter-field");
if(filterCookie!='') {
filter.value=filterCookie;
}
function filterTableList() {
document.cookie = "tableFilter="+filter.value
while(tableList.firstChild) {
tableList.removeChild(tableList.firstChild);
}
tempTables = [];
var value = filter.value.toLowerCase();
var item;
for (var i = 0, len = tables.length; i < len; i++) {
item = tables[i];
if(item.toLowerCase().indexOf(value) > -1) {
tempTables.push(item);
}
}
appendTables();
};
filter.onkeyup = function(event) {
filterTableList();
}
filterTableList();
}
window.onload=filterf;
</script>
<?php return true;}} ?>

View file

@ -0,0 +1,28 @@
<?php
/** Allow using Adminer inside a frame (disables ClickJacking protection)
* @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 AdminerFrames {
/** @access protected */
var $sameOrigin;
/**
* @param bool allow running from the same origin only
*/
function __construct($sameOrigin = false) {
$this->sameOrigin = $sameOrigin;
}
function headers() {
if ($this->sameOrigin) {
header("X-Frame-Options: SameOrigin");
} elseif (function_exists('header_remove')) {
header_remove("X-Frame-Options");
}
}
}

View file

@ -0,0 +1,59 @@
<?php
/** Display JSON values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @author Martin Zeman (Zemistr), http://www.zemistr.eu/
* @author Pau Capó, https://www.paucapo.com/
* @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 AdminerJsonColumn
{
private function _testJson($value)
{
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true)))
{
return htmlentities(json_encode($json, JSON_PRETTY_PRINT));
}
return false;
}
function editInput($table, $field, $attrs, $value)
{
$json = $this->_testJson($value);
if (!$json)
{
return;
}
$name = $field['field'];
?>
<a href="#" id="toggle_json_<?= $name ?>">show as table</a><br>
<pre id="show_json_<?= $name ?>" style="display: none;max-height:600px;overflow:auto;" contenteditable><code class="language-json"><?= $json; ?></code></pre>
<script <?= Adminer\nonce() ?>>
document.getElementById('toggle_json_<?= $name ?>').addEventListener('click', function (e) {
e.preventDefault();
var show = document.getElementById('show_json_<?= $name ?>');
if (show.style.display === 'none') {
show.style.display = '';
} else {
show.style.display = 'none';
}
});
document.getElementById('show_json_<?= $name ?>').addEventListener('input', function (e) {
let content = document.getElementById('show_json_<?= $name ?>').innerText;
let json = false;
try {
json = JSON.parse(content);
} catch (e) {
document.getElementById('show_json_<?= $name ?>').style.border = '5px solid red';
return;
}
document.getElementById('show_json_<?= $name ?>').style.border = '';
document.querySelector('[name="fields[<?= $name ?>]"]').value = JSON.stringify(json);
});
</script>
<?php
}
}

View file

@ -0,0 +1,36 @@
<?php
/** Enable auto-login for SQLite
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://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 AdminerLoginSqlite {
function login($login, $password) {
return true;
}
function loginForm() {
?>
<script type="text/javascript" <?= Adminer\nonce() ?>>
addEventListener('load', function () {
var driver = document.getElementsByName('auth[driver]')[0];
if (isTag(driver, 'select')) {
driver.onchange = function () {
var trs = parentTag(driver, 'table').rows;
for (var i=1; i < trs.length - 1; i++) {
var disabled = /sqlite/.test(driver.value);
alterClass(trs[i], 'hidden', disabled);
trs[i].getElementsByTagName('input')[0].disabled = disabled;
}
};
}
driver.onchange();
});
</script>
<?php
}
}

View file

@ -0,0 +1,43 @@
<?php
/** Display XML values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Pau Capó, https://www.paucapo.com/
* @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 AdminerPrism
{
function head()
{
?>
<script<?= Adminer\nonce() ?>>
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[class^=jush-]').forEach(function ($item) {
const current_class = $item.getAttribute('class').trim();
const language_class = current_class.replace('jush-', 'language-');
$item.setAttribute('class', language_class);
});
document.querySelectorAll('code').forEach(function ($item) {
const current_class = ($item.getAttribute('class') || '').trim();
if (current_class === '') {
$item.setAttribute('class', 'language-plain');
}
})
});
</script>
<link rel="stylesheet" type="text/css" href="assets/prism.css?<?= filemtime(__DIR__ . '/../assets/prism.js') ?>"/>
<script <?= Adminer\nonce() ?> src="assets/prism.js?<?= filemtime(__DIR__ . '/../assets/prism.js') ?>"></script>
<script<?= Adminer\nonce() ?>>
// Prism.hooks.add('before-highlight', function (env) {
// env.code = env.element.innerText;
// });
Prism.hooks.add('before-sanity-check', function (env) {
env.element.innerHTML = env.element.innerHTML.replace(/<br>/g, '\n');
env.code = env.element.textContent;
});
</script>
<?php
}
}

View file

@ -0,0 +1,37 @@
<?php
/** This plugin replaces UNIX timestamps with human-readable dates in your local format.
* Mouse click on the date field reveals timestamp back.
*
* @link https://www.adminer.org/plugins/#use
* @author Anonymous
* @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 AdminerReadableDates
{
/** @access protected */
var $prepend;
function __construct()
{
$this->prepend = <<<EOT
document.addEventListener('DOMContentLoaded', function(event) {
var date = new Date();
var tds = document.querySelectorAll('td[id^="val"]');
for (var i = 0; i < tds.length; i++) {
var text = tds[i].innerHTML.trim();
if (text.match(/^\d{10}$/)) {
date.setTime(parseInt(text) * 1000);
tds[i].title = date.toLocaleString();
}
}
});
EOT;
}
function head()
{
echo Adminer\script($this->prepend);
}
}

View file

@ -0,0 +1,50 @@
<?php
/** This plugin replaces bytes sizes in tables list with human-readable sizes.
* Original sizes are set to the title=""
*
* @link https://www.adminer.org/plugins/#use
* @author Anonymous
* @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 AdminerReadableTableSize
{
/** @access protected */
var $prepend;
function __construct()
{
$this->prepend = <<<EOT
function AdminerReadableTableSizeConvert(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}
function AdminerReadableTableSize(field) {
var rows = document.querySelectorAll('[id*="'+field+'"]');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var bytes = row.innerText.replace(/,/g, '');
var sized = '-';
if (bytes > 16384) {
sized = AdminerReadableTableSizeConvert(bytes, 2);
}
row.title = row.title+' [' + row.innerText + ' Bytes]';
row.innerText = sized;
}
}
document.addEventListener('DOMContentLoaded', function(event) {
setTimeout(function() {
AdminerReadableTableSize('Data_length');
AdminerReadableTableSize('Index_length');
AdminerReadableTableSize('Data_free');
}, 500);
});
EOT;
}
function head()
{
echo Adminer\script($this->prepend);
}
}

View file

@ -0,0 +1,24 @@
<?php
/** Display serialize() values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Pau Capó, https://www.paucapo.com/
* @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 AdminerSerializedColumn {
function serialized_value($data) {
echo '<pre disabled style="max-height:300px;overflow:auto;">';
var_export($data);
echo '</pre>';
}
function editInput($table, $field, $attrs, $value) {
$unserialized = @unserialize($value);
if ($unserialized && $unserialized !== $value) {
$this->serialized_value($unserialized);
}
}
}

View file

@ -0,0 +1,53 @@
<?php
/** Display XML values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Pau Capó, https://www.paucapo.com/
* @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 AdminerXMLColumn
{
function _testXML($value)
{
$xml = @simplexml_load_string($value);
if (is_null($xml) || $xml === false)
{
return false;
}
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
return htmlentities($dom->saveXML());
}
function editInput($table, $field, $attrs, $value)
{
$xml = $this->_testXML($value);
if (!$xml)
{
return;
}
$name = $field['field'];
?>
<a href="#" id="toggle_xml_<?= $name ?>">show as table</a><br>
<pre id="show_xml_<?= $name ?>" style="display: none"><code class="language-xml"><?= $xml ?></code></pre>
<script <?= Adminer\nonce() ?>>
document.getElementById('toggle_xml_<?= $name ?>').addEventListener('click', function (e) {
e.preventDefault();
var show = document.getElementById('show_xml_<?= $name ?>');
if (show.style.display === 'none') {
show.style.display = '';
} else {
show.style.display = 'none';
}
});
</script>
<?php
}
}