Skip to content

Commit

Permalink
Update Adminer to use pematon fork because AdminerEvo is now dead.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbj committed Jan 24, 2025
1 parent 3e8fa20 commit a16f9c5
Show file tree
Hide file tree
Showing 13 changed files with 574 additions and 957 deletions.
1 change: 0 additions & 1 deletion ProcessTracyAdminerRenderer.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function adminer_object() {
$plugins = [
new AdminerFrames,
new AdminerProcessWireLogin(wire('config')->urls->admin, wire('config')->dbHost . $port, wire('config')->dbName, wire('config')->dbUser, wire('config')->dbPass, wire('config')->dbName),
new AdminerTablesFilter(),
new AdminerSimpleMenu(),
new AdminerCollations(),
new AdminerJsonPreview($data['adminerJsonMaxLevel'], $data['adminerJsonInTable'], $data['adminerJsonInEdit'], $data['adminerJsonMaxTextLength']),
Expand Down
6 changes: 3 additions & 3 deletions TracyDebugger.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getModuleInfo() {
'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/',
'version' => '4.26.59',
'version' => '4.26.60',
'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first
'singular' => true,
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
Expand Down Expand Up @@ -4114,7 +4114,7 @@ public function getModuleConfigInputfields(array $data) {
$f = $this->wire('modules')->get("InputfieldCheckbox");
$f->attr('name', 'adminerJsonInTable');
$f->label = __('JSON In Table', __FILE__);
$f->description = __('Whether apply JSON preview in selection table.', __FILE__);
$f->description = __('Whether to apply JSON preview in selection table.', __FILE__);
$f->notes = __('Default: true', __FILE__);
$f->columnWidth = 25;
$f->attr('checked', $this->data['adminerJsonInTable'] == '1' ? 'checked' : '');
Expand All @@ -4123,7 +4123,7 @@ public function getModuleConfigInputfields(array $data) {
$f = $this->wire('modules')->get("InputfieldCheckbox");
$f->attr('name', 'adminerJsonInEdit');
$f->label = __('JSON In Edit', __FILE__);
$f->description = __('Whether apply JSON preview in edit form.', __FILE__);
$f->description = __('Whether to apply JSON preview in edit form.', __FILE__);
$f->notes = __('Default: true', __FILE__);
$f->columnWidth = 25;
$f->attr('checked', $this->data['adminerJsonInEdit'] == '1' ? 'checked' : '');
Expand Down
1,314 changes: 492 additions & 822 deletions panels/Adminer/adminer-mysql.php

Large diffs are not rendered by default.

52 changes: 32 additions & 20 deletions panels/Adminer/plugins/AdminerJsonPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public function head()
document.addEventListener("DOMContentLoaded", init, false);

function init() {
var links = document.querySelectorAll('a.json-icon');
const links = document.querySelectorAll('a.json-icon');

for (var i = 0; i < links.length; i++) {
for (let i = 0; i < links.length; i++) {
links[i].addEventListener("click", function(event) {
event.preventDefault();
toggleJson(this);
Expand All @@ -150,11 +150,10 @@ function init() {
}

function toggleJson(button) {
var index = button.dataset.index;
const index = button.dataset.index;

var obj = document.getElementById("json-code-" + index);
if (!obj)
return;
const obj = document.getElementById("json-code-" + index);
if (!obj) return;

if (obj.style.display === "none") {
button.className += " json-up";
Expand All @@ -170,43 +169,42 @@ function toggleJson(button) {
<?php
}

public function selectVal(&$val, $link, $field, $original)
public function selectVal(&$val, $link, array $field, $original)
{
static $counter = 1;

if (!$this->inTable) {
return;
}

if (is_string($original) && in_array(substr($original, 0, 1), ['{', '[']) && ($json = json_decode($original, true))) {
if ($this->isJson($field, $original) && ($json = json_decode($original, true)) !== null) {
$val = "<a class='icon json-icon' href='#' title='JSON' data-index='$counter'>JSON</a> " . $val;
$val .= $this->convertJson($json, 1, $counter++);
if (is_array($json)) {
$val .= $this->convertJson($json, 1, $counter++);
}
}
}

public function editInput($table, $field, $attrs, $value)
public function editInput($table, array $field, $attrs, $value)
{
static $counter = 1;

if (!$this->inEdit) {
return;
}

if (is_string($value) && in_array(substr($value, 0, 1), ['{', '[']) && ($json = json_decode($value, true))) {
if ($this->isJson($field, $value) && ($json = json_decode($value, true)) !== null && is_array($json)) {
echo "<a class='icon json-icon json-link' href='#' title='JSON' data-index='$counter'><span>JSON</span></a><br/>";
echo $this->convertJson($json, 1, $counter);
}
}

public function truncate($value)
private function isJson(array $field, $value)
{
if ($this->maxTextLength > 0 && mb_strlen($value, "UTF-8") > $this->maxTextLength) {
$value = mb_substr($value, 0, $this->maxTextLength - 1, "UTF-8") . "";
}
return $value;
return $field["type"] == "json" || (is_string($value) && in_array(substr($value, 0, 1), ['{', '[']));
}

public function convertJson($json, $level = 1, $id = 0)
private function convertJson(array $json, $level = 1, $id = 0)
{
$value = "";

Expand All @@ -223,9 +221,12 @@ public function convertJson($json, $level = 1, $id = 0)
if (is_array($val) && ($this->maxLevel <= 0 || $level < $this->maxLevel)) {
$value .= $this->convertJson($val, $level + 1);
} elseif (is_array($val)) {
$val = json_encode($val);
$value .= "<code class='jush-js'>" . h(preg_replace('/([,:])([^\s])/', '$1 $2', $this->truncate($val))) . "</code>";
// Shorten encoded JSON to max. length.
$val = $this->truncate(json_encode($val));

$value .= "<code class='jush-js'>" . h(preg_replace('/([,:])([^\s])/', '$1 $2', $val)) . "</code>";
} elseif (is_string($val)) {
// Shorten string to max. length.
$val = $this->truncate($val);

// Add extra new line to make it visible in HTML output.
Expand All @@ -245,8 +246,19 @@ public function convertJson($json, $level = 1, $id = 0)
}
}

if (empty($json)) {
$value .= "<tr><td> </td></tr>";
}

$value .= "</table>";

return $value;
}
}

private function truncate($value)
{
return $this->maxTextLength > 0 && mb_strlen($value, "UTF-8") > $this->maxTextLength
? mb_substr($value, 0, $this->maxTextLength - 1, "UTF-8") . ""
: $value;
}
}
2 changes: 1 addition & 1 deletion panels/Adminer/plugins/AdminerProcessWireLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function name() {
</svg>
</a>
';
return $pwLink."<a href='https://www.adminerevo.org/'".target_blank()." id='h1'>AdminerEvo</a>";
return $pwLink."<a href='".h(HOME_URL)."' id='h1'>Adminer</a>";
}

function credentials() {
Expand Down
6 changes: 3 additions & 3 deletions panels/Adminer/plugins/AdminerSimpleMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function tablesPrint($tables)
$actions = [$_GET["select"], $_GET["edit"], $_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"]];

foreach ($tables as $table => $status) {
$name = $status['Name'];
$name = adminer()->tableName($status);
if ($name == "") {
continue;
}
Expand All @@ -63,9 +63,9 @@ public function tablesPrint($tables)

echo "<li data-table-name='$name'>";
if ($this->preferSelect || support("table") || support("indexes")) {
echo '<a href="' . h(ME) . $action . '=' . urlencode($table) . '"' . bold($active, (is_view($status) ? "view" : "")) . " data-link='main'>$name</a>";
echo '<a href="' . h(ME) . $action . '=' . urlencode($table) . '"' . bold($active, (is_view($status) ? "view" : "")) . "' data-link='main' data-main='true'>$name</a>";
} else {
echo "<span data-link='main'>$name</span>";
echo "<span data-link='main' data-main='true'>$name</span>";
}
echo "</li>\n";
}
Expand Down
14 changes: 7 additions & 7 deletions panels/Adminer/plugins/dump-alter.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerDumpAlter {

function dumpFormat() {
if (DRIVER == 'server') {
if (DRIVER == 'server' || DRIVER == 'mysql') {
return array('sql_alter' => 'Alter');
}
}

function _database() {
// drop old tables
$query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()";
Expand Down Expand Up @@ -52,7 +52,7 @@ function _database() {
SELECT @adminer_alter;
";
}

function dumpDatabase($db) {
static $first = true;
if ($_POST["format"] == "sql_alter") {
Expand All @@ -66,8 +66,8 @@ function dumpDatabase($db) {
return true;
}
}
function dumpTable($table, $style, $is_view = false) {

function dumpTable($table, $style, $is_view = 0) {
if ($_POST["format"] == "sql_alter") {
$create = create_sql($table, $_POST["auto_increment"], $style);
if ($is_view) {
Expand Down Expand Up @@ -146,7 +146,7 @@ function dumpTable($table, $style, $is_view = false) {
return true;
}
}

function dumpData() {
if ($_POST["format"] == "sql_alter") {
return true;
Expand Down
Empty file modified panels/Adminer/plugins/dump-bz2.php
100644 → 100755
Empty file.
12 changes: 6 additions & 6 deletions panels/Adminer/plugins/dump-json.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
class AdminerDumpJson {
/** @access protected */
var $database = false;

function dumpFormat() {
return ['json' => 'JSON'];
return array('json' => 'JSON');
}

function dumpTable($table, $style, $is_view = false) {
function dumpTable($table, $style, $is_view = 0) {
if ($_POST["format"] == "json") {
return true;
}
}

function _database() {
echo "}\n";
}

function dumpData($table, $style, $query) {
if ($_POST["format"] == "json") {
if ($this->database) {
echo ",\n";
} else {
$this->database = true;
echo "{\n";
register_shutdown_function([$this, '_database']);
register_shutdown_function(array($this, '_database'));
}
$connection = connection();
$result = $connection->query($query, 1);
Expand Down
Empty file modified panels/Adminer/plugins/dump-zip.php
100644 → 100755
Empty file.
Empty file modified panels/Adminer/plugins/frames.php
100644 → 100755
Empty file.
55 changes: 30 additions & 25 deletions panels/Adminer/plugins/plugin.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,31 @@
* @license https://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 __construct($plugins) {
protected $plugins;

/**
* Registers plugins.
* @param array $plugins Object instances or null to register all classes starting by 'Adminer'.
*/
function __construct(array $plugins = null)
{
if ($plugins === null) {
$plugins = array();
$plugins = [];
foreach (get_declared_classes() as $class) {
if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface
if (preg_match('~^Adminer.~i', $class) && !is_subclass_of($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)) {
Expand All @@ -57,7 +52,7 @@ function _applyPlugin($function, $args) {
}
return $this->_callParent($function, $args);
}

function _appendPlugin($function, $args) {
$return = $this->_callParent($function, $args);
foreach ($this->plugins as $plugin) {
Expand All @@ -70,26 +65,31 @@ function _appendPlugin($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 editRowPrint($table, $fields, $row, $update) {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}

function editFunctions($field) {
$args = func_get_args();
return $this->_appendPlugin(__FUNCTION__, $args);
}

// applyPlugin

function name() {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
Expand All @@ -110,6 +110,11 @@ function permanentLogin($create = false) {
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);
Expand Down Expand Up @@ -245,7 +250,7 @@ function tableIndexesPrint($indexes) {
return $this->_applyPlugin(__FUNCTION__, $args);
}

function selectColumnsPrint($select, $columns) {
function selectColumnsPrint($select,$columns) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
Expand Down Expand Up @@ -330,7 +335,7 @@ function messageQuery($query, $time, $failed = false) {
return $this->_applyPlugin(__FUNCTION__, $args);
}

function editInput($table, $field, $attrs, $value) {
function editInput($table, $field, $attrs, $value, $function) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}
Expand Down
Loading

0 comments on commit a16f9c5

Please sign in to comment.