Issue #306 - Elimination of the function api_set_string_library_default_language(). Various logic improvements.

skala
Ivan Tcholakov 16 years ago
parent 699989fc4f
commit 3659ea7fd4
  1. 3
      main/inc/global.inc.php
  2. 12
      main/inc/lib/main_api.lib.php
  3. 45
      main/inc/lib/multibyte_string_functions.lib.php
  4. 24
      main/inc/lib/multibyte_string_functions_internal.lib.php
  5. 2
      main/install/index.php

@ -573,9 +573,6 @@ if ($_course['language'])
// to use it within the function get_lang(...).
$language_interface_initial_value = $language_interface;
// Initialization of the default language for the multibyte string library.
api_set_string_library_default_language($language_interface);
/*
* Include all necessary language files
* - trad4all

@ -1438,6 +1438,9 @@ function & get_lang_to_system_encoding(& $string, $language) {
*/
function api_get_interface_language($purified = false) {
global $language_interface;
if (empty($language_interface)) {
return 'english';
}
if ($purified) {
return api_refine_language_id($language_interface);
}
@ -3477,19 +3480,14 @@ if ( !function_exists('sys_get_temp_dir') )
}
}
}
/**
* This function allow know when request sent is XMLHttpRequest
*/
function api_is_xml_http_request() {
/*
if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') {
return true;
} else {
return false;
}
*/
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false;
}
/**
* This function gets the hash in md5 or sha1 (it depends in the platform config) of a given password
* @param string password

@ -65,7 +65,6 @@ function api_initialize_string_library() {
@ini_set('mbstring.language', 'neutral');
}
api_set_string_library_default_encoding('ISO-8859-15');
api_set_string_library_default_language('english');
}
/**
@ -82,20 +81,6 @@ function api_set_string_library_default_encoding($encoding) {
return $result;
}
/**
* Sets the internal default language value.
* If the intl extension is present, given language identificator modifies string comparison and sorting functionaliry.
* @param string $language The specified default language.
* @return string Returns the old value of the default language.
*/
function api_set_string_library_default_language($language) {
static $old_language = 'english';
_api_set_default_locale(_api_get_locale_from_language($language));
$result = $old_language;
$old_language = $language;
return $result;
}
/**
* ----------------------------------------------------------------------------
@ -1521,7 +1506,7 @@ function api_ucwords($string, $encoding = null) {
*/
function api_preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
$encoding = _api_mb_internal_encoding();
}
return preg_match(api_is_utf8($encoding) ? $pattern.'u' : $pattern, $subject, $matches, $flags, $offset);
}
@ -1544,7 +1529,7 @@ function api_preg_match($pattern, $subject, &$matches = null, $flags = 0, $offse
*/
function api_preg_match_all($pattern, $subject, &$matches, $flags = PREG_PATTERN_ORDER, $offset = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
$encoding = _api_mb_internal_encoding();
}
if (is_null($flags)) {
$flags = PREG_PATTERN_ORDER;
@ -1566,7 +1551,7 @@ function api_preg_match_all($pattern, $subject, &$matches, $flags = PREG_PATTERN
*/
function api_preg_replace($pattern, $replacement, $subject, $limit = -1, &$count = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
$encoding = _api_mb_internal_encoding();
}
$is_utf8 = api_is_utf8($encoding);
if (is_array($pattern)) {
@ -1592,7 +1577,7 @@ function api_preg_replace($pattern, $replacement, $subject, $limit = -1, &$count
*/
function api_preg_replace_callback($pattern, $callback, $subject, $limit = -1, &$count = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
$encoding = _api_mb_internal_encoding();
}
if (is_array($pattern)) {
foreach ($pattern as &$p) {
@ -1620,7 +1605,7 @@ function api_preg_replace_callback($pattern, $callback, $subject, $limit = -1, &
*/
function api_preg_split($pattern, $subject, $limit = -1, $flags = 0, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
$encoding = _api_mb_internal_encoding();
}
return preg_split(api_is_utf8($encoding) ? $pattern.'u' : $pattern, $subject, $limit, $flags);
}
@ -2458,15 +2443,18 @@ function api_is_latin1($encoding, $strict = false) {
* @return string The system's encoding.
* Note: The value of api_get_setting('platform_charset') is tried to be returned first,
* on the second place the global variable $charset is tried to be returned. If for some
* reason both attempts fail, 'ISO-8859-15' will be returned.
* reason both attempts fail, then the libraly's internal value will be returned.
*/
function api_get_system_encoding() {
$system_encoding = api_get_setting('platform_charset');
if (!empty($system_encoding)) {
return $system_encoding;
if (empty($system_encoding)) {
global $charset;
if (empty($charset)) {
return _api_mb_internal_encoding();
}
return $charset;
}
global $charset;
return empty($charset) ? 'ISO-8859-15' : $charset;
return $system_encoding;
}
/**
@ -2738,8 +2726,11 @@ function api_is_valid_ascii($string) {
* @param string The same purified or filtered language identificator, for example 'french'.
*/
function api_refine_language_id($language) {
static $search = array('_unicode', '_latin', '_corporate', '_org', '_KM');
return strtolower(str_replace($search, '', $language));
static $purified = array();
if (!isset($purified[$language])) {
$purified[$language] = strtolower(str_replace(array('_unicode', '_latin', '_corporate', '_org', '_KM'), '', $language));
}
return $purified[$language];
}
/**

@ -8,13 +8,18 @@
* @author: Ivan Tcholakov, ivantcholakov@gmail.com, 2009
* @package dokeos.library
* ==============================================================================
*
*
* Note: All functions and data structures here are not to be used directly.
* See the file multibyte_string_functions.lib.php which contains the "public" API.
*
*/
// Global variables used by some callback functions.
/**
* ----------------------------------------------------------------------------
* Global variables used by some callback functions
* ----------------------------------------------------------------------------
*/
$_api_encoding = null;
$_api_collator = null;
@ -479,6 +484,9 @@ function _api_array_utf8_decode($variable) {
*/
function _api_get_collator($language = null) {
static $collator = array();
if (empty($language)) {
$language = api_get_interface_language();
}
if (!isset($collator[$language])) {
$locale = _api_get_locale_from_language($language);
$collator[$language] = collator_create($locale);
@ -496,6 +504,9 @@ function _api_get_collator($language = null) {
*/
function _api_get_alpha_numerical_collator($language = null) {
static $collator = array();
if (empty($language)) {
$language = api_get_interface_language();
}
if (!isset($collator[$language])) {
$locale = _api_get_locale_from_language($language);
$collator[$language] = collator_create($locale);
@ -607,13 +618,18 @@ function _api_get_collator_sort_flag($sort_flag = SORT_REGULAR) {
*/
function _api_get_locale_from_language($language = null) {
static $locale = array();
if (empty($language)) {
$language = api_get_interface_language();
}
if (!isset($locale[$language])) {
if (class_exists('Database')) {
$locale[$language] = Database::get_language_isocode($language);
} else {
return 'en';
}
if (!is_null($locale[$language])) {
if (empty($locale[$language])) {
$locale[$language] = 'en';
} else {
$locale[$language] = str_replace('-', '_', $locale[$language]);
}
}

@ -161,8 +161,6 @@ header('Content-Type: text/html; charset='. $charset);
api_initialize_string_library();
// Initialization of the default encoding that will be used by the multibyte string routines.
api_set_string_library_default_encoding($charset);
// Initialization of the default language for the multibyte string library.
api_set_string_library_default_language($install_language);
require_once 'install_upgrade.lib.php'; //also defines constants
require_once 'install_functions.inc.php';

Loading…
Cancel
Save