ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HTML_Template_ITX Class Reference
+ Inheritance diagram for HTML_Template_ITX:
+ Collaboration diagram for HTML_Template_ITX:

Public Member Functions

 __construct ($root='')
 Builds some complex regexps and calls the constructor of the parent class. More...
 
 init ()
 
 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
 __construct ($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 39 of file ITX.php.

Constructor & Destructor Documentation

◆ __construct()

HTML_Template_ITX::__construct (   $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 116 of file ITX.php.

References $root.

117  {
118  $this->checkblocknameRegExp = '@' . $this->blocknameRegExp . '@';
119  $this->functionRegExp = '@' . $this->functionPrefix . '(' .
120  $this->functionnameRegExp . ')\s*\(@sm';
121 
122  parent::__construct($root);
123  } // end func constructor
$root
Definition: sabredav.php:45

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
ilTemplateException
See also
addBlockfile() User interface

Definition at line 241 of file ITX.php.

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

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

242  {
243  // Don't trust any user even if it's a programmer or yourself...
244  if ($placeholder == '') {
245  throw (new ilTemplateException('No variable placeholder given.'));
246  } elseif ($blockname == '' ||
247  !preg_match($this->checkblocknameRegExp, $blockname)
248  ) {
249  throw (new ilTemplateException("No or invalid blockname '$blockname' given."));
250  } elseif ($template == '') {
251  throw (new ilTemplateException('No block content given.'));
252  } elseif (isset($this->blocklist[$blockname])) {
253  throw (new ilTemplateException('The block ' . $blockname . ' already exists.'));
254  }
255 
256  // find out where to insert the new block
257  $parents = $this->findPlaceholderBlocks($placeholder);
258  if (count($parents) == 0) {
259  throw (new ilTemplateException("The variable placeholder" .
260  " '$placeholder' was not found in the template."));
261  return;
262  } elseif (count($parents) > 1) {
263  reset($parents);
264  foreach ($parents as $k => $parent) {
265  $msg .= "$parent, ";
266  }
267  $msg = substr($parent, -2);
268  throw (new ilTemplateException("The variable placeholder " . "'$placeholder'" .
269  " must be unique, found in multiple blocks '$msg'."));
270  }
271 
272  $template = "<!-- BEGIN $blockname -->" . $template . "<!-- END $blockname -->";
273  $this->findBlocks($template);
274  if ($this->flagBlocktrouble) {
275  return false; // findBlocks() already throws an exception
276  }
277  $this->blockinner[$parents[0]][] = $blockname;
278  $this->blocklist[$parents[0]] = preg_replace(
279  '@' . $this->openingDelimiter . $placeholder .
280  $this->closingDelimiter . '@',
281  $this->openingDelimiter . '__' . $blockname . '__' .
282  $this->closingDelimiter,
283  $this->blocklist[$parents[0]]
284  );
285 
286  $this->deleteFromBlockvariablelist($parents[0], $placeholder);
287  $this->updateBlockvariablelist($blockname);
288 
289  return true;
290  } // end func addBlock
deleteFromBlockvariablelist($block, $variables)
Deletes one or many variables from the block variable list.
Definition: ITX.php:691
findPlaceholderBlocks($variable)
Returns an array of blocknames where the given variable placeholder is used.
Definition: ITX.php:750
updateBlockvariablelist($block)
Updates the variable list of a block.
Definition: ITX.php:711
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:863
+ 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 addBlock() public

Definition at line 302 of file ITX.php.

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

303  {
304  return $this->addBlock($placeholder, $blockname, $this->getFile($filename));
305  } // end func addBlockfile
addBlock($placeholder, $blockname, $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
Definition: ITX.php:241
$filename
Definition: buildRTE.php:89
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:912
+ Here is the call graph for this function:

◆ blockExists()

HTML_Template_ITX::blockExists (   $blockname)

Checks wheter a block exists.

Parameters
string
Returns
boolean public
See also
getBlocklist()

Definition at line 546 of file ITX.php.

547  {
548  return isset($this->blocklist[$blockname]);
549  } // end func blockExists

◆ BlockvariableExists()

HTML_Template_ITX::BlockvariableExists (   $block,
  $variable 
)

Checks wheter a block variable exists.

Parameters
stringBlockname
stringVariablename
Returns
boolean public
See also
getBlockvariables()

Definition at line 582 of file ITX.php.

583  {
584  return isset($this->blockvariables[$block][$variable]);
585  } // end func BlockvariableExists

◆ buildFunctionlist()

HTML_Template_ITX::buildFunctionlist ( )

Builds a functionlist from the template.

private

Definition at line 591 of file ITX.php.

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

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

592  {
593  $this->functions = array();
594 
596  $num = 0;
597 
598  while (preg_match($this->functionRegExp, $template, $regs)) {
599  $pos = strpos($template, $regs[0]);
600  $template = substr($template, $pos + strlen($regs[0]));
601 
602  $head = $this->getValue($template, ')');
603  $args = array();
604 
605  $search = $regs[0] . $head . ')';
606 
607  $replace = $this->openingDelimiter .
608  '__function' . $num . '__' .
610 
611  $this->template = str_replace($search, $replace, $this->template);
612  $template = str_replace($search, $replace, $template);
613 
614  while ($head != '' && $args2 = $this->getValue($head, ',')) {
615  $arg2 = trim($args2);
616  $args[] = ('"' == $arg2[0] || "'" == $arg2[0]) ?
617  substr($arg2, 1, -1) : $arg2;
618  if ($arg2 == $head) {
619  break;
620  }
621  $head = substr($head, strlen($arg2) + 1);
622  }
623 
624  $this->functions[$num++] = array(
625  'name' => $regs[1],
626  'args' => $args
627  );
628  }
629  } // end func buildFunctionlist
getValue($code, $delimiter)
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " ...
Definition: ITX.php:641
+ 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. private

Definition at line 691 of file ITX.php.

Referenced by addBlock().

692  {
693  if (!is_array($variables)) {
694  $variables = array($variables => true);
695  }
696 
697  reset($this->blockvariables[$block]);
698  foreach ($this->blockvariables[$block] as $varname => $val) {
699  if (isset($variables[$varname])) {
700  unset($this->blockvariables[$block][$varname]);
701  }
702  }
703  } // end deleteFromBlockvariablelist
+ 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 public

Definition at line 750 of file ITX.php.

Referenced by addBlock().

751  {
752  $parents = array();
753  reset($this->blocklist);
754  foreach ($this->blocklist as $blockname => $content) {
755  reset($this->blockvariables[$blockname]);
756  foreach ($this->blockvariables[$blockname] as $varname => $val) {
757  if ($variable == $varname) {
758  $parents[] = $blockname;
759  }
760  }
761  }
762 
763  return $parents;
764  } // end func findPlaceholderBlocks
+ 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] public
See also
blockExists()

Definition at line 528 of file ITX.php.

References HTML_Template_IT\$blocklist.

529  {
530  $blocklist = array();
531  foreach ($this->blocklist as $block => $content) {
532  $blocklist[$block] = $block;
533  }
534 
535  return $blocklist;
536  } // end func getBlocklist

◆ getBlockvariables()

HTML_Template_ITX::getBlockvariables (   $block)

Returns a list of variables of a block.

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

Definition at line 559 of file ITX.php.

560  {
561  if (!isset($this->blockvariables[$block])) {
562  return array();
563  }
564 
565  $variables = array();
566  foreach ($this->blockvariables[$block] as $variable => $v) {
567  $variables[$variable] = $variable;
568  }
569 
570  return $variables;
571  } // end func getBlockvariables

◆ getFunctioncalls()

HTML_Template_ITX::getFunctioncalls ( )

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

Returns
array public

Definition at line 404 of file ITX.php.

References $functions.

405  {
406  return $this->functions;
407  } // end func getFunctioncalls

◆ getValue()

HTML_Template_ITX::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()

Definition at line 641 of file ITX.php.

References $code, $delimiter, and $i.

Referenced by buildFunctionlist().

642  {
643  if ($code == '') {
644  return '';
645  }
646 
647  if (!is_array($delimiter)) {
648  $delimiter = array( $delimiter => true );
649  }
650 
651  $len = strlen($code);
652  $enclosed = false;
653  $enclosed_by = '';
654 
655  if (isset($delimiter[$code[0]])) {
656  $i = 1;
657  } else {
658  for ($i = 0; $i < $len; ++$i) {
659  $char = $code[$i];
660 
661  if (
662  ($char == '"' || $char == "'") &&
663  ($char == $enclosed_by || '' == $enclosed_by) &&
664  (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
665  ) {
666  if (!$enclosed) {
667  $enclosed_by = $char;
668  } else {
669  $enclosed_by = "";
670  }
671  $enclosed = !$enclosed;
672  }
673 
674  if (!$enclosed && isset($delimiter[$char])) {
675  break;
676  }
677  }
678  }
679 
680  return substr($code, 0, $i);
681  } // end func getValue
$delimiter
Definition: showstats.php:16
$code
Definition: example_050.php:99
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ init()

HTML_Template_ITX::init ( )

Definition at line 125 of file ITX.php.

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

126  {
127  $this->free();
128  $this->buildFunctionlist();
129  $this->findBlocks($this->template);
130  // we don't need it any more
131  $this->template = '';
132  $this->buildBlockvariablelist();
133  } // end func init
free()
Clears all datafields of the object.
Definition: IT.php:714
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:822
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:863
buildFunctionlist()
Builds a functionlist from the template.
Definition: ITX.php:591
+ 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.

public

Definition at line 367 of file ITX.php.

References $GLOBALS.

368  {
369  reset($this->functions);
370  foreach ($this->functions as $func_id => $function) {
371  if (isset($this->callback[$function['name']])) {
372  if ($this->callback[$function['name']]['expandParameters']) {
373  $callFunction = 'call_user_func_array';
374  } else {
375  $callFunction = 'call_user_func';
376  }
377 
378  if ($this->callback[$function['name']]['object'] != '') {
379  $call =
380  $callFunction(
381  array(
382  &$GLOBALS[$this->callback[$function['name']]['object']],
383  $this->callback[$function['name']]['function']),
384  $function['args']
385  );
386  } else {
387  $call =
388  $callFunction(
389  $this->callback[$function['name']]['function'],
390  $function['args']
391  );
392  }
393  $this->variableCache['__function' . $func_id . '__'] = $call;
394  }
395  }
396  } // end func performCallback
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.

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

Definition at line 321 of file ITX.php.

322  {
323  if ($placeholder == '') {
324  throw (new ilTemplateException('No placeholder name given.'));
325  }
326 
327  if ($block != '' && !isset($this->blocklist[$block])) {
328  throw (new ilTemplateException("Unknown block '$block'."));
329  }
330 
331  // name of the block where the given placeholder was found
332  $found = '';
333 
334  if ($block != '') {
335  if (is_array($variables = $this->blockvariables[$block])) {
336  // search the value in the list of blockvariables
337  reset($variables);
338  foreach ($variables as $k => $variable) {
339  if ($k == $placeholder) {
340  $found = $block;
341  break;
342  }
343  }
344  }
345  } else {
346 
347  // search all blocks and return the name of the first block that
348  // contains the placeholder
349  reset($this->blockvariables);
350  foreach ($this->blockvariables as $blockname => $variables) {
351  if (is_array($variables) && isset($variables[$placeholder])) {
352  $found = $blockname;
353  break;
354  }
355  }
356  }
357 
358  return $found;
359  } // 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 private

Definition at line 505 of file ITX.php.

Referenced by replaceBlock().

506  {
507  if (isset($this->blockinner[$block])) {
508  foreach ($this->blockinner[$block] as $k => $inner) {
509  $this->removeBlockData($inner);
510  }
511 
512  unset($this->blockinner[$block]);
513  }
514 
515  unset($this->blocklist[$block]);
516  unset($this->blockdata[$block]);
517  unset($this->blockvariables[$block]);
518  unset($this->touchedBlocks[$block]);
519  } // end func removeBlockinner
removeBlockData($block)
Recursively removes all data assiciated with a block, including all inner blocks. ...
Definition: ITX.php:505
+ 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
ilTemplateException
See also
replaceBlockfile(), addBlock(), addBlockfile() User interface

Definition at line 160 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().

161  {
162  if (!isset($this->blocklist[$block])) {
163  throw (new ilTemplateException("The block " . "'$block'" .
164  " does not exist in the template and thus it can't be replaced."));
165  }
166 
167  if ($template == '') {
168  throw (new ilTemplateException('No block content given.'));
169  }
170 
171  if ($keep_content) {
172  $blockdata = $this->blockdata[$block];
173  }
174 
175  // remove all kinds of links to the block / data of the block
176  $this->removeBlockData($block);
177 
178  $template = "<!-- BEGIN $block -->" . $template . "<!-- END $block -->";
179  $parents = $this->blockparents[$block];
180  $this->findBlocks($template);
181  $this->blockparents[$block] = $parents;
182 
183  // KLUDGE: rebuild the list for all block - could be done faster
184  $this->buildBlockvariablelist();
185 
186  if ($keep_content) {
187  $this->blockdata[$block] = $blockdata;
188  }
189 
190  // old TODO - I'm not sure if we need this
191  // update caches
192 
193  return true;
194  } // end func replaceBlock
removeBlockData($block)
Recursively removes all data assiciated with a block, including all inner blocks. ...
Definition: ITX.php:505
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:822
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:863
+ 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.

replaceBlock()

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

Definition at line 205 of file ITX.php.

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

206  {
207  return $this->replaceBlock($block, $this->getFile($filename), $keep_content);
208  } // end func replaceBlockfile
$filename
Definition: buildRTE.php:89
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:912
replaceBlock($block, $template, $keep_content=false)
Replaces an existing block with new content.
Definition: ITX.php:160
+ 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
ilTemplateExceptionpublic
Deprecated:
The $callbackobject parameter is depricated since version 1.2 and might be dropped in further versions.

Definition at line 468 of file ITX.php.

469  {
470  if ($tplfunction == '' || $callbackfunction == '') {
471  throw (new ilTemplateException("No template function " . "('$tplfunction')" .
472  " and/or no callback function ('$callbackfunction') given."));
473  }
474  $this->callback[$tplfunction] = array(
475  'function' => $callbackfunction,
476  'object' => $callbackobject,
477  'expandParameters' => (boolean) $expandCallbackParameters
478  );
479 
480  return true;
481  } // 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 ) public

Definition at line 494 of file ITX.php.

References $functions.

495  {
496  $this->callback = $functions;
497  } // end func setCallbackFunctiontable

◆ setFunctioncontent()

HTML_Template_ITX::setFunctioncontent (   $functionID,
  $replacement 
)

Replaces a function call with the given replacement.

Parameters
intFunction ID
stringReplacement
Deprecated:

Definition at line 416 of file ITX.php.

417  {
418  $this->variableCache['__function' . $functionID . '__'] = $replacement;
419  } // end func setFunctioncontent

◆ updateBlockvariablelist()

HTML_Template_ITX::updateBlockvariablelist (   $block)

Updates the variable list of a block.

Parameters
stringBlockname private

Definition at line 711 of file ITX.php.

Referenced by addBlock().

712  {
713  preg_match_all(
714  $this->variablesRegExp,
715  $this->blocklist[$block],
716  $regs
717  );
718 
719  if (count($regs[1]) != 0) {
720  foreach ($regs[1] as $k => $var) {
721  $this->blockvariables[$block][$var] = true;
722  }
723  } else {
724  $this->blockvariables[$block] = array();
725  }
726 
727  // check if any inner blocks were found
728  if (isset($this->blockinner[$block]) &&
729  is_array($this->blockinner[$block]) &&
730  count($this->blockinner[$block]) > 0
731  ) {
732  /*
733  * loop through inner blocks, registering the variable
734  * placeholders in each
735  */
736  foreach ($this->blockinner[$block] as $childBlock) {
737  $this->updateBlockvariablelist($childBlock);
738  }
739  }
740  } // end func updateBlockvariablelist
updateBlockvariablelist($block)
Updates the variable list of a block.
Definition: ITX.php:711
+ 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 private

Definition at line 776 of file ITX.php.

References $message.

777  {
778  $message = sprintf(
779  'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
780  $message,
781  $file,
782  $line
783  );
784 
785  $this->warn[] = $message;
786 
787  if ($this->printWarning) {
788  print $message;
789  }
790 
791  if ($this->haltOnWarning) {
792  die($message);
793  }
794  } // end func warning
catch(Exception $e) $message

Field Documentation

◆ $callback

HTML_Template_ITX::$callback = array()

Definition at line 105 of file ITX.php.

◆ $checkblocknameRegExp

HTML_Template_ITX::$checkblocknameRegExp = ''

Definition at line 69 of file ITX.php.

◆ $functionnameRegExp

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

Definition at line 81 of file ITX.php.

◆ $functionPrefix

HTML_Template_ITX::$functionPrefix = 'func_'

Definition at line 75 of file ITX.php.

◆ $functionRegExp

HTML_Template_ITX::$functionRegExp = ''

Definition at line 91 of file ITX.php.

◆ $functions

HTML_Template_ITX::$functions = array()

Definition at line 98 of file ITX.php.

Referenced by getFunctioncalls(), and setCallbackFuntiontable().

◆ $haltOnWarning

HTML_Template_ITX::$haltOnWarning = false

Definition at line 63 of file ITX.php.

◆ $printWarning

HTML_Template_ITX::$printWarning = false

Definition at line 55 of file ITX.php.

◆ $warn

HTML_Template_ITX::$warn = array()

Definition at line 47 of file ITX.php.


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