📄 smarty.class.php
字号:
<?php
class smarty
{
var $template_dir = "./themes";
var $compile_dir = "./";
var $config_dir = "./langs";
var $debugging = false;
var $debug_tpl = "file:debug.tpl";
var $debugging_ctrl = "NONE";
var $global_assign = array
(
"HTTP_SERVER_VARS" => array
(
0 => "SCRIPT_NAME"
)
);
var $undefined = null;
var $compile_check = true;
var $force_compile = false;
var $caching = false;
var $cache_dir = "./cache";
var $cache_lifetime = 3600;
var $insert_tag_check = true;
var $cache_handler_func = null;
var $default_template_handler_func = "";
var $tpl_file_ext = ".tpl";
var $php_handling = SMARTY_PHP_PASSTHRU;
var $security = false;
var $secure_dir = array
(
0 => "./templates"
);
var $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"
)
);
var $trusted_dir = array( );
var $left_delimiter = "{";
var $right_delimiter = "}";
var $compiler_funcs = array( );
var $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"
);
var $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"
);
var $show_info_header = false;
var $show_info_include = false;
var $compiler_class = "Smarty_Compiler";
var $resource_funcs = array( );
var $prefilter_funcs = array( );
var $postfilter_funcs = array( );
var $request_vars_order = "EGPCS";
var $compile_id = null;
var $_error_msg = false;
var $_tpl_vars = array( );
var $_smarty_vars = array( );
var $_sections = array( );
var $_foreach = array( );
var $_conf_obj = null;
var $_config = array( );
var $_smarty_md5 = "f8d698aea36fcbead2b9d5359ffca76f";
var $_version = "1.5.2";
var $_extract = false;
var $_inclusion_depth = 0;
var $_compile_id = null;
var $_smarty_debug_id = "SMARTY_DEBUG";
var $_smarty_debug_info = array( );
var $_cache_info = array( );
function smarty( )
{
foreach ( $this->global_assign as $key => $var_name )
{
if ( is_array( $var_name ) )
{
foreach ( $var_name as $var )
{
if ( isset( $Var_48[$var] ) )
{
$this->assign( $var, $GLOBALS[$key][$var] );
}
else
{
$this->assign( $var, $this->undefined );
}
}
}
else if ( isset( $var_name ) )
{
$this->assign( $var_name, $GLOBALS[$var_name] );
}
else
{
$this->assign( $var_name, $this->undefined );
}
}
}
function assign( $tpl_var, $value = NULL )
{
if ( is_array( $tpl_var ) )
{
foreach ( $tpl_var as $key => $val )
{
if ( !empty( $key ) && isset( $val ) )
{
$this->_tpl_vars[$key] = $val;
}
}
}
else if ( !empty( $tpl_var ) && isset( $value ) )
{
$this->_tpl_vars[$tpl_var] = $value;
}
$this->_extract = true;
}
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;
}
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;
}
else
{
return call_user_func_array( $func, $ar );
}
}
function clear_assign( $tpl_var )
{
if ( is_array( $tpl_var ) )
{
foreach ( $tpl_var as $curr_var )
{
unset( $this->$this->_tpl_vars->$curr_var );
}
}
else
{
unset( $this->$this->_tpl_vars->$tpl_var );
}
}
function register_function( $function, $function_impl )
{
$this->custom_funcs[$function] = $function_impl;
}
function unregister_function( $function )
{
unset( $this->$this->custom_funcs->$function );
}
function register_compiler_function( $function, $function_impl )
{
$this->compiler_funcs[$function] = $function_impl;
}
function unregister_compiler_function( $function )
{
unset( $this->$this->compiler_funcs->$function );
}
function register_modifier( $modifier, $modifier_impl )
{
$this->custom_mods[$modifier] = $modifier_impl;
}
function unregister_modifier( $modifier )
{
unset( $this->$this->custom_mods->$modifier );
}
function register_resource( $name, $function_name )
{
$this->resource_funcs[$name] = $function_name;
}
function unregister_resource( $name )
{
unset( $this->$this->resource_funcs->$name );
}
function register_prefilter( $function_name )
{
$this->prefilter_funcs[] = $function_name;
}
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( $function_name )
{
$this->postfilter_funcs[] = $function_name;
}
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( $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( )
{
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( $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( )
{
$this->_tpl_vars = array( );
}
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( )
{
return $this->_tpl_vars;
}
function display( $tpl_file, $cache_id = null, $compile_id = null )
{
$this->fetch( $tpl_file, $cache_id, $compile_id, true );
}
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( );
}
return;
}
else
{
return $_smarty_results;
}
}
}
$this->_assign_smarty_interface( );
if ( $this->_conf_obj === null )
{
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 );
$this->_config = array(
array(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -