]> git.joonet.de Git - adminer.git/commitdiff
Move rendering of table structure and indexes list into plugin system
authorMatthew Gamble <git@matthewgamble.net>
Sat, 5 Dec 2015 14:21:37 +0000 (01:21 +1100)
committerJakub Vrana <jakub@vrana.cz>
Sat, 18 Feb 2017 18:15:23 +0000 (19:15 +0100)
This allows the creation of a plugin to extend the display of either or
both of these things.

adminer/include/adminer.inc.php
adminer/table.inc.php
plugins/plugin.php

index 9761ac81540ac182d2a158c09597e27e41e06ac1..3028e7d5c476f9020bdc1891cd51e041c93b2c46 100644 (file)
@@ -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 "<table cellspacing='0'>\n";
+               echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . (support("comment") ? "<td>" . lang('Comment') : "") . "</thead>\n";
+               foreach ($fields as $field) {
+                       echo "<tr" . odd() . "><th>" . h($field["field"]);
+                       echo "<td><span title='" . h($field["collation"]) . "'>" . h($field["full_type"]) . "</span>";
+                       echo ($field["null"] ? " <i>NULL</i>" : "");
+                       echo ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
+                       echo (isset($field["default"]) ? " <span title='" . lang('Default value') . "'>[<b>" . h($field["default"]) . "</b>]</span>" : "");
+                       echo (support("comment") ? "<td>" . nbsp($field["comment"]) : "");
+                       echo "\n";
+               }
+               echo "</table>\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 "<table cellspacing='0'>\n";
+               foreach ($indexes as $name => $index) {
+                       ksort($index["columns"]); // enforce correct columns order
+                       $print = array();
+                       foreach ($index["columns"] as $key => $val) {
+                               $print[] = "<i>" . h($val) . "</i>"
+                                       . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
+                                       . ($index["descs"][$key] ? " DESC" : "")
+                               ;
+                       }
+                       echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
+               }
+               echo "</table>\n";
+       }
+
        /** Print columns box in select
        * @param array result of selectColumnsProcess()[0]
        * @param array selectable columns
index 11e8ced67c580e2556aed241d37de86d39c65426..ef1dbc81f2c59745b76f4d89a27d9cfbf52089a8 100644 (file)
@@ -15,18 +15,7 @@ if ($comment != "") {
 }
 
 if ($fields) {
-       echo "<table cellspacing='0'>\n";
-       echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . (support("comment") ? "<td>" . lang('Comment') : "") . "</thead>\n";
-       foreach ($fields as $field) {
-               echo "<tr" . odd() . "><th>" . h($field["field"]);
-               echo "<td><span title='" . h($field["collation"]) . "'>" . h($field["full_type"]) . "</span>";
-               echo ($field["null"] ? " <i>NULL</i>" : "");
-               echo ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
-               echo (isset($field["default"]) ? " <span title='" . lang('Default value') . "'>[<b>" . h($field["default"]) . "</b>]</span>" : "");
-               echo (support("comment") ? "<td>" . nbsp($field["comment"]) : "");
-               echo "\n";
-       }
-       echo "</table>\n";
+       $adminer->tableStructurePrint($fields);
 }
 
 if (!is_view($table_status)) {
@@ -34,19 +23,7 @@ if (!is_view($table_status)) {
                echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
                $indexes = indexes($TABLE);
                if ($indexes) {
-                       echo "<table cellspacing='0'>\n";
-                       foreach ($indexes as $name => $index) {
-                               ksort($index["columns"]); // enforce correct columns order
-                               $print = array();
-                               foreach ($index["columns"] as $key => $val) {
-                                       $print[] = "<i>" . h($val) . "</i>"
-                                               . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
-                                               . ($index["descs"][$key] ? " DESC" : "")
-                                       ;
-                               }
-                               echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
-                       }
-                       echo "</table>\n";
+                       $adminer->tableIndexesPrint($indexes);
                }
                echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
        }
index b686a736e14d66c5d1bd900cf8930e317fde814b..aae72c35a4dbfc617bc1a0f61355f0293b52082c 100644 (file)
@@ -202,6 +202,16 @@ class AdminerPlugin extends Adminer {
                return $this->_applyPlugin(__FUNCTION__, $args);
        }
 
+       function tableStructurePrint($fields) {
+               $args = func_get_args();
+               return $this->_applyPlugin(__FUNCTION__, $args);
+       }
+
+       function tableIndexesPrint($indexes) {
+               $args = func_get_args();
+               return $this->_applyPlugin(__FUNCTION__, $args);
+       }
+
        function selectColumnsPrint($select, $columns) {
                $args = func_get_args();
                return $this->_applyPlugin(__FUNCTION__, $args);