📄 smarty.class.php
字号:
<?php
/*
* Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php
* Author: Monte Ohrt <monte@ispi.net>
* Andrei Zmievski <andrei@php.net>
*
* Version: 1.5.2
* Copyright: 2001 ispi of Lincoln, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General var
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General var License for more details.
*
* You should have received a copy of the GNU Lesser General var
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to smarty-subscribe@lists.ispi.net
*
* You may contact the authors of Smarty by e-mail at:
* monte@ispi.net
* andrei@php.net
*
* Or, write to:
* Monte Ohrt
* Director of Technology, ispi
* 237 S. 70th suite 220
* Lincoln, NE 68510
*
* The latest version of Smarty can be obtained from:
* http://www.phpinsider.com/
*
*/
// set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used.
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);
class Smarty
{
/**************************************************************************/
/* BEGIN SMARTY CONFIGURATION SECTION */
/* Set the following config variables to your liking. */
/**************************************************************************/
// var vars
var $template_dir = './themes'; // name of directory for templates
var $compile_dir = './'; // name of directory for compiled templates
var $config_dir = './langs'; // directory where config files are located
var $debugging = false; // enable debugging console true/false
var $debug_tpl = 'file:debug.tpl'; // path to debug console template
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array
// that are implicitly assigned
// to all templates
var $undefined = null; // undefined variables in $global_assign will be
// created with this value
var $compile_check = true; // whether to check for compiling step or not:
// This is generally set to false once the
// application is entered into production and
// initially compiled. Leave set to true
// during development. true/false default true.
var $force_compile = false; // force templates to compile every time,
// overrides cache settings. default false.
var $caching = false; // enable caching. true/false default false.
var $cache_dir = './cache'; // name of directory for template cache files
var $cache_lifetime = 3600; // number of seconds cached content will persist.
// 0 = never expires. default is one hour (3600)
var $insert_tag_check = true; // if you have caching turned on and you
// don't use {insert} tags anywhere
// in your templates, set this to false.
// this will tell Smarty not to look for
// insert tags, thus speeding up cached page
// fetches. true/false default true.
var $cache_handler_func = null; // function used for cached content. this is
// an alternative to using the built-in file
// based caching.
var $default_template_handler_func = ''; // function to handle missing templates
var $tpl_file_ext = '.tpl'; // template file extention (deprecated)
var $php_handling = SMARTY_PHP_PASSTHRU;
// how smarty handles php tags in the templates
// possible values:
// SMARTY_PHP_PASSTHRU -> echo tags as is
// SMARTY_PHP_QUOTE -> escape tags as entities
// SMARTY_PHP_REMOVE -> remove php tags
// SMARTY_PHP_ALLOW -> execute php tags
// default: SMARTY_PHP_PASSTHRU
var $security = false; // enable template security (default false)
var $secure_dir = array('./templates'); // array of directories considered secure
var $security_settings = array(
'PHP_HANDLING' => false,
'IF_FUNCS' => array('array', 'list',
'isset', 'empty',
'count', 'sizeof',
'in_array', 'is_array'),
'INCLUDE_ANY' => false,
'PHP_TAGS' => false,
'MODIFIER_FUNCS' => array('count')
);
var $trusted_dir = array(); // directories where trusted templates
// reside ($security is disabled during their
// execution).
var $left_delimiter = '{'; // template tag delimiters.
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; // display HTML info header at top of page output
var $show_info_include = false; // display HTML comments at top & bottom of
// each included template
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
// Smarty to compile templates
var $resource_funcs = array(); // functions that resource handlers are mapped to
var $prefilter_funcs = array(); // functions that templates are filtered through
// before being compiled
var $postfilter_funcs = array(); // functions that compiled templates are filtered
// through after compilation
var $request_vars_order = "EGPCS"; // the order in which request variables are
// registered, similar to variables_order
// in php.ini
var $compile_id = null; // persistent compile identifier
/**************************************************************************/
/* END SMARTY CONFIGURATION SECTION */
/* There should be no need to touch anything below this line. */
/**************************************************************************/
// internal vars
var $_error_msg = false; // error messages. true/false
var $_tpl_vars = array(); // where assigned template vars are kept
var $_smarty_vars = array(); // stores run-time $smarty.* vars
var $_sections = array(); // keeps track of sections
var $_foreach = array(); // keeps track of foreach blocks
var $_conf_obj = null; // configuration object
var $_config = array(); // loaded configuration settings
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
var $_version = '1.5.2'; // Smarty version number
var $_extract = false; // flag for custom functions
var $_inclusion_depth = 0; // current template inclusion depth
var $_compile_id = null; // for different compiled templates
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
var $_smarty_debug_info = array(); // debugging information for debug console
var $_cache_info = array(); // info that makes up a cache file
/*======================================================================*\
Function: Smarty
Purpose: Constructor
\*======================================================================*/
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);
}
}
}
}
/*======================================================================*\
Function: assign()
Purpose: assigns values to template variables
\*======================================================================*/
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
Purpose: appens values to template variables
\*======================================================================*/
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;
}
/**
* Define call_user_func_array if it does not exist
**/
function my_call_user_func_array($func, $ar) {
if (!function_exists('call_user_func_array')) {
$funcCall = "$func(";
// Build function call string by adding each parameter
for ($i=0; $i<sizeof($ar); $i++) {
eval ("\$funcCall .= '\$ar[$i],';");
}
// Strip off last comma ','
$funcCall = substr($funcCall, 0, -1);
$funcCall .= ')';
eval("\$retval = $funcCall;");
return $retval;
} else
return call_user_func_array($func, $ar);
}
/*======================================================================*\
Function: clear_assign()
Purpose: clear the given assigned template variable.
\*======================================================================*/
function clear_assign($tpl_var)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -