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

Public Member Functions

 HTML_Template_ITX ($root= '')
 init ()
 replaceBlock ($block, $template, $keep_content=false)
 replaceBlockfile ($block, $filename, $keep_content=false)
 addBlock ($placeholder, $blockname, $template)
 addBlockfile ($placeholder, $blockname, $filename)
 placeholderExists ($placeholder, $block= '')
 performCallback ()
 getFunctioncalls ()
 setFunctioncontent ($functionID, $replacement)
 setCallbackFunction ($tplfunction, $callbackfunction, $callbackobject= '', $expandCallbackParameters=false)
 setCallbackFuntiontable ($functions)
 removeBlockData ($block)
 getBlocklist ()
 blockExists ($blockname)
 getBlockvariables ($block)
 BlockvariableExists ($block, $variable)
 buildFunctionlist ()
 getValue ($code, $delimiter)
 deleteFromBlockvariablelist ($block, $variables)
 updateBlockvariablelist ($block)
 findPlaceholderBlocks ($variable)
 warning ($message, $file= '', $line=0)
- Public Member Functions inherited from HTML_Template_IT
 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)
 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

 $warn = array()
 $printWarning = false
 $haltOnWarning = false
 $checkblocknameRegExp = ''
 $functionPrefix = 'func_'
 $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*'
 $functionRegExp = ''
 $functions = array()
 $callback = array()
- Data Fields inherited from HTML_Template_IT
 $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

addBlock (   $placeholder,
  $blockname,
  $template 
)

Adds a block to the template changing a variable placeholder to a block placeholder.

Add means "replace a variable placeholder by a new block". This is different to PHPLibs templates. The function loads a block, creates a handle for it and assigns it to a certain variable placeholder. To to the same with PHPLibs templates you would call set_file() to create the handle and parse() to assign the parsed block to a variable. By this PHPLibs templates assume that you tend to assign a block to more than one one placeholder. To assign a parsed block to more than only the placeholder you specify in this function you have to use a combination of getBlock() and setVariable().

As no updates to cached data is necessary addBlock() and addBlockfile() are rather "cheap" meaning quick operations.

The block content must not start with and end with this would cause overhead and produce an error.

Parameters
stringName of the variable placeholder, the name must be unique within the template.
stringName of the block to be added
stringContent of the block
Returns
boolean
Exceptions
IT_Error
See Also
addBlockfile() public

Here is the call graph for this function:

Here is the caller graph for this function:

addBlockfile (   $placeholder,
  $blockname,
  $filename 
)

Adds a block taken from a file to the template changing a variable placeholder to a block placeholder.

Parameters
stringName of the variable placeholder to be converted
stringName of the block to be added
stringFile that contains the block addBlock() public

Here is the call graph for this function:

blockExists (   $blockname)

Checks wheter a block exists.

Parameters
string
Returns
boolean public
See Also
getBlocklist()
BlockvariableExists (   $block,
  $variable 
)

Checks wheter a block variable exists.

Parameters
stringBlockname
stringVariablename
Returns
boolean public
See Also
getBlockvariables()
buildFunctionlist ( )

Builds a functionlist from the template. private

Here is the call graph for this function:

Here is the caller graph for this function:

deleteFromBlockvariablelist (   $block,
  $variables 
)

Deletes one or many variables from the block variable list.

Parameters
stringBlockname
mixedName of one variable or array of variables ( array ( name => true ) ) to be stripped. private

Here is the caller graph for this function:

findPlaceholderBlocks (   $variable)

Returns an array of blocknames where the given variable placeholder is used.

Parameters
stringVariable placeholder
Returns
array $parents parents[0..n] = blockname public

Here is the caller graph for this function:

getBlocklist ( )

Returns a list of blocknames in the template.

Returns
array [blockname => blockname] public
See Also
blockExists()
getBlockvariables (   $block)

Returns a list of variables of a block.

Parameters
stringBlockname
Returns
array [varname => varname] public
See Also
BlockvariableExists()
getFunctioncalls ( )

Returns a list of all function calls in the current template.

Returns
array public
getValue (   $code,
  $delimiter 
)

Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '.

private

Parameters
stringThe code which should be parsed
stringThe delimiter char
Returns
string
See Also
buildFunctionList()

Here is the caller graph for this function:

HTML_Template_ITX (   $root = '')

