XoopsModules25x /
adminer
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** Dump to JSON format |
||
| 4 | * @link https://www.adminer.org/plugins/#use |
||
| 5 | * @author Jakub Vrana, http://www.vrana.cz/ |
||
| 6 | * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
||
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) |
||
| 8 | */ |
||
| 9 | class AdminerDumpJson { |
||
| 10 | /** @access protected */ |
||
| 11 | var $database = false; |
||
| 12 | |||
| 13 | function dumpFormat() { |
||
|
0 ignored issues
–
show
|
|||
| 14 | return array('json' => 'JSON'); |
||
| 15 | } |
||
| 16 | |||
| 17 | function dumpTable($table, $style, $is_view = false) { |
||
|
0 ignored issues
–
show
|
|||
| 18 | if ($_POST['format'] == 'json') { |
||
| 19 | return true; |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | function _database() { |
||
|
0 ignored issues
–
show
|
|||
| 24 | echo "}\n"; |
||
| 25 | } |
||
| 26 | |||
| 27 | function dumpData($table, $style, $query) { |
||
|
0 ignored issues
–
show
|
|||
| 28 | if ($_POST['format'] == 'json') { |
||
| 29 | if ($this->database) { |
||
| 30 | echo ",\n"; |
||
| 31 | } else { |
||
| 32 | $this->database = true; |
||
| 33 | echo "{\n"; |
||
| 34 | register_shutdown_function(array($this, '_database')); |
||
| 35 | } |
||
| 36 | $connection = connection(); |
||
| 37 | $result = $connection->query($query, 1); |
||
| 38 | if ($result) { |
||
| 39 | echo '"' . addcslashes($table, "\r\n\"\\") . "\": [\n"; |
||
| 40 | $first = true; |
||
| 41 | while ($row = $result->fetch_assoc()) { |
||
| 42 | echo ($first ? '' : ', '); |
||
| 43 | $first = false; |
||
| 44 | foreach ($row as $key => $val) { |
||
| 45 | json_row($key, $val); |
||
| 46 | } |
||
| 47 | json_row(''); |
||
| 48 | } |
||
| 49 | echo ']'; |
||
| 50 | } |
||
| 51 | return true; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | function dumpHeaders($identifier, $multi_table = false) { |
||
|
0 ignored issues
–
show
|
|||
| 56 | if ($_POST['format'] == 'json') { |
||
| 57 | header('Content-Type: application/json; charset=utf-8'); |
||
| 58 | return 'json'; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | } |
||
| 63 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.