public function __construct() { /** * Просматриваем какие языки есть */ foreach ($this->lagnuages as $key => $val) { $LF = wasp_strtolower($key . '.php'); if (!is_file(LANGUAGE_DIR . DIR_SEP . $LF)) { unset($this->lagnuages[$key]); } } unset($LF, $key, $val); /** * Смотрим язык установленный в конфиге */ $config = cfg('config')->application; $DL = !empty($config->language) ? $config->language : null; if (!empty($DL) && array_key_isset($DL, $this->lagnuages)) { $this->DEFAULT_LANG = $this->CURRENT_LANG = wasp_strtoupper($DL); } unset($config, $DL); $cookie_lang = cookie()->get('LANG'); if (!empty($cookie_lang) && array_key_isset($cookie_lang, $this->lagnuages)) { $this->CURRENT_LANG = $cookie_lang; } /** * Загружаем языковые пакеты */ $this->strings = new stdObject(); $default_lang_file = wasp_strtolower($this->DEFAULT_LANG . '.php'); if (is_dir(LANGUAGE_DIR) && is_file(LANGUAGE_DIR . DIR_SEP . $default_lang_file)) { $default_lng_strings = (include LANGUAGE_DIR . DIR_SEP . $default_lang_file); if (array_count($default_lng_strings) > 0) { foreach ($default_lng_strings as $key => $val) { if (is_varible_name($key) && is_scalar($val)) { $this->strings->{$key} = $val; } } } } if ($this->DEFAULT_LANG != $this->CURRENT_LANG) { $default_lang_file = wasp_strtolower($this->CURRENT_LANG . '.php'); if (is_dir(LANGUAGE_DIR) && is_file(LANGUAGE_DIR . DIR_SEP . $default_lang_file)) { $default_lng_strings = (include LANGUAGE_DIR . DIR_SEP . $default_lang_file); if (array_count($default_lng_strings) > 0) { foreach ($default_lng_strings as $key => $val) { if (is_varible_name($key) && is_scalar($val)) { $this->strings->{$key} = $val; } } } } } $this->getControllerLang(router()->getControllerName()); }
public function display($content) { if (!$this->render) { if (!headers_sent() && array_count($this->_headers) > 0) { foreach ($this->_headers as $key => $val) { header($val); } } http_cache_off(); if (!Cookie::isSaved()) { cookie()->save(); } if (wasp_strlen($content) > 102400) { @ini_set('zlib.output_compression', 1); } echo $this->getDebugInfo($content); return; } $templater = new \Smarty(); $templater->enableSecurity('Wasp_Smarty_Security'); $templater->setTemplateDir($this->getThemePath() . DIR_SEP); $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . $this->getThemeName(); if (!is_dir($temp_dir)) { wasp_mkdir($temp_dir); } $templater->setCompileDir($temp_dir . DIR_SEP); if (array_count($this->_assigns) > 0) { foreach ($this->_assigns as $key => $val) { $templater->assign($key, $val); } } $templater->assign('content', $content); if (function_exists('memory_get_peak_usage')) { $templater->assign('max_mem_use', get_mem_use(true)); } else { $templater->assign('max_mem_use', '-//-'); } $out = $templater->fetch($this->_layout); if (!headers_sent() && array_count($this->_headers) > 0) { foreach ($this->_headers as $key => $val) { header($val); } } if (!Cookie::isSaved()) { cookie()->save(); } if (wasp_strlen($out) > 102400) { ini_set('zlib.output_compression', 1); } unset($templater); memory_clear(); /** * Add CSS */ if (array_count($this->_css_list) > 0) { $_ = "\n\t\t<!-- DYNAMIC CSS -->\n"; foreach ($this->_css_list as $key => $val) { if (preg_match('/^http/is', $val)) { $_ .= "\t\t<link href=\"{$val}\" rel=\"stylesheet\" type=\"text/css\" />\n"; } else { $url = $this->getThemeUrl() . '/css/' . $val; $_ .= "\t\t<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" />\n"; } } $out = preg_replace('#\\<\\/head\\>#is', $_ . "</head>\n", $out); unset($_, $key, $val, $url); } /** * Add JS */ if (array_count($this->_js_list) > 0) { $info = "\n\t\t<!-- :position DYNAMIC JS -->\n"; foreach ($this->_js_list as $pos => $item) { $_ = str_replace(':position', wasp_strtoupper($pos), "\n\t\t<!-- :position DYNAMIC JS -->\n"); if (array_count($item) > 0) { foreach ($item as $key => $val) { if (preg_match('/^http/is', $val)) { $_ .= "\t\t<script type=\"text/javascript\" src=\"{$val}\"></script>\n"; } else { $url = $this->getThemeUrl() . '/js/' . $val; $_ .= "\t\t<script type=\"text/javascript\" src=\"{$url}\"></script>\n"; } } $out = preg_replace("#\\<\\/{$pos}\\>#is", $_ . "</{$pos}>\n", $out); unset($_, $key, $val, $url); } } unset($pos, $item); } echo $this->getDebugInfo($out); }