Adding language support in the before login plugin see BT#6939

1.9.x
Julio Montoya 12 years ago
parent e4f5b65026
commit 05db5ecedb
  1. 7
      index.php
  2. 15
      main/inc/lib/main_api.lib.php
  3. 13
      plugin/before_login/index.php
  4. 9
      plugin/before_login/plugin.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;
}
}
}
}

@ -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)

@ -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');

@ -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

Loading…
Cancel
Save