Skip to content

Commit

Permalink
Use template for getHtmlForImportCharset
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Nov 25, 2017
1 parent aeef8e5 commit ef7936a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
38 changes: 7 additions & 31 deletions libraries/classes/Display/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,14 @@ public static function getHtmlForImportCompressions()
public static function getHtmlForImportCharset()
{
global $cfg;
$html = ' <div class="formelementrow" id="charaset_of_file">';
// charset of file
if (Encoding::isSupported()) {
$html .= '<label for="charset_of_file">' . __('Character set of the file:')
. '</label>';
$html .= '<select id="charset_of_file" name="charset_of_file" size="1">';
foreach (Encoding::listEncodings() as $temp_charset) {
$html .= '<option value="' . htmlentities($temp_charset) . '"';
if ((empty($cfg['Import']['charset']) && $temp_charset == 'utf-8')
|| $temp_charset == $cfg['Import']['charset']
) {
$html .= ' selected="selected"';
}
$html .= '>' . htmlentities($temp_charset) . '</option>';
}
$html .= ' </select><br />';
} else {
$html .= '<label for="charset_of_file">' . __('Character set of the file:')
. '</label>' . "\n";
$html .= Charsets::getCharsetDropdownBox(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['DisableIS'],
'charset_of_file',
'charset_of_file',
'utf8',
false
);
} // end if (recoding)

$html .= ' </div>';

return $html;
return Template::get('display/import/charset')->render([
'is_encoding_supported' => Encoding::isSupported(),
'encodings' => Encoding::listEncodings(),
'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null,
'dbi' => $GLOBALS['dbi'],
'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
]);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions libraries/classes/Twig/CharsetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function getFunctions()
'Charsets_getCollationDescr',
'PhpMyAdmin\Charsets::getCollationDescr'
),
new Twig_SimpleFunction(
'Charsets_getCharsetDropdownBox',
'PhpMyAdmin\Charsets::getCharsetDropdownBox',
array('is_safe' => array('html'))
),
new Twig_SimpleFunction(
'Charsets_getCollationDropdownBox',
'PhpMyAdmin\Charsets::getCollationDropdownBox',
Expand Down
26 changes: 26 additions & 0 deletions templates/display/import/charset.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="formelementrow" id="charaset_of_file">
{# Charset of file #}
<label for="charset_of_file">{% trans 'Character set of the file:' %}</label>
{% if is_encoding_supported %}
<select id="charset_of_file" name="charset_of_file" size="1">
{% for charset in encodings %}
<option value="{{ charset }}"
{% if (import_charset is empty and charset == 'utf-8')
or charset == import_charset %}
selected="selected"
{% endif %}>
{{ charset }}
</option>
{% endfor %}
</select>
{% else %}
{{ Charsets_getCharsetDropdownBox(
dbi,
disable_is,
'charset_of_file',
'charset_of_file',
'utf8',
false
) }}
{% endif %}
</div>

0 comments on commit ef7936a

Please sign in to comment.