Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: /var/www/html/projects/pat/patTemplate/include/patTemplate.php
patTemplate - patTemplate

patTemplate

patTemplate

Easy-to-use but powerful template engine

 

public class patTemplate

Easy-to-use but powerful template engine
Features include: several templates in one file, automatic repetitions, global variables,alternating lists, conditions, and much more

AuthorsStephan Schmidt <schst@php-tools.de>
Version2.4 ($Id: patTemplate.php,v 1.54 2001/11/03 13:34:16 schst Exp $)

 

Public Method Summary

void

patTemplate([ string $type ])

Constructor
void

setType([ string $type ])

Set template type
void

setTags([ string $start, string $end ])

Set template tags
void

setBasedir(string $basedir)

Set template directory
bool

exists(string $name)

Check if a template exists
void

addTemplate(string $name, string $filename)

Add a template
void

addTemplates(array $templates)

Adds several templates
void

setAttribute(string $template, string $attribute, mixed $value)

Sets an attribute of a template
void

setAttributes(string $template, array $attributes)

Sets several attribute of a template
mixed

getAttribute(string $template, string $attribute)

Gets an attribute of a template
void

clearAttribute(string $template, string $attribute)

Clears an attribute of a template
void

readTemplatesFromFile(string $file)

Parses several templates from one patTemplate file
void

addVar(string $template, string $name, mixed $value)

Adds a variable to a template
void

addVars(string $template, array $variables, [ string $prefix ])

Adds several variables to a template
void

addRows(string $template, array $rows, [ string $prefix ])

Adds several rows of variables to a template
void

addGlobalVar(string $name, string $value)

Adds a global variable
void

addGlobalVars(array $variables, [ string $prefix ])

Adds several global variables
void

parseTemplate(string $template, [ string $mode ])

parses a template
string

getParsedTemplate([ string $name ])

returns a parsed Template
void

displayParsedTemplate([ string $name ])

displays a parsed Template
void

clearTemplate(string $name)

clears a parsed Template
void

clearAllTemplates()

clears all templates
void

dump()

displays useful information about all templates

Private Method Summary

void

createTemplate(string $name, array $source)

creates a new template
void

setTemplateType(string $template, string $type)

Sets the type of the Template
void

setConditionVar(string $template, string $conditionvar)

Sets the conditionvar of a condtion Template
void

addSubTemplate(string $template, string $condition)

Adds a subtemplate for a condition or oddeven template
void

createParser(string $fname)

parse a template file and call the appropriate handlers
void

startElementHandler(string $fname, string $tagname, array $attributes, string $line, integer $lineno)

handle a <patTemplate:...> start tag in template parser
void

endElementHandler(string $fname, string $tagname, string $line)

handle a </patTemplate:...> end tag in template parser
void

DataHandler(string $fname, string $data)

handle a CDATA in template parser
void

addDependency(string $container, string $child)

Creates a dependeny between two templates
void

loadTemplate(string $name)

loads a template
void

setPlainContent(string $template, string $content, [ string $sub ])

sets the content of a template
void

parseStandardTemplate(string $name, [ string $mode ])

parses a standard template
void

parseIterativeTemplate(string $name, string $mode)

parses an iterative template
array

getVars(string $template)

get variables for a template
void

parseGlobals(string $name, string &$temp)

parses the global variables in a template
void

stripUnusedVars(string $name, string &$template)

handles unset variables
void

parseDependencies(string $name, string &$temp, string $mode)

parses dependencies of a template
string

getPlainTemplate(string $name)

returns an unparsed Template
string

getPlainSubTemplate(string $name, string $sub)

returns an unparsed Subtemplate
void

displayPlainTemplate(string $name)

displays an unparsed Template
array

parseAttributes(string $string)

parsed attributes from a string
string

getTemplateContent(string $name)

returns the plain content of a template
mixed

getVar(string $template)

get the value of a variable

Public Constant Summary

patTEMPLATE_TAG_START >>{<< Variable prefix
patTEMPLATE_TAG_END >>}<< Variable sufix

Private Constant Summary

patTEMPLATE_TYPE_STANDARD >>STANDARD<< Template type Standard
patTEMPLATE_TYPE_ODDEVEN >>ODDEVEN<< Template type OddEven
patTEMPLATE_TYPE_CONDITION >>CONDITION<< Template type Condition
patTEMPLATE_TYPE_SIMPLECONDITION >>SIMPLECONDITION<< Template type SimpleCondition

Public Method Details

patTemplate

public void patTemplate( [ string $type ] )

  Constructor
Create new patTemplate objectYou can choose between two outputs you want tp generate: html (default) or tex (LaTex).When "tex" is used the patTemplate markings used for variables are changed as LaTex makes use of the default patTemplate markings.You can also change the markings later by calling setTags();

Parameter
string $type = >>"html"<<
type of output you want to generate.
Returns void


setType

public void setType( [ string $type ] )

  Set template type
select a predefined template type

Parameter
string $type = >>""<<
predefined template type, like "html" or "tex"
Returns void


setTags

public void setTags( [ string $start, string $end ] )

  Set template tags
Sets the start and end tags of template variables

Parameter
string $start = >>patTEMPLATE_TAG_START,<<
start tag
string $end = >>patTEMPLATE_TAG_END<<
end tag
Returns void


setBasedir

public void setBasedir( string $basedir )

  Set template directory
Sets the directory where the template are stored.By default the engine looks in the directory where the original file is stored.

Parameter
string $basedir
directory of the templates
Returns void


exists

public bool exists( string $name )

  Check if a template exists

Parameter
string $name
name of the template
Returns bool


addTemplate

public void addTemplate( string $name, string $filename )

  Add a template
Adds a plain text/html to the template engine.The file has to be in the directory that has been set using setBaseDir

Parameter
string $name
name of the template
string $filename
filename of the sourcetemplate
Returns void

Deprecated 2.4 2001/11/05
See Also setBaseDir(), addTemplates()

addTemplates

public void addTemplates( array $templates )

  Adds several templates
Adds several templates to the template engine using an associative array.Names of the templates are stored in the keys, filenames are the values.The templates have to be in the directory set by setBaseDir().

Parameter
array $templates
associative Array with name/filename pairs
Returns void

Deprecated 2.4 2001/11/05
See Also setBaseDir(), addTemplate()

setAttribute

public void setAttribute( string $template, string $attribute, mixed $value )

  Sets an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars

Parameter
string $template
name of the template
string $attribute
name of the attribute
mixed $value
value of the attribute
Returns void

See Also setAttributes(), getAttribute(), clearAttribute()

setAttributes

public void setAttributes( string $template, array $attributes )

  Sets several attribute of a template
$attributes has to be a assotiative arrays containing attribute/value pairssupported attributes: visibilty, loop, parse, unusedvars

Parameter
string $template
name of the template
array $attributes
attribute/value pairs
Returns void

See Also setAttribute(), getAttribute(), clearAttribute()

getAttribute

public mixed getAttribute( string $template, string $attribute )

  Gets an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars

Parameter
string $template
name of the template
string $attribute
name of the attribute
Returns mixed

value of the attribute

See Also setAttribute(), setAttributes(), clearAttribute()

clearAttribute

public void clearAttribute( string $template, string $attribute )

  Clears an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars

Parameter
string $template
name of the template
string $attribute
name of the attribute
Returns void

See Also setAttribute(), setAttributes(), getAttribute()

readTemplatesFromFile

public void readTemplatesFromFile( string $file )

  Parses several templates from one patTemplate file
Templates can be seperated using TagsThe file has to be located in the directory that has been set using setBaseDir.

Parameter
string $file
filename
Returns void

See Also setBasedir()

addVar

public void addVar( string $template, string $name, mixed $value )

  Adds a variable to a template
Each Template can have an unlimited amount of its own variables

Parameter
string $template
name of the template
string $name
name of the variables
mixed $value
value of the variable
Returns void

See Also addVars(), addRows(), addGlobalVar(), addGlobalVars()

addVars

public void addVars( string $template, array $variables, [ string $prefix ] )

  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

Parameter
string $template
name of the template
array $variables
assotiative array of the variables
string $prefix = >>""<<
prefix for all variable names
Returns void

See Also addVar(), addRows(), addGlobalVar(), addGlobalVars()

addRows

public void addRows( string $template, array $rows, [ string $prefix ] )

  Adds several rows of variables to a template
Each Template can have an unlimited amount of its own variablesCan be used to add a database result as variables to a template

Parameter
string $template
name of the template
array $rows
array containing assotiative arrays with variable/value pairs
string $prefix = >>""<<
prefix for all variable names
Returns void

See Also addVar(), addVars(), addGlobalVar(), addGlobalVars()

addGlobalVar

public void addGlobalVar( string $name, string $value )

  Adds a global variable
Global variables are valid in all templates of this object

Parameter
string $name
name of the global variable
string $value
value of the variable
Returns void

See Also addGlobalVars(), addVar(), addVars(), addRows()

addGlobalVars

public void addGlobalVars( array $variables, [ string $prefix ] )

  Adds several global variables
Global variables are valid in all templates of this object$variables is an assotiative array, containing name/value pairs of the variables

Parameter
array $variables
array containing the variables
string $prefix = >>""<<
prefix for variable names
Returns void

See Also addGlobalVar(), addVar(), addVars(), addRows()

parseTemplate

public void parseTemplate( string $template, [ string $mode ] )

  parses a template
Parses a template and stores the parsed content.mode can be "w" for write (delete already parsed content) or "a" for append (appends thenew parsed content to the already parsed content)

Parameter
string $template
name of the template
string $mode = >>"w"<<
mode for the parsing
Returns void

See Also parseStandardTemplate(), parseIterativeTemplate()

getParsedTemplate

public string getParsedTemplate( [ string $name ] )

  returns a parsed Template
If the template already has been parsed, it just returns the parsed template.If the template has not been loaded, it will be loaded.

Parameter
string $name = >>""<<
name of the template
Returns string $content

Content of the parsed template

See Also displayParsedTemplate()

displayParsedTemplate

public void displayParsedTemplate( [ string $name ] )

  displays a parsed Template
If the template has not been loaded, it will be loaded.

Parameter
string $name = >>""<<
name of the template
Returns void

See Also getParsedTemplate()

clearTemplate

public void clearTemplate( string $name )

  clears a parsed Template
parsed Content, variables and the loop attribute are cleared

Parameter
string $name
name of the template
Returns void


clearAllTemplates

public void clearAllTemplates( )

  clears all templates

Returns void


dump

public void dump( )

  displays useful information about all templates
returns content, variables, attributes and unused variables

Returns void


Private Method Details

createTemplate

private void createTemplate( string $name, array $source )

  creates a new template
creates all needed variables

Parameter
string $name
name of the template
array $source
data regarding the source of the template
Returns void


setTemplateType

private void setTemplateType( string $template, string $type )

  Sets the type of the Template
Template types can be STANDARD, CONDITION or ODDEVENThe type of the template can also be set using setAttribute()

Parameter
string $template
name of the template
string $type
type of the template
Returns void

See Also setAttribute()

setConditionVar

private void setConditionVar( string $template, string $conditionvar )

  Sets the conditionvar of a condtion Template
The type of the template has to be condition

Parameter
string $template
name of the template
string $conditionvar
name of the conditionvariable
Returns void

See Also setTemplateType()

addSubTemplate

private void addSubTemplate( string $template, string $condition )

  Adds a subtemplate for a condition or oddeven template
template type has to be condition or oddeven

Parameter
string $template
name of the template
string $condition
condition for this subtemplate
Returns void

See Also setTemplateType()

createParser

private void createParser( string $fname )

  parse a template file and call the appropriate handlers

Parameter
string $fname
filename of the template
Returns void


startElementHandler

private void startElementHandler( string $fname, string $tagname, array $attributes, string $line, integer $lineno )

  handle a <patTemplate:...> start tag in template parser

Parameter
string $fname
name of the file where the tag was found (kind of parser id)
string $tagname
name of the start tag that was found
array $attributes
all attributes that were found
string $line
the complete line containing the tag
integer $lineno
lineno in the parse file (can be used for error messages
Returns void


endElementHandler

private void endElementHandler( string $fname, string $tagname, string $line )

  handle a </patTemplate:...> end tag in template parser

Parameter
string $fname
name of the file where the tag was found (kind of parser id)
string $tagname
name of the start tag that was found
string $line
the complete line containing the tag
Returns void


DataHandler

private void DataHandler( string $fname, string $data )

  handle a CDATA in template parser

Parameter
string $fname
name of the file where the tag was found (kind of parser id)
string $data
all cdata that was found
Returns void


addDependency

private void addDependency( string $container, string $child )

  Creates a dependeny between two templates
The Dependency tells a template, which templates have to be parsed before parsing the current template, because they are its children.

Parameter
string $container
the name of the template, that contains the other template
string $child
the child of the container
Returns void


loadTemplate

private void loadTemplate( string $name )

  loads a template
The template has to be defined using addTemplate() or addTemplates()

Parameter
string $name
name of the template that has to be loaded
Returns void

Deprecated 2.4 2001/11/05
See Also addTemplate(), addTemplates()

setPlainContent

private void setPlainContent( string $template, string $content, [ string $sub ] )

  sets the content of a template
This function should used, if a template is added using tags instead of defining it by a filename

Parameter
string $template
name of the template
string $content
the content that has to be set
string $sub = >>""<<
condition, for the subtemplate, if any
Returns void


parseStandardTemplate

private void parseStandardTemplate( string $name, [ string $mode ] )

  parses a standard template
Parses a template and stores the parsed content.mode can be "w" for write (delete already parsed content) or "a" for append (appends thenew parsed content to the already parsed content)

Parameter
string $name
name of the template
string $mode = >>"w"<<
mode for the parsing
Returns void

See Also parseTemplate(), parseIterativeTemplate()

parseIterativeTemplate

private void parseIterativeTemplate( string $name, string $mode )

  parses an iterative template
Parses a template and stores the parsed content.mode can be "w" for write (delete already parsed content) or "a" for append (appends thenew parsed content to the already parsed content)

Parameter
string $name
name of the template
string $mode
mode for the parsing
Returns void

See Also parseTemplate(), parseStandardTemplate()

getVars

private array getVars( string $template )

  get variables for a template
if the templates uses the attribute 'varscope' these vars will be fetched, too

Parameter
string $template
name of the template
Returns array $vars

array containign vars


parseGlobals

private void parseGlobals( string $name, string &$temp )

  parses the global variables in a template
global variables are valid in all templates

Parameter
string $name
name of the template
string &$temp
content of the parsed Template
Returns void

See Also parseTemplate(), addGlobalVar(), addGlobalVars()

stripUnusedVars

private void stripUnusedVars( string $name, string &$template )

  handles unset variables
either strips, comments, replaces or ignores them, depending on the unusedvars attribute

Parameter
string $name
name of the template
string &$template
content of the parsed Template
Returns void

See Also setAttribute()

parseDependencies

private void parseDependencies( string $name, string &$temp, string $mode )

  parses dependencies of a template
parses child templates of a template and inserts their content

Parameter
string $name
name of the template
string &$temp
content of the parsed Template
string $mode
Warning: documentation is missing.
Returns void

See Also addDependency()

getPlainTemplate

private string getPlainTemplate( string $name )

  returns an unparsed Template
If the template has not been loaded, it will be loaded.

Parameter
string $name
name of the template
Returns string $content

Unparsed content of the template

Deprecated 2.4 2001/11/05
See Also getPlainSubTemplate(), displayPlainTemplate()

getPlainSubTemplate

private string getPlainSubTemplate( string $name, string $sub )

  returns an unparsed Subtemplate
The template of the template has to be set

Parameter
string $name
name of the template
string $sub
condition for the subtemplate
Returns string $content

Unparsed content of the template

Deprecated 2.4 2001/11/05
See Also getPlainTemplate(), displayPlainTemplate()

displayPlainTemplate

private void displayPlainTemplate( string $name )

  displays an unparsed Template
If the template has not been loaded, it will be loaded.

Parameter
string $name
name of the template
Returns void

Deprecated 2.4 2001/11/05
See Also getPlainTemplate(), getPlainSubTemplate()

parseAttributes

private array parseAttributes( string $string )

  parsed attributes from a string
used for parsing <patTemplate> Tags

Parameter
string $string
string containing the attributes
Returns array $array

assotiative array, containing all attributes


getTemplateContent

private string getTemplateContent( string $name )

  returns the plain content of a template
return value depends on iteration value

Parameter
string $name
name of the template
Returns string $content

plain content of the template


getVar

private mixed getVar( string $template )

  get the value of a variable

Parameter
string $template
name of the template
Returns mixed $value

value of the variable / false if it doesn't exist


Public Constant Details

patTEMPLATE_TAG_START

define( patTEMPLATE_TAG_START, >>{<< )
Case: default: case sensitive

Variable prefix


patTEMPLATE_TAG_END

define( patTEMPLATE_TAG_END, >>}<< )
Case: default: case sensitive

Variable sufix


Private Constant Details

patTEMPLATE_TYPE_STANDARD

define( patTEMPLATE_TYPE_STANDARD, >>STANDARD<< )
Case: default: case sensitive

Template type Standard


patTEMPLATE_TYPE_ODDEVEN

define( patTEMPLATE_TYPE_ODDEVEN, >>ODDEVEN<< )
Case: default: case sensitive

Template type OddEven


patTEMPLATE_TYPE_CONDITION

define( patTEMPLATE_TYPE_CONDITION, >>CONDITION<< )
Case: default: case sensitive

Template type Condition


patTEMPLATE_TYPE_SIMPLECONDITION

define( patTEMPLATE_TYPE_SIMPLECONDITION, >>SIMPLECONDITION<< )
Case: default: case sensitive

Template type SimpleCondition



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta