From 05db5ecedb51f78137148a7d7027ad563f7cfebf Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 6 Nov 2013 11:35:27 +0100 Subject: [PATCH] Adding language support in the before login plugin see BT#6939 --- index.php | 7 ++++++- main/inc/lib/main_api.lib.php | 15 +++++++++++++++ plugin/before_login/index.php | 13 +++++++++++-- plugin/before_login/plugin.php | 9 +++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 7abe126d50..d8fa3bb8ff 100644 --- a/index.php +++ b/index.php @@ -137,11 +137,16 @@ if (api_get_setting('display_categories_on_homepage') == 'true') { if (api_is_facebook_auth_activated() && !api_get_user_id()) { facebook_connect(); } + +// before login plugin conditions $showLoginForm = true; if (api_is_anonymous()) { if (!isset($_SESSION['before_login_accepted'])) { if (in_array('before_login', $controller->tpl->plugin->get_installed_plugins())) { - $showLoginForm = false; + $languageToActivate = api_get_plugin_setting('before_login', 'language'); + if (api_get_interface_language() == $languageToActivate) { + $showLoginForm = false; + } } } } diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index d2f51b494b..60439566f0 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -3490,6 +3490,21 @@ function api_get_languages() { return $language_list; } +/** + * Returns a list of all the languages that are made available by the admin. + * @return array + */ +function api_get_languages_to_array() { + $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE); + $sql = "SELECT * FROM $tbl_language WHERE available='1' ORDER BY original_name ASC"; + $result = Database::query($sql); + $languages = array(); + while ($row = Database::fetch_array($result)) { + $languages[$row['dokeos_folder']] = $row['original_name']; + } + return $languages; +} + /** * Returns the id (the database id) of a language * @param string language name (the corresponding name of the language-folder in the filesystem) diff --git a/plugin/before_login/index.php b/plugin/before_login/index.php index 1f7289efec..08135015cf 100644 --- a/plugin/before_login/index.php +++ b/plugin/before_login/index.php @@ -7,16 +7,25 @@ if (api_is_anonymous()) { // Only available in the index.php page $loginAccepted = isset($_SESSION['before_login_accepted']) ? $_SESSION['before_login_accepted'] : null; - $currentPage = str_replace('index.php', '', $_SERVER['REQUEST_URI']); - //var_dump(api_get_path(REL_PATH), $currentPage); + $parsedUrl = parse_url($_SERVER['REQUEST_URI']); + $currentPage = str_replace('index.php', '', $parsedUrl['path']); + if (api_get_path(REL_PATH) !== $currentPage) { return null; } + // Hide only if the before_login_accepted session was set to ON. if ($loginAccepted) { return null; } + // Only available for the selected language. + $languageToActivate = api_get_plugin_setting('before_login', 'language'); + + if (api_get_interface_language() != $languageToActivate) { + return null; + } + $option1 = api_get_plugin_setting('before_login', 'option1'); $urlOption1 = api_get_plugin_setting('before_login', 'option1_url'); diff --git a/plugin/before_login/plugin.php b/plugin/before_login/plugin.php index 3619d946f3..e9d6ef2745 100644 --- a/plugin/before_login/plugin.php +++ b/plugin/before_login/plugin.php @@ -20,14 +20,15 @@ $plugin_info['author'] = 'Julio Montoya'; // The plugin configuration. $form = new FormValidator('form'); +$form->addElement('select', 'language', get_lang('Language'), api_get_languages_to_array()); $form->addElement('header', 'Option 1'); -$form->addElement('textarea', 'option1', 'Description'); -$form->addElement('text', 'option1_url', 'Redirect to'); +$form->addElement('textarea', 'option1', get_lang('Description')); +$form->addElement('text', 'option1_url', get_lang('RedirectTo')); $form->addElement('header', 'Option 2'); -$form->addElement('textarea', 'option2', 'Description'); -$form->addElement('text', 'option2_url', 'Redirect to'); +$form->addElement('textarea', 'option2', get_lang('Description')); +$form->addElement('text', 'option2_url', get_lang('RedirectTo')); $form->addElement('button', 'submit_button', get_lang('Save')); // Get default value for form