public function signout() { if ($this->autorization) { $obj = $this->user->session; if (!empty($obj->session_id) && !empty($obj->ip_address)) { $obj->session_id = ''; $obj->save(); $this->user = null; $this->autorization = false; $this->session->destroy(); $smarty = new \Smarty(); $smarty->assignGlobal('auth_user', null); $smarty->assignGlobal('auth', null); } } }
public function addGlobal($name, $value) { return $this->engine->assignGlobal($name, $value); }
switch ($module) { case "export" : $smarty_output = "fetch"; break; default : $smarty_output = "display"; break; } //get the url - used for templates / pdf $siUrl = getURL(); //zend db // Get extensions from DB, and update config array //If using the folowing line, the DB settings should be appended to the config array, instead of replacing it (NOT TESTED!) //$config->extension() = $DB_extensions; if (isset($install_data_exists) && $install_data_exists) { $SI_SYSTEM_DEFAULTS = new SimpleInvoices_Db_Table_SystemDefaults(); $defaults = $SI_SYSTEM_DEFAULTS->fetchAll(); } else { $defaults = array(); } $smarty->assignGlobal("defaults",$defaults); $smarty->assignGlobal('baseUrl', $config->resources->frontController->baseUrl); // Get rid of some errors $smarty->assign('subPageActive',''); ?>
private function _prepare() { $theme_url = theme()->getThemeUrl(); $vars = ['base_url' => BASE_URL, 'content_url' => CONTENT_URL, 'core_name' => CORE_NAME, 'core_version' => CORE_VERSION, 'core_version_name' => CORE_VERSION_NAME, 'framework' => FRAMEWORK, 'timer_varible' => time(), 'theme_url' => $theme_url, 'css_url' => $theme_url . '/css', 'js_url' => $theme_url . '/js', 'images_url' => $theme_url . '/images', 'action' => router()->getAction(), 'controller_name' => router()->getControllerName(), 'method_name' => router()->getMethodName()]; $config = cfg('config')->application; if (!empty($config->url_suffix)) { $vars['url_suffix'] = (string) $config->url_suffix; } else { $vars['url_suffix'] = '.html'; } $msg = unserialize(pickup_temp('redirect')); if (!empty($msg['message'])) { $vars['redirect_message'] = $msg['message']; } if (!empty($msg['error'])) { $vars['redirect_error'] = $msg['error']; } $smarty = new \Smarty(); foreach ($vars as $key => $val) { $smarty->assignGlobal($key, $val); } unset($theme, $config, $msg, $smarty, $key, $val); }
/** * Returns the current smarty object, creating it and the prototype if necessary * * @return Smarty object */ public function smarty() { // set time for benchmarking $time = microtime(TRUE); // see if we need to set up the smarty object for this instance if ($this->_smarty === NULL) { // see if we need to set up the prototype smarty object if (self::$_smarty_prototype === NULL) { // nearly everything can be done in the confif file $config = Kohana::$config->load('smarty'); // instantiate the prototype Smarty object require_once $config->smarty_class_file; $smarty = new Smarty(); self::$_smarty_prototype = $smarty; // set up the prototype with options from config file foreach ($config->smarty_config as $key => $value) { $smarty->{$key} = $value; } // deal with config options that are not simple properties $smarty->php_handling = constant($config->php_handling); if ($config->check_dirs) { // check we can write to the compiled templates directory if (!is_writeable($smarty->compile_dir)) { self::create_dir($smarty->compile_dir, 'Smarty compiled template'); } // if smarty caching is enabled, check we can write to the cache directory if ($smarty->caching && !is_writeable($smarty->cache_dir)) { self::create_dir($smarty->cache_dir, 'Smarty cache'); } } // now assign useful globals $smarty->assignGlobal('base_url', URL::base()); $smarty->assignGlobal('helper', new Smarty_Helper()); // and register useful plugins // set timing for benchmark self::$_init_time = microtime(TRUE) - $time; } $this->_smarty = clone self::$_smarty_prototype; $time = microtime(TRUE) - $time; $this->_clone_time = $time; self::$_total_clone_time += $time; self::$_clone_count++; } return $this->_smarty; }
/** * Returns the smarty prototype object, creating it if necessary * * @return Smarty prototype object */ public static function smarty_prototype() { // set time for benchmarking $time = microtime(TRUE); // see if we need to set up the prototype smarty object if (self::$_smarty_prototype === NULL) { // nearly everything can be done in the config file if (Kohana::VERSION > '3.2') { $config = Kohana::$config->load('smarty'); } else { $config = Kohana::config('smarty'); } // locate a Smarty class - first check if it is already loaded if (!class_exists('Smarty', false)) { // next check if a path is set in config/smarty.php if ($file = $config->smarty_class_file) { require_once $file; // save the location in case we have more than one Smarty version around self::$_smarty_path = realpath(dirname($file)) . DIRECTORY_SEPARATOR; } elseif (!class_exists('Smarty')) { // try and autoload it // if it doesn't autoload, fall back to letting Kohana find the bundled version $file = Kohana::find_file('vendor', 'smarty/libs/Smarty.class'); require_once $file; // save the location in case we have more than one Smarty version around self::$_smarty_path = realpath(dirname($file)) . DIRECTORY_SEPARATOR; } } // instantiate the prototype Smarty object $smarty = new Smarty(); self::$_smarty_prototype = $smarty; // set up the prototype with options from config file foreach ($config->smarty_config as $key => $value) { $smarty->{$key} = $value; } // deal with config options that are not simple properties $smarty->php_handling = constant($config->php_handling); // add the path to the plugins for the located Smarty distro $smarty->addPluginsDir(self::$_smarty_path . 'plugins'); // add views directories for all loaded modules (including Smarty3) $dirs = array(); foreach (Kohana::modules() as $dir) { $dirs[] = "{$dir}views"; } $smarty->addTemplateDir($dirs); if ($config->check_dirs) { // check we can write to the compiled templates directory if (!is_writeable($smarty->compile_dir)) { self::create_dir($smarty->compile_dir, 'Smarty compiled template'); } // if smarty caching is enabled, check we can write to the cache directory if ($smarty->caching && !is_writeable($smarty->cache_dir)) { self::create_dir($smarty->cache_dir, 'Smarty cache'); } } // now assign useful globals $smarty->assignGlobal('base_url', URL::base()); $smarty->assignGlobal('helper', new Smarty_Helper()); $bound = View::$_global_bound_variables; // register any globals foreach (View::$_global_data as $key => $value) { if (isset($bound[$key])) { Smarty::$global_tpl_vars[$key] = new Smarty_variable($value); Smarty::$global_tpl_vars[$key]->value =& $value; } else { $smarty->assignGlobal($key, $value); } } // and register useful plugins // add to registered template engines View::$_smarty_is_loaded = TRUE; // set timing for benchmark self::$_init_time = microtime(TRUE) - $time; } return self::$_smarty_prototype; }
<?php require_once "smarty/Smarty.class.php"; //TODO admin panel variable $theme = "bootstrap"; $smarty = new Smarty(); $smarty->setConfigDir("templates/{$theme}/configs/"); $smarty->setTemplateDir("templates/{$theme}/source/"); $smarty->setCompileDir("templates/{$theme}/compiled/"); if (file_exists('templates/' . $theme . '/theme.php')) { require_once 'templates/' . $theme . '/theme.php'; } $smarty->assignGlobal("title", "Server Status"); $smarty->assignGlobal("version", STATUS_VERSION);
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; }