ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTML_Template_ITX Class Reference
+ Inheritance diagram for HTML_Template_ITX:
+ Collaboration diagram for HTML_Template_ITX:

Public Member Functions

 HTML_Template_ITX ($root='')
 Builds some complex regexps and calls the constructor of the parent class. More...
 
 init ()
 Clears all datafields of the object and rebuild the internal blocklist. More...
 
 replaceBlock ($block, $template, $keep_content=false)
 Replaces an existing block with new content. More...
 
 replaceBlockfile ($block, $filename, $keep_content=false)
 Replaces an existing block with new content from a file. More...
 
 addBlock ($placeholder, $blockname, $template)
 Adds a block to the template changing a variable placeholder to a block placeholder. More...
 
 addBlockfile ($placeholder, $blockname, $filename)
 Adds a block taken from a file to the template changing a variable placeholder to a block placeholder. More...
 
 placeholderExists ($placeholder, $block='')
 Returns the name of the (first) block that contains the specified placeholder. More...
 
 performCallback ()
 Checks the list of function calls in the template and calls their callback function. More...
 
 getFunctioncalls ()
 Returns a list of all function calls in the current template. More...
 
 setFunctioncontent ($functionID, $replacement)
 Replaces a function call with the given replacement. More...
 
 setCallbackFunction ($tplfunction, $callbackfunction, $callbackobject='', $expandCallbackParameters=false)
 Sets a callback function. More...
 
 setCallbackFuntiontable ($functions)
 Sets the Callback function lookup table. More...
 
 removeBlockData ($block)
 Recursively removes all data assiciated with a block, including all inner blocks. More...
 
 getBlocklist ()
 Returns a list of blocknames in the template. More...
 
 blockExists ($blockname)
 Checks wheter a block exists. More...
 
 getBlockvariables ($block)
 Returns a list of variables of a block. More...
 
 BlockvariableExists ($block, $variable)
 Checks wheter a block variable exists. More...
 
 buildFunctionlist ()
 Builds a functionlist from the template. More...
 
 getValue ($code, $delimiter)
 Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '. More...
 
 deleteFromBlockvariablelist ($block, $variables)
 Deletes one or many variables from the block variable list. More...
 
 updateBlockvariablelist ($block)
 Updates the variable list of a block. More...
 
 findPlaceholderBlocks ($variable)
 Returns an array of blocknames where the given variable placeholder is used. More...
 
 warning ($message, $file='', $line=0)
 Handles warnings, saves them to $warn and prints them or calls die() depending on the flags. More...
 
