📄 smarty.class.php
字号:
$i = 1;
for ( ; $i < count( $this->_config ); ++$i )
{
if ( !isset( $this->_config[$i]['files'][$file] ) )
{
$this->_config[$i]['vars'] = array_merge( $this->_config[$i]['vars'], $this->_conf_obj->get( $file ) );
$this->_config[$i]['files'][$file] = true;
}
}
}
if ( !empty( $section ) )
{
$this->_config[0]['vars'] = array_merge( $this->_config[0]['vars'], $this->_conf_obj->get( $file, $section ) );
if ( $scope == "parent" )
{
if ( 0 < count( $this->_config ) )
{
$this->_config[1]['vars'] = array_merge( $this->_config[1]['vars'], $this->_conf_obj->get( $file, $section ) );
}
}
else if ( $scope == "global" )
{
$i = 1;
for ( ; $i < count( $this->_config ); ++$i )
{
$this->_config[$i]['vars'] = array_merge( $this->_config[$i]['vars'], $this->_conf_obj->get( $file, $section ) );
}
}
}
if ( $this->debugging )
{
$debug_start_time = $this->_get_microtime( );
$this->_smarty_debug_info[] = array(
"type" => "config",
"filename" => $file." [".$section."] ".$scope,
"depth" => $this->_inclusion_depth,
"exec_time" => $this->_get_microtime( ) - $debug_start_time
);
}
}
function _process_cached_inserts( $results )
{
preg_match_all( "!".$this->_smarty_md5."{insert_cache (.*)}".$this->_smarty_md5."!Uis", $results, $match );
list( $cached_inserts, $insert_args ) = $match;
$i = 0;
for ( ; $i < count( $cached_inserts ); ++$i )
{
if ( $this->debugging )
{
$debug_start_time = $this->_get_microtime( );
}
$args = unserialize( $insert_args[$i] );
$name = $args['name'];
unset( $args->'name' );
if ( isset( $args['script'] ) )
{
$this->_parse_file_path( $this->trusted_dir, $this->_dequote( $args['script'] ), $resource_type, $resource_name );
if ( $this->security )
{
if ( $resource_type != "file" || !is_file( $resource_name ) )
{
$this->_syntax_error( "include_php: {$resource_type}: {$resource_name} is not readable" );
return false;
}
if ( !$this->_is_trusted( $resource_type, $resource_name ) )
{
$this->_syntax_error( "include_php: {$resource_type}: {$resource_name} is not trusted" );
return false;
}
}
include_once( $resource_name );
unset( $args->'script' );
}
$function_name = "insert_".$name;
$replace = $function_name( $args, $this );
$results = str_replace( $cached_inserts[$i], $replace, $results );
if ( $this->debugging )
{
$this->_smarty_debug_info[] = array(
"type" => "insert",
"filename" => "insert_".$name,
"depth" => $this->_inclusion_depth,
"exec_time" => $this->_get_microtime( ) - $debug_start_time
);
}
}
return $results;
}
function _run_insert_handler( $args )
{
if ( $this->debugging )
{
$debug_start_time = $this->_get_microtime( );
}
if ( $this->caching )
{
$arg_string = serialize( $args );
return $this->_smarty_md5."{insert_cache {$arg_string}}".$this->_smarty_md5;
}
else
{
$function_name = "insert_".$args['name'];
if ( isset( $args['script'] ) )
{
$this->_parse_file_path( $this->trusted_dir, $this->_dequote( $args['script'] ), $resource_type, $resource_name );
if ( $this->security )
{
if ( $resource_type != "file" || !is_file( $resource_name ) )
{
$this->_syntax_error( "include_php: {$resource_type}: {$resource_name} is not readable" );
return false;
}
if ( !$this->_is_trusted( $resource_type, $resource_name ) )
{
$this->_syntax_error( "include_php: {$resource_type}: {$resource_name} is not trusted" );
return false;
}
}
include_once( $resource_name );
}
$content = $function_name( $args, $this );
if ( $this->debugging )
{
$this->_smarty_debug_info[] = array(
"type" => "insert",
"filename" => "insert_".$args['name'],
"depth" => $this->_inclusion_depth,
"exec_time" => $this->_get_microtime( ) - $debug_start_time
);
}
if ( !empty( $args['assign'] ) )
{
$this->assign( $args['assign'], $content );
}
else
{
return $content;
}
}
}
function _run_mod_handler( )
{
$args = func_get_args( );
list( $func_name, $map_array ) = array_splice( $args, 0, 2 );
$var = $args[0];
if ( $map_array && is_array( $var ) )
{
foreach ( $var as $key => $val )
{
$args[0] = $val;
$var[$key] = $this->my_call_user_func_array( $func_name, $args );
}
return $var;
}
else
{
return $this->my_call_user_func_array( $func_name, $args );
}
}
function _dequote( $string )
{
if ( ( $string[0] == "'" || $string[0] == "\"" ) && $string[strlen( $string ) - 1] == $string[0] )
{
return substr( $string, 1, -1 );
}
else
{
return $string;
}
}
function _read_file( $filename, $start = null, $lines = null )
{
if ( !( $fd = @fopen( $filename, "r" ) ) )
{
return false;
}
flock( $fd, LOCK_SH );
if ( $start == null && $lines == null )
{
$contents = fread( $fd, filesize( $filename ) );
}
else
{
if ( 1 < $start )
{
$loop = 1;
for ( ; $loop < $start; ++$loop )
{
fgets( $fd, 65536 );
}
}
if ( $lines == null )
{
while ( !feof( $fd ) )
{
$contents .= fgets( $fd, 65536 );
}
}
else
{
$loop = 0;
for ( ; $loop < $lines; ++$loop )
{
$contents .= fgets( $fd, 65536 );
if ( feof( $fd ) )
{
break;
}
}
}
}
fclose( $fd );
return $contents;
}
function _write_file( $filename, $contents, $create_dirs = false )
{
if ( $create_dirs )
{
$this->_create_dir_structure( dirname( $filename ) );
}
if ( !( $fd = @fopen( $filename, "w" ) ) )
{
$this->_trigger_error_msg( "problem writing '{$filename}.'" );
return false;
}
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) == "WIN" || flock( $fd, LOCK_EX ) )
{
fwrite( $fd, $contents );
fclose( $fd );
chmod( $filename, 420 );
}
return true;
}
function _get_auto_base( $auto_base, $auto_source )
{
$source_md5 = md5( $auto_source );
$res = $auto_base."/_cached_templates";
return $res;
}
function _get_auto_filename( $auto_base, $auto_source, $auto_id = null )
{
$filename = !empty( $auto_source ) ? ereg_replace( "\\.htm", "", $auto_source ) : uniqid( "" );
$res = $this->_get_auto_base( $auto_base, $auto_source )."/".$filename.".php";
return $res;
}
function _rm_auto( $auto_base, $auto_source = null, $auto_id = null )
{
if ( !is_dir( $auto_base ) )
{
return false;
}
if ( !isset( $auto_source ) )
{
$res = $this->_rmdir( $auto_base, 0 );
}
else if ( isset( $auto_id ) )
{
$tname = $this->_get_auto_filename( $auto_base, $auto_source, $auto_id );
$res = is_file( $tname ) && unlink( $tname );
}
else
{
$tname = $this->_get_auto_base( $auto_base, $auto_source );
$res = $this->_rmdir( $tname );
}
return $res;
}
function _rmdir( $dirname, $level = 1 )
{
$handle = opendir( $dirname );
while ( $entry = readdir( $handle ) )
{
if ( $entry != "." && $entry != ".." )
{
if ( is_dir( $dirname."/".$entry ) )
{
$this->_rmdir( $dirname."/".$entry, $level + 1 );
}
else
{
unlink( $dirname."/".$entry );
}
}
}
closedir( $handle );
if ( $level )
{
@rmdir( $dirname );
}
return true;
}
function _create_dir_structure( $dir )
{
if ( !file_exists( $dir ) )
{
$dir_parts = preg_split( "!/+!", $dir, -1, PREG_SPLIT_NO_EMPTY );
$new_dir = $dir[0] == "/" ? "/" : "";
foreach ( $dir_parts as $dir_part )
{
$new_dir .= $dir_part;
if ( !file_exists( $new_dir ) && !mkdir( $new_dir, 505 ) )
{
$this->_trigger_error_msg( "problem creating directory \"{$dir}\"" );
return false;
}
$new_dir .= "/";
}
}
}
function _write_cache_file( $tpl_file, $cache_id, $compile_id, $results )
{
$this->_cache_info['timestamp'] = time( );
$results = "SMARTY_CACHE_INFO_HEADER".serialize( $this->_cache_info )."\n".$results;
if ( !empty( $this->cache_handler_func ) )
{
$funcname = $this->cache_handler_func;
return $funcname( "write", $this, $results, $tpl_file, $cache_id, $compile_id );
}
else
{
if ( isset( $compile_id ) || isset( $cache_id ) )
{
$auto_id = $compile_id.$cache_id;
}
else
{
$auto_id = null;
}
$cache_file = $this->_get_auto_filename( $this->cache_dir, $tpl_file, $auto_id );
$this->_write_file( $cache_file, $results, true );
return true;
}
}
function _read_cache_file( $tpl_file, $cache_id, $compile_id, &$results )
{
if ( $this->force_compile || $this->cache_lifetime == 0 )
{
return false;
}
if ( !empty( $this->cache_handler_func ) )
{
$funcname = $this->cache_handler_func;
$funcname( "read", $this, $results, $tpl_file, $cache_id, $compile_id );
}
else
{
if ( isset( $compile_id ) || isset( $cache_id ) )
{
$auto_id = $compile_id.$cache_id;
}
else
{
$auto_id = null;
}
$cache_file = $this->_get_auto_filename( $this->cache_dir, $tpl_file, $auto_id );
$results = $this->_read_file( $cache_file );
}
if ( empty( $results ) )
{
return false;
}
$cache_split = explode( "\n", $results, 2 );
$cache_header = $cache_split[0];
if ( substr( $cache_header, 0, 24 ) == "SMARTY_CACHE_INFO_HEADER" )
{
$cache_info = unserialize( substr( $cache_header, 24 ) );
$cache_timestamp = $cache_info['timestamp'];
if ( $this->cache_lifetime < time( ) - $cache_timestamp )
{
return false;
}
if ( $this->compile_check )
{
foreach ( $cache_info as $curr_cache_info )
{
switch ( $curr_cache_info[0] )
{
case "template" :
$this->_fetch_template_info( $curr_cache_info[1], $template_source, $template_timestamp, false );
if ( !( $cache_timestamp < $template_timestamp ) )
{
break;
}
return false;
break;
case "config" :
if ( $cache_timestamp < filemtime( $this->config_dir."/".$curr_cache_info[1] ) )
{
break;
}
return false;
}
}
}
$results = $cache_split[1];
return true;
}
else
{
return false;
}
}
function quote_replace( $string )
{
return preg_replace( "![\\\$]\\d!", "\\\\\\0", $string );
}
function _trigger_error_msg( $error_msg, $error_type = E_USER_WARNING )
{
trigger_error( "Smarty error: {$error_msg}", $error_type );
}
function _get_microtime( )
{
$mtime = microtime( );
$mtime = explode( " ", $mtime );
$mtime = ( double )$mtime[1] + ( double )$mtime[0];
return $mtime;
}
}
if ( !defined( "SMARTY_DIR" ) )
{
define( "SMARTY_DIR", "" );
}
require_once( SMARTY_DIR."Smarty.addons.php" );
define( "SMARTY_PHP_PASSTHRU", 0 );
define( "SMARTY_PHP_QUOTE", 1 );
define( "SMARTY_PHP_REMOVE", 2 );
define( "SMARTY_PHP_ALLOW", 3 );
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -