Stud.IP  2.0 Revision 48548
 All Data Structures Namespaces Files Functions Variables Pages
HTML_Template_IT Class Reference
Inheritance diagram for HTML_Template_IT:
Inheritance graph
Collaboration diagram for HTML_Template_IT:
Collaboration graph

Public Member Functions

 HTML_Template_IT ($root= '', $options=null)
 setOption ($option, $value)
 setOptions ($options)
 show ($block= '__global__')
 get ($block= '__global__')
 parse ($block= '__global__', $flag_recursion=false)
 parseCurrentBlock ()
 setVariable ($variable, $value= '')
 setCurrentBlock ($block= '__global__')
 touchBlock ($block)
 init ()
 free ()
 setTemplate ($template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 loadTemplatefile ($filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 setRoot ($root)
 buildBlockvariablelist ()
 getGlobalvariables ()
 findBlocks ($string)
 getFile ($filename)
 _addPregDelimiters ($str)
 _preserveOpeningDelimiter ($str)
 errorMessage ($value, $blockname= '')

Data Fields

 $err = array()
 $clearCache = false
 $openingDelimiter = '###'
 $closingDelimiter = '###'
 $blocknameRegExp = '[0-9A-Za-z_-]+'
 $variablenameRegExp = '[\.0-9A-Za-z_-]+'
 $variablesRegExp = ''
 $removeVariablesRegExp = ''
 $removeUnknownVariables = true
 $removeEmptyBlocks = true
 $blockRegExp = ''
 $currentBlock = '__global__'
 $template = ''
 $blocklist = array()
 $blockdata = array()
 $blockvariables = array()
 $blockinner = array()
 $touchedBlocks = array()
 $_hiddenBlocks = array()
 $variableCache = array()
 $clearCacheOnParse = false
 $fileRoot = ''
 $flagBlocktrouble = false
 $flagGlobalParsed = false
 $flagCacheTemplatefile = true
 $lastTemplatefile = ''
 $_options

Member Function Documentation

_addPregDelimiters (   $str)

Adds delimiters to a string, so it can be used as a pattern in preg_* functions

Parameters
string
Returns
string
_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string

Parameters
string
Returns
string
buildBlockvariablelist ( )

Build a list of all variables within of a block

Here is the caller graph for this function:

errorMessage (   $value,
  $blockname = '' 
)

Return a textual error message for a IT error code

Parameters
integer$valueerror code
Returns
string error message, or false if the error code was not recognized
findBlocks (   $string)

Recusively builds a list of all blocks within the template.

Parameters
stringstring that gets scanned
See Also
$blocklist

Here is the caller graph for this function:

free ( )

Clears all datafields of the object.

Don't use this function unless you know what you're doing.

public

See Also
init()

Here is the caller graph for this function:

get (   $block = '__global__')

Returns a block with all replacements done.

Parameters
stringname of the block
Returns
string
Exceptions
PEAR_Errorpublic
See Also
show()

Here is the call graph for this function:

getFile (   $filename)

Reads a file from disk and returns its content.

Parameters
stringFilename
Returns
string Filecontent

Here is the caller graph for this function:

getGlobalvariables ( )

Returns a list of all global variables

HTML_Template_IT (   $root = '',
  $options = null 
)

Builds some complex regular expressions and optinally sets the file root directory.

Make sure that you call this constructor if you derive your template class from this one.

Parameters
stringFile root directory, prefix for all filenames given to the object.
See Also
setRoot()

Here is the call graph for this function:

Here is the caller graph for this function:

init ( )

Clears all datafields of the object and rebuild the internal blocklist

LoadTemplatefile() and setTemplate() automatically call this function when a new template is given. Don't use this function unless you know what you're doing.

public

See Also
free()

Reimplemented in HTML_Template_ITX.

Here is the call graph for this function:

Here is the caller graph for this function:

loadTemplatefile (   $filename,
  $removeUnknownVariables = true,
  $removeEmptyBlocks = true 
)

Reads a template file from the disk.

Parameters
stringname of the template file
boolhow to handle unknown variables.
boolhow to handle empty blocks. public
Returns
boolean false on failure, otherwise true
See Also
$template, setTemplate(), $removeUnknownVariables, $removeEmptyBlocks

Here is the call graph for this function:

parse (   $block = '__global__',
  $flag_recursion = false 
)

Parses the given block.

Parameters
stringname of the block to be parsed public
See Also
parseCurrentBlock()
Exceptions
PEAR_Error

Here is the caller graph for this function:

parseCurrentBlock ( )

Parses the current block

See Also
parse(), setCurrentBlock(), $currentBlock public

Here is the call graph for this function:

setCurrentBlock (   $block = '__global__')

Sets the name of the current block that is the block where variables are added.

Parameters
stringname of the block
Returns
boolean false on failure, otherwise true
Exceptions
PEAR_Errorpublic
setOption (   $option,
  $value 
)

Sets the option for the template class

public

Parameters
stringoption name
mixedoption value
Returns
mixed IT_OK on success, error object on failure

Here is the caller graph for this function:

setOptions (   $options)

Sets the options for the template class

public

Parameters
stringoptions array of options default value: 'preserve_data' => false, 'use_preg' => true
mixedoption value
Returns
mixed IT_OK on success, error object on failure
See Also
$options

Here is the call graph for this function:

Here is the caller graph for this function:

setRoot (   $root)

Sets the file root. The file root gets prefixed to all filenames passed to the object.

Make sure that you override this function when using the class on windows.

Parameters
string
See Also
HTML_Template_IT() public

Here is the caller graph for this function:

setTemplate (   $template,
  $removeUnknownVariables = true,
  $removeEmptyBlocks = true 
)

Sets the template.

You can eighter load a template file from disk with LoadTemplatefile() or set the template manually using this function.

Parameters
stringtemplate content
booleanremove unknown/unused variables?
booleanremove empty blocks?
See Also
LoadTemplatefile(), $template public
Returns
boolean

Here is the call graph for this function:

Here is the caller graph for this function:

setVariable (   $variable,
  $value = '' 
)

Sets a variable value.

The function can be used eighter like setVariable( "varname", "value") or with one array $variables["varname"] = "value" given setVariable($variables) quite like phplib templates set_var().

Parameters
mixedstring with the variable name or an array variables["varname"] = "value"
stringvalue of the variable or empty if $variable is an array.
stringprefix for variable names public
show (   $block = '__global__')

Print a certain block with all replacements done. get()

touchBlock (   $block)

Preserves an empty block even if removeEmptyBlocks is true.

Parameters
stringname of the block
Returns
boolean false on false, otherwise true
Exceptions
PEAR_Errorpublic
See Also
$removeEmptyBlocks

Field Documentation

array $_hiddenBlocks = array()

List of blocks which should not be shown even if not "empty"

See Also
hideBlock(), $removeEmptyBlocks
$_options
Initial value:
array(
'preserve_data' => false,
'use_preg' => true
)

$_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951). $_options['use_preg'] Whether to use preg_replace instead of str_replace in parse() (this is a backwards compatibility feature, see also bugs #21951, #20392)

$blockdata = array()
$blockinner = array()
$blocklist = array()
$blocknameRegExp = '[0-9A-Za-z_-]+'
$blockRegExp = ''
$blockvariables = array()
$clearCache = false
$clearCacheOnParse = false
$closingDelimiter = '###'
$currentBlock = '__global__'
$err = array()
$fileRoot = ''
$flagBlocktrouble = false
$flagCacheTemplatefile = true
$flagGlobalParsed = false
$lastTemplatefile = ''

EXPERIMENTAL! FIXME!

$openingDelimiter = '###'
$removeEmptyBlocks = true
$removeUnknownVariables = true
$removeVariablesRegExp = ''

RegExp used to strip unused variable placeholder. $variablesRegExp

$template = ''
array $touchedBlocks = array()

List of blocks to preverse even if they are "empty".

This is something special. Sometimes you have blocks that should be preserved although they are empty (no placeholder replaced). Think of a shopping basket. If it's empty you have to drop a message to the user. If it's filled you have to show the contents of the shopping baseket. Now where do you place the message that the basket is empty? It's no good idea to place it in you applications as customers tend to like unecessary minor text changes. Having another template file for an empty basket means that it's very likely that one fine day the filled and empty basket templates have different layout. I decided to introduce blocks that to not contain any placeholder but only text such as the message "Your shopping basked is empty".

Now if there is no replacement done in such a block the block will be recognized as "empty" and by default ($removeEmptyBlocks = true) be stripped off. To avoid thisyou can now call touchBlock() to avoid this.

The array $touchedBlocks stores a list of touched block which must not be removed even if they are empty.

See Also
touchBlock(), $removeEmptyBlocks
$variableCache = array()
$variablenameRegExp = '[\.0-9A-Za-z_-]+'
$variablesRegExp = ''

The documentation for this class was generated from the following file: