add a few plugins
This commit is contained in:
parent
b3bc49e576
commit
f254601f6f
5 changed files with 156 additions and 20 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.idea
|
||||
|
|
@ -325,6 +325,7 @@ input[name=logout]:hover {
|
|||
|
||||
.logout {
|
||||
z-index:3;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.js .column {
|
||||
|
|
|
|||
|
|
@ -7,30 +7,44 @@
|
|||
* @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))) {
|
||||
class AdminerJsonColumn
|
||||
{
|
||||
private function _testJson($value)
|
||||
{
|
||||
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true)))
|
||||
{
|
||||
return $json;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function _buildTable($json) {
|
||||
echo '<table cellspacing="0" style="margin:2px">';
|
||||
foreach ($json as $key => $val) {
|
||||
private function _buildTable($json)
|
||||
{
|
||||
echo '<table cellspacing="0" style="margin:2px;">';
|
||||
foreach ($json as $key => $val)
|
||||
{
|
||||
echo '<tr>';
|
||||
echo '<th>' . h($key) . '</th>';
|
||||
echo '<td>';
|
||||
if (is_scalar($val) || $val === null) {
|
||||
if (is_bool($val)) {
|
||||
if (is_scalar($val) || $val === null)
|
||||
{
|
||||
if (is_bool($val))
|
||||
{
|
||||
$val = $val ? 'true' : 'false';
|
||||
} elseif ($val === null) {
|
||||
}
|
||||
elseif ($val === null)
|
||||
{
|
||||
$val = 'null';
|
||||
} elseif (!is_numeric($val)) {
|
||||
}
|
||||
elseif (!is_numeric($val))
|
||||
{
|
||||
$val = '"' . h(addcslashes($val, "\r\n\"")) . '"';
|
||||
}
|
||||
echo '<code class="jush-js">' . $val . '</code>';
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_buildTable($val);
|
||||
}
|
||||
echo '</td>';
|
||||
|
|
@ -39,10 +53,28 @@ class AdminerJsonColumn {
|
|||
echo '</table>';
|
||||
}
|
||||
|
||||
function editInput($table, $field, $attrs, $value) {
|
||||
function editInput($table, $field, $attrs, $value)
|
||||
{
|
||||
$json = $this->_testJson($value);
|
||||
if ($json !== $value) {
|
||||
$this->_buildTable($json);
|
||||
if ($json !== $value)
|
||||
{
|
||||
$name = $field['field'];
|
||||
?>
|
||||
<a href="#" id="toggle_json_<?= $name ?>">show as table</a><br>
|
||||
<pre id="show_json_<?= $name ?>" style="display: none"><?= json_encode($json, JSON_PRETTY_PRINT); ?></pre>
|
||||
<script <?= 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';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
52
plugins/AdminerReadableDates.php
Normal file
52
plugins/AdminerReadableDates.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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].oldDate = text;
|
||||
|
||||
// tds[i].newDate = date.toUTCString().substr(5); // UTC format
|
||||
tds[i].newDate = date.toLocaleString(); // Local format
|
||||
// tds[i].newDate = date.toLocaleFormat('%e %b %Y %H:%M:%S'); // Custom format - works in Firefox only
|
||||
|
||||
tds[i].newDate = '<span style="color: #009900">' + tds[i].newDate + '</span>';
|
||||
tds[i].innerHTML = tds[i].newDate;
|
||||
tds[i].dateIsNew = true;
|
||||
|
||||
tds[i].addEventListener('click', function(event) {
|
||||
this.innerHTML = (this.dateIsNew ? this.oldDate : this.newDate);
|
||||
this.dateIsNew = !this.dateIsNew;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
EOT;
|
||||
}
|
||||
|
||||
function head()
|
||||
{
|
||||
echo script($this->prepend);
|
||||
}
|
||||
}
|
||||
50
plugins/AdminerReadableTableSize.php
Normal file
50
plugins/AdminerReadableTableSize.php
Normal 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","KB","MB","GB","TB","PB","EB","ZB","YB"],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 > 0) {
|
||||
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 script($this->prepend);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue