Source code for file /pattemplate/patTemplate/Reader/IT.php
Documentation is available at IT.php
* patTemplate reader that reads HTML_Template_IT files
* $Id: IT.php 413 2005-08-05 13:51:01Z schst $
// Check to ensure this file is within the rest of the framework
* patTemplate reader that reads HTML_Template_IT files
* files that have been used
* parse templates from string
* @param string string to parse
* @return array templates
function parseString( $string )
* apply input filter before parsing
$string =
$this->_tmpl->applyInputFilters( $string );
$this->_inheritAtts =
array();
$this->_elStack =
array();
$this->_data =
array( '' );
$this->_tmplStack =
array();
$this->_processedData =
'';
$this->_defaultAtts =
$this->_tmpl->getDefaultAttributes();
if( !isset
( $this->_defaultAtts['autoload'] ) )
$this->_defaultAtts['autoload'] =
'on';
* create a special root template
$attributes =
$this->_rootAtts;
$attributes['name'] =
'__global';
$rootTemplate =
$this->_initTemplate( $attributes );
$regexp =
'/(<!-- (BEGIN|END) ([a-zA-Z]+) -->)/m';
$tokens =
preg_split( $regexp, $string, -
1, PREG_SPLIT_DELIM_CAPTURE );
* the first token is always character data
* Though it could just be empty
$this->_characterData( $tokens[0] );
$fullTag =
$tokens[$i++
];
$closing =
strtoupper( $tokens[$i++
] ) ==
'END' ?
true :
false;
$tmplName =
$tokens[$i++
];
$namespace =
$patNamespace;
$result =
$this->_endElement( $namespace, $tagname );
$this->_characterData( $data );
$attributes =
array( 'name' =>
$tmplName );
$result =
$this->_startElement( $namespace, $tagname, $attributes );
$this->_characterData( $data );
$rootTemplate =
array_pop( $this->_tmplStack );
$this->_closeTemplate( $rootTemplate, $this->_data[0] );
* check for tags that are still open
$this->_createErrorMessage( "No closing tag for {$el['ns']}:{$el['name']} found" )
* read templates from any input
* @param string file to parse
* @return array templates
$this->_currentInput =
$input;
$fullPath =
$this->_resolveFullPath( $input );
$content =
$this->_getFileContents( $fullPath );
$templates =
$this->parseString( $content );
* load template from any input
* If the a template is loaded, the content will not get
* analyzed but the whole content is returned as a string.
* @abstract must be implemented in the template readers
* @param mixed input to load from.
* This can be a string, a filename, a resource or whatever the derived class needs to read from
* @return string template content
$fullPath =
$this->_resolveFullPath( $input );
return $this->_getFileContents( $fullPath );
* resolve path for a template
* @return string full path
function _resolveFullPath( $filename )
$fullPath =
$baseDir .
'/' .
$filename;
* get the contents of a file
* @return string file contents
function _getFileContents( $file )
"Could not load templates from $file."