2013-04-02 18:49:32 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/** Display JSON values as table in edit
|
2015-09-08 09:23:25 -07:00
|
|
|
* @link https://www.adminer.org/plugins/#use
|
2017-02-27 13:43:33 +01:00
|
|
|
* @author Jakub Vrana, https://www.vrana.cz/
|
2014-09-18 12:09:54 +02:00
|
|
|
* @author Martin Zeman (Zemistr), http://www.zemistr.eu/
|
2018-01-14 11:03:54 +01:00
|
|
|
* @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)
|
2013-04-02 18:49:32 -07:00
|
|
|
*/
|
2025-04-07 16:32:57 +02:00
|
|
|
class AdminerJsonColumn extends Adminer\Plugin {
|
2025-03-11 07:56:28 +01:00
|
|
|
private function testJson($value) {
|
2014-09-18 12:09:54 +02:00
|
|
|
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) {
|
|
|
|
|
return $json;
|
|
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 07:56:28 +01:00
|
|
|
private function buildTable($json) {
|
2025-02-23 11:42:05 +01:00
|
|
|
echo '<table style="margin:2px; font-size:100%;">';
|
2014-09-18 12:09:54 +02:00
|
|
|
foreach ($json as $key => $val) {
|
|
|
|
|
echo '<tr>';
|
2025-03-05 11:40:56 +01:00
|
|
|
echo '<th>' . Adminer\h($key) . '</th>';
|
2014-09-18 12:09:54 +02:00
|
|
|
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)) {
|
2025-03-05 11:40:56 +01:00
|
|
|
$val = '"' . Adminer\h(addcslashes($val, "\r\n\"")) . '"';
|
2014-09-18 12:09:54 +02:00
|
|
|
}
|
|
|
|
|
echo '<code class="jush-js">' . $val . '</code>';
|
|
|
|
|
} else {
|
2025-03-11 07:56:28 +01:00
|
|
|
$this->buildTable($val);
|
2013-04-02 18:49:32 -07:00
|
|
|
}
|
2014-09-18 12:09:54 +02:00
|
|
|
echo '</td>';
|
|
|
|
|
echo '</tr>';
|
2013-04-02 18:49:32 -07:00
|
|
|
}
|
2014-09-18 12:09:54 +02:00
|
|
|
echo '</table>';
|
2013-04-02 18:49:32 -07:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 12:09:54 +02:00
|
|
|
function editInput($table, $field, $attrs, $value) {
|
2025-03-11 07:56:28 +01:00
|
|
|
$json = $this->testJson($value);
|
2014-09-18 12:09:54 +02:00
|
|
|
if ($json !== $value) {
|
2025-03-11 07:56:28 +01:00
|
|
|
$this->buildTable($json);
|
2014-09-18 12:09:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-04-07 17:00:59 +02:00
|
|
|
|
2025-04-08 12:57:03 +02:00
|
|
|
protected $translations = array(
|
2025-04-07 17:00:59 +02:00
|
|
|
'cs' => array('' => 'Hodnoty JSON v editaci zobrazí formou tabulky'),
|
|
|
|
|
'de' => array('' => 'Zeigen Sie JSON-Werte als Tabelle in der Bearbeitung an'),
|
|
|
|
|
'pl' => array('' => 'Wyświetl wartości JSON jako tabelę w edycji'),
|
|
|
|
|
'ro' => array('' => 'Afișează valorile JSON sub formă de tabel în editare'),
|
|
|
|
|
);
|
2013-04-02 18:49:32 -07:00
|
|
|
}
|