';
echo '
patTemplate Dump
';
}
/**
* dump the global variables
*
* @access public
* @param array array containing all global variables
*/
function dumpGlobals( $globals )
{
echo '
Global template variables ('.count( $globals ).')
';
if( !empty( $globals ) )
{
echo '
';
echo '
';
foreach( $globals as $key => $value )
{
$this->_displayLine( $key, $value );
}
echo '
';
echo '
';
}
}
/**
* dump the templates
*
* @access public
* @param array templates
*/
function dumpTemplates( $templates, $vars )
{
$templates = array_reverse( $templates );
echo '
';
echo '
Dumping selected templates...
';
foreach( $templates as $name => $tmpl )
{
if( !isset( $vars[$name] ) )
$vars[$name] = array();
$vars[$name] = $this->_flattenVars( $vars[$name] );
echo '
';
echo '
';
echo '
';
echo ' ';
echo '
';
echo ' ';
echo ' ';
$this->_displayAttributes( $tmpl, $name );
echo ' | ';
echo ' ';
$this->_displayTemplateState( $tmpl );
echo ' | ';
echo ' ';
echo ' Dependencies ';
if( !empty( $tmpl['dependencies'] ) )
{
$dependencies = array();
foreach( $tmpl['dependencies'] as $dependency )
array_push( $dependencies, ''.$dependency.'' );
echo implode( ' ', $dependencies );
}
else
{
echo '[none]';
}
echo ' | ';
echo '
';
echo '
';
/**
* ------------------------------------------------------------------
* display variables
*/
$nestedTypes = array(
'condition',
'modulo',
);
if( in_array( $tmpl['attributes']['type'], $nestedTypes ) )
{
$content = '';
foreach( $tmpl['subtemplates'] as $subName => $subDetails )
{
$content .= $subDetails['data'];
}
}
else
{
$content = $tmpl['content'];
}
$setVars = $this->_extractVars( $content );
echo '
';
echo '
Variables
';
$this->_displayVariables( $tmpl, $name, $setVars, $vars );
echo '
';
if( !empty( $tmpl['comments'] ) )
{
echo '
';
echo '
Comments
';
echo '
';
echo implode( '
', $tmpl['comments'] );
echo '
';
echo '
';
}
/**
* ------------------------------------------------------------------
* display template content
*/
echo '
';
switch( $tmpl['attributes']['type'] )
{
case 'condition':
case 'modulo':
$this->_displayConditions( $tmpl, $name, $vars );
break;
default:
echo '
Content
';
echo '
'.$this->_highlightVars( htmlspecialchars( $tmpl['content'] ), $vars[$name] ).'
';
break;
}
echo '
';
echo '
';
echo '
';
}
echo '
';
}
function _displayVariables( $tmpl, $tmplName, $setVars, $vars )
{
if( empty( $setVars ) )
{
echo '
[none]';
return true;
}
echo '
';
$this->_useBorders( true );
$this->_displayHead( 'Name', 'Assigned value', 'Modifier' );
foreach( $setVars as $var )
{
if( isset( $vars[$tmplName][$var] ) )
$value = $vars[$tmplName][$var];
else
$value = '[no value set]';
if( isset( $tmpl['modifyVars'][$var] ) )
{
$params = array();
foreach( $tmpl['modifyVars'][$var]['params'] as $n => $val )
{
array_push( $params, $n.'="'.$val.'"' );
}
$modifier = sprintf( '%s( %s )', $tmpl['modifyVars'][$var]['mod'], implode( ', ', $params ) );
}
else
{
$modifier = '[none]';
}
$this->_displayLine( $var, $value, $modifier );
}
echo '
';
$this->_useBorders( false );
}
function _displayConditions( $tmpl, $tmplName, $vars )
{
foreach( $tmpl['subtemplates'] as $cond => $spec )
{
echo '
';
echo '
';
echo ' ';
if( !empty( $spec['comments'] ) )
{
echo '
Comments
';
echo '
';
echo implode( '
', $spec['comments'] );
echo '
';
}
echo '
Dependencies
';
echo '
';
if( !empty( $spec['dependencies'] ) )
{
$dependencies = array();
foreach( $spec['dependencies'] as $dependency )
array_push( $dependencies, '
'.$dependency.'' );
echo implode( ', ', $dependencies );
}
else
{
echo '
[none]';
}
echo '
';
echo '
Content
';
echo '
'.$this->_highlightVars( htmlspecialchars( $spec['data'] ), $vars[$tmplName] ).'
';
echo '
';
}
}
/**
* display the attributes of a template
*
* @access private
* @param array template data
* @param string name of the template
*/
function _displayAttributes( $tmpl, $tmplName = null )
{
echo '
Attributes
';
echo '
';
/**
* type
*/
switch( $tmpl['attributes']['type'] )
{
case 'modulo':
if( $tmpl['attributes']['modulo'] == 2 )
$type = 'OddEven';
else
$type = 'modulo (' . $tmpl['attributes']['modulo'] . ')';
case 'condition':
if( !isset( $type ) )
$type = 'condition';
$this->_displayLine( 'Type', $tmpl['attributes']['type'] );
/**
* condition variable, only used in condition templates
*/
if( isset( $tmpl['attributes']['conditionvar'] ) )
{
if( isset( $tmpl['attributes']['conditiontmpl'] ) )
$this->_displayLine( 'ConditionVar', $tmpl['attributes']['conditiontmpl'].'.'.$tmpl['attributes']['conditionvar'] );
elseif( isset( $tmpl['attributes']['useglobals'] ) && $tmpl['attributes']['useglobals'] == 'yes' )
$this->_displayLine( 'ConditionVar', '__globals.'.$tmpl['attributes']['conditionvar'] );
else
$this->_displayLine( 'ConditionVar', $tmpl['attributes']['conditionvar'] );
}
break;
case 'simplecondition':
$this->_displayLine( 'Type', 'simplecondition' );
$requiredvars = array();
foreach ($tmpl['attributes']['requiredvars'] as $tmp) {
if ($tmp[0] !== $tmplName) {
$var = $tmp[0] . '.' . $tmp[1];
} else {
$var = $tmp[1];
}
if ($tmp[2] !== null) {
$var = $var . '='.$tmp[2];
}
array_push($requiredvars, $var);
}
$this->_displayLine( 'RequiredVars', implode( ', ', $requiredvars ) );
break;
default:
$this->_displayLine( 'Type', $tmpl['attributes']['type'] );
}
/**
* standard attributes
*/
$this->_displayLine( 'Visibility', $tmpl['attributes']['visibility'] );
$this->_displayLine( 'WhiteSpace', $tmpl['attributes']['whitespace'] );
$this->_displayLine( 'AddSystemVars', $tmpl['attributes']['addsystemvars'] );
$this->_displayLine( 'UnusedVars', $tmpl['attributes']['unusedvars'] );
/**
* external source
*/
if( isset( $tmpl['attributes']['src'] ) )
$this->_displayLine( 'External Src', $tmpl['attributes']['src'] );
/**
* varscope
*/
if (isset($tmpl['attributes']['varscope'])) {
if (is_array($tmpl['attributes']['varscope'])) {
$this->_displayLine( 'Varscope', implode(', ', $tmpl['attributes']['varscope'] ) );
} else {
$this->_displayLine( 'Varscope', $tmpl['attributes']['varscope'] );
}
}
echo '
';
}
function _displayTemplateState( $tmpl )
{
echo '
States
';
echo '
';
$this->_displayLine( 'Loaded', $tmpl['loaded'] );
$this->_displayLine( 'Parsed', $tmpl['parsed'] );
echo '
';
}
/**
* hilight variables in a template
*
* @access private
* @param string template content
* @return string template content
*/
function _highlightVars( $template, $vars )
{
$pattern = '/('.$this->_tmpl->getStartTag().'TMPL\:([^a-z]+)'.$this->_tmpl->getEndTag().')/U';
$template = preg_replace( $pattern, '
\1', $template );
$pattern = '/('.$this->_tmpl->getStartTag().'([^a-z:]+)'.$this->_tmpl->getEndTag().')/U';
$matches = array();
preg_match_all( $pattern, $template, $matches );
for( $i = 0; $i < count( $matches[1] ); $i++ )
{
if( isset( $vars[$matches[2][$i]] ) )
{
$value = $vars[$matches[2][$i]];
}
else
{
$value = '[No value set]';
}
$replace = '
'.$matches[1][$i].'';
$template = str_replace( $matches[1][$i], $replace, $template );
}
return $template;
}
/**
* display a table header
*
* @access private
* @param string property
* @param mixed value, you may pass more than one value
*/
function _displayHead()
{
$args = func_get_args();
echo '
';
foreach( $args as $head )
{
printf( ' %s | ', $head );
}
echo '
';
}
function _getClassName( $class )
{
if( !$this->_useBorders )
return $class;
return $class .= 'Border';
}
/**
* sets whether to draw borders in the tables generated via the
* {@link _displayHead()} and {@link _displayLine()} methods.
*
* @access private
* @param bool $state Whether to draw the borders. true=draw, false=don't draw
*/
function _useBorders( $state )
{
$this->_useBorders = $state;
}
/**
* display a line in a table
*
* @access private
* @param string property
* @param mixed value, you may pass more than one value
*/
function _displayLine( $prop, $value )
{
$args = func_get_args();
$prop = array_shift( $args );
echo '
';
printf( ' %s | ', $prop );
if( count( $args ) == 1 )
{
echo ' : | ';
}
foreach( $args as $value )
{
if( is_bool( $value ) )
{
$value = ( $value === true ) ? 'yes' : 'no';
}
printf( ' %s | ', $value );
}
echo '
';
}
/**
* display the footer
*
* @access public
*/
function displayFooter()
{
echo '
';
echo ' ';
echo '';
}
}
?>