ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
HTML_Template_IT Class Reference
+ Inheritance diagram for HTML_Template_IT:
+ Collaboration diagram for HTML_Template_IT:

Public Member Functions

 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

 $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 124 of file IT.php.

Member Function Documentation

◆ _addPregDelimiters()

HTML_Template_IT::_addPregDelimiters (   $str)

Adds delimiters to a string, so it can be used as a pattern in preg_* functions.

Parameters
string
Returns
string

Definition at line 944 of file IT.php.

945  {
946  return '@' . $str . '@';
947  }

◆ _preserveOpeningDelimiter()

HTML_Template_IT::_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string.

Parameters
string
Returns
string

Definition at line 955 of file IT.php.

956  {
957  return (false === strpos($str, $this->openingDelimiter))?
958  $str:
959  str_replace(
960  $this->openingDelimiter,
961  $this->openingDelimiter .
962  '%preserved%' . $this->closingDelimiter,
963  $str
964  );
965  }

◆ buildBlockvariablelist()

HTML_Template_IT::buildBlockvariablelist ( )

Build a list of all variables within of a block.

Definition at line 813 of file IT.php.

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

814  {
815  foreach ($this->blocklist as $name => $content) {
816  preg_match_all($this->variablesRegExp, $content, $regs);
817 
818  if (count($regs[1]) != 0) {
819  foreach ($regs[1] as $k => $var) {
820  $this->blockvariables[$name][$var] = true;
821  }
822  } else {
823  $this->blockvariables[$name] = array();
824  }
825  }
826  } // end func buildBlockvariablelist
+ Here is the caller graph for this function:

◆ errorMessage()

HTML_Template_IT::errorMessage (   $value,
  $blockname = '' 
)

Return a textual error message for a IT error code.

Parameters
integer$valueerror code
Returns
string error message, or false if the error code was not recognized

Definition at line 975 of file IT.php.

References PEAR\isError(), IT_BLOCK_DUPLICATE, IT_BLOCK_NOT_FOUND, IT_ERROR, IT_OK, IT_TPL_NOT_FOUND, and IT_UNKNOWN_OPTION.

Referenced by findBlocks(), get(), getFile(), parse(), setCurrentBlock(), setOption(), and touchBlock().

976  {
977  static $errorMessages;
978  if (!isset($errorMessages)) {
979  $errorMessages = array(
980  IT_OK => '',
981  IT_ERROR => 'unknown error',
982  IT_TPL_NOT_FOUND => 'Cannot read the template file',
983  IT_BLOCK_NOT_FOUND => 'Cannot find this block',
984  IT_BLOCK_DUPLICATE => 'The name of a block must be'.
985  ' uniquewithin a template.'.
986  ' Found "' . $blockname . '" twice.'.
987  'Unpredictable results '.
988  'may appear.',
989  IT_UNKNOWN_OPTION => 'Unknown option'
990  );
991  }
992 
993  if (PEAR::isError($value)) {
994  $value = $value->getCode();
995  }
996 
997  return isset($errorMessages[$value]) ?
998  $errorMessages[$value] : $errorMessages[IT_ERROR];
999  }
const IT_OK
Definition: IT.php:23
const IT_UNKNOWN_OPTION
Definition: IT.php:28
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
const IT_ERROR
Definition: IT.php:24
const IT_TPL_NOT_FOUND
Definition: IT.php:25
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findBlocks()

HTML_Template_IT::findBlocks (   $string)

Recusively builds a list of all blocks within the template.

Parameters
stringstring that gets scanned
See also
$blocklist

Definition at line 854 of file IT.php.

References $blocklist, errorMessage(), IT_BLOCK_DUPLICATE, and PEAR\raiseError().

Referenced by HTML_Template_ITX\addBlock(), HTML_Template_ITX\init(), ilTemplate\init(), init(), and HTML_Template_ITX\replaceBlock().

855  {
856  $blocklist = array();
857 
858  if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
859  foreach ($regs as $k => $match) {
860  $blockname = $match[1];
861  $blockcontent = $match[2];
862 
863  if (isset($this->blocklist[$blockname])) {
864  $this->err[] = PEAR::raiseError(
865  $this->errorMessage(
866  IT_BLOCK_DUPLICATE, $blockname),
868  );
869  $this->flagBlocktrouble = true;
870  }
871 
872  $this->blocklist[$blockname] = $blockcontent;
873  $this->blockdata[$blockname] = "";
874 
875  $blocklist[] = $blockname;
876 
877  $inner = $this->findBlocks($blockcontent);
878  foreach ($inner as $k => $name) {
879  $pattern = sprintf(
880  '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
881  $name,
882  $name
883  );
884 
885  $this->blocklist[$blockname] = preg_replace(
886  $pattern,
887  $this->openingDelimiter .
888  '__' . $name . '__' .
889  $this->closingDelimiter,
890  $this->blocklist[$blockname]
891  );
892  $this->blockinner[$blockname][] = $name;
893  $this->blockparents[$name] = $blockname;
894  }
895  }
896  }
897 
898  return $blocklist;
899  } // end func findBlocks
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:854
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free()

HTML_Template_IT::free ( )

Clears all datafields of the object.

Don't use this function unless you know what you're doing.

public

See also
init()

Definition at line 710 of file IT.php.

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

711  {
712  $this->err = array();
713 
714  $this->currentBlock = '__global__';
715 
716  $this->variableCache = array();
717  $this->blocklist = array();
718  $this->touchedBlocks = array();
719 
720  $this->flagBlocktrouble = false;
721  $this->flagGlobalParsed = false;
722  } // end func free
+ Here is the caller graph for this function:

◆ get()

HTML_Template_IT::get (   $block = '__global__')

Returns a block with all replacements done.

Parameters
stringname of the block
Returns
string
Exceptions
PEAR_Errorpublic
See also
show()

Definition at line 454 of file IT.php.

References $ret, errorMessage(), IT_BLOCK_NOT_FOUND, parse(), and PEAR\raiseError().

455  {
456  if ($block == '__global__' && !$this->flagGlobalParsed) {
457  $this->parse('__global__');
458  }
459 
460  if (!isset($this->blocklist[$block])) {
461  $this->err[] = PEAR::raiseError(
463  '"' . $block . "'",
465  );
466  return '';
467  }
468 
469  if (isset($this->blockdata[$block])) {
470  $ret = $this->blockdata[$block];
471  if ($this->clearCache) {
472  unset($this->blockdata[$block]);
473  }
474  if ($this->_options['preserve_data']) {
475  $ret = str_replace(
476  $this->openingDelimiter .
477  '%preserved%' . $this->closingDelimiter,
478  $this->openingDelimiter,
479  $ret
480  );
481  }
482  return $ret;
483  }
484 
485  return '';
486  } // end func get()
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:496
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ getFile()

HTML_Template_IT::getFile (   $filename)

Reads a file from disk and returns its content.

Parameters
stringFilename
Returns
string Filecontent

Definition at line 906 of file IT.php.

References $filename, errorMessage(), IT_TPL_NOT_FOUND, and PEAR\raiseError().

Referenced by HTML_Template_ITX\addBlockfile(), ilTemplate\addBlockFile(), loadTemplatefile(), ilTemplate\loadTemplatefile(), and HTML_Template_ITX\replaceBlockfile().

907  {
908  if ($filename{0} == '/' && substr($this->fileRoot, -1) == '/') {
909  $filename = substr($filename, 1);
910  }
911 
912  $filename = $this->fileRoot . $filename;
913 
914  if (!($fh = @fopen($filename, 'r'))) {
915  $this->err[] = PEAR::raiseError(
917  ': "' .$filename .'"',
919  );
920  return "";
921  }
922 
923  $fsize = filesize($filename);
924  if ($fsize < 1) {
925  fclose($fh);
926  return '';
927  }
928 
929  $content = fread($fh, $fsize);
930  fclose($fh);
931 
932  return preg_replace(
933  "#<!-- INCLUDE (.*) -->#ime", "\$this->getFile('\\1')", $content
934  );
935  } // end func getFile
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
$filename
Definition: buildRTE.php:89
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
const IT_TPL_NOT_FOUND
Definition: IT.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGlobalvariables()

HTML_Template_IT::getGlobalvariables ( )

Returns a list of all global variables.

Definition at line 831 of file IT.php.

832  {
833  $regs = array();
834  $values = array();
835 
836  foreach ($this->blockvariables['__global__'] as $allowedvar => $v) {
837  if (isset($this->variableCache[$allowedvar])) {
838  $regs[] = '@' . $this->openingDelimiter .
839  $allowedvar . $this->closingDelimiter . '@';
840  $values[] = $this->variableCache[$allowedvar];
841  unset($this->variableCache[$allowedvar]);
842  }
843  }
844 
845  return array($regs, $values);
846  } // end func getGlobalvariables

◆ HTML_Template_IT()

HTML_Template_IT::HTML_Template_IT (   $root = '',
  $options = null 
)

Builds some complex regular expressions and optinally sets the file root directory.

Make sure that you call this constructor if you derive your template class from this one.

Parameters
stringFile root directory, prefix for all filenames given to the object.
See also
setRoot()

Definition at line 370 of file IT.php.

References $options, setOptions(), and setRoot().

Referenced by HTML_Template_ITX\HTML_Template_ITX().

371  {
372  if (!is_null($options)) {
373  $this->setOptions($options);
374  }
375  $this->variablesRegExp = '@' . $this->openingDelimiter .
376  '(' . $this->variablenameRegExp . ')' .
377  $this->closingDelimiter . '@sm';
378  $this->removeVariablesRegExp = '@' . $this->openingDelimiter .
379  "\s*(" . $this->variablenameRegExp .
380  ")\s*" . $this->closingDelimiter .'@sm';
381 
382  $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp .
383  ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm';
384 
385  $this->setRoot($root);
386  } // end constructor
setOptions($options)
Sets the options for the template class.
Definition: IT.php:422
if(!is_array($argv)) $options
setRoot($root)
Sets the file root.
Definition: IT.php:801
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

HTML_Template_IT::init ( )

Clears all datafields of the object and rebuild the internal blocklist.

LoadTemplatefile() and setTemplate() automatically call this function when a new template is given. Don't use this function unless you know what you're doing.

public

See also
free()

Definition at line 693 of file IT.php.

References buildBlockvariablelist(), findBlocks(), and free().

Referenced by setTemplate().

694  {
695  $this->free();
696  $this->findBlocks($this->template);
697  // we don't need it any more
698  $this->template = '';
699  $this->buildBlockvariablelist();
700  } // end func init
free()
Clears all datafields of the object.
Definition: IT.php:710
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:813
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:854
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadTemplatefile()

HTML_Template_IT::loadTemplatefile (   $filename,
  $removeUnknownVariables = true,
  $removeEmptyBlocks = true 
)

Reads a template file from the disk.

Parameters
stringname of the template file
boolhow to handle unknown variables.
boolhow to handle empty blocks. public
Returns
boolean false on failure, otherwise true
See also
$template, setTemplate(), $removeUnknownVariables, $removeEmptyBlocks

Definition at line 772 of file IT.php.

References $filename, getFile(), and setTemplate().

775  {
776  $template = '';
777  if (!$this->flagCacheTemplatefile ||
778  $this->lastTemplatefile != $filename
779  ) {
780  $template = $this->getFile($filename);
781  }
782  $this->lastTemplatefile = $filename;
783 
784  return $template != '' ?
785  $this->setTemplate(
787  ) : false;
788  } // end func LoadTemplatefile
$removeUnknownVariables
Definition: IT.php:195
$filename
Definition: buildRTE.php:89
$removeEmptyBlocks
Definition: IT.php:202
setTemplate( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Sets the template.
Definition: IT.php:737
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:906
+ Here is the call graph for this function:

◆ parse()

HTML_Template_IT::parse (   $block = '__global__',
  $flag_recursion = false 
)

Parses the given block.

Parameters
stringname of the block to be parsed public
See also
parseCurrentBlock()
Exceptions
PEAR_Error

Definition at line 496 of file IT.php.

References $closingDelimiter, errorMessage(), IT_BLOCK_NOT_FOUND, and PEAR\raiseError().

Referenced by get(), and parseCurrentBlock().

497  {
498  static $regs, $values;
499 
500  if (!isset($this->blocklist[$block])) {
501  return PEAR::raiseError(
502  $this->errorMessage( IT_BLOCK_NOT_FOUND ) . '"' . $block . "'",
504  );
505  }
506 
507  if ($block == '__global__') {
508  $this->flagGlobalParsed = true;
509  }
510 
511  if (!$flag_recursion) {
512  $regs = array();
513  $values = array();
514  }
515  $outer = $this->blocklist[$block];
516  $empty = true;
517 
518  if ($this->clearCacheOnParse) {
519  foreach ($this->variableCache as $name => $value) {
520  $regs[] = $this->openingDelimiter .
521  $name . $this->closingDelimiter;
522  $values[] = $value;
523  $empty = false;
524  }
525  $this->variableCache = array();
526  } else {
527  foreach ($this->blockvariables[$block] as $allowedvar => $v) {
528 
529  if (isset($this->variableCache[$allowedvar])) {
530  $regs[] = $this->openingDelimiter .
531  $allowedvar . $this->closingDelimiter;
532  $values[] = $this->variableCache[$allowedvar];
533  unset($this->variableCache[$allowedvar]);
534  $empty = false;
535  }
536  }
537  }
538 
539  if (isset($this->blockinner[$block])) {
540  foreach ($this->blockinner[$block] as $k => $innerblock) {
541 
542  $this->parse($innerblock, true);
543  if ($this->blockdata[$innerblock] != '') {
544  $empty = false;
545  }
546 
547  $placeholder = $this->openingDelimiter . "__" .
548  $innerblock . "__" . $this->closingDelimiter;
549  $outer = str_replace(
550  $placeholder,
551  $this->blockdata[$innerblock], $outer
552  );
553  $this->blockdata[$innerblock] = "";
554  }
555 
556  }
557 
558  if (!$flag_recursion && 0 != count($values)) {
559  if ($this->_options['use_preg']) {
560  $regs = array_map(array(
561  &$this, '_addPregDelimiters'),
562  $regs
563  );
564  $funcReplace = 'preg_replace';
565  } else {
566  $funcReplace = 'str_replace';
567  }
568 
569  if ($this->_options['preserve_data']) {
570  $values = array_map(
571  array(&$this, '_preserveOpeningDelimiter'), $values
572  );
573  }
574 
575  $outer = $funcReplace($regs, $values, $outer);
576 
577  if ($this->removeUnknownVariables) {
578  $outer = preg_replace($this->removeVariablesRegExp, "", $outer);
579  }
580  }
581 
582  if ($empty) {
583  if (!$this->removeEmptyBlocks) {
584  $this->blockdata[$block ].= $outer;
585  } else {
586  if (isset($this->touchedBlocks[$block])) {
587  $this->blockdata[$block] .= $outer;
588  unset($this->touchedBlocks[$block]);
589  }
590  }
591  } else {
592  if (empty($this->blockdata[$block])) {
593  $this->blockdata[$block] = $outer;
594  } else {
595  $this->blockdata[$block] .= $outer;
596  }
597  }
598 
599  return $empty;
600  } // end func parse
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:496
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseCurrentBlock()

HTML_Template_IT::parseCurrentBlock ( )

◆ setCurrentBlock()

HTML_Template_IT::setCurrentBlock (   $block = '__global__')

Sets the name of the current block that is the block where variables are added.

Parameters
stringname of the block
Returns
boolean false on failure, otherwise true
Exceptions
PEAR_Errorpublic

Definition at line 646 of file IT.php.

References errorMessage(), IT_BLOCK_NOT_FOUND, and PEAR\raiseError().

647  {
648 
649  if (!isset($this->blocklist[$block])) {
650  return PEAR::raiseError(
651  $this->errorMessage( IT_BLOCK_NOT_FOUND ) .
652  '"' . $block . "'", IT_BLOCK_NOT_FOUND
653  );
654  }
655 
656  $this->currentBlock = $block;
657 
658  return true;
659  } // end func setCurrentBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ setOption()

HTML_Template_IT::setOption (   $option,
  $value 
)

Sets the option for the template class.

public

Parameters
stringoption name
mixedoption value
Returns
mixed IT_OK on success, error object on failure

Definition at line 397 of file IT.php.

References errorMessage(), IT_OK, IT_UNKNOWN_OPTION, and PEAR\raiseError().

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

398  {
399  if (array_key_exists($option, $this->_options)) {
400  $this->_options[$option] = $value;
401  return IT_OK;
402  }
403 
404  return PEAR::raiseError(
405  $this->errorMessage(IT_UNKNOWN_OPTION) . ": '{$option}'",
407  );
408  }
const IT_OK
Definition: IT.php:23
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
const IT_UNKNOWN_OPTION
Definition: IT.php:28
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOptions()

HTML_Template_IT::setOptions (   $options)

Sets the options for the template class.

public

Parameters
stringoptions array of options default value: 'preserve_data' => false, 'use_preg' => true
mixedoption value
Returns
mixed IT_OK on success, error object on failure
See also
$options

Definition at line 422 of file IT.php.

References $options, PEAR\isError(), IT_OK, and setOption().

Referenced by HTML_Template_IT().

423  {
424  if (is_array($options)) {
425  foreach ($options as $option => $value) {
426  $error = $this->setOption($option, $value);
427  if (PEAR::isError($error)) {
428  return $error;
429  }
430  }
431  }
432 
433  return IT_OK;
434  }
const IT_OK
Definition: IT.php:23
if(!is_array($argv)) $options
setOption($option, $value)
Sets the option for the template class.
Definition: IT.php:397
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRoot()

HTML_Template_IT::setRoot (   $root)

Sets the file root.

The file root gets prefixed to all filenames passed to the object.

Make sure that you override this function when using the class on windows.

Parameters
string
See also
HTML_Template_IT() User interface

Definition at line 801 of file IT.php.

Referenced by HTML_Template_IT().

802  {
803  if ($root != '' && substr($root, -1) != '/') {
804  $root .= '/';
805  }
806 
807  $this->fileRoot = $root;
808  } // end func setRoot
+ Here is the caller graph for this function:

◆ setTemplate()

HTML_Template_IT::setTemplate (   $template,
  $removeUnknownVariables = true,
  $removeEmptyBlocks = true 
)

Sets the template.

You can eighter load a template file from disk with LoadTemplatefile() or set the template manually using this function.

Parameters
stringtemplate content
booleanremove unknown/unused variables?
booleanremove empty blocks?
See also
LoadTemplatefile(), $template User interface
Returns
boolean

Definition at line 737 of file IT.php.

References $removeEmptyBlocks, $removeUnknownVariables, and init().

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

739  {
740  $this->removeUnknownVariables = $removeUnknownVariables;
741  $this->removeEmptyBlocks = $removeEmptyBlocks;
742 
743  if ($template == '' && $this->flagCacheTemplatefile) {
744  $this->variableCache = array();
745  $this->blockdata = array();
746  $this->touchedBlocks = array();
747  $this->currentBlock = '__global__';
748  } else {
749  $this->template = '<!-- BEGIN __global__ -->' . $template .
750  '<!-- END __global__ -->';
751  $this->init();
752  }
753 
754  if ($this->flagBlocktrouble) {
755  return false;
756  }
757 
758  return true;
759  } // end func setTemplate
$removeUnknownVariables
Definition: IT.php:195
$removeEmptyBlocks
Definition: IT.php:202
init()
Clears all datafields of the object and rebuild the internal blocklist.
Definition: IT.php:693
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setVariable()

HTML_Template_IT::setVariable (   $variable,
  $value = '' 
)

Sets a variable value.

The function can be used eighter like setVariable( "varname", "value") or with one array $variables["varname"] = "value" given setVariable($variables) quite like phplib templates set_var().

Parameters
mixedstring with the variable name or an array variables["varname"] = "value"
stringvalue of the variable or empty if $variable is an array.
stringprefix for variable names public

Definition at line 626 of file IT.php.

Referenced by ilContainerRenderer\addHeaderRow(), ilTemplate\addILIASFooter(), ilContainerRenderer\addStandardRow(), ilChatroomViewTask\cancelJoin(), ilTermsOfServiceSignedDocumentFormElementGUI\checkInput(), ilForumExportGUI\executeCommand(), ilTemplate\fillAdminPanel(), ilTemplate\fillBodyClass(), ilTemplate\fillContentLanguage(), ilTemplate\fillContentStyle(), ilTemplate\fillCssFiles(), ilTemplate\fillHeader(), ilTemplate\fillInlineCss(), ilTemplate\fillJavascriptFile(), ilTemplate\fillJavaScriptFiles(), ilTemplate\fillLeftContent(), ilTemplate\fillLeftNav(), ilTemplate\fillLightbox(), ilTemplate\fillMainContent(), ilTemplate\fillMessage(), ilTemplate\fillNewContentStyle(), ilTemplate\fillOnLoadCode(), ilTemplate\fillPageFormAction(), ilTemplate\fillPermanentLink(), ilTemplate\fillRightContent(), ilTemplate\fillSideIcons(), ilTemplate\fillTabs(), ilTemplate\fillToolbar(), ilTemplate\fillVars(), ilTemplate\fillWindowTitle(), ilEMailInputGUI\insert(), ilCaptchaInputGUI\insert(), ilClozeGapInputBuilderGUI\insert(), ilAssQuestionPreviewGUI\populateGenericQuestionFeedback(), ilAssQuestionPreviewGUI\populatePreviewToolbar(), ilAssQuestionPreviewGUI\populateQuestionNavigation(), ilAssQuestionPreviewGUI\populateQuestionOutput(), ilAssQuestionPreviewGUI\populateSolutionOutput(), ilAssQuestionPreviewGUI\populateSpecificQuestionFeedback(), ilContainerRenderer\renderDetails(), ilChatroomViewTask\renderFileUploadForm(), ilSurveyPageGUI\renderPageNode(), ilContainerRenderer\renderSelectAllBlock(), ilTemplate\replace(), ilTemplate\setBackgroundColor(), ilTemplate\setBanner(), ilTemplate\setCenterColumnClass(), ilTemplate\setLocator(), ilTemplate\setNewContentStyleSheetLocation(), ilTemplate\setStyleSheetLocation(), ilTemplate\setSubTabs(), ilTemplate\setTabs(), and ilTemplate\show().

627  {
628  if (is_array($variable)) {
629  $this->variableCache = array_merge(
630  $this->variableCache, $variable
631  );
632  } else {
633  $this->variableCache[$variable] = $value;
634  }
635  } // end func setVariable
+ Here is the caller graph for this function:

◆ show()

HTML_Template_IT::show (   $block = '__global__')

Print a certain block with all replacements done.

get()

Definition at line 440 of file IT.php.

441  {
442  print $this->get($block);
443  } // end func show

◆ touchBlock()

HTML_Template_IT::touchBlock (   $block)

Preserves an empty block even if removeEmptyBlocks is true.

Parameters
stringname of the block
Returns
boolean false on false, otherwise true
Exceptions
PEAR_Errorpublic
See also
$removeEmptyBlocks

Definition at line 670 of file IT.php.

References errorMessage(), IT_BLOCK_NOT_FOUND, and PEAR\raiseError().

671  {
672  if (!isset($this->blocklist[$block])) {
673  return PEAR::raiseError(
675  '"' . $block . "'", IT_BLOCK_NOT_FOUND);
676  }
677 
678  $this->touchedBlocks[$block] = true;
679 
680  return true;
681  } // end func touchBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:975
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

Field Documentation

◆ $_hiddenBlocks

array HTML_Template_IT::$_hiddenBlocks = array()

List of blocks which should not be shown even if not "empty".

See also
hideBlock(), $removeEmptyBlocks

Definition at line 282 of file IT.php.

◆ $_options

HTML_Template_IT::$_options
Initial value:
= array(
'preserve_data' => false,
'use_preg' => true
)

$_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951).

$_options['use_preg'] Whether to use preg_replace instead of str_replace in parse() (this is a backwards compatibility feature, see also bugs #21951, #20392)

Definition at line 354 of file IT.php.

◆ $blockdata

HTML_Template_IT::$blockdata = array()

Definition at line 236 of file IT.php.

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

◆ $blockinner

HTML_Template_IT::$blockinner = array()

Definition at line 248 of file IT.php.

Referenced by ilTemplate\init().

◆ $blocklist

HTML_Template_IT::$blocklist = array()

Definition at line 229 of file IT.php.

Referenced by findBlocks(), HTML_Template_ITX\getBlocklist(), and ilTemplate\init().

◆ $blocknameRegExp

HTML_Template_IT::$blocknameRegExp = '[\.0-9A-Za-z_-]+'

Definition at line 164 of file IT.php.

◆ $blockRegExp

HTML_Template_IT::$blockRegExp = ''

Definition at line 209 of file IT.php.

◆ $blockvariables

HTML_Template_IT::$blockvariables = array()

Definition at line 242 of file IT.php.

Referenced by ilTemplate\init().

◆ $clearCache

HTML_Template_IT::$clearCache = false

Definition at line 138 of file IT.php.

◆ $clearCacheOnParse

HTML_Template_IT::$clearCacheOnParse = false

Definition at line 305 of file IT.php.

◆ $closingDelimiter

HTML_Template_IT::$closingDelimiter = '}'

Definition at line 154 of file IT.php.

Referenced by HTML_Template_ITX\buildFunctionlist(), and parse().

◆ $currentBlock

HTML_Template_IT::$currentBlock = '__global__'

Definition at line 215 of file IT.php.

◆ $err

HTML_Template_IT::$err = array()

Definition at line 132 of file IT.php.

Referenced by ilTemplate\init().

◆ $fileRoot

HTML_Template_IT::$fileRoot = ''

Definition at line 313 of file IT.php.

◆ $flagBlocktrouble

HTML_Template_IT::$flagBlocktrouble = false

Definition at line 319 of file IT.php.

Referenced by ilTemplate\init().

◆ $flagCacheTemplatefile

HTML_Template_IT::$flagCacheTemplatefile = true

Definition at line 339 of file IT.php.

◆ $flagGlobalParsed

HTML_Template_IT::$flagGlobalParsed = false

Definition at line 325 of file IT.php.

◆ $lastTemplatefile

HTML_Template_IT::$lastTemplatefile = ''

EXPERIMENTAL! FIXME!

Definition at line 344 of file IT.php.

◆ $openingDelimiter

HTML_Template_IT::$openingDelimiter = '{'

Definition at line 146 of file IT.php.

◆ $removeEmptyBlocks

HTML_Template_IT::$removeEmptyBlocks = true

Definition at line 202 of file IT.php.

Referenced by ilTemplate\loadTemplatefile(), and setTemplate().

◆ $removeUnknownVariables

HTML_Template_IT::$removeUnknownVariables = true

Definition at line 195 of file IT.php.

Referenced by ilTemplate\loadTemplatefile(), and setTemplate().

◆ $removeVariablesRegExp

HTML_Template_IT::$removeVariablesRegExp = ''

RegExp used to strip unused variable placeholder.

$variablesRegExp

Definition at line 188 of file IT.php.

◆ $template

◆ $touchedBlocks

array HTML_Template_IT::$touchedBlocks = array()

List of blocks to preverse even if they are "empty".

This is something special. Sometimes you have blocks that should be preserved although they are empty (no placeholder replaced). Think of a shopping basket. If it's empty you have to drop a message to the user. If it's filled you have to show the contents of the shopping baseket. Now where do you place the message that the basket is empty? It's no good idea to place it in you applications as customers tend to like unecessary minor text changes. Having another template file for an empty basket means that it's very likely that one fine day the filled and empty basket templates have different layout. I decided to introduce blocks that to not contain any placeholder but only text such as the message "Your shopping basked is empty".

Now if there is no replacement done in such a block the block will be recognized as "empty" and by default ($removeEmptyBlocks = true) be stripped off. To avoid thisyou can now call touchBlock() to avoid this.

The array $touchedBlocks stores a list of touched block which must not be removed even if they are empty.

See also
touchBlock(), $removeEmptyBlocks

Definition at line 275 of file IT.php.

◆ $variableCache

HTML_Template_IT::$variableCache = array()

Definition at line 294 of file IT.php.

◆ $variablenameRegExp

HTML_Template_IT::$variablenameRegExp = '[\.0-9A-Za-z_-]+'

Definition at line 174 of file IT.php.

◆ $variablesRegExp

HTML_Template_IT::$variablesRegExp = ''

Definition at line 182 of file IT.php.


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