Builds some complex regexps and calls the constructor of the parent class.

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

See Also
HTML_Template_IT()

Here is the call 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 from HTML_Template_IT.

Here is the call graph for this function:

performCallback ( )

Checks the list of function calls in the template and calls their callback function.

public

placeholderExists (   $placeholder,
  $block = '' 
)

Returns the name of the (first) block that contains the specified placeholder.

Parameters
stringName of the placeholder you're searching
stringName of the block to scan. If left out (default) all blocks are scanned.
Returns
string Name of the (first) block that contains the specified placeholder. If the placeholder was not found or an error occured an empty string is returned.
Exceptions
IT_Errorpublic
removeBlockData (   $block)

Recursively removes all data assiciated with a block, including all inner blocks

Parameters
stringblock to be removed private

Here is the caller graph for this function:

replaceBlock (   $block,
  $template,
  $keep_content = false 
)

Replaces an existing block with new content.

This function will replace a block of the template and all blocks contained in the replaced block and add a new block insted, means you can dynamically change your template.

Note that changing the template structure violates one of the IT[X] development goals. I've tried to write a simple to use template engine supporting blocks. In contrast to other systems IT[X] analyses the way you've nested blocks and knows which block belongs into another block. The nesting information helps to make the API short and simple. Replacing blocks does not only mean that IT[X] has to update the nesting information (relatively time consumpting task) but you have to make sure that you do not get confused due to the template change itself.

Parameters
stringBlockname
stringBlockcontent
booleantrue if the new block inherits the content of the old block
Returns
boolean
Exceptions
IT_Error
See Also
replaceBlockfile(), addBlock(), addBlockfile() public

Here is the call graph for this function:

Here is the caller graph for this function:

replaceBlockfile (   $block,
  $filename,
  $keep_content = false 
)

Replaces an existing block with new content from a file.

replaceBlock()

Parameters
stringBlockname
stringName of the file that contains the blockcontent
booleantrue if the new block inherits the content of the old block public

Here is the call graph for this function:

setCallbackFunction (   $tplfunction,
  $callbackfunction,
  $callbackobject = '',
  $expandCallbackParameters = false 
)

Sets a callback function.

IT[X] templates (note the X) can contain simple function calls. "function call" means that the editor of the template can add special placeholder to the template like 'func_h1("embedded in h1")'. IT[X] will grab this function calls and allow you to define a callback function for them.

This is an absolutely evil feature. If your application makes heavy use of such callbacks and you're even implementing if-then etc. on the level of a template engine you're reiventing the wheel... - that's actually how PHP came into life. Anyway, sometimes it's handy.

Consider also using XML/XSLT or native PHP. And please do not push IT[X] any further into this direction of adding logics to the template engine.

For those of you ready for the X in IT[X]:

<?php ... function h_one($args) { return sprintf('

s

', $args[0]); }

... $itx = new HTML_Template_ITX( ... ); ... $itx->setCallbackFunction('h1', 'h_one'); $itx->performCallback(); ?>

template: func_h1('H1 Headline');

Parameters
stringFunction name in the template
stringName of the callback function
stringName of the callback object
booleanIf the callback is called with a list of parameters or with an array holding the parameters
Returns
boolean False on failure.
Exceptions
IT_Errorpublic
Deprecated:
The $callbackobject parameter is depricated since version 1.2 and might be dropped in further versions.
setCallbackFuntiontable (   $functions)

Sets the Callback function lookup table

Parameters
arrayfunction table array[templatefunction] = array( "function" => userfunction, "object" => userobject ) public
setFunctioncontent (   $functionID,
  $replacement 
)

Replaces a function call with the given replacement.

Parameters
intFunction ID
stringReplacement
Deprecated:
updateBlockvariablelist (   $block)

Updates the variable list of a block.

Parameters
stringBlockname private

Here is the caller graph for this function:

warning (   $message,
  $file = '',
  $line = 0 
)

Handles warnings, saves them to $warn and prints them or calls die() depending on the flags

Parameters
stringWarning
stringFile where the warning occured
intLinenumber where the warning occured
See Also
$warn, $printWarning, $haltOnWarning private

Field Documentation

$callback = array()
$checkblocknameRegExp = ''
$functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*'
$functionPrefix = 'func_'
$functionRegExp = ''
$functions = array()
$haltOnWarning = false
$printWarning = false
$warn = array()

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