From 0ebf022426654a557397a57f045802e7d212e134 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 11 Apr 2012 16:50:10 -0400 Subject: [PATCH] Refactoring challenge --- tbl_structure.php | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/tbl_structure.php b/tbl_structure.php index 30c937e15a..3c19da67db 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -259,34 +259,22 @@ foreach ($fields as $row) { } // for the case ENUM('–','“') $type = htmlspecialchars($type); - // in case it is too long - $start = 0; - if (strlen($type) > $GLOBALS['cfg']['LimitChars']) { - $start = 13; - $type = '' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . ''; + + $field_charset = ''; + if ( + $extracted_fieldspec['binary'] == false + && + preg_match("@^(char|varchar|text|tinytext|mediumtext|longtext|set|enum)@", $type)) { + if (! empty($row['Collation'])) { + $field_charset = $row['Collation']; + } } - unset($field_charset); - if ((substr($type, $start, 4) == 'char' - || substr($type, $start, 7) == 'varchar' - || substr($type, $start, 4) == 'text' - || substr($type, $start, 8) == 'tinytext' - || substr($type, $start, 10) == 'mediumtext' - || substr($type, $start, 8) == 'longtext' - || substr($type, $start, 3) == 'set' - || substr($type, $start, 4) == 'enum') - && !$extracted_fieldspec['binary'] - ) { - if (strpos($type, ' character set ')) { - $type = substr($type, 0, strpos($type, ' character set ')); - } - if (!empty($row['Collation'])) { - $field_charset = $row['Collation']; - } else { - $field_charset = ''; - } - } else { - $field_charset = ''; + $displayed_type = $type; + if (strlen($type) > $GLOBALS['cfg']['LimitChars']) { + $displayed_type = ""; + $displayed_type .= substr($type, 0, $GLOBALS['cfg']['LimitChars']); + $displayed_type .= ""; } // Display basic mimetype [MIME] @@ -343,7 +331,7 @@ foreach ($fields as $row) { - > + > ' . $field_charset . ''); ?>