예제 #1
0
파일: Helper.php 프로젝트: admpub/MicroPHP
 public static function cookie($key = null, $default = null, $xss_clean = false)
 {
     return CoreInput::cookie($key, $default, $xss_clean);
 }
예제 #2
0
 public function __construct()
 {
     parent::__construct();
     $this->router_info = CoreRouter::info();
     // ====================================
     // 确定语言
     // ====================================
     $cookie_lifetime = 7 * 86400;
     if (!empty($_GET['lang']) && preg_match('/^[a-z\\-]+$/', $_GET['lang'])) {
         if ($this->validLanguage($_GET['lang'])) {
             CoreLoader::setCookie('lang', $_GET['lang'], $cookie_lifetime);
             CoreLoader::$system['language'] = $_GET['lang'];
         } else {
             CoreLoader::setCookie('lang', CoreLoader::$system['default_language'], $cookie_lifetime);
             CoreLoader::$system['language'] = CoreLoader::$system['default_language'];
         }
     } else {
         $cookieLang = CoreInput::cookie('lang');
         if (empty($cookieLang) || !preg_match('/^[a-z\\-]+$/', $cookieLang) || !$this->validLanguage($cookieLang)) {
             // if user doesn't specify any language, check his/her browser language
             // check if the visitor language is supported
             // $this->language(true) to return the country code such as en-US zh-CN zh-TW
             $countryCode = true;
             $langcode = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
             $langcode = !empty($langcode) ? explode(';', $langcode) : $langcode;
             $langcode = !empty($langcode[0]) ? explode(',', $langcode[0]) : $langcode;
             if (!$countryCode) {
                 $langcode = !empty($langcode[0]) ? explode('-', $langcode[0]) : $langcode;
             }
             $lang = $langcode[0];
             $lang = strtolower($lang);
             if (preg_match('/^[a-z\\-]+$/', $lang) && $this->validLanguage($lang)) {
                 CoreLoader::setCookie('lang', $lang, $cookie_lifetime);
                 CoreLoader::$system['language'] = $lang;
             } else {
                 CoreLoader::setCookie('lang', CoreLoader::$system['default_language'], $cookie_lifetime);
                 CoreLoader::$system['language'] = CoreLoader::$system['default_language'];
             }
         } else {
             CoreLoader::$system['language'] = $cookieLang;
         }
     }
     #echo CoreLoader::$system['language'];
     $locale = CoreLoader::locale(CoreLoader::$system['language']);
     $langEncoding = explode('.', $locale->getLocale());
     $localeDataFile = CoreLoader::$system['language_folder'] . '/' . $langEncoding[0] . '/locale.php';
     if (file_exists($localeDataFile)) {
         CoreLocale::$LANG = (include $localeDataFile);
     }
     // ====================================
     // 初始化Smarty模板引擎
     // ====================================
     include_once FRAMEWORK_CORE_PATH . '/Smarty/Smarty.class.php';
     $smarty = new Smarty();
     $view_dir = self::$system['view_folder'];
     $cache_dir = self::$system['table_cache_folder'] . '/smarty';
     // $smarty->force_compile = true;
     $smarty->error_reporting = 9;
     //E_ALL;
     $smarty->debugging = false;
     $smarty->caching = false;
     //$smarty->use_sub_dirs = true;
     $smarty->cache_lifetime = 120;
     $smarty->left_delimiter = '<{';
     $smarty->right_delimiter = '}>';
     $smarty->allow_php_templates = true;
     $smarty->setTemplateDir($view_dir);
     $smarty->setCompileDir($cache_dir . '/templates_c/');
     $smarty->setConfigDir($cache_dir . '/configs/');
     $smarty->setCacheDir($cache_dir . '/cache/');
     $smarty->registered_cache_resources = array('phpFastCache', 'memcache');
     //$smarty->caching_type = 'phpFastCache'; //TODO: 缓存无效
     $smarty->caching_type = 'file';
     switch (phpFastCache::$storage) {
         case 'memcache':
         case 'apc':
             $smarty->caching_type = phpFastCache::$storage;
             break;
         default:
             if (function_exists('apc_cache_info')) {
                 $smarty->caching_type = 'apc';
             }
             break;
     }
     $smarty->default_resource_type = 'file';
     //模板保存方式
     // ====================================
     // 设置全局变量
     // ====================================
     $smarty->assignGlobal('TITLE', '');
     $smarty->assignGlobal('KEYWORDS', '');
     $smarty->assignGlobal('DESCRIPTION', '');
     // ====================================
     // 注册自定义函数
     // ====================================
     //$smarty->registerPlugin('function', 'burl', 'build_url');
     //<{burl param=value}> ===> function build_url(...){...}
     //$smarty->registerPlugin('modifier', 'astatus', 'audit_status');
     //<{$var|astatus}> ===> function audit_status(...){...}
     $smarty->registerPlugin('modifier', 'url', 'Fn::url');
     $this->view =& $smarty;
 }