- 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. More...
 
 setOption ($option, $value)
 Sets the option for the template class. More...
 
 setOptions ($options)
 Sets the options for the template class. More...
 
 show ($block='__global__')
 Print a certain block with all replacements done. More...
 
 get ($block='__global__')
 Returns a block with all replacements done. More...
 
 parse ($block='__global__', $flag_recursion=false)
 Parses the given block. More...
 
 parseCurrentBlock ()
 Parses the current block. More...
 
 setVariable ($variable, $value='')
 Sets a variable value. More...
 
 setCurrentBlock ($block='__global__')
 Sets the name of the current block that is the block where variables are added. More...
 
 touchBlock ($block)
 Preserves an empty block even if removeEmptyBlocks is true. More...
 
 init ()
 Clears all datafields of the object and rebuild the internal blocklist. More...
 
 free ()
 Clears all datafields of the object. More...
 
 setTemplate ( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 Sets the template. More...
 
 loadTemplatefile ( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 Reads a template file from the disk. More...
 
 setRoot ($root)
 Sets the file root. More...
 
 buildBlockvariablelist ()
 Build a list of all variables within of a block. More...
 
 getGlobalvariables ()
 Returns a list of all global variables. More...
 
 findBlocks ($string)
 Recusively builds a list of all blocks within the template. More...
 
 getFile ($filename)
 Reads a file from disk and returns its content. More...
 
 _addPregDelimiters ($str)
 Adds delimiters to a string, so it can be used as a pattern in preg_* functions. More...
 
 _preserveOpeningDelimiter ($str)
 Replaces an opening delimiter by a special string. More...
 
 errorMessage ($value, $blockname='')
 Return a textual error message for a IT error code. More...
 

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. More...
 
 $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". More...
 
 $_hiddenBlocks = array()
 List of blocks which should not be shown even if not "empty". More...
 
 $variableCache = array()
 
 $clearCacheOnParse = false
 
 $fileRoot = ''
 
 $flagBlocktrouble = false
 
 $flagGlobalParsed = false
 
 $flagCacheTemplatefile = true
 
 $lastTemplatefile = ''
 EXPERIMENTAL! FIXME! More...
 
 $_options
 $_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951). More...
 

Detailed Description

Definition at line 41 of file ITX.php.

Member Function Documentation

◆ addBlock()

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.

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() @access User interface

Definition at line 248 of file ITX.php.

249 {
250 // Don't trust any user even if it's a programmer or yourself...
251 if ($placeholder == '') {
252 return new IT_Error('No variable placeholder given.',
253 __FILE__, __LINE__
254 );
255 } elseif ($blockname == '' ||
256 !preg_match($this->checkblocknameRegExp, $blockname)
257 ) {
258 return new IT_Error("No or invalid blockname '$blockname' given.",
259 __FILE__, __LINE__
260 );
261 } elseif ($template == '') {
262 return new IT_Error('No block content given.', __FILE__, __LINE__);
263 } elseif (isset($this->blocklist[$blockname])) {
264 return new IT_Error('The block already exists.',
265 __FILE__, __LINE__
266 );
267 }
268
269 // find out where to insert the new block
270 $parents = $this->findPlaceholderBlocks($placeholder);
271 if (count($parents) == 0) {
272
273 return new IT_Error(
274 "The variable placeholder".
275 " '$placeholder' was not found in the template.",
276 __FILE__, __LINE__
277 );
278
279 } elseif (count($parents) > 1) {
280
281 reset($parents);
282 while (list($k, $parent) = each($parents)) {
283 $msg .= "$parent, ";
284 }
285 $msg = substr($parent, -2);
286
287 return new IT_Error("The variable placeholder "."'$placeholder'".
288 " must be unique, found in multiple blocks '$msg'.",
289 __FILE__, __LINE__
290 );
291 }
292
293 $template = "<!-- BEGIN $blockname -->" . $template . "<!-- END $blockname -->";
294 $this->findBlocks($template);
295 if ($this->flagBlocktrouble) {
296 return false; // findBlocks() already throws an exception
297 }
298 $this->blockinner[$parents[0]][] = $blockname;
299 $this->blocklist[$parents[0]] = preg_replace(
300 '@' . $this->openingDelimiter . $placeholder .
301 $this->closingDelimiter . '@',
302
303 $this->openingDelimiter . '__' . $blockname . '__' .
304 $this->closingDelimiter,
305
306 $this->blocklist[$parents[0]]
307 );
308
309 $this->deleteFromBlockvariablelist($parents[0], $placeholder);
310 $this->updateBlockvariablelist($blockname);
311
312 return true;
313 } // end func addBlock
updateBlockvariablelist($block)
Updates the variable list of a block.
Definition: ITX.php:746
findPlaceholderBlocks($variable)
Returns an array of blocknames where the given variable placeholder is used.
Definition: ITX.php:783
deleteFromBlockvariablelist($block, $variables)
Deletes one or many variables from the block variable list.
Definition: ITX.php:726
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:874

References HTML_Template_IT\$template, deleteFromBlockvariablelist(), HTML_Template_IT\findBlocks(), findPlaceholderBlocks(), and updateBlockvariablelist().

Referenced by addBlockfile(), and ilTemplate\addBlockFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

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

Definition at line 325 of file ITX.php.

326 {
327 return $this->addBlock($placeholder, $blockname, $this->getFile($filename));
328 } // end func addBlockfile
$filename
Definition: buildRTE.php:89
addBlock($placeholder, $blockname, $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
Definition: ITX.php:248
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:925

References $filename, addBlock(), and HTML_Template_IT\getFile().

+ Here is the call graph for this function:

◆ blockExists()

HTML_Template_ITX::blockExists (   $blockname)

Checks wheter a block exists.

Parameters
string
Returns
boolean @access public
See also
getBlocklist()

Reimplemented in ilTemplate, and ilTemplate.

Definition at line 578 of file ITX.php.

579 {
580 return isset($this->blocklist[$blockname]);
581 } // end func blockExists

◆ BlockvariableExists()

HTML_Template_ITX::BlockvariableExists (   $block,
  $variable 
)

Checks wheter a block variable exists.

Parameters
stringBlockname
stringVariablename
Returns
boolean @access public
See also
getBlockvariables()

Definition at line 614 of file ITX.php.

615 {
616 return isset($this->blockvariables[$block][$variable]);
617 } // end func BlockvariableExists

◆ buildFunctionlist()

HTML_Template_ITX::buildFunctionlist ( )

Builds a functionlist from the template.

@access private

Definition at line 623 of file ITX.php.

624 {
625 $this->functions = array();
626
628 $num = 0;
629
630 while (preg_match($this->functionRegExp, $template, $regs)) {
631
632 $pos = strpos($template, $regs[0]);
633 $template = substr($template, $pos + strlen($regs[0]));
634
635 $head = $this->getValue($template, ')');
636 $args = array();
637
638 $search = $regs[0] . $head . ')';
639
640 $replace = $this->openingDelimiter .
641 '__function' . $num . '__' .
643
644 $this->template = str_replace($search, $replace, $this->template);
645 $template = str_replace($search, $replace, $template);
646
647 while ($head != '' && $args2 = $this->getValue($head, ',')) {
648 $arg2 = trim($args2);
649 $args[] = ('"' == $arg2{0} || "'" == $arg2{0}) ?
650 substr($arg2, 1, -1) : $arg2;
651 if ($arg2 == $head) {
652 break;
653 }
654 $head = substr($head, strlen($arg2) + 1);
655 }
656
657 $this->functions[$num++] = array(
658 'name' => $regs[1],
659 'args' => $args
660 );
661 }
662
663 } // end func buildFunctionlist
getValue($code, $delimiter)
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " ...
Definition: ITX.php:675

References HTML_Template_IT\$closingDelimiter, HTML_Template_IT\$template, and getValue().

Referenced by init(), and ilTemplate\init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteFromBlockvariablelist()

HTML_Template_ITX::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. @access private

Definition at line 726 of file ITX.php.

727 {
728 if (!is_array($variables)) {
729 $variables = array($variables => true);
730 }
731
732 reset($this->blockvariables[$block]);
733 while (list($varname, $val) = each($this->blockvariables[$block])) {
734 if (isset($variables[$varname])) {
735 unset($this->blockvariables[$block][$varname]);
736 }
737 }
738 } // end deleteFromBlockvariablelist

Referenced by addBlock().

+ Here is the caller graph for this function:

◆ findPlaceholderBlocks()

HTML_Template_ITX::findPlaceholderBlocks (   $variable)

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

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

Definition at line 783 of file ITX.php.

784 {
785 $parents = array();
786 reset($this->blocklist);
787 while (list($blockname, $content) = each($this->blocklist)) {
788 reset($this->blockvariables[$blockname]);
789 while (
790 list($varname, $val) = each($this->blockvariables[$blockname]))
791 {
792 if ($variable == $varname) {
793 $parents[] = $blockname;
794 }
795 }
796 }
797
798 return $parents;
799 } // end func findPlaceholderBlocks

Referenced by addBlock().

+ Here is the caller graph for this function:

◆ getBlocklist()

HTML_Template_ITX::getBlocklist ( )

Returns a list of blocknames in the template.

Returns
array [blockname => blockname] @access public
See also
blockExists()

Definition at line 560 of file ITX.php.

561 {
562 $blocklist = array();
563 foreach ($this->blocklist as $block => $content) {
564 $blocklist[$block] = $block;
565 }
566
567 return $blocklist;
568 } // end func getBlocklist

References HTML_Template_IT\$blocklist.

◆ getBlockvariables()

HTML_Template_ITX::getBlockvariables (   $block)

Returns a list of variables of a block.

Parameters
stringBlockname
Returns
array [varname => varname] @access public
See also
BlockvariableExists()

Definition at line 591 of file ITX.php.

592 {
593 if (!isset($this->blockvariables[$block])) {
594 return array();
595 }
596
597 $variables = array();
598 foreach ($this->blockvariables[$block] as $variable => $v) {
599 $variables[$variable] = $variable;
600 }
601
602 return $variables;
603 } // end func getBlockvariables

◆ getFunctioncalls()

HTML_Template_ITX::getFunctioncalls ( )

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

Returns
array @access public

Definition at line 431 of file ITX.php.

432 {
433 return $this->functions;
434 } // end func getFunctioncalls

References $functions.

◆ getValue()

HTML_Template_ITX::getValue (   $code,
  $delimiter 
)

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

@access private

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

Definition at line 675 of file ITX.php.

675 {
676 if ($code == '') {
677 return '';
678 }
679
680 if (!is_array($delimiter)) {
681 $delimiter = array( $delimiter => true );
682 }
683
684 $len = strlen($code);
685 $enclosed = false;
686 $enclosed_by = '';
687
688 if (isset($delimiter[$code[0]])) {
689 $i = 1;
690 } else {
691 for ($i = 0; $i < $len; ++$i) {
692 $char = $code[$i];
693
694 if (
695 ($char == '"' || $char == "'") &&
696 ($char == $enclosed_by || '' == $enclosed_by) &&
697 (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
698 ) {
699
700 if (!$enclosed) {
701 $enclosed_by = $char;
702 } else {
703 $enclosed_by = "";
704 }
705 $enclosed = !$enclosed;
706
707 }
708
709 if (!$enclosed && isset($delimiter[$char])) {
710 break;
711 }
712 }
713 }
714
715 return substr($code, 0, $i);
716 } // end func getValue
$code
Definition: example_050.php:99

References $code.

Referenced by buildFunctionlist().

+ Here is the caller graph for this function:

◆ HTML_Template_ITX()

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.

See also
HTML_Template_IT()

Definition at line 118 of file ITX.php.

119 {
120
121 $this->checkblocknameRegExp = '@' . $this->blocknameRegExp . '@';
122 $this->functionRegExp = '@' . $this->functionPrefix . '(' .
123 $this->functionnameRegExp . ')\s*\‍(@sm';
124
125 $this->HTML_Template_IT($root);
126 } // end func constructor
HTML_Template_IT($root='', $options=null)
Builds some complex regular expressions and optinally sets the file root directory.
Definition: IT.php:370

References HTML_Template_IT\HTML_Template_IT().

Referenced by ilTemplateX\callConstructor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

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.

@access public

See also
free()

Reimplemented from HTML_Template_IT.

Reimplemented in ilTemplate.

Definition at line 128 of file ITX.php.

129 {
130 $this->free();
131 $this->buildFunctionlist();
132 $this->findBlocks($this->template);
133 // we don't need it any more
134 $this->template = '';
135 $this->buildBlockvariablelist();
136
137 } // end func init
buildFunctionlist()
Builds a functionlist from the template.
Definition: ITX.php:623
free()
Clears all datafields of the object.
Definition: IT.php:730
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:833

References HTML_Template_IT\buildBlockvariablelist(), buildFunctionlist(), HTML_Template_IT\findBlocks(), and HTML_Template_IT\free().

+ Here is the call graph for this function:

◆ performCallback()

HTML_Template_ITX::performCallback ( )

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

@access public

Definition at line 392 of file ITX.php.

393 {
394 reset($this->functions);
395 while (list($func_id, $function) = each($this->functions)) {
396 if (isset($this->callback[$function['name']])) {
397 if ($this->callback[$function['name']]['expandParameters']) {
398 $callFunction = 'call_user_func_array';
399 } else {
400 $callFunction = 'call_user_func';
401 }
402
403 if ($this->callback[$function['name']]['object'] != '') {
404 $call =
405 $callFunction(
406 array(
407 &$GLOBALS[$this->callback[$function['name']]['object']],
408 $this->callback[$function['name']]['function']),
409 $function['args']
410 );
411
412 } else {
413 $call =
414 $callFunction(
415 $this->callback[$function['name']]['function'],
416 $function['args']
417 );
418 }
419 $this->variableCache['__function' . $func_id . '__'] = $call;
420 }
421 }
422
423 } // end func performCallback
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

References $GLOBALS.

◆ placeholderExists()

HTML_Template_ITX::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_Error@access public

Definition at line 344 of file ITX.php.

345 {
346 if ($placeholder == '') {
347 new IT_Error('No placeholder name given.', __FILE__, __LINE__);
348 return '';
349 }
350
351 if ($block != '' && !isset($this->blocklist[$block])) {
352 new IT_Error("Unknown block '$block'.", __FILE__, __LINE__);
353 return '';
354 }
355
356 // name of the block where the given placeholder was found
357 $found = '';
358
359 if ($block != '') {
360 if (is_array($variables = $this->blockvariables[$block])) {
361 // search the value in the list of blockvariables
362 reset($variables);
363 while (list($k, $variable) = each($variables)) {
364 if ($k == $placeholder) {
365 $found = $block;
366 break;
367 }
368 }
369 }
370 } else {
371
372 // search all blocks and return the name of the first block that
373 // contains the placeholder
374 reset($this->blockvariables);
375 while (list($blockname, $variables) = each($this->blockvariables)){
376 if (is_array($variables) && isset($variables[$placeholder])) {
377 $found = $blockname;
378 break;
379 }
380 }
381 }
382
383 return $found;
384 } // end func placeholderExists

◆ removeBlockData()

HTML_Template_ITX::removeBlockData (   $block)

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

Parameters
stringblock to be removed @access private

Definition at line 536 of file ITX.php.

537 {
538 if (isset($this->blockinner[$block])) {
539 foreach ($this->blockinner[$block] as $k => $inner) {
540 $this->removeBlockData($inner);
541 }
542
543 unset($this->blockinner[$block]);
544 }
545
546 unset($this->blocklist[$block]);
547 unset($this->blockdata[$block]);
548 unset($this->blockvariables[$block]);
549 unset($this->touchedBlocks[$block]);
550
551 } // end func removeBlockinner
removeBlockData($block)
Recursively removes all data assiciated with a block, including all inner blocks.
Definition: ITX.php:536

References removeBlockData().

Referenced by removeBlockData(), and replaceBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

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() @access User interface

Definition at line 164 of file ITX.php.

165 {
166 if (!isset($this->blocklist[$block])) {
167 return new IT_Error(
168 "The block "."'$block'".
169 " does not exist in the template and thus it can't be replaced.",
170 __FILE__, __LINE__
171 );
172 }
173
174 if ($template == '') {
175 return new IT_Error('No block content given.', __FILE__, __LINE__);
176 }
177
178 if ($keep_content) {
179 $blockdata = $this->blockdata[$block];
180 }
181
182 // remove all kinds of links to the block / data of the block
183 $this->removeBlockData($block);
184
185 $template = "<!-- BEGIN $block -->" . $template . "<!-- END $block -->";
186 $parents = $this->blockparents[$block];
187 $this->findBlocks($template);
188 $this->blockparents[$block] = $parents;
189
190 // KLUDGE: rebuild the list for all block - could be done faster
191 $this->buildBlockvariablelist();
192
193 if ($keep_content) {
194 $this->blockdata[$block] = $blockdata;
195 }
196
197 // old TODO - I'm not sure if we need this
198 // update caches
199
200 return true;
201 } // end func replaceBlock

References HTML_Template_IT\$blockdata, HTML_Template_IT\$template, HTML_Template_IT\buildBlockvariablelist(), HTML_Template_IT\findBlocks(), and removeBlockData().

Referenced by replaceBlockfile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceBlockfile()

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

Replaces an existing block with new content from a file.

@brother replaceBlock()

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

Definition at line 212 of file ITX.php.

213 {
214 return $this->replaceBlock($block, $this->getFile($filename), $keep_content);
215 } // end func replaceBlockfile
replaceBlock($block, $template, $keep_content=false)
Replaces an existing block with new content.
Definition: ITX.php:164

References $filename, HTML_Template_IT\getFile(), and replaceBlock().

+ Here is the call graph for this function:

◆ setCallbackFunction()

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('

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_Error@access public
Deprecated:
The $callbackobject parameter is depricated since version 1.2 and might be dropped in further versions.

Definition at line 496 of file ITX.php.

497 {
498 if ($tplfunction == '' || $callbackfunction == '') {
499 return new IT_Error(
500 "No template function "."('$tplfunction')".
501 " and/or no callback function ('$callback') given.",
502 __FILE__, __LINE__
503 );
504 }
505 $this->callback[$tplfunction] = array(
506 'function' => $callbackfunction,
507 'object' => $callbackobject,
508 'expandParameters' => (boolean) $expandCallbackParameters
509 );
510
511 return true;
512 } // end func setCallbackFunction

◆ setCallbackFuntiontable()

HTML_Template_ITX::setCallbackFuntiontable (   $functions)

Sets the Callback function lookup table.

Parameters
arrayfunction table array[templatefunction] = array( "function" => userfunction, "object" => userobject ) @access public

Definition at line 525 of file ITX.php.

526 {
527 $this->callback = $functions;
528 } // end func setCallbackFunctiontable

References $functions.

◆ setFunctioncontent()

HTML_Template_ITX::setFunctioncontent (   $functionID,
  $replacement 
)

Replaces a function call with the given replacement.

Parameters
intFunction ID
stringReplacement
Deprecated:

Definition at line 443 of file ITX.php.

444 {
445 $this->variableCache['__function' . $functionID . '__'] = $replacement;
446 } // end func setFunctioncontent

◆ updateBlockvariablelist()

HTML_Template_ITX::updateBlockvariablelist (   $block)

Updates the variable list of a block.

Parameters
stringBlockname @access private

Definition at line 746 of file ITX.php.

747 {
748 preg_match_all( $this->variablesRegExp,
749 $this->blocklist[$block], $regs
750 );
751
752 if (count($regs[1]) != 0) {
753 foreach ($regs[1] as $k => $var) {
754 $this->blockvariables[$block][$var] = true;
755 }
756 } else {
757 $this->blockvariables[$block] = array();
758 }
759
760 // check if any inner blocks were found
761 if (isset($this->blockinner[$block]) &&
762 is_array($this->blockinner[$block]) &&
763 count($this->blockinner[$block]) > 0
764 ) {
765 /*
766 * loop through inner blocks, registering the variable
767 * placeholders in each
768 */
769 foreach ($this->blockinner[$block] as $childBlock) {
770 $this->updateBlockvariablelist($childBlock);
771 }
772 }
773 } // end func updateBlockvariablelist

References updateBlockvariablelist().

Referenced by addBlock(), and updateBlockvariablelist().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ warning()

HTML_Template_ITX::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 @access private

Definition at line 811 of file ITX.php.

812 {
813 $message = sprintf(
814 'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
815 $message,
816 $file,
817 $line
818 );
819
820 $this->warn[] = $message;
821
822 if ($this->printWarning) {
823 print $message;
824 }
825
826 if ($this->haltOnWarning) {
827 die($message);
828 }
829 } // end func warning
print $file
if(! $in) print

References $file, and print.

Field Documentation

◆ $callback

HTML_Template_ITX::$callback = array()

Definition at line 107 of file ITX.php.

◆ $checkblocknameRegExp

HTML_Template_ITX::$checkblocknameRegExp = ''

Definition at line 71 of file ITX.php.

◆ $functionnameRegExp

HTML_Template_ITX::$functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*'

Definition at line 83 of file ITX.php.

◆ $functionPrefix

HTML_Template_ITX::$functionPrefix = 'func_'

Definition at line 77 of file ITX.php.

◆ $functionRegExp

HTML_Template_ITX::$functionRegExp = ''

Definition at line 93 of file ITX.php.

◆ $functions

HTML_Template_ITX::$functions = array()

Definition at line 100 of file ITX.php.

Referenced by getFunctioncalls(), and setCallbackFuntiontable().

◆ $haltOnWarning

HTML_Template_ITX::$haltOnWarning = false

Definition at line 65 of file ITX.php.

◆ $printWarning

HTML_Template_ITX::$printWarning = false

Definition at line 57 of file ITX.php.

◆ $warn

HTML_Template_ITX::$warn = array()

Definition at line 49 of file ITX.php.


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