123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215 |
- <?php
- $_api_encoding = null;
- $_api_collator = null;
- function _api_get_latin1_compatible_languages() {
- static $latin1_languages;
- if (!isset($latin1_languages)) {
- $latin1_languages = array();
- $encodings = & _api_non_utf8_encodings();
- foreach ($encodings as $key => $value) {
- if (api_is_latin1($value[0])) {
- $latin1_languages[] = $key;
- }
- }
- }
- return $latin1_languages;
- }
- function &_api_generate_n_grams(&$string, $encoding, $n_grams_max = 350, $n_max = 4) {
- if (empty($string)) {
- return array();
- }
-
-
-
- $words = preg_split('/_/u', preg_replace('/[\x00-\x1F\x20-\x26\x28-\x3E\?@\x5B-\x60{|}~\x7F]/u', '_', ' '.api_strtolower(api_utf8_encode($string, $encoding), 'UTF-8').' '), -1, PREG_SPLIT_NO_EMPTY);
- $prefix = '_';
- $suffix = str_repeat('_', $n_max);
- $n_grams = array();
- foreach ($words as $word) {
- $k = api_strlen($word, 'UTF-8') + 1;
- $word = $prefix.$word.$suffix;
- for ($n = 1; $n <= $n_max; $n++) {
- for ($i = 0; $i < $k; $i++) {
- $n_gram = api_utf8_decode(api_substr($word, $i, $n, 'UTF-8'), $encoding);
- if (isset($n_grams[$n_gram])) {
- $n_grams[$n_gram]++;
- } else {
- $n_grams[$n_gram] = 1;
- }
- }
- }
- }
-
- arsort($n_grams);
-
- return array_keys(array_slice($n_grams, 0, $n_grams_max));
- }
- function & _api_compare_n_grams(&$n_grams, $encoding, $max_delta = LANGUAGE_DETECT_MAX_DELTA) {
- static $language_profiles;
- if (!isset($language_profiles)) {
-
- $exceptions = array('.', '..', 'CVS', '.htaccess', '.svn', '_svn', 'index.html');
- $path = str_replace("\\", '/', dirname(__FILE__).'/internationalization_database/language_detection/language_profiles/');
- $non_utf8_encodings = & _api_non_utf8_encodings();
- if (is_dir($path)) {
- if ($handle = @opendir($path)) {
- while (($dir_entry = @readdir($handle)) !== false) {
- if (api_in_array_nocase($dir_entry, $exceptions)) continue;
- if (strpos($dir_entry, '.txt') === false) continue;
- $dir_entry_full_path = $path .'/'. $dir_entry;
- if (@filetype($dir_entry_full_path) != 'dir') {
- if (false !== $data = @file_get_contents($dir_entry_full_path)) {
- $language = basename($dir_entry_full_path, '.txt');
- $encodings = array('UTF-8');
- if (!empty($non_utf8_encodings[$language])) {
- $encodings = array_merge($encodings, $non_utf8_encodings[$language]);
- }
- foreach ($encodings as $enc) {
- $data_enc = api_utf8_decode($data, $enc);
- if (empty($data_enc)) {
- continue;
- }
- $key = $language.':'.$enc;
- $language_profiles[$key]['data'] = array_flip(explode("\n", $data_enc));
- $language_profiles[$key]['language'] = $language;
- $language_profiles[$key]['encoding'] = $enc;
- }
- }
- }
- }
- }
- }
- @closedir($handle);
- ksort($language_profiles);
- }
- if (!is_array($n_grams) || empty($n_grams)) {
- return array();
- }
-
- foreach ($language_profiles as $key => &$language_profile) {
- if (!api_is_language_supported($language_profile['language']) || !api_equal_encodings($encoding, $language_profile['encoding'])) {
- continue;
- }
- $delta = 0;
-
- foreach ($n_grams as $rank => &$n_gram) {
- if (isset($language_profile['data'][$n_gram])) {
-
-
-
- $delta += abs($rank - $language_profile['data'][$n_gram]);
- } else {
-
-
- $delta += 400;
- }
-
- if ($delta > $max_delta) {
- break;
- }
- }
-
- if ($delta < ($max_delta - 400)) {
- $result[$key] = $delta;
- }
- }
- if (!isset($result)) {
- return array();
- }
- asort($result);
- return $result;
- }
- 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'));
- }
- $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) {
- $str = (string)$string;
- static $character_map = array();
- static $utf8_compatible = array('UTF-8', 'US-ASCII');
- if (empty($str)) {
- return $str;
- }
- $to_encoding = api_refine_encoding_id($to_encoding);
- $from_encoding = api_refine_encoding_id($from_encoding);
- if (api_equal_encodings($to_encoding, $from_encoding)) {
- return $str;
- }
- if ($to_encoding == 'HTML-ENTITIES') {
- return api_htmlentities($str, ENT_QUOTES, $from_encoding);
- }
- if ($from_encoding == 'HTML-ENTITIES') {
- return api_html_entity_decode($str, ENT_QUOTES, $to_encoding);
- }
- $to = _api_get_character_map_name($to_encoding);
- $from = _api_get_character_map_name($from_encoding);
- if (empty($to) || empty($from) || $to == $from || (in_array($to, $utf8_compatible) && in_array($from, $utf8_compatible))) {
- return $str;
- }
- if (!isset($character_map[$to])) {
- $character_map[$to] = &_api_parse_character_map($to);
- }
- if ($character_map[$to] === false) {
- return $str;
- }
- if (!isset($character_map[$from])) {
- $character_map[$from] = &_api_parse_character_map($from);
- }
- if ($character_map[$from] === false) {
- return $str;
- }
- if ($from != 'UTF-8') {
- $len = api_byte_count($str);
- $codepoints = array();
- for ($i = 0; $i < $len; $i++) {
- $ord = ord($str[$i]);
- if ($ord > 127) {
- if (isset($character_map[$from]['local'][$ord])) {
- $codepoints[] = $character_map[$from]['local'][$ord];
- } else {
- $codepoints[] = 0xFFFD;
- }
- } else {
- $codepoints[] = $ord;
- }
- }
- } else {
- $codepoints = _api_utf8_to_unicode($str);
- }
- if ($to != 'UTF-8') {
- foreach ($codepoints as $i => &$codepoint) {
- if ($codepoint > 127) {
- if (isset($character_map[$to]['unicode'][$codepoint])) {
- $codepoint = chr($character_map[$to]['unicode'][$codepoint]);
- } else {
- $codepoint = '?';
- }
- } else {
- $codepoint = chr($codepoint);
- }
- }
- $str = implode($codepoints);
- } else {
- $str = _api_utf8_from_unicode($codepoints);
- }
- return $str;
- }
- 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_parse_character_map($name) {
- $result = array();
- $file = dirname(__FILE__).'/internationalization_database/conversion/' . $name . '.TXT';
- if (file_exists($file)) {
- $text = @file_get_contents($file);
- if ($text !== false) {
- $text = explode(chr(10), $text);
- foreach ($text as $line) {
- if (empty($line)) {
- continue;
- }
- if (!empty($line) && trim($line) && $line[0] != '#') {
- $matches = array();
- preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/', $line, $matches);
- $ord = hexdec(trim($matches[1]));
- if ($ord > 127) {
- $codepoint = hexdec(trim($matches[2]));
- $result['local'][$ord] = $codepoint;
- $result['unicode'][$codepoint] = $ord;
- }
- }
- }
- } else {
- return false ;
- }
- } else {
- return false;
- }
- return $result;
- }
- 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_utf8_ord($utf8_character) {
- if ($utf8_character == '') {
- return 0xFFFD;
- }
- $codepoints = _api_utf8_to_unicode($utf8_character);
- return $codepoints[0];
- }
- function _api_html_entity_from_unicode($codepoint) {
- if ($codepoint < 128) {
- return chr($codepoint);
- }
- return '&#'.$codepoint.';';
- }
- function &_api_utf8_get_letter_case_properties($codepoint, $type = 'lower') {
- static $config = array();
- static $range = array();
- if (!isset($range[$codepoint])) {
- if ($codepoint > 128 && $codepoint < 256) {
- $range[$codepoint] = '0080_00ff';
- } elseif ($codepoint < 384) {
- $range[$codepoint] = '0100_017f';
- } elseif ($codepoint < 592) {
- $range[$codepoint] = '0180_024F';
- } elseif ($codepoint < 688) {
- $range[$codepoint] = '0250_02af';
- } elseif ($codepoint >= 880 && $codepoint < 1024) {
- $range[$codepoint] = '0370_03ff';
- } elseif ($codepoint < 1280) {
- $range[$codepoint] = '0400_04ff';
- } elseif ($codepoint < 1328) {
- $range[$codepoint] = '0500_052f';
- } elseif ($codepoint < 1424) {
- $range[$codepoint] = '0530_058f';
- } elseif ($codepoint >= 7680 && $codepoint < 7936) {
- $range[$codepoint] = '1e00_1eff';
- } elseif ($codepoint < 8192) {
- $range[$codepoint] = '1f00_1fff';
- } elseif ($codepoint >= 8448 && $codepoint < 8528) {
- $range[$codepoint] = '2100_214f';
- } elseif ($codepoint < 8592) {
- $range[$codepoint] = '2150_218f';
- } elseif ($codepoint >= 9312 && $codepoint < 9472) {
- $range[$codepoint] = '2460_24ff';
- } elseif ($codepoint >= 11264 && $codepoint < 11360) {
- $range[$codepoint] = '2c00_2c5f';
- } elseif ($codepoint < 11392) {
- $range[$codepoint] = '2c60_2c7f';
- } elseif ($codepoint < 11520) {
- $range[$codepoint] = '2c80_2cff';
- } elseif ($codepoint >= 65280 && $codepoint < 65520) {
- $range[$codepoint] = 'ff00_ffef';
- } else {
- $range[$codepoint] = false;
- }
- if ($range[$codepoint] === false) {
- return null;
- }
- if (!isset($config[$range[$codepoint]])) {
- $file = dirname(__FILE__).'/internationalization_database/casefolding/' . $range[$codepoint] . '.php';
- if (file_exists($file)) {
- include $file;
- }
- }
- }
- if ($range[$codepoint] === false || !isset($config[$range[$codepoint]])) {
- return null;
- }
- $result = array();
- $count = count($config[$range[$codepoint]]);
- for ($i = 0; $i < $count; $i++) {
- if ($type === 'lower' && $config[$range[$codepoint]][$i][$type][0] === $codepoint) {
- $result[] = $config[$range[$codepoint]][$i];
- } elseif ($type === 'upper' && $config[$range[$codepoint]][$i][$type] === $codepoint) {
- $result[] = $config[$range[$codepoint]][$i];
- }
- }
- return $result;
- }
- function _api_utf8_ucwords_callback($matches) {
- return $matches[2] . api_ucfirst(ltrim($matches[0]), 'UTF-8');
- }
- function _api_array_utf8_decode($variable) {
- global $_api_encoding;
- if (is_array($variable)) {
- return array_map('_api_array_utf8_decode', $variable);
- }
- if (is_string($variable)) {
- return api_utf8_decode($variable, $_api_encoding);
- }
- return $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);
- if (is_object($collator[$language])) {
- collator_set_attribute($collator[$language], Collator::CASE_FIRST, Collator::UPPER_FIRST);
- }
- }
- return $collator[$language];
- }
- 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);
- if (is_object($collator[$language])) {
- collator_set_attribute($collator[$language], Collator::CASE_FIRST, Collator::UPPER_FIRST);
- collator_set_attribute($collator[$language], Collator::NUMERIC_COLLATION, Collator::ON);
- }
- }
- return $collator[$language];
- }
- function _api_cmp($string1, $string2) {
- global $_api_collator, $_api_encoding;
- $result = collator_compare($_api_collator, api_utf8_encode($string1, $_api_encoding), api_utf8_encode($string2, $_api_encoding));
- return $result === false ? 0 : $result;
- }
- function _api_rcmp($string1, $string2) {
- global $_api_collator, $_api_encoding;
- $result = collator_compare($_api_collator, api_utf8_encode($string2, $_api_encoding), api_utf8_encode($string1, $_api_encoding));
- return $result === false ? 0 : $result;
- }
- function _api_casecmp($string1, $string2) {
- global $_api_collator, $_api_encoding;
- $result = collator_compare($_api_collator, api_strtolower(api_utf8_encode($string1, $_api_encoding), 'UTF-8'), api_strtolower(api_utf8_encode($string2, $_api_encoding), 'UTF-8'));
- return $result === false ? 0 : $result;
- }
- function _api_casercmp($string1, $string2) {
- global $_api_collator, $_api_encoding;
- $result = collator_compare($_api_collator, api_strtolower(api_utf8_encode($string2, $_api_encoding), 'UTF-8'), api_strtolower(api_utf8_encode($string1, $_api_encoding), 'UTF-8'));
- return $result === false ? 0 : $result;
- }
- function _api_strnatrcmp($string1, $string2) {
- return strnatcmp($string2, $string1);
- }
- function _api_strnatcasercmp($string1, $string2) {
- return strnatcasecmp($string2, $string1);
- }
- function _api_get_collator_sort_flag($sort_flag = SORT_REGULAR) {
- switch ($sort_flag) {
- case SORT_STRING:
- case SORT_SORT_LOCALE_STRING:
- return Collator::SORT_STRING;
- case SORT_NUMERIC:
- return Collator::SORT_NUMERIC;
- }
- return Collator::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])) {
- $locale[$language] = str_replace('-', '_', api_get_language_isocode($language));
- }
- return $locale[$language];
- }
- function _api_set_default_locale($locale = null) {
- static $default_locale = 'en';
- if (!empty($locale)) {
- $default_locale = $locale;
- if (INTL_INSTALLED) {
- return @locale_set_default($locale);
- }
- return true;
- } else {
- if (INTL_INSTALLED) {
- $default_locale = @locale_get_default();
- }
- }
- return $default_locale;
- }
- function api_get_default_locale() {
- return _api_set_default_locale();
- }
- function & _api_non_utf8_encodings() {
- static $encodings;
- if (!isset($encodings)) {
- $file = dirname(__FILE__).'/internationalization_database/non_utf8_encodings.php';
- if (file_exists($file)) {
- $encodings = include ($file);
- } else {
- $encodings = array('english' => array('ISO-8859-15'));
- }
- }
- return $encodings;
- }
- function _api_mb_internal_encoding($encoding = null) {
- static $mb_internal_encoding = null;
- if (empty($encoding)) {
- if (is_null($mb_internal_encoding)) {
- if (MBSTRING_INSTALLED) {
- $mb_internal_encoding = @mb_internal_encoding();
- } else {
- $mb_internal_encoding = 'UTF-8';
- }
- }
- return $mb_internal_encoding;
- }
- $mb_internal_encoding = $encoding;
- if (_api_mb_supports($encoding)) {
- return @mb_internal_encoding($encoding);
- }
- return false;
- }
- function _api_mb_regex_encoding($encoding = null) {
- static $mb_regex_encoding = null;
- if (empty($encoding)) {
- if (is_null($mb_regex_encoding)) {
- if (MBSTRING_INSTALLED) {
- $mb_regex_encoding = @mb_regex_encoding();
- } else {
- $mb_regex_encoding = 'UTF-8';
- }
- }
- return $mb_regex_encoding;
- }
- $mb_regex_encoding = $encoding;
- if (_api_mb_supports($encoding)) {
- return @mb_regex_encoding($encoding);
- }
- return false;
- }
- function _api_iconv_get_encoding($type) {
- return _api_iconv_set_encoding($type);
- }
- function _api_iconv_set_encoding($type, $encoding = null) {
- static $iconv_internal_encoding = null;
- static $iconv_input_encoding = null;
- static $iconv_output_encoding = null;
- if (!ICONV_INSTALLED) {
- return false;
- }
- switch ($type) {
- case 'iconv_internal_encoding':
- if (empty($encoding)) {
- if (is_null($iconv_internal_encoding)) {
- $iconv_internal_encoding = @iconv_get_encoding($type);
- }
- return $iconv_internal_encoding;
- }
- if (_api_iconv_supports($encoding)) {
- if(@iconv_set_encoding($type, $encoding)) {
- $iconv_internal_encoding = $encoding;
- return true;
- }
- return false;
- }
- return false;
- case 'iconv_input_encoding':
- if (empty($encoding)) {
- if (is_null($iconv_input_encoding)) {
- $iconv_input_encoding = @iconv_get_encoding($type);
- }
- return $iconv_input_encoding;
- }
- if (_api_iconv_supports($encoding)) {
- if(@iconv_set_encoding($type, $encoding)) {
- $iconv_input_encoding = $encoding;
- return true;
- }
- return false;
- }
- return false;
- case 'iconv_output_encoding':
- if (empty($encoding)) {
- if (is_null($iconv_output_encoding)) {
- $iconv_output_encoding = @iconv_get_encoding($type);
- }
- return $iconv_output_encoding;
- }
- if (_api_iconv_supports($encoding)) {
- if(@iconv_set_encoding($type, $encoding)) {
- $iconv_output_encoding = $encoding;
- return true;
- }
- return false;
- }
- return false;
- }
- return false;
- }
- function _api_is_single_byte_encoding($encoding) {
- static $checked = array();
- if (!isset($checked[$encoding])) {
- $character_map = _api_get_character_map_name(api_refine_encoding_id($encoding));
- $checked[$encoding] = (!empty($character_map)
- && !in_array($character_map, array('UTF-8', 'HTML-ENTITIES')));
- }
- return $checked[$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];
- }
- if (MBSTRING_INSTALLED && !function_exists('mb_strchr')) {
- function mb_strchr($haystack, $needle, $part = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = mb_internal_encoding();
- }
- return mb_strstr($haystack, $needle, $part, $encoding);
- }
- }
- if (MBSTRING_INSTALLED && !function_exists('mb_stripos')) {
- function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = mb_internal_encoding();
- }
- return mb_strpos(mb_strtolower($haystack, $encoding), mb_strtolower($needle, $encoding), $offset, $encoding);
- }
- }
- if (MBSTRING_INSTALLED && !function_exists('mb_stristr')) {
- function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = mb_internal_encoding();
- }
- $pos = mb_strpos(mb_strtolower($haystack, $encoding), mb_strtolower($needle, $encoding), 0, $encoding);
- if ($pos === false) {
- return false;
- }
- if ($part) {
- return mb_substr($haystack, 0, $pos + 1, $encoding);
- }
- return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
- }
- }
- if (MBSTRING_INSTALLED && !function_exists('mb_strrchr')) {
- function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = mb_internal_encoding();
- }
- $needle = mb_substr($needle, 0, 1, $encoding);
- $pos = mb_strrpos($haystack, $needle, mb_strlen($haystack, $encoding) - 1, $encoding);
- if ($pos === false) {
- return false;
- }
- if ($part) {
- return mb_substr($haystack, 0, $pos + 1, $encoding);
- }
- return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
- }
- }
- if (MBSTRING_INSTALLED && !function_exists('mb_strstr')) {
- function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = mb_internal_encoding();
- }
- $pos = mb_strpos($haystack, $needle, 0, $encoding);
- if ($pos === false) {
- return false;
- }
- if ($part) {
- return mb_substr($haystack, 0, $pos + 1, $encoding);
- }
- return mb_substr($haystack, $pos, mb_strlen($haystack, $encoding), $encoding);
- }
- }
|