ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 PHPMailer\PHPMailer\$options, $root, 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
setRoot($root)
Sets the file root.
Definition: IT.php:810
$root
Definition: sabredav.php:45
+ 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 960 of file IT.php.

961  {
962  return '@' . $str . '@';
963  }

◆ _preserveOpeningDelimiter()

HTML_Template_IT::_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string.

Parameters
string
Returns
string

Definition at line 971 of file IT.php.

972  {
973  return (false === strpos($str, $this->openingDelimiter))?
974  $str:
975  str_replace(
976  $this->openingDelimiter,
977  $this->openingDelimiter .
978  '%preserved%' . $this->closingDelimiter,
979  $str
980  );
981  }

◆ buildBlockvariablelist()

HTML_Template_IT::buildBlockvariablelist ( )

Build a list of all variables within of a block.

Definition at line 822 of file IT.php.

References $name.

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

823  {
824  foreach ($this->blocklist as $name => $content) {
825  preg_match_all($this->variablesRegExp, $content, $regs);
826 
827  if (count($regs[1]) != 0) {
828  foreach ($regs[1] as $k => $var) {
829  $this->blockvariables[$name][$var] = true;
830  }
831  } else {
832  $this->blockvariables[$name] = array();
833  }
834  }
835  } // 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 991 of file IT.php.

References 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().

992  {
993  static $errorMessages;
994  if (!isset($errorMessages)) {
995  $errorMessages = array(
996  IT_OK => '',
997  IT_ERROR => 'unknown error',
998  IT_TPL_NOT_FOUND => 'Cannot read the template file',
999  IT_BLOCK_NOT_FOUND => 'Cannot find this block',
1000  IT_BLOCK_DUPLICATE => 'The name of a block must be' .
1001  ' uniquewithin a template.' .
1002  ' Found "' . $blockname . '" twice.' .
1003  'Unpredictable results ' .
1004  'may appear.',
1005  IT_UNKNOWN_OPTION => 'Unknown option'
1006  );
1007  }
1008 
1009  return isset($errorMessages[$value]) ?
1010  $errorMessages[$value] : $errorMessages[IT_ERROR];
1011  }
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
+ 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 863 of file IT.php.

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

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

864  {
865  $blocklist = array();
866  if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
867  foreach ($regs as $k => $match) {
868  $blockname = $match[1];
869  $blockcontent = $match[2];
870 
871  if (isset($this->blocklist[$blockname])) {
872  throw (new ilTemplateException($this->errorMessage(
874  $blockname
875  )));
876  }
877 
878  $this->blocklist[$blockname] = $blockcontent;
879  $this->blockdata[$blockname] = "";
880 
881  $blocklist[] = $blockname;
882 
883  $inner = $this->findBlocks($blockcontent);
884  foreach ($inner as $k => $name) {
885  $pattern = sprintf(
886  '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
887  $name,
888  $name
889  );
890 
891  $this->blocklist[$blockname] = preg_replace(
892  $pattern,
893  $this->openingDelimiter .
894  '__' . $name . '__' .
895  $this->closingDelimiter,
896  $this->blocklist[$blockname]
897  );
898  $this->blockinner[$blockname][] = $name;
899  $this->blockparents[$name] = $blockname;
900  }
901  }
902  }
903 
904  return $blocklist;
905  } // end func findBlocks
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:991
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:863
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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
+ 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:991
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 912 of file IT.php.

References $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().

913  {
914  if ($filename[0] == '/' && substr($this->fileRoot, -1) == '/') {
915  $filename = substr($filename, 1);
916  }
917 
918  $filename = $this->fileRoot . $filename;
919 
920  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
921  $this->real_filename = $filename;
923  if (!$content = $ilGlobalCache->get($filename)) {
924  if (!($fh = @fopen($filename, 'r'))) {
926  ': "' . $filename . '"'));
927  }
928 
929  $fsize = filesize($filename);
930  if ($fsize < 1) {
931  fclose($fh);
932  return '';
933  }
934 
935  $content = fread($fh, $fsize);
936  $ilGlobalCache->set($filename, $content, 60);
937  fclose($fh);
938  }
939 
940 
941  /* performance patch, 6.4.2017
942  return preg_replace_callback(
943  "#<!-- INCLUDE (.*) -->#im",
944  function ($hit) {
945  return $this->getFile($hit[1]);
946  },
947  $content
948  );*/
949 
950  return $content;
951  } // end func getFile
static getInstance($component)
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:991
$filename
Definition: buildRTE.php:89
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 840 of file IT.php.

References $values.

841  {
842  $regs = array();
843  $values = array();
844 
845  foreach ($this->blockvariables['__global__'] as $allowedvar => $v) {
846  if (isset($this->variableCache[$allowedvar])) {
847  $regs[] = '@' . $this->openingDelimiter .
848  $allowedvar . $this->closingDelimiter . '@';
849  $values[] = $this->variableCache[$allowedvar];
850  unset($this->variableCache[$allowedvar]);
851  }
852  }
853 
854  return array($regs, $values);
855  } // end func getGlobalvariables
$values

◆ 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:822
static log($message, $log_level)
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:863
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References $filename, $removeEmptyBlocks, $removeUnknownVariables, $template, getFile(), and setTemplate().

Referenced by ilIndependentTemplate\loadTemplatefile().

782  {
783  $template = '';
784  if (!$this->flagCacheTemplatefile ||
785  $this->lastTemplatefile != $filename
786  ) {
787  $template = $this->getFile($filename);
788  }
789  $this->lastTemplatefile = $filename;
790 
791  return $template != '' ?
792  $this->setTemplate(
793  $template,
796  ) : false;
797  } // 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:741
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:912
+ 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, $name, $values, 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 .
509  $values[] = $value;
510  $empty = false;
511  }
512  $this->variableCache = array();
513  } else {
514  foreach ($this->blockvariables[$block] as $allowedvar => $v) {
515  if (isset($this->variableCache[$allowedvar])) {
516  $regs[] = $this->openingDelimiter .
517  $allowedvar . $this->closingDelimiter;
518  $values[] = $this->variableCache[$allowedvar];
519  unset($this->variableCache[$allowedvar]);
520  $empty = false;
521  }
522  }
523  }
524 
525  if (isset($this->blockinner[$block])) {
526  foreach ($this->blockinner[$block] as $k => $innerblock) {
527  $this->parse($innerblock, true);
528  if ($this->blockdata[$innerblock] != '') {
529  $empty = false;
530  }
531 
532  $placeholder = $this->openingDelimiter . "__" .
533  $innerblock . "__" . $this->closingDelimiter;
534  $outer = str_replace(
535  $placeholder,
536  $this->blockdata[$innerblock],
537  $outer
538  );
539  $this->blockdata[$innerblock] = "";
540  }
541  }
542 
543  if (!$flag_recursion && 0 != count($values)) {
544  if ($this->_options['use_preg']) {
545  $regs = array_map(
546  array(
547  &$this, '_addPregDelimiters'),
548  $regs
549  );
550  $funcReplace = 'preg_replace';
551  } else {
552  $funcReplace = 'str_replace';
553  }
554 
555  if ($this->_options['preserve_data']) {
556  $values = array_map(
557  array(&$this, '_preserveOpeningDelimiter'),
558  $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:991
$values
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
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 634 of file IT.php.

References errorMessage(), and IT_BLOCK_NOT_FOUND.

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:991
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:991
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 PHPMailer\PHPMailer\$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  }
const IT_OK
Definition: IT.php:23
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 810 of file IT.php.

References $root.

Referenced by __construct().

811  {
812  if ($root != '' && substr($root, -1) != '/') {
813  $root .= '/';
814  }
815 
816  $this->fileRoot = $root;
817  } // end func setRoot
$root
Definition: sabredav.php:45
+ 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, $template, and init().

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

745  {
746  $this->removeUnknownVariables = $removeUnknownVariables;
747  $this->removeEmptyBlocks = $removeEmptyBlocks;
748 
749  if ($template == '' && $this->flagCacheTemplatefile) {
750  $this->variableCache = array();
751  $this->blockdata = array();
752  $this->touchedBlocks = array();
753  $this->currentBlock = '__global__';
754  } else {
755  $this->template = '<!-- BEGIN __global__ -->' . $template .
756  '<!-- END __global__ -->';
757  $this->init();
758  }
759 
760  if ($this->flagBlocktrouble) {
761  return false;
762  }
763 
764  return true;
765  } // 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: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 ilBTPopOverGUI\addButton(), ilContainerRenderer\addHeaderRow(), ilTemplate\addILIASFooter(), ilPDSelectedItemsBlockGUI\addSectionHeader(), ilContainerRenderer\addStandardRow(), 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(), ilPDSelectedItemsBlockGUI\getViewBlockHtml(), ilOrgUnitAuthorityInputGUI\insert(), ilChatroomAuthInputGUI\insert(), ilEMailInputGUI\insert(), ilCaptchaInputGUI\insert(), ilClozeGapInputBuilderGUI\insert(), ilSCORMExplorer\insertObject(), ilTestServiceGUI\populateExamId(), ilAssQuestionPreviewGUI\populateGenericQuestionFeedback(), ilAssQuestionPreviewGUI\populateInstantResponseHeader(), ilAssQuestionPreviewGUI\populateNotesPanel(), ilAssQuestionPreviewGUI\populatePreviewToolbar(), ilAssQuestionPreviewGUI\populateQuestionOutput(), ilAssQuestionPreviewGUI\populateReachedPointsOutput(), ilAssQuestionPreviewGUI\populateSolutionOutput(), ilAssQuestionPreviewGUI\populateSpecificQuestionFeedback(), ilAssLacLegendGUI\populateTriggerDepencies(), ilAssLacLegendGUI\populateVisibilityCss(), ilTestQuestionNavigationGUI\renderActionsIcon(), ilTestQuestionNavigationGUI\renderButtonInstance(), ilAssLacLegendGUI\renderCommonLegendPart(), ilContainerRenderer\renderDetails(), ilAssLacLegendGUI\renderExample(), ilChatroomViewGUI\renderFileUploadForm(), ilContainerRenderer\renderHelperGeneric(), ilTestQuestionNavigationGUI\renderIcon(), ilChatroomViewGUI\renderLanguageVariables(), ilSurveyPageGUI\renderPageNode(), ilForumExportGUI\renderPostHtml(), ilAssLacLegendGUI\renderQuestSpecificExamples(), ilAssLacLegendGUI\renderQuestSpecificLegendPart(), ilChatroomViewGUI\renderRightUsersBlock(), ilContainerRenderer\renderSelectAllBlock(), ilChatroomViewGUI\renderSendMessageBox(), ilMainMenuGUI\renderStatusBox(), ilTemplate\replace(), ilTemplate\setBackgroundColor(), ilTemplate\setBanner(), ilTemplate\setCenterColumnClass(), ilKioskPageRenderer\setHeaderVars(), 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,
618  $variable
619  );
620  } else {
621  $this->variableCache[$variable] = $value;
622  }
623  } // 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:991
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:
= 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(), 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: