Stud.IP
2.0 Revision 48548
|
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 |
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.
string | Name of the variable placeholder, the name must be unique within the template. |
string | Name of the block to be added |
string | Content of the block |
IT_Error |
addBlockfile | ( | $placeholder, | |
$blockname, | |||
$filename | |||
) |
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder.
string | Name of the variable placeholder to be converted |
string | Name of the block to be added |
string | File that contains the block addBlock() public |
blockExists | ( | $blockname | ) |
BlockvariableExists | ( | $block, | |
$variable | |||
) |
Checks wheter a block variable exists.
string | Blockname |
string | Variablename |
buildFunctionlist | ( | ) |
Builds a functionlist from the template. private
deleteFromBlockvariablelist | ( | $block, | |
$variables | |||
) |
Deletes one or many variables from the block variable list.
string | Blockname |
mixed | Name of one variable or array of variables ( array ( name => true ) ) to be stripped. private |
findPlaceholderBlocks | ( | $variable | ) |
Returns an array of blocknames where the given variable placeholder is used.
string | Variable placeholder |
getBlocklist | ( | ) |
Returns a list of blocknames in the template.
getBlockvariables | ( | $block | ) |
Returns a list of variables of a block.
string | Blockname |
getFunctioncalls | ( | ) |
Returns a list of all function calls in the current template.
getValue | ( | $code, | |
$delimiter | |||
) |
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '.
private
string | The code which should be parsed |
string | The delimiter char |
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.
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
Reimplemented from HTML_Template_IT.
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.
string | Name of the placeholder you're searching |
string | Name of the block to scan. If left out (default) all blocks are scanned. |
IT_Error | public |
removeBlockData | ( | $block | ) |
Recursively removes all data assiciated with a block, including all inner blocks
string | block to be removed private |
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.
string | Blockname |
string | Blockcontent |
boolean | true if the new block inherits the content of the old block |
IT_Error |
replaceBlockfile | ( | $block, | |
$filename, | |||
$keep_content = false |
|||
) |
Replaces an existing block with new content from a file.
string | Blockname |
string | Name of the file that contains the blockcontent |
boolean | true if the new block inherits the content of the old block public |
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('
', $args[0]); }
... $itx = new HTML_Template_ITX( ... ); ... $itx->setCallbackFunction('h1', 'h_one'); $itx->performCallback(); ?>
template: func_h1('H1 Headline');
string | Function name in the template |
string | Name of the callback function |
string | Name of the callback object |
boolean | If the callback is called with a list of parameters or with an array holding the parameters |
IT_Error | public |
setCallbackFuntiontable | ( | $functions | ) |
Sets the Callback function lookup table
array | function table array[templatefunction] = array( "function" => userfunction, "object" => userobject ) public |
setFunctioncontent | ( | $functionID, | |
$replacement | |||
) |
Replaces a function call with the given replacement.
int | Function ID |
string | Replacement |
updateBlockvariablelist | ( | $block | ) |
Updates the variable list of a block.
string | Blockname private |
warning | ( | $message, | |
$file = '' , |
|||
$line = 0 |
|||
) |
Handles warnings, saves them to $warn and prints them or calls die() depending on the flags
string | Warning |
string | File where the warning occured |
int | Linenumber where the warning occured |
$callback = array() |
$checkblocknameRegExp = '' |
$functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*' |
$functionPrefix = 'func_' |
$functionRegExp = '' |
$functions = array() |
$haltOnWarning = false |
$printWarning = false |
$warn = array() |