Пример #1
0
 function display($tmpl_file, $app_id = null, $fetch = false, $is_theme = false)
 {
     array_unshift($this->_files, $tmpl_file);
     $this->_vars = $this->pagedata;
     if ($p = strpos($tmpl_file, ':')) {
         $object = kernel::service('tpl_source.' . substr($tmpl_file, 0, $p));
         if ($object) {
             $tmpl_file_path = substr($tmpl_file, $p + 1);
             $last_modified = $object->last_modified($tmpl_file_path);
         }
     } else {
         if (defined('CUSTOM_CORE_DIR') && file_exists(CUSTOM_CORE_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file)) {
             $tmpl_file = CUSTOM_CORE_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file;
         } else {
             if (!$is_theme) {
                 $tmpl_file = realpath(APP_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file);
             } else {
                 $tmpl_file = realpath(THEME_DIR . '/' . $tmpl_file);
             }
         }
         $last_modified = filemtime($tmpl_file);
     }
     if (!$last_modified) {
         //无文件
     }
     $this->tmpl_cachekey('__temp_lang', kernel::get_lang());
     //设置模版所属语言包
     $this->tmpl_cachekey('__temp_app_id', $app_id ? $app_id : $this->app->app_id);
     $compile_id = $this->compile_id($tmpl_file);
     #if($this->force_compile || base_kvstore::instance('cache/template')->fetch($compile_id, $compile_code, $last_modified) === false){
     if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) {
         if ($object) {
             $compile_code = $this->_compiler()->compile($object->get_file_contents($tmpl_file_path));
         } else {
             $compile_code = $this->_compiler()->compile_file($tmpl_file);
         }
         if ($compile_code !== false) {
             #base_kvstore::instance('cache/template')->store($compile_id,$compile_code);
             cachemgr::co_start();
             cachemgr::set($compile_id . $last_modified, $compile_code, cachemgr::co_end());
         }
     }
     ob_start();
     eval('?>' . $compile_code);
     $content = ob_get_contents();
     ob_end_clean();
     array_shift($this->_files);
     $this->pre_display($content);
     if ($fetch === true) {
         return $content;
     } else {
         echo $content;
     }
 }
Пример #2
0
 static function tips_item_by_app($app_id)
 {
     $lang = kernel::get_lang();
     $tips = array();
     foreach (file(PUBLIC_DIR . '/app/' . $app_id . '/lang/' . $lang . '/tips.txt') as $tip) {
         $tip = trim($tip);
         if ($tip) {
             $tips[] = $tip;
         }
     }
     return $tips;
 }
Пример #3
0
 public function get_varys()
 {
     $varys['HOST'] = kernel::base_url(true);
     //host信息
     $varys['REWRITE'] = defined('WITH_REWRITE') ? WITH_REWRITE : '';
     //是否有rewirte支持
     $varys['LANG'] = kernel::get_lang();
     //语言环境
     $varys['ECAE'] = ECAE_PUB_POINT;
     //ecae布置环境
     return $varys;
 }
Пример #4
0
 public static function init_pack($app)
 {
     $current_lang = kernel::get_lang();
     $lang_resource = $app->lang_resource;
     if (is_array($lang_resource[$current_lang]) && in_array('config.php', $lang_resource[$current_lang])) {
         self::$_langPack[$app->app_id] = (array) @(include $app->lang_dir . '/' . $current_lang . '/config.php');
     } elseif (is_array($lang_resource['zh-cn']) && in_array('config.php', $lang_resource['zh-cn'])) {
         self::$_langPack[$app->app_id] = (array) @(include $app->lang_dir . '/zh-cn/config.php');
     } else {
         //trigger_error('language pack is lost in '.$this->app_id, E_USER_ERROR);
         self::$_langPack[$app->app_id] = array();
     }
 }
Пример #5
0
 public static function _($lang_dir, $key, $args = null)
 {
     if (self::is_need_conv()) {
         $language = kernel::get_lang();
         putenv("LANG={$language}");
         setlocale(LC_ALL, $language);
         $domain = 'lang';
         bindtextdomain($domain, $lang_dir);
         textdomain($domain);
         bind_textdomain_codeset($domain, 'utf-8');
         return gettext($key);
     } else {
         return $key;
     }
 }
Пример #6
0
 public static function _($lang_dir, $key, $args)
 {
     if (!is_string($key) || trim($key) == '') {
         return '';
     }
     if (self::is_need_conv()) {
         $language = kernel::get_lang();
         putenv("LANG={$language}");
         setlocale(LC_ALL, $language);
         $domain = 'lang';
         bindtextdomain($domain, $lang_dir);
         textdomain($domain);
         bind_textdomain_codeset($domain, 'utf-8');
     }
     if (count($args) > 1) {
         return call_user_func_array("sprintf", $args);
     } else {
         return self::__($key);
     }
 }
Пример #7
0
 private function parse_app($app_id)
 {
     $app = app::get($app_id);
     $lang = kernel::get_lang();
     $dir = $app->lang_dir . '/' . $lang . '/LC_MESSAGES';
     if (!is_dir($dir)) {
         mkdir($dir, 0775, true);
     }
     $file = $dir . '/lang.po';
     $array = array();
     /* $this->parse_php($app, $app->app_dir . '/controller', $array); */
     /* $this->parse_php($app, $app->app_dir . '/dbschema', $array); */
     /* $this->parse_php($app, $app->app_dir . '/model', $array); */
     /* $this->parse_php($app, $app->app_dir . '/lib', $array); */
     $this->parse_php($app, $app->app_dir . '/', $array);
     $this->parse_html($app, $app->app_dir . '/view', $array);
     $this->parse_html($app, $app->app_dir . '/lang/js', $array);
     if (!empty($array)) {
         $this->create_po_package($app_id, $file, $array);
         logger::info(sprintf('%s 语言包转换文件生成成功,共 %d items', $app->app_id, count($array)));
     } else {
         logger::info(sprintf('%s 没有语言包', $app->app_id));
     }
 }
Пример #8
0
 function lang_css($params)
 {
     $default = array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen, projection');
     $app = $params['app'] ? app::get($params['app']) : $this->app;
     $lang = kernel::get_lang();
     $src = 'css/' . $params['src'];
     if (is_array($app->lang_resource[$lang]) && in_array($src, $app->lang_resource[$lang])) {
         $file = $app->lang_url . '/' . $lang . '/' . $src;
     } elseif (is_array($app->lang_resource['zh-cn']) && in_array($src, $app->lang_resource['zh-cn'])) {
         $file = $app->lang_url . '/zh-cn/' . $src;
     } else {
         return '';
     }
     if (isset($params['src'])) {
         unset($params['src']);
     }
     if (isset($params['app'])) {
         unset($params['app']);
     }
     $params = count($params) ? $params + $default : $default;
     foreach ($params as $k => $v) {
         $ext .= sprintf('%s="%s" ', $k, $v);
     }
     $time = substr(cachemgr::ask_cache_check_version(), 0, 6);
     $file = $file . '?' . $time;
     return sprintf('<link href="%s" %s/>', $file, $ext);
 }
Пример #9
0
 function lang_css($params)
 {
     $default = array('rel' => 'stylesheet', 'media' => 'screen, projection');
     $app = $params['app'] ? app::get($params['app']) : $this->app;
     $lang = kernel::get_lang();
     $debug = defined('DEBUG_CSS') && constant('DEBUG_CSS');
     if ($params['pdir'] && !$debug) {
         $pdir = $params['pdir'];
     } else {
         $pdir = 'css';
     }
     $src = $pdir . '/' . $params['src'];
     if (is_array($app->lang_resource($lang)) && in_array($src, $app->lang_resource($lang))) {
         $file = $app->lang_url . '/' . $lang . '/' . $src;
     } elseif (is_array($app->lang_resource('zh_CN')) && in_array($src, $app->lang_resource('zh_CN'))) {
         $file = $app->lang_url . '/zh_CN/' . $src;
     } else {
         return '';
     }
     if (isset($params['pdir'])) {
         unset($params['pdir']);
     }
     if (isset($params['src'])) {
         unset($params['src']);
     }
     if (isset($params['app'])) {
         unset($params['app']);
     }
     $params = count($params) ? $params + $default : $default;
     foreach ($params as $k => $v) {
         $ext .= sprintf('%s="%s" ', $k, $v);
     }
     $version = $this->getVer($debug);
     return sprintf('<link href="%s" %s/>', $file . $version, $ext);
 }
Пример #10
0
 function lang_css($params)
 {
     if (empty($params['app'])) {
         throw new \InvalidArgumentException('lang script tag missing app argument. detail:' . $params['src']);
     }
     $app = app::get($params['app']);
     $default = array('rel' => 'stylesheet', 'media' => 'screen, projection');
     $lang = kernel::get_lang();
     $debug = config::get('app.debug', false);
     if ($params['pdir'] && !$debug) {
         $pdir = $params['pdir'];
     } else {
         $pdir = 'css';
     }
     $src = $pdir . '/' . $params['src'];
     if (is_array($app->lang_resource($lang)) && in_array($src, $app->lang_resource($lang))) {
         $file = $app->lang_url . '/' . $lang . '/' . $src;
     } elseif (is_array($app->lang_resource('zh_CN')) && in_array($src, $app->lang_resource('zh_CN'))) {
         $file = $app->lang_url . '/zh_CN/' . $src;
     } else {
         return '';
     }
     if (isset($params['pdir'])) {
         unset($params['pdir']);
     }
     if (isset($params['src'])) {
         unset($params['src']);
     }
     if (isset($params['app'])) {
         unset($params['app']);
     }
     $params = count($params) ? $params + $default : $default;
     foreach ($params as $k => $v) {
         $ext .= sprintf('%s="%s" ', $k, $v);
     }
     $version = $this->getVer($debug);
     return sprintf('<link href="%s" %s/>', $file . $version, $ext);
 }