|
|
|
@ -124,21 +124,14 @@ function get_lang($variable, $reserved = null, $language = null) { |
|
|
|
|
$_api_is_translated, $_api_is_translated_call; |
|
|
|
|
|
|
|
|
|
// Caching results from some API functions, for speed. |
|
|
|
|
static $encoding, $is_utf8_encoding, $langpath, $test_server_mode, $show_special_markup; |
|
|
|
|
if (!isset($is_utf8_encoding)) { |
|
|
|
|
static $initialized, $encoding, $is_utf8_encoding, $langpath, $test_server_mode, $show_special_markup; |
|
|
|
|
if (!isset($initialized)) { |
|
|
|
|
$encoding = api_get_system_encoding(); |
|
|
|
|
} |
|
|
|
|
if (!isset($is_utf8_encoding)) { |
|
|
|
|
$is_utf8_encoding = api_is_utf8($encoding); |
|
|
|
|
} |
|
|
|
|
if (!isset($langpath)) { |
|
|
|
|
$langpath = api_get_path(SYS_LANG_PATH); |
|
|
|
|
} |
|
|
|
|
if (!isset($test_server_mode)) { |
|
|
|
|
$test_server_mode = api_get_setting('server_type') == 'test'; |
|
|
|
|
} |
|
|
|
|
if (!isset($show_special_markup)) { |
|
|
|
|
$show_special_markup = api_get_setting('hide_dltt_markup') != 'true' || $test_server_mode; |
|
|
|
|
$initialized = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Combining both ways for requesting specific language. |
|
|
|
@ -521,9 +514,9 @@ function api_get_local_time($time = null, $to_timezone = null, $from_timezone = |
|
|
|
|
if (is_int($time)) { |
|
|
|
|
$from_timezone = 'UTC'; |
|
|
|
|
$time = gmdate('Y-m-d H:i:s', $time); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
$date = new DateTime($time, new DateTimezone($from_timezone)); |
|
|
|
|
$date = new DateTime($time, new DateTimezone($from_timezone)); |
|
|
|
|
$date->setTimezone(new DateTimeZone($to_timezone)); |
|
|
|
|
return $date->format('Y-m-d H:i:s'); |
|
|
|
|
} catch (Exception $e) { |
|
|
|
@ -580,7 +573,7 @@ function api_format_date($time, $format = null, $language = null) { |
|
|
|
|
|
|
|
|
|
$datetype = null; |
|
|
|
|
$timetype = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(is_int($format)) { |
|
|
|
|
switch ($format) { |
|
|
|
|
case TIME_NO_SEC_FORMAT: |
|
|
|
@ -627,12 +620,12 @@ function api_format_date($time, $format = null, $language = null) { |
|
|
|
|
if (is_null($language)) { |
|
|
|
|
$language = api_get_language_isocode(); |
|
|
|
|
} |
|
|
|
|
$date_formatter = datefmt_create($language, $datetype, $timetype, date_default_timezone_get()); |
|
|
|
|
$date_formatter = datefmt_create($language, $datetype, $timetype, date_default_timezone_get()); |
|
|
|
|
$formatted_date = api_to_system_encoding(datefmt_format($date_formatter, $time), 'UTF-8'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// We replace %a %A %b %B masks of date format with translated strings. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$translated = &_api_get_day_month_names($language); |
|
|
|
|
$date_format = str_replace(array('%A', '%a', '%B', '%b'), |
|
|
|
|
array($translated['days_long'][(int)strftime('%w', $time )], |
|
|
|
@ -785,7 +778,7 @@ function date_to_str_ago($date) { |
|
|
|
|
*/ |
|
|
|
|
function api_convert_and_format_date($time = null, $format = null, $from_timezone = null) { |
|
|
|
|
// First, convert the datetime to the right timezone |
|
|
|
|
$time = api_get_local_time($time, null, $from_timezone); |
|
|
|
|
$time = api_get_local_time($time, null, $from_timezone); |
|
|
|
|
// Second, localize the date |
|
|
|
|
return api_format_date($time, $format); |
|
|
|
|
} |
|
|
|
|