diff --git a/libraries/classes/Twig/MessageExtension.php b/libraries/classes/Twig/MessageExtension.php index 0883b046d0..621f9f2637 100644 --- a/libraries/classes/Twig/MessageExtension.php +++ b/libraries/classes/Twig/MessageExtension.php @@ -42,6 +42,13 @@ class MessageExtension extends AbstractExtension }, ['is_safe' => ['html']] ), + new TwigFilter( + 'raw_success', + function ($string) { + return Message::rawSuccess($string)->getDisplay(); + }, + ['is_safe' => ['html']] + ), ]; } } diff --git a/libraries/classes/Twig/SanitizeExtension.php b/libraries/classes/Twig/SanitizeExtension.php index 2b68e77357..a95a5e15fa 100644 --- a/libraries/classes/Twig/SanitizeExtension.php +++ b/libraries/classes/Twig/SanitizeExtension.php @@ -11,6 +11,7 @@ namespace PhpMyAdmin\Twig; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; +use Twig\TwigFunction; /** * Class SanitizeExtension @@ -44,4 +45,20 @@ class SanitizeExtension extends AbstractExtension ), ]; } + + /** + * Returns a list of functions to add to the existing list. + * + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction( + 'get_js_value', + 'PhpMyAdmin\Sanitize::getJsValue', + ['is_safe' => ['html']] + ) + ]; + } } diff --git a/libraries/classes/Twig/UtilExtension.php b/libraries/classes/Twig/UtilExtension.php index ed105d1f3f..4693b84707 100644 --- a/libraries/classes/Twig/UtilExtension.php +++ b/libraries/classes/Twig/UtilExtension.php @@ -178,6 +178,11 @@ class UtilExtension extends AbstractExtension 'timespan_format', 'PhpMyAdmin\Util::timespanFormat' ), + new TwigFunction( + 'generate_hidden_max_file_size', + 'PhpMyAdmin\Util::generateHiddenMaxFileSize', + ['is_safe' => ['html']] + ), ]; } diff --git a/prefs_manage.php b/prefs_manage.php index 9f1ecb6d6d..a392694755 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -13,11 +13,9 @@ use PhpMyAdmin\Core; use PhpMyAdmin\File; use PhpMyAdmin\Message; use PhpMyAdmin\Response; -use PhpMyAdmin\Sanitize; use PhpMyAdmin\ThemeManager; -use PhpMyAdmin\Url; use PhpMyAdmin\UserPreferences; -use PhpMyAdmin\Util; +use PhpMyAdmin\Template; if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); @@ -28,6 +26,8 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; +$template = new Template(); + $userPreferences = new UserPreferences(); $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings); @@ -123,33 +123,13 @@ if (isset($_POST['submit_export']) if (! $all_ok) { // mimic original form and post json in a hidden field include ROOT_PATH . 'libraries/user_preferences.inc.php'; - $msg = Message::error( - __('Configuration contains incorrect data for some fields.') - ); - $msg->display(); - echo '
'; - echo $form_display->displayErrors(); - echo '
'; - echo '
'; - echo Url::getHiddenInputs() , "\n"; - echo ''; - echo ''; - if (! empty($_POST['import_merge'])) { - echo ''; - } - if ($return_url) { - echo ''; - } - echo '

'; - echo __('Do you want to import remaining settings?'); - echo '

'; - echo ''; - echo ''; - echo '
'; + + echo $template->render('prefs_manage_error', [ + 'form_errors' => $form_display->displayErrors(), + 'json' => $json, + 'import_merge' => isset($_POST['import_merge']) ? $_POST['import_merge'] : null, + 'return_url' => $return_url + ]); exit; } @@ -173,7 +153,7 @@ if (isset($_POST['submit_export']) $result = $userPreferences->save($cf->getConfigArray()); if ($result === true) { if ($return_url) { - $query = PhpMyAdmin\Util::splitURLQuery($return_url); + $query = PhpMyAdmin\Util::splitURLQuery($return_url); $return_url = parse_url($return_url, PHP_URL_PATH); foreach ($query as $q) { @@ -211,7 +191,7 @@ if (isset($_POST['submit_export']) $response = Response::getInstance(); $header = $response->getHeader(); -$scripts = $header->getScripts(); +$scripts = $header->getScripts(); $scripts->addFile('config.js'); require ROOT_PATH . 'libraries/user_preferences.inc.php'; @@ -219,168 +199,15 @@ if ($error) { if (! $error instanceof Message) { $error = Message::error($error); } - $error->display(); + $error->getDisplay(); } -?> - -
-
-
-' , __('Import') , '' - , '
' - , Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) - , Url::getHiddenInputs() - , '' - , '' - , '' - , '
' - , '' - , '' - , '
' - , '' - , '' - , '
' - , '
' - , __('Settings will be imported from your browser\'s local storage.') - , '
' - , '
' - , __('Saved on: @DATE@') - , '
' - , '
'; -Message::notice(__('You have no saved settings!'))->display(); -echo '
' - , '
' - , '
'; -Message::notice( - __('This feature is not supported by your web browser') -)->display(); -echo '
' - , '
' - , '' - , '' - , '

' - , '' - , '
' - , '
'; -if (@file_exists(ROOT_PATH . 'setup/index.php') && ! @file_exists(CONFIG_FILE)) { - // show only if setup script is available, allows to disable this message - // by simply removing setup directory - // Also do not show in config exists (and setup would refuse to work) - ?> -
-

-
- ', - '' - ) , PhpMyAdmin\Util::showDocu('setup', 'setup-script'); - ?> -
-
- -
-
-
-

-
- display(); - ?> -
-
- -
- -
- -
- - -
-
- - -
- - - -
-
-
- display(); - ?> -
-
-
- '; - ?> -
-
-
-

-
- -

- -
-
-
-
-
-render('prefs_manage', [ + 'error' => $error, + 'max_upload_size' => $GLOBALS['max_upload_size'], + 'exists_setup_and_not_exists_config' => @file_exists(ROOT_PATH . 'setup/index.php') && ! @file_exists(CONFIG_FILE), +]); + if ($response->isAjax()) { $response->addJSON('_disableNaviSettings', true); } else { diff --git a/templates/prefs_manage.twig b/templates/prefs_manage.twig new file mode 100644 index 0000000000..b5863abcc6 --- /dev/null +++ b/templates/prefs_manage.twig @@ -0,0 +1,112 @@ +{{ error|raw }} + +
+
+
+

{% trans 'Import' %}

+
+ {{ generate_hidden_max_file_size(max_upload_size) }} + {{ get_hidden_inputs() }} + + + +
+ + +
+ + +
+
+ {% trans 'Settings will be imported from your browser\'s local storage.' %} +
+
+ {% trans 'Saved on: @DATE@' %} +
+
+ {{ 'You have no saved settings!'|trans|notice }} +
+
+
+ {{ 'This feature is not supported by your web browser'|trans|notice }} +
+
+ + +

+ +
+
+ {% if exists_setup_and_not_exists_config %} + {# show only if setup script is available, allows to disable this message #} + {# by simply removing setup directory #} + {# Also do not show in config exists (and setup would refuse to work) #} +
+

{% trans 'More settings' %}

+
+ {{ 'You can set more settings by modifying config.inc.php, eg. by using %sSetup script%s.'|trans|format('','')|raw }} + {{ show_docu('setup', 'setup-script') }} +
+
+ {% endif %} +
+
+
+

{% trans 'Export' %}

+
+ {{ 'Configuration has been saved.'|trans|raw_success }} +
+
+ {{ get_hidden_inputs() }} +
+ +
+ +
+ + +
+
+ + {% trans 'Settings will be saved in your browser\'s local storage.' %} +
+ + {% trans 'Existing settings will be overwritten!' %} + +
+
+
+ {{ 'This feature is not supported by your web browser'|trans|notice }} +
+
+
+ +
+
+
+

{% trans 'Reset' %}

+
+ {{ get_hidden_inputs() }} + {% trans 'You can reset all your settings and restore them to default values.' %} +

+ +
+
+
+
+
diff --git a/templates/prefs_manage_error.twig b/templates/prefs_manage_error.twig new file mode 100644 index 0000000000..10c27078b2 --- /dev/null +++ b/templates/prefs_manage_error.twig @@ -0,0 +1,20 @@ +{{ 'Configuration contains incorrect data for some fields.'|trans|error }} +
+ {{ form_errors|raw }} +
+
+ {{ get_hidden_inputs() }} + + + {% if import_merge is not empty %} + + {% endif %} + {% if return_url %} + + {% endif %} +

+ {% trans 'Do you want to import remaining settings?' %} +

+ + +