📄 smarty.class.php
字号:
function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
{
if (file_exists(SMARTY_DIR . $this->compiler_file)) {
require_once(SMARTY_DIR . $this->compiler_file);
} else {
// use include_path
require_once($this->compiler_file);
}
$smarty_compiler = new $this->compiler_class;
$smarty_compiler->template_dir = $this->template_dir;
$smarty_compiler->compile_dir = $this->compile_dir;
$smarty_compiler->plugins_dir = $this->plugins_dir;
$smarty_compiler->config_dir = $this->config_dir;
$smarty_compiler->force_compile = $this->force_compile;
$smarty_compiler->caching = $this->caching;
$smarty_compiler->php_handling = $this->php_handling;
$smarty_compiler->left_delimiter = $this->left_delimiter;
$smarty_compiler->right_delimiter = $this->right_delimiter;
$smarty_compiler->_version = $this->_version;
$smarty_compiler->security = $this->security;
$smarty_compiler->secure_dir = $this->secure_dir;
$smarty_compiler->security_settings = $this->security_settings;
$smarty_compiler->trusted_dir = $this->trusted_dir;
$smarty_compiler->use_sub_dirs = $this->use_sub_dirs;
$smarty_compiler->_reg_objects = &$this->_reg_objects;
$smarty_compiler->_plugins = &$this->_plugins;
$smarty_compiler->_tpl_vars = &$this->_tpl_vars;
$smarty_compiler->default_modifiers = $this->default_modifiers;
$smarty_compiler->compile_id = $this->_compile_id;
$smarty_compiler->_config = $this->_config;
$smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals;
$smarty_compiler->_cache_serial = null;
$smarty_compiler->_cache_include = $cache_include_path;
$_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);
if ($smarty_compiler->_cache_serial) {
$this->_cache_include_info = array(
'cache_serial'=>$smarty_compiler->_cache_serial
,'plugins_code'=>$smarty_compiler->_plugins_code
,'include_file_path' => $cache_include_path);
} else {
$this->_cache_include_info = null;
}
return $_results;
}
function _get_compile_path($resource_name)
{
return $this->_get_auto_filename($this->compile_dir, $resource_name,
$this->_compile_id) . '.php';
}
function _fetch_resource_info(&$params)
{
if(!isset($params['get_source'])) { $params['get_source'] = true; }
if(!isset($params['quiet'])) { $params['quiet'] = false; }
$_return = false;
$_params = array('resource_name' => $params['resource_name']) ;
if (isset($params['resource_base_path']))
$_params['resource_base_path'] = $params['resource_base_path'];
else
$_params['resource_base_path'] = $this->template_dir;
if ($this->_parse_resource_name($_params)) {
$_resource_type = $_params['resource_type'];
$_resource_name = $_params['resource_name'];
switch ($_resource_type) {
case 'file':
if ($params['get_source']) {
$params['source_content'] = $this->_read_file($_resource_name);
}
$params['resource_timestamp'] = filemtime($_resource_name);
$_return = is_file($_resource_name);
break;
default:
// call resource functions to fetch the template source and timestamp
if ($params['get_source']) {
$_source_return = isset($this->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],
array($_resource_name, &$params['source_content'], &$this));
} else {
$_source_return = true;
}
$_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&
call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],
array($_resource_name, &$params['resource_timestamp'], &$this));
$_return = $_source_return && $_timestamp_return;
break;
}
}
if (!$_return) {
// see if we can get a template with the default template handler
if (!empty($this->default_template_handler_func)) {
if (!is_callable($this->default_template_handler_func)) {
$this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
} else {
$_return = call_user_func_array(
$this->default_template_handler_func,
array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));
}
}
}
if (!$_return) {
if (!$params['quiet']) {
$this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');
}
} else if ($_return && $this->security) {
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');
if (!smarty_core_is_secure($_params, $this)) {
if (!$params['quiet'])
$this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');
$params['source_content'] = null;
$params['resource_timestamp'] = null;
return false;
}
}
return $_return;
}
function _parse_resource_name(&$params)
{
// split tpl_path by the first colon
$_resource_name_parts = explode(':', $params['resource_name'], 2);
if (count($_resource_name_parts) == 1) {
// no resource type given
$params['resource_type'] = $this->default_resource_type;
$params['resource_name'] = $_resource_name_parts[0];
} else {
if(strlen($_resource_name_parts[0]) == 1) {
// 1 char is not resource type, but part of filepath
$params['resource_type'] = $this->default_resource_type;
$params['resource_name'] = $params['resource_name'];
} else {
$params['resource_type'] = $_resource_name_parts[0];
$params['resource_name'] = $_resource_name_parts[1];
}
}
if ($params['resource_type'] == 'file') {
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) {
foreach ((array)$params['resource_base_path'] as $_curr_path) {
$_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];
if (file_exists($_fullpath) && is_file($_fullpath)) {
$params['resource_name'] = $_fullpath;
return true;
}
// didn't find the file, try include_path
$_params = array('file_path' => $_fullpath);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');
if(smarty_core_get_include_path($_params, $this)) {
$params['resource_name'] = $_params['new_file_path'];
return true;
}
}
return false;
} else {
/* absolute path */
return file_exists($params['resource_name']);
}
} elseif (empty($this->_plugins['resource'][$params['resource_type']])) {
$_params = array('type' => $params['resource_type']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php');
smarty_core_load_resource_plugin($_params, $this);
}
return true;
}
function _run_mod_handler()
{
$_args = func_get_args();
list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);
list($_func_name, $_tpl_file, $_tpl_line) =
$this->_plugins['modifier'][$_modifier_name];
$_var = $_args[0];
foreach ($_var as $_key => $_val) {
$_args[0] = $_val;
$_var[$_key] = call_user_func_array($_func_name, $_args);
}
return $_var;
}
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)
{
if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {
$contents = ($size = filesize($filename)) ? fread($fd, $size) : '';
fclose($fd);
return $contents;
} else {
return false;
}
}
function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)
{
$_compile_dir_sep = $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
$_return = $auto_base . DIRECTORY_SEPARATOR;
if(isset($auto_id)) {
$auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));
$_return .= $auto_id . $_compile_dir_sep;
}
if(isset($auto_source)) {
$_filename = urlencode(basename($auto_source));
$_crc32 = sprintf('%08X', crc32($auto_source));
$_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .
substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;
$_return .= '%%' . $_crc32 . '%%' . $_filename;
}
return $_return;
}
function _unlink($resource, $exp_time = null)
{
if(isset($exp_time)) {
if(time() - @filemtime($resource) >= $exp_time) {
return @unlink($resource);
}
} else {
return @unlink($resource);
}
}
function _get_auto_id($cache_id=null, $compile_id=null) {
if (isset($cache_id))
return (isset($compile_id)) ? $cache_id . '|' . $compile_id : $cache_id;
elseif(isset($compile_id))
return $compile_id;
else
return null;
}
function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,
$file = null, $line = null, $error_type = E_USER_ERROR)
{
if(isset($file) && isset($line)) {
$info = ' ('.basename($file).", line $line)";
} else {
$info = '';
}
if (isset($tpl_line) && isset($tpl_file)) {
$this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type);
} else {
$this->trigger_error($error_msg . $info, $error_type);
}
}
function _process_compiled_include_callback($match) {
$_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3];
ob_start();
$_func($this);
$_ret = ob_get_contents();
ob_end_clean();
return $_ret;
}
function _smarty_include($params)
{
if ($this->debugging) {
$_params = array();
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
$debug_start_time = smarty_core_get_microtime($_params, $this);
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $params['smarty_include_tpl_file'],
'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
$this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);
array_unshift($this->_config, $this->_config[0]);
$_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);
if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
|| $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
{
include($_smarty_compile_path);
}
array_shift($this->_config);
$this->_inclusion_depth--;
if ($this->debugging) {
$_params = array();
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;
}
if ($this->caching) {
$this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
}
}
function &_smarty_cache_attrs($cache_serial, $count) {
$_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count];
if ($this->_cache_including) {
/* return next set of cache_attrs */
$_return =& current($_cache_attrs);
next($_cache_attrs);
return $_return;
} else {
/* add a reference to a new set of cache_attrs */
$_cache_attrs[] = array();
return $_cache_attrs[count($_cache_attrs)-1];
}
}
function _include($filename, $once=false, $params=null)
{
if ($once) {
return include_once($filename);
} else {
return include($filename);
}
}
function _eval($code, $params=null)
{
return eval($code);
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -