From 4ad866a499f70c42a4f018c5a37cd4ddf266a708 Mon Sep 17 00:00:00 2001 From: Guillaume Viguier Date: Tue, 2 Mar 2010 11:28:03 -0500 Subject: [PATCH] Localized date formats, added localized date formats (only available with php 5.3) and fixed a few deprecated functions in php 5.3. Potential risk of problems with php 4 versions. - Chamilo - CT#290 --- main/inc/lib/main_api.lib.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index a3bbcf4f6d..61b3f0099e 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1086,9 +1086,6 @@ function api_session_start($already_installed = true) { */ function api_session_register($variable) { global $$variable; - // session_register() is deprecated as of PHP 5.3 - session_register($variable); - // $_SESSION[$variable] = $$variable; } @@ -1104,10 +1101,7 @@ function api_session_unregister($variable) { unset ($GLOBALS[$variable]); } if (isset($_SESSION[$variable])) { - $_SESSION[$variable] = null; - // session_unregister() is deprecated as of PHP 5.3 - session_unregister($variable); - // + unset($_SESSION[$variable]); } } @@ -4582,7 +4576,9 @@ function api_get_local_time($time, $format=null, $to_timezone=null, $from_timezo } } // Determine the format + $format_null = false; if ($format === null) { + $format_null = true; $format = 'Y-m-d H:i:s'; } // If time is a timestamp, convert it to a string @@ -4596,7 +4592,15 @@ function api_get_local_time($time, $format=null, $to_timezone=null, $from_timezo if (is_int($format) || strpos($format, '%') !== false) { return api_format_date($format, strtotime($date->format("Y-m-d H:i:s"))); } else { - return $date->format($format); + if ($format_null == true && phpversion() >= 5.3) { + // use IntlDateFormatter to localize the date in the language of the user + require_once api_get_path(LIBRARY_PATH).'/internationalization.lib.php'; + $locale = api_get_language_isocode(); + $date_formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::SHORT); + return $date_formatter->format(strtotime($date->format("Y-m-d H:i:s"))); + } else { + return $date->format($format); + } } } catch (Exception $e) { return null;