コード例 #1
0
ファイル: Main.php プロジェクト: hard990/altocms
 /**
  * Транслитерация строки
  *
  * @param   string      $sText
  * @param   string|bool $xLang  - true - использовать установки текущего языка/локали
  *                              - false - использовать системную локаль
  *                              - <string> - использовать установки заданного языка/локали
  *
  * @return  string
  */
 public static function Translit($sText, $xLang = true)
 {
     if ($xLang === true) {
         if (class_exists('ModuleLang', false)) {
             $xLang = E::ModuleLang()->GetLang();
         } elseif (class_exists('Config', false)) {
             $xLang = Config::Get('lang.current');
         } else {
             $xLang = false;
         }
     }
     $sText = mb_strtolower($sText, 'UTF-8');
     if ($xLang !== false) {
         $aChars = UserLocale::getLocale($xLang, 'translit');
         if ($aChars) {
             $sText = str_replace(array_keys($aChars), array_values($aChars), $sText);
         }
         $sText = preg_replace('/[\\-]{2,}/u', '-', $sText);
     }
     $sResult = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $sText);
     // В некоторых случаях может возвращаться пустая строка
     if (!$sResult) {
         $sResult = $sText;
     }
     return $sResult;
 }
コード例 #2
0
ファイル: Loader.class.php プロジェクト: Azany/altocms
 /**
  * @param array $aConfig
  */
 public static function Init($aConfig)
 {
     // Регистрация автозагрузчика классов
     spl_autoload_register('Loader::Autoload');
     Config::Load($aConfig);
     $sConfigDir = Config::Get('path.dir.config');
     // Load main config
     Config::LoadFromFile($sConfigDir . '/config.php', false);
     // Load additional config files if defined
     $aConfigLoad = F::Str2Array(Config::Get('config_load'));
     if ($aConfigLoad) {
         self::_loadConfigSections($sConfigDir, $aConfigLoad);
     }
     // Includes all *.php files from {path.root.engine}/include/
     $sIncludeDir = Config::Get('path.dir.engine') . '/include/';
     self::_includeAllFiles($sIncludeDir);
     // Load main config level (modules, local & plugins)
     self::_loadConfigFiles($sConfigDir, Config::LEVEL_MAIN);
     // Define app config dir
     $sAppConfigDir = Config::Get('path.dir.app') . '/config/';
     // Ups config level
     Config::ResetLevel(Config::LEVEL_APP);
     // Load application config level (modules, local & plugins)
     self::_loadConfigFiles($sAppConfigDir, Config::LEVEL_APP);
     // Load additional config files (the set could be changed in this point)
     $aConfigLoad = F::Str2Array(Config::Get('config_load'));
     if ($aConfigLoad) {
         self::_loadConfigSections($sAppConfigDir, $aConfigLoad, Config::LEVEL_APP);
     }
     // Load include files of plugins
     self::_loadIncludeFiles(Config::LEVEL_MAIN);
     self::_loadIncludeFiles(Config::LEVEL_APP);
     self::_checkRequiredDirs();
     $aSeekDirClasses = array(Config::Get('path.dir.app'), Config::Get('path.dir.common'), Config::Get('path.dir.engine'));
     Config::Set('path.root.seek', $aSeekDirClasses);
     if (is_null(Config::Get('path.root.subdir'))) {
         if (isset($_SERVER['DOCUMENT_ROOT'])) {
             $sPathSubdir = '/' . F::File_LocalPath(ALTO_DIR, $_SERVER['DOCUMENT_ROOT']);
         } elseif ($iOffset = Config::Get('path.offset_request_url')) {
             $aParts = array_slice(explode('/', F::File_NormPath(ALTO_DIR)), -$iOffset);
             $sPathSubdir = '/' . implode('/', $aParts);
         } else {
             $sPathSubdir = '';
         }
         Config::Set('path.root.subdir', $sPathSubdir);
     }
     // Подгружаем конфиг из файлового кеша, если он есть
     Config::ResetLevel(Config::LEVEL_CUSTOM);
     $aConfig = Config::ReadCustomConfig(null, true);
     if ($aConfig) {
         Config::Load($aConfig, false, null, null, 'custom');
     }
     // Задаем локаль по умолчанию
     F::IncludeLib('UserLocale/UserLocale.class.php');
     // Устанавливаем признак того, является ли сайт многоязычным
     $aLangsAllow = (array) Config::Get('lang.allow');
     if (sizeof($aLangsAllow) > 1) {
         UserLocale::initLocales($aLangsAllow);
         Config::Set('lang.multilang', true);
     } else {
         Config::Set('lang.multilang', false);
     }
     UserLocale::setLocale(Config::Get('lang.current'), array('local' => Config::Get('i18n.locale'), 'timezone' => Config::Get('i18n.timezone')));
     Config::Set('i18n', UserLocale::getLocale());
     F::IncludeFile(Config::Get('path.dir.engine') . '/classes/core/Engine.class.php');
 }
コード例 #3
0
ファイル: Lang.class.php プロジェクト: AntiqS/altocms
 /**
  * Возвращает список доступных языков
  */
 public function GetAvailableLanguages()
 {
     $aLanguages = UserLocale::getAvailableLanguages(true);
     foreach ($aLanguages as $sLang => $aLang) {
         if (!isset($aLang['aliases']) && isset($aLang['name'])) {
             $aLanguages[$sLang]['aliases'] = strtolower($aLang['name']);
         }
     }
     return $aLanguages;
 }
コード例 #4
0
ファイル: UserLocale.class.php プロジェクト: AntiqS/altocms
 static function setLocale($sLang = null, $aParam = array())
 {
     if (!$sLang) {
         $sLang = self::$aDefaultLocale;
     }
     if (!isset(self::$aLocales[$sLang])) {
         self::initLocales($sLang);
     }
     if (isset(self::$aLocales[$sLang])) {
         // Set locale
         if (isset($aParam['locale']) and $aParam['locale']) {
             self::$aLocales[$sLang]['locale'] = $aParam['locale'];
         }
         self::setLocaleSys(self::$aLocales[$sLang]['locale']);
         // Set timezone
         if (isset($aParam['timezone']) and $aParam['timezone']) {
             self::$aLocales[$sLang]['timezone'] = $aParam['timezone'];
         }
         date_default_timezone_set(self::$aLocales[$sLang]['timezone']);
     }
     self::$sCurrentLanguage = $sLang;
 }