21include_once(
"./Services/UICore/lib/html-it/exceptions/class.ilTemplateException.php");
 
   24define(
'IT_ERROR',                     -1);
 
   25define(
'IT_TPL_NOT_FOUND',             -2);
 
   26define(
'IT_BLOCK_NOT_FOUND',           -3);
 
   27define(
'IT_BLOCK_DUPLICATE',           -4);
 
   28define(
'IT_UNKNOWN_OPTION',            -6);
 
  355        'preserve_data' => 
false,
 
  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';
 
  382        $this->blockRegExp = 
'@<!--\s+BEGIN\s+(' . $this->blocknameRegExp .
 
  383                             ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm';
 
  399        if (array_key_exists($option, $this->_options)) {
 
  400            $this->_options[$option] = $value;
 
  421            foreach (
$options as $option => $value) {
 
  433    function show($block = 
'__global__')
 
  435        print $this->
get($block);
 
  447    function get($block = 
'__global__')
 
  449        if ($block == 
'__global__'  && !$this->flagGlobalParsed) {
 
  450            $this->
parse(
'__global__');
 
  453        if (!isset($this->blocklist[$block])) {
 
  455                '"' . $block . 
"'"));
 
  458        if (isset($this->blockdata[$block])) {
 
  459            $ret = $this->blockdata[$block];
 
  460            if ($this->clearCache) {
 
  461                unset($this->blockdata[$block]);
 
  463            if ($this->_options[
'preserve_data']) {
 
  465                        $this->openingDelimiter .
 
  466                        '%preserved%' . $this->closingDelimiter,
 
  467                        $this->openingDelimiter,
 
  485    function parse($block = 
'__global__', $flag_recursion = 
false)
 
  487        static $regs, $values;
 
  489        if (!isset($this->blocklist[$block])) {
 
  491                '"' . $block . 
"'"));
 
  494        if ($block == 
'__global__') {
 
  495            $this->flagGlobalParsed = 
true;
 
  498        if (!$flag_recursion) {
 
  502        $outer = $this->blocklist[$block];
 
  505        if ($this->clearCacheOnParse) {
 
  506            foreach ($this->variableCache as $name => $value) {
 
  507                $regs[] = $this->openingDelimiter .
 
  512            $this->variableCache = array();
 
  514            foreach ($this->blockvariables[$block] as $allowedvar => $v) {
 
  516                if (isset($this->variableCache[$allowedvar])) {
 
  517                   $regs[]   = $this->openingDelimiter .
 
  519                   $values[] = $this->variableCache[$allowedvar];
 
  520                   unset($this->variableCache[$allowedvar]);
 
  526        if (isset($this->blockinner[$block])) {
 
  527            foreach ($this->blockinner[$block] as $k => $innerblock) {
 
  529                $this->
parse($innerblock, 
true);
 
  530                if ($this->blockdata[$innerblock] != 
'') {
 
  534                $placeholder = $this->openingDelimiter . 
"__" .
 
  536                $outer = str_replace(
 
  538                                    $this->blockdata[$innerblock], $outer
 
  540                $this->blockdata[$innerblock] = 
"";
 
  545        if (!$flag_recursion && 0 != count($values)) {
 
  546            if ($this->_options[
'use_preg']) {
 
  547                $regs        = array_map(array(
 
  548                                    &$this, 
'_addPregDelimiters'),
 
  551                $funcReplace = 
'preg_replace';
 
  553                $funcReplace = 
'str_replace';
 
  556            if ($this->_options[
'preserve_data']) {
 
  558                            array(&$this, 
'_preserveOpeningDelimiter'), $values
 
  562            $outer = $funcReplace($regs, $values, $outer);
 
  564            if ($this->removeUnknownVariables) {
 
  565                $outer = preg_replace($this->removeVariablesRegExp, 
"", $outer);
 
  570            if (!$this->removeEmptyBlocks) {
 
  571                $this->blockdata[$block ].= $outer;
 
  573                if (isset($this->touchedBlocks[$block])) {
 
  574                    $this->blockdata[$block] .= $outer;
 
  575                    unset($this->touchedBlocks[$block]);
 
  579            if (empty($this->blockdata[$block])) {
 
  580                $this->blockdata[$block] = $outer;
 
  582                $this->blockdata[$block] .= $outer;
 
  596        return $this->
parse($this->currentBlock);
 
  615        if (is_array($variable)) {
 
  616            $this->variableCache = array_merge(
 
  617                                            $this->variableCache, $variable
 
  620            $this->variableCache[$variable] = $value;
 
  636        if (!isset($this->blocklist[$block])) {
 
  638                '"' . $block . 
"'"));
 
  641        $this->currentBlock = $block;
 
  657        if (!isset($this->blocklist[$block])) {
 
  659                '"' . $block . 
"'"));
 
  662        $this->touchedBlocks[$block] = 
true;
 
  680        require_once(
'./Services/GlobalCache/classes/class.ilGlobalCache.php');
 
  683        if (
$blockdata = $blocks->get($this->real_filename)) {
 
  691            $blocks->set($this->real_filename, 
$blockdata, 60);
 
  695        $this->
template = 
'';
 
  702            $variables->set($this->real_filename, $this->blockvariables, 60);
 
  716        $this->err = array();
 
  718        $this->currentBlock = 
'__global__';
 
  720        $this->variableCache    = array();
 
  721        $this->blocklist        = array();
 
  722        $this->touchedBlocks    = array();
 
  724        $this->flagBlocktrouble = 
false;
 
  725        $this->flagGlobalParsed = 
false;
 
  747        if (
$template == 
'' && $this->flagCacheTemplatefile) {
 
  748            $this->variableCache = array();
 
  749            $this->blockdata = array();
 
  750            $this->touchedBlocks = array();
 
  751            $this->currentBlock = 
'__global__';
 
  753            $this->
template = 
'<!-- BEGIN __global__ -->' . $template .
 
  754                              '<!-- END __global__ -->';
 
  758        if ($this->flagBlocktrouble) {
 
  781        if (!$this->flagCacheTemplatefile ||
 
  807        if ($root != 
'' && substr($root, -1) != 
'/') {
 
  811        $this->fileRoot = $root;
 
  819        foreach ($this->blocklist as $name => $content) {
 
  820            preg_match_all($this->variablesRegExp, $content, $regs);
 
  822            if (count($regs[1]) != 0) {
 
  823                foreach ($regs[1] as $k => $var) {
 
  824                    $this->blockvariables[$name][$var] = 
true;
 
  827                $this->blockvariables[$name] = array();
 
  840        foreach ($this->blockvariables[
'__global__'] as $allowedvar => $v) {
 
  841            if (isset($this->variableCache[$allowedvar])) {
 
  842                $regs[]   = 
'@' . $this->openingDelimiter .
 
  843                            $allowedvar . $this->closingDelimiter . 
'@';
 
  844                $values[] = $this->variableCache[$allowedvar];
 
  845                unset($this->variableCache[$allowedvar]);
 
  849        return array($regs, $values);
 
  861        if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
 
  862            foreach ($regs as $k => $match) {
 
  863                $blockname         = $match[1];
 
  864                $blockcontent = $match[2];
 
  866                if (isset($this->blocklist[$blockname])) {
 
  871                $this->blocklist[$blockname] = $blockcontent;
 
  872                $this->blockdata[$blockname] = 
"";
 
  877                foreach ($inner as $k => $name) {
 
  879                        '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
 
  884                    $this->blocklist[$blockname] = preg_replace(
 
  886                                        $this->openingDelimiter .
 
  887                                        '__' . $name . 
'__' .
 
  888                                        $this->closingDelimiter,
 
  889                                        $this->blocklist[$blockname]
 
  891                    $this->blockinner[$blockname][] = $name;
 
  892                    $this->blockparents[$name] = $blockname;
 
  907        if (
$filename{0} == 
'/' && substr($this->fileRoot, -1) == 
'/') {
 
  913        require_once(
'./Services/GlobalCache/classes/class.ilGlobalCache.php');
 
  916        if(!$content = $ilGlobalCache->get(
$filename)) {
 
  928            $content = fread(
$fh, $fsize);
 
  929            $ilGlobalCache->set(
$filename, $content, 60);
 
  934        return preg_replace_callback(
 
  935            "#<!-- INCLUDE (.*) -->#im",
 
  937                return $this->
getFile($hit[1]);
 
  952        return '@' . $str . 
'@';
 
  963        return (
false === strpos($str, $this->openingDelimiter))?
 
  966                    $this->openingDelimiter,
 
  967                    $this->openingDelimiter .
 
  968                    '%preserved%' . $this->closingDelimiter,
 
  983        static $errorMessages;
 
  984        if (!isset($errorMessages)) {
 
  985            $errorMessages = array(
 
  991                                               ' uniquewithin a template.'.
 
  992                                               ' Found "' . $blockname . 
'" twice.'.
 
  993                                               'Unpredictable results '.
 
  999        return isset($errorMessages[$value]) ?
 
 1000                $errorMessages[$value] : $errorMessages[
IT_ERROR];
 
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
findBlocks($string)
Recusively builds a list of all blocks within the template.
getGlobalvariables()
Returns a list of all global variables.
free()
Clears all datafields of the object.
buildBlockvariablelist()
Build a list of all variables within of a block.
init()
Clears all datafields of the object and rebuild the internal blocklist.
_addPregDelimiters($str)
Adds delimiters to a string, so it can be used as a pattern in preg_* functions.
$_options
$_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data pass...
$lastTemplatefile
EXPERIMENTAL! FIXME!
setRoot($root)
Sets the file root.
errorMessage($value, $blockname='')
Return a textual error message for a IT error code.
setCurrentBlock($block='__global__')
Sets the name of the current block that is the block where variables are added.
setOptions($options)
Sets the options for the template class.
setOption($option, $value)
Sets the option for the template class.
$removeVariablesRegExp
RegExp used to strip unused variable placeholder.
parseCurrentBlock()
Parses the current block.
loadTemplatefile( $filename, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Reads a template file from the disk.
$_hiddenBlocks
List of blocks which should not be shown even if not "empty".
__construct($root='', $options=null)
Builds some complex regular expressions and optinally sets the file root directory.
show($block='__global__')
Print a certain block with all replacements done.
setVariable($variable, $value='')
Sets a variable value.
getFile($filename)
Reads a file from disk and returns its content.
parse($block='__global__', $flag_recursion=false)
Parses the given block.
setTemplate( $template, $removeUnknownVariables=true, $removeEmptyBlocks=true)
Sets the template.
$touchedBlocks
List of blocks to preverse even if they are "empty".
touchBlock($block)
Preserves an empty block even if removeEmptyBlocks is true.
_preserveOpeningDelimiter($str)
Replaces an opening delimiter by a special string.
static log($message, $log_level)
static getInstance($component)
Integrated Template - IT.
if(!is_array($argv)) $options