3declare(strict_types=1);
 
   88        $this->checkblocknameRegExp = 
'@' . $this->blocknameRegExp . 
'@';
 
   89        $this->functionRegExp = 
'@' . $this->functionPrefix . 
'(' .
 
   90            $this->functionnameRegExp . 
')\s*\(@sm';
 
   95    protected function init(): void
 
  101        $this->
template = 
'';
 
  123        if (!isset($this->blocklist[$block])) {
 
  124            throw new ilTemplateException(
"The block " . 
"'$block'" . 
" does not exist in the template and thus it can't be replaced.");
 
  139        $parents = $this->blockparents[$block];
 
  141        $this->blockparents[$block] = $parents;
 
  176        if ($placeholder === 
'') {
 
  180        if ($blockname === 
'' ||
 
  181            !preg_match($this->checkblocknameRegExp, $blockname)) {
 
  189        if (isset($this->blocklist[$blockname])) {
 
  195        if (count($parents) === 0) {
 
  197                " '$placeholder' was not found in the template."));
 
  200        if (count($parents) > 1) {
 
  202            foreach ($parents as 
$index => $parent) {
 
  203                $msg .= (isset($parents[
$index + 1])) ?
 
  204                    "$parent, " : $parent;
 
  207            throw new ilTemplateException(
"The variable placeholder " . 
"'$placeholder'" . 
" must be unique, found in multiple blocks '$msg'.");
 
  212        if ($this->flagBlocktrouble) {
 
  215        $this->blockinner[$parents[0]][] = $blockname;
 
  216        $this->blocklist[$parents[0]] = preg_replace(
 
  217            '@' . $this->openingDelimiter . $placeholder .
 
  218            $this->closingDelimiter . 
'@',
 
  219            $this->openingDelimiter . 
'__' . $blockname . 
'__' .
 
  220            $this->closingDelimiter,
 
  221            $this->blocklist[$parents[0]]
 
  237        return $this->
addBlock($placeholder, $blockname, $this->
getFile($filename));
 
  245        if (isset($this->blockinner[$block])) {
 
  246            foreach ($this->blockinner[$block] as $inner) {
 
  250            unset($this->blockinner[$block]);
 
  254            $this->blocklist[$block],
 
  255            $this->blockdata[$block],
 
  256            $this->blockvariables[$block],
 
  257            $this->touchedBlocks[$block]
 
  266        return isset($this->blocklist[$blockname]);
 
  274        $this->functions = [];
 
  279        while (preg_match($this->functionRegExp, 
$template, $regs)) {
 
  286            $search = $regs[0] . $head . 
')';
 
  288            $replace = $this->openingDelimiter .
 
  289                '__function' . $num . 
'__' .
 
  292            $this->
template = str_replace($search, $replace, $this->
template);
 
  295            while ($head !== 
'' && $args2 = $this->
getValue($head, 
',')) {
 
  296                $arg2 = trim($args2);
 
  297                $args[] = (
'"' === $arg2[0] || 
"'" === $arg2[0]) ?
 
  298                    substr($arg2, 1, -1) : $arg2;
 
  299                if ($arg2 === $head) {
 
  302                $head = substr($head, strlen($arg2) + 1);
 
  305            $this->functions[$num++] = [
 
  317    public function getValue(
string $code, $delimiter): string
 
  323        if (!is_array($delimiter)) {
 
  324            $delimiter = [$delimiter => 
true];
 
  327        $len = strlen($code);
 
  331        if (isset($delimiter[$code[0]])) {
 
  334            for (
$i = 0; 
$i < $len; ++
$i) {
 
  338                    ($char === 
'"' || $char === 
"'") &&
 
  339                    ($char === $enclosed_by || 
'' === $enclosed_by) &&
 
  340                    (0 === 
$i || (
$i > 0 && 
'\\' !== $code[
$i - 1]))
 
  343                        $enclosed_by = $char;
 
  347                    $enclosed = !$enclosed;
 
  350                if (!$enclosed && isset($delimiter[$char])) {
 
  356        return substr($code, 0, 
$i);
 
  366        if (!is_array($variables)) {
 
  367            $variables = [$variables => 
true];
 
  370        reset($this->blockvariables[$block]);
 
  371        foreach ($this->blockvariables[$block] as $varname => $val) {
 
  372            if (isset($variables[$varname])) {
 
  373                unset($this->blockvariables[$block][$varname]);
 
  384            $this->variablesRegExp,
 
  385            $this->blocklist[$block],
 
  389        if (count($regs[1]) !== 0) {
 
  390            foreach ($regs[1] as $var) {
 
  391                $this->blockvariables[$block][$var] = 
true;
 
  394            $this->blockvariables[$block] = [];
 
  398        if (isset($this->blockinner[$block]) &&
 
  399            is_array($this->blockinner[$block]) &&
 
  400            count($this->blockinner[$block]) > 0
 
  406            foreach ($this->blockinner[$block] as $childBlock) {
 
  419        reset($this->blocklist);
 
  420        foreach ($this->blocklist as $blockname => $content) {
 
  421            reset($this->blockvariables[$blockname]);
 
  422            foreach ($this->blockvariables[$blockname] as $varname => $val) {
 
  423                if ($variable === $varname) {
 
  424                    $parents[] = $blockname;
 
  439            'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
 
  447        if ($this->printWarning) {
 
  451        if ($this->haltOnWarning) {
 
Integrated Template Extension - ITX With this class you get the full power of the phplib template cla...
 
bool $haltOnWarning
Call die() on warning?
 
string $functionPrefix
Functionnameprefix used when searching function calls in the template.
 
addBlock(string $placeholder, string $blockname, string $template)
Adds a block to the template changing a variable placeholder to a block placeholder.
 
removeBlockData(string $block)
Recursively removes all data assiciated with a block, including all inner blocks.
 
array $warn
Array with all warnings.
 
addBlockfile(string $placeholder, string $blockname, string $filename)
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder...
 
deleteFromBlockvariablelist(string $block, $variables)
Deletes one or many variables from the block variable list.
 
findPlaceholderBlocks(string $variable)
Returns an array of blocknames where the given variable placeholder is used.
 
updateBlockvariablelist(string $block)
Updates the variable list of a block.
 
buildFunctionlist()
Builds a functionlist from the template.
 
blockExists(string $blockname)
Checks wheter a block exists.
 
array $callback
List of callback functions specified by the user.
 
array $functions
List of functions found in the template.
 
init()
Clears all datafields of the object and rebuild the internal blocklist LoadTemplatefile() and setTemp...
 
string $functionnameRegExp
Functionname RegExp.
 
getValue(string $code, $delimiter)
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " ...
 
string $functionRegExp
RegExp used to grep function calls in the template.
 
string $checkblocknameRegExp
RegExp used to test for a valid blockname.
 
__construct(string $root='')
Builds some complex regexps and calls the constructor of the parent class.
 
replaceBlock(string $block, string $template, bool $keep_content=false)
Replaces an existing block with new content.
 
bool $printWarning
Print warnings?
 
warning(string $message, string $file='', int $line=0)
Handles warnings, saves them to $warn and prints them or calls die() depending on the flags.
 
Integrated Template - IT Well there's not much to say about it.
 
string $closingDelimiter
Last character of a variable placeholder ( {VARIABLE_}_ ).
 
free()
Clears all datafields of the object.
 
buildBlockvariablelist()
Build a list of all variables within of a block.
 
string $template
Content of the template.
 
findBlocks(string $string)
Recusively builds a list of all blocks within the template.
 
array $blockdata
Array with the parsed content of a block.
 
getFile(string $filename)
Reads a file from disk and returns its content.
 
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc