aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/controller
diff options
context:
space:
mode:
authorMate Bartus <mate.bartus@gmail.com>2015-07-22 03:16:16 +0200
committerMate Bartus <mate.bartus@gmail.com>2015-07-22 03:16:16 +0200
commit97d08d6f56cf448fd4def8a4d29c570da91faa89 (patch)
tree47bd1cdc55a71ab2e9f149b2dc59144316407273 /phpBB/phpbb/install/controller
parent11642a5f9481e4e25402833edb2bac903c23c627 (diff)
downloadforums-97d08d6f56cf448fd4def8a4d29c570da91faa89.tar
forums-97d08d6f56cf448fd4def8a4d29c570da91faa89.tar.gz
forums-97d08d6f56cf448fd4def8a4d29c570da91faa89.tar.bz2
forums-97d08d6f56cf448fd4def8a4d29c570da91faa89.tar.xz
forums-97d08d6f56cf448fd4def8a4d29c570da91faa89.zip
[ticket/13740] Allow language change in the installer
PHPBB3-13740
Diffstat (limited to 'phpBB/phpbb/install/controller')
-rw-r--r--phpBB/phpbb/install/controller/helper.php165
-rw-r--r--phpBB/phpbb/install/controller/install.php2
-rw-r--r--phpBB/phpbb/install/controller/installer_index.php2
3 files changed, 121 insertions, 48 deletions
diff --git a/phpBB/phpbb/install/controller/helper.php b/phpBB/phpbb/install/controller/helper.php
index 569938be09..5fd0abf9c7 100644
--- a/phpBB/phpbb/install/controller/helper.php
+++ b/phpBB/phpbb/install/controller/helper.php
@@ -17,10 +17,13 @@ use phpbb\install\helper\navigation\navigation_provider;
use phpbb\language\language;
use phpbb\language\language_file_helper;
use phpbb\path_helper;
+use phpbb\request\request;
+use phpbb\request\request_interface;
use phpbb\routing\router;
use phpbb\symfony_request;
use phpbb\template\template;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\Cookie;
/**
* A duplicate of \phpbb\controller\helper
@@ -36,6 +39,11 @@ class helper
protected $language;
/**
+ * @var bool|string
+ */
+ protected $language_cookie;
+
+ /**
* @var \phpbb\language\language_file_helper
*/
protected $lang_helper;
@@ -56,6 +64,11 @@ class helper
protected $path_helper;
/**
+ * @var \phpbb\request\request
+ */
+ protected $phpbb_request;
+
+ /**
* @var \phpbb\symfony_request
*/
protected $request;
@@ -83,49 +96,117 @@ class helper
* @param navigation_provider $nav
* @param template $template
* @param path_helper $path_helper
+ * @param request $phpbb_request
* @param symfony_request $request
* @param router $router
* @param string $phpbb_root_path
*/
- public function __construct(language $language, language_file_helper $lang_helper, navigation_provider $nav, template $template, path_helper $path_helper, symfony_request $request, router $router, $phpbb_root_path)
+ public function __construct(language $language, language_file_helper $lang_helper, navigation_provider $nav, template $template, path_helper $path_helper, request $phpbb_request, symfony_request $request, router $router, $phpbb_root_path)
{
$this->language = $language;
+ $this->language_cookie = false;
$this->lang_helper = $lang_helper;
$this->navigation_provider = $nav;
$this->template = $template;
$this->path_helper = $path_helper;
+ $this->phpbb_request = $phpbb_request;
$this->request = $request;
$this->router = $router;
$this->phpbb_root_path = $phpbb_root_path;
$this->phpbb_admin_path = $phpbb_root_path . 'adm/';
+
+ $this->handle_language_select();
}
/**
* Automate setting up the page and creating the response object.
*
- * @param string $template_file The template handle to render
- * @param string $page_title The title of the page to output
- * @param int $status_code The status code to be sent to the page header
+ * @param string $template_file The template handle to render
+ * @param string $page_title The title of the page to output
+ * @param bool $selected_language True to enable language selector it, false otherwise
+ * @param int $status_code The status code to be sent to the page header
*
* @return Response object containing rendered page
*/
- public function render($template_file, $page_title = '', $status_code = 200)
+ public function render($template_file, $page_title = '', $selected_language = false, $status_code = 200)
{
- $this->page_header($page_title);
+ $this->page_header($page_title, $selected_language);
$this->template->set_filenames(array(
'body' => $template_file,
));
- return new Response($this->template->assign_display('body'), $status_code);
+ $response = new Response($this->template->assign_display('body'), $status_code);
+
+ // Set language cookie
+ if ($this->language_cookie !== false)
+ {
+ $cookie = new Cookie('lang', $this->language_cookie, time() + 3600);
+ $response->headers->setCookie($cookie);
+
+ $this->language_cookie = false;
+ }
+
+ return $response;
+ }
+
+ /**
+ * Returns path from route name
+ *
+ * @param string $route_name
+ *
+ * @return string
+ */
+ public function route($route_name)
+ {
+ $url = $this->router->generate($route_name);
+
+ return $url;
+ }
+
+ /**
+ * Handles language selector form
+ */
+ protected function handle_language_select()
+ {
+ $lang = null;
+
+ // Check if language form has been submited
+ $submit = $this->phpbb_request->variable('change_lang', '');
+ if (!empty($submit))
+ {
+ $lang = $this->phpbb_request->variable('language', '');
+
+ if (!empty($lang))
+ {
+ $this->language_cookie = $lang;
+ }
+ }
+
+ // Retrive language from cookie
+ $lang_cookie = $this->phpbb_request->variable('lang', '', false, request_interface::COOKIE);
+ if (empty($lang) && !empty($lang_cookie))
+ {
+ $lang = $lang_cookie;
+ $this->language_cookie = $lang;
+ }
+
+ $lang = (!empty($lang)) ? $lang : null;
+ $this->render_language_select($lang);
+
+ if ($lang !== null)
+ {
+ $this->language->set_user_language($lang, true);
+ }
}
/**
* Set default template variables
*
- * @param string $page_title
+ * @param string $page_title Title of the page
+ * @param bool $selected_language True to enable language selector it, false otherwise
*/
- protected function page_header($page_title)
+ protected function page_header($page_title, $selected_language = false)
{
$this->template->assign_vars(array(
'L_CHANGE' => $this->language->lang('CHANGE'),
@@ -143,6 +224,7 @@ class helper
'S_CONTENT_FLOW_BEGIN' => ($this->language->lang('DIRECTION') === 'ltr') ? 'left' : 'right',
'S_CONTENT_FLOW_END' => ($this->language->lang('DIRECTION') === 'ltr') ? 'right' : 'left',
'S_CONTENT_ENCODING' => 'UTF-8',
+ 'S_LANG_SELECT' => $selected_language,
'S_USER_LANG' => $this->language->lang('USER_LANG'),
)
@@ -151,6 +233,8 @@ class helper
$this->render_navigation();
}
+
+
/**
* Render navigation
*/
@@ -163,35 +247,29 @@ class helper
$active_main_menu = $this->get_active_main_menu($nav_array);
// Pass navigation to template
- foreach ($nav_array as $key => $entry)
- {
+ foreach ($nav_array as $key => $entry) {
$this->template->assign_block_vars('t_block1', array(
- 'L_TITLE' => $this->language->lang($entry['label']),
- 'S_SELECTED' => ($active_main_menu === $key),
- 'U_TITLE' => $this->route($entry['route']),
+ 'L_TITLE' => $this->language->lang($entry['label']),
+ 'S_SELECTED' => ($active_main_menu === $key),
+ 'U_TITLE' => $this->route($entry['route']),
));
- if (is_array($entry[0]) && $active_main_menu === $key)
- {
+ if (is_array($entry[0]) && $active_main_menu === $key) {
$entry[0] = $this->sort_navigation_level($entry[0]);
- foreach ($entry[0] as $name => $sub_entry)
- {
- if (isset($sub_entry['stage']) && $sub_entry['stage'] === true)
- {
+ foreach ($entry[0] as $name => $sub_entry) {
+ if (isset($sub_entry['stage']) && $sub_entry['stage'] === true) {
$this->template->assign_block_vars('l_block2', array(
- 'L_TITLE' => $this->language->lang($sub_entry['label']),
- 'S_SELECTED' => (isset($sub_entry['selected']) && $sub_entry['selected'] === true),
- 'S_COMPLETE' => (isset($sub_entry['completed']) && $sub_entry['completed'] === true),
- 'STAGE_NAME' => $name,
+ 'L_TITLE' => $this->language->lang($sub_entry['label']),
+ 'S_SELECTED' => (isset($sub_entry['selected']) && $sub_entry['selected'] === true),
+ 'S_COMPLETE' => (isset($sub_entry['completed']) && $sub_entry['completed'] === true),
+ 'STAGE_NAME' => $name,
));
- }
- else
- {
+ } else {
$this->template->assign_block_vars('l_block1', array(
- 'L_TITLE' => $this->language->lang($sub_entry['label']),
- 'S_SELECTED' => (isset($sub_entry['route']) && $sub_entry['route'] === $this->request->get('_route')),
- 'U_TITLE' => $this->route($sub_entry['route']),
+ 'L_TITLE' => $this->language->lang($sub_entry['label']),
+ 'S_SELECTED' => (isset($sub_entry['route']) && $sub_entry['route'] === $this->request->get('_route')),
+ 'U_TITLE' => $this->route($sub_entry['route']),
));
}
}
@@ -200,26 +278,21 @@ class helper
}
/**
- * Returns path from route name
- *
- * @param string $route_name
- *
- * @return string
- */
- public function route($route_name)
- {
- $url = $this->router->generate($route_name);
-
- return $url;
- }
-
- /**
* Render language select form
+ *
+ * @param string $selected_language
*/
- protected function render_language_select()
+ protected function render_language_select($selected_language = null)
{
$langs = $this->lang_helper->get_available_languages();
- // @todo Implement language change option
+ foreach ($langs as $lang)
+ {
+ $this->template->assign_block_vars('language_select_item', array(
+ 'VALUE' => $lang['iso'],
+ 'NAME' => $lang['local_name'],
+ 'SELECTED' => ($lang['iso'] === $selected_language),
+ ));
+ }
}
/**
diff --git a/phpBB/phpbb/install/controller/install.php b/phpBB/phpbb/install/controller/install.php
index b3103c8284..da806948fb 100644
--- a/phpBB/phpbb/install/controller/install.php
+++ b/phpBB/phpbb/install/controller/install.php
@@ -189,7 +189,7 @@ class install
'TITLE' => $this->language->lang('INSTALL_INTRO'),
'CONTENT' => $this->language->lang('INSTALL_INTRO_BODY'),
));
- return $this->controller_helper->render('installer_install.html', 'INSTALL');
+ return $this->controller_helper->render('installer_install.html', 'INSTALL', true);
}
// @todo: implement no js controller logic
diff --git a/phpBB/phpbb/install/controller/installer_index.php b/phpBB/phpbb/install/controller/installer_index.php
index 3d5224f1be..0a1855f4e5 100644
--- a/phpBB/phpbb/install/controller/installer_index.php
+++ b/phpBB/phpbb/install/controller/installer_index.php
@@ -74,6 +74,6 @@ class installer_index
'BODY' => $body,
));
- return $this->helper->render('install_main.html', $title);
+ return $this->helper->render('install_main.html', $title, true);
}
}