From 116c87367186f93617384a0028dd4fd26bd55837 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 21 Jul 2009 13:59:02 +0000 Subject: [PATCH] Ignore tables and fields with empty name git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@861 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/edit.inc.php | 2 +- adminer/select.inc.php | 66 ++++++++++++++++++---------------- editor/include/adminer.inc.php | 5 +-- editor/lang/cs.inc.php | 9 +++-- examples/editor-cds/index.php | 8 +++++ 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index a81a60a35..802f8f48b 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -3,7 +3,7 @@ $update = ($where && !$_POST["clone"]); $fields = fields($_GET["edit"]); foreach ($fields as $name => $field) { - if (isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) { + if ((isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) || !strlen(adminer_field_name($fields, $name))) { unset($fields[$name]); } } diff --git a/adminer/select.inc.php b/adminer/select.inc.php index fab31791c..196f6d262 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -18,8 +18,9 @@ $columns = array(); // selectable columns unset($text_length); foreach ($fields as $key => $field) { - if (isset($field["privileges"]["select"])) { - $columns[$key] = html_entity_decode(strip_tags(adminer_field_name($fields, $key))); //! numeric $key is problematic in optionlist() + $name = adminer_field_name($fields, $key); + if (isset($field["privileges"]["select"]) && strlen($name)) { + $columns[$key] = html_entity_decode(strip_tags($name)); //! numeric $key is problematic in optionlist() if (ereg('text|blob', $field["type"])) { $text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100"); } @@ -304,46 +305,51 @@ echo "\n"; echo "\n"; foreach ($descriptions as $n => $row) { $unique_idf = implode('&', unique_idf($row, $indexes)); //! don't use aggregation functions echo '
"; foreach ($rows[0] as $key => $val) { - echo '' . adminer_field_name($fields, $key) . ''; + $name = adminer_field_name($fields, $key); + if (strlen($name)) { + echo '$name"; + } } echo ($backward_keys ? "" . lang('Relations') : "") . "
' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' ' . lang('edit') . ''); foreach ($row as $key => $val) { - if (strlen($val) && (!isset($email_fields[$key]) || $email_fields[$key])) { - $email_fields[$key] = is_email($val); //! filled e-mails may be contained on other pages - } - if (!isset($val)) { - $val = "NULL"; - } elseif (ereg('blob|binary', $fields[$key]["type"]) && !is_utf8($val)) { //! download link may be printed even with is_utf8 - $val = '' . lang('%d byte(s)', strlen($val)) . ''; - } else { - if (!strlen(trim($val, " \t"))) { - $val = " "; - } elseif (intval($text_length) > 0 && ereg('blob|text', $fields[$key]["type"])) { - $val = nl2br(shorten_utf8($val, intval($text_length))); // usage of LEFT() would reduce traffic but complicates query + if (strlen(adminer_field_name($fields, $key))) { + if (strlen($val) && (!isset($email_fields[$key]) || $email_fields[$key])) { + $email_fields[$key] = is_email($val); //! filled e-mails may be contained on other pages + } + if (!isset($val)) { + $val = "NULL"; + } elseif (ereg('blob|binary', $fields[$key]["type"]) && !is_utf8($val)) { //! download link may be printed even with is_utf8 + $val = '' . lang('%d byte(s)', strlen($val)) . ''; } else { - $val = nl2br(htmlspecialchars($val)); - if ($fields[$key]["type"] == "char") { - $val = "$val"; + if (!strlen(trim($val, " \t"))) { + $val = " "; + } elseif (intval($text_length) > 0 && ereg('blob|text', $fields[$key]["type"])) { + $val = nl2br(shorten_utf8($val, intval($text_length))); // usage of LEFT() would reduce traffic but complicates query + } else { + $val = nl2br(htmlspecialchars($val)); + if ($fields[$key]["type"] == "char") { + $val = "$val"; + } } - } - - // link related items - $link = ""; - foreach ((array) $foreign_keys[$key] as $foreign_key) { - if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { - foreach ($foreign_key["source"] as $i => $source) { - $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]); + + // link related items + $link = ""; + foreach ((array) $foreign_keys[$key] as $foreign_key) { + if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) { + foreach ($foreign_key["source"] as $i => $source) { + $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]); + } + $link = htmlspecialchars((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . urlencode($foreign_key["table"])) . $link; // InnoDB supports non-UNIQUE keys + break; } - $link = htmlspecialchars((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . urlencode($foreign_key["table"])) . $link; // InnoDB supports non-UNIQUE keys - break; } + $val = adminer_select_val($val, $link); } - $val = adminer_select_val($val, $link); + echo "$val"; } - echo "$val"; } if ($backward_keys) { echo ""; diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index ff082f323..3da889ce3 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -108,8 +108,9 @@ function adminer_navigation($missing) { } else { echo "

\n"; foreach ($table_status as $row) { - if (isset($row["Engine"])) { // ignore views - echo '' . adminer_table_name($row) . "
\n"; + $name = adminer_table_name($row); + if (isset($row["Engine"]) && strlen($name)) { // ignore views and tables without name + echo '$name
\n"; } } } diff --git a/editor/lang/cs.inc.php b/editor/lang/cs.inc.php index 442755f2f..1088aadf1 100644 --- a/editor/lang/cs.inc.php +++ b/editor/lang/cs.inc.php @@ -4,7 +4,6 @@ 'Invalid credentials.' => 'Neplatné přihlašovací údaje.', 'Server' => 'Server', 'Save' => 'Uložit', - 'SQL command' => 'SQL příkaz', 'Logout' => 'Odhlásit', 'Use' => 'Vybrat', 'No tables.' => 'Žádné tabulky.', @@ -53,7 +52,6 @@ '%d row(s) has been imported.' => array('Byl importován %d záznam.', 'Byly importovány %d záznamy.', 'Bylo importováno %d záznamů.'), 'CSV Import' => 'Import CSV', 'Import' => 'Import', - 'Table structure' => 'Struktura tabulky', '(anywhere)' => '(kdekoliv)', 'Editor' => 'Editor', 'E-mail' => 'E-mail', @@ -61,4 +59,11 @@ 'Subject' => 'Předmět', 'Send' => 'Odeslat', '%d e-mail(s) have been sent.' => array('Byl odeslán %d e-mail.', 'Byly odeslány %d e-maily.', 'Bylo odesláno %d e-mailů.'), + 'Relations' => 'Vztahy', + 'Maximum allowed file size is %sB.' => 'Maximální povolená velikost souboru je %sB.', + 'Username' => 'Uživatel', + 'Password' => 'Heslo', + 'Logout successful.' => 'Odhlášení proběhlo v pořádku.', + 'Sessions must be enabled.' => 'Session proměnné musí být povolené.', + 'Session expired, please login again.' => 'Session vypršela, přihlašte se prosím znovu.', ); diff --git a/examples/editor-cds/index.php b/examples/editor-cds/index.php index 9166163b9..86848de49 100644 --- a/examples/editor-cds/index.php +++ b/examples/editor-cds/index.php @@ -23,6 +23,14 @@ function login($login, $password) { return ($login == 'admin'); } + function table_name($row) { + return htmlspecialchars($row["Comment"]); + } + + function field_name($fields, $key) { + return htmlspecialchars($fields[$key]["comment"]); + } + } include "./editor.php";