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

📄 reader.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 3 页
字号:
			 */
			case 'var':
				$result	=	false;
				break;

			/**
			 * instance
			 */
			case 'instance':
			case 'comment':
				$result	=	false;
				break;

			/**
			 * any other tag
			 */
			default:
				if (isset($this->_funcAliases[strtolower($name)])) {
					$name = $this->_funcAliases[strtolower($name)];
				}
				$name = ucfirst( $name );

				if( !$this->_tmpl->moduleExists( 'Function', $name ) ) {

					if (isset($this->_options['defaultFunction']) && !empty($this->_options['defaultFunction'])) {
						$attributes['_originalTag'] = $name;
						$name = ucfirst($this->_options['defaultFunction']);
					} else {
						return patErrorManager::raiseError(
															PATTEMPLATE_READER_ERROR_UNKNOWN_TAG,
															$this->_createErrorMessage( "Unknown tag {$ns}:{$name}." )
														);
					}
				}
				$result = array(
								'type'	   => 'custom',
								'function'   => $name,
								'attributes' => $attributes
								);
				break;
		}

		if( patErrorManager::isError( $result ) ) {
			return	$result;
		}

		array_push( $this->_tmplStack, $result );
		return true;
	}

	/**
	* handle end element
	*
	* @access	private
	* @param	string		element name
	*/
	function _endElement( $ns, $name )
	{
		$el			=	array_pop( $this->_elStack );
		$data		=	$this->_getCData();
		$this->_depth--;

		if( $el['name'] != $name || $el['ns'] != $ns ) {
			return patErrorManager::raiseError(
				PATTEMPLATE_READER_ERROR_INVALID_CLOSING_TAG,
				$this->_createErrorMessage( "Invalid closing tag {$ns}:{$name}, {$el['ns']}:{$el['name']} expected" )
			);
		}

		$tmpl	=	array_pop( $this->_tmplStack );

		/**
		 * handle tag
		 */
		switch( $name )
		{
			/**
			 * template
			 */
			case 'tmpl':
				$this->_closeTemplate( $tmpl, $data );
				break;

			/**
			 * sub-template
			 */
			case 'sub':
				$this->_closeSubTemplate( $tmpl, $data );
				break;

			/**
			 * link
			 */
			case 'link':
				$this->_closeLink( $tmpl );
				break;

			/**
			 * variable
			 */
			case 'var':
				$this->_handleVariable( $el['attributes'], $data );
				break;

			/**
			 * instance
			 */
			case 'instance':
				break;

			/**
			 * comment
			 */
			case 'comment':
				$this->_handleComment( $el['attributes'], $data );
				break;

			/**
			 * custom function
			 */
			default:
				$name = ucfirst( $tmpl['function'] );

				if( !isset( $this->_functions[$name] ) ) {
					$this->_functions[$name] = $this->_tmpl->loadModule( 'Function', $name );
					$this->_functions[$name]->setReader( $this );
				}

				$result = $this->_functions[$name]->call( $tmpl['attributes'], $data );

				if( patErrorManager::isError( $result ) ) {
					return $result;
				}

				if( is_string( $result ) ) {
					$this->_characterData( $result, false );
				}
				break;
		}
		return true;
	}

	/**
	* handle character data
	*
	* @access	private
	* @param	string		data
	*/
	function _characterData( $data, $readFromTemplate = true )
	{
		$this->_data[$this->_depth]	.=	$data;

		if ($readFromTemplate) {
			$this->_processedData .= $data;
		}

		return	true;
	}

	/**
	* handle a Link
	*
	* @access	private
	* @param	array		attributes
	* @return	boolean		true on success
	*/
	function _initLink( $attributes )
	{
		/**
		 * needs a src attribute
		 */
		if( !isset( $attributes['src'] ) ) {
			return patErrorManager::raiseError(
												PATTEMPLATE_READER_ERROR_INVALID_TAG,
												$this->_createErrorMessage( "Attribute 'src' missing for link" )
												);
		}

		/**
		 * create a new template
		 */
		$tmpl	=	array(
							'type'			=>	'link',
							'src'			=>	$attributes['src'],
						);
		return $tmpl;
	}

	/**
	* close a link template
	*
	* It will be added to the dependecies of the parent template.
	*
	* @access	private
	* @param	array	template definition for the link
	*/
	function _closeLink( $tmpl )
	{
		/**
		 * add it to the dependencies
		 */
		if( !empty( $this->_tmplStack ) )
		{
			$this->_addToParentTag( 'dependencies', strtolower( $tmpl['src'] ) );
			$this->_characterData( sprintf( "%sTMPL:%s%s", $this->_startTag, strtoupper( $tmpl['src'] ), $this->_endTag ) );
		}

		return true;
	}

	/**
	* create a new template
	*
	* @access	private
	* @param	array		attributes
	* @return	boolean		true on success
	*/
	function _initTemplate( $attributes )
	{
		/**
		 * build name for the template
		 */
		if (!isset( $attributes['name'] )) {
			$name	=	$this->_buildTemplateName();
		} else {
			$name	=	strtolower( $attributes['name'] );
			unset( $attributes['name'] );
		}

		/**
		 * name must be unique
		 */
		if( isset( $this->_templates[$name] ) || $this->_tmpl->exists( $name ) ) {
			patErrorManager::raiseNotice(
										PATTEMPLATE_READER_NOTICE_TEMPLATE_EXISTS,
										$this->_createErrorMessage( "Template $name already exists" ),
										$name
										);
		}

		/**
		 * update the path
		 */
		array_push( $this->_path, $name );

		if( isset( $attributes['maxloop'] ) ) {
			if (!isset( $attributes['parent'] )) {
				$attributes['parent'] = $this->_getFromParentTemplate( 'name' );
			}
		}

		$attributes	= $this->_prepareTmplAttributes( $attributes, $name );

		array_push( $this->_inheritAtts, array(
												'whitespace' => $attributes['whitespace'],
												'unusedvars' => $attributes['unusedvars'],
												'autoclear'  => $attributes['autoclear']
											)
				 );

		/**
		 * create a new template
		 */
		$tmpl	=	array(
							'type'			=>	'tmpl',
							'name'			=>	$name,
							'attributes'	=>	$attributes,
							'content'		=>	'',
							'dependencies'	=>	array(),
							'varspecs'		=>	array(),
							'comments'		=>	array(),
							'loaded'		=>	false,
							'parsed'		=>	false,
							'input'			=>  $this->_name.'://'.$this->_currentInput
						);

		if( $this->_root == null ) {
			$this->_root = $name;
			$tmpl['isRoot'] = true;
		}


		/**
		 * prepare subtemplates
		 */
		switch( $attributes['type'] ) {
			case 'condition':
			case 'modulo':
				$tmpl['subtemplates']	=	array();
				break;
		}

		return $tmpl;
	}

	/**
	* prepare attributes
	*
	* @access	private
	* @param	array	attributes
	* @param	string	template name (only used for error messages)
	* @return	array	attributes
	*/
	function _prepareTmplAttributes( $attributes, $templatename )
	{
		/**
		 * do not prepare twice
		 */
		if( isset( $attributes['__prepared'] ) && $attributes['__prepared'] === true ) {
			return $attributes;
		}

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

		/**
		 * get the attributes
		 */
		$attributes	= array_merge( $this->_tmpl->getDefaultAttributes(), $attributes );

		$attributes['type']	= strtolower( $attributes['type'] );

		if( !isset( $attributes['rowoffset'] ) ) {
			$attributes['rowoffset'] = 1;
		}

		if( !isset( $attributes['addsystemvars'] ) ) {
			$attributes['addsystemvars'] = false;
		} else {
			switch ($attributes['addsystemvars']) {
				case 'on':
				case 'boolean':
					$attributes['addsystemvars'] = 'boolean';
					break;
				case 'int':
				case 'integer':
					$attributes['addsystemvars'] = 'integer';
					break;
				case 'off':
					$attributes['addsystemvars'] = false;
					break;
			}
		}

		/**
		 * external template
		 */
		if( isset( $attributes['src'] ) ) {
		 	if( !isset( $attributes['parse'] ) )
				$attributes['parse']	=	'on';
		 	if( !isset( $attributes['reader'] ) )
				$attributes['reader']	=	$this->getName();
		 	if( !isset( $attributes['autoload'] ) )
				$attributes['autoload']	=	$this->_defaultAtts['autoload'];

		 	if (isset($attributes['relative']) && strtolower($attributes['relative'] === 'yes')) {
				$attributes['relative']	= $this->getCurrentInput();
		 	} else {
				$attributes['relative']	= false;
		 	}
		}

		/**
		 * varscope is set
		 */
		if( isset( $attributes['varscope'] ) ) {
		 	/**
			 * varscope is parent
			 */
		 	if( $attributes['varscope'] === '__parent' ) {
				$attributes['varscope'] = $this->_getFromParentTemplate( 'name' );
			}

			$attributes['varscope']	= strtolower( $attributes['varscope'] );
			if (strstr($attributes['varscope'], ',')) {
				$attributes['varscope'] = array_map('trim', explode(',', $attributes['varscope']));
			}
		}

		switch( $attributes['type'] ) {
			/**
			 * validate condition template
			 */
			case	'condition':
				if( !isset( $attributes['conditionvar'] ) ) {
					return patErrorManager::raiseError(
														PATTEMPLATE_READER_ERROR_INVALID_TAG,
														$this->_createErrorMessage( "Attribute 'conditionvar' missing for $templatename" )
														);
				}
				$attributes['conditionvar']	=	strtoupper( $attributes['conditionvar'] );

				if( strstr( $attributes['conditionvar'], '.' ) ) {
					list( $attributes['conditiontmpl'], $attributes['conditionvar'] ) = explode( '.', $attributes['conditionvar'] );
					$attributes['conditiontmpl'] = strtolower( $attributes['conditiontmpl'] );
				}

				$attributes['autoclear']	=	'yes';

				if (!isset( $attributes['useglobals'] )) {
					$attributes['useglobals']	=	'no';
				}
				break;

			/**
			 * validate simplecondition template
			 */
			case	'simplecondition':
				if( !isset( $attributes['requiredvars'] ) ) {
					return patErrorManager::raiseError(
														PATTEMPLATE_READER_ERROR_INVALID_TAG,
														$this->_createErrorMessage( "Attribute 'requiredvars' missing for $templatename" )
														);
				}
				$tmp = array_map( 'trim', explode( ',', $attributes['requiredvars'] ) );
				$attributes['requiredvars']   = array();
				foreach( $tmp as $var ) {

					$pos = strpos( $var, '=' );
					if ($pos !== false) {
						$val = trim(substr( $var, $pos+1 ));
						$var = trim(substr( $var, 0, $pos ));
					} else {
						$val = null;
					}
					$var = strtoupper($var);
					$pos = strpos( $var, '.' );

					if ($pos === false) {
						array_push( $attributes['requiredvars'], array( $templatename, $var, $val ) );
					} else {
						array_push( $attributes['requiredvars'], array(
																		strtolower( substr( $var, 0, $pos ) ),
																		substr( $var, $pos+1 ),
																		$val
																	)
								);
					}

				}
				$attributes['autoclear'] = 'yes';
				break;

			/**
			 * oddeven => switch to new modulo syntax
			 */
			case	'oddeven':
				$attributes['type']		 = 'modulo';
				$attributes['modulo']	 = 2;
				$attributes['autoclear'] = 'yes';
				break;

			/**
			 * modulo => requires a module attribute
			 */
			case	'modulo':
				if( !isset( $attributes['modulo'] ) ) {
					return patErrorManager::raiseError(
														PATTEMPLATE_READER_ERROR_INVALID_TAG,
														$this->_createErrorMessage( "Attribute 'modulo' missing for $templatename" )
														);
				}
				$attributes['autoclear'] = 'yes';
				break;

			/**
			 * standard template => do nothing
			 */
			case	'standard':
				break;

			/**
			 * unknown type
			 */
			default:
				return patErrorManager::raiseError(
													PATTEMPLATE_READER_ERROR_INVALID_TAG,
													$this->_createErrorMessage( "Unknown value for attribute type: {$attributes['type']}" )
													);
				break;
		}

		$attributes['__prepared'] = true;

		return $attributes;
	}

	/**
	* build a template name
	*
	* @access	private
	* @return	string	new template name
	*/
	function _buildTemplateName()
	{
		return strtolower( uniqid( 'tmpl' ) );
	}

	/**
	* close the current template
	*
	* @access	private
	* @return	boolean	true on success
	*/
	function _closeTemplate( $tmpl, $data )
	{
		$name = array_pop( $this->_path );

		$data = $this->_adjustWhitespace( $data, $tmpl['attributes']['whitespace'] );

		array_pop( $this->_inheritAtts );

		/**
		 * check for special templates
		 */
		switch( $tmpl['attributes']['type'] )
		{
			/**
			 * check for whitespace in conditional templates
			 * and raise a notice
			 */
			case	'condition':
			case	'modulo':
				if( trim( $data ) != '' ) {
					patErrorManager::raiseNotice(
													PATTEMPLATE_READER_NOTICE_INVALID_CDATA_SECTION,

⌨️ 快捷键说明

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