From 6e5fbd7403691e4a19a5b9ffe80457955a18c7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 18:01:18 -0200 Subject: [PATCH 01/21] Use template for getHtmlForImportOptionsSubmit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 6 +----- templates/display/import/submit_option.twig | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 templates/display/import/submit_option.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 3a13cab3ba..d84513ad23 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -331,11 +331,7 @@ class Import */ public static function getHtmlForImportOptionsSubmit() { - $html = '
'; - $html .= ' '; - $html .= '
'; - - return $html; + return Template::get('display/import/submit_option')->render(); } /** diff --git a/templates/display/import/submit_option.twig b/templates/display/import/submit_option.twig new file mode 100644 index 0000000000..8f56a075ee --- /dev/null +++ b/templates/display/import/submit_option.twig @@ -0,0 +1,3 @@ +
+ +
From dfd8abaae60a94b945201f95238f8aeb219b857f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 18:44:13 -0200 Subject: [PATCH 02/21] Use template for getHtmlForImportOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 36 +++++++-------------------- templates/display/import/options.twig | 12 +++++++++ 2 files changed, 21 insertions(+), 27 deletions(-) create mode 100644 templates/display/import/options.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index d84513ad23..5383657377 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -105,37 +105,19 @@ class Import /** * Prints Html For Display Export options * - * @param String $import_type Import type: server, database, table - * @param String $db Selected DB - * @param String $table Selected Table + * @param String $importType Import type: server, database, table + * @param String $db Selected DB + * @param String $table Selected Table * * @return string */ - public static function getHtmlForImportOptions($import_type, $db, $table) + public static function getHtmlForImportOptions($importType, $db, $table) { - $html = ' '; - - return $html; + return Template::get('display/import/options')->render([ + 'import_type' => $importType, + 'db' => $db, + 'table' => $table, + ]); } /** diff --git a/templates/display/import/options.twig b/templates/display/import/options.twig new file mode 100644 index 0000000000..52ee928f84 --- /dev/null +++ b/templates/display/import/options.twig @@ -0,0 +1,12 @@ + From ce50bd64ce79647cff09db11f8117d937568d122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 18:52:19 -0200 Subject: [PATCH 03/21] Use template for getHtmlForHiddenInputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 25 ++++++++------------- templates/display/import/hidden_inputs.twig | 8 +++++++ 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 templates/display/import/hidden_inputs.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 5383657377..f0d100bd05 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -29,26 +29,19 @@ class Import /** * Prints Html For Display Import Hidden Input * - * @param String $import_type Import type: server, database, table - * @param String $db Selected DB - * @param String $table Selected Table + * @param String $importType Import type: server, database, table + * @param String $db Selected DB + * @param String $table Selected Table * * @return string */ - public static function getHtmlForHiddenInputs($import_type, $db, $table) + public static function getHtmlForHiddenInputs($importType, $db, $table) { - $html = ''; - if ($import_type == 'server') { - $html .= Url::getHiddenInputs('', '', 1); - } elseif ($import_type == 'database') { - $html .= Url::getHiddenInputs($db, '', 1); - } else { - $html .= Url::getHiddenInputs($db, $table, 1); - } - $html .= ' ' . "\n"; - - return $html; + return Template::get('display/import/hidden_inputs')->render([ + 'import_type' => $importType, + 'db' => $db, + 'table' => $table, + ]); } /** diff --git a/templates/display/import/hidden_inputs.twig b/templates/display/import/hidden_inputs.twig new file mode 100644 index 0000000000..493796b7d6 --- /dev/null +++ b/templates/display/import/hidden_inputs.twig @@ -0,0 +1,8 @@ +{% if import_type == 'server' %} + {{ Url_getHiddenInputs('', '', 1) }} +{% elseif import_type == 'database' %} + {{ Url_getHiddenInputs(db, '', 1) }} +{% else %} + {{ Url_getHiddenInputs(db, table, 1) }} +{% endif %} + From 45860954cd2c8453bc7b15d9517fa86c7c5021b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 19:49:08 -0200 Subject: [PATCH 04/21] Use template for getHtmlForImportWithPlugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 165 ++-------------------- libraries/classes/Twig/UrlExtension.php | 5 + templates/display/import/with_plugin.twig | 148 +++++++++++++++++++ 3 files changed, 162 insertions(+), 156 deletions(-) create mode 100644 templates/display/import/with_plugin.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index f0d100bd05..fc7dd11bb6 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -376,171 +376,24 @@ class Import /** * Prints javascript for upload with plugin, upload process bar * - * @param int $upload_id The selected upload id + * @param int $uploadId The selected upload id * * @return string */ - public static function getHtmlForImportWithPlugin($upload_id) + public static function getHtmlForImportWithPlugin($uploadId) { - //some variable for javascript - $ajax_url = "import_status.php?id=" . $upload_id . "&" - . Url::getCommonRaw(array('import_status'=>1)); - $promot_str = Sanitize::jsFormat( - __( - 'The file being uploaded is probably larger than ' - . 'the maximum allowed size or this is a known bug in webkit ' - . 'based (Safari, Google Chrome, Arora etc.) browsers.' - ), - false - ); - $statustext_str = Sanitize::escapeJsString(__('%s of %s')); - $upload_str = Sanitize::jsFormat(__('Uploading your import file…'), false); - $second_str = Sanitize::jsFormat(__('%s/sec.'), false); - $remaining_min = Sanitize::jsFormat(__('About %MIN min. %SEC sec. remaining.'), false); - $remaining_second = Sanitize::jsFormat(__('About %SEC sec. remaining.'), false); - $processed_str = Sanitize::jsFormat( - __('The file is being processed, please be patient.'), - false - ); - $import_url = Url::getCommonRaw(array('import_status'=>1)); - - //start output - $html = 'var finished = false; '; - $html .= 'var percent = 0.0; '; - $html .= 'var total = 0; '; - $html .= 'var complete = 0; '; - $html .= 'var original_title = ' - . 'parent && parent.document ? parent.document.title : false; '; - $html .= 'var import_start; '; - - $html .= 'var perform_upload = function () { '; - $html .= 'new $.getJSON( '; - $html .= ' "' . $ajax_url . '", '; - $html .= ' {}, '; - $html .= ' function(response) { '; - $html .= ' finished = response.finished; '; - $html .= ' percent = response.percent; '; - $html .= ' total = response.total; '; - $html .= ' complete = response.complete; '; - - $html .= ' if (total==0 && complete==0 && percent==0) { '; - $img_tag = 'ajax clock ' - . $promot_str . '\'); '; - $html .= ' $("#upload_form_status").css("display", "none"); '; - $html .= ' } else { '; - $html .= ' var now = new Date(); '; - $html .= ' now = Date.UTC( '; - $html .= ' now.getFullYear(), '; - $html .= ' now.getMonth(), '; - $html .= ' now.getDate(), '; - $html .= ' now.getHours(), '; - $html .= ' now.getMinutes(), '; - $html .= ' now.getSeconds()) '; - $html .= ' + now.getMilliseconds() - 1000; '; - $html .= ' var statustext = PMA_sprintf('; - $html .= ' "' . $statustext_str . '", '; - $html .= ' formatBytes( '; - $html .= ' complete, 1, PMA_messages.strDecimalSeparator'; - $html .= ' ), '; - $html .= ' formatBytes('; - $html .= ' total, 1, PMA_messages.strDecimalSeparator'; - $html .= ' ) '; - $html .= ' ); '; - - $html .= ' if ($("#importmain").is(":visible")) { '; - // show progress UI - $html .= ' $("#importmain").hide(); '; - $html .= ' $("#import_form_status") '; - $html .= ' .html(\'
' - . '
' - . '
' - . '
' - . 'ajax clock ' - . $upload_str . '
\') '; - $html .= ' .show(); '; - $html .= ' import_start = now; '; - $html .= ' } '; - $html .= ' else if (percent > 9 || complete > 2000000) { '; - // calculate estimated time - $html .= ' var used_time = now - import_start; '; - $html .= ' var seconds = ' - . 'parseInt(((total - complete) / complete) * used_time / 1000); '; - $html .= ' var speed = PMA_sprintf("' . $second_str . '"'; - $html .= ' , formatBytes(complete / used_time * 1000, 1,' - . ' PMA_messages.strDecimalSeparator)); '; - - $html .= ' var minutes = parseInt(seconds / 60); '; - $html .= ' seconds %= 60; '; - $html .= ' var estimated_time; '; - $html .= ' if (minutes > 0) { '; - $html .= ' estimated_time = "' . $remaining_min . '"'; - $html .= ' .replace("%MIN", minutes)'; - $html .= ' .replace("%SEC", seconds); '; - $html .= ' } '; - $html .= ' else { '; - $html .= ' estimated_time = "' . $remaining_second . '"'; - $html .= ' .replace("%SEC", seconds); '; - $html .= ' } '; - - $html .= ' statustext += "
" + speed + "

" ' - . '+ estimated_time; '; - $html .= ' } '; - - $html .= ' var percent_str = Math.round(percent) + "%"; '; - $html .= ' $("#status").animate({width: percent_str}, 150); '; - $html .= ' $(".percentage").text(percent_str); '; - - // show percent in window title - $html .= ' if (original_title !== false) { '; - $html .= ' parent.document.title '; - $html .= ' = percent_str + " - " + original_title; '; - $html .= ' } '; - $html .= ' else { '; - $html .= ' document.title '; - $html .= ' = percent_str + " - " + original_title; '; - $html .= ' } '; - $html .= ' $("#statustext").html(statustext); '; - $html .= ' } '; - - $html .= ' if (finished == true) { '; - $html .= ' if (original_title !== false) { '; - $html .= ' parent.document.title = original_title; '; - $html .= ' } '; - $html .= ' else { '; - $html .= ' document.title = original_title; '; - $html .= ' } '; - $html .= ' $("#importmain").hide(); '; - // loads the message, either success or mysql error - $html .= ' $("#import_form_status") '; - $html .= ' .html(\'ajax clock ' - . $processed_str . '\')'; - $html .= ' .show(); '; - $html .= ' $("#import_form_status").load("import_status.php?' - . 'message=true&' . $import_url . '"); '; - $html .= ' PMA_reloadNavigation(); '; - - // if finished - $html .= ' } '; - $html .= ' else { '; - $html .= ' setTimeout(perform_upload, 1000); '; - $html .= ' } '; - $html .= '}); '; - $html .= '}; '; - $html .= 'setTimeout(perform_upload, 1000); '; - - return $html; + return Template::get('display/import/with_plugin')->render([ + 'upload_id' => $uploadId, + 'pma_theme_image' => $GLOBALS['pmaThemeImage'], + ]); } /** * Gets HTML to display import dialogs * - * @param String $import_type Import type: server|database|table - * @param String $db Selected DB - * @param String $table Selected Table + * @param string $import_type Import type: server|database|table + * @param string $db Selected DB + * @param string $table Selected Table * @param int $max_upload_size Max upload size * * @return string $html diff --git a/libraries/classes/Twig/UrlExtension.php b/libraries/classes/Twig/UrlExtension.php index 842114686f..ef9d81efcd 100644 --- a/libraries/classes/Twig/UrlExtension.php +++ b/libraries/classes/Twig/UrlExtension.php @@ -40,6 +40,11 @@ class UrlExtension extends Twig_Extension 'PhpMyAdmin\Url::getCommon', array('is_safe' => array('html')) ), + new Twig_SimpleFunction( + 'Url_getCommonRaw', + 'PhpMyAdmin\Url::getCommonRaw', + array('is_safe' => array('html')) + ), new Twig_SimpleFunction( 'Url_link', 'PhpMyAdmin\Core::linkURL' diff --git a/templates/display/import/with_plugin.twig b/templates/display/import/with_plugin.twig new file mode 100644 index 0000000000..b3a3180987 --- /dev/null +++ b/templates/display/import/with_plugin.twig @@ -0,0 +1,148 @@ +{# Some variable for javascript #} +{% set ajax_url = 'import_status.php?id=' ~ upload_id ~ '&' ~ Url_getCommonRaw({ + 'import_status': 1 +}) %} +{% set promot_str = Sanitize_jsFormat( + 'The file being uploaded is probably larger than the maximum allowed size or this is a known bug in webkit based (Safari, Google Chrome, Arora etc.) browsers.'|trans, + false +) %} +{% set statustext_str = Sanitize_escapeJsString('%s of %s'|trans) %} +{% set second_str = Sanitize_jsFormat('%s/sec.'|trans, false) %} +{% set remaining_min = Sanitize_jsFormat('About %MIN min. %SEC sec. remaining.'|trans, false) %} +{% set remaining_second = Sanitize_jsFormat('About %SEC sec. remaining.'|trans, false) %} +{% set processed_str = Sanitize_jsFormat( + 'The file is being processed, please be patient.'|trans, + false +) %} +{% set import_url = Url_getCommonRaw({'import_status': 1}) %} + +{% set upload_html %} + {% spaceless %} +
+
+
+
+
+
+
+
+ ajax clock {{ Sanitize_jsFormat('Uploading your import file…'|trans, false) -}} +
+
+
+ {% endspaceless %} +{% endset %} + +{# Start output #} +var finished = false; +var percent = 0.0; +var total = 0; +var complete = 0; +var original_title = parent && parent.document ? parent.document.title : false; +var import_start; + +var perform_upload = function () { +new $.getJSON( + "{{ ajax_url|raw }}", + {}, + function(response) { + finished = response.finished; + percent = response.percent; + total = response.total; + complete = response.complete; + + if (total==0 && complete==0 && percent==0) { + $("#upload_form_status_info").html('ajax clock {{ promot_str|raw }}'); + $("#upload_form_status").css("display", "none"); + } else { + var now = new Date(); + now = Date.UTC( + now.getFullYear(), + now.getMonth(), + now.getDate(), + now.getHours(), + now.getMinutes(), + now.getSeconds()) + + now.getMilliseconds() - 1000; + var statustext = PMA_sprintf( + "{{ statustext_str|raw }}", + formatBytes( + complete, 1, PMA_messages.strDecimalSeparator + ), + formatBytes( + total, 1, PMA_messages.strDecimalSeparator + ) + ); + + if ($("#importmain").is(":visible")) { + {# Show progress UI #} + $("#importmain").hide(); + $("#import_form_status") + .html('{{ upload_html|raw }}') + .show(); + import_start = now; + } + else if (percent > 9 || complete > 2000000) { + {# Calculate estimated time #} + var used_time = now - import_start; + var seconds = parseInt(((total - complete) / complete) * used_time / 1000); + var speed = PMA_sprintf( + "{{ second_str|raw }}", + formatBytes(complete / used_time * 1000, 1, PMA_messages.strDecimalSeparator) + ); + + var minutes = parseInt(seconds / 60); + seconds %= 60; + var estimated_time; + if (minutes > 0) { + estimated_time = "{{ remaining_min|raw }}" + .replace("%MIN", minutes) + .replace("%SEC", seconds); + } + else { + estimated_time = "{{ remaining_second|raw }}" + .replace("%SEC", seconds); + } + + statustext += "
" + speed + "

" + estimated_time; + } + + var percent_str = Math.round(percent) + "%"; + $("#status").animate({width: percent_str}, 150); + $(".percentage").text(percent_str); + + {# Show percent in window title #} + if (original_title !== false) { + parent.document.title + = percent_str + " - " + original_title; + } + else { + document.title + = percent_str + " - " + original_title; + } + $("#statustext").html(statustext); + } + + if (finished == true) { + if (original_title !== false) { + parent.document.title = original_title; + } + else { + document.title = original_title; + } + $("#importmain").hide(); + {# Loads the message, either success or mysql error #} + $("#import_form_status") + .html('ajax clock {{ processed_str|raw }}') + .show(); + $("#import_form_status").load("import_status.php?message=true&{{ import_url|raw }}"); + PMA_reloadNavigation(); + + {# If finished #} + } + else { + setTimeout(perform_upload, 1000); + } + }); +}; +setTimeout(perform_upload, 1000); From 0d2e214c58328e5796d6583fd7d0e7437ba7506c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 19:57:31 -0200 Subject: [PATCH 05/21] Remove getHtmlForImportWithPlugin method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportWithPlugin method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index fc7dd11bb6..f987d255b2 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -67,7 +67,10 @@ class Import if ($_SESSION[$SESSION_KEY]["handler"] != 'PhpMyAdmin\Plugins\Import\Upload\UploadNoplugin') { - $html .= self::getHtmlForImportWithPlugin($upload_id); + $html .= Template::get('display/import/with_plugin')->render([ + 'upload_id' => $uploadId, + 'pma_theme_image' => $GLOBALS['pmaThemeImage'], + ]); } else { // no plugin available $image_tag = ''; - $html .= ' //render([ - 'upload_id' => $uploadId, - 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - ]); - - } else { // no plugin available - $image_tag = 'ajax clock ' - . Sanitize::jsFormat( - __( - 'Please be patient, the file is being uploaded. ' - . 'Details about the upload are not available.' - ), - false - ) . Util::showDocu('faq', 'faq2-9'); - $html .= " $('#upload_form_status_info').html('" . $image_tag . "');"; - $html .= ' $("#upload_form_status").css("display", "none");'; - } // else - - // onclick - $html .= ' });'; - // domready - $html .= ' });'; - $html .= ' //]]>'; - //with "\n", so that the following lines won't be commented out by //]]> - $html .= "\n"; - $html .= ''; - - return $html; + return Template::get('display/import/javascript')->render([ + 'upload_id' => $uploadId, + 'handler' => $_SESSION[$SESSION_KEY]["handler"], + 'pma_theme_image' => $GLOBALS['pmaThemeImage'], + ]); } /** diff --git a/templates/display/import/javascript.twig b/templates/display/import/javascript.twig new file mode 100644 index 0000000000..76474c1a6f --- /dev/null +++ b/templates/display/import/javascript.twig @@ -0,0 +1,31 @@ + From aeef8e54180567915960c022d81b93875dfea0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 23 Nov 2017 22:02:51 -0200 Subject: [PATCH 07/21] Use template for getHtmlForImportCompressions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 22 ++++------------------ templates/display/import/compressions.twig | 10 ++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 templates/display/import/compressions.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index f53d730b54..3eb6231541 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -88,10 +88,9 @@ class Import public static function getHtmlForImportCompressions() { global $cfg; - $html = ''; + // zip, gzip and bzip2 encode features $compressions = array(); - if ($cfg['GZipDump'] && @function_exists('gzopen')) { $compressions[] = 'gzip'; } @@ -101,23 +100,10 @@ class Import if ($cfg['ZipDump'] && @function_exists('zip_open')) { $compressions[] = 'zip'; } - // We don't have show anything about compression, when no supported - if ($compressions != array()) { - $html .= '
'; - $compress_str = sprintf( - __('File may be compressed (%s) or uncompressed.'), - implode(", ", $compressions) - ); - $html .= $compress_str; - $html .= '
'; - $html .= __( - 'A compressed file\'s name must end in .[format].[compression]. ' - . 'Example: .sql.zip' - ); - $html .= '
'; - } - return $html; + return Template::get('display/import/compressions')->render([ + 'compressions' => $compressions, + ]); } /** diff --git a/templates/display/import/compressions.twig b/templates/display/import/compressions.twig new file mode 100644 index 0000000000..e3834299bc --- /dev/null +++ b/templates/display/import/compressions.twig @@ -0,0 +1,10 @@ +{# We don't have show anything about compression, when no supported #} +{% if compressions is not empty %} +
+

+ {{ 'File may be compressed (%s) or uncompressed.'|trans|format(compressions|join(', ')) }} +
+ {% trans 'A compressed file\'s name must end in .[format].[compression]. Example: .sql.zip' %} +

+
+{% endif %} From ef7936af09b6b0d95f688c75f1c7a35af619d7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 24 Nov 2017 00:13:22 -0200 Subject: [PATCH 08/21] Use template for getHtmlForImportCharset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 38 ++++---------------- libraries/classes/Twig/CharsetsExtension.php | 5 +++ templates/display/import/charset.twig | 26 ++++++++++++++ 3 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 templates/display/import/charset.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 3eb6231541..d8aab1f80e 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -114,38 +114,14 @@ class Import public static function getHtmlForImportCharset() { global $cfg; - $html = '
'; - // charset of file - if (Encoding::isSupported()) { - $html .= ''; - $html .= '
'; - } else { - $html .= '' . "\n"; - $html .= Charsets::getCharsetDropdownBox( - $GLOBALS['dbi'], - $GLOBALS['cfg']['Server']['DisableIS'], - 'charset_of_file', - 'charset_of_file', - 'utf8', - false - ); - } // end if (recoding) - $html .= '
'; - - 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'], + ]); } /** diff --git a/libraries/classes/Twig/CharsetsExtension.php b/libraries/classes/Twig/CharsetsExtension.php index fd61b0cf1a..c36beb10ba 100644 --- a/libraries/classes/Twig/CharsetsExtension.php +++ b/libraries/classes/Twig/CharsetsExtension.php @@ -29,6 +29,11 @@ class CharsetsExtension extends Twig_Extension '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', diff --git a/templates/display/import/charset.twig b/templates/display/import/charset.twig new file mode 100644 index 0000000000..8f2d3b0c1c --- /dev/null +++ b/templates/display/import/charset.twig @@ -0,0 +1,26 @@ +
+ {# Charset of file #} + + {% if is_encoding_supported %} + + {% else %} + {{ Charsets_getCharsetDropdownBox( + dbi, + disable_is, + 'charset_of_file', + 'charset_of_file', + 'utf8', + false + ) }} + {% endif %} +
From 96a1f01a624dba0447d6048d26043a2cc8ea9a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 00:10:01 -0200 Subject: [PATCH 09/21] Remove getHtmlForHiddenInputs method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForHiddenInputs method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index d8aab1f80e..a96729a214 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -26,24 +26,6 @@ use PhpMyAdmin\Util; */ class Import { - /** - * Prints Html For Display Import Hidden Input - * - * @param String $importType Import type: server, database, table - * @param String $db Selected DB - * @param String $table Selected Table - * - * @return string - */ - public static function getHtmlForHiddenInputs($importType, $db, $table) - { - return Template::get('display/import/hidden_inputs')->render([ - 'import_type' => $importType, - 'db' => $db, - 'table' => $table, - ]); - } - /** * Prints Html For Import Javascript * @@ -280,7 +262,11 @@ class Import $html .= $_SESSION[$SESSION_KEY]['handler']::getIdKey(); $html .= '" value="' . $upload_id . '" />'; - $html .= self::getHtmlForHiddenInputs($import_type, $db, $table); + $html .= Template::get('display/import/hidden_inputs')->render([ + 'import_type' => $import_type, + 'db' => $db, + 'table' => $table, + ]); $html .= self::getHtmlForImportOptions($import_type, $db, $table); From 3d688660afb927d1c273e966a865969978b11eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 00:12:08 -0200 Subject: [PATCH 10/21] Remove getHtmlForImportJs method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportJs method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index a96729a214..df1bd7886f 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -26,24 +26,6 @@ use PhpMyAdmin\Util; */ class Import { - /** - * Prints Html For Import Javascript - * - * @param int $uploadId The selected upload id - * - * @return string - */ - public static function getHtmlForImportJs($uploadId) - { - global $SESSION_KEY; - - return Template::get('display/import/javascript')->render([ - 'upload_id' => $uploadId, - 'handler' => $_SESSION[$SESSION_KEY]["handler"], - 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - ]); - } - /** * Prints Html For Display Export options * @@ -248,7 +230,11 @@ class Import $html .= ' ajax clock'; - $html .= self::getHtmlForImportJs($upload_id); + $html .= Template::get('display/import/javascript')->render([ + 'upload_id' => $upload_id, + 'handler' => $_SESSION[$SESSION_KEY]["handler"], + 'pma_theme_image' => $GLOBALS['pmaThemeImage'], + ]); $html .= '
Date: Sat, 25 Nov 2017 00:13:41 -0200 Subject: [PATCH 11/21] Remove getHtmlForImportCompressions method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportCompressions method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 43 +++++++++++----------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index df1bd7886f..52dc191b63 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -44,32 +44,6 @@ class Import ]); } - /** - * Prints Html For Display Import options : Compressions - * - * @return string - */ - public static function getHtmlForImportCompressions() - { - global $cfg; - - // zip, gzip and bzip2 encode features - $compressions = array(); - if ($cfg['GZipDump'] && @function_exists('gzopen')) { - $compressions[] = 'gzip'; - } - if ($cfg['BZipDump'] && @function_exists('bzopen')) { - $compressions[] = 'bzip2'; - } - if ($cfg['ZipDump'] && @function_exists('zip_open')) { - $compressions[] = 'zip'; - } - - return Template::get('display/import/compressions')->render([ - 'compressions' => $compressions, - ]); - } - /** * Prints Html For Display Import charset * @@ -101,9 +75,24 @@ class Import $max_upload_size, $import_list, $local_import_file ) { global $cfg; + + // zip, gzip and bzip2 encode features + $compressions = array(); + if ($cfg['GZipDump'] && @function_exists('gzopen')) { + $compressions[] = 'gzip'; + } + if ($cfg['BZipDump'] && @function_exists('bzopen')) { + $compressions[] = 'bzip2'; + } + if ($cfg['ZipDump'] && @function_exists('zip_open')) { + $compressions[] = 'zip'; + } + $html = '
'; $html .= '

' . __('File to import:') . '

'; - $html .= self::getHtmlForImportCompressions(); + $html .= Template::get('display/import/compressions')->render([ + 'compressions' => $compressions, + ]); $html .= '
'; if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { From 1c4390205cb597000850d95c953ab72490481f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 00:16:33 -0200 Subject: [PATCH 12/21] Remove getHtmlForImportOptions method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptions method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 52dc191b63..94ade4a5c3 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -26,24 +26,6 @@ use PhpMyAdmin\Util; */ class Import { - /** - * Prints Html For Display Export options - * - * @param String $importType Import type: server, database, table - * @param String $db Selected DB - * @param String $table Selected Table - * - * @return string - */ - public static function getHtmlForImportOptions($importType, $db, $table) - { - return Template::get('display/import/options')->render([ - 'import_type' => $importType, - 'db' => $db, - 'table' => $table, - ]); - } - /** * Prints Html For Display Import charset * @@ -243,7 +225,11 @@ class Import 'table' => $table, ]); - $html .= self::getHtmlForImportOptions($import_type, $db, $table); + $html .= Template::get('display/import/options')->render([ + 'import_type' => $import_type, + 'db' => $db, + 'table' => $table, + ]); $html .= self::getHtmlForImportOptionsFile( $max_upload_size, $import_list, $local_import_file From 8502c2ad479b0b7894623a988ecdb6e2bb9e4e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 00:21:38 -0200 Subject: [PATCH 13/21] Remove getHtmlForImportCharset method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportCharset method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 94ade4a5c3..9b0555688c 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -26,24 +26,6 @@ use PhpMyAdmin\Util; */ class Import { - /** - * Prints Html For Display Import charset - * - * @return string - */ - public static function getHtmlForImportCharset() - { - global $cfg; - - 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'], - ]); - } - /** * Prints Html For Display Import options : file property * @@ -116,7 +98,13 @@ class Import } // end if (web-server upload directory) $html .= '
'; - $html .= self::getHtmlForImportCharset(); + $html .= 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'], + ]); $html .= '
'; return $html; From 8f12613b7b7398abd5792fa8ad0b2fb7bd39ec29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 00:29:54 -0200 Subject: [PATCH 14/21] Remove getHtmlForImportOptionsPartialImport method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptionsPartialImport method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 9b0555688c..d5c5f4e0a9 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -110,22 +110,6 @@ class Import return $html; } - /** - * Prints Html For Display Import options : Partial Import - * - * @param String $timeout_passed timeout passed - * @param String $offset timeout offset - * - * @return string - */ - public static function getHtmlForImportOptionsPartialImport($timeout_passed, $offset) - { - return Template::get('display/import/partial_import_option')->render([ - 'timeout_passed' => isset($timeout_passed) ? $timeout_passed : null, - 'offset' => $offset, - ]); - } - /** * Prints Html For Display Import options : Other * @@ -223,7 +207,10 @@ class Import $max_upload_size, $import_list, $local_import_file ); - $html .= self::getHtmlForImportOptionsPartialImport($timeout_passed, $offset); + $html .= Template::get('display/import/partial_import_option')->render([ + 'timeout_passed' => isset($timeout_passed) ? $timeout_passed : null, + 'offset' => $offset, + ]); $html .= self::getHtmlForImportOptionsOther(); From 4ef1e098d28404865bcdbeda12a365f377b5480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 01:57:12 -0200 Subject: [PATCH 15/21] Remove getHtmlForImportOptionsOther method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptionsOther method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index d5c5f4e0a9..31ed26456b 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -110,16 +110,6 @@ class Import return $html; } - /** - * Prints Html For Display Import options : Other - * - * @return string - */ - public static function getHtmlForImportOptionsOther() - { - return Template::get('display/import/other_option')->render(); - } - /** * Prints Html For Display Import options : Format * @@ -212,7 +202,7 @@ class Import 'offset' => $offset, ]); - $html .= self::getHtmlForImportOptionsOther(); + $html .= Template::get('display/import/other_option')->render(); $html .= self::getHtmlForImportOptionsFormat($import_list); From 4ea6e68b37ad8c82cfef8a9c4136dc3c84649cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 01:59:34 -0200 Subject: [PATCH 16/21] Remove getHtmlForImportOptionsFormat method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptionsFormat method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 31ed26456b..7713f07e6a 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -110,21 +110,6 @@ class Import return $html; } - /** - * Prints Html For Display Import options : Format - * - * @param ImportPlugin[] $importList import list - * - * @return string - */ - public static function getHtmlForImportOptionsFormat($importList) - { - return Template::get('display/import/format_option')->render([ - 'import_list' => $importList, - 'can_convert_kanji' => Encoding::canConvertKanji(), - ]); - } - /** * Prints Html For Display Import options : submit * @@ -204,7 +189,10 @@ class Import $html .= Template::get('display/import/other_option')->render(); - $html .= self::getHtmlForImportOptionsFormat($import_list); + $html .= Template::get('display/import/format_option')->render([ + 'import_list' => $import_list, + 'can_convert_kanji' => Encoding::canConvertKanji(), + ]); $html .= self::getHtmlForImportOptionsSubmit(); From db607e7fa8eb29b9a06ce9da0583c32341cff53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 02:01:30 -0200 Subject: [PATCH 17/21] Remove getHtmlForImportOptionsSubmit method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptionsSubmit method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 7713f07e6a..776b934cab 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -110,16 +110,6 @@ class Import return $html; } - /** - * Prints Html For Display Import options : submit - * - * @return string - */ - public static function getHtmlForImportOptionsSubmit() - { - return Template::get('display/import/submit_option')->render(); - } - /** * Prints Html For Display Import * @@ -194,7 +184,7 @@ class Import 'can_convert_kanji' => Encoding::canConvertKanji(), ]); - $html .= self::getHtmlForImportOptionsSubmit(); + $html .= Template::get('display/import/submit_option')->render(); $html .= ''; $html .= ''; From 7e81e5e09e1c9a65eb93bbfd7ead1ab5d78591a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 15:53:50 -0200 Subject: [PATCH 18/21] Use template for getHtmlForImportOptionsFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 58 ++++------------------- libraries/classes/Twig/UtilExtension.php | 10 ++++ templates/display/import/file_option.twig | 44 +++++++++++++++++ 3 files changed, 62 insertions(+), 50 deletions(-) create mode 100644 templates/display/import/file_option.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 776b934cab..0e67f2e318 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -52,62 +52,20 @@ class Import $compressions[] = 'zip'; } - $html = '
'; - $html .= '

' . __('File to import:') . '

'; - $html .= Template::get('display/import/compressions')->render([ + return Template::get('display/import/file_option')->render([ + 'max_upload_size' => $max_upload_size, + 'import_list' => $import_list, + 'local_import_file' => $local_import_file, + 'is_upload' => $GLOBALS['is_upload'], + 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null, + 'timeout_passed' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, 'compressions' => $compressions, - ]); - $html .= '
'; - - if ($GLOBALS['is_upload'] && !empty($cfg['UploadDir'])) { - $html .= '
    '; - $html .= '
  • '; - $html .= ' '; - $html .= Util::getBrowseUploadFileBlock($max_upload_size); - $html .= '
    ' . __('You may also drag and drop a file on any page.'); - $html .= '
  • '; - $html .= '
  • '; - $html .= ' getDisplay(); - } elseif (!empty($cfg['UploadDir'])) { - $html .= Util::getSelectUploadFileBlock( - $import_list, - $cfg['UploadDir'] - ); - } // end if (web-server upload directory) - - $html .= '
'; - $html .= 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'], + 'disable_is' => $cfg['Server']['DisableIS'], ]); - $html .= '
'; - - return $html; } /** diff --git a/libraries/classes/Twig/UtilExtension.php b/libraries/classes/Twig/UtilExtension.php index 26007fba63..ecf4909f26 100644 --- a/libraries/classes/Twig/UtilExtension.php +++ b/libraries/classes/Twig/UtilExtension.php @@ -29,6 +29,11 @@ class UtilExtension extends Twig_Extension 'Util_backquote', 'PhpMyAdmin\Util::backquote' ), + new Twig_SimpleFunction( + 'Util_getBrowseUploadFileBlock', + 'PhpMyAdmin\Util::getBrowseUploadFileBlock', + array('is_safe' => array('html')) + ), new Twig_SimpleFunction( 'Util_convertBitDefaultValue', 'PhpMyAdmin\Util::convertBitDefaultValue' @@ -122,6 +127,11 @@ class UtilExtension extends Twig_Extension 'PhpMyAdmin\Util::getRadioFields', array('is_safe' => array('html')) ), + new Twig_SimpleFunction( + 'Util_getSelectUploadFileBlock', + 'PhpMyAdmin\Util::getSelectUploadFileBlock', + array('is_safe' => array('html')) + ), new Twig_SimpleFunction( 'Util_getScriptNameForOption', 'PhpMyAdmin\Util::getScriptNameForOption', diff --git a/templates/display/import/file_option.twig b/templates/display/import/file_option.twig new file mode 100644 index 0000000000..e187d0313e --- /dev/null +++ b/templates/display/import/file_option.twig @@ -0,0 +1,44 @@ +
+

{% trans 'File to import:' %}

+ {% include 'display/import/compressions.twig' with { + 'compressions': compressions + } only %} +
+ {% if is_upload and upload_dir is not empty %} +
    +
  • + + {{ Util_getBrowseUploadFileBlock(max_upload_size) }} + {% trans 'You may also drag and drop a file on any page.' %} +
  • +
  • + + {{ Util_getSelectUploadFileBlock( + import_list, + upload_dir + ) }} +
  • +
+ {% elseif is_upload %} + {{ Util_getBrowseUploadFileBlock(max_upload_size) }} +

{% trans 'You may also drag and drop a file on any page.' %}

+ {% elseif not is_upload %} + {{ Message_notice('File uploads are not allowed on this server.'|trans) }} + {% elseif upload_dir is not empty %} + {{ Util_getSelectUploadFileBlock( + import_list, + upload_dir + ) }} + {% endif %} +
+ {% include 'display/import/charset.twig' with { + 'is_encoding_supported': is_encoding_supported, + 'encodings': encodings, + 'import_charset': import_charset, + 'dbi': dbi, + 'disable_is': disable_is + } only %} +
From ec3591fe60a92139dc6c0cd2a1f962de04fdec0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 16:44:44 -0200 Subject: [PATCH 19/21] Remove getHtmlForImportOptionsFile method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace getHtmlForImportOptionsFile method with the template call. Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 73 +++++++++++----------------- 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 0e67f2e318..190912b2de 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -26,48 +26,6 @@ use PhpMyAdmin\Util; */ class Import { - /** - * Prints Html For Display Import options : file property - * - * @param int $max_upload_size Max upload size - * @param ImportPlugin[] $import_list import list - * @param String $local_import_file from upload directory - * - * @return string - */ - public static function getHtmlForImportOptionsFile( - $max_upload_size, $import_list, $local_import_file - ) { - global $cfg; - - // zip, gzip and bzip2 encode features - $compressions = array(); - if ($cfg['GZipDump'] && @function_exists('gzopen')) { - $compressions[] = 'gzip'; - } - if ($cfg['BZipDump'] && @function_exists('bzopen')) { - $compressions[] = 'bzip2'; - } - if ($cfg['ZipDump'] && @function_exists('zip_open')) { - $compressions[] = 'zip'; - } - - return Template::get('display/import/file_option')->render([ - 'max_upload_size' => $max_upload_size, - 'import_list' => $import_list, - 'local_import_file' => $local_import_file, - 'is_upload' => $GLOBALS['is_upload'], - 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null, - 'timeout_passed' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, - 'compressions' => $compressions, - 'is_encoding_supported' => Encoding::isSupported(), - 'encodings' => Encoding::listEncodings(), - 'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null, - 'dbi' => $GLOBALS['dbi'], - 'disable_is' => $cfg['Server']['DisableIS'], - ]); - } - /** * Prints Html For Display Import * @@ -88,6 +46,20 @@ class Import $max_upload_size, $import_list, $timeout_passed, $offset, $local_import_file ) { global $SESSION_KEY; + global $cfg; + + // zip, gzip and bzip2 encode features + $compressions = array(); + if ($cfg['GZipDump'] && @function_exists('gzopen')) { + $compressions[] = 'gzip'; + } + if ($cfg['BZipDump'] && @function_exists('bzopen')) { + $compressions[] = 'bzip2'; + } + if ($cfg['ZipDump'] && @function_exists('zip_open')) { + $compressions[] = 'zip'; + } + $html = ''; $html .= ''; @@ -126,9 +98,20 @@ class Import 'table' => $table, ]); - $html .= self::getHtmlForImportOptionsFile( - $max_upload_size, $import_list, $local_import_file - ); + $html .= Template::get('display/import/file_option')->render([ + 'max_upload_size' => $max_upload_size, + 'import_list' => $import_list, + 'local_import_file' => $local_import_file, + 'is_upload' => $GLOBALS['is_upload'], + 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null, + 'timeout_passed' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, + 'compressions' => $compressions, + 'is_encoding_supported' => Encoding::isSupported(), + 'encodings' => Encoding::listEncodings(), + 'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null, + 'dbi' => $GLOBALS['dbi'], + 'disable_is' => $cfg['Server']['DisableIS'], + ]); $html .= Template::get('display/import/partial_import_option')->render([ 'timeout_passed' => isset($timeout_passed) ? $timeout_passed : null, From 4b51f335de4bbe1e33e7a136ebecf71e2e759cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 17:36:15 -0200 Subject: [PATCH 20/21] Use template for getHtmlForImport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- libraries/classes/Display/Import.php | 52 ++---------------- templates/display/import/file_option.twig | 2 +- templates/display/import/import.twig | 64 +++++++++++++++++++++++ templates/display/import/javascript.twig | 2 +- 4 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 templates/display/import/import.twig diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 190912b2de..062eb30dbb 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -60,77 +60,31 @@ class Import $compressions[] = 'zip'; } - $html = ''; - $html .= ''; - $html .= '
'; - $html .= '
'; - $html .= ' ajax clock'; - - $html .= Template::get('display/import/javascript')->render([ + return Template::get('display/import/import')->render([ 'upload_id' => $upload_id, 'handler' => $_SESSION[$SESSION_KEY]["handler"], + 'id_key' => $_SESSION[$SESSION_KEY]['handler']::getIdKey(), 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - ]); - - $html .= '
'; - - $html .= Template::get('display/import/hidden_inputs')->render([ 'import_type' => $import_type, 'db' => $db, 'table' => $table, - ]); - - $html .= Template::get('display/import/options')->render([ - 'import_type' => $import_type, - 'db' => $db, - 'table' => $table, - ]); - - $html .= Template::get('display/import/file_option')->render([ 'max_upload_size' => $max_upload_size, 'import_list' => $import_list, 'local_import_file' => $local_import_file, 'is_upload' => $GLOBALS['is_upload'], 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null, - 'timeout_passed' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, + 'timeout_passed_global' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, 'compressions' => $compressions, 'is_encoding_supported' => Encoding::isSupported(), 'encodings' => Encoding::listEncodings(), 'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null, 'dbi' => $GLOBALS['dbi'], 'disable_is' => $cfg['Server']['DisableIS'], - ]); - - $html .= Template::get('display/import/partial_import_option')->render([ 'timeout_passed' => isset($timeout_passed) ? $timeout_passed : null, 'offset' => $offset, - ]); - - $html .= Template::get('display/import/other_option')->render(); - - $html .= Template::get('display/import/format_option')->render([ 'import_list' => $import_list, 'can_convert_kanji' => Encoding::canConvertKanji(), ]); - - $html .= Template::get('display/import/submit_option')->render(); - - $html .= '
'; - $html .= '
'; - - return $html; } /** diff --git a/templates/display/import/file_option.twig b/templates/display/import/file_option.twig index e187d0313e..ca5d68a7b0 100644 --- a/templates/display/import/file_option.twig +++ b/templates/display/import/file_option.twig @@ -13,7 +13,7 @@
  • {{ Util_getSelectUploadFileBlock( diff --git a/templates/display/import/import.twig b/templates/display/import/import.twig new file mode 100644 index 0000000000..2c2dc13deb --- /dev/null +++ b/templates/display/import/import.twig @@ -0,0 +1,64 @@ + +
    +
    + ajax clock + + {% include 'display/import/javascript.twig' with { + 'upload_id': upload_id, + 'handler': handler, + 'pma_theme_image': pma_theme_image + } only %} + +
    + + + {% include 'display/import/hidden_inputs.twig' with { + 'import_type': import_type, + 'db': db, + 'table': table + } only %} + + {% include 'display/import/options.twig' with { + 'import_type': import_type, + 'db': db, + 'table': table + } only %} + + {% include 'display/import/file_option.twig' with { + 'max_upload_size': max_upload_size, + 'import_list': import_list, + 'local_import_file': local_import_file, + 'is_upload': is_upload, + 'upload_dir': upload_dir, + 'timeout_passed_global': timeout_passed_global, + 'compressions': compressions, + 'is_encoding_supported': is_encoding_supported, + 'encodings': encodings, + 'import_charset': import_charset, + 'dbi': dbi, + 'disable_is': disable_is + } only %} + + {% include 'display/import/partial_import_option.twig' with { + 'timeout_passed': timeout_passed, + 'offset': offset + } only %} + + {% include 'display/import/other_option.twig' only %} + + {% include 'display/import/format_option.twig' with { + 'import_list': import_list, + 'can_convert_kanji': can_convert_kanji + } only %} + + {% include 'display/import/submit_option.twig' only %} +
    +
    diff --git a/templates/display/import/javascript.twig b/templates/display/import/javascript.twig index 76474c1a6f..2e95ec1a1e 100644 --- a/templates/display/import/javascript.twig +++ b/templates/display/import/javascript.twig @@ -6,7 +6,7 @@ {# Hide form #} $("#upload_form_form").css("display", "none"); - {% if handler != 'PhpMyAdmin\Plugins\Import\Upload\UploadNoplugin' %} + {% if handler != 'PhpMyAdmin\\Plugins\\Import\\Upload\\UploadNoplugin' %} {% include 'display/import/with_plugin.twig' with { 'upload_id': upload_id, 'pma_theme_image': pma_theme_image From 73e558337c62521e207359b444ca76317d307e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 25 Nov 2017 18:20:19 -0200 Subject: [PATCH 21/21] Refactor PhpMyAdmin\Display\Import class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- db_import.php | 2 +- libraries/classes/Display/Import.php | 144 ++++++++++----------------- server_import.php | 2 +- tbl_import.php | 2 +- 4 files changed, 54 insertions(+), 96 deletions(-) diff --git a/db_import.php b/db_import.php index 21dfd1aa07..0ec1d49ef6 100644 --- a/db_import.php +++ b/db_import.php @@ -38,7 +38,7 @@ list( $response = Response::getInstance(); $response->addHTML( - Import::getImportDisplay( + Import::get( 'database', $db, $table, $max_upload_size ) ); diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index 062eb30dbb..c8171e234d 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -7,17 +7,12 @@ */ namespace PhpMyAdmin\Display; -use PhpMyAdmin\Charsets; use PhpMyAdmin\Core; use PhpMyAdmin\Display\ImportAjax; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins; -use PhpMyAdmin\Plugins\ImportPlugin; -use PhpMyAdmin\Sanitize; use PhpMyAdmin\Template; -use PhpMyAdmin\Url; -use PhpMyAdmin\Util; /** * PhpMyAdmin\Display\Import class @@ -27,26 +22,54 @@ use PhpMyAdmin\Util; class Import { /** - * Prints Html For Display Import + * Gets HTML to display import dialogs * - * @param int $upload_id The selected upload id - * @param String $import_type Import type: server, database, table - * @param String $db Selected DB - * @param String $table Selected Table - * @param int $max_upload_size Max upload size - * @param ImportPlugin[] $import_list Import list - * @param String $timeout_passed Timeout passed - * @param String $offset Timeout offset - * @param String $local_import_file from upload directory + * @param string $importType Import type: server|database|table + * @param string $db Selected DB + * @param string $table Selected Table + * @param int $maxUploadSize Max upload size * - * @return string + * @return string HTML */ - public static function getHtmlForImport( - $upload_id, $import_type, $db, $table, - $max_upload_size, $import_list, $timeout_passed, $offset, $local_import_file - ) { - global $SESSION_KEY; + public static function get($importType, $db, $table, $maxUploadSize) + { global $cfg; + global $SESSION_KEY; + + list( + $SESSION_KEY, + $uploadId, + ) = ImportAjax::uploadProgressSetup(); + + /* Scan for plugins */ + /* @var $importList \PhpMyAdmin\Plugins\ImportPlugin[] */ + $importList = Plugins::getPlugins( + "import", + 'libraries/classes/Plugins/Import/', + $importType + ); + + /* Fail if we didn't find any plugin */ + if (empty($importList)) { + Message::error( + __( + 'Could not load import plugins, please check your installation!' + ) + )->display(); + exit; + } + + if (Core::isValid($_REQUEST['offset'], 'numeric')) { + $offset = intval($_REQUEST['offset']); + } + if (isset($_REQUEST['timeout_passed'])) { + $timeoutPassed = $_REQUEST['timeout_passed']; + } + + $localImportFile = ''; + if (isset($_REQUEST['local_import_file'])) { + $localImportFile = $_REQUEST['local_import_file']; + } // zip, gzip and bzip2 encode features $compressions = array(); @@ -61,16 +84,16 @@ class Import } return Template::get('display/import/import')->render([ - 'upload_id' => $upload_id, + 'upload_id' => $uploadId, 'handler' => $_SESSION[$SESSION_KEY]["handler"], 'id_key' => $_SESSION[$SESSION_KEY]['handler']::getIdKey(), 'pma_theme_image' => $GLOBALS['pmaThemeImage'], - 'import_type' => $import_type, + 'import_type' => $importType, 'db' => $db, 'table' => $table, - 'max_upload_size' => $max_upload_size, - 'import_list' => $import_list, - 'local_import_file' => $local_import_file, + 'max_upload_size' => $maxUploadSize, + 'import_list' => $importList, + 'local_import_file' => $localImportFile, 'is_upload' => $GLOBALS['is_upload'], 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null, 'timeout_passed_global' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null, @@ -80,74 +103,9 @@ class Import 'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null, 'dbi' => $GLOBALS['dbi'], 'disable_is' => $cfg['Server']['DisableIS'], - 'timeout_passed' => isset($timeout_passed) ? $timeout_passed : null, - 'offset' => $offset, - 'import_list' => $import_list, + 'timeout_passed' => isset($timeoutPassed) ? $timeoutPassed : null, + 'offset' => isset($offset) ? $offset : null, 'can_convert_kanji' => Encoding::canConvertKanji(), ]); } - - /** - * Gets HTML to display import dialogs - * - * @param string $import_type Import type: server|database|table - * @param string $db Selected DB - * @param string $table Selected Table - * @param int $max_upload_size Max upload size - * - * @return string $html - */ - public static function getImportDisplay($import_type, $db, $table, $max_upload_size) - { - global $SESSION_KEY; - - list( - $SESSION_KEY, - $upload_id, - ) = ImportAjax::uploadProgressSetup(); - - /* Scan for plugins */ - /* @var $import_list ImportPlugin[] */ - $import_list = Plugins::getPlugins( - "import", - 'libraries/classes/Plugins/Import/', - $import_type - ); - - /* Fail if we didn't find any plugin */ - if (empty($import_list)) { - Message::error( - __( - 'Could not load import plugins, please check your installation!' - ) - )->display(); - exit; - } - - if (Core::isValid($_REQUEST['offset'], 'numeric')) { - $offset = intval($_REQUEST['offset']); - } - if (isset($_REQUEST['timeout_passed'])) { - $timeout_passed = $_REQUEST['timeout_passed']; - } - - $local_import_file = ''; - if (isset($_REQUEST['local_import_file'])) { - $local_import_file = $_REQUEST['local_import_file']; - } - - $timeout_passed_str = isset($timeout_passed)? $timeout_passed : null; - $offset_str = isset($offset)? $offset : null; - return self::getHtmlForImport( - $upload_id, - $import_type, - $db, - $table, - $max_upload_size, - $import_list, - $timeout_passed_str, - $offset_str, - $local_import_file - ); - } } diff --git a/server_import.php b/server_import.php index 6c419a2c18..25d7c172e0 100644 --- a/server_import.php +++ b/server_import.php @@ -28,7 +28,7 @@ require 'libraries/server_common.inc.php'; $response = Response::getInstance(); $response->addHTML( - Import::getImportDisplay( + Import::get( 'server', $db, $table, $max_upload_size ) ); diff --git a/tbl_import.php b/tbl_import.php index 9a5b908fbb..e52543037a 100644 --- a/tbl_import.php +++ b/tbl_import.php @@ -28,7 +28,7 @@ require_once 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_import.php&back=tbl_import.php'; $response->addHTML( - Import::getImportDisplay( + Import::get( 'table', $db, $table, $max_upload_size ) );