ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTML_Template_IT Class Reference
+ Inheritance diagram for HTML_Template_IT:
+ Collaboration diagram for HTML_Template_IT:

Public Member Functions

 HTML_Template_IT ($root='', $options=null)
 Builds some complex regular expressions and optinally sets the file root directory. More...
 
 setOption ($option, $value)
 Sets the option for the template class. More...
 
 setOptions ($options)
 Sets the options for the template class. More...
 
 show ($block='__global__')
 Print a certain block with all replacements done. More...
 
 get ($block='__global__')
 Returns a block with all replacements done. More...
 
 parse ($block='__global__', $flag_recursion=false)
 Parses the given block. More...
 
 parseCurrentBlock ()
 Parses the current block. More...
 
 setVariable ($variable, $value='')
 Sets a variable value. More...
 
 setCurrentBlock ($block='__global__')
 Sets the name of the current block that is the block where variables are added. More...
 
 touchBlock ($block)
 Preserves an empty block even if removeEmptyBlocks is true. More...
 
 init ()
 Clears all datafields of the object and rebuild the internal blocklist. More...
 
 free ()
 Clears all datafields of the object. More...
 
 setTemplate ( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 Sets the template. More...
 
 loadTemplatefile ( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
 Reads a template file from the disk. More...
 
 setRoot ($root)
 Sets the file root. More...
 
 buildBlockvariablelist ()
 Build a list of all variables within of a block. More...
 
 getGlobalvariables ()
 Returns a list of all global variables. More...
 
 findBlocks ($string)
 Recusively builds a list of all blocks within the template. More...
 
 getFile ($filename)
 Reads a file from disk and returns its content. More...
 
 _addPregDelimiters ($str)
 Adds delimiters to a string, so it can be used as a pattern in preg_* functions. More...
 
 _preserveOpeningDelimiter ($str)
 Replaces an opening delimiter by a special string. More...
 
 errorMessage ($value, $blockname='')
 Return a textual error message for a IT error code. More...
 

Data Fields

 $err = array()
 
 $clearCache = false
 
 $openingDelimiter = '{'
 
 $closingDelimiter = '}'
 
 $blocknameRegExp = '[\.0-9A-Za-z_-]+'
 
 $variablenameRegExp = '[\.0-9A-Za-z_-]+'
 
 $variablesRegExp = ''
 
 $removeVariablesRegExp = ''
 RegExp used to strip unused variable placeholder. More...
 
 $removeUnknownVariables = true
 
 $removeEmptyBlocks = true
 
 $blockRegExp = ''
 
 $currentBlock = '__global__'
 
 $template = ''
 
 $blocklist = array()
 
 $blockdata = array()
 
 $blockvariables = array()
 
 $blockinner = array()
 
 $touchedBlocks = array()
 List of blocks to preverse even if they are "empty". More...
 
 $_hiddenBlocks = array()
 List of blocks which should not be shown even if not "empty". More...
 
 $variableCache = array()
 
 $clearCacheOnParse = false
 
 $fileRoot = ''
 
 $flagBlocktrouble = false
 
 $flagGlobalParsed = false
 
 $flagCacheTemplatefile = true
 
 $lastTemplatefile = ''
 EXPERIMENTAL! FIXME! More...
 
 $_options
 $_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951). More...
 

Detailed Description

Definition at line 124 of file IT.php.

Member Function Documentation

◆ _addPregDelimiters()

HTML_Template_IT::_addPregDelimiters (   $str)

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

Parameters
string
Returns
string

Definition at line 974 of file IT.php.

975 {
976 return '@' . $str . '@';
977 }

◆ _preserveOpeningDelimiter()

HTML_Template_IT::_preserveOpeningDelimiter (   $str)

Replaces an opening delimiter by a special string.

Parameters
string
Returns
string

Definition at line 985 of file IT.php.

986 {
987 return (false === strpos($str, $this->openingDelimiter))?
988 $str:
989 str_replace(
990 $this->openingDelimiter,
991 $this->openingDelimiter .
992 '%preserved%' . $this->closingDelimiter,
993 $str
994 );
995 }

◆ buildBlockvariablelist()

HTML_Template_IT::buildBlockvariablelist ( )

Build a list of all variables within of a block.

Definition at line 833 of file IT.php.

834 {
835 foreach ($this->blocklist as $name => $content) {
836 preg_match_all($this->variablesRegExp, $content, $regs);
837
838 if (count($regs[1]) != 0) {
839 foreach ($regs[1] as $k => $var) {
840 $this->blockvariables[$name][$var] = true;
841 }
842 } else {
843 $this->blockvariables[$name] = array();
844 }
845 }
846 } // end func buildBlockvariablelist

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

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

1006 {
1007 static $errorMessages;
1008 if (!isset($errorMessages)) {
1009 $errorMessages = array(
1010 IT_OK => '',
1011 IT_ERROR => 'unknown error',
1012 IT_TPL_NOT_FOUND => 'Cannot read the template file',
1013 IT_BLOCK_NOT_FOUND => 'Cannot find this block',
1014 IT_BLOCK_DUPLICATE => 'The name of a block must be'.
1015 ' uniquewithin a template.'.
1016 ' Found "' . $blockname . '" twice.'.
1017 'Unpredictable results '.
1018 'may appear.',
1019 IT_UNKNOWN_OPTION => 'Unknown option'
1020 );
1021 }
1022
1023 if (PEAR::isError($value)) {
1024 $value = $value->getCode();
1025 }
1026
1027 return isset($errorMessages[$value]) ?
1028 $errorMessages[$value] : $errorMessages[IT_ERROR];
1029 }
const IT_UNKNOWN_OPTION
Definition: IT.php:28
const IT_OK
Definition: IT.php:23
const IT_TPL_NOT_FOUND
Definition: IT.php:25
const IT_BLOCK_DUPLICATE
Definition: IT.php:27
const IT_ERROR
Definition: IT.php:24
const IT_BLOCK_NOT_FOUND
Definition: IT.php:26
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findBlocks()

HTML_Template_IT::findBlocks (   $string)

Recusively builds a list of all blocks within the template.

Parameters
stringstring that gets scanned
See also
$blocklist

Definition at line 874 of file IT.php.

875 {
876 $blocklist = array();
877 if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
878 foreach ($regs as $k => $match) {
879 $blockname = $match[1];
880 $blockcontent = $match[2];
881
882 if (isset($this->blocklist[$blockname])) {
883 $this->err[] = PEAR::raiseError(
884 $this->errorMessage(
885 IT_BLOCK_DUPLICATE, $blockname),
887 );
888 $this->flagBlocktrouble = true;
889 }
890
891 $this->blocklist[$blockname] = $blockcontent;
892 $this->blockdata[$blockname] = "";
893
894 $blocklist[] = $blockname;
895
896 $inner = $this->findBlocks($blockcontent);
897 foreach ($inner as $k => $name) {
898 $pattern = sprintf(
899 '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
900 $name,
901 $name
902 );
903
904 $this->blocklist[$blockname] = preg_replace(
905 $pattern,
906 $this->openingDelimiter .
907 '__' . $name . '__' .
908 $this->closingDelimiter,
909 $this->blocklist[$blockname]
910 );
911 $this->blockinner[$blockname][] = $name;
912 $this->blockparents[$name] = $blockname;
913 }
914 }
915 }
916
917 return $blocklist;
918 } // end func findBlocks
findBlocks($string)
Recusively builds a list of all blocks within the template.
Definition: IT.php:874
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
Definition: IT.php:1005
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524

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

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

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

@access public

See also
init()

Definition at line 730 of file IT.php.

731 {
732 $this->err = array();
733
734 $this->currentBlock = '__global__';
735
736 $this->variableCache = array();
737 $this->blocklist = array();
738 $this->touchedBlocks = array();
739
740 $this->flagBlocktrouble = false;
741 $this->flagGlobalParsed = false;
742 } // end func free

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

+ Here is the caller graph for this function:

◆ get()

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

Returns a block with all replacements done.

Parameters
stringname of the block
Returns
string
Exceptions
PEAR_Error@access public
See also
show()

Reimplemented in ilTemplate.

Definition at line 454 of file IT.php.

455 {
456 if ($block == '__global__' && !$this->flagGlobalParsed) {
457 $this->parse('__global__');
458 }
459
460 if (!isset($this->blocklist[$block])) {
461 $this->err[] = PEAR::raiseError(
463 '"' . $block . "'",
465 );
466 return '';
467 }
468
469 if (isset($this->blockdata[$block])) {
470 $ret = $this->blockdata[$block];
471 if ($this->clearCache) {
472 unset($this->blockdata[$block]);
473 }
474 if ($this->_options['preserve_data']) {
475 $ret = str_replace(
476 $this->openingDelimiter .
477 '%preserved%' . $this->closingDelimiter,
478 $this->openingDelimiter,
479 $ret
480 );
481 }
482 return $ret;
483 }
484
485 return '';
486 } // end func get()
parse($block='__global__', $flag_recursion=false)
Parses the given block.
Definition: IT.php:496

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

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

926 {
927 if ($filename{0} == '/' && substr($this->fileRoot, -1) == '/') {
928 $filename = substr($filename, 1);
929 }
930
931 $filename = $this->fileRoot . $filename;
932
933 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
934 $this->real_filename = $filename;
936 if(!$content = $ilGlobalCache->get($filename)) {
937 if (!($fh = @fopen($filename, 'r'))) {
938 $this->err[] = PEAR::raiseError(
940 ': "' .$filename .'"',
942 );
943 return "";
944 }
945
946 $fsize = filesize($filename);
947 if ($fsize < 1) {
948 fclose($fh);
949 return '';
950 }
951
952 $content = fread($fh, $fsize);
953 $ilGlobalCache->set($filename, $content, 60);
954 fclose($fh);
955 }
956
957
958 return preg_replace_callback(
959 "#<!-- INCLUDE (.*) -->#im",
960 function ($hit) {
961 return $this->getFile($hit[1]);
962 },
963 $content
964 );
965 } // end func getFile
$filename
Definition: buildRTE.php:89
getFile($filename)
Reads a file from disk and returns its content.
Definition: IT.php:925
static getInstance($component)

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

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

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

852 {
853 $regs = array();
854 $values = array();
855
856 foreach ($this->blockvariables['__global__'] as $allowedvar => $v) {
857 if (isset($this->variableCache[$allowedvar])) {
858 $regs[] = '@' . $this->openingDelimiter .
859 $allowedvar . $this->closingDelimiter . '@';
860 $values[] = $this->variableCache[$allowedvar];
861 unset($this->variableCache[$allowedvar]);
862 }
863 }
864
865 return array($regs, $values);
866 } // end func getGlobalvariables

◆ HTML_Template_IT()

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

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

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

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

Definition at line 370 of file IT.php.

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
setRoot($root)
Sets the file root.
Definition: IT.php:821
setOptions($options)
Sets the options for the template class.
Definition: IT.php:422
if(!is_array($argv)) $options

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

Referenced by HTML_Template_ITX\HTML_Template_ITX().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

HTML_Template_IT::init ( )

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

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

@access public

See also
free()

Reimplemented in HTML_Template_ITX, and ilTemplate.

Definition at line 693 of file IT.php.

