ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

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

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 243 of file ITX.php.

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

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

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

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

308  {
309  return $this->addBlock($placeholder, $blockname, $this->getFile($filename));
310  } // end func addBlockfile
addBlock($placeholder, $blockname, $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
Definition: ITX.php:243
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:905
+ 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 555 of file ITX.php.

556  {
557  return isset($this->blocklist[$blockname]);
558  } // 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 591 of file ITX.php.

592  {
593  return isset($this->blockvariables[$block][$variable]);
594  } // end func BlockvariableExists

◆ buildFunctionlist()

HTML_Template_ITX::buildFunctionlist ( )

Builds a functionlist from the template.

private

Definition at line 600 of file ITX.php.

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

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

601  {
602  $this->functions = array();
603 
605  $num = 0;
606 
607  while (preg_match($this->functionRegExp, $template, $regs)) {
608 
609  $pos = strpos($template, $regs[0]);
610  $template = substr($template, $pos + strlen($regs[0]));
611 
612  $head = $this->getValue($template, ')');
613  $args = array();
614 
615  $search = $regs[0] . $head . ')';
616 
617  $replace = $this->openingDelimiter .
618  '__function' . $num . '__' .
620 
621  $this->template = str_replace($search, $replace, $this->template);
622  $template = str_replace($search, $replace, $template);
623 
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) {
629  break;
630  }
631  $head = substr($head, strlen($arg2) + 1);
632  }
633 
634  $this->functions[$num++] = array(
635  'name' => $regs[1],
636  'args' => $args
637  );
638  }
639 
640  } // end func buildFunctionlist
List implemented functions
getValue($code, $delimiter)
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " ...
Definition: ITX.php:652
Create styles array
The data for the language used.
+ 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 703 of file ITX.php.

References array.

Referenced by addBlock().

704  {
705  if (!is_array($variables)) {
706  $variables = array($variables => true);
707  }
708 
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]);
713  }
714  }
715  } // end deleteFromBlockvariablelist
Create styles array
The data for the language used.
+ 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 760 of file ITX.php.

References array.

Referenced by addBlock().

761  {
762  $parents = array();
763  reset($this->blocklist);
764  while (list($blockname, $content) = each($this->blocklist)) {
765  reset($this->blockvariables[$blockname]);
766  while (
767  list($varname, $val) = each($this->blockvariables[$blockname]))
768  {
769  if ($variable == $varname) {
770  $parents[] = $blockname;
771  }
772  }
773  }
774 
775  return $parents;
776  } // end func findPlaceholderBlocks
Create styles array
The data for the language used.
+ 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 537 of file ITX.php.

References HTML_Template_IT\$blocklist, and array.

538  {
539  $blocklist = array();
540  foreach ($this->blocklist as $block => $content) {
541  $blocklist[$block] = $block;
542  }
543 
544  return $blocklist;
545  } // end func getBlocklist
Create styles array
The data for the language used.

◆ 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 568 of file ITX.php.

References array.

569  {
570  if (!isset($this->blockvariables[$block])) {
571  return array();
572  }
573 
574  $variables = array();
575  foreach ($this->blockvariables[$block] as $variable => $v) {
576  $variables[$variable] = $variable;
577  }
578 
579  return $variables;
580  } // end func getBlockvariables
Create styles array
The data for the language used.

◆ getFunctioncalls()

HTML_Template_ITX::getFunctioncalls ( )

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

Returns
array public

Definition at line 411 of file ITX.php.

References $functions.

412  {
413  return $this->functions;
414  } // 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 652 of file ITX.php.

References $code, and array.

Referenced by buildFunctionlist().

652  {
653  if ($code == '') {
654  return '';
655  }
656 
657  if (!is_array($delimiter)) {
658  $delimiter = array( $delimiter => true );
659  }
660 
661  $len = strlen($code);
662  $enclosed = false;
663  $enclosed_by = '';
664 
665  if (isset($delimiter[$code[0]])) {
666  $i = 1;
667  } else {
668  for ($i = 0; $i < $len; ++$i) {
669  $char = $code[$i];
670 
671  if (
672  ($char == '"' || $char == "'") &&
673  ($char == $enclosed_by || '' == $enclosed_by) &&
674  (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
675  ) {
676 
677  if (!$enclosed) {
678  $enclosed_by = $char;
679  } else {
680  $enclosed_by = "";
681  }
682  $enclosed = !$enclosed;
683 
684  }
685 
686  if (!$enclosed && isset($delimiter[$char])) {
687  break;
688  }
689  }
690  }
691 
692  return substr($code, 0, $i);
693  } // end func getValue
$code
Definition: example_050.php:99
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ init()

HTML_Template_ITX::init ( )

Definition at line 126 of file ITX.php.

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

127  {
128  $this->free();
129  $this->buildFunctionlist();
130  $this->findBlocks($this->template);
131  // we don't need it any more
132  $this->template = '';
133  $this->buildBlockvariablelist();
134 
135  } // 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:817
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:858
buildFunctionlist()
Builds a functionlist from the template.
Definition: ITX.php:600
+ 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 372 of file ITX.php.

References $GLOBALS, array, and functions.

373  {
374  reset($this->functions);
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';
379  } else {
380  $callFunction = 'call_user_func';
381  }
382 
383  if ($this->callback[$function['name']]['object'] != '') {
384  $call =
385  $callFunction(
386  array(
387  &$GLOBALS[$this->callback[$function['name']]['object']],
388  $this->callback[$function['name']]['function']),
389  $function['args']
390  );
391 
392  } else {
393  $call =
394  $callFunction(
395  $this->callback[$function['name']]['function'],
396  $function['args']
397  );
398  }
399  $this->variableCache['__function' . $func_id . '__'] = $call;
400  }
401  }
402 
403  } // end func performCallback
List implemented functions
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Create styles array
The data for the language used.

◆ 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 326 of file ITX.php.

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

Referenced by replaceBlock().

514  {
515  if (isset($this->blockinner[$block])) {
516  foreach ($this->blockinner[$block] as $k => $inner) {
517  $this->removeBlockData($inner);
518  }
519 
520  unset($this->blockinner[$block]);
521  }
522 
523  unset($this->blocklist[$block]);
524  unset($this->blockdata[$block]);
525  unset($this->blockvariables[$block]);
526  unset($this->touchedBlocks[$block]);
527 
528  } // end func removeBlockinner
removeBlockData($block)
Recursively removes all data assiciated with a block, including all inner blocks. ...
Definition: ITX.php:513
+ 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 162 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().

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

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

208  {
209  return $this->replaceBlock($block, $this->getFile($filename), $keep_content);
210  } // end func replaceBlockfile
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:905
replaceBlock($block, $template, $keep_content=false)
Replaces an existing block with new content.
Definition: ITX.php:162
+ 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 476 of file ITX.php.

References array.

477  {
478  if ($tplfunction == '' || $callbackfunction == '') {
479  throw (new ilTemplateException("No template function "."('$tplfunction')".
480  " and/or no callback function ('$callbackfunction') given."));
481  }
482  $this->callback[$tplfunction] = array(
483  'function' => $callbackfunction,
484  'object' => $callbackobject,
485  'expandParameters' => (boolean) $expandCallbackParameters
486  );
487 
488  return true;
489  } // end func setCallbackFunction
Create styles array
The data for the language used.

◆ 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 502 of file ITX.php.

References $functions.

503  {
504  $this->callback = $functions;
505  } // 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 423 of file ITX.php.

424  {
425  $this->variableCache['__function' . $functionID . '__'] = $replacement;
426  } // end func setFunctioncontent

◆ updateBlockvariablelist()

HTML_Template_ITX::updateBlockvariablelist (   $block)

Updates the variable list of a block.

Parameters
stringBlockname private

Definition at line 723 of file ITX.php.

References array.

Referenced by addBlock().

724  {
725  preg_match_all( $this->variablesRegExp,
726  $this->blocklist[$block], $regs
727  );
728 
729  if (count($regs[1]) != 0) {
730  foreach ($regs[1] as $k => $var) {
731  $this->blockvariables[$block][$var] = true;
732  }
733  } else {
734  $this->blockvariables[$block] = array();
735  }
736 
737  // check if any inner blocks were found
738  if (isset($this->blockinner[$block]) &&
739  is_array($this->blockinner[$block]) &&
740  count($this->blockinner[$block]) > 0
741  ) {
742  /*
743  * loop through inner blocks, registering the variable
744  * placeholders in each
745  */
746  foreach ($this->blockinner[$block] as $childBlock) {
747  $this->updateBlockvariablelist($childBlock);
748  }
749  }
750  } // end func updateBlockvariablelist
Create styles array
The data for the language used.
updateBlockvariablelist($block)
Updates the variable list of a block.
Definition: ITX.php:723
+ 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 788 of file ITX.php.

References $file.

789  {
790  $message = sprintf(
791  'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
792  $message,
793  $file,
794  $line
795  );
796 
797  $this->warn[] = $message;
798 
799  if ($this->printWarning) {
800  print $message;
801  }
802 
803  if ($this->haltOnWarning) {
804  die($message);
805  }
806  } // end func warning
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

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: