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

📄 reader.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 3 页
字号:
													$this->_createErrorMessage( sprintf( 'No cdata is allowed inside a template of type %s (cdata was found in %s)', $tmpl['attributes']['type'], $tmpl['name'] ) )
												);
				}
				$data	=	null;
				break;
		}

		/**
		 * store the content
		 */
		$tmpl['content'] = $data;

		/**
		 * No external template
		 */
		if( !isset( $tmpl['attributes']['src'] ) ) {
			$tmpl['loaded']	=	true;
		}

		/**
		 * add it to the dependencies
		 */
		 if( !empty( $this->_tmplStack ) ) {
			$this->_addToParentTag( 'dependencies', $name );

			if( isset( $tmpl['attributes']['placeholder'] ) ) {
				// maintain BC
				if( $this->shouldMaintainBc() && $tmpl['attributes']['placeholder'] === 'none' ) {
					$tmpl['attributes']['placeholder'] = '__none';
				}

				if( $tmpl['attributes']['placeholder'] !== '__none' ) {
					$this->_characterData( $this->_startTag.(strtoupper( $tmpl['attributes']['placeholder'] ) ).$this->_endTag );
				}
			} else {
				$this->_characterData( sprintf( "%sTMPL:%s%s", $this->_startTag, strtoupper( $name ), $this->_endTag ) );
			}
		 }

		unset( $tmpl['name'] );
		unset( $tmpl['tag'] );

		$this->_templates[$name] = $tmpl;

		return true;
	}

	/**
	* create a new sub-template
	*
	* @access	private
	* @param	array		attributes
	* @return	boolean		true on success
	*/
	function _initSubTemplate( $attributes )
	{
		/**
		 * has to be embedded in a 'tmpl' tag
		 */
		if (!$this->_parentTagIs('tmpl')) {
			return patErrorManager::raiseError(
												PATTEMPLATE_READER_ERROR_INVALID_TAG,
												$this->_createErrorMessage( 'A subtemplate is only allowed in a TMPL tag' )
												);
		}

		/**
		 * needs a condition attribute
		 */
		if (!isset( $attributes['condition'] )) {
			return patErrorManager::raiseError(
												PATTEMPLATE_READER_ERROR_NO_CONDITION_SPECIFIED,
												$this->_createErrorMessage( 'Missing \'condition\' attribute for subtemplate' )
												);
		}
		$matches = array();
		$regexp = '/^'.$this->_startTag.'([^a-z]+[^\\\])'.$this->_endTag.'$/U';
		if (preg_match($regexp, $attributes['condition'], $matches)) {
			$attributes['var'] = $matches[1];
		}

		/**
		 * maintain BC
		 */
		if( $this->shouldMaintainBc() && in_array( $attributes['condition'], array( 'default', 'empty', 'odd', 'even' ) ) ) {
			$attributes['condition'] = '__' . $attributes['condition'];
		}

		if( $attributes['condition'] == '__odd' ) {
			$attributes['condition'] = 1;
		} elseif( $attributes['condition'] == '__even' ) {
			$attributes['condition'] = 0;
		}

		$parent	= array_pop( $this->_tmplStack );
		array_push( $this->_tmplStack, $parent );
		if ($parent['attributes']['type'] == 'modulo') {

			if( preg_match( '/^\d$/', $attributes['condition'] ) ) {
				if( (integer)$attributes['condition'] >= $parent['attributes']['modulo'] ) {
					return patErrorManager::raiseError(
														PATTEMPLATE_READER_ERROR_INVALID_CONDITION,
														$this->_createErrorMessage( 'Condition may only be between 0 and '.($parent['attributes']['modulo']-1) )
													);
				}
			}
		}

		$attributes = $this->_inheritAttributes( $attributes );

		$condition  = $attributes['condition'];
		unset( $attributes['condition'] );

		$subTmpl = array(
						'type'			=>	'sub',
						'condition'		=>	$condition,
						'data'			=>	'',
						'attributes'	=>	$attributes,
						'comments'		=>	array(),
						'dependencies'	=>	array()
						);

		return	$subTmpl;
	}

	/**
	* close subtemplate
	*
	* @access	private
	* @param	string		data
	* @return	boolean		true on success
	*/
	function _closeSubTemplate( $subTmpl, $data )
	{
		$data				=	$this->_adjustWhitespace( $data, $subTmpl['attributes']['whitespace'] );

		$subTmpl['data']	=	$data;
		$condition			=	$subTmpl['condition'];
		unset( $subTmpl['condition'] );

		$this->_addToParentTemplate( 'subtemplates',
									  $subTmpl,
									  $condition
									);
		return true;
	}

	/**
	* handle a variable
	*
	* @access	private
	* @param	array	attributes of the var tag
	* @param	string	cdata between the tags (will be used as default)
	* @return	boolean	true on success
	*/
	function _handleVariable( $attributes, $data )
	{
		if( !isset( $attributes['name'] ) ) {
			return patErrorManager::raiseError(
												PATTEMPLATE_READER_ERROR_NO_NAME_SPECIFIED,
												$this->_createErrorMessage( 'Variable needs a name attribute' )
												);
		}

		$specs = array();

		/**
		 * get name
		 */
		$name	=	strtoupper( $attributes['name'] );
		unset( $attributes['name'] );
		$specs['name']	=	$name;

		/**
		 * use data as default value
		 */
		if( isset( $attributes['default'] ) ) {
			$data 				=	$attributes['default'];
			$specs['default']	=	$data;
			unset( $attributes['default'] );
		} elseif (!empty( $data )) {
			$specs['default']	=	$data;
		}

		/**
		 * add it to template, if it's not hidden
		 */
		if (!isset( $attributes['hidden'] ) || $attributes['hidden'] == 'no') {
			$this->_characterData( $this->_startTag . strtoupper( $name ) . $this->_endTag );
		}

		if( isset( $attributes['hidden'] ) ) {
			unset( $attributes['hidden'] );
		}

		/**
		 * copy value from any other variable
		 */
		if (isset( $attributes['copyfrom'] )) {
			$specs['copyfrom'] = strtoupper( $attributes['copyfrom'] );

			if (strstr( $specs['copyfrom'], '.' )) {
				$specs['copyfrom']	= explode( '.', $specs['copyfrom'] );
				$specs['copyfrom'][0] = strtolower( $specs['copyfrom'][0] );
			}

			unset( $attributes['copyfrom'] );
		}

		if( isset( $attributes['modifier'] ) ) {
			$modifier = $attributes['modifier'];
			unset( $attributes['modifier'] );

			$type = isset( $attributes['modifiertype'] ) ? $attributes['modifiertype'] : 'auto';

			if( isset( $attributes['modifiertype'] ) )
				unset( $attributes['modifiertype'] );

			$specs['modifier'] = array( 'mod' => $modifier, 'type' => $type, 'params' => $attributes );
		}

		if (!empty( $specs )) {
			$this->_addToParentTemplate(
										'varspecs',
										$specs,
										$name
										);
		}
		return true;
	}


	/**
	* handle a comment
	*
	* @access	private
	* @param	array	attributes of the comment tag
	* @param	string	cdata between the tags (will be used as default)
	* @return	boolean	true on success
	*/
	function _handleComment( $attributes, $data )
	{
		$this->_addToParentTag( 'comments', $data );
	}

	/**
	* get the character data of the element
	*
	* @access	private
	* @return	string
	*/
	function _getCData()
	{
		if( $this->_depth == 0 ) {
			return	'';
		}
		return $this->_data[$this->_depth];
	}

	/**
	* add to a property of the parent template
	*
	* @access	private
	* @param	string	property to add to
	* @param	mixed	value to add
	* @param	string	key
	*/
	function _addToParentTemplate( $property, $value, $key = null )
	{
		$cnt = count( $this->_tmplStack );

		if ($cnt === 0) {
			return false;
		}

		$pos = $cnt - 1;
		while ($pos >= 0) {
			if ($this->_tmplStack[$pos]['type'] != 'tmpl') {
				$pos--;
				continue;
			}

			if ($key === null) {

				if (!in_array( $value, $this->_tmplStack[$pos][$property] )) {
					array_push( $this->_tmplStack[$pos][$property], $value );
				}
			} else {
				$this->_tmplStack[$pos][$property][$key] = $value;
			}

			return true;
		}

		return	false;
	}

	/**
	* get a property of the parent template
	*
	* @access	private
	* @param	string	property to add to
	* @return	mixed	value to add
	*/
	function _getFromParentTemplate( $property )
	{
		$cnt = count( $this->_tmplStack );

		if ($cnt === 0) {
			return false;
		}

		$pos = $cnt - 1;
		while ($pos >= 0) {
			if( $this->_tmplStack[$pos]['type'] != 'tmpl' ) {
				$pos--;
				continue;
			}

			if (isset( $this->_tmplStack[$pos][$property] )) {
				return $this->_tmplStack[$pos][$property];
			}

			return false;
		}
		return	false;
	}


	/**
	* add to a property of the parent tag
	*
	* @access	private
	* @param	string	property to add to
	* @param	mixed	value to add
	* @param	string	key
	*/
	function _addToParentTag( $property, $value, $key = null )
	{
		$cnt = count( $this->_tmplStack );

		if ($cnt === 0) {
			return false;
		}

		$pos = $cnt - 1;

		if ($key === null) {

			if (!in_array( $value, $this->_tmplStack[$pos][$property] )) {
				array_push( $this->_tmplStack[$pos][$property], $value );
			}
		} else {
			$this->_tmplStack[$pos][$property][$key] = $value;
		}

		return true;
	}

	/**
	* adjust whitespace in a CData block
	*
	* @access	private
	* @param	string		data
	* @param	string		behaviour
	* @return	string		data
	*/
	function _adjustWhitespace( $data, $behaviour )
	{
		switch( $behaviour ) {
			case 'trim':
				$data = str_replace( '\n', ' ', $data );
				$data = preg_replace( '/\s\s+/', ' ', $data );
				$data = trim( $data );
				break;
		}
		return	$data;
	}

	/**
	* inherit attributes from the parent template
	*
	* The following attributes are inherited automatically:
	* - whitespace
	* - unusedvars
	*
	* @access	private
	* @param	array	attributes
	* @param	array	attributes with inherited attributes
	* @return	array	new attribute collection
	*/
	function _inheritAttributes( $attributes )
	{
		if (!empty( $this->_inheritAtts )) {
			$parent = end( $this->_inheritAtts );
		} else {
			$parent = array(
								'whitespace' => $this->_defaultAtts['whitespace'],
								'unusedvars' => $this->_defaultAtts['unusedvars'],
								'autoclear'  => $this->_defaultAtts['autoclear']
							);
		}

		$attributes = array_merge( $parent, $attributes );

		return	$attributes;
	}

	/**
	* checks, whether the parent tag is of a certain type
	*
	* This is needed to ensure, that subtemplates are only
	* placed inside a template
	*
	* @access	private
	* @param	string	type (tmpl, sub, var, link)
	* @return	boolean
	*/
	function _parentTagIs( $type )
	{
		$parent	=	array_pop( $this->_tmplStack );
		if( $parent === null ) {
			return false;
		}
		array_push( $this->_tmplStack, $parent );

		if( $parent['type'] == $type ) {
			return true;
		}

		return false;
	}

	/**
	* get the current line number
	*
	* @access	private
	* @return	integer		line number
	*/
	function _getCurrentLine()
	{
		$line = count( explode( "\n", $this->_processedData ) );
		return $line;
	}

	/**
	* create an error message
	*
	* This method takes an error messages and appends the
	* current line number as well as a pointer to the input
	* (filename)
	*
	* @access	private
	* @param	string	base error message
	* @return	strin	error message
	*/
	function _createErrorMessage( $msg )
	{
		return sprintf( '%s in %s on line %d', $msg, $this->getCurrentInput(), $this->_getCurrentLine() );
	}

	/**
	* get the current input
	*
	* @access   public
	* @return   string
	*/
	function getCurrentInput()
	{
		return $this->_currentInput;
	}

	/**
	* tests whether the reader should maintain backwards compatibility
	*
	* If enabled, you can still use 'default', 'empty', 'odd' and 'even'
	* instead of '__default', '__empty', etc.
	*
	* This will be disabled by default in future versions.
	*
	* @access	public
	* @return	boolean
	*/
	function shouldMaintainBc()
	{
		if (!isset( $this->_options['maintainBc'] )) {
			return false;
		}
		return $this->_options['maintainBc'];
	}

	/**
	* returns, whether the reader currently is in use
	*
	* @access   public
	* @return   boolean
	*/
	function isInUse()
	{
		return $this->_inUse;
	}

	/**
	* get the template root for this reader
	*
	* @access  public
	* @return  string
	*/
	function getTemplateRoot()
	{
		if (!isset($this->_options['root'])) {
			return null;
		}
		if (isset($this->_options['root'][$this->_name])) {
			return $this->_options['root'][$this->_name];
		}
		if (isset($this->_options['root']['__default'])) {
			return $this->_options['root']['__default'];
		}
		return null;
	}
}
?>

⌨️ 快捷键说明

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