119 $this->checkblocknameRegExp =
'@' . $this->blocknameRegExp .
'@';
120 $this->functionRegExp =
'@' . $this->functionPrefix .
'(' .
121 $this->functionnameRegExp .
')\s*\(@sm';
123 parent::__construct($root);
132 $this->
template =
'';
164 if (!isset($this->blocklist[$block])) {
166 " does not exist in the template and thus it can't be replaced."));
181 $parents = $this->blockparents[$block];
183 $this->blockparents[$block] = $parents;
246 if ($placeholder ==
'') {
248 } elseif ($blockname ==
'' ||
249 !preg_match($this->checkblocknameRegExp, $blockname)
254 } elseif (isset($this->blocklist[$blockname])) {
260 if (count($parents) == 0) {
262 " '$placeholder' was not found in the template."));
264 } elseif (count($parents) > 1) {
267 while (list($k, $parent) = each($parents)) {
270 $msg = substr($parent, -2);
272 " must be unique, found in multiple blocks '$msg'."));
277 if ($this->flagBlocktrouble) {
280 $this->blockinner[$parents[0]][] = $blockname;
281 $this->blocklist[$parents[0]] = preg_replace(
282 '@' . $this->openingDelimiter . $placeholder .
283 $this->closingDelimiter .
'@',
285 $this->openingDelimiter .
'__' . $blockname .
'__' .
286 $this->closingDelimiter,
288 $this->blocklist[$parents[0]]
328 if ($placeholder ==
'') {
332 if ($block !=
'' && !isset($this->blocklist[$block])) {
340 if (is_array($variables = $this->blockvariables[$block])) {
343 while (list($k, $variable) = each($variables)) {
344 if ($k == $placeholder) {
354 reset($this->blockvariables);
355 while (list($blockname, $variables) = each($this->blockvariables)){
356 if (is_array($variables) && isset($variables[$placeholder])) {
375 while (list($func_id, $function) = each($this->
functions)) {
376 if (isset($this->callback[$function[
'name']])) {
377 if ($this->callback[$function[
'name']][
'expandParameters']) {
378 $callFunction =
'call_user_func_array';
380 $callFunction =
'call_user_func';
383 if ($this->callback[$function[
'name']][
'object'] !=
'') {
387 &
$GLOBALS[$this->callback[$function[
'name']][
'object']],
388 $this->callback[$function[
'name']][
'function']),
395 $this->callback[$function[
'name']][
'function'],
399 $this->variableCache[
'__function' . $func_id .
'__'] = $call;
425 $this->variableCache[
'__function' . $functionID .
'__'] = $replacement;
476 setCallbackFunction($tplfunction, $callbackfunction, $callbackobject =
'', $expandCallbackParameters=
false)
478 if ($tplfunction ==
'' || $callbackfunction ==
'') {
480 " and/or no callback function ('$callbackfunction') given."));
482 $this->callback[$tplfunction] =
array(
483 'function' => $callbackfunction,
484 'object' => $callbackobject,
485 'expandParameters' => (
boolean) $expandCallbackParameters
515 if (isset($this->blockinner[$block])) {
516 foreach ($this->blockinner[$block] as $k => $inner) {
520 unset($this->blockinner[$block]);
523 unset($this->blocklist[$block]);
524 unset($this->blockdata[$block]);
525 unset($this->blockvariables[$block]);
526 unset($this->touchedBlocks[$block]);
540 foreach ($this->blocklist as $block => $content) {
557 return isset($this->blocklist[$blockname]);
570 if (!isset($this->blockvariables[$block])) {
574 $variables =
array();
575 foreach ($this->blockvariables[$block] as $variable => $v) {
576 $variables[$variable] = $variable;
593 return isset($this->blockvariables[$block][$variable]);
607 while (preg_match($this->functionRegExp,
$template, $regs)) {
615 $search = $regs[0] . $head .
')';
617 $replace = $this->openingDelimiter .
618 '__function' . $num .
'__' .
621 $this->
template = str_replace($search, $replace, $this->
template);
624 while ($head !=
'' && $args2 = $this->
getValue($head,
',')) {
625 $arg2 = trim($args2);
626 $args[] = (
'"' == $arg2{0} ||
"'" == $arg2{0}) ?
627 substr($arg2, 1, -1) : $arg2;
628 if ($arg2 == $head) {
631 $head = substr($head, strlen($arg2) + 1);
657 if (!is_array($delimiter)) {
658 $delimiter =
array( $delimiter =>
true );
661 $len = strlen(
$code);
665 if (isset($delimiter[
$code[0]])) {
668 for ($i = 0; $i < $len; ++$i) {
672 ($char ==
'"' || $char ==
"'") &&
673 ($char == $enclosed_by ||
'' == $enclosed_by) &&
674 (0 == $i || ($i > 0 &&
'\\' != $code[$i - 1]))
678 $enclosed_by = $char;
682 $enclosed = !$enclosed;
686 if (!$enclosed && isset($delimiter[$char])) {
692 return substr($code, 0, $i);
705 if (!is_array($variables)) {
706 $variables =
array($variables =>
true);
709 reset($this->blockvariables[$block]);
710 while (list($varname, $val) = each($this->blockvariables[$block])) {
711 if (isset($variables[$varname])) {
712 unset($this->blockvariables[$block][$varname]);
725 preg_match_all( $this->variablesRegExp,
726 $this->blocklist[$block], $regs
729 if (count($regs[1]) != 0) {
730 foreach ($regs[1] as $k => $var) {
731 $this->blockvariables[$block][$var] =
true;
734 $this->blockvariables[$block] =
array();
738 if (isset($this->blockinner[$block]) &&
739 is_array($this->blockinner[$block]) &&
740 count($this->blockinner[$block]) > 0
746 foreach ($this->blockinner[$block] as $childBlock) {
763 reset($this->blocklist);
764 while (list($blockname, $content) = each($this->blocklist)) {
765 reset($this->blockvariables[$blockname]);
767 list($varname, $val) = each($this->blockvariables[$blockname]))
769 if ($variable == $varname) {
770 $parents[] = $blockname;
791 'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
797 $this->warn[] = $message;
799 if ($this->printWarning) {
803 if ($this->haltOnWarning) {
addBlockfile($placeholder, $blockname, $filename)
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder...
deleteFromBlockvariablelist($block, $variables)
Deletes one or many variables from the block variable list.
List implemented functions
setCallbackFuntiontable($functions)
Sets the Callback function lookup table.
findPlaceholderBlocks($variable)
Returns an array of blocknames where the given variable placeholder is used.
__construct($root='')
Builds some complex regexps and calls the constructor of the parent class.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getBlocklist()
Returns a list of blocknames in the template.
addBlock($placeholder, $blockname, $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
getFunctioncalls()
Returns a list of all function calls in the current template.
removeBlockData($block)
Recursively removes all data assiciated with a block, including all inner blocks. ...
getBlockvariables($block)
Returns a list of variables of a block.
replaceBlockfile($block, $filename, $keep_content=false)
Replaces an existing block with new content from a file.
free()
Clears all datafields of the object.
getValue($code, $delimiter)
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " ...
setCallbackFunction($tplfunction, $callbackfunction, $callbackobject='', $expandCallbackParameters=false)
Sets a callback function.
setFunctioncontent($functionID, $replacement)
Replaces a function call with the given replacement.
Create styles array
The data for the language used.
blockExists($blockname)
Checks wheter a block exists.
buildBlockvariablelist()
Build a list of all variables within of a block.
updateBlockvariablelist($block)
Updates the variable list of a block.
BlockvariableExists($block, $variable)
Checks wheter a block variable exists.
warning($message, $file='', $line=0)
Handles warnings, saves them to $warn and prints them or calls die() depending on the flags...
placeholderExists($placeholder, $block='')
Returns the name of the (first) block that contains the specified placeholder.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
findBlocks($string)
Recusively builds a list of all blocks within the template.
getFile($filename)
Reads a file from disk and returns its content.
replaceBlock($block, $template, $keep_content=false)
Replaces an existing block with new content.
Integrated Template - IT.
buildFunctionlist()
Builds a functionlist from the template.
performCallback()
Checks the list of function calls in the template and calls their callback function.