21 require_once
'HTML/Template/IT.php';
22 require_once
'HTML/Template/IT_Error.php';
121 $this->checkblocknameRegExp =
'@' . $this->blocknameRegExp .
'@';
122 $this->functionRegExp =
'@' . $this->functionPrefix .
'(' .
123 $this->functionnameRegExp .
')\s*\(@sm';
134 $this->
template =
'';
166 if (!isset($this->blocklist[$block])) {
168 "The block ".
"'$block'".
169 " does not exist in the template and thus it can't be replaced.",
175 return new IT_Error(
'No block content given.', __FILE__, __LINE__);
186 $parents = $this->blockparents[$block];
188 $this->blockparents[$block] = $parents;
251 if ($placeholder ==
'') {
252 return new IT_Error(
'No variable placeholder given.',
255 } elseif ($blockname ==
'' ||
256 !preg_match($this->checkblocknameRegExp, $blockname)
258 return new IT_Error(
"No or invalid blockname '$blockname' given.",
262 return new IT_Error(
'No block content given.', __FILE__, __LINE__);
263 } elseif (isset($this->blocklist[$blockname])) {
264 return new IT_Error(
'The block already exists.',
271 if (count($parents) == 0) {
274 "The variable placeholder".
275 " '$placeholder' was not found in the template.",
279 } elseif (count($parents) > 1) {
282 while (list($k, $parent) = each($parents)) {
285 $msg = substr($parent, -2);
287 return new IT_Error(
"The variable placeholder ".
"'$placeholder'".
288 " must be unique, found in multiple blocks '$msg'.",
295 if ($this->flagBlocktrouble) {
298 $this->blockinner[$parents[0]][] = $blockname;
299 $this->blocklist[$parents[0]] = preg_replace(
300 '@' . $this->openingDelimiter . $placeholder .
301 $this->closingDelimiter .
'@',
303 $this->openingDelimiter .
'__' . $blockname .
'__' .
304 $this->closingDelimiter,
306 $this->blocklist[$parents[0]]
346 if ($placeholder ==
'') {
347 new IT_Error(
'No placeholder name given.', __FILE__, __LINE__);
351 if ($block !=
'' && !isset($this->blocklist[$block])) {
352 new IT_Error(
"Unknown block '$block'.", __FILE__, __LINE__);
360 if (is_array($variables = $this->blockvariables[$block])) {
363 while (list($k, $variable) = each($variables)) {
364 if ($k == $placeholder) {
374 reset($this->blockvariables);
375 while (list($blockname, $variables) = each($this->blockvariables)){
376 if (is_array($variables) && isset($variables[$placeholder])) {
394 reset($this->functions);
395 while (list($func_id, $function) = each($this->functions)) {
396 if (isset($this->callback[$function[
'name']])) {
397 if ($this->callback[$function[
'name']][
'expandParameters']) {
398 $callFunction =
'call_user_func_array';
400 $callFunction =
'call_user_func';
403 if ($this->callback[$function[
'name']][
'object'] !=
'') {
407 &
$GLOBALS[$this->callback[$function[
'name']][
'object']],
408 $this->callback[$function[
'name']][
'function']),
415 $this->callback[$function[
'name']][
'function'],
419 $this->variableCache[
'__function' . $func_id .
'__'] = $call;
445 $this->variableCache[
'__function' . $functionID .
'__'] = $replacement;
496 setCallbackFunction($tplfunction, $callbackfunction, $callbackobject =
'', $expandCallbackParameters=
false)
498 if ($tplfunction ==
'' || $callbackfunction ==
'') {
500 "No template function ".
"('$tplfunction')".
501 " and/or no callback function ('$callback') given.",
505 $this->callback[$tplfunction] = array(
506 'function' => $callbackfunction,
507 'object' => $callbackobject,
508 'expandParameters' => (
boolean) $expandCallbackParameters
538 if (isset($this->blockinner[$block])) {
539 foreach ($this->blockinner[$block] as $k => $inner) {
543 unset($this->blockinner[$block]);
546 unset($this->blocklist[$block]);
547 unset($this->blockdata[$block]);
548 unset($this->blockvariables[$block]);
549 unset($this->touchedBlocks[$block]);
563 foreach ($this->blocklist as $block => $content) {
580 return isset($this->blocklist[$blockname]);
593 if (!isset($this->blockvariables[$block])) {
597 $variables = array();
598 foreach ($this->blockvariables[$block] as $variable => $v) {
599 $variables[$variable] = $variable;
616 return isset($this->blockvariables[$block][$variable]);
625 $this->functions = array();
630 while (preg_match($this->functionRegExp,
$template, $regs)) {
638 $search = $regs[0] . $head .
')';
640 $replace = $this->openingDelimiter .
641 '__function' . $num .
'__' .
644 $this->
template = str_replace($search, $replace, $this->
template);
647 while ($head !=
'' && $args2 = $this->
getValue($head,
',')) {
648 $arg2 = trim($args2);
649 $args[] = (
'"' == $arg2{0} ||
"'" == $arg2{0}) ?
650 substr($arg2, 1, -1) : $arg2;
651 if ($arg2 == $head) {
654 $head = substr($head, strlen($arg2) + 1);
657 $this->functions[$num++] = array(
680 if (!is_array($delimiter)) {
681 $delimiter = array( $delimiter =>
true );
684 $len = strlen($code);
688 if (isset($delimiter[$code[0]])) {
691 for ($i = 0; $i < $len; ++$i) {
695 ($char ==
'"' || $char ==
"'") &&
696 ($char == $enclosed_by ||
'' == $enclosed_by) &&
697 (0 == $i || ($i > 0 &&
'\\' != $code[$i - 1]))
701 $enclosed_by = $char;
705 $enclosed = !$enclosed;
709 if (!$enclosed && isset($delimiter[$char])) {
715 return substr($code, 0, $i);
728 if (!is_array($variables)) {
729 $variables = array($variables =>
true);
732 reset($this->blockvariables[$block]);
733 while (list($varname, $val) = each($this->blockvariables[$block])) {
734 if (isset($variables[$varname])) {
735 unset($this->blockvariables[$block][$varname]);
748 preg_match_all( $this->variablesRegExp,
749 $this->blocklist[$block], $regs
752 if (count($regs[1]) != 0) {
753 foreach ($regs[1] as $k => $var) {
754 $this->blockvariables[$block][$var] =
true;
757 $this->blockvariables[$block] = array();
761 if (isset($this->blockinner[$block]) &&
762 is_array($this->blockinner[$block]) &&
763 count($this->blockinner[$block]) > 0
769 foreach ($this->blockinner[$block] as $childBlock) {
786 reset($this->blocklist);
787 while (list($blockname, $content) = each($this->blocklist)) {
788 reset($this->blockvariables[$blockname]);
790 list($varname, $val) = each($this->blockvariables[$blockname]))
792 if ($variable == $varname) {
793 $parents[] = $blockname;
814 'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
820 $this->warn[] = $message;
822 if ($this->printWarning) {
826 if ($this->haltOnWarning) {