123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029 |
- <?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 $app;
- $translated = $app['translator']->trans($variable);
- if ($translated == $variable) {
- $translated = $app['translator']->trans("lang$variable");
- if ($translated == "lang$variable") {
- return $variable;
- }
- }
- return $translated;
- $language_interface = api_get_language_interface();
- global
-
-
-
-
- $language_interface_initial_value,
-
- $_api_is_translated, $_api_is_translated_call, $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 = false;
- $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 (!$test_server_mode) { $read_global_variables = false;
- 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()
- {
- $user_id = api_get_user_id();
-
- $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_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 (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_NUMBER_NO_YEAR:
- $date_format = get_lang('dateFormatShortNumberNoYear', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_NUMBER:
- $date_format = get_lang('dateFormatShortNumber', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::SHORT;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case TIME_NO_SEC_FORMAT:
- $date_format = get_lang('timeNoSecFormat', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::NONE;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_FORMAT_SHORT:
- $date_format = get_lang('dateFormatShort', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::LONG;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_FORMAT_LONG:
- $date_format = get_lang('dateFormatLong', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::NONE;
- }
- break;
- case DATE_TIME_FORMAT_LONG:
- $date_format = get_lang('dateTimeFormatLong', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_FORMAT_LONG_NO_DAY:
- $date_format = get_lang('dateFormatLongNoDay', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_SHORT:
- $date_format = get_lang('dateTimeFormatShort', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_SHORT_TIME_FIRST:
- $date_format = get_lang('dateTimeFormatShortTimeFirst', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- case DATE_TIME_FORMAT_LONG_24H:
- $date_format = get_lang('dateTimeFormatLong24H', '', $language);
- if (IS_PHP_53 && INTL_INSTALLED) {
- $datetype = IntlDateFormatter::FULL;
- $timetype = IntlDateFormatter::SHORT;
- }
- break;
- default:
- $date_format = get_lang('dateTimeFormatLong', '', $language);
- if (IS_PHP_53 && 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)
- {
- 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');
- $username_order_from_database = api_get_setting('user_name_order');
- if (isset($username_order_from_database) && !empty($username_order_from_database)) {
- if (strpos($username_order_from_database, '%t') == false || strpos(
- $username_order_from_database,
- '%l'
- ) == false || strpos($username_order_from_database, '%f') == false
- ) {
- $valid[$format][$language] = $username_order_from_database;
- }
- }
- 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];
- $person_name = str_replace(array('%f', '%l', '%t'), array($first_name, $last_name, $title), $format);
- if (strpos($format, '%F') !== false || strpos($format, '%L') !== false || strpos($format, '%T') !== false) {
- $person_name = str_replace(
- array(
- '%F',
- '%L',
- '%T'
- ),
- array(
- api_strtoupper($first_name, $encoding),
- api_strtoupper($last_name, $encoding),
- api_strtoupper($title, $encoding)
- ),
- $person_name
- );
- }
- 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)
- {
- 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 (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_mb_supports($encoding)) {
- return @mb_stripos($haystack, $needle, $offset, $encoding);
- } elseif (api_is_encoding_supported($encoding)) {
- if (MBSTRING_INSTALLED) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
- return @mb_stripos($haystack, $needle, $offset, 'UTF-8');
- }
- return api_strpos(api_strtolower($haystack, $encoding), api_strtolower($needle, $encoding), $offset, $encoding);
- }
- return stripos($haystack, $needle, $offset);
- }
- function api_stristr($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_mb_supports($encoding)) {
- return @mb_stristr($haystack, $needle, $before_needle, $encoding);
- } elseif (api_is_encoding_supported($encoding)) {
- if (MBSTRING_INSTALLED) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
- $result = @mb_stristr($haystack, $needle, $before_needle, 'UTF-8');
- if ($result === false) {
- return false;
- }
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($result, $encoding);
- }
- return $result;
- }
- $result = api_strstr(
- api_strtolower($haystack, $encoding),
- api_strtolower($needle, $encoding),
- $before_needle,
- $encoding
- );
- if ($result === false) {
- return false;
- }
- if ($before_needle) {
- return api_substr($haystack, 0, api_strlen($result, $encoding), $encoding);
- }
- return api_substr(
- $haystack,
- api_strlen($haystack, $encoding) - api_strlen($result, $encoding),
- null,
- $encoding
- );
- }
- if (!IS_PHP_53) {
- return stristr($haystack, $needle);
- }
- 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);
- }
- if (api_is_utf8($encoding)) {
- return api_byte_count(preg_replace("/[\x80-\xBF]/", '', $string));
- }
- return strlen($string);
- }
- function api_strpos($haystack, $needle, $offset = 0, $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 strpos($haystack, $needle, $offset);
- } elseif (_api_mb_supports($encoding)) {
- return @mb_strpos($haystack, $needle, $offset, $encoding);
- } elseif (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
- if (MBSTRING_INSTALLED) {
- return @mb_strpos($haystack, $needle, $offset, 'UTF-8');
- }
- if (empty($offset)) {
- $haystack = explode($needle, $haystack, 2);
- if (count($haystack) > 1) {
- return api_strlen($haystack[0]);
- }
- return false;
- }
- $haystack = api_substr($haystack, $offset);
- if (($pos = api_strpos($haystack, $needle)) !== false) {
- return $pos + $offset;
- }
- return false;
- }
- return strpos($haystack, $needle, $offset);
- }
- function api_strrchr($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)) {
- 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);
- } elseif (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
- $result = @mb_strrchr($haystack, $needle, $before_needle, 'UTF-8');
- if ($result === false) {
- return false;
- }
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($result, $encoding);
- }
- return $result;
- }
- 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);
- }
- 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 (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 strrpos($haystack, $needle, $offset);
- }
- if (_api_mb_supports($encoding) && IS_PHP_52) {
- return @mb_strrpos($haystack, $needle, $offset, $encoding);
- } elseif (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
-
- if (MBSTRING_INSTALLED && IS_PHP_SUP_OR_EQ_51) {
-
-
- return @mb_strrpos($haystack, $needle, 'UTF-8');
- }
- if (MBSTRING_INSTALLED && IS_PHP_SUP_OR_EQ_52) {
- return @mb_strrpos($haystack, $needle, $offset, 'UTF-8');
- }
-
- $found = false;
- $haystack = _api_utf8_to_unicode($haystack);
- $haystack_count = count($haystack);
- $matches = array_count_values($haystack);
- $needle = _api_utf8_to_unicode($needle);
- $needle_count = count($needle);
- $position = $offset;
- while (($found === false) && ($position < $haystack_count)) {
- if (isset($needle[0]) && $needle[0] === $haystack[$position]) {
- for ($i = 1; $i < $needle_count; $i++) {
- if ($needle[$i] !== $haystack[$position + $i]) {
- if ($needle[$i] === $haystack[($position + $i) - 1]) {
- $position--;
- $found = true;
- continue;
- }
- }
- }
- if (!$offset && isset($matches[$needle[0]]) && $matches[$needle[0]] > 1) {
- $matches[$needle[0]] = $matches[$needle[0]] - 1;
- } elseif ($i === $needle_count) {
- $found = true;
- $position--;
- }
- }
- $position++;
- }
- return ($found) ? $position : false;
- }
- 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)) {
-
- if (!$before_needle) {
- return strstr($haystack, $needle);
- }
- if (!IS_PHP_53) {
- $result = explode($needle, $haystack, 2);
- if ($result === false || count($result) < 2) {
- return false;
- }
- return $result[0];
- }
- return strstr($haystack, $needle, $before_needle);
- }
- if (_api_mb_supports($encoding)) {
- return @mb_strstr($haystack, $needle, $before_needle, $encoding);
- } elseif (MBSTRING_INSTALLED && api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $haystack = api_utf8_encode($haystack, $encoding);
- $needle = api_utf8_encode($needle, $encoding);
- }
- $result = @mb_strstr($haystack, $needle, $before_needle, 'UTF-8');
- if ($result !== false) {
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($result, $encoding);
- }
- return $result;
- }
- return false;
- }
-
- if (!$before_needle) {
- return strstr($haystack, $needle);
- }
- if (!IS_PHP_53) {
- $result = explode($needle, $haystack, 2);
- if ($result === false || count($result) < 2) {
- return false;
- }
- return $result[0];
- }
- 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);
- } elseif (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- if (MBSTRING_INSTALLED) {
- $string = @mb_strtolower($string, 'UTF-8');
- } else {
-
- $codepoints = _api_utf8_to_unicode($string);
- $length = count($codepoints);
- $matched = false;
- $result = array();
- for ($i = 0; $i < $length; $i++) {
- $codepoint = $codepoints[$i];
- if ($codepoint < 128) {
- $str = strtolower(chr($codepoint));
- $strlen = api_byte_count($str);
- for ($ii = 0; $ii < $strlen; $ii++) {
- $lower = ord($str[$ii]);
- }
- $result[] = $lower;
- $matched = true;
- } else {
- $matched = false;
- $properties = & _api_utf8_get_letter_case_properties($codepoint, 'upper');
- if (!empty($properties)) {
- foreach ($properties as $key => $value) {
- if ($properties[$key]['upper'] == $codepoint && count(
- $properties[$key]['lower'][0]
- ) === 1
- ) {
- $result[] = $properties[$key]['lower'][0];
- $matched = true;
- break 1;
- }
- }
- }
- }
- if ($matched === false) {
- $result[] = $codepoint;
- }
- }
- $string = _api_utf8_from_unicode($result);
- }
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- 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);
- } elseif (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- if (MBSTRING_INSTALLED) {
- $string = @mb_strtoupper($string, 'UTF-8');
- } else {
-
- $codepoints = _api_utf8_to_unicode($string);
- $length = count($codepoints);
- $matched = false;
- $replaced = array();
- $result = array();
- for ($i = 0; $i < $length; $i++) {
- $codepoint = $codepoints[$i];
- if ($codepoint < 128) {
- $str = strtoupper(chr($codepoint));
- $strlen = api_byte_count($str);
- for ($ii = 0; $ii < $strlen; $ii++) {
- $lower = ord($str[$ii]);
- }
- $result[] = $lower;
- $matched = true;
- } else {
- $matched = false;
- $properties = & _api_utf8_get_letter_case_properties($codepoint);
- $property_count = count($properties);
- if (!empty($properties)) {
- foreach ($properties as $key => $value) {
- $matched = false;
- $replace = 0;
- if ($length > 1 && count($properties[$key]['lower']) > 1) {
- $j = 0;
- for ($ii = 0; $ii < count($properties[$key]['lower']); $ii++) {
- $next_codepoint = $next_codepoints[$i + $ii];
- if (isset($next_codepoint) && ($next_codepoint == $properties[$key]['lower'][$j + $ii])) {
- $replace++;
- }
- }
- if ($replace == count($properties[$key]['lower'])) {
- $result[] = $properties[$key]['upper'];
- $replaced = array_merge($replaced, array_values($properties[$key]['lower']));
- $matched = true;
- break 1;
- }
- } elseif ($length > 1 && $property_count > 1) {
- $j = 0;
- for ($ii = 1; $ii < $property_count; $ii++) {
- $next_codepoint = $next_codepoints[$i + $ii - 1];
- if (in_array($next_codepoint, $properties[$ii]['lower'])) {
- for ($jj = 0; $jj < count($properties[$ii]['lower']); $jj++) {
- $next_codepoint = $next_codepoints[$i + $jj];
- if (isset($next_codepoint) && ($next_codepoint == $properties[$ii]['lower'][$j + $jj])) {
- $replace++;
- }
- }
- if ($replace == count($properties[$ii]['lower'])) {
- $result[] = $properties[$ii]['upper'];
- $replaced = array_merge($replaced, array_values($properties[$ii]['lower']));
- $matched = true;
- break 2;
- }
- }
- }
- }
- if ($properties[$key]['lower'][0] == $codepoint) {
- $result[] = $properties[$key]['upper'];
- $matched = true;
- break 1;
- }
- }
- }
- }
- if ($matched === false && !in_array($codepoint, $replaced, true)) {
- $result[] = $codepoint;
- }
- }
- $string = _api_utf8_from_unicode($result);
- }
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- 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);
- } elseif (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- if (MBSTRING_INSTALLED) {
- $string = @mb_substr($string, $start, $length, 'UTF-8');
- } else {
-
- $strlen = api_byte_count($string);
-
- $bytes = 0;
- if ($start > 0) {
-
-
- $bytes = -1;
- $chars = -1;
- while ($bytes < $strlen && $chars < $start) {
- $bytes++;
- $c = ord($string[$bytes]);
- if ($c < 0x80 || $c >= 0xC0) {
- $chars++;
- }
- }
- } else {
- if ($start < 0) {
-
-
- $start = abs($start);
- $bytes = $strlen;
- $chars = 0;
- while ($bytes > 0 && $chars < $start) {
- $bytes--;
- $c = ord($string[$bytes]);
- if ($c < 0x80 || $c >= 0xC0) {
- $chars++;
- }
- }
- }
- }
- $istart = $bytes;
-
- if ($length === null) {
- $bytes = $strlen - 1;
- } else {
- if ($length > 0) {
-
-
- $bytes = $istart;
- $chars = 0;
- while ($bytes < $strlen && $chars < $length) {
- $bytes++;
- $c = ord($string[$bytes]);
- if ($c < 0x80 || $c >= 0xC0) {
- $chars++;
- }
- }
- $bytes--;
- } else {
- if ($length < 0) {
-
-
- $length = abs($length);
- $bytes = $strlen - 1;
- $chars = 0;
- while ($bytes >= 0 && $chars < $length) {
- $c = ord($string[$bytes]);
- if ($c < 0x80 || $c >= 0xC0) {
- $chars++;
- }
- $bytes--;
- }
- }
- }
- }
- $iend = $bytes;
- $string = substr($string, $istart, max(0, $iend - $istart + 1));
- }
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- 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 (empty($encoding)) {
- $encoding = _api_mb_internal_encoding();
- }
- if (_api_mb_supports($encoding)) {
- return @mb_convert_case($string, MB_CASE_TITLE, $encoding);
- }
- if (api_is_encoding_supported($encoding)) {
- if (!api_is_utf8($encoding)) {
- $string = api_utf8_encode($string, $encoding);
- }
- if (MBSTRING_INSTALLED) {
- $string = @mb_convert_case($string, MB_CASE_TITLE, 'UTF-8');
- } else {
-
-
-
-
- $pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
- $string = preg_replace_callback($pattern, '_api_utf8_ucwords_callback', $string);
- }
- if (!api_is_utf8($encoding)) {
- return api_utf8_decode($string, $encoding);
- }
- return $string;
- }
- 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) {
- $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)) {
- $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));
- 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 setting_gettext()
- {
- $domain = 'default';
- $locale = api_get_language_isocode();
- $locale = 'es_ES';
- putenv("LC_ALL=$locale");
- setlocale(LC_ALL, $locale);
- bindtextdomain($domain, api_get_path(SYS_LANG_PATH));
- bind_textdomain_codeset($domain, 'UTF-8');
- textdomain($domain);
- }
- require_once dirname(__FILE__).'/internationalization_internal.lib.php';
|