php封装的smarty类完整实例_php实例
程序员文章站
2022-05-21 15:25:47
...
本文实例讲述了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. *
-
*
- NONE => no debugging control allowed *
- URL => enable debugging when SMARTY_DEBUG is found in the URL. *
-
*
- NONE => no debugging control allowed *
- URL => enable debugging when SMARTY_DEBUG is found in the URL. *
更多关于Smarty相关内容感兴趣的读者可查看本站专题:《smarty模板入门基础教程》、《PHP模板技术总结》、《PHP基于pdo操作数据库技巧总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于smarty模板的PHP程序设计有所帮助。