ILIAS
release_4-3 Revision
|
Public Member Functions | |
HTML_Template_ITX ($root= '') | |
Builds some complex regexps and calls the constructor of the parent class. | |
init () | |
Clears all datafields of the object and rebuild the internal blocklist. | |
replaceBlock ($block, $template, $keep_content=false) | |
Replaces an existing block with new content. | |
replaceBlockfile ($block, $filename, $keep_content=false) | |
Replaces an existing block with new content from a file. | |
addBlock ($placeholder, $blockname, $template) | |
Adds a block to the template changing a variable placeholder to a block placeholder. | |
addBlockfile ($placeholder, $blockname, $filename) | |
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder. | |
placeholderExists ($placeholder, $block= '') | |
Returns the name of the (first) block that contains the specified placeholder. | |
performCallback () | |
Checks the list of function calls in the template and calls their callback function. | |
getFunctioncalls () | |
Returns a list of all function calls in the current template. | |
setFunctioncontent ($functionID, $replacement) | |
Replaces a function call with the given replacement. | |
setCallbackFunction ($tplfunction, $callbackfunction, $callbackobject= '', $expandCallbackParameters=false) | |
Sets a callback function. | |
setCallbackFuntiontable ($functions) | |
Sets the Callback function lookup table. | |
removeBlockData ($block) | |
Recursively removes all data assiciated with a block, including all inner blocks. | |
getBlocklist () | |
Returns a list of blocknames in the template. | |
blockExists ($blockname) | |
Checks wheter a block exists. | |
getBlockvariables ($block) | |
Returns a list of variables of a block. | |
BlockvariableExists ($block, $variable) | |
Checks wheter a block variable exists. | |
buildFunctionlist () | |
Builds a functionlist from the template. | |
getValue ($code, $delimiter) | |
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '. | |
deleteFromBlockvariablelist ($block, $variables) | |
Deletes one or many variables from the block variable list. | |
updateBlockvariablelist ($block) | |
Updates the variable list of a block. | |
findPlaceholderBlocks ($variable) | |
Returns an array of blocknames where the given variable placeholder is used. | |
warning ($message, $file= '', $line=0) | |
Handles warnings, saves them to $warn and prints them or calls die() depending on the flags. | |
Public Member Functions inherited from HTML_Template_IT | |
HTML_Template_IT ($root= '', $options=null) | |
Builds some complex regular expressions and optinally sets the file root directory. | |
setOption ($option, $value) | |
Sets the option for the template class. | |
setOptions ($options) | |
Sets the options for the template class. | |
show ($block= '__global__') | |
Print a certain block with all replacements done. | |
get ($block= '__global__') | |
Returns a block with all replacements done. | |
parse ($block= '__global__', $flag_recursion=false) | |
Parses the given block. | |
parseCurrentBlock () | |
Parses the current block. | |
setVariable ($variable, $value= '') | |
Sets a variable value. | |
setCurrentBlock ($block= '__global__') | |
Sets the name of the current block that is the block where variables are added. | |
touchBlock ($block) | |
Preserves an empty block even if removeEmptyBlocks is true. | |
free () | |
Clears all datafields of the object. | |
setTemplate ($template, $removeUnknownVariables=true, $removeEmptyBlocks=true) | |
Sets the template. | |
loadTemplatefile ($filename, $removeUnknownVariables=true, $removeEmptyBlocks=true) | |
Reads a template file from the disk. | |
setRoot ($root) | |
Sets the file root. | |
buildBlockvariablelist () | |
Build a list of all variables within of a block. | |
getGlobalvariables () | |
Returns a list of all global variables. | |
findBlocks ($string) | |
Recusively builds a list of all blocks within the template. | |
getFile ($filename) | |
Reads a file from disk and returns its content. | |
_addPregDelimiters ($str) | |
Adds delimiters to a string, so it can be used as a pattern in preg_* functions. | |
_preserveOpeningDelimiter ($str) | |
Replaces an opening delimiter by a special string. | |
errorMessage ($value, $blockname= '') | |
Return a textual error message for a IT error code. |
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 = '' | |
RegExp used to strip unused variable placeholder. | |
$removeUnknownVariables = true | |
$removeEmptyBlocks = true | |
$blockRegExp = '' | |
$currentBlock = '__global__' | |
$template = '' | |
$blocklist = array() | |
$blockdata = array() | |
$blockvariables = array() | |
$blockinner = array() | |
$touchedBlocks = array() | |
List of blocks to preverse even if they are "empty". | |
$_hiddenBlocks = array() | |
List of blocks which should not be shown even if not "empty". | |
$variableCache = array() | |
$clearCacheOnParse = false | |
$fileRoot = '' | |
$flagBlocktrouble = false | |
$flagGlobalParsed = false | |
$flagCacheTemplatefile = true | |
$lastTemplatefile = '' | |
EXPERIMENTAL! FIXME! | |
$_options | |
$_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951). |
HTML_Template_ITX::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 |
Definition at line 248 of file ITX.php.
References HTML_Template_IT\$template, deleteFromBlockvariablelist(), HTML_Template_IT\findBlocks(), findPlaceholderBlocks(), and updateBlockvariablelist().
Referenced by addBlockfile(), and ilTemplate\addBlockFile().
HTML_Template_ITX::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 |
Definition at line 325 of file ITX.php.
References $filename, addBlock(), and HTML_Template_IT\getFile().
HTML_Template_ITX::blockExists | ( | $blockname | ) |
Checks wheter a block exists.
string |
Reimplemented in ilTemplate, and ilTemplate.
Definition at line 578 of file ITX.php.
HTML_Template_ITX::BlockvariableExists | ( | $block, | |
$variable | |||
) |
Checks wheter a block variable exists.
string | Blockname |
string | Variablename |
Definition at line 614 of file ITX.php.
HTML_Template_ITX::buildFunctionlist | ( | ) |
Builds a functionlist from the template.
private
Definition at line 623 of file ITX.php.
References HTML_Template_IT\$closingDelimiter, HTML_Template_IT\$template, and getValue().
Referenced by ilTemplate\init(), and init().
HTML_Template_ITX::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 |
Definition at line 726 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::findPlaceholderBlocks | ( | $variable | ) |
Returns an array of blocknames where the given variable placeholder is used.
string | Variable placeholder |
Definition at line 783 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::getBlocklist | ( | ) |
Returns a list of blocknames in the template.
Definition at line 560 of file ITX.php.
References HTML_Template_IT\$blocklist.
HTML_Template_ITX::getBlockvariables | ( | $block | ) |
Returns a list of variables of a block.
string | Blockname |
Definition at line 591 of file ITX.php.
HTML_Template_ITX::getFunctioncalls | ( | ) |
Returns a list of all function calls in the current template.
Definition at line 431 of file ITX.php.
References $functions.
HTML_Template_ITX::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 |
Definition at line 675 of file ITX.php.
Referenced by buildFunctionlist().
HTML_Template_ITX::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.
Definition at line 118 of file ITX.php.
References HTML_Template_IT\HTML_Template_IT().
Referenced by ilTemplateX\callConstructor().
HTML_Template_ITX::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.
Reimplemented in ilTemplate.
Definition at line 128 of file ITX.php.
References HTML_Template_IT\buildBlockvariablelist(), buildFunctionlist(), HTML_Template_IT\findBlocks(), and HTML_Template_IT\free().
HTML_Template_ITX::performCallback | ( | ) |
Checks the list of function calls in the template and calls their callback function.
public
Definition at line 392 of file ITX.php.
References $GLOBALS.
HTML_Template_ITX::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 |
Definition at line 344 of file ITX.php.
HTML_Template_ITX::removeBlockData | ( | $block | ) |
Recursively removes all data assiciated with a block, including all inner blocks.
string | block to be removed private |
Definition at line 536 of file ITX.php.
Referenced by replaceBlock().
HTML_Template_ITX::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 |
Definition at line 164 of file ITX.php.
References HTML_Template_IT\$blockdata, HTML_Template_IT\$template, HTML_Template_IT\buildBlockvariablelist(), HTML_Template_IT\findBlocks(), and removeBlockData().
Referenced by replaceBlockfile().
HTML_Template_ITX::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 |
Definition at line 212 of file ITX.php.
References $filename, HTML_Template_IT\getFile(), and replaceBlock().
HTML_Template_ITX::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 |
Definition at line 496 of file ITX.php.
HTML_Template_ITX::setCallbackFuntiontable | ( | $functions | ) |
Sets the Callback function lookup table.
array | function table array[templatefunction] = array( "function" => userfunction, "object" => userobject ) public |
Definition at line 525 of file ITX.php.
References $functions.
HTML_Template_ITX::setFunctioncontent | ( | $functionID, | |
$replacement | |||
) |
HTML_Template_ITX::updateBlockvariablelist | ( | $block | ) |
Updates the variable list of a block.
string | Blockname private |
Definition at line 746 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::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 |
Definition at line 811 of file ITX.php.
References $file.
HTML_Template_ITX::$functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*' |
HTML_Template_ITX::$functions = array() |
Definition at line 100 of file ITX.php.
Referenced by getFunctioncalls(), and setCallbackFuntiontable().