⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pattemplate.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?PHP/** * patTemplate * * $Id: patTemplate.php 10381 2008-06-01 03:35:53Z pasamio $ * * powerful templating engine * * @version		3.1.0 * @package		patTemplate * @author		Stephan Schmidt <schst@php.net> * @license		LGPL * @link		http://www.php-tools.net */// ** Following line Joomla! specific **require_once( dirname( __FILE__ ) . '/patErrorManager.php' );/** * template already exists */define( 'PATTEMPLATE_ERROR_TEMPLATE_EXISTS', 5010 );/** * template does not exist */define ( 'PATTEMPLATE_WARNING_NO_TEMPLATE', 5011 );/** * unknown type */define ( 'PATTEMPLATE_WARNING_UNKNOWN_TYPE', 5012 );/** * base class for module could not be found */define( 'PATTEMPLATE_ERROR_BASECLASS_NOT_FOUND', 5050 );/** * module could not be found */define( 'PATTEMPLATE_ERROR_MODULE_NOT_FOUND', 5051 );/** * array expected */define( 'PATTEMPLATE_ERROR_EXPECTED_ARRAY', 5052 );/** * No input */define( 'PATTEMPLATE_ERROR_NO_INPUT', 6000 );/** * Recursion */define( 'PATTEMPLATE_ERROR_RECURSION', 6010 );/** * patTemplate * * powerful templating engine * * @version		3.1.0 * @package		patTemplate * @author		Stephan Schmidt <schst@php.net> * @license		LGPL * @link		http://www.php-tools.net */class patTemplate{	/**	* standard system vars that identify pat tools	* @var	array	*/	var	$_systemVars			=	array(										'appName'		=>	'patTemplate',										'appVersion'	=>	'3.1.0',										'author'		=>	array(																	'Stephan Schmidt <schst@php.net>'																 )									);	/**	* default attributes for new templates	* @access	private	* @var		array	*/	var	$_defaultAttributes	=	array(										'type'			=>	'standard',										'visibility'	=>	'visible',										'loop'			=>	1,										'unusedvars'	=>	'strip',										'whitespace'	=>	'keep',										'autoclear'		=>	'off',										'autoload'		=>	'on'									);	/**	* options for patTemplate	*	* Currently the following options are implemented:	* - maintainBc defines, whether patTemplate should be backwards compatible.	*   This means, that you may use 'default' and 'empty' for subtemplates.	*	* @access	private	* @var		array	*/	var	$_options	=	array(								'startTag'			=> '{',								'endTag'			=> '}',								'root'				=> array('__default' => '.'),								'namespace'			=> 'patTemplate',								'maintainBc'		=> true,								'defaultFunction'	=> false							 );	/**	* start tag	*	* @access	private	* @var		string	*/	var $_startTag = '{';	/**	* end tag	*	* @access	private	* @var		string	*/	var $_endTag = '}';	/**	* loaded modules	*	* Modules are:	* - Readers	* - Caches	* - Variable modifiers	* - Filters	*	* @access	private	* @var		array	*/	var	$_modules		=	array();	/**	* directories, where modules can be stored	* @access	private	* @var		array	*/	var	$_moduleDirs	=	array();	/**	* stores all template names	* @access	private	* @var		array	*/	var	$_templateList	=	array();	/**	* stores all template data	* @access	private	* @var		array	*/	var	$_templates		=	array();	/**	* stores all global variables	* @access	private	* @var		array	*/	var	$_globals	=	array();	/**	* stores all local variables	* @access	private	* @var		array	*/	var	$_vars	=	array();	/**	* stores the name of the first template that has been	* found	*	* @access	private	* @var		string	*/	var	$_root;	/**	* output filters that should be used	*	* @access	private	* @var		array	*/	var	$_outputFilters = array();	/**	* input filters that should be used	*	* @access	private	* @var		array	*/	var	$_inputFilters = array();	/**	* template cache, that should be used	*	* @access	private	* @var		array	*/	var	$_tmplCache = null;	/**	* placeholders, that have been discovered	*	* @access	private	* @var		array	*/	var	$_discoveredPlaceholders = array();	/**	* Create a new patTemplate instance.	*	* The constructor accepts the type of the templates as sole parameter.	* You may choose one of:	* - html (default)	* - tex	*	* The type influences the tags you are using in your templates.	*	* @access	public	* @param	string	type (either html or tex)	*/	function patTemplate( $type = 'html' )	{		if( !defined( 'PATTEMPLATE_INCLUDE_PATH' ) ) {			define( 'PATTEMPLATE_INCLUDE_PATH', dirname( __FILE__ ) . '/patTemplate' );		}		$this->setType( $type );	}	/**	* sets an option	*	* Currently, the following options are supported	* - maintainBc (true|false)	* - namespace (string)	*	* @access	public	* @param	string	option to set	* @param	string	value of the option	*/	function setOption($option, $value)	{		$this->_options[$option] = $value;	}	/**	* gets an option	*	* @access	public	* @param	string	option to get	* @return	mixed	value of the option	*/	function getOption( $option )	{		if (!isset($this->_options[$option])) {			return null;		}		return $this->_options[$option];	}	/**	* sets name of directory where templates are stored	*	* @access	public	* @param	string	dir where templates are stored	* @deprecated		please use patTemplate::setRoot() instead	*/	function setBasedir($basedir)	{		$this->setRoot($basedir);	}	/**	* sets root base for the template	*	* The parameter depends on the reader you are using.	*	* @access	public	* @param	string	root base of the templates	*/	function setRoot($root, $reader = '__default')	{		$this->_options['root'][$reader] = $root;	}	/**	* gets name of root base for the templates	*	* @access	public	* @return	mixed 		root base	*/	function getRoot($reader = '__default')	{		return	$this->_options['root'][$reader];	}	/**	* sets namespace of patTemplate tags	*	* If you want to use more than one namespace, you may set this to	* an array. All tags in these namespaces will be treated as patTemplate	* tags.	*	* @access	public	* @param	string|array	namespace(s)	*/	function setNamespace($ns)	{		$this->_options['namespace'] = $ns;	}	/**	* gets namespace of patTemplate tags	*	* @access	public	* @return	string|array	namespace(s)	*/	function getNamespace()	{		return $this->_options['namespace'];	}	/**	* set default attribute	*	* @access	public	* @param	string	attribute name	* @param	mixed	attribute value	*/	function setDefaultAttribute( $name, $value )	{		$this->_defaultAttributes[$name]	=	$value;	}	/**	* set default attributes	*	* @access	public	* @param	array	attributes	*/	function setDefaultAttributes( $attributes )	{		$this->_defaultAttributes	=	array_merge( $this->_defaultAttributes, $attributes );	}	/**	* get default attributes	*	* @access	public	* @return	return default attributes	*/	function getDefaultAttributes()	{		return	$this->_defaultAttributes;	}	/**	* set the type for the templates	*	* @access	public	* @param	string	type (html or tex)	* @return	boolean	true on success	*/	function setType( $type )	{		switch( strtolower( $type ) )		{			case "tex":				$this->setTags( '<{', '}>' );				break;			case "html":				$this->setTags( '{', '}' );				break;			default:				return	patErrorManager::raiseWarning(														PATTEMPLATE_WARNING_UNKNOWN_TYPE,														"Unknown type '$type'. Please use 'html' or 'tex'."													);		}		return true;	}	/**	* set the start and end tag for variables	*	* @access	public	* @param	string	start tag	* @param	string	end tag	* @return	boolean	true on success	*/	function setTags( $startTag, $endTag )	{		$this->_options['startTag']	=	$startTag;		$this->_options['endTag']	=	$endTag;		$this->_startTag	=	$startTag;		$this->_endTag		=	$endTag;		return true;	}	/**	* get start tag for variables	*	* @access	public	* @return	string	start tag	*/	function getStartTag()	{		return $this->_options['startTag'];	}	/**	* get end tag for variables	*	* @access	public	* @return	string	end tag	*/	function getEndTag()	{		return $this->_options['endTag'];	}	/**	* add a directory where patTemplate should search for	* modules.	*	* You may either pass a string or an array of directories.	*	* patTemplate will be searching for a module in the same	* order you added them. If the module cannot be found in	* the custom folders, it will look in	* patTemplate/$moduleType.	*	* @access	public	* @param	string			module type	* @param	string|array	directory or directories to search.	*/	function addModuleDir( $moduleType, $dir )	{		if( !isset( $this->_moduleDirs[$moduleType] ) )			$this->_moduleDirs[$moduleType]	=	array();		if( is_array( $dir ) )			$this->_moduleDirs[$moduleType] = array_merge( $this->_moduleDirs[$moduleType], $dir );		else			array_push( $this->_moduleDirs[$moduleType], $dir );	}	/**	* Sets an attribute of a template	*	* supported attributes: visibilty, loop, parse, unusedvars	*	* @param	string	$template	name of the template	* @param	string	$attribute	name of the attribute	* @param	mixed	$value	value of the attribute	* @access	public	* @see		setAttributes(),getAttribute(), clearAttribute()	*/	function setAttribute( $template, $attribute, $value )	{		$template	=	strtolower( $template );		if( !isset( $this->_templates[$template] ) )		{			return	patErrorManager::raiseWarning(													PATTEMPLATE_WARNING_NO_TEMPLATE,													"Template '$template' does not exist."												);		}		$attribute	=	strtolower( $attribute );		$this->_templates[$template]['attributes'][$attribute]	=	$value;		return true;	}	/**	* Sets several attribute of a template	*	* $attributes has to be a assotiative arrays containing attribute/value pairs	* supported attributes: visibilty, loop, parse, unusedvars	*	* @param	string	$template	name of the template	* @param	array	$attributes	attribute/value pairs	* @access	public	* @see		setAttribute(), getAttribute(), clearAttribute()	*/	function setAttributes( $template, $attributes )	{		if( !is_array( $attributes ) )		{			return patErrorManager::raiseError( PATTEMPLATE_ERROR_EXPECTED_ARRAY, 'patTemplate::setAttributes: Expected array as second parameter, '.gettype( $attributes ).' given' );		}		$template	=	strtolower( $template );		$attributes	=	array_change_key_case( $attributes );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -