1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349 |
- <?php
- define('SPECIAL_OPENING_TAG', '[=');
- define('SPECIAL_CLOSING_TAG', '=]');
- define('TIME_NO_SEC_FORMAT', 0);
- define('DATE_FORMAT_SHORT', 1);
- define('DATE_FORMAT_LONG', 2);
- define('DATE_FORMAT_LONG_NO_DAY', 10);
- define('DATE_TIME_FORMAT_LONG', 3);
- define('DATE_FORMAT_NUMBER', 4);
- define('DATE_TIME_FORMAT_LONG_24H', 5);
- define('DATE_TIME_FORMAT_SHORT', 6);
- define('DATE_TIME_FORMAT_SHORT_TIME_FIRST', 7);
- define('DATE_FORMAT_NUMBER_NO_YEAR', 8);
- define('DATE_FORMAT_ONLY_DAYNAME', 9);
- define('PERSON_NAME_COMMON_CONVENTION', 0);
- define('PERSON_NAME_WESTERN_ORDER', 1);
- define('PERSON_NAME_EASTERN_ORDER', 2);
- define('PERSON_NAME_LIBRARY_ORDER', 3);
- define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER);
- define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER);
- define ('LANGUAGE_DETECT_MAX_LENGTH', 2000);
- define ('LANGUAGE_DETECT_MAX_DELTA', 140000);
- function api_initialize_internationalization()
- {
- if (MBSTRING_INSTALLED) {
- @ini_set('mbstring.func_overload', 0);
- @ini_set('mbstring.encoding_translation', 0);
- @ini_set('mbstring.http_input', 'pass');
- @ini_set('mbstring.http_output', 'pass');
- @ini_set('mbstring.language', 'neutral');
- }
- api_set_internationalization_default_encoding('UTF-8');
- }
- function api_set_internationalization_default_encoding($encoding) {
- $encoding = api_refine_encoding_id($encoding);
- $result = _api_mb_internal_encoding();
- _api_mb_internal_encoding($encoding);
- _api_mb_regex_encoding($encoding);
- _api_iconv_set_encoding('iconv_internal_encoding', $encoding);
- return $result;
- }
- $_api_is_translated = false;
- $_api_is_translated_call = false;
- function get_lang($variable, $reserved = null, $language = null) {
- global
-
-
- $language_interface,
-
- $language_interface_initial_value,
-
- $_api_is_translated, $_api_is_translated_call;
- global $used_lang_vars, $_configuration;
-
-
-
- if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
- require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
- global $langstats;
- $langstats->add_use($variable,'');
- }
- if (!isset ($used_lang_vars)) {
- $used_lang_vars = array();
- }
-
- static $initialized, $encoding, $is_utf8_encoding, $langpath, $test_server_mode, $show_special_markup;
- if (!isset($initialized)) {
- $encoding = api_get_system_encoding();
- $is_utf8_encoding = api_is_utf8($encoding);
- $langpath = api_get_path(SYS_LANG_PATH);
- $test_server_mode = api_get_setting('server_type') == 'test';
- $show_special_markup = api_get_setting('hide_dltt_markup') != 'true' || $test_server_mode;
- $initialized = true;
- }
-
- if (empty($language)) {
- $language = $language_interface;
- }
- $lang_postfix = isset($is_interface_language) && $is_interface_language ? '' : '('.$language.')';
- $is_interface_language = $language == $language_interface_initial_value;
-
- static $cache;
-
- if (isset($cache[$language][$variable]) && !$_api_is_translated_call) {
-
-
- $ret = $cache[$language][$variable];
- $used_lang_vars[$variable.$lang_postfix] = $ret;
- return $ret;
- }
- $_api_is_translated = false;
-
-
-
- $read_global_variables = $is_interface_language && !$test_server_mode && !$_api_is_translated_call;
-
- if (!$read_global_variables) {
- global $language_files;
- if (isset($language_files)) {
- $parent_language = null;
- if (api_get_setting('allow_use_sub_language') == 'true') {
- require_once api_get_path(SYS_CODE_PATH).'admin/sub_language.class.php';
- $parent_language = SubLanguageManager::get_parent_language_path($language);
- }
- if (!is_array($language_files)) {
- if (isset($parent_language)) {
- @include "$langpath$parent_language/$language_files.inc.php";
- }
- @include "$langpath$language/$language_files.inc.php";
- } else {
- foreach ($language_files as &$language_file) {
- if (isset($parent_language)) {
- @include "$langpath$parent_language/$language_file.inc.php";
- }
- @include "$langpath$language/$language_file.inc.php";
- }
- }
- }
- }
-
- if (!$test_server_mode) {
- if ($read_global_variables) {
- if (isset($GLOBALS[$variable])) {
- $langvar = $GLOBALS[$variable];
- $_api_is_translated = true;
- } elseif (isset($GLOBALS["lang$variable"])) {
- $langvar = $GLOBALS["lang$variable"];
- $_api_is_translated = true;
- } else {
- $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
- }
- } else {
- if (isset($$variable)) {
- $langvar = $$variable;
- $_api_is_translated = true;
- } elseif (isset(${"lang$variable"})) {
- $langvar = ${"lang$variable"};
- $_api_is_translated = true;
- } else {
- $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
- }
- }
- if (empty($langvar) || !is_string($langvar)) {
- $_api_is_translated = false;
- $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
- }
-
- $ret = $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
- $used_lang_vars[$variable.$lang_postfix] = $ret;
- return $ret;
- }
-
- if (!is_string($variable)) {
-
- $ret = $cache[$language][$variable] = SPECIAL_OPENING_TAG.'get_lang(?)'.SPECIAL_CLOSING_TAG;
- $used_lang_vars[$variable.$lang_postfix] = $ret;
- return $ret;
- }
- if (isset($$variable)) {
- $langvar = $$variable;
- $_api_is_translated = true;
- } elseif (isset(${"lang$variable"})) {
- $langvar = ${"lang$variable"};
- $_api_is_translated = true;
- } else {
- $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
- }
- if (empty($langvar) || !is_string($langvar)) {
- $_api_is_translated = false;
- $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
- }
-
- $ret = $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
- $used_lang_vars[$variable.$lang_postfix] = $ret;
- return $ret;
- }
- function api_is_translated($variable, $language = null) {
- global $_api_is_translated, $_api_is_translated_call;
- $_api_is_translated_call = true;
- get_lang($variable, $language);
- $_api_is_translated_call = false;
- return $_api_is_translated;
- }
- function api_get_interface_language($purified = false, $check_sub_language = false) {
- global $language_interface;
- if (empty($language_interface)) {
- return 'english';
- }
-
- $language_is_supported = api_is_language_supported($language_interface);
- if ($check_sub_language && !$language_is_supported) {
- static $parent_language_name = null;
- if (!isset($parent_language_name)) {
-
- $language_id = api_get_language_id($language_interface);
- $language_info = api_get_language_info($language_id);
- if (!empty($language_id) && !empty($language_info)) {
- $language_info = api_get_language_info($language_info['parent_id']);
- $parent_language_name = $language_info['english_name'];
- if (!empty($parent_language_name)) {
- return $parent_language_name;
- }
- }
- return 'english';
- } else {
- return $parent_language_name;
- }
- } else {
-
- $interface_language = $purified ? api_purify_language_id($language_interface) : $language_interface;
- }
- return $interface_language;
- }
- function api_is_language_supported($language) {
- static $supported = array();
- if (!isset($supported[$language])) {
- $supported[$language] = in_array(api_purify_language_id($language), array_keys(_api_non_utf8_encodings()));
- }
- return $supported[$language];
- }
- function api_get_valid_language($language) {
- static $enabled_languages;
- if (!isset($enabled_languages)) {
- $enabled_languages_info = api_get_languages();
- $enabled_languages = $enabled_languages_info['folder'];
- }
- $language = str_replace('_km', '_KM', strtolower(trim($language)));
- if (empty($language) || !in_array($language, $enabled_languages) || !api_is_language_supported($language)) {
- $language = api_get_setting('platformLanguage');
- }
- return $language;
- }
- function api_purify_language_id($language) {
- static $purified = array();
- if (!isset($purified[$language])) {
- $purified[$language] = trim(str_replace(array('_unicode', '_latin', '_corporate', '_org', '_km'), '', strtolower($language)));
- }
- return $purified[$language];
- }
- function api_get_language_isocode($language = null, $default_code = 'en') {
- static $iso_code = array();
- if (empty($language)) {
- $language = api_get_interface_language(false, true);
- }
- if (!isset($iso_code[$language])) {
- if (!class_exists('Database')) {
- return $default_code;
- }
- $sql_result = Database::query("SELECT isocode FROM ".Database::get_main_table(TABLE_MAIN_LANGUAGE)." WHERE dokeos_folder = '$language'");
- if (Database::num_rows($sql_result)) {
- $result = Database::fetch_array($sql_result);
- $iso_code[$language] = trim($result['isocode']);
- } else {
- $language_purified_id = api_purify_language_id($language);
- $iso_code[$language] = isset($iso_code[$language_purified_id]) ? $iso_code[$language_purified_id] : null;
- }
- if (empty($iso_code[$language])) {
- $iso_code[$language] = $default_code;
- }
- }
- return $iso_code[$language];
- }
- function api_get_platform_isocodes() {
- $iso_code = array();
- $sql_result = Database::query("SELECT isocode FROM ".Database::get_main_table(TABLE_MAIN_LANGUAGE)." ORDER BY isocode ");
- if (Database::num_rows($sql_result)) {
- while ($row = Database::fetch_array($sql_result)) {;
- $iso_code[] = trim($row['isocode']);
- }
- }
- return $iso_code;
- }
- function api_get_text_direction($language = null) {
- static $text_direction = array();
-
- if (empty($language)) {
- $language = api_get_interface_language();
- }
- if (!isset($text_direction[$language])) {
- $text_direction[$language] = in_array(api_purify_language_id($language),
- array(
- 'arabic',
- 'ar',
- 'dari',
- 'prs',
- 'hebrew',
- 'he',
- 'iw',
- 'pashto',
- 'ps',
- 'persian',
- 'fa',
- 'ur',
- 'yiddish',
- 'yid'
- )
- ) ? 'rtl' : 'ltr';
- }
- return $text_direction[$language];
- }
- function api_is_latin1_compatible($language) {
- static $latin1_languages;
- if (!isset($latin1_languages)) {
- $latin1_languages = _api_get_latin1_compatible_languages();
- }
- $language = api_purify_language_id($language);
- return in_array($language, $latin1_languages);
- }
- function api_detect_language(&$string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (empty($string)) {
- return false;
- }
- $result_array = &_api_compare_n_grams(_api_generate_n_grams(api_substr($string, 0, LANGUAGE_DETECT_MAX_LENGTH, $encoding), $encoding), $encoding);
- if (empty($result_array)) {
- return false;
- }
- list($key, $delta_points) = each($result_array);
- return strstr($key, ':', true);
- }
- function api_get_timezones()
- {
- $timezone_identifiers = DateTimeZone::listIdentifiers();
- sort($timezone_identifiers);
- $out = array();
- foreach ($timezone_identifiers as $tz) {
- $out[$tz] = $tz;
- }
- $null_option = array('' => '');
- $result = array_merge($null_option, $out);
- return $result;
- }
- function _api_get_timezone() {
- global $_user;
-
- $to_timezone = date_default_timezone_get();
-
- $timezone_value = api_get_setting('timezone_value', 'timezones');
- if ($timezone_value != null) {
- $to_timezone = $timezone_value;
- }
-
- $use_users_timezone = api_get_setting('use_users_timezone', 'timezones');
- if ($use_users_timezone == 'true') {
-
- $timezone_user = UserManager::get_extra_user_data_by_field($_user['user_id'],'timezone');
- if (isset($timezone_user['timezone']) && $timezone_user['timezone'] != null) {
- $to_timezone = $timezone_user['timezone'];
- }
- }
- return $to_timezone;
- }
- function api_get_utc_datetime($time = null, $return_null_if_invalid_date = false) {
- $from_timezone = _api_get_timezone();
- $to_timezone = 'UTC';
- if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
- if ($return_null_if_invalid_date) {
- return null;
- }
- return gmdate('Y-m-d H:i:s');
- }
-
- if (is_numeric($time)) {
- $time = intval($time);
- return gmdate('Y-m-d H:i:s', $time);
- }
- try {
- $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) {
- return null;
- }
- }
- function api_get_local_time($time = null, $to_timezone = null, $from_timezone = null, $return_null_if_invalid_date = false)
- {
-
- if (is_null($from_timezone)) {
- $from_timezone = 'UTC';
- }
-
- if (is_null($to_timezone)) {
- $to_timezone = _api_get_timezone();
- }
-
- if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
- if ($return_null_if_invalid_date) {
- return null;
- }
- $from_timezone = 'UTC';
- $time = gmdate('Y-m-d H:i:s');
- }
- if (is_numeric($time)) {
- $time = intval($time);
- $from_timezone = 'UTC';
- $time = gmdate('Y-m-d H:i:s', $time);
- }
- try {
- $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) {
- return null;
- }
- }
- function api_strtotime($time, $timezone = null) {
- $system_timezone = date_default_timezone_get();
- if (!empty($timezone)) {
- date_default_timezone_set($timezone);
- }
- $timestamp = strtotime($time);
- date_default_timezone_set($system_timezone);
- return $timestamp;
- }
- function api_format_date($time, $format = null, $language = null) {
- $system_timezone = date_default_timezone_get();
- date_default_timezone_set(_api_get_timezone());
- if (is_string($time)) {
- $time = strtotime($time);
- }
- if (is_null($format)) {
- $format = DATE_TIME_FORMAT_LONG;
- }
- $datetype = null;
- $timetype = null;
- if (is_int($format)) {
- switch ($format) {
- case DATE_FORMAT_ONLY_DAYNAME:
- $date_format = get_lang('dateFormatOnlyDayName', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_NUMBER_NO_YEAR:
- $date_format = get_lang('dateFormatShortNumberNoYear', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_NUMBER:
- $date_format = get_lang('dateFormatShortNumber', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case TIME_NO_SEC_FORMAT:
- $date_format = get_lang('timeNoSecFormat', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::NONE;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_FORMAT_SHORT:
- $date_format = get_lang('dateFormatShort', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::LONG;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_LONG:
- $date_format = get_lang('dateFormatLong', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_TIME_FORMAT_LONG:
- $date_format = get_lang('dateTimeFormatLong', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_FORMAT_LONG_NO_DAY:
- $date_format = get_lang('dateFormatLongNoDay', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_SHORT:
- $date_format = get_lang('dateTimeFormatShort', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_SHORT_TIME_FIRST:
- $date_format = get_lang('dateTimeFormatShortTimeFirst', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_LONG_24H:
- $date_format = get_lang('dateTimeFormatLong24H', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- default:
- $date_format = get_lang('dateTimeFormatLong', '', $language);
- if (INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- }
- } else {
- $date_format = $format;
- }
- if (0) {
-
-
-
- if (is_null($language)) {
- $language = api_get_language_isocode();
- }
- $date_formatter = new IntlDateFormatter($language, $datetype, $timetype, date_default_timezone_get());
-
- $formatted_date = api_to_system_encoding($date_formatter->format($time), 'UTF-8');
- } else {
-
- $translated = &_api_get_day_month_names($language);
- $date_format = str_replace(array('%A', '%a', '%B', '%b'),
- array($translated['days_long'][(int)strftime('%w', $time )],
- $translated['days_short'][(int)strftime('%w', $time)],
- $translated['months_long'][(int)strftime('%m', $time) - 1],
- $translated['months_short'][(int)strftime('%m', $time) - 1]),
- $date_format);
- $formatted_date = api_to_system_encoding(strftime($date_format, $time), 'UTF-8');
- }
- date_default_timezone_set($system_timezone);
- return $formatted_date;
- }
- function date_to_str_ago($date) {
- static $initialized = false;
- static $today, $yesterday;
- static $min_decade, $min_year, $min_month, $min_week, $min_day, $min_hour, $min_minute;
- static $min_decades, $min_years, $min_months, $min_weeks, $min_days, $min_hours, $min_minutes;
- static $sec_time_time, $sec_time_sing, $sec_time_plu;
- $system_timezone = date_default_timezone_get();
- date_default_timezone_set(_api_get_timezone());
- if (!$initialized) {
- $today = get_lang('Today');
- $yesterday = get_lang('Yesterday');
- $min_decade = get_lang('MinDecade');
- $min_year = get_lang('MinYear');
- $min_month = get_lang('MinMonth');
- $min_week = get_lang('MinWeek');
- $min_day = get_lang('MinDay');
- $min_hour = get_lang('MinHour');
- $min_minute = get_lang('MinMinute');
- $min_decades = get_lang('MinDecades');
- $min_years = get_lang('MinYears');
- $min_months = get_lang('MinMonths');
- $min_weeks = get_lang('MinWeeks');
- $min_days = get_lang('MinDays');
- $min_hours = get_lang('MinHours');
- $min_minutes = get_lang('MinMinutes');
-
-
-
- $sec_time_time = array(315569260, 31556926, 2629743.83, 604800, 86400, 3600, 60);
- $sec_time_sing = array($min_decade, $min_year, $min_month, $min_week, $min_day, $min_hour, $min_minute);
- $sec_time_plu = array($min_decades, $min_years, $min_months, $min_weeks, $min_days, $min_hours, $min_minutes);
- $initialized = true;
- }
- $dst_date = is_string($date) ? strtotime($date) : $date;
-
- $date_array = date('s/i/G/j/n/Y', $dst_date);
- $date_split = explode('/', $date_array);
- $dst_s = $date_split[0];
- $dst_m = $date_split[1];
- $dst_h = $date_split[2];
- $dst_day = $date_split[3];
- $dst_mth = $date_split[4];
- $dst_yr = $date_split[5];
- $dst_date = mktime($dst_h, $dst_m, $dst_s, $dst_mth, $dst_day, $dst_yr);
- $time = $offset = time() - $dst_date;
-
- $act_day = date('d');
- $act_mth = date('n');
- $act_yr = date('Y');
- if ($dst_day == $act_day && $dst_mth == $act_mth && $dst_yr == $act_yr) {
- return $today;
- }
- if ($dst_day == $act_day - 1 && $dst_mth == $act_mth && $dst_yr == $act_yr) {
- return $yesterday;
- }
- $str_result = array();
- $time_result = array();
- $key_result = array();
- $str = '';
- $i = 0;
- for ($i = 0; $i < count($sec_time_time); $i++) {
- $seconds = $sec_time_time[$i];
- if ($seconds > $time) {
- continue;
- }
- $current_value = intval($time/$seconds);
- if ($current_value != 1) {
- $date_str = $sec_time_plu[$i];
- } else {
- $date_str = $sec_time_sing[$i];
- }
- $key_result[] = $sec_time_sing[$i];
- $str_result[] = $current_value.' '.$date_str;
- $time_result[] = $current_value;
- $str .= $current_value.$date_str;
- $time %= $seconds;
- }
- if ($key_result[0] == $min_day && $key_result[1]== $min_minute) {
- $key_result[1] = ' 0 '.$min_hours;
- $str_result[0] = $time_result[0].' '.$key_result[0];
- $str_result[1] = $key_result[1];
- }
- if ($key_result[0] == $min_year && ($key_result[1] == $min_day || $key_result[1] == $min_week)) {
- $key_result[1] = ' 0 '.$min_months;
- $str_result[0] = $time_result[0].' '.$key_result[0];
- $str_result[1] = $key_result[1];
- }
- if (!empty($str_result[1])) {
- $str = $str_result[0].', '.$str_result[1];
- } else {
- $str = $str_result[0];
- }
- date_default_timezone_set($system_timezone);
- return $str;
- }
- function api_convert_and_format_date($time = null, $format = null, $from_timezone = null) {
-
- $time = api_get_local_time($time, null, $from_timezone);
-
- return api_format_date($time, $format);
- }
- function api_get_week_days_short($language = null) {
- $days = &_api_get_day_month_names($language);
- return $days['days_short'];
- }
- function api_get_week_days_long($language = null) {
- $days = &_api_get_day_month_names($language);
- return $days['days_long'];
- }
- function api_get_months_short($language = null) {
- $months = &_api_get_day_month_names($language);
- return $months['months_short'];
- }
- function api_get_months_long($language = null) {
- $months = &_api_get_day_month_names($language);
- return $months['months_long'];
- }
- function api_get_person_name($first_name, $last_name, $title = null, $format = null, $language = null, $encoding = null, $username = null) {
- static $valid = array();
- if (empty($format)) {
- $format = PERSON_NAME_COMMON_CONVENTION;
- }
-
- $language_is_supported = api_is_language_supported($language);
- if (!$language_is_supported || empty($language)) {
- $language = api_get_interface_language(false, true);
- }
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (!isset($valid[$format][$language])) {
- if (is_int($format)) {
- switch ($format) {
- case PERSON_NAME_COMMON_CONVENTION:
- $valid[$format][$language] = _api_get_person_name_convention($language, 'format');
- $usernameOrderFromDatabase = api_get_setting('user_name_order');
- if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) {
- $valid[$format][$language] = $usernameOrderFromDatabase;
- }
- break;
- case PERSON_NAME_WESTERN_ORDER:
- $valid[$format][$language] = '%t %f %l';
- break;
- case PERSON_NAME_EASTERN_ORDER:
- $valid[$format][$language] = '%t %l %f';
- break;
- case PERSON_NAME_LIBRARY_ORDER:
- $valid[$format][$language] = '%t %l, %f';
- break;
- default:
- $valid[$format][$language] = '%t %f %l';
- break;
- }
- } else {
- $valid[$format][$language] = _api_validate_person_name_format($format);
- }
- }
- $format = $valid[$format][$language];
- $keywords = array('%firstname', '%f', '%F', '%lastname', '%l', '%L', '%title', '%t', '%T', '%username', '%u', '%U');
- $values = array(
- $first_name,
- $first_name,
- api_strtoupper($first_name, $encoding),
- $last_name,
- $last_name,
- api_strtoupper($last_name, $encoding),
- $title,
- $title,
- api_strtoupper($title, $encoding),
- $username,
- $username,
- api_strtoupper($username, $encoding),
- );
- $person_name = str_replace($keywords, $values, $format);
- return _api_clean_person_name($person_name);
- }
- function api_is_western_name_order($format = null, $language = null) {
- static $order = array();
- if (empty($format)) {
- $format = PERSON_NAME_COMMON_CONVENTION;
- }
- $language_is_supported = api_is_language_supported($language);
- if (!$language_is_supported || empty($language)) {
- $language = api_get_interface_language(false, true);
- }
- if (!isset($order[$format][$language])) {
- $test_name = api_get_person_name('%f', '%l', '%t', $format, $language);
- $order[$format][$language] = stripos($test_name, '%f') <= stripos($test_name, '%l');
- }
- return $order[$format][$language];
- }
- function api_sort_by_first_name($language = null) {
- $userNameSortBy = api_get_setting('user_name_sort_by');
- if (!empty($userNameSortBy) && in_array($userNameSortBy, array('firstname', 'lastname'))) {
- return $userNameSortBy == 'firstname' ? true : false;
- }
- static $sort_by_first_name = array();
- $language_is_supported = api_is_language_supported($language);
- if (!$language_is_supported || empty($language)) {
- $language = api_get_interface_language(false, true);
- }
- if (!isset($sort_by_first_name[$language])) {
- $sort_by_first_name[$language] = _api_get_person_name_convention($language, 'sort_by');
- }
- return $sort_by_first_name[$language];
- }
- function api_byte_count(& $string) {
- static $use_mb_strlen;
- if (!isset($use_mb_strlen)) {
- $use_mb_strlen = MBSTRING_INSTALLED && ((int) ini_get('mbstring.func_overload') & 2);
- }
- if ($use_mb_strlen) {
- return mb_strlen($string, '8bit');
- }
- return strlen($string);
- }
- function api_convert_encoding($string, $to_encoding, $from_encoding = null) {
- if (empty($from_encoding)) {
- $from_encoding = _api_mb_internal_encoding();
- }
- if (api_equal_encodings($to_encoding, $from_encoding)) {
- return $string;
- }
- if (_api_mb_supports($to_encoding) && _api_mb_supports($from_encoding)) {
- return @mb_convert_encoding($string, $to_encoding, $from_encoding);
- }
- if (_api_iconv_supports($to_encoding) && _api_iconv_supports($from_encoding)) {
- return @iconv($from_encoding, $to_encoding, $string);
- }
- if (api_is_utf8($to_encoding) && api_is_latin1($from_encoding, true)) {
- return utf8_encode($string);
- }
- if (api_is_latin1($to_encoding, true) && api_is_utf8($from_encoding)) {
- return utf8_decode($string);
- }
- if (_api_convert_encoding_supports($to_encoding) && _api_convert_encoding_supports($from_encoding)) {
- return _api_convert_encoding($string, $to_encoding, $from_encoding);
- }
- return $string;
- }
- function api_utf8_encode($string, $from_encoding = null) {
- if (empty($from_encoding)) {
- $from_encoding = _api_mb_internal_encoding();
- }
- if (api_is_utf8($from_encoding)) {
- return $string;
- }
- if (_api_mb_supports($from_encoding)) {
- return @mb_convert_encoding($string, 'UTF-8', $from_encoding);
- }
- if (_api_iconv_supports($from_encoding)) {
- return @iconv($from_encoding, 'UTF-8', $string);
- }
- if (api_is_latin1($from_encoding, true)) {
- return utf8_encode($string);
- }
- if (_api_convert_encoding_supports($from_encoding)) {
- return _api_convert_encoding($string, 'UTF-8', $from_encoding);
- }
- return $string;
- }
- function api_utf8_decode($string, $to_encoding = null) {
- if (empty($to_encoding)) {
- $to_encoding = _api_mb_internal_encoding();
- }
- if (api_is_utf8($to_encoding)) {
- return $string;
- }
- if (_api_mb_supports($to_encoding)) {
- return @mb_convert_encoding($string, $to_encoding, 'UTF-8');
- }
- if (_api_iconv_supports($to_encoding)) {
- return @iconv('UTF-8', $to_encoding, $string);
- }
- if (api_is_latin1($to_encoding, true)) {
- return utf8_decode($string);
- }
- if (_api_convert_encoding_supports($to_encoding)) {
- return _api_convert_encoding($string, $to_encoding, 'UTF-8');
- }
- return $string;
- }
- function api_to_system_encoding($string, $from_encoding = null, $check_utf8_validity = false) {
- $system_encoding = api_get_system_encoding();
- if (empty($from_encoding)) {
- if (api_is_utf8($system_encoding)) {
- $from_encoding = api_get_non_utf8_encoding();
- } else {
- $from_encoding = 'UTF-8';
- }
- }
- if (api_equal_encodings($system_encoding, $from_encoding)) {
- return $string;
- }
- if ($check_utf8_validity) {
- if (api_is_utf8($system_encoding)) {
- if (api_is_valid_utf8($string)) {
- return $string;
- }
- } elseif (api_is_utf8($from_encoding)) {
- if (!api_is_valid_utf8($string)) {
- return $string;
- }
- }
- }
- return api_convert_encoding($string, $system_encoding, $from_encoding);
- }
- function api_htmlentities($string, $quote_style = ENT_COMPAT, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (!api_is_utf8($encoding) && _api_html_entity_supports($encoding)) {
- return htmlentities($string, $quote_style, $encoding);
- }
- switch($quote_style) {
- case ENT_COMPAT:
- $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
- break;
- case ENT_QUOTES:
- $string = str_replace(array('&', '\'', '"', '<', '>'), array('&', ''', '"', '<', '>'), $string);
- break;
- }
- if (_api_mb_supports($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- $string = @mb_convert_encoding(api_utf8_encode($string, $encoding), 'HTML-ENTITIES', 'UTF-8');
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_decode($string, $encoding);
- }
- } elseif (_api_convert_encoding_supports($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = _api_convert_encoding($string, 'UTF-8', $encoding);
- }
- $string = implode(array_map('_api_html_entity_from_unicode', _api_utf8_to_unicode($string)));
- if (!api_is_utf8($encoding)) {
- $string = _api_convert_encoding($string, $encoding, 'UTF-8');
- }
- }
- return $string;
- }
- function api_html_entity_decode($string, $quote_style = ENT_COMPAT, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_html_entity_supports($encoding)) {
- return html_entity_decode($string, $quote_style, $encoding);
- }
- if (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- $string = html_entity_decode($string, $quote_style, 'UTF-8');
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- return $string;
- }
- function api_xml_http_response_encode($string, $from_encoding = null) {
- if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
- if (empty($from_encoding)) {
- $from_encoding = _api_mb_internal_encoding();
- }
- if (!api_is_utf8($from_encoding)) {
- return api_utf8_encode($string, $from_encoding);
- }
- }
- return $string;
- }
- function api_file_system_encode($string, $from_encoding = null) {
- if (empty($from_encoding)) {
- $from_encoding = _api_mb_internal_encoding();
- }
- return api_convert_encoding($string, api_get_file_system_encoding(), $from_encoding);
- }
- function api_file_system_decode($string, $to_encoding = null) {
- if (empty($to_encoding)) {
- $to_encoding = _api_mb_internal_encoding();
- }
- return api_convert_encoding($string, $to_encoding, api_get_file_system_encoding());
- }
- function api_transliterate($string, $unknown = '?', $from_encoding = null) {
- static $map = array();
- $string = api_utf8_encode($string, $from_encoding);
-
- $string = preg_replace('/[\x00-\x08\x0b\x0c\x0e-\x1f]/', $unknown, $string);
-
-
-
- if (api_is_valid_ascii($string)) {
- return $string;
- }
- static $tail_bytes;
- if (!isset($tail_bytes)) {
-
-
- $tail_bytes = array();
- for ($n = 0; $n < 256; $n++) {
- if ($n < 0xc0) {
- $remaining = 0;
- }
- elseif ($n < 0xe0) {
- $remaining = 1;
- }
- elseif ($n < 0xf0) {
- $remaining = 2;
- }
- elseif ($n < 0xf8) {
- $remaining = 3;
- }
- elseif ($n < 0xfc) {
- $remaining = 4;
- }
- elseif ($n < 0xfe) {
- $remaining = 5;
- } else {
- $remaining = 0;
- }
- $tail_bytes[chr($n)] = $remaining;
- }
- }
-
-
-
-
- preg_match_all('/[\x00-\x7f]+|[\x80-\xff][\x00-\x40\x5b-\x5f\x7b-\xff]*/', $string, $matches);
- $result = '';
- foreach ($matches[0] as $str) {
- if ($str{0} < "\x80") {
-
-
- $result .= $str;
- continue;
- }
-
-
-
-
-
-
- $head = '';
- $chunk = api_byte_count($str);
-
- $len = $chunk + 1;
- for ($i = -1; --$len; ) {
- $c = $str{++$i};
- if ($remaining = $tail_bytes[$c]) {
-
- $sequence = $head = $c;
- do {
-
- if (--$len && ($c = $str{++$i}) >= "\x80" && $c < "\xc0") {
-
- $sequence .= $c;
- } else {
- if ($len == 0) {
-
-
-
- $result .= $unknown;
- break 2;
- } else {
-
- $result .= $unknown;
-
-
- --$i;
- ++$len;
- continue 2;
- }
- }
- } while (--$remaining);
- $n = ord($head);
- if ($n <= 0xdf) {
- $ord = ($n - 192) * 64 + (ord($sequence{1}) - 128);
- }
- else if ($n <= 0xef) {
- $ord = ($n - 224) * 4096 + (ord($sequence{1}) - 128) * 64 + (ord($sequence{2}) - 128);
- }
- else if ($n <= 0xf7) {
- $ord = ($n - 240) * 262144 + (ord($sequence{1}) - 128) * 4096 + (ord($sequence{2}) - 128) * 64 + (ord($sequence{3}) - 128);
- }
- else if ($n <= 0xfb) {
- $ord = ($n - 248) * 16777216 + (ord($sequence{1}) - 128) * 262144 + (ord($sequence{2}) - 128) * 4096 + (ord($sequence{3}) - 128) * 64 + (ord($sequence{4}) - 128);
- }
- else if ($n <= 0xfd) {
- $ord = ($n - 252) * 1073741824 + (ord($sequence{1}) - 128) * 16777216 + (ord($sequence{2}) - 128) * 262144 + (ord($sequence{3}) - 128) * 4096 + (ord($sequence{4}) - 128) * 64 + (ord($sequence{5}) - 128);
- }
-
- $bank = $ord >> 8;
-
- if (!isset($map[$bank])) {
- $file = dirname(__FILE__).'/internationalization_database/transliteration/' . sprintf('x%02x', $bank) . '.php';
- if (file_exists($file)) {
- $map[$bank] = include ($file);
- } else {
- $map[$bank] = array('en' => array());
- }
- }
- $ord = $ord & 255;
- $result .= isset($map[$bank]['en'][$ord]) ? $map[$bank]['en'][$ord] : $unknown;
- $head = '';
- } elseif ($c < "\x80") {
-
- $result .= $c;
- $head = '';
- } elseif ($c < "\xc0") {
-
- if ($head == '') {
- $result .= $unknown;
- }
- } else {
-
- $result .= $unknown;
- $head = '';
- }
- }
- }
- return $result;
- }
- function api_ord($character, $encoding) {
- return _api_utf8_ord(api_utf8_encode($character, $encoding));
- }
- function api_chr($codepoint, $encoding) {
- return api_utf8_decode(_api_utf8_chr($codepoint), $encoding);
- }
- function api_str_ireplace($search, $replace, $subject, & $count = null, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (api_is_encoding_supported($encoding)) {
- if (!is_array($search) && !is_array($replace)) {
- if (!api_is_utf8($encoding)) {
- $search = api_utf8_encode($search, $encoding);
- }
- $slen = api_byte_count($search);
- if ( $slen == 0 ) {
- return $subject;
- }
- if (!api_is_utf8($encoding)) {
- $replace = api_utf8_encode($replace, $encoding);
- $subject = api_utf8_encode($subject, $encoding);
- }
- $lendif = api_byte_count($replace) - api_byte_count($search);
- $search = api_strtolower($search, 'UTF-8');
- $search = preg_quote($search);
- $lstr = api_strtolower($subject, 'UTF-8');
- $i = 0;
- $matched = 0;
- while (preg_match('/(.*)'.$search.'/Us', $lstr, $matches) ) {
- if ($i === $count) {
- break;
- }
- $mlen = api_byte_count($matches[0]);
- $lstr = substr($lstr, $mlen);
- $subject = substr_replace($subject, $replace, $matched + api_byte_count($matches[1]), $slen);
- $matched += $mlen + $lendif;
- $i++;
- }
- if (!api_is_utf8($encoding)) {
- $subject = api_utf8_decode($subject, $encoding);
- }
- return $subject;
- } else {
- foreach (array_keys($search) as $k) {
- if (is_array($replace)) {
- if (array_key_exists($k, $replace)) {
- $subject = api_str_ireplace($search[$k], $replace[$k], $subject, $count);
- } else {
- $subject = api_str_ireplace($search[$k], '', $subject, $count);
- }
- } else {
- $subject = api_str_ireplace($search[$k], $replace, $subject, $count);
- }
- }
- return $subject;
- }
- }
- if (is_null($count)) {
- return str_ireplace($search, $replace, $subject);
- }
- return str_ireplace($search, $replace, $subject, $count);
- }
- function api_str_split($string, $split_length = 1, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (empty($string)) {
- return array();
- }
- if ($split_length < 1) {
- return false;
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return str_split($string, $split_length);
- }
- if (api_is_encoding_supported($encoding)) {
- $len = api_strlen($string);
- if ($len <= $split_length) {
- return array($string);
- }
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- if (preg_match_all('/.{'.$split_length.'}|[^\x00]{1,'.$split_length.'}$/us', $string, $result) === false) {
- return array();
- }
- if (!api_is_utf8($encoding)) {
- global $_api_encoding;
- $_api_encoding = $encoding;
- $result = _api_array_utf8_decode($result[0]);
- }
- return $result[0];
- }
- return str_split($string, $split_length);
- }
- function api_stripos($haystack, $needle, $offset = 0, $encoding = null) {
- if (_api_mb_supports($encoding)) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return mb_stripos($haystack, $needle, $offset, $encoding);
- }
- return stripos($haystack, $needle, $offset);
- }
- function api_stristr($haystack, $needle, $before_needle = false, $encoding = null) {
- if (_api_mb_supports($encoding)) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return mb_stristr($haystack, $needle, $before_needle, $encoding);
- }
- return stristr($haystack, $needle, $before_needle);
- }
- function api_strlen($string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return strlen($string);
- }
- if (_api_mb_supports($encoding)) {
- return @mb_strlen($string, $encoding);
- }
- if (_api_iconv_supports($encoding)) {
- return @iconv_strlen($string, $encoding);
- }
- return strlen($string);
- }
- function api_strpos($haystack, $needle, $offset = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return strpos($haystack, $needle, $offset);
- } elseif (_api_mb_supports($encoding)) {
- return mb_strpos($haystack, $needle, $offset, $encoding);
- }
- return strpos($haystack, $needle, $offset);
- }
- function api_strrchr($haystack, $needle, $before_needle = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_is_single_byte_encoding($encoding)) {
- if (!$before_needle) {
- return strrchr($haystack, $needle);
- }
- $result = strrchr($haystack, $needle);
- if ($result === false) {
- return false;
- }
- return api_substr($haystack, 0, api_strlen($haystack, $encoding) - api_strlen($result, $encoding), $encoding);
- } elseif (_api_mb_supports($encoding)) {
- return mb_strrchr($haystack, $needle, $before_needle, $encoding);
- }
- $result = strrchr($haystack, $needle);
- if ($result === false) {
- return false;
- }
- return api_substr($haystack, 0, api_strlen($haystack, $encoding) - api_strlen($result, $encoding), $encoding);
- }
- function api_strrev($string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (empty($string)) {
- return '';
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return strrev($string);
- }
- if (api_is_encoding_supported($encoding)) {
- return implode(array_reverse(api_str_split($string, 1, $encoding)));
- }
- return strrev($string);
- }
- function api_strripos($haystack, $needle, $offset = 0, $encoding = null)
- {
- return api_strrpos(api_strtolower($haystack, $encoding), api_strtolower($needle, $encoding), $offset, $encoding);
- }
- function api_strrpos($haystack, $needle, $offset = 0, $encoding = null)
- {
- if (_api_mb_supports($encoding)) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return mb_strrpos($haystack, $needle, $offset, $encoding);
- }
- return strrpos($haystack, $needle, $offset);
- }
- function api_strstr($haystack, $needle, $before_needle = false, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (!is_string($needle)) {
- $needle = (int)$needle;
- if (api_is_utf8($encoding)) {
- $needle = _api_utf8_chr($needle);
- } else {
- $needle = chr($needle);
- }
- }
- if ($needle == '') {
- return false;
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return strstr($haystack, $needle, $before_needle);
- }
- if (_api_mb_supports($encoding)) {
- return mb_strstr($haystack, $needle, $before_needle, $encoding);
- }
- return strstr($haystack, $needle, $before_needle);
- }
- function api_strtolower($string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_mb_supports($encoding)) {
- return mb_strtolower($string, $encoding);
- }
- return strtolower($string);
- }
- function api_strtoupper($string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_mb_supports($encoding)) {
- return mb_strtoupper($string, $encoding);
- }
- return strtoupper($string);
- }
- function api_substr($string, $start, $length = null, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
-
- if (is_null($length)) {
- $length = api_strlen($string, $encoding);
- }
- if (_api_is_single_byte_encoding($encoding)) {
- return substr($string, $start, $length);
- }
- if (_api_mb_supports($encoding)) {
- return mb_substr($string, $start, $length, $encoding);
- }
- return substr($string, $start, $length);
- }
- function api_substr_count($haystack, $needle, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_mb_supports($encoding)) {
- return mb_substr_count($haystack, $needle, $encoding);
- }
- return substr_count($haystack, $needle);
- }
- function api_substr_replace($string, $replacement, $start, $length = null, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_is_single_byte_encoding($encoding)) {
- if (is_null($length)) {
- return substr_replace($string, $replacement, $start);
- }
- return substr_replace($string, $replacement, $start, $length);
- }
- if (api_is_encoding_supported($encoding)) {
- if (is_null($length)) {
- $length = api_strlen($string);
- }
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- $replacement = api_utf8_encode($replacement, $encoding);
- }
- $string = _api_utf8_to_unicode($string);
- array_splice($string, $start, $length, _api_utf8_to_unicode($replacement));
- $string = _api_utf8_from_unicode($string);
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- if (is_null($length)) {
- return substr_replace($string, $replacement, $start);
- }
- return substr_replace($string, $replacement, $start, $length);
- }
- function api_ucfirst($string, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return api_strtoupper(api_substr($string, 0, 1, $encoding), $encoding) . api_substr($string, 1, api_strlen($string, $encoding), $encoding);
- }
- function api_ucwords($string, $encoding = null) {
- if (_api_mb_supports($encoding)) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return mb_convert_case($string, MB_CASE_TITLE, $encoding);
- }
- return ucwords($string);
- }
- function api_preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return preg_match(api_is_utf8($encoding) ? $pattern.'u' : $pattern, $subject, $matches, $flags, $offset);
- }
- function api_preg_match_all($pattern, $subject, &$matches, $flags = PREG_PATTERN_ORDER, $offset = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (is_null($flags)) {
- $flags = PREG_PATTERN_ORDER;
- }
- return preg_match_all(api_is_utf8($encoding) ? $pattern.'u' : $pattern, $subject, $matches, $flags, $offset);
- }
- function api_preg_replace($pattern, $replacement, $subject, $limit = -1, &$count = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $is_utf8 = api_is_utf8($encoding);
- if (is_array($pattern)) {
- foreach ($pattern as &$p) {
- $p = $is_utf8 ? $p.'u' : $p;
- }
- } else {
- $pattern = $is_utf8 ? $pattern.'u' : $pattern;
- }
- return preg_replace($pattern, $replacement, $subject, $limit, $count);
- }
- function api_preg_replace_callback($pattern, $callback, $subject, $limit = -1, &$count = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (is_array($pattern)) {
- foreach ($pattern as &$p) {
- $p = api_is_utf8($encoding) ? $p.'u' : $p;
- }
- } else {
- $pattern = api_is_utf8($encoding) ? $pattern.'u' : $pattern;
- }
- return preg_replace_callback($pattern, $callback, $subject, $limit, $count);
- }
- function api_preg_split($pattern, $subject, $limit = -1, $flags = 0, $encoding = null) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- return preg_split(api_is_utf8($encoding) ? $pattern.'u' : $pattern, $subject, $limit, $flags);
- }
- function api_ereg($pattern, $string, & $regs = null) {
- $count = func_num_args();
- $encoding = _api_mb_regex_encoding();
- if (_api_mb_supports($encoding)) {
- if ($count < 3) {
- return @mb_ereg($pattern, $string);
- }
- return @mb_ereg($pattern, $string, $regs);
- }
- if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- global $_api_encoding;
- $_api_encoding = $encoding;
- _api_mb_regex_encoding('UTF-8');
- if ($count < 3) {
- $result = @mb_ereg(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
- } else {
- $result = @mb_ereg(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $regs);
- $regs = _api_array_utf8_decode($regs);
- }
- _api_mb_regex_encoding($encoding);
- return $result;
- }
- if ($count < 3) {
- return ereg($pattern, $string);
- }
- return ereg($pattern, $string, $regs);
- }
- function api_ereg_replace($pattern, $replacement, $string, $option = null) {
- $encoding = _api_mb_regex_encoding();
- if (_api_mb_supports($encoding)) {
- if (is_null($option)) {
- return @mb_ereg_replace($pattern, $replacement, $string);
- }
- return @mb_ereg_replace($pattern, $replacement, $string, $option);
- }
- if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- _api_mb_regex_encoding('UTF-8');
- if (is_null($option)) {
- $result = api_utf8_decode(@mb_ereg_replace(api_utf8_encode($pattern, $encoding), api_utf8_encode($replacement, $encoding), api_utf8_encode($string, $encoding)), $encoding);
- } else {
- $result = api_utf8_decode(@mb_ereg_replace(api_utf8_encode($pattern, $encoding), api_utf8_encode($replacement, $encoding), api_utf8_encode($string, $encoding), $option), $encoding);
- }
- _api_mb_regex_encoding($encoding);
- return $result;
- }
- return ereg_replace($pattern, $replacement, $string);
- }
- function api_eregi($pattern, $string, & $regs = null) {
- $count = func_num_args();
- $encoding = _api_mb_regex_encoding();
- if (_api_mb_supports($encoding)) {
- if ($count < 3) {
- return @mb_eregi($pattern, $string);
- }
- return @mb_eregi($pattern, $string, $regs);
- }
- if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- global $_api_encoding;
- $_api_encoding = $encoding;
- _api_mb_regex_encoding('UTF-8');
- if ($count < 3) {
- $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
- } else {
- $result = @mb_eregi(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $regs);
- $regs = _api_array_utf8_decode($regs);
- }
- _api_mb_regex_encoding($encoding);
- return $result;
- }
- if ($count < 3) {
- return eregi($pattern, $string);
- }
- return eregi($pattern, $string, $regs);
- }
- function api_eregi_replace($pattern, $replacement, $string, $option = null) {
- $encoding = _api_mb_regex_encoding();
- if (_api_mb_supports($encoding)) {
- if (is_null($option)) {
- return @mb_eregi_replace($pattern, $replacement, $string);
- }
- return @mb_eregi_replace($pattern, $replacement, $string, $option);
- }
- if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- _api_mb_regex_encoding('UTF-8');
- if (is_null($option)) {
- $result = api_utf8_decode(@mb_eregi_replace(api_utf8_encode($pattern, $encoding), api_utf8_encode($replacement, $encoding), api_utf8_encode($string, $encoding)), $encoding);
- } else {
- $result = api_utf8_decode(@mb_eregi_replace(api_utf8_encode($pattern, $encoding), api_utf8_encode($replacement, $encoding), api_utf8_encode($string, $encoding), $option), $encoding);
- }
- _api_mb_regex_encoding($encoding);
- return $result;
- }
- return eregi_replace($pattern, $replacement, $string);
- }
- function api_split($pattern, $string, $limit = null) {
- $encoding = _api_mb_regex_encoding();
- if (_api_mb_supports($encoding)) {
- if (is_null($limit)) {
- return @mb_split($pattern, $string);
- }
- return @mb_split($pattern, $string, $limit);
- }
- if (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- global $_api_encoding;
- $_api_encoding = $encoding;
- _api_mb_regex_encoding('UTF-8');
- if (is_null($limit)) {
- $result = @mb_split(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding));
- } else {
- $result = @mb_split(api_utf8_encode($pattern, $encoding), api_utf8_encode($string, $encoding), $limit);
- }
- $result = _api_array_utf8_decode($result);
- _api_mb_regex_encoding($encoding);
- return $result;
- }
- if (is_null($limit)) {
- return split($pattern, $string);
- }
- return split($pattern, $string, $limit);
- }
- function api_strcasecmp($string1, $string2, $language = null, $encoding = null) {
- return api_strcmp(api_strtolower($string1, $encoding), api_strtolower($string2, $encoding), $language, $encoding);
- }
- function api_strcmp($string1, $string2, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- $result = collator_compare($collator, api_utf8_encode($string1, $encoding), api_utf8_encode($string2, $encoding));
- return $result === false ? 0 : $result;
- }
- }
- return strcmp($string1, $string2);
- }
- function api_strnatcasecmp($string1, $string2, $language = null, $encoding = null) {
- return api_strnatcmp(api_strtolower($string1, $encoding), api_strtolower($string2, $encoding), $language, $encoding);
- }
- function api_strnatcmp($string1, $string2, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- $result = collator_compare($collator, api_utf8_encode($string1, $encoding), api_utf8_encode($string2, $encoding));
- return $result === false ? 0 : $result;
- }
- }
- return strnatcmp($string1, $string2);
- }
- function api_asort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if (api_is_utf8($encoding)) {
- $sort_flag = ($sort_flag == SORT_LOCALE_STRING) ? SORT_STRING : $sort_flag;
- return collator_asort($collator, $array, _api_get_collator_sort_flag($sort_flag));
- }
- elseif ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_cmp');
- }
- }
- }
- return asort($array, $sort_flag);
- }
- function api_arsort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_rcmp');
- }
- }
- }
- return arsort($array, $sort_flag);
- }
- function api_natsort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_cmp');
- }
- }
- return natsort($array);
- }
- function api_natrsort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_rcmp');
- }
- }
- return uasort($array, '_api_strnatrcmp');
- }
- function api_natcasesort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_casecmp');
- }
- }
- return natcasesort($array);
- }
- function api_natcasersort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uasort($array, '_api_casercmp');
- }
- }
- return uasort($array, '_api_strnatcasercmp');
- }
- function api_ksort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_cmp');
- }
- }
- }
- return ksort($array, $sort_flag);
- }
- function api_krsort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_rcmp');
- }
- }
- }
- return krsort($array, $sort_flag);
- }
- function api_knatsort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_cmp');
- }
- }
- return uksort($array, 'strnatcmp');
- }
- function api_knatrsort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_rcmp');
- }
- }
- return uksort($array, '_api_strnatrcmp');
- }
- function api_knatcasesort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_casecmp');
- }
- }
- return uksort($array, 'strnatcasecmp');
- }
- function api_knatcasersort(&$array, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_alpha_numerical_collator($language);
- if (is_object($collator)) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return uksort($array, '_api_casercmp');
- }
- }
- return uksort($array, '_api_strnatcasercmp');
- }
- function api_sort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if (api_is_utf8($encoding)) {
- $sort_flag = ($sort_flag == SORT_LOCALE_STRING) ? SORT_STRING : $sort_flag;
- return collator_sort($collator, $array, _api_get_collator_sort_flag($sort_flag));
- } elseif ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return usort($array, '_api_cmp');
- }
- }
- }
- return sort($array, $sort_flag);
- }
- function api_rsort(&$array, $sort_flag = SORT_REGULAR, $language = null, $encoding = null) {
- if (INTL_INSTALLED) {
- if (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- $collator = _api_get_collator($language);
- if (is_object($collator)) {
- if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
- global $_api_collator, $_api_encoding;
- $_api_collator = $collator;
- $_api_encoding = $encoding;
- return usort($array, '_api_rcmp');
- }
- }
- }
- return rsort($array, $sort_flag);
- }
- function api_in_array_nocase($needle, $haystack, $strict = false, $encoding = null) {
- if (is_array($needle)) {
- foreach ($needle as $item) {
- if (api_in_array_nocase($item, $haystack, $strict, $encoding)) return true;
- }
- return false;
- }
- if (!is_string($needle)) {
- return in_array($needle, $haystack, $strict);
- }
- $needle = api_strtolower($needle, $encoding);
- if (!is_array($haystack)) {
- return false;
- }
- foreach ($haystack as $item) {
- if ($strict && !is_string($item)) {
- continue;
- }
- if (api_strtolower($item, $encoding) == $needle) {
- return true;
- }
- }
- return false;
- }
- function api_refine_encoding_id($encoding) {
- if (is_array($encoding)){
- return array_map('api_refine_encoding_id', $encoding);
- }
- return strtoupper(str_replace('_', '-', $encoding));
- }
- function api_equal_encodings($encoding1, $encoding2, $strict = false) {
- static $equal_encodings = array();
- if (is_array($encoding1)) {
- foreach ($encoding1 as $encoding) {
- if (api_equal_encodings($encoding, $encoding2, $strict)) {
- return true;
- }
- }
- return false;
- }
- elseif (is_array($encoding2)) {
- foreach ($encoding2 as $encoding) {
- if (api_equal_encodings($encoding1, $encoding, $strict)) {
- return true;
- }
- }
- return false;
- }
- if (!isset($equal_encodings[$encoding1][$encoding2][$strict])) {
- $encoding_1 = api_refine_encoding_id($encoding1);
- $encoding_2 = api_refine_encoding_id($encoding2);
- if ($encoding_1 == $encoding_2) {
- $result = true;
- } else {
- if ($strict) {
- $result = false;
- } else {
- $alias1 = _api_get_character_map_name($encoding_1);
- $alias2 = _api_get_character_map_name($encoding_2);
- $result = !empty($alias1) && !empty($alias2) && $alias1 == $alias2;
- }
- }
- $equal_encodings[$encoding1][$encoding2][$strict] = $result;
- }
- return $equal_encodings[$encoding1][$encoding2][$strict];
- }
- function api_is_utf8($encoding) {
- static $result = array();
- if (!isset($result[$encoding])) {
- $result[$encoding] = api_equal_encodings($encoding, 'UTF-8');
- }
- return $result[$encoding];
- }
- function api_is_latin1($encoding, $strict = false) {
- static $latin1 = array();
- static $latin1_strict = array();
- if ($strict) {
- if (!isset($latin1_strict[$encoding])) {
- $latin1_strict[$encoding] = api_equal_encodings($encoding, array('ISO-8859-1', 'ISO8859-1', 'CP819', 'LATIN1'));
- }
- return $latin1_strict[$encoding];
- }
- if (!isset($latin1[$encoding])) {
- $latin1[$encoding] = api_equal_encodings($encoding, array(
- 'ISO-8859-1', 'ISO8859-1', 'CP819', 'LATIN1',
- 'ISO-8859-15', 'ISO8859-15', 'CP923', 'LATIN0', 'LATIN-9',
- 'WINDOWS-1252', 'CP1252', 'WIN-1252', 'WIN1252'
- ));
- }
- return $latin1[$encoding];
- }
- function api_get_system_encoding() {
- static $system_encoding;
- if (!isset($system_encoding)) {
- $encoding_setting = api_get_setting('platform_charset');
- if (empty($encoding_setting)) {
- global $charset;
- if (empty($charset)) {
- return _api_mb_internal_encoding();
- }
- return $charset;
- }
- $system_encoding = $encoding_setting;
- }
- return $system_encoding;
- }
- function api_get_file_system_encoding() {
- static $file_system_encoding;
- if (!isset($file_system_encoding)) {
- $locale = setlocale(LC_CTYPE, '0');
- $seek_pos = strpos($locale, '.');
- if ($seek_pos !== false) {
- $file_system_encoding = substr($locale, $seek_pos + 1);
- if (IS_WINDOWS_OS) {
- $file_system_encoding = 'CP'.$file_system_encoding;
- }
- }
-
- $file_system_encoding = str_ireplace('utf8', 'UTF-8', $file_system_encoding);
- $file_system_encoding = preg_replace('/^CP65001$/', 'UTF-8', $file_system_encoding);
- $file_system_encoding = preg_replace('/^CP(125[0-9])$/', 'WINDOWS-\1', $file_system_encoding);
- $file_system_encoding = str_replace('WINDOWS-1252', 'ISO-8859-15', $file_system_encoding);
- if (empty($file_system_encoding)) {
- if (IS_WINDOWS_OS) {
-
- $file_system_encoding = api_get_system_encoding();
- } else {
-
- $file_system_encoding = 'UTF-8';
- }
- }
- }
- return $file_system_encoding;
- }
- function api_is_encoding_supported($encoding) {
- static $supported = array();
- if (!isset($supported[$encoding])) {
- $supported[$encoding] = _api_mb_supports($encoding) || _api_iconv_supports($encoding) || _api_convert_encoding_supports($encoding);
- }
- return $supported[$encoding];
- }
- function api_get_non_utf8_encoding($language = null)
- {
- $language_is_supported = api_is_language_supported($language);
- if (!$language_is_supported || empty($language)) {
- $language = api_get_interface_language(false, true);
- }
- $language = api_purify_language_id($language);
- $encodings = & _api_non_utf8_encodings();
- if (is_array($encodings[$language])) {
- if (!empty($encodings[$language][0])) {
- return $encodings[$language][0];
- }
- return null;
- }
- return null;
- }
- function api_get_valid_encodings() {
- $encodings = & _api_non_utf8_encodings();
- if (!is_array($encodings)) {
- $encodings = array('english', array('ISO-8859-15'));
- }
- $result1 = array();
- $result2 = array();
- $result3 = array();
- foreach ($encodings as $value) {
- if (!empty($value)) {
- $encoding = api_refine_encoding_id(trim($value[0]));
- if (!empty($encoding)) {
- if (strpos($encoding, 'ISO-') === 0) {
- $result1[] = $encoding;
- } elseif (strpos($encoding, 'WINDOWS-') === 0) {
- $result2[] = $encoding;
- } else {
- $result3[] = $encoding;
- }
- }
- }
- }
- $result1 = array_unique($result1);
- $result2 = array_unique($result2);
- $result3 = array_unique($result3);
- natsort($result1);
- natsort($result2);
- natsort($result3);
- return array_merge(array('UTF-8'), $result1, $result2, $result3);
- }
- function api_detect_encoding($string, $language = null) {
-
- if (api_is_valid_utf8($string)) {
- return 'UTF-8';
- }
- $result = null;
- $delta_points_min = LANGUAGE_DETECT_MAX_DELTA;
-
- $encodings = api_get_valid_encodings();
- foreach ($encodings as & $encoding) {
- if (api_is_encoding_supported($encoding) && !api_is_utf8($encoding)) {
- $stringToParse = api_substr($string, 0, LANGUAGE_DETECT_MAX_LENGTH, $encoding);
- $strintToParse2 = _api_generate_n_grams(
- $stringToParse,
- $encoding
- );
- $result_array = _api_compare_n_grams(
- $strintToParse2,
- $encoding
- );
- if (!empty($result_array)) {
- list($key, $delta_points) = each($result_array);
- if ($delta_points < $delta_points_min) {
- $pos = strpos($key, ':');
- $result_encoding = api_refine_encoding_id(substr($key, $pos + 1));
- if (api_equal_encodings($encoding, $result_encoding)) {
- if ($string == api_utf8_decode(api_utf8_encode($string, $encoding), $encoding)) {
- $delta_points_min = $delta_points;
- $result = $encoding;
- }
- }
- }
- }
- }
- }
-
-
- $language = api_purify_language_id((string)$language);
- if (!empty($language)) {
- $encoding = 'UTF-8';
- $result_array = & _api_compare_n_grams(_api_generate_n_grams(api_substr($string, 0, LANGUAGE_DETECT_MAX_LENGTH, $encoding), $encoding), $encoding);
- if (!empty($result_array)) {
- list($key, $delta_points) = each($result_array);
- if ($delta_points < $delta_points_min) {
- $pos = strpos($key, ':');
- $result_encoding = api_refine_encoding_id(substr($key, $pos + 1));
- $result_language = substr($key, 0, $pos);
- if ($language == $result_language && api_is_utf8($result_encoding)) {
- $delta_points_min = $delta_points;
- $result = $encoding;
- }
- }
- }
- }
- return $result;
- }
- function api_is_valid_utf8(&$string) {
- return Encoding::utf8()->is_valid($string);
- }
- function api_is_valid_ascii(&$string) {
- if (MBSTRING_INSTALLED) {
- return @mb_detect_encoding($string, 'ASCII', true) == 'ASCII' ? true : false;
- }
- return !preg_match('/[^\x00-\x7F]/S', $string);
- }
- function api_is_valid_date($date, $format = 'Y-m-d H:i:s') {
- $d = DateTime::createFromFormat($format, $date);
- return $d && $d->format($format) == $date;
- }
- function get_datepicker_langage_code() {
- $languaje = 'en-GB';
- $platform_isocode = strtolower(api_get_language_isocode());
-
- $datapicker_langs = array('af', 'ar', 'ar-DZ', 'az', 'bg', 'bs', 'ca', 'cs', 'cy-GB', 'da', 'de', 'el', 'en-AU', 'en-GB', 'en-NZ', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr', 'fr-CH', 'gl', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kk', 'km', 'ko', 'lb', 'lt', 'lv', 'mk', 'ml', 'ms', 'nl', 'nl-BE', 'no', 'pl', 'pt', 'pt-BR', 'rm', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sr-SR', 'sv', 'ta', 'th', 'tj', 'tr', 'uk', 'vi', 'zh-CN', 'zh-HK', 'zh-TW');
- if (in_array($platform_isocode, $datapicker_langs)) {
- $languaje = $platform_isocode;
- }
- return $languaje;
- }
- function get_plugin_lang($variable, $pluginName) {
- eval("\$plugin = {$pluginName}::create();");
- return $plugin->get_lang($variable);
- }
- require_once dirname(__FILE__).'/internationalization_internal.lib.php';
|