📄 smarty.class.php
字号:
<?php
class Smarty
{
public $template_dir = "./themes";
public $compile_dir = "./";
public $config_dir = "./langs";
public $debugging = FALSE;
public $debug_tpl = "file:debug.tpl";
public $debugging_ctrl = "NONE";
public $global_assign = array
(
"HTTP_SERVER_VARS" => array
(
0 => "SCRIPT_NAME"
)
);
public $undefined = NULL;
public $compile_check = TRUE;
public $force_compile = FALSE;
public $caching = FALSE;
public $cache_dir = "./cache";
public $cache_lifetime = 3600;
public $insert_tag_check = TRUE;
public $cache_handler_func = NULL;
public $default_template_handler_func = "";
public $tpl_file_ext = ".tpl";
public $php_handling = SMARTY_PHP_PASSTHRU;
public $security = FALSE;
public $secure_dir = array
(
0 => "./templates"
);
public $security_settings = array
(
"PHP_HANDLING" => FALSE,
"IF_FUNCS" => array
(
0 => "array",
1 => "list",
2 => "isset",
3 => "empty",
4 => "count",
5 => "sizeof",
6 => "in_array",
7 => "is_array"
),
"INCLUDE_ANY" => FALSE,
"PHP_TAGS" => FALSE,
"MODIFIER_FUNCS" => array
(
0 => "count"
)
);
public $trusted_dir = array( );
public $left_delimiter = "{";
public $right_delimiter = "}";
public $compiler_funcs = array( );
public $custom_funcs = array
(
"html_options" => "smarty_func_html_options",
"html_select_date" => "smarty_func_html_select_date",
"html_select_time" => "smarty_func_html_select_time",
"math" => "smarty_func_math",
"fetch" => "smarty_func_fetch",
"counter" => "smarty_func_counter",
"assign" => "smarty_func_assign",
"popup_init" => "smarty_func_overlib_init",
"popup" => "smarty_func_overlib",
"assign_debug_info" => "smarty_func_assign_debug_info",
"um_translatebox" => "smarty_func_um_translatebox",
"um_welcome_message" => "smarty_func_um_welcome_message"
);
public $custom_mods = array
(
"lower" => "strtolower",
"upper" => "strtoupper",
"capitalize" => "ucwords",
"escape" => "smarty_mod_escape",
"truncate" => "smarty_mod_truncate",
"spacify" => "smarty_mod_spacify",
"date_format" => "smarty_mod_date_format",
"string_format" => "smarty_mod_string_format",
"replace" => "smarty_mod_replace",
"regex_replace" => "smarty_mod_regex_replace",
"strip_tags" => "smarty_mod_strip_tags",
"default" => "smarty_mod_default",
"count_characters" => "smarty_mod_count_characters",
"count_words" => "smarty_mod_count_words",
"count_sentences" => "smarty_mod_count_sentences",
"count_paragraphs" => "smarty_mod_count_paragraphs",
"debug_print_var" => "smarty_mod_debug_print_var"
);
public $show_info_header = FALSE;
public $show_info_include = FALSE;
public $compiler_class = "Smarty_Compiler";
public $resource_funcs = array( );
public $prefilter_funcs = array( );
public $postfilter_funcs = array( );
public $request_vars_order = "EGPCS";
public $compile_id = NULL;
public $_error_msg = FALSE;
public $_tpl_vars = array( );
public $_smarty_vars = array( );
public $_sections = array( );
public $_foreach = array( );
public $_conf_obj = NULL;
public $_config = array( );
public $_smarty_md5 = "f8d698aea36fcbead2b9d5359ffca76f";
public $_version = "1.5.2";
public $_extract = FALSE;
public $_inclusion_depth = 0;
public $_compile_id = NULL;
public $_smarty_debug_id = "SMARTY_DEBUG";
public $_smarty_debug_info = array( );
public $_cache_info = array( );
public function Smarty( )
{
foreach ( $this->global_assign as $key => $var_name )
{
if ( is_array( $var_name ) )
{
foreach ( $var_name as $var )
{
if ( isset( $GLOBALS[$key][$var] ) )
{
$this->assign( $var, $GLOBALS[$key][$var] );
}
else
{
$this->assign( $var, $this->undefined );
}
}
}
else if ( isset( $GLOBALS[$var_name] ) )
{
$this->assign( $var_name, $GLOBALS[$var_name] );
}
else
{
$this->assign( $var_name, $this->undefined );
}
}
}
public function assign( $tpl_var, $value = NULL )
{
if ( is_array( $tpl_var ) )
{
foreach ( $tpl_var as $key => $val )
{
if ( !empty( $key ) )
{
if ( isset( $val ) )
{
$this->_tpl_vars[$key] = $val;
}
}
}
}
else if ( !empty( $tpl_var ) || isset( $value ) )
{
$this->_tpl_vars[$tpl_var] = $value;
}
$this->_extract = TRUE;
}
public function append( $tpl_var, $value = NULL )
{
if ( is_array( $tpl_var ) )
{
foreach ( $tpl_var as $key => $val )
{
if ( !empty( $key ) )
{
if ( !is_array( $this->_tpl_vars[$key] ) )
{
settype( &$this->_tpl_vars[$key], "array" );
}
$this->_tpl_vars[$key][] = $val;
}
}
}
else if ( !empty( $tpl_var ) || isset( $value ) )
{
if ( !is_array( $this->_tpl_vars[$tpl_var] ) )
{
settype( &$this->_tpl_vars[$tpl_var], "array" );
}
$this->_tpl_vars[$tpl_var][] = $value;
}
$this->_extract = TRUE;
}
public function my_call_user_func_array( $func, $ar )
{
if ( !function_exists( "call_user_func_array" ) )
{
$funcCall = "{$func}(";
$i = 0;
for ( ; $i < sizeof( $ar ); ++$i )
{
eval( "\$funcCall .= '\$ar[".$i."],';" );
}
$funcCall = substr( $funcCall, 0, -1 );
$funcCall .= ")";
eval( "\$retval = ".$funcCall.";" );
return $retval;
}
return call_user_func_array( $func, $ar );
}
public function clear_assign( $tpl_var )
{
if ( is_array( $tpl_var ) )
{
foreach ( $tpl_var as $curr_var )
{
unset( $this->_tpl_vars[$curr_var] );
}
}
else
{
unset( $this->_tpl_vars[$tpl_var] );
}
}
public function register_function( $function, $function_impl )
{
$this->custom_funcs[$function] = $function_impl;
}
public function unregister_function( $function )
{
unset( $this->custom_funcs[$function] );
}
public function register_compiler_function( $function, $function_impl )
{
$this->compiler_funcs[$function] = $function_impl;
}
public function unregister_compiler_function( $function )
{
unset( $this->compiler_funcs[$function] );
}
public function register_modifier( $modifier, $modifier_impl )
{
$this->custom_mods[$modifier] = $modifier_impl;
}
public function unregister_modifier( $modifier )
{
unset( $this->custom_mods[$modifier] );
}
public function register_resource( $name, $function_name )
{
$this->resource_funcs[$name] = $function_name;
}
public function unregister_resource( $name )
{
unset( $this->resource_funcs[$name] );
}
public function register_prefilter( $function_name )
{
$this->prefilter_funcs[] = $function_name;
}
public 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;
}
public function register_postfilter( $function_name )
{
$this->postfilter_funcs[] = $function_name;
}
public 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;
}
public 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 );
}
return $this->_rm_auto( $this->cache_dir, $tpl_file, $auto_id );
}
public function clear_all_cache( )
{
if ( !empty( $this->cache_handler_func ) )
{
$funcname = $this->cache_handler_func;
return $funcname( "clear", $this, $dummy );
}
return $this->_rm_auto( $this->cache_dir );
}
public 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 );
}
public function clear_all_assign( )
{
$this->_tpl_vars = array( );
}
public 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 );
}
public function &get_template_vars( )
{
return $this->_tpl_vars;
}
public function display( $tpl_file, $cache_id = NULL, $compile_id = NULL )
{
$this->fetch( $tpl_file, $cache_id, $compile_id, TRUE );
}
public function fetch( $_smarty_tpl_file, $_smarty_cache_id = NULL, $_smarty_compile_id = NULL, $_smarty_display = FALSE )
{
global $HTTP_SERVER_VARS;
global $QUERY_STRING;
global $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 )
{
$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 )
{
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime( ) - $debug_start_time;
echo $this->_generate_debug_output( );
}
}
else
{
return $_smarty_results;
}
}
}
else
{
$this->_assign_smarty_interface( );
if ( $this->_conf_obj === NULL )
{
if ( !class_exists( "Smarty_Config" ) )
{
include_once( SMARTY_DIR."Smarty_Config.class.php" );
}
( $this->config_dir );
$this->_conf_obj = new Config_File( );
$this->_conf_obj->read_hidden = FALSE;
}
else
{
$this->_conf_obj->set_path( $this->config_dir );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -