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

📄 pattemplate.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		if( !isset( $this->_templates[$template] ) )		{			return	patErrorManager::raiseWarning(													PATTEMPLATE_WARNING_NO_TEMPLATE,													"Template '$template' does not exist."												);		}		$this->_templates[$template]['attributes']	=	array_merge( $this->_templates[$template]['attributes'], $attributes );		return true;	}	/**	* Get all attributes of a template	*	* @param	string	name of the template	* @return	array	attributes	* @access	public	*/	function getAttributes( $template )	{		$template	=	strtolower( $template );		if( !isset( $this->_templates[$template] ) )		{			return	patErrorManager::raiseWarning(													PATTEMPLATE_WARNING_NO_TEMPLATE,													"Template '$template' does not exist."												);		}		return	$this->_templates[$template]['attributes'];	}	/**	* Gets 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	* @return	mixed	value of the attribute	* @access	public	* @see		setAttribute(), setAttributes(), clearAttribute()	*/	function getAttribute( $template, $attribute )	{		$template	=	strtolower( $template );		$attribute	=	strtolower( $attribute );		if( !isset( $this->_templates[$template] ) )		{			return	patErrorManager::raiseWarning(													PATTEMPLATE_WARNING_NO_TEMPLATE,													"Template '$template' does not exist."												);		}		return	$this->_templates[$template]['attributes'][$attribute];	}	/**	* Clears 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	* @access	public	* @see		setAttribute(), setAttributes(), getAttribute()	*/	function clearAttribute( $template, $attribute )	{		$template	=	strtolower( $template );		$attribute	=	strtolower( $attribute );		if( !isset( $this->_templates[$template] ) )		{			return	patErrorManager::raiseWarning(													PATTEMPLATE_WARNING_NO_TEMPLATE,													"Template '$template' does not exist."												);		}		$this->_templates[$template]['attributes'][$attribute]	=	'';;		return true;	}	/**	* Prepare a template	*	* This can be used if you want to add variables to	* a template, that has not been loaded yet.	*	* @access	public	* @param	string	template name	*/	function prepareTemplate( $name )	{		$name	=	strtolower( $name );		if( !isset( $this->_vars[$name] ) )		{			$this->_vars[$name]	=	array(												'scalar'	=>	array(),												'rows'		=>	array()											);		}	}	/**	* add a variable to a template	*	* A variable may also be an indexed array, but _not_	* an associative array!	*	* @access	public	* @param	string	$template	name of the template	* @param	string	$varname	name of the variable	* @param	mixed	$value		value of the variable	*/	function addVar( $template, $varname, $value )	{		$template = strtolower( $template );		$varname  = strtoupper( $varname );		if( !is_array( $value ) ) {			$this->_vars[$template]['scalar'][$varname] = $value;			return true;		}		$cnt = count( $value );		for ($i = 0; $i < $cnt; $i++) {			if (!isset( $this->_vars[$template]['rows'][$i] )) {				$this->_vars[$template]['rows'][$i] = array();			}			$this->_vars[$template]['rows'][$i][$varname] = $value[$i];		}		return true;	}	/**	* get the value of a variable	*	* @access	public	* @param	string	name of the template	* @param	string	name of the variable	* @return	string	value of the variable, null if the variable is not set	*/	function getVar( $template, $varname )	{		$template	=	strtolower( $template );		$varname	=	strtoupper( $varname );		if( isset( $this->_vars[$template]['scalar'][$varname] ) )			return $this->_vars[$template]['scalar'][$varname];		$value = array();		if(!isset($this->_vars[$template]['rows']))			return null;		$cnt = count( $this->_vars[$template]['rows'] );		for( $i = 0; $i < $cnt; $i++ )		{			if( !isset( $this->_vars[$template]['rows'][$i][$varname] ) )				continue;			array_push( $value, $this->_vars[$template]['rows'][$i][$varname] );		}		if( !empty( $value ) )			return $value;		return null;	}	/**	* clear the value of a variable	*	* @access	public	* @param	string	name of the template	* @param	string	name of the variable	* @return   boolean	* @see	  clearVars(), clearTemplate()	*/	function clearVar( $template, $varname )	{		$template	=	strtolower( $template );		$varname	=	strtoupper( $varname );		if (isset( $this->_vars[$template]['scalar'][$varname] )) {			unset ($this->_vars[$template]['scalar'][$varname]);			return true;		}		$result = false;		$cnt = count( $this->_vars[$template]['rows'] );		for ($i = 0; $i < $cnt; $i++) {			if (!isset($this->_vars[$template]['rows'][$i][$varname])) {				continue;			}			unset($this->_vars[$template]['rows'][$i][$varname]);			$result = true;		}		return $result;	}	/**	* Adds several variables to a template	*	* Each Template can have an unlimited amount of its own variables	* $variables has to be an assotiative array containing variable/value pairs	*	* @param	string	$template	name of the template	* @param	array	$variables	assotiative array of the variables	* @param	string	$prefix	prefix for all variable names	* @access	public	* @see		addVar(), addRows(), addGlobalVar(), addGlobalVars()	*/	function addVars( $template, $variables, $prefix = '' )	{		$template	=	strtolower( $template );		$prefix		=	strtoupper( $prefix );		$variables	=	array_change_key_case( $variables, CASE_UPPER );		foreach ($variables as $varname => $value) {			$varname = $prefix.$varname;			if (!is_array($value)) {				if (!is_scalar($value)) {					continue;				}				$this->_vars[$template]['scalar'][$varname] = $value;				continue;			}			$cnt = count( $value );			for( $i = 0; $i < $cnt; $i++ ) {				if( !isset( $this->_vars[$template]['rows'][$i] ) )					$this->_vars[$template]['rows'][$i]	=	array();				$this->_vars[$template]['rows'][$i][$varname]	=	$value[$i];			}		}	}	/**	* Clear all variables in a template	*	* This clears only variables, but does	*	* @access	public	* @param	string	$template	name of the template	* @return   boolean	* @see		clearVar(), clearTemplate()	*/	function clearVars( $template )	{		$template = strtolower($template);		$this->_vars[$template] = array(										 'scalar' => array(),										 'rows'   => array()										);		return true;	}	/**	* Adds several rows of variables to a template	*	* Each Template can have an unlimited amount of its own variables	* Can be used to add a database result as variables to a template	*	* @param	string	$template	name of the template	* @param	array	$rows	array containing assotiative arrays with variable/value pairs	* @param	string	$prefix	prefix for all variable names	* @access	public	* @see		addVar(), addVars(), addGlobalVar(), addGlobalVars()	*/	function addRows( $template, $rows, $prefix = '' )	{		$template	=	strtolower( $template );		$prefix		=	strtoupper( $prefix );		$cnt		=	count( $rows );		for( $i = 0; $i < $cnt; $i++ )		{			if( !isset( $this->_vars[$template]['rows'][$i] ) )				$this->_vars[$template]['rows'][$i]	=	array();			$rows[$i]	=	array_change_key_case( $rows[$i], CASE_UPPER );			foreach( $rows[$i] as $varname => $value )			{				$this->_vars[$template]['rows'][$i][$prefix.$varname]	=	$value;			}		}	}	/**	* Adds an object to a template	*	* All properties of the object will be available as template variables.	*	* @access	public	* @param	string			name of the template	* @param	object|array	object or array of objects	* @param	string			prefix for all variable names	* @param	boolean			ignore private properties (starting with _)	* @see		addVar(), addRows(), addGlobalVar(), addGlobalVars()	*/	function addObject( $template, $object, $prefix = '', $ignorePrivate = false )	{		if( is_array( $object ) ) {			$rows = array();			foreach($object as $o) {				array_push( $rows, $this->getObjectVars($o, $ignorePrivate) );			}	   		return $this->addRows( $template, $rows, $prefix );		} elseif (is_object($object)) {			return $this->addVars( $template, $this->getObjectVars($object, $ignorePrivate), $prefix );		}		return false;	}	/**	* get the vars from an object	*	* @access   private	* @param	object	* @param	boolean	 ignore private properties (starting with _)	* @return   array	*/	function getObjectVars($obj, $ignorePrivate = false)	{		if (method_exists($obj, 'getVars')) {			return $obj->getVars();		}		$vars = get_object_vars($obj);		if ($ignorePrivate === false) {			return $vars;		}		foreach ($vars as $var => $value) {			if ($var{0} == '_') {				unset($vars[$var]);			}		}		return $vars;	}	/**	* Adds a global variable	*	* Global variables are valid in all templates of this object.	* A global variable has to be scalar, it will be converted to a string.	*	* @access	public	* @param	string	$varname	name of the global variable	* @param	string	$value		value of the variable	* @return	boolean	true on success	* @see		addGlobalVars(), addVar(), addVars(), addRows()	*/	function addGlobalVar( $varname, $value )	{		$this->_globals[strtoupper( $varname )]	=	( string )$value;		return	true;	}	/**	* Clears a global variable	*	* @access	public	* @param	string	$varname	name of the global variable	* @return	boolean	true on success	* @see		clearVar(), clearVars(), clearGlobalVars()	*/	function clearGlobalVar( $varname )	{		$varname = strtoupper( $varname );		if (!isset($this->_globals[$varname])) {			return false;		}		unset($this->_globals[$varname]);		return	true;	}	/**	* Clears all global variables	*	* @access	public	* @return	boolean	true on success	* @see		clearVar(), clearVars(), clearGlobalVar()	*/	function clearGlobalVars()	{		$this->_globals = array();		return	true;	}	/**	* Adds several global variables	*	* Global variables are valid in all templates of this object.	*	* $variables is an associative array, containing name/value pairs of the variables.	*	* @access	public	* @param	array	$variables	array containing the variables	* @param	string	$prefix		prefix for variable names	* @return	boolean	true on success	* @see		addGlobalVar(), addVar(), addVars(), addRows()	*/	function addGlobalVars( $variables, $prefix = '' )	{		$variables	=	array_change_key_case( $variables, CASE_UPPER );		$prefix		=	strtoupper( $prefix );		foreach( $variables as $varname => $value )		{			$this->_globals[$prefix.$varname]	=	( string )$value;		}		return	true;	}	/**	* get all global variables	*	* @access	public	* @return	array	global variables	*/	function getGlobalVars()	{		return	$this->_globals;	}	/**	* checks wether a template exists	*	* @access	public	* @param	string		name of the template	* @return	boolean		true, if the template exists, false otherwise	*/	function exists( $name )	{		return	in_array( strtolower( $name ), $this->_templateList );	}	/**	* enable a template cache	*	* A template cache will improve performace, as the templates	* do not have to be read on each request.	*	* @access	public	* @param	string		name of the template cache	* @param	array		parameters for the template cache	* @return	boolean		true on success, patError otherwise	*/	function useTemplateCache( $cache, $params = array() )	{		if( !is_object( $cache ) )		{			$cache = &$this->loadModule( 'TemplateCache', $cache, $params );		}		if( patErrorManager::isError( $cache ) )			return $cache;		$this->_tmplCache = &$cache;		return true;	}	/**	* enable an output filter	*	* Output filters are used to modify the template	* result before it is sent to the browser.	*	* They are applied, when displayParsedTemplate() is called.	*	* @access	public	* @param	string		name of the output filter	* @param	array		parameters for the output filter	* @return	boolean		true on success, patError otherwise	*/	function applyOutputFilter( $filter, $params = array(), $template = null )	{		if (!is_object($filter)) {			$filter = &$this->loadModule( 'OutputFilter', $filter, $params );		}		if (patErrorManager::isError($filter)) {			return $filter;		}		if ($template === null) {			$this->_outputFilters[] = &$filter;			return true;		}		$template = strtolower($template);		if (!$this->exists($template)) {			return patErrorManager::raiseWarning(PATTEMPLATE_WARNING_NO_TEMPLATE, 'The selected template does not exist');		}		$this->_templates[$template]['attributes']['outputfilter'] = &$filter;		return true;	}	/**	* enable an input filter	*	* input filters are used to modify the template	* stream before it is split into smaller templates-	*	* @access	public	* @param	string		name of the input filter

⌨️ 快捷键说明

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