php封装的smarty类完整实例
php  /  管理员 发布于 7年前   184
本文实例讲述了php封装的smarty类。分享给大家供大家参考,具体如下: * @author Uwe Tews * @author Rodney Rehm * @package Smarty * @version 3.1.19 *//** * define shorthand directory separator constant */if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR);}/** * set SMARTY_DIR to absolute path to Smarty library files. * Sets SMARTY_DIR only if user application has not already defined it. */if (!defined('SMARTY_DIR')) { define('SMARTY_DIR', dirname(__FILE__) . DS);}/** * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. */if (!defined('SMARTY_SYSPLUGINS_DIR')) { define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);}if (!defined('SMARTY_PLUGINS_DIR')) { define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);}if (!defined('SMARTY_MBSTRING')) { define('SMARTY_MBSTRING', function_exists('mb_split'));}if (!defined('SMARTY_RESOURCE_CHAR_SET')) { // UTF-8 can only be done properly when mbstring is available! /** * @deprecated in favor of Smarty::$_CHARSET */ define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');}if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { /** * @deprecated in favor of Smarty::$_DATE_FORMAT */ define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');}/** * register the class autoloader */if (!defined('SMARTY_SPL_AUTOLOAD')) { define('SMARTY_SPL_AUTOLOAD', 0);}if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { $registeredAutoLoadFunctions = spl_autoload_functions(); if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { spl_autoload_register(); }} else { spl_autoload_register('smartyAutoload');}/** * Load always needed external class files */include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_cacheresource_file.php';/** * This is the main Smarty class * * @package Smarty */class Smarty extends Smarty_Internal_TemplateBase{ /**#@+ * constant definitions */ /** * smarty version */ const SMARTY_VERSION = 'Smarty-3.1.19'; /** * define variable scopes */ const SCOPE_LOCAL = 0; const SCOPE_PARENT = 1; const SCOPE_ROOT = 2; const SCOPE_GLOBAL = 3; /** * define caching modes */ const CACHING_OFF = 0; const CACHING_LIFETIME_CURRENT = 1; const CACHING_LIFETIME_SAVED = 2; /** * define constant for clearing cache files be saved expiration datees */ const CLEAR_EXPIRED = - 1; /** * define compile check modes */ const COMPILECHECK_OFF = 0; const COMPILECHECK_ON = 1; const COMPILECHECK_CACHEMISS = 2; /** * modes for handling of "" tags in templates. */ const PHP_PASSTHRU = 0; //-> print tags as plain text const PHP_QUOTE = 1; //-> escape tags as entities const PHP_REMOVE = 2; //-> escape tags as entities const PHP_ALLOW = 3; //-> escape tags as entities /** * filter types */ const FILTER_POST = 'post'; const FILTER_PRE = 'pre'; const FILTER_OUTPUT = 'output'; const FILTER_VARIABLE = 'variable'; /** * plugin types */ const PLUGIN_FUNCTION = 'function'; const PLUGIN_BLOCK = 'block'; const PLUGIN_COMPILER = 'compiler'; const PLUGIN_MODIFIER = 'modifier'; const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; /**#@-*/ /** * assigned global tpl vars */ public static $global_tpl_vars = array(); /** * error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors() */ public static $_previous_error_handler = null; /** * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() */ public static $_muted_directories = array(); /** * Flag denoting if Multibyte String functions are available */ public static $_MBSTRING = SMARTY_MBSTRING; /** * The character set to adhere to (e.g. "UTF-8") */ public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET; /** * The date format to be used internally * (accepts date() and strftime()) */ public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; /** * Flag denoting if PCRE should run in UTF-8 mode */ public static $_UTF8_MODIFIER = 'u'; /** * Flag denoting if operating system is windows */ public static $_IS_WINDOWS = false; /**#@+ * variables */ /** * auto literal on delimiters with whitspace * * @var boolean */ public $auto_literal = true; /** * display error on not assigned variables * * @var boolean */ public $error_unassigned = false; /** * look up relative filepaths in include_path * * @var boolean */ public $use_include_path = false; /** * template directory * * @var array */ private $template_dir = array(); /** * joined template directory string used in cache keys * * @var string */ public $joined_template_dir = null; /** * joined config directory string used in cache keys * * @var string */ public $joined_config_dir = null; /** * default template handler * * @var callable */ public $default_template_handler_func = null; /** * default config handler * * @var callable */ public $default_config_handler_func = null; /** * default plugin handler * * @var callable */ public $default_plugin_handler_func = null; /** * compile directory * * @var string */ private $compile_dir = null; /** * plugins directory * * @var array */ private $plugins_dir = array(); /** * cache directory * * @var string */ private $cache_dir = null; /** * config directory * * @var array */ private $config_dir = array(); /** * force template compiling? * * @var boolean */ public $force_compile = false; /** * check template for modifications? * * @var boolean */ public $compile_check = true; /** * use sub dirs for compiled/cached files? * * @var boolean */ public $use_sub_dirs = false; /** * allow ambiguous resources (that are made unique by the resource handler) * * @var boolean */ public $allow_ambiguous_resources = false; /** * caching enabled * * @var boolean */ public $caching = false; /** * merge compiled includes * * @var boolean */ public $merge_compiled_includes = false; /** * template inheritance merge compiled includes * * @var boolean */ public $inheritance_merge_compiled_includes = true; /** * cache lifetime in seconds * * @var integer */ public $cache_lifetime = 3600; /** * force cache file creation * * @var boolean */ public $force_cache = false; /** * Set this if you want different sets of cache files for the same * templates. * * @var string */ public $cache_id = null; /** * Set this if you want different sets of compiled files for the same * templates. * * @var string */ public $compile_id = null; /** * template left-delimiter * * @var string */ public $left_delimiter = "{"; /** * template right-delimiter * * @var string */ public $right_delimiter = "}"; /**#@+ * security */ /** * class name * This should be instance of Smarty_Security. * * @var string * @see Smarty_Security */ public $security_class = 'Smarty_Security'; /** * implementation of security class * * @var Smarty_Security */ public $security_policy = null; /** * controls handling of PHP-blocks * * @var integer */ public $php_handling = self::PHP_PASSTHRU; /** * controls if the php template file resource is allowed * * @var bool */ public $allow_php_templates = false; /** * Should compiled-templates be prevented from being called directly? * {@internal * Currently used by Smarty_Internal_Template only. * }} * * @var boolean */ public $direct_access_security = true; /**#@-*/ /** * debug mode * Setting this to true enables the debug-console. * * @var boolean */ public $debugging = false; /** * This determines if debugging is enable-able from the browser. *
*
* * @var string */ public $debugging_ctrl = 'NONE'; /** * Name of debugging URL-param. * Only used when $debugging_ctrl is set to 'URL'. * The name of the URL-parameter that activates debugging. * * @var type */ public $smarty_debug_id = 'SMARTY_DEBUG'; /** * Path of debug template. * * @var string */ public $debug_tpl = null; /** * When set, smarty uses this value as error_reporting-level. * * @var int */ public $error_reporting = null; /** * Internal flag for getTags() * * @var boolean */ public $get_used_tags = false; /**#@+ * config var settings */ /** * Controls whether variables with the same name overwrite each other. * * @var boolean */ public $config_overwrite = true; /** * Controls whether config values of on/true/yes and off/false/no get converted to boolean. * * @var boolean */ public $config_booleanize = true; /** * Controls whether hidden config sections/vars are read from the file. * * @var boolean */ public $config_read_hidden = false; /**#@-*/ /**#@+ * resource locking */ /** * locking concurrent compiles * * @var boolean */ public $compile_locking = true; /** * Controls whether cache resources should emply locking mechanism * * @var boolean */ public $cache_locking = false; /** * seconds to wait for acquiring a lock before ignoring the write lock * * @var float */ public $locking_timeout = 10; /**#@-*/ /** * global template functions * * @var array */ public $template_functions = array(); /** * resource type used if none given * Must be an valid key of $registered_resources. * * @var string */ public $default_resource_type = 'file'; /** * caching type * Must be an element of $cache_resource_types. * * @var string */ public $caching_type = 'file'; /** * internal config properties * * @var array */ public $properties = array(); /** * config type * * @var string */ public $default_config_type = 'file'; /** * cached template objects * * @var array */ public $template_objects = array(); /** * check If-Modified-Since headers * * @var boolean */ public $cache_modified_check = false; /** * registered plugins * * @var array */ public $registered_plugins = array(); /** * plugin search order * * @var array */ public $plugin_search_order = array('function', 'block', 'compiler', 'class'); /** * registered objects * * @var array */ public $registered_objects = array(); /** * registered classes * * @var array */ public $registered_classes = array(); /** * registered filters * * @var array */ public $registered_filters = array(); /** * registered resources * * @var array */ public $registered_resources = array(); /** * resource handler cache * * @var array */ public $_resource_handlers = array(); /** * registered cache resources * * @var array */ public $registered_cache_resources = array(); /** * cache resource handler cache * * @var array */ public $_cacheresource_handlers = array(); /** * autoload filter * * @var array */ public $autoload_filters = array(); /** * default modifier * * @var array */ public $default_modifiers = array(); /** * autoescape variable output * * @var boolean */ public $escape_html = false; /** * global internal smarty vars * * @var array */ public static $_smarty_vars = array(); /** * start time for execution time calculation * * @var int */ public $start_time = 0; /** * default file permissions * * @var int */ public $_file_perms = 0644; /** * default dir permissions * * @var int */ public $_dir_perms = 0771; /** * block tag hierarchy * * @var array */ public $_tag_stack = array(); /** * self pointer to Smarty object * * @var Smarty */ public $smarty; /** * required by the compiler for BC * * @var string */ public $_current_file = null; /** * internal flag to enable parser debugging * * @var bool */ public $_parserdebug = false; /** * Saved parameter of merged templates during compilation * * @var array */ public $merged_templates_func = array(); /**#@-*/ /** * Initialize new Smarty object */ public function __construct() { // selfpointer needed by some other class methods $this->smarty = $this; if (is_callable('mb_internal_encoding')) { mb_internal_encoding(Smarty::$_CHARSET); } $this->start_time = microtime(true); // set default dirs $this->setTemplateDir('.' . DS . 'templates' . DS) ->setCompileDir('.' . DS . 'templates_c' . DS) ->setPluginsDir(SMARTY_PLUGINS_DIR) ->setCacheDir('.' . DS . 'cache' . DS) ->setConfigDir('.' . DS . 'configs' . DS); $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl'; if (isset($_SERVER['SCRIPT_NAME'])) { $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); } } /** * Class destructor */ public function __destruct() { // intentionally left blank } /** * <
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号