ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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

 __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...
 
 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()
 
 $blockparents = 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...
 

Protected Member Functions

 init ()
 Clears all datafields of the object and rebuild the internal blocklist. 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 372 of file IT.php.

References setOptions(), and setRoot().

373  {
374  if (!is_null($options)) {
375  $this->setOptions($options);
376  }
377  $this->variablesRegExp = '@' . $this->openingDelimiter .
378  '(' . $this->variablenameRegExp . ')' .
379  $this->closingDelimiter . '@sm';
380  $this->removeVariablesRegExp = '@' . $this->openingDelimiter .
381  "\s*(" . $this->variablenameRegExp .
382  ")\s*" . $this->closingDelimiter . '@sm';
383 
384  $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp .
385  ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm';
386 
387  $this->setRoot($root);
388  } // end constructor
setOptions($options)
Sets the options for the template class.
Definition: IT.php:420
setRoot($root)
Sets the file root.
Definition: IT.php:812
+ 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 962 of file IT.php.

963  {
964  return '@' . $str . '@';
965  }

◆ _preserveOpeningDelimiter()

HTML_Template_IT::_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string.

Parameters
string
Returns
string

Definition at line 973 of file IT.php.

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

◆ buildBlockvariablelist()

HTML_Template_IT::buildBlockvariablelist ( )

Build a list of all variables within of a block.

Definition at line 824 of file IT.php.

References $name.

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

825  {
826  foreach ($this->blocklist as $name => $content) {
827  preg_match_all($this->variablesRegExp, $content, $regs);
828 
829  if (count($regs[1]) != 0) {
830  foreach ($regs[1] as $k => $var) {
831  $this->blockvariables[$name][$var] = true;
832  }
833  } else {
834  $this->blockvariables[$name] = array();
835  }
836  }
837  } // end func buildBlockvariablelist
if($format !==null) $name
Definition: metadata.php:230
+ 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 993 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(), get(), getFile(), parse(), setCurrentBlock(), setOption(), and touchBlock().

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

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

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

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

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

717  {
718  $this->err = array();
719 
720  $this->currentBlock = '__global__';
721 
722  $this->variableCache = array();
723  $this->blocklist = array();
724  $this->touchedBlocks = array();
725 
726  $this->flagBlocktrouble = false;
727  $this->flagGlobalParsed = false;
728  } // 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 449 of file IT.php.

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

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

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

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

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

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

◆ init()

HTML_Template_IT::init ( )
protected

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

680  {
681  $this->free();
682  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
684 
685  if ($blockdata = $blocks->get($this->real_filename)) {
686  $this->blockdata = $blockdata['blockdata'];
687  $this->blocklist = $blockdata['blocklist'];
688  } else {
690  $this->findBlocks($this->template);
691  $blockdata['blockdata'] = $this->blockdata;
692  $blockdata['blocklist'] = $this->blocklist;
693  $blocks->set($this->real_filename, $blockdata, 60);
694  }
695 
696  // we don't need it any more
697  $this->template = '';
698 
700  if ($blockvariables = $variables->get($this->real_filename)) {
701  $this->blockvariables = $blockvariables;
702  } else {
703  $this->buildBlockvariablelist();
704  $variables->set($this->real_filename, $this->blockvariables, 60);
705  }
706  } // end func init
static getInstance($component)
free()
Clears all datafields of the object.
Definition: IT.php:716
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:824
static log($message, $log_level)
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:865
+ 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 780 of file IT.php.

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

Referenced by ilIndependantTemplate\loadTemplatefile().

784  {
785  $template = '';
786  if (!$this->flagCacheTemplatefile ||
787  $this->lastTemplatefile != $filename
788  ) {
789  $template = $this->getFile($filename);
790  }
791  $this->lastTemplatefile = $filename;
792 
793  return $template != '' ?
794  $this->setTemplate(
795  $template,
798  ) : false;
799  } // 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:743
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:914
+ 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 487 of file IT.php.

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

Referenced by get(), and parseCurrentBlock().

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

◆ parseCurrentBlock()

HTML_Template_IT::parseCurrentBlock ( )

Parses the current block.

See also
parse(), setCurrentBlock(), $currentBlock User interface

Definition at line 596 of file IT.php.

References parse().

Referenced by ilTemplate\fillCssFiles(), ilTemplate\fillJavaScriptFiles(), and ilTemplate\touchBlock().

597  {
598  return $this->parse($this->currentBlock);
599  } // end func parseCurrentBlock
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:487
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References errorMessage(), and IT_BLOCK_NOT_FOUND.

637  {
638  if (!isset($this->blocklist[$block])) {
640  '"' . $block . "'"));
641  }
642 
643  $this->currentBlock = $block;
644 
645  return true;
646  } // end func setCurrentBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:993
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 399 of file IT.php.

References errorMessage(), IT_OK, and IT_UNKNOWN_OPTION.

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

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

References IT_OK, and setOption().

Referenced by __construct().

421  {
422  if (is_array($options)) {
423  foreach ($options as $option => $value) {
424  $error = $this->setOption($option, $value);
425  }
426  }
427 
428  return IT_OK;
429  }
const IT_OK
Definition: IT.php:23
setOption($option, $value)
Sets the option for the template class.
Definition: IT.php:399
+ 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 812 of file IT.php.

Referenced by __construct().

813  {
814  if ($root != '' && substr($root, -1) != '/') {
815  $root .= '/';
816  }
817 
818  $this->fileRoot = $root;
819  } // 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 743 of file IT.php.

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

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

747  {
748  $this->removeUnknownVariables = $removeUnknownVariables;
749  $this->removeEmptyBlocks = $removeEmptyBlocks;
750 
751  if ($template == '' && $this->flagCacheTemplatefile) {
752  $this->variableCache = array();
753  $this->blockdata = array();
754  $this->touchedBlocks = array();
755  $this->currentBlock = '__global__';
756  } else {
757  $this->template = '<!-- BEGIN __global__ -->' . $template .
758  '<!-- END __global__ -->';
759  $this->init();
760  }
761 
762  if ($this->flagBlocktrouble) {
763  return false;
764  }
765 
766  return true;
767  } // 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:679
+ 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 615 of file IT.php.

616  {
617  if (is_array($variable)) {
618  $this->variableCache = array_merge(
619  $this->variableCache,
620  $variable
621  );
622  } else {
623  $this->variableCache[$variable] = $value;
624  }
625  } // end func setVariable

◆ show()

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

Print a certain block with all replacements done.

get()

Definition at line 435 of file IT.php.

436  {
437  print $this->get($block);
438  } // 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 657 of file IT.php.

References errorMessage(), and IT_BLOCK_NOT_FOUND.

658  {
659  if (!isset($this->blocklist[$block])) {
661  '"' . $block . "'"));
662  }
663 
664  $this->touchedBlocks[$block] = true;
665 
666  return true;
667  } // end func touchBlock
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:993
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 284 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 356 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 250 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.

◆ $blockparents

HTML_Template_IT::$blockparents = array()

Definition at line 244 of file IT.php.

Referenced by ilTemplate\init().

◆ $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 307 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 315 of file IT.php.

◆ $flagBlocktrouble

HTML_Template_IT::$flagBlocktrouble = false

Definition at line 321 of file IT.php.

Referenced by ilTemplate\init().

◆ $flagCacheTemplatefile

HTML_Template_IT::$flagCacheTemplatefile = true

Definition at line 341 of file IT.php.

◆ $flagGlobalParsed

HTML_Template_IT::$flagGlobalParsed = false

Definition at line 327 of file IT.php.

◆ $lastTemplatefile

HTML_Template_IT::$lastTemplatefile = ''

EXPERIMENTAL! FIXME!

Definition at line 346 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(), loadTemplatefile(), and setTemplate().

◆ $removeUnknownVariables

HTML_Template_IT::$removeUnknownVariables = true

Definition at line 195 of file IT.php.

Referenced by ilTemplate\loadTemplatefile(), 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 277 of file IT.php.

◆ $variableCache

HTML_Template_IT::$variableCache = array()

Definition at line 296 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: