From 35c725515b049d816497a3491c108792ffb2b22e Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 29 Apr 2012 08:29:55 -0400 Subject: [PATCH] Fix duplicate code --- libraries/export/odt.php | 117 ++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 64 deletions(-) diff --git a/libraries/export/odt.php b/libraries/export/odt.php index 80be80f8c4..55f9d3ffdd 100644 --- a/libraries/export/odt.php +++ b/libraries/export/odt.php @@ -269,41 +269,11 @@ if (isset($plugin_list)) { . ''; $GLOBALS['odt_buffer'] .= ''; - $columns = PMA_DBI_get_columns($db, $table); + $columns = PMA_DBI_get_columns($db, $view); foreach ($columns as $column) { - $field_name = $column['Field']; - $GLOBALS['odt_buffer'] .= ''; - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($field_name) . '' - . ''; - - $extracted_columnspec = PMA_extractColumnSpec($column['Type']); - $type = htmlspecialchars($extracted_columnspec['print_type']); - if (empty($type)) { - $type = ' '; - } - - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($type) . '' - . ''; - if (!isset($column['Default'])) { - if ($column['Null'] != 'NO') { - $column['Default'] = 'NULL'; - } else { - $column['Default'] = ''; - } - } else { - $column['Default'] = $column['Default']; - } - $GLOBALS['odt_buffer'] .= '' - . '' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '' - . ''; - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($column['Default']) . '' - . ''; - + $GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column); $GLOBALS['odt_buffer'] .= ''; - } // end while + } // end foreach $GLOBALS['odt_buffer'] .= ''; return true; @@ -416,36 +386,7 @@ if (isset($plugin_list)) { $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { - $field_name = $column['Field']; - $GLOBALS['odt_buffer'] .= ''; - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($field_name) . '' - . ''; - - $extracted_columnspec = PMA_extractColumnSpec($column['Type']); - $type = htmlspecialchars($extracted_columnspec['print_type']); - if (empty($type)) { - $type = ' '; - } - - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($type) . '' - . ''; - if (!isset($column['Default'])) { - if ($column['Null'] != 'NO') { - $column['Default'] = 'NULL'; - } else { - $column['Default'] = ''; - } - } else { - $column['Default'] = $column['Default']; - } - $GLOBALS['odt_buffer'] .= '' - . '' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '' - . ''; - $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($column['Default']) . '' - . ''; + $GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column); if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { @@ -477,7 +418,7 @@ if (isset($plugin_list)) { } } $GLOBALS['odt_buffer'] .= ''; - } // end while + } // end foreach $GLOBALS['odt_buffer'] .= ''; return true; @@ -587,5 +528,53 @@ if (isset($plugin_list)) { return PMA_exportOutputHandler($dump); } // end of the 'PMA_exportStructure' function + /** + * Formats the definition for one column + * + * @param array $column info about this column + * + * @return string Formatted column definition + * + * @access public + */ + function PMA_formatOneColumnDefinition( + $column + ) { + $field_name = $column['Field']; + $definition = ''; + $definition .= '' + . '' . htmlspecialchars($field_name) . '' + . ''; + + $extracted_columnspec = PMA_extractColumnSpec($column['Type']); + $type = htmlspecialchars($extracted_columnspec['print_type']); + if (empty($type)) { + $type = ' '; + } + + $definition .= '' + . '' . htmlspecialchars($type) . '' + . ''; + if (! isset($column['Default'])) { + if ($column['Null'] != 'NO') { + $column['Default'] = 'NULL'; + } else { + $column['Default'] = ''; + } + } else { + $column['Default'] = $column['Default']; + } + $definition .= '' + . '' + . (($column['Null'] == '' || $column['Null'] == 'NO') + ? __('No') + : __('Yes')) + . '' + . ''; + $definition .= '' + . '' . htmlspecialchars($column['Default']) . '' + . ''; + return $definition; + } } // end else ?>