diff --git a/adminer/plugin.php b/adminer/plugin.php index dac12efe..534b50f1 100644 --- a/adminer/plugin.php +++ b/adminer/plugin.php @@ -11,6 +11,7 @@ function adminer_object() { $plugins = array( // specify enabled plugins here new AdminerDatabaseHide(array('information_schema')), + new AdminerDumpJson, new AdminerDumpZip, new AdminerDumpXml, //~ new AdminerSqlLog("past-" . rtrim(`git describe --tags --abbrev=0`) . ".sql"), diff --git a/plugins/dump-json.php b/plugins/dump-json.php new file mode 100644 index 00000000..97a5a9b7 --- /dev/null +++ b/plugins/dump-json.php @@ -0,0 +1,62 @@ + 'JSON'); + } + + function dumpTable($table, $style, $is_view = false) { + 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(array($this, '_database')); + } + $connection = connection(); + $result = $connection->query($query, 1); + if ($result) { + echo '"' . addcslashes($table, "\r\n\"\\") . "\": [\n"; + $first = true; + while ($row = $result->fetch_assoc()) { + echo ($first ? "" : ", "); + $first = false; + foreach ($row as $key => $val) { + json_row($key, $val); + } + json_row(""); + } + echo "]"; + } + return true; + } + } + + function dumpHeaders($identifier, $multi_table = false) { + if ($_POST["format"] == "json") { + header("Content-Type: application/json; charset=utf-8"); + return "json"; + } + } + +}