created serialized-column - add edit-foreign enu-option json-column
This commit is contained in:
parent
2c1cb8b8c1
commit
35e6c11a44
4 changed files with 151 additions and 0 deletions
43
plugins/AdminerEditForeign.php
Normal file
43
plugins/AdminerEditForeign.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** Select foreign key in edit form
|
||||||
|
* @link https://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 AdminerEditForeign {
|
||||||
|
var $_limit;
|
||||||
|
|
||||||
|
function __construct($limit = 0) {
|
||||||
|
$this->_limit = $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function editInput($table, $field, $attrs, $value) {
|
||||||
|
static $foreignTables = array();
|
||||||
|
static $values = array();
|
||||||
|
$foreignKeys = &$foreignTables[$table];
|
||||||
|
if ($foreignKeys === null) {
|
||||||
|
$foreignKeys = 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 = idf_escape($id);
|
||||||
|
if (preg_match('~binary~', $field["type"])) {
|
||||||
|
$column = "HEX($column)";
|
||||||
|
}
|
||||||
|
$options = array("" => "") + get_vals("SELECT $column FROM " . table($target) . " ORDER BY 1" . ($this->_limit ? " LIMIT " . ($this->_limit + 1) : ""));
|
||||||
|
if ($this->_limit && count($options) - 1 > $this->_limit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "<select$attrs>" . optionlist($options, $value) . "</select>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
plugins/AdminerEnumOption.php
Normal file
37
plugins/AdminerEnumOption.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** Use <select><option> for enum edit instead of <input type="radio">
|
||||||
|
* @link https://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 AdminerEnumOption {
|
||||||
|
|
||||||
|
function editInput($table, $field, $attrs, $value) {
|
||||||
|
if ($field["type"] == "enum") {
|
||||||
|
$options = array("" => array());
|
||||||
|
$selected = $value;
|
||||||
|
if (isset($_GET["select"])) {
|
||||||
|
$options[""][-1] = lang('original');
|
||||||
|
}
|
||||||
|
if ($field["null"]) {
|
||||||
|
$options[""][""] = "NULL";
|
||||||
|
if ($value === null && !isset($_GET["select"])) {
|
||||||
|
$selected = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$options[""][0] = 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>" . optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
plugins/AdminerJsonColumn.php
Normal file
48
plugins/AdminerJsonColumn.php
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** Display JSON values as table in edit
|
||||||
|
* @link https://www.adminer.org/plugins/#use
|
||||||
|
* @author Jakub Vrana, http://www.vrana.cz/
|
||||||
|
* @author Martin Zeman (Zemistr), http://www.zemistr.eu/
|
||||||
|
* @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 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) {
|
||||||
|
echo '<tr>';
|
||||||
|
echo '<th>' . h($key) . '</th>';
|
||||||
|
echo '<td>';
|
||||||
|
if (is_scalar($val) || $val === null) {
|
||||||
|
if (is_bool($val)) {
|
||||||
|
$val = $val ? 'true' : 'false';
|
||||||
|
} elseif ($val === null) {
|
||||||
|
$val = 'null';
|
||||||
|
} elseif (!is_numeric($val)) {
|
||||||
|
$val = '"' . h(addcslashes($val, "\r\n\"")) . '"';
|
||||||
|
}
|
||||||
|
echo '<code class="jush-js">' . $val . '</code>';
|
||||||
|
} else {
|
||||||
|
$this->_buildTable($val);
|
||||||
|
}
|
||||||
|
echo '</td>';
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '</table>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function editInput($table, $field, $attrs, $value) {
|
||||||
|
$json = $this->_testJson($value);
|
||||||
|
if ($json !== $value) {
|
||||||
|
$this->_buildTable($json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
plugins/AdminerSerializedColumn.php
Normal file
23
plugins/AdminerSerializedColumn.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue