From 76612b1e8a8dbfd8d9fbd505a671d6f7af0213d9 Mon Sep 17 00:00:00 2001 From: Matthew Gamble Date: Sun, 6 Dec 2015 01:21:37 +1100 Subject: [PATCH] Move rendering of table structure and indexes list into plugin system This allows the creation of a plugin to extend the display of either or both of these things. --- adminer/include/adminer.inc.php | 39 +++++++++++++++++++++++++++++++++ adminer/table.inc.php | 27 ++--------------------- plugins/plugin.php | 10 +++++++++ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 9761ac81..3028e7d5 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -246,6 +246,45 @@ focus(document.getElementById('username')); return $val; } + /** Print table structure in tabular format + * @param array data about individual fields + * @return null + */ + function tableStructurePrint($fields) { + echo "\n"; + echo "\n"; + foreach ($fields as $field) { + echo "
" . lang('Column') . "" . lang('Type') . (support("comment") ? "" . lang('Comment') : "") . "
" . h($field["field"]); + echo "" . h($field["full_type"]) . ""; + echo ($field["null"] ? " NULL" : ""); + echo ($field["auto_increment"] ? " " . lang('Auto Increment') . "" : ""); + echo (isset($field["default"]) ? " [" . h($field["default"]) . "]" : ""); + echo (support("comment") ? "" . nbsp($field["comment"]) : ""); + echo "\n"; + } + echo "
\n"; + } + + /** Print list of indexes on table in tabular format + * @param array data about all indexes on a table + * @return null + */ + function tableIndexesPrint($indexes) { + echo "\n"; + foreach ($indexes as $name => $index) { + ksort($index["columns"]); // enforce correct columns order + $print = array(); + foreach ($index["columns"] as $key => $val) { + $print[] = "" . h($val) . "" + . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "") + . ($index["descs"][$key] ? " DESC" : "") + ; + } + echo "
$index[type]" . implode(", ", $print) . "\n"; + } + echo "
\n"; + } + /** Print columns box in select * @param array result of selectColumnsProcess()[0] * @param array selectable columns diff --git a/adminer/table.inc.php b/adminer/table.inc.php index 11e8ced6..ef1dbc81 100644 --- a/adminer/table.inc.php +++ b/adminer/table.inc.php @@ -15,18 +15,7 @@ if ($comment != "") { } if ($fields) { - echo "\n"; - echo "\n"; - foreach ($fields as $field) { - echo "
" . lang('Column') . "" . lang('Type') . (support("comment") ? "" . lang('Comment') : "") . "
" . h($field["field"]); - echo "" . h($field["full_type"]) . ""; - echo ($field["null"] ? " NULL" : ""); - echo ($field["auto_increment"] ? " " . lang('Auto Increment') . "" : ""); - echo (isset($field["default"]) ? " [" . h($field["default"]) . "]" : ""); - echo (support("comment") ? "" . nbsp($field["comment"]) : ""); - echo "\n"; - } - echo "
\n"; + $adminer->tableStructurePrint($fields); } if (!is_view($table_status)) { @@ -34,19 +23,7 @@ if (!is_view($table_status)) { echo "

" . lang('Indexes') . "

\n"; $indexes = indexes($TABLE); if ($indexes) { - echo "\n"; - foreach ($indexes as $name => $index) { - ksort($index["columns"]); // enforce correct columns order - $print = array(); - foreach ($index["columns"] as $key => $val) { - $print[] = "" . h($val) . "" - . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "") - . ($index["descs"][$key] ? " DESC" : "") - ; - } - echo "
$index[type]" . implode(", ", $print) . "\n"; - } - echo "
\n"; + $adminer->tableIndexesPrint($indexes); } echo '