📄 smarty.class.php
字号:
{
if (is_array($tpl_var))
foreach ($tpl_var as $curr_var)
unset($this->_tpl_vars[$curr_var]);
else
unset($this->_tpl_vars[$tpl_var]);
}
/*======================================================================*\
Function: register_function
Purpose: Registers custom function to be used in templates
\*======================================================================*/
function register_function($function, $function_impl)
{
$this->custom_funcs[$function] = $function_impl;
}
/*======================================================================*\
Function: unregister_function
Purpose: Unregisters custom function
\*======================================================================*/
function unregister_function($function)
{
unset($this->custom_funcs[$function]);
}
/*======================================================================*\
Function: register_compiler_function
Purpose: Registers compiler function
\*======================================================================*/
function register_compiler_function($function, $function_impl)
{
$this->compiler_funcs[$function] = $function_impl;
}
/*======================================================================*\
Function: unregister_compiler_function
Purpose: Unregisters compiler function
\*======================================================================*/
function unregister_compiler_function($function)
{
unset($this->compiler_funcs[$function]);
}
/*======================================================================*\
Function: register_modifier
Purpose: Registers modifier to be used in templates
\*======================================================================*/
function register_modifier($modifier, $modifier_impl)
{
$this->custom_mods[$modifier] = $modifier_impl;
}
/*======================================================================*\
Function: unregister_modifier
Purpose: Unregisters modifier
\*======================================================================*/
function unregister_modifier($modifier)
{
unset($this->custom_mods[$modifier]);
}
/*======================================================================*\
Function: register_resource
Purpose: Registers a resource to fetch a template
\*======================================================================*/
function register_resource($name, $function_name)
{
$this->resource_funcs[$name] = $function_name;
}
/*======================================================================*\
Function: unregister_resource
Purpose: Unregisters a resource
\*======================================================================*/
function unregister_resource($name)
{
unset($this->resource_funcs[$name]);
}
/*======================================================================*\
Function: register_prefilter
Purpose: Registers a prefilter function to apply
to a template before compiling
\*======================================================================*/
function register_prefilter($function_name)
{
$this->prefilter_funcs[] = $function_name;
}
/*======================================================================*\
Function: unregister_prefilter
Purpose: Unregisters a prefilter function
\*======================================================================*/
function unregister_prefilter($function_name)
{
$tmp_array = array();
foreach($this->prefilter_funcs as $curr_func) {
if ($curr_func != $function_name) {
$tmp_array[] = $curr_func;
}
}
$this->prefilter_funcs = $tmp_array;
}
/*======================================================================*\
Function: register_postfilter
Purpose: Registers a postfilter function to apply
to a compiled template after compilation
\*======================================================================*/
function register_postfilter($function_name)
{
$this->postfilter_funcs[] = $function_name;
}
/*======================================================================*\
Function: unregister_postfilter
Purpose: Unregisters a postfilter function
\*======================================================================*/
function unregister_postfilter($function_name)
{
$tmp_array = array();
foreach($this->postfilter_funcs as $curr_func) {
if ($curr_func != $function_name) {
$tmp_array[] = $curr_func;
}
}
$this->postfilter_funcs = $tmp_array;
}
/*======================================================================*\
Function: clear_cache()
Purpose: clear cached content for the given template and cache id
\*======================================================================*/
function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null)
{
if (!isset($compile_id))
$compile_id = $this->compile_id;
if (isset($compile_id) || isset($cache_id))
$auto_id = $compile_id . $cache_id;
else
$auto_id = null;
if (!empty($this->cache_handler_func)) {
$funcname = $this->cache_handler_func;
return $funcname('clear', $this, $dummy, $tpl_file, $cache_id, $compile_id);
} else {
return $this->_rm_auto($this->cache_dir, $tpl_file, $auto_id);
}
}
/*======================================================================*\
Function: clear_all_cache()
Purpose: clear the entire contents of cache (all templates)
\*======================================================================*/
function clear_all_cache()
{
if (!empty($this->cache_handler_func)) {
$funcname = $this->cache_handler_func;
return $funcname('clear', $this, $dummy);
} else {
return $this->_rm_auto($this->cache_dir);
}
}
/*======================================================================*\
Function: is_cached()
Purpose: test to see if valid cache exists for this template
\*======================================================================*/
function is_cached($tpl_file, $cache_id = null, $compile_id = null)
{
if (!$this->caching)
return false;
if (!isset($compile_id))
$compile_id = $this->compile_id;
return $this->_read_cache_file($tpl_file, $cache_id, $compile_id, $results);
}
/*======================================================================*\
Function: clear_all_assign()
Purpose: clear all the assigned template variables.
\*======================================================================*/
function clear_all_assign()
{
$this->_tpl_vars = array();
}
/*======================================================================*\
Function: clear_compiled_tpl()
Purpose: clears compiled version of specified template resource,
or all compiled template files if one is not specified.
This function is for advanced use only, not normally needed.
\*======================================================================*/
function clear_compiled_tpl($tpl_file = null, $compile_id = null)
{
if (!isset($compile_id))
$compile_id = $this->compile_id;
return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id);
}
/*======================================================================*\
Function: get_template_vars
Purpose: Returns an array containing template variables
\*======================================================================*/
function &get_template_vars()
{
return $this->_tpl_vars;
}
/*======================================================================*\
Function: display()
Purpose: executes & displays the template results
\*======================================================================*/
function display($tpl_file, $cache_id = null, $compile_id = null)
{
$this->fetch($tpl_file, $cache_id, $compile_id, true);
}
/*======================================================================*\
Function: fetch()
Purpose: executes & returns or displays the template results
\*======================================================================*/
function fetch($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null, $_smarty_display = false)
{
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
if (!$this->debugging && $this->debugging_ctrl == 'URL'
&& (!empty($QUERY_STRING) && strstr($QUERY_STRING, $this->_smarty_debug_id))) {
$this->debugging = true;
}
if ($this->debugging) {
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_tpl_file,
'depth' => 0);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
if (!isset($_smarty_compile_id))
$_smarty_compile_id = $this->compile_id;
$this->_inclusion_depth = 0;
if ($this->caching) {
$this->_cache_info[] = array('template', $_smarty_tpl_file);
if ($this->_read_cache_file($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_results)) {
if ($this->insert_tag_check) {
$_smarty_results = $this->_process_cached_inserts($_smarty_results);
}
if ($_smarty_display) {
echo $_smarty_results;
if ($this->debugging)
{
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output();
}
return;
} else {
return $_smarty_results;
}
}
}
$this->_assign_smarty_interface();
if ($this->_conf_obj === null) {
/* Prepare the configuration object. */
if (!class_exists('Smarty_Config'))
include_once SMARTY_DIR.'Smarty_Config.class.php';
$this->_conf_obj = new Config_File($this->config_dir);
$this->_conf_obj->read_hidden = false;
} else
$this->_conf_obj->set_path($this->config_dir);
extract($this->_tpl_vars);
/* Initialize config array. */
$this->_config = array(array('vars' => array(),
'files' => array()));
if ($this->show_info_header) {
$_smarty_info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
} else {
$_smarty_info_header = '';
}
$compile_path = $this->_get_compile_path($_smarty_tpl_file);
$_smarty_trusted = false;
if ($this->security) {
$this->_parse_file_path($this->template_dir, $_smarty_tpl_file, $resource_type, $resource_name);
if ($this->_is_trusted($resource_type, $resource_name)) {
$_smarty_trusted = true;
$this->security = false;
}
}
// if we just need to display the results, don't perform output
// buffering - for speed
if ($_smarty_display && !$this->caching) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -