ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
HTML_Template_IT Class Reference
+ Inheritance diagram for HTML_Template_IT:
+ Collaboration diagram for HTML_Template_IT:

Public Member Functions

 __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

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

Constructor & Destructor Documentation

◆ __construct()

HTML_Template_IT::__construct (   $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().

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:418
if(!is_array($argv)) $options
setRoot($root)
Sets the file root.
Definition: IT.php:805
+ Here is the call graph for this function:

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

951  {
952  return '@' . $str . '@';
953  }

◆ _preserveOpeningDelimiter()

HTML_Template_IT::_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string.

Parameters
string
Returns
string

Definition at line 961 of file IT.php.

962  {
963  return (false === strpos($str, $this->openingDelimiter))?
964  $str:
965  str_replace(
966  $this->openingDelimiter,
967  $this->openingDelimiter .
968  '%preserved%' . $this->closingDelimiter,
969  $str
970  );
971  }

◆ buildBlockvariablelist()

HTML_Template_IT::buildBlockvariablelist ( )

Build a list of all variables within of a block.

Definition at line 817 of file IT.php.

References array.

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

818  {
819  foreach ($this->blocklist as $name => $content) {
820  preg_match_all($this->variablesRegExp, $content, $regs);
821 
822  if (count($regs[1]) != 0) {
823  foreach ($regs[1] as $k => $var) {
824  $this->blockvariables[$name][$var] = true;
825  }
826  } else {
827  $this->blockvariables[$name] = array();
828  }
829  }
830  } // end func buildBlockvariablelist
Create styles array
The data for the language used.
+ 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 981 of file IT.php.

References array, IT_BLOCK_DUPLICATE, IT_BLOCK_NOT_FOUND, IT_ERROR, IT_OK, IT_TPL_NOT_FOUND, and IT_UNKNOWN_OPTION.

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

982  {
983  static $errorMessages;
984  if (!isset($errorMessages)) {
985  $errorMessages = array(
986  IT_OK => '',
987  IT_ERROR => 'unknown error',
988  IT_TPL_NOT_FOUND => 'Cannot read the template file',
989  IT_BLOCK_NOT_FOUND => 'Cannot find this block',
990  IT_BLOCK_DUPLICATE => 'The name of a block must be'.
991  ' uniquewithin a template.'.
992  ' Found "' . $blockname . '" twice.'.
993  'Unpredictable results '.
994  'may appear.',
995  IT_UNKNOWN_OPTION => 'Unknown option'
996  );
997  }
998 
999  return isset($errorMessages[$value]) ?
1000  $errorMessages[$value] : $errorMessages[IT_ERROR];
1001  }
const IT_OK
Definition: IT.php:23
const IT_UNKNOWN_OPTION
Definition: IT.php:28
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
Create styles array
The data for the language used.
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
const IT_ERROR
Definition: IT.php:24
const IT_TPL_NOT_FOUND
Definition: IT.php:25
+ 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 858 of file IT.php.

References $blocklist, array, errorMessage(), and IT_BLOCK_DUPLICATE.

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

859  {
860  $blocklist = array();
861  if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
862  foreach ($regs as $k => $match) {
863  $blockname = $match[1];
864  $blockcontent = $match[2];
865 
866  if (isset($this->blocklist[$blockname])) {
867  throw (new ilTemplateException($this->errorMessage(
868  IT_BLOCK_DUPLICATE, $blockname)));
869  }
870 
871  $this->blocklist[$blockname] = $blockcontent;
872  $this->blockdata[$blockname] = "";
873 
874  $blocklist[] = $blockname;
875 
876  $inner = $this->findBlocks($blockcontent);
877  foreach ($inner as $k => $name) {
878  $pattern = sprintf(
879  '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
880  $name,
881  $name
882  );
883 
884  $this->blocklist[$blockname] = preg_replace(
885  $pattern,
886  $this->openingDelimiter .
887  '__' . $name . '__' .
888  $this->closingDelimiter,
889  $this->blocklist[$blockname]
890  );
891  $this->blockinner[$blockname][] = $name;
892  $this->blockparents[$name] = $blockname;
893  }
894  }
895  }
896 
897  return $blocklist;
898  } // end func findBlocks
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
Create styles array
The data for the language used.
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
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:

◆ 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 714 of file IT.php.

References array.

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

715  {
716  $this->err = array();
717 
718  $this->currentBlock = '__global__';
719 
720  $this->variableCache = array();
721  $this->blocklist = array();
722  $this->touchedBlocks = array();
723 
724  $this->flagBlocktrouble = false;
725  $this->flagGlobalParsed = false;
726  } // end func free
Create styles array
The data for the language used.
+ 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
ilTemplateExceptionpublic
See also
show()

Definition at line 447 of file IT.php.

References $ret, errorMessage(), IT_BLOCK_NOT_FOUND, and parse().

448  {
449  if ($block == '__global__' && !$this->flagGlobalParsed) {
450  $this->parse('__global__');
451  }
452 
453  if (!isset($this->blocklist[$block])) {
455  '"' . $block . "'"));
456  }
457 
458  if (isset($this->blockdata[$block])) {
459  $ret = $this->blockdata[$block];
460  if ($this->clearCache) {
461  unset($this->blockdata[$block]);
462  }
463  if ($this->_options['preserve_data']) {
464  $ret = str_replace(
465  $this->openingDelimiter .
466  '%preserved%' . $this->closingDelimiter,
467  $this->openingDelimiter,
468  $ret
469  );
470  }
471  return $ret;
472  }
473 
474  return '';
475  } // end func get()
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:485
$ret
Definition: parser.php:6
+ 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 905 of file IT.php.

References $fh, $filename, ilGlobalCache\COMP_TEMPLATE, errorMessage(), ilGlobalCache\getInstance(), and IT_TPL_NOT_FOUND.

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

906  {
907  if ($filename{0} == '/' && substr($this->fileRoot, -1) == '/') {
908  $filename = substr($filename, 1);
909  }
910 
911  $filename = $this->fileRoot . $filename;
912 
913  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
914  $this->real_filename = $filename;
916  if(!$content = $ilGlobalCache->get($filename)) {
917  if (!($fh = @fopen($filename, 'r'))) {
919  ': "' .$filename .'"'));
920  }
921 
922  $fsize = filesize($filename);
923  if ($fsize < 1) {
924  fclose($fh);
925  return '';
926  }
927 
928  $content = fread($fh, $fsize);
929  $ilGlobalCache->set($filename, $content, 60);
930  fclose($fh);
931  }
932 
933 
934  return preg_replace_callback(
935  "#<!-- INCLUDE (.*) -->#im",
936  function ($hit) {
937  return $this->getFile($hit[1]);
938  },
939  $content
940  );
941  } // end func getFile
static getInstance($component)
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_TPL_NOT_FOUND
Definition: IT.php:25
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:905
+ 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 835 of file IT.php.

References array.

836  {
837  $regs = array();
838  $values = array();
839 
840  foreach ($this->blockvariables['__global__'] as $allowedvar => $v) {
841  if (isset($this->variableCache[$allowedvar])) {
842  $regs[] = '@' . $this->openingDelimiter .
843  $allowedvar . $this->closingDelimiter . '@';
844  $values[] = $this->variableCache[$allowedvar];
845  unset($this->variableCache[$allowedvar]);
846  }
847  }
848 
849  return array($regs, $values);
850  } // end func getGlobalvariables
Create styles array
The data for the language used.

◆ 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 677 of file IT.php.

References $blockdata, $blocklist, $blockvariables, buildBlockvariablelist(), ilGlobalCache\COMP_TPL_BLOCKS, ilGlobalCache\COMP_TPL_VARIABLES, findBlocks(), free(), ilGlobalCache\getInstance(), ilGlobalCache\log(), and ilGlobalCacheSettings\LOG_LEVEL_FORCED.

Referenced by setTemplate().

678  {
679  $this->free();
680  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
682 
683  if ($blockdata = $blocks->get($this->real_filename)) {
684  $this->blockdata = $blockdata['blockdata'];
685  $this->blocklist = $blockdata['blocklist'];
686  } else {
688  $this->findBlocks($this->template);
689  $blockdata['blockdata'] = $this->blockdata;
690  $blockdata['blocklist'] = $this->blocklist;
691  $blocks->set($this->real_filename, $blockdata, 60);
692  }
693 
694  // we don't need it any more
695  $this->template = '';
696 
698  if ($blockvariables = $variables->get($this->real_filename)) {
699  $this->blockvariables = $blockvariables;
700  } else {
701  $this->buildBlockvariablelist();
702  $variables->set($this->real_filename, $this->blockvariables, 60);
703  }
704  } // end func init
static getInstance($component)
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
static log($message, $log_level)
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:

◆ 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 776 of file IT.php.

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

Referenced by ilIndependentTemplate\loadTemplatefile().

779  {
780  $template = '';
781  if (!$this->flagCacheTemplatefile ||
782  $this->lastTemplatefile != $filename
783  ) {
784  $template = $this->getFile($filename);
785  }
786  $this->lastTemplatefile = $filename;
787 
788  return $template != '' ?
789  $this->setTemplate(
791  ) : false;
792  } // end func LoadTemplatefile
$removeUnknownVariables
Definition: IT.php:195
$removeEmptyBlocks
Definition: IT.php:202
setTemplate( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Sets the template.
Definition: IT.php:741
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:905
+ Here is the call graph for this function:
+ Here is the caller 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
ilTemplateException

Definition at line 485 of file IT.php.

References $closingDelimiter, array, errorMessage(), and IT_BLOCK_NOT_FOUND.

Referenced by ilIndependentTemplate\get(), get(), and parseCurrentBlock().

486  {
487  static $regs, $values;
488 
489  if (!isset($this->blocklist[$block])) {
491  '"' . $block . "'"));
492  }
493 
494  if ($block == '__global__') {
495  $this->flagGlobalParsed = true;
496  }
497 
498  if (!$flag_recursion) {
499  $regs = array();
500  $values = array();
501  }
502  $outer = $this->blocklist[$block];
503  $empty = true;
504 
505  if ($this->clearCacheOnParse) {
506  foreach ($this->variableCache as $name => $value) {
507  $regs[] = $this->openingDelimiter .
508  $name . $this->closingDelimiter;
509  $values[] = $value;
510  $empty = false;
511  }
512  $this->variableCache = array();
513  } else {
514  foreach ($this->blockvariables[$block] as $allowedvar => $v) {
515 
516  if (isset($this->variableCache[$allowedvar])) {
517  $regs[] = $this->openingDelimiter .
518  $allowedvar . $this->closingDelimiter;
519  $values[] = $this->variableCache[$allowedvar];
520  unset($this->variableCache[$allowedvar]);
521  $empty = false;
522  }
523  }
524  }
525 
526  if (isset($this->blockinner[$block])) {
527  foreach ($this->blockinner[$block] as $k => $innerblock) {
528 
529  $this->parse($innerblock, true);
530  if ($this->blockdata[$innerblock] != '') {
531  $empty = false;
532  }
533 
534  $placeholder = $this->openingDelimiter . "__" .
535  $innerblock . "__" . $this->closingDelimiter;
536  $outer = str_replace(
537  $placeholder,
538  $this->blockdata[$innerblock], $outer
539  );
540  $this->blockdata[$innerblock] = "";
541  }
542 
543  }
544 
545  if (!$flag_recursion && 0 != count($values)) {
546  if ($this->_options['use_preg']) {
547  $regs = array_map(array(
548  &$this, '_addPregDelimiters'),
549  $regs
550  );
551  $funcReplace = 'preg_replace';
552  } else {
553  $funcReplace = 'str_replace';
554  }
555 
556  if ($this->_options['preserve_data']) {
557  $values = array_map(
558  array(&$this, '_preserveOpeningDelimiter'), $values
559  );
560  }
561 
562  $outer = $funcReplace($regs, $values, $outer);
563 
564  if ($this->removeUnknownVariables) {
565  $outer = preg_replace($this->removeVariablesRegExp, "", $outer);
566  }
567  }
568 
569  if ($empty) {
570  if (!$this->removeEmptyBlocks) {
571  $this->blockdata[$block ].= $outer;
572  } else {
573  if (isset($this->touchedBlocks[$block])) {
574  $this->blockdata[$block] .= $outer;
575  unset($this->touchedBlocks[$block]);
576  }
577  }
578  } else {
579  if (empty($this->blockdata[$block])) {
580  $this->blockdata[$block] = $outer;
581  } else {
582  $this->blockdata[$block] .= $outer;
583  }
584  }
585 
586  return $empty;
587  } // end func parse
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
Create styles array
The data for the language used.
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:485
+ 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
ilTemplateExceptionpublic

Definition at line 633 of file IT.php.

References errorMessage(), and IT_BLOCK_NOT_FOUND.

634  {
635 
636  if (!isset($this->blocklist[$block])) {
638  '"' . $block . "'"));
639  }
640 
641  $this->currentBlock = $block;
642 
643  return true;
644  } // end func setCurrentBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
+ 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, and IT_UNKNOWN_OPTION.

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

398  {
399  if (array_key_exists($option, $this->_options)) {
400  $this->_options[$option] = $value;
401  return IT_OK;
402  }
403  throw (new ilTemplateException($this->errorMessage(IT_UNKNOWN_OPTION) . ": '{$option}'"));
404  }
const IT_OK
Definition: IT.php:23
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_UNKNOWN_OPTION
Definition: IT.php:28
+ 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 418 of file IT.php.