694 {
695 $this->free();
696 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
698
699 if ($blockdata = $blocks->get($this->real_filename)) {
700 $this->blockdata = $blockdata['blockdata'];
701 $this->blocklist = $blockdata['blocklist'];
702 } else {
704 $this->findBlocks($this->template);
705 $blockdata['blockdata'] = $this->blockdata;
706 $blockdata['blocklist'] = $this->blocklist;
707 $blocks->set($this->real_filename, $blockdata, 60);
708 }
709
710 // we don't need it any more
711 $this->template = '';
712
714 if ($blockvariables = $variables->get($this->real_filename)) {
715 $this->blockvariables = $blockvariables;
716 } else {
717 $this->buildBlockvariablelist();
718 $variables->set($this->real_filename, $this->blockvariables, 60);
719 }
720 } // end func init
free()
Clears all datafields of the object.
Definition: IT.php:730
buildBlockvariablelist()
Build a list of all variables within of a block.
Definition: IT.php:833
static log($message, $log_level)

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

+ 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. @access public
Returns
boolean false on failure, otherwise true
See also
$template, setTemplate(), $removeUnknownVariables, $removeEmptyBlocks

Reimplemented in ilTemplate.

Definition at line 792 of file IT.php.

795 {
796 $template = '';
797 if (!$this->flagCacheTemplatefile ||
798 $this->lastTemplatefile != $filename
799 ) {
800 $template = $this->getFile($filename);
801 }
802 $this->lastTemplatefile = $filename;
803
804 return $template != '' ?
805 $this->setTemplate(
807 ) : false;
808 } // end func LoadTemplatefile
$removeEmptyBlocks
Definition: IT.php:202
$removeUnknownVariables
Definition: IT.php:195
setTemplate( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Sets the template.
Definition: IT.php:757

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

+ Here is the call graph for this function:

◆ parse()

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

Parses the given block.

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

Definition at line 496 of file IT.php.

497 {
498 static $regs, $values;
499
500 if (!isset($this->blocklist[$block])) {
501 return PEAR::raiseError(
502 $this->errorMessage( IT_BLOCK_NOT_FOUND ) . '"' . $block . "'",
504 );
505 }
506
507 if ($block == '__global__') {
508 $this->flagGlobalParsed = true;
509 }
510
511 if (!$flag_recursion) {
512 $regs = array();
513 $values = array();
514 }
515 $outer = $this->blocklist[$block];
516 $empty = true;
517
518 if ($this->clearCacheOnParse) {
519 foreach ($this->variableCache as $name => $value) {
520 $regs[] = $this->openingDelimiter .
522 $values[] = $value;
523 $empty = false;
524 }
525 $this->variableCache = array();
526 } else {
527 foreach ($this->blockvariables[$block] as $allowedvar => $v) {
528
529 if (isset($this->variableCache[$allowedvar])) {
530 $regs[] = $this->openingDelimiter .
531 $allowedvar . $this->closingDelimiter;
532 $values[] = $this->variableCache[$allowedvar];
533 unset($this->variableCache[$allowedvar]);
534 $empty = false;
535 }
536 }
537 }
538
539 if (isset($this->blockinner[$block])) {
540 foreach ($this->blockinner[$block] as $k => $innerblock) {
541
542 $this->parse($innerblock, true);
543 if ($this->blockdata[$innerblock] != '') {
544 $empty = false;
545 }
546
547 $placeholder = $this->openingDelimiter . "__" .
548 $innerblock . "__" . $this->closingDelimiter;
549 $outer = str_replace(
550 $placeholder,
551 $this->blockdata[$innerblock], $outer
552 );
553 $this->blockdata[$innerblock] = "";
554 }
555
556 }
557
558 if (!$flag_recursion && 0 != count($values)) {
559 if ($this->_options['use_preg']) {
560 $regs = array_map(array(
561 &$this, '_addPregDelimiters'),
562 $regs
563 );
564 $funcReplace = 'preg_replace';
565 } else {
566 $funcReplace = 'str_replace';
567 }
568
569 if ($this->_options['preserve_data']) {
570 $values = array_map(
571 array(&$this, '_preserveOpeningDelimiter'), $values
572 );
573 }
574
575 $outer = $funcReplace($regs, $values, $outer);
576
577 if ($this->removeUnknownVariables) {
578 $outer = preg_replace($this->removeVariablesRegExp, "", $outer);
579 }
580 }
581
582 if ($empty) {
583 if (!$this->removeEmptyBlocks) {
584 $this->blockdata[$block ].= $outer;
585 } else {
586 if (isset($this->touchedBlocks[$block])) {
587 $this->blockdata[$block] .= $outer;
588 unset($this->touchedBlocks[$block]);
589 }
590 }
591 } else {
592 if (empty($this->blockdata[$block])) {
593 $this->blockdata[$block] = $outer;
594 } else {
595 $this->blockdata[$block] .= $outer;
596 }
597 }
598
599 return $empty;
600 } // end func parse

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

Referenced by get(), parse(), and parseCurrentBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseCurrentBlock()

◆ setCurrentBlock()

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

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

Parameters
stringname of the block
Returns
boolean false on failure, otherwise true
Exceptions
PEAR_Error@access public

Reimplemented in ilTemplate, and ilTemplate.

Definition at line 646 of file IT.php.

647 {
648
649 if (!isset($this->blocklist[$block])) {
650 return PEAR::raiseError(
652 '"' . $block . "'", IT_BLOCK_NOT_FOUND
653 );
654 }
655
656 $this->currentBlock = $block;
657
658 return true;
659 } // end func setCurrentBlock

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

+ Here is the call graph for this function:

◆ setOption()

HTML_Template_IT::setOption (   $option,
  $value 
)

Sets the option for the template class.

@access public

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

Definition at line 397 of file IT.php.

398 {
399 if (array_key_exists($option, $this->_options)) {
400 $this->_options[$option] = $value;
401 return IT_OK;
402 }
403
404 return PEAR::raiseError(
405 $this->errorMessage(IT_UNKNOWN_OPTION) . ": '{$option}'",
407 );
408 }

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

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

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

@access public

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

Definition at line 422 of file IT.php.

423 {
424 if (is_array($options)) {
425 foreach ($options as $option => $value) {
426 $error = $this->setOption($option, $value);
427 if (PEAR::isError($error)) {
428 return $error;
429 }
430 }
431 }
432
433 return IT_OK;
434 }
setOption($option, $value)
Sets the option for the template class.
Definition: IT.php:397

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

Referenced by HTML_Template_IT().

+ 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() @access User interface

Definition at line 821 of file IT.php.

822 {
823 if ($root != '' && substr($root, -1) != '/') {
824 $root .= '/';
825 }
826
827 $this->fileRoot = $root;
828 } // end func setRoot

Referenced by HTML_Template_IT().

+ 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 @access User interface
Returns
boolean

Definition at line 757 of file IT.php.

759 {
760 $this->removeUnknownVariables = $removeUnknownVariables;
761 $this->removeEmptyBlocks = $removeEmptyBlocks;
762
763 if ($template == '' && $this->flagCacheTemplatefile) {
764 $this->variableCache = array();
765 $this->blockdata = array();
766 $this->touchedBlocks = array();
767 $this->currentBlock = '__global__';
768 } else {
769 $this->template = '<!-- BEGIN __global__ -->' . $template .
770 '<!-- END __global__ -->';
771 $this->init();
772 }
773
774 if ($this->flagBlocktrouble) {
775 return false;
776 }
777
778 return true;
779 } // end func setTemplate
init()
Clears all datafields of the object and rebuild the internal blocklist.
Definition: IT.php:693

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

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

+ 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 @access public

Definition at line 626 of file IT.php.

627 {
628 if (is_array($variable)) {
629 $this->variableCache = array_merge(
630 $this->variableCache, $variable
631 );
632 } else {
633 $this->variableCache[$variable] = $value;
634 }
635 } // end func setVariable

Referenced by ilContainerRenderer\addHeaderRow(), ilTemplate\addILIASFooter(), 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(), ilCaptchaInputGUI\insert(), ilEMailInputGUI\insert(), ilClozeGapInputBuilderGUI\insert(), ilAssLacLegendGUI\populateVisibilityCss(), ilContainerRenderer\renderDetails(), ilChatroomViewTask\renderFileUploadForm(), ilSurveyPageGUI\renderPageNode(), ilContainerRenderer\renderSelectAllBlock(), ilTemplate\replace(), ilTemplate\setBackgroundColor(), ilTemplate\setBanner(), ilTemplate\setCenterColumnClass(), ilTemplate\setLocator(), ilTemplate\setNewContentStyleSheetLocation(), ilTemplate\setStyleSheetLocation(), ilTemplate\setSubTabs(), ilTemplate\setTabs(), and ilTemplate\show().

+ Here is the caller graph for this function:

◆ show()

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

Print a certain block with all replacements done.

@brother get()

Reimplemented in ilTemplate.

Definition at line 440 of file IT.php.

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

References print.

◆ touchBlock()

HTML_Template_IT::touchBlock (   $block)

Preserves an empty block even if removeEmptyBlocks is true.

Parameters
stringname of the block
Returns
boolean false on false, otherwise true
Exceptions
PEAR_Error@access public
See also
$removeEmptyBlocks

Reimplemented in ilTemplate, and ilTemplate.

Definition at line 670 of file IT.php.

671 {
672 if (!isset($this->blocklist[$block])) {
673 return PEAR::raiseError(
675 '"' . $block . "'", IT_BLOCK_NOT_FOUND);
676 }
677
678 $this->touchedBlocks[$block] = true;
679
680 return true;
681 } // end func touchBlock

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

+ 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 init(), ilTemplate\init(), and HTML_Template_ITX\replaceBlock().

◆ $blockinner

HTML_Template_IT::$blockinner = array()

Definition at line 248 of file IT.php.

Referenced by ilTemplate\init().

◆ $blocklist

HTML_Template_IT::$blocklist = array()

Definition at line 229 of file IT.php.

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

◆ $blocknameRegExp

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

Definition at line 164 of file IT.php.

◆ $blockRegExp

HTML_Template_IT::$blockRegExp = ''

Definition at line 209 of file IT.php.

◆ $blockvariables

HTML_Template_IT::$blockvariables = array()

Definition at line 242 of file IT.php.

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

◆ $clearCache

HTML_Template_IT::$clearCache = false

Definition at line 138 of file IT.php.

◆ $clearCacheOnParse

HTML_Template_IT::$clearCacheOnParse = false

Definition at line 305 of file IT.php.

◆ $closingDelimiter

HTML_Template_IT::$closingDelimiter = '}'

Definition at line 154 of file IT.php.

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

◆ $currentBlock

HTML_Template_IT::$currentBlock = '__global__'

Definition at line 215 of file IT.php.

◆ $err

HTML_Template_IT::$err = array()

Definition at line 132 of file IT.php.

Referenced by ilTemplate\init().

◆ $fileRoot

HTML_Template_IT::$fileRoot = ''

Definition at line 313 of file IT.php.

◆ $flagBlocktrouble

HTML_Template_IT::$flagBlocktrouble = false

Definition at line 319 of file IT.php.

Referenced by ilTemplate\init().

◆ $flagCacheTemplatefile

HTML_Template_IT::$flagCacheTemplatefile = true

Definition at line 339 of file IT.php.

◆ $flagGlobalParsed

HTML_Template_IT::$flagGlobalParsed = false

Definition at line 325 of file IT.php.

◆ $lastTemplatefile

HTML_Template_IT::$lastTemplatefile = ''

EXPERIMENTAL! FIXME!

Definition at line 344 of file IT.php.

◆ $openingDelimiter

HTML_Template_IT::$openingDelimiter = '{'

Definition at line 146 of file IT.php.

◆ $removeEmptyBlocks

HTML_Template_IT::$removeEmptyBlocks = true

Definition at line 202 of file IT.php.

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

◆ $removeUnknownVariables

HTML_Template_IT::$removeUnknownVariables = true

Definition at line 195 of file IT.php.

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

◆ $removeVariablesRegExp

HTML_Template_IT::$removeVariablesRegExp = ''

RegExp used to strip unused variable placeholder.

@brother $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: