123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- <?php
- $_api_encoding = null;
- $_api_collator = null;
- function &_api_get_day_month_names($language = null) {
- static $date_parts = array();
- if (empty($language)) {
- $language = api_get_interface_language();
- }
- if (!isset($date_parts[$language])) {
- $week_day = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
- $month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
- for ($i = 0; $i < 7; $i++) {
- $date_parts[$language]['days_short'][] = get_lang($week_day[$i].'Short', '', $language);
- $date_parts[$language]['days_long'][] = get_lang($week_day[$i].'Long', '', $language);
- }
- for ($i = 0; $i < 12; $i++) {
- $date_parts[$language]['months_short'][] = get_lang($month[$i].'Short', '', $language);
- $date_parts[$language]['months_long'][] = get_lang($month[$i].'Long', '', $language);
- }
- }
- return $date_parts[$language];
- }
- function _api_get_person_name_convention($language, $type)
- {
- static $conventions;
- $language = api_purify_language_id($language);
- if (!isset($conventions)) {
- $file = dirname(__FILE__).'/internationalization_database/name_order_conventions.php';
- if (file_exists($file)) {
- $conventions = include ($file);
- } else {
- $conventions = array(
- 'english' => array(
- 'format' => 'title first_name last_name',
- 'sort_by' => 'first_name'
- )
- );
- }
-
- $customConventions = api_get_configuration_value('name_order_conventions');
- if (!empty($customConventions)) {
- foreach ($customConventions as $key => $data) {
- $conventions[$key] = $data;
- }
- }
- $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
- $replacement1 = array('%F', '%L', '%T');
- $search2 = array('first_name', 'last_name', 'title');
- $replacement2 = array('%f', '%l', '%t');
- foreach (array_keys($conventions) as $key) {
- $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
- $conventions[$key]['format'] = _api_validate_person_name_format(_api_clean_person_name(str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))));
- $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
- }
- }
- switch ($type) {
- case 'format':
- return is_string($conventions[$language]['format']) ? $conventions[$language]['format'] : '%t %f %l';
- case 'sort_by':
- return is_bool($conventions[$language]['sort_by']) ? $conventions[$language]['sort_by'] : true;
- }
- return null;
- }
- function _api_validate_person_name_format($format) {
- if (empty($format) || stripos($format, '%f') === false || stripos($format, '%l') === false) {
- return '%t %f %l';
- }
- return $format;
- }
- function _api_clean_person_name($person_name) {
- return preg_replace(array('/\s+/', '/, ,/', '/,+/', '/^[ ,]/', '/[ ,]$/'), array(' ', ', ', ',', '', ''), $person_name);
- }
- function _api_convert_encoding(&$string, $to_encoding, $from_encoding)
- {
- return mb_convert_encoding($string, $to_encoding, $from_encoding);
- }
- function _api_get_character_map_name($encoding) {
- static $character_map_selector;
- if (!isset($character_map_selector)) {
- $file = dirname(__FILE__).'/internationalization_database/conversion/character_map_selector.php';
- if (file_exists($file)) {
- $character_map_selector = include ($file);
- } else {
- $character_map_selector = array();
- }
- }
- return isset($character_map_selector[$encoding]) ? $character_map_selector[$encoding] : '';
- }
- function _api_utf8_to_unicode(&$string) {
- $str = (string)$string;
- $state = 0;
-
- $codepoint = 0;
- $bytes = 1;
- $result = array();
- $len = api_byte_count($str);
- for ($i = 0; $i < $len; $i++) {
- $byte = ord($str[$i]);
- if ($state == 0) {
-
- if (0 == (0x80 & ($byte))) {
-
- $result[] = $byte;
- $bytes = 1;
- } else if (0xC0 == (0xE0 & ($byte))) {
-
- $codepoint = ($byte);
- $codepoint = ($codepoint & 0x1F) << 6;
- $state = 1;
- $bytes = 2;
- } else if (0xE0 == (0xF0 & ($byte))) {
-
- $codepoint = ($byte);
- $codepoint = ($codepoint & 0x0F) << 12;
- $state = 2;
- $bytes = 3;
- } else if (0xF0 == (0xF8 & ($byte))) {
-
- $codepoint = ($byte);
- $codepoint = ($codepoint & 0x07) << 18;
- $state = 3;
- $bytes = 4;
- } else if (0xF8 == (0xFC & ($byte))) {
-
-
-
-
-
-
- $codepoint = ($byte);
- $codepoint = ($codepoint & 0x03) << 24;
- $state = 4;
- $bytes = 5;
- } else if (0xFC == (0xFE & ($byte))) {
-
- $codepoint = ($byte);
- $codepoint = ($codepoint & 1) << 30;
- $state = 5;
- $bytes = 6;
- } else {
-
- $state = 0;
- $codepoint = 0;
- $bytes = 1;
- $result[] = 0xFFFD;
- continue ;
- }
- } else {
-
- if (0x80 == (0xC0 & ($byte))) {
-
- $shift = ($state - 1) * 6;
- $tmp = $byte;
- $tmp = ($tmp & 0x0000003F) << $shift;
- $codepoint |= $tmp;
-
- if (0 == --$state) {
-
-
- if (((2 == $bytes) && ($codepoint < 0x0080)) ||
- ((3 == $bytes) && ($codepoint < 0x0800)) ||
- ((4 == $bytes) && ($codepoint < 0x10000)) ||
- (4 < $bytes) ||
-
- (($codepoint & 0xFFFFF800) == 0xD800) ||
-
- ($codepoint > 0x10FFFF)) {
- $state = 0;
- $codepoint = 0;
- $bytes = 1;
- $result[] = 0xFFFD;
- continue ;
- }
- if (0xFEFF != $codepoint) {
-
- $result[] = $codepoint;
- }
-
- $state = 0;
- $codepoint = 0;
- $bytes = 1;
- }
- } else {
-
-
- $state = 0;
- $codepoint = 0;
- $bytes = 1;
- $result[] = 0xFFFD;
- }
- }
- }
- return $result;
- }
- function _api_utf8_from_unicode($codepoints) {
- return implode(array_map('_api_utf8_chr', $codepoints));
- }
- function _api_utf8_chr($codepoint) {
-
- if ( ($codepoint >= 0) && ($codepoint <= 0x007f) ) {
- $result = chr($codepoint);
-
- } else if ($codepoint <= 0x07ff) {
- $result = chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x003f));
-
- } else if($codepoint == 0xFEFF) {
-
- $result = '';
-
- } else if ($codepoint >= 0xD800 && $codepoint <= 0xDFFF) {
-
- $result = _api_utf8_chr(0xFFFD);
-
- } else if ($codepoint <= 0xffff) {
- $result = chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x003f)) . chr(0x80 | ($codepoint & 0x003f));
-
- } else if ($codepoint <= 0x10ffff) {
- $result = chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
- } else {
-
- $result = _api_utf8_chr(0xFFFD);
- }
- return $result;
- }
- function _api_strnatrcmp($string1, $string2) {
- return strnatcmp($string2, $string1);
- }
- function _api_mb_internal_encoding($encoding = null)
- {
- return mb_internal_encoding($encoding);
- }
- function _api_mb_supports($encoding) {
- static $supported = array();
- if (!isset($supported[$encoding])) {
- if (MBSTRING_INSTALLED) {
- $supported[$encoding] = api_equal_encodings($encoding, mb_list_encodings(), true);
- } else {
- $supported[$encoding] = false;
- }
- }
- return $supported[$encoding];
- }
- function _api_iconv_supports($encoding) {
- static $supported = array();
- if (!isset($supported[$encoding])) {
- if (ICONV_INSTALLED) {
- $enc = api_refine_encoding_id($encoding);
- if ($enc != 'HTML-ENTITIES') {
- $test_string = '';
- for ($i = 32; $i < 128; $i++) {
- $test_string .= chr($i);
- }
- $supported[$encoding] = (@iconv_strlen($test_string, $enc)) ? true : false;
- } else {
- $supported[$encoding] = false;
- }
- } else {
- $supported[$encoding] = false;
- }
- }
- return $supported[$encoding];
- }
- function _api_convert_encoding_supports($encoding) {
- static $supports = array();
- if (!isset($supports[$encoding])) {
- $supports[$encoding] = _api_get_character_map_name(api_refine_encoding_id($encoding)) != '';
- }
- return $supports[$encoding];
- }
- function _api_html_entity_supports($encoding) {
- static $supports = array();
- if (!isset($supports[$encoding])) {
-
- $html_entity_encodings = array(
- 'ISO-8859-1',
- 'ISO-8859-15',
- 'UTF-8',
- 'CP866',
- 'CP1251',
- 'CP1252',
- 'KOI8-R',
- 'BIG5', '950',
- 'GB2312', '936',
- 'BIG5-HKSCS',
- 'Shift_JIS', 'SJIS', '932',
- 'EUC-JP', 'EUCJP'
- );
- $supports[$encoding] = api_equal_encodings($encoding, $html_entity_encodings);
- }
- return $supports[$encoding];
- }
|