References $error, $options, IT_OK, and setOption().

Referenced by __construct().

419  {
420  if (is_array($options)) {
421  foreach ($options as $option => $value) {
422  $error = $this->setOption($option, $value);
423  }
424  }
425 
426  return IT_OK;
427  }
$error
Definition: Error.php:17
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
+ 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 805 of file IT.php.

Referenced by __construct().

806  {
807  if ($root != '' && substr($root, -1) != '/') {
808  $root .= '/';
809  }
810 
811  $this->fileRoot = $root;
812  } // 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 741 of file IT.php.

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

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

743  {
744  $this->removeUnknownVariables = $removeUnknownVariables;
745  $this->removeEmptyBlocks = $removeEmptyBlocks;
746 
747  if ($template == '' && $this->flagCacheTemplatefile) {
748  $this->variableCache = array();
749  $this->blockdata = array();
750  $this->touchedBlocks = array();
751  $this->currentBlock = '__global__';
752  } else {
753  $this->template = '<!-- BEGIN __global__ -->' . $template .
754  '<!-- END __global__ -->';
755  $this->init();
756  }
757 
758  if ($this->flagBlocktrouble) {
759  return false;
760  }
761 
762  return true;
763  } // end func setTemplate
$removeUnknownVariables
Definition: IT.php:195
Create styles array
The data for the language used.
$removeEmptyBlocks
Definition: IT.php:202
init()
Clears all datafields of the object and rebuild the internal blocklist.
Definition: IT.php:677
+ 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 613 of file IT.php.

Referenced by ilContainerRenderer\addHeaderRow(), ilTemplate\addILIASFooter(), ilContainerRenderer\addStandardRow(), ilChatroomViewGUI\cancelJoin(), 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(), ilTermsOfServiceSignedDocumentFormElementGUI\insert(), ilChatroomAuthInputGUI\insert(), ilEMailInputGUI\insert(), ilCaptchaInputGUI\insert(), ilClozeGapInputBuilderGUI\insert(), ilSCORMExplorer\insertObject(), ilAssQuestionPreviewGUI\populateGenericQuestionFeedback(), ilAssQuestionPreviewGUI\populatePreviewToolbar(), ilAssQuestionPreviewGUI\populateQuestionNavigation(), ilAssQuestionPreviewGUI\populateQuestionOutput(), ilAssQuestionPreviewGUI\populateSolutionOutput(), ilAssQuestionPreviewGUI\populateSpecificQuestionFeedback(), ilAssLacLegendGUI\populateTriggerDepencies(), ilAssLacLegendGUI\populateVisibilityCss(), ilTestQuestionNavigationGUI\renderActionsIcon(), ilTestQuestionNavigationGUI\renderButtonInstance(), ilAssLacLegendGUI\renderCommonLegendPart(), ilContainerRenderer\renderDetails(), ilAssLacLegendGUI\renderExample(), ilChatroomViewGUI\renderFileUploadForm(), ilTestQuestionNavigationGUI\renderIcon(), ilUsersGalleryGUI\renderLinkButton(), ilSurveyPageGUI\renderPageNode(), ilAssLacLegendGUI\renderQuestSpecificExamples(), ilAssLacLegendGUI\renderQuestSpecificLegendPart(), ilContainerRenderer\renderSelectAllBlock(), ilTemplate\replace(), ilTemplate\setBackgroundColor(), ilTemplate\setBanner(), ilTemplate\setCenterColumnClass(), ilTemplate\setLocator(), ilTemplate\setNewContentStyleSheetLocation(), ilTemplate\setStyleSheetLocation(), ilTemplate\setSubTabs(), ilTemplate\setTabs(), and ilTemplate\show().

614  {
615  if (is_array($variable)) {
616  $this->variableCache = array_merge(
617  $this->variableCache, $variable
618  );
619  } else {
620  $this->variableCache[$variable] = $value;
621  }
622  } // 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 433 of file IT.php.

434  {
435  print $this->get($block);
436  } // 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
ilTemplateExceptionpublic
See also
$removeEmptyBlocks

Definition at line 655 of file IT.php.

References errorMessage(), and IT_BLOCK_NOT_FOUND.

656  {
657  if (!isset($this->blocklist[$block])) {
659  '"' . $block . "'"));
660  }
661 
662  $this->touchedBlocks[$block] = true;
663 
664  return true;
665  } // end func touchBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:981
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
+ 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:
'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(), 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(), ilTemplate\init(), and 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(), and 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

◆ $removeUnknownVariables

HTML_Template_IT::$removeUnknownVariables = true

◆ $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: