PageRenderTime 26ms CodeModel.GetById 3ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/php-pear-HTML-Template-IT-1.3.0/HTML_Template_IT-1.3.0/HTML/Template/ITX.php

#
PHP | 889 lines | 390 code | 92 blank | 407 comment | 74 complexity | 16b0300b5fbe3be7a1df976ce5d27c4f MD5 | raw file
  1<?php
  2/**
  3 * Integrated Template - IT
  4 *
  5 * PHP version 4
  6 *
  7 * Copyright (c) 1997-2007 Ulf Wendel, Pierre-Alain Joye,
  8 *                         David Soria Parra
  9 *
 10 * This source file is subject to the New BSD license, That is bundled
 11 * with this package in the file LICENSE, and is available through
 12 * the world-wide-web at
 13 * http://www.opensource.org/licenses/bsd-license.php
 14 * If you did not receive a copy of the new BSDlicense and are unable
 15 * to obtain it through the world-wide-web, please send a note to
 16 * pajoye@php.net so we can mail you a copy immediately.
 17 *
 18 * Author: Ulf Wendel <ulf.wendel@phpdoc.de>
 19 *         Pierre-Alain Joye <pajoye@php.net>
 20 *         David Soria Parra <dsp@php.net>
 21 *
 22 * @category HTML
 23 * @package  HTML_Template_IT
 24 * @author   Ulf Wendel <uw@netuse.de>
 25 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
 26 * @version  CVS: $Id: ITX.php 295086 2010-02-15 06:31:36Z clockwerx $
 27 * @link     http://pear.php.net/packages/HTML_Template_IT
 28 * @access   public
 29 */
 30
 31require_once 'HTML/Template/IT.php';
 32require_once 'HTML/Template/IT_Error.php';
 33
 34/**
 35* Integrated Template Extension - ITX
 36*
 37* With this class you get the full power of the phplib template class.
 38* You may have one file with blocks in it but you have as well one main file
 39* and multiple files one for each block. This is quite usefull when you have
 40* user configurable websites. Using blocks not in the main template allows
 41* you to modify some parts of your layout easily.
 42*
 43* Note that you can replace an existing block and add new blocks at runtime.
 44* Adding new blocks means changing a variable placeholder to a block.
 45*
 46 * @category HTML
 47 * @package  HTML_Template_IT
 48 * @author   Ulf Wendel <uw@netuse.de>
 49 * @license  BSD http://www.opensource.org/licenses/bsd-license.php
 50 * @link     http://pear.php.net/packages/HTML_Template_IT
 51 * @access   public
 52*/
 53class HTML_Template_ITX extends HTML_Template_IT
 54{
 55    /**
 56     * Array with all warnings.
 57     * @var    array
 58     * @access public
 59     * @see    $printWarning, $haltOnWarning, warning()
 60     */
 61    var $warn = array();
 62
 63    /**
 64     * Print warnings?
 65     * @var    array
 66     * @access public
 67     * @see    $haltOnWarning, $warn, warning()
 68     */
 69    var $printWarning = false;
 70
 71    /**
 72     * Call die() on warning?
 73     * @var    boolean
 74     * @access public
 75     * @see    $warn, $printWarning, warning()
 76     */
 77    var $haltOnWarning = false;
 78
 79    /**
 80     * RegExp used to test for a valid blockname.
 81     * @var string
 82     * @access private
 83     */
 84    var $checkblocknameRegExp = '';
 85
 86    /**
 87     * Functionnameprefix used when searching function calls in the template.
 88     * @var string
 89     * @access public
 90     */
 91    var $functionPrefix = 'func_';
 92
 93    /**
 94     * Functionname RegExp.
 95     * @var string
 96     * @access public
 97     */
 98    var $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*';
 99
100    /**
101     * RegExp used to grep function calls in the template.
102     *
103     * The variable gets set by the constructor.
104     *
105     * @access private
106     * @var string
107     * @see HTML_Template_IT()
108     */
109    var $functionRegExp = '';
110
111    /**
112     * List of functions found in the template.
113     *
114     * @access private
115     * @var array
116     */
117    var $functions = array();
118
119    /**
120     * List of callback functions specified by the user.
121     *
122     * @access private
123     * @var array
124     */
125    var $callback = array();
126
127    /**
128     * Builds some complex regexps and calls the constructor
129     * of the parent class.
130     *
131     * Make sure that you call this constructor if you derive your own
132     * template class from this one.
133     *
134     * @param string $root Root node?
135     *
136     * @access public
137     * @see    HTML_Template_IT()
138     */
139    function HTML_Template_ITX($root = '')
140    {
141
142        $this->checkblocknameRegExp = '@' . $this->blocknameRegExp . '@';
143
144        $this->functionRegExp = '@' . $this->functionPrefix . '(' .
145                                $this->functionnameRegExp . ')\s*\(@sm';
146
147        $this->HTML_Template_IT($root);
148    } // end func constructor
149
150    /**
151     * Clears all datafields of the object and rebuild the internal blocklist
152     *
153     * LoadTemplatefile() and setTemplate() automatically call this function
154     * when a new template is given. Don't use this function
155     * unless you know what you're doing.
156     *
157     * @access private
158     * @return null
159     */
160    function init()
161    {
162        $this->free();
163        $this->buildFunctionlist();
164        $this->findBlocks($this->template);
165
166        // we don't need it any more
167        $this->template = '';
168        $this->buildBlockvariablelist();
169
170    } // end func init
171
172    /**
173     * Replaces an existing block with new content.
174     *
175     * This function will replace a block of the template and all blocks
176     * contained in the replaced block and add a new block insted, means
177     * you can dynamically change your template.
178     *
179     * Note that changing the template structure violates one of the IT[X]
180     * development goals. I've tried to write a simple to use template engine
181     * supporting blocks. In contrast to other systems IT[X] analyses the way
182     * you've nested blocks and knows which block belongs into another block.
183     * The nesting information helps to make the API short and simple. Replacing
184     * blocks does not only mean that IT[X] has to update the nesting
185     * information (relatively time consumpting task) but you have to make sure
186     * that you do not get confused due to the template change itself.
187     *
188     * @param string  $block        Blockname
189     * @param string  $template     Blockcontent
190     * @param boolean $keep_content true if the new block inherits the content
191     *                              of the old block
192     *
193     * @return   boolean
194     * @throws   IT_Error
195     * @see      replaceBlockfile(), addBlock(), addBlockfile()
196     * @access   public
197     */
198    function replaceBlock($block, $template, $keep_content = false)
199    {
200        if (!isset($this->blocklist[$block])) {
201            return new IT_Error("The block "."'$block'".
202            " does not exist in the template and thus it can't be replaced.",
203            __FILE__, __LINE__);
204        }
205
206        if ($template == '') {
207            return new IT_Error('No block content given.', __FILE__, __LINE__);
208        }
209
210        if ($keep_content) {
211            $blockdata = $this->blockdata[$block];
212        }
213
214        // remove all kinds of links to the block / data of the block
215        $this->removeBlockData($block);
216
217        $template = "<!-- BEGIN $block -->" . $template . "<!-- END $block -->";
218        $parents  = $this->blockparents[$block];
219
220        $this->findBlocks($template);
221        $this->blockparents[$block] = $parents;
222
223        // KLUDGE: rebuild the list for all block - could be done faster
224        $this->buildBlockvariablelist();
225
226        if ($keep_content) {
227            $this->blockdata[$block] = $blockdata;
228        }
229
230        // old TODO - I'm not sure if we need this
231        // update caches
232
233        return true;
234    } // end func replaceBlock
235
236    /**
237     * Replaces an existing block with new content from a file.
238     *
239     * @param string  $block        Blockname
240     * @param string  $filename     Name of the file that contains the blockcontent
241     * @param boolean $keep_content true if the new block inherits the content of
242     *                              the old block
243     *
244     * @brother replaceBlock()
245     * @access  public
246     * @return null
247     */
248    function replaceBlockfile($block, $filename, $keep_content = false)
249    {
250        return $this->replaceBlock($block, $this->getFile($filename), $keep_content);
251    } // end func replaceBlockfile
252
253    /**
254     * Adds a block to the template changing a variable placeholder
255     * to a block placeholder.
256     *
257     * Add means "replace a variable placeholder by a new block".
258     * This is different to PHPLibs templates. The function loads a
259     * block, creates a handle for it and assigns it to a certain
260     * variable placeholder. To to the same with PHPLibs templates you would
261     * call set_file() to create the handle and parse() to assign the
262     * parsed block to a variable. By this PHPLibs templates assume
263     * that you tend to assign a block to more than one one placeholder.
264     * To assign a parsed block to more than only the placeholder you specify
265     * in this function you have to use a combination of getBlock()
266     * and setVariable().
267     *
268     * As no updates to cached data is necessary addBlock() and addBlockfile()
269     * are rather "cheap" meaning quick operations.
270     *
271     * The block content must not start with <!-- BEGIN blockname -->
272     * and end with <!-- END blockname --> this would cause overhead and
273     * produce an error.
274     *
275     * @param string $placeholder Name of the variable placeholder, the name
276     *                            must be unique within the template.
277     * @param string $blockname   Name of the block to be added
278     * @param string $template    Content of the block
279     *
280     * @return   boolean
281     * @throws   IT_Error
282     * @see      addBlockfile()
283     * @access   public
284     */
285    function addBlock($placeholder, $blockname, $template)
286    {
287        // Don't trust any user even if it's a programmer or yourself...
288        if ($placeholder == '') {
289            return new IT_Error('No variable placeholder given.',
290                                __FILE__, __LINE__);
291        } elseif ($blockname == '' ||
292                    !preg_match($this->checkblocknameRegExp, $blockname)
293        ) {
294            return new IT_Error("No or invalid blockname '$blockname' given.",
295                    __FILE__, __LINE__);
296        } elseif ($template == '') {
297            return new IT_Error('No block content given.', __FILE__, __LINE__);
298        } elseif (isset($this->blocklist[$blockname])) {
299            return new IT_Error('The block already exists.',
300                                __FILE__, __LINE__);
301        }
302
303        // find out where to insert the new block
304        $parents = $this->findPlaceholderBlocks($placeholder);
305        if (count($parents) == 0) {
306
307            return new IT_Error("The variable placeholder".
308                                " '$placeholder' was not found in the template.",
309                                __FILE__, __LINE__);
310
311        } elseif (count($parents) > 1) {
312
313            reset($parents);
314            while (list($k, $parent) = each($parents)) {
315                $msg .= "$parent, ";
316            }
317            $msg = substr($parent, -2);
318
319            return new IT_Error("The variable placeholder "."'$placeholder'".
320                                " must be unique, found in multiple blocks '$msg'.",
321                                __FILE__, __LINE__);
322        }
323
324        $template = "<!-- BEGIN $blockname -->"
325                  . $template
326                  . "<!-- END $blockname -->";
327        $this->findBlocks($template);
328        if ($this->flagBlocktrouble) {
329            return false;    // findBlocks() already throws an exception
330        }
331
332        $this->blockinner[$parents[0]][] = $blockname;
333
334        $escblockname = '__' . $blockname . '__';
335
336        $this->blocklist[$parents[0]] = preg_replace(
337            '@' . $this->openingDelimiter . $placeholder .
338            $this->closingDelimiter . '@',
339            $this->openingDelimiter . $escblockname . $this->closingDelimiter,
340            $this->blocklist[$parents[0]]
341        );
342
343        $this->deleteFromBlockvariablelist($parents[0], $placeholder);
344        $this->updateBlockvariablelist($blockname);
345
346        return true;
347    } // end func addBlock
348
349    /**
350     * Adds a block taken from a file to the template changing a variable
351     * placeholder to a block placeholder.
352     *
353     * @param string $placeholder Name of the variable placeholder to be converted
354     * @param string $blockname   Name of the block to be added
355     * @param string $filename    File that contains the block
356     *
357     * @brother    addBlock()
358     * @access     public
359     * @return     null
360     */
361    function addBlockfile($placeholder, $blockname, $filename)
362    {
363        return $this->addBlock($placeholder, $blockname, $this->getFile($filename));
364    } // end func addBlockfile
365
366    /**
367     * Returns the name of the (first) block that contains
368     * the specified placeholder.
369     *
370     * @param string $placeholder Name of the placeholder you're searching
371     * @param string $block       Name of the block to scan. If left out (default)
372     *                            all blocks are scanned.
373     *
374     * @return   string  Name of the (first) block that contains
375     *                   the specified placeholder.
376     *                   If the placeholder was not found or an error occured
377     *                   an empty string is returned.
378     * @throws   IT_Error
379     * @access   public
380     */
381    function placeholderExists($placeholder, $block = '')
382    {
383        if ($placeholder == '') {
384            new IT_Error('No placeholder name given.', __FILE__, __LINE__);
385            return '';
386        }
387
388        if ($block != '' && !isset($this->blocklist[$block])) {
389            new IT_Error("Unknown block '$block'.", __FILE__, __LINE__);
390            return '';
391        }
392
393        // name of the block where the given placeholder was found
394        $found = '';
395
396        if ($block != '') {
397            if (is_array($variables = $this->blockvariables[$block])) {
398                // search the value in the list of blockvariables
399                reset($variables);
400                while (list($k, $variable) = each($variables)) {
401                    if ($k == $placeholder) {
402                        $found = $block;
403                        break;
404                    }
405                }
406            }
407        } else {
408
409            // search all blocks and return the name of the first block that
410            // contains the placeholder
411            reset($this->blockvariables);
412            while (list($blockname, $variables) = each($this->blockvariables)) {
413                if (is_array($variables) && isset($variables[$placeholder])) {
414                    $found = $blockname;
415                    break;
416                }
417            }
418        }
419
420        return $found;
421    } // end func placeholderExists
422
423    /**
424     * Checks the list of function calls in the template and
425     * calls their callback function.
426     *
427     * @access  public
428     * @return  null
429     */
430    function performCallback()
431    {
432        reset($this->functions);
433        while (list($func_id, $function) = each($this->functions)) {
434            if (isset($this->callback[$function['name']])) {
435                if ($this->callback[$function['name']]['expandParameters']) {
436                    $callFunction = 'call_user_func_array';
437                } else {
438                    $callFunction = 'call_user_func';
439                }
440
441                if ($this->callback[$function['name']]['object'] != '') {
442                     $call = $callFunction(
443                        array(
444                            &$GLOBALS[$this->callback[$function['name']]['object']],
445                            $this->callback[$function['name']]['function']),
446                        $function['args']);
447
448                } else {
449                     $call = $callFunction(
450                        $this->callback[$function['name']]['function'],
451                        $function['args']);
452                }
453                $this->variableCache['__function' . $func_id . '__'] = $call;
454            }
455        }
456
457    } // end func performCallback
458
459    /**
460     * Returns a list of all function calls in the current template.
461     *
462     * @return   array
463     * @access   public
464     */
465    function getFunctioncalls()
466    {
467        return $this->functions;
468    } // end func getFunctioncalls
469
470    /**
471     * Replaces a function call with the given replacement.
472     *
473     * @param int    $functionID  Function ID
474     * @param string $replacement Replacement
475     *
476     * @access   public
477     * @deprecated
478     * @return null
479     */
480    function setFunctioncontent($functionID, $replacement)
481    {
482        $this->variableCache['__function' . $functionID . '__'] = $replacement;
483    } // end func setFunctioncontent
484
485    /**
486     * Sets a callback function.
487     *
488     * IT[X] templates (note the X) can contain simple function calls.
489     * "function call" means that the editor of the template can add
490     * special placeholder to the template like 'func_h1("embedded in h1")'.
491     * IT[X] will grab this function calls and allow you to define a callback
492     * function for them.
493     *
494     * This is an absolutely evil feature. If your application makes heavy
495     * use of such callbacks and you're even implementing if-then etc. on
496     * the level of a template engine you're reiventing the wheel... - that's
497     * actually how PHP came into life. Anyway, sometimes it's handy.
498     *
499     * Consider also using XML/XSLT or native PHP. And please do not push
500     * IT[X] any further into this direction of adding logics to the template
501     * engine.
502     *
503     * For those of you ready for the X in IT[X]:
504     *
505     * <?php
506     * ...
507     * function h_one($args) {
508     *    return sprintf('<h1>%s</h1>', $args[0]);
509     * }
510     *
511     * ...
512     * $itx = new HTML_Template_ITX(...);
513     * ...
514     * $itx->setCallbackFunction('h1', 'h_one');
515     * $itx->performCallback();
516     * ?>
517     *
518     * template:
519     * func_h1('H1 Headline');
520     *
521     * @param string  $tplfunction              Function name in the template
522     * @param string  $callbackfunction         Name of the callback function
523     * @param string  $callbackobject           Name of the callback object
524     * @param boolean $expandCallbackParameters If the callback is called with
525     *                                          a list of parameters or with an
526     *                                          array holding the parameters
527     *
528     * @return     boolean   False on failure.
529     * @throws     IT_Error
530     * @access     public
531     * @deprecated The $callbackobject parameter is depricated since
532     *             version 1.2 and might be dropped in further versions.
533     */
534    function setCallbackFunction($tplfunction, $callbackfunction,
535        $callbackobject = '',
536    $expandCallbackParameters = false) {
537        if ($tplfunction == '' || $callbackfunction == '') {
538            return new IT_Error("No template function "."('$tplfunction')".
539                                " and/or no callback function ('$callback') given.",
540                                __FILE__, __LINE__);
541        }
542        $this->callback[$tplfunction] = array(
543                                          'function' => $callbackfunction,
544                                          'object'   => $callbackobject,
545                                          'expandParameters' => (boolean)
546                                                $expandCallbackParameters);
547
548        return true;
549    } // end func setCallbackFunction
550
551    /**
552     * Sets the Callback function lookup table
553     *
554     * @param array $functions function table
555     *                           array[templatefunction] =
556     *                               array(
557     *                                   "function" => userfunction,
558     *                                   "object" => userobject
559     *                               )
560     *
561     * @access    public
562     * @return null
563     */
564    function setCallbackFuntiontable($functions)
565    {
566        $this->callback = $functions;
567    } // end func setCallbackFunctiontable
568
569    /**
570     * Recursively removes all data assiciated with a block, including
571     * all inner blocks
572     *
573     * @param string $block block to be removed
574     *
575     * @return null
576     * @access   private
577     */
578    function removeBlockData($block)
579    {
580        if (isset($this->blockinner[$block])) {
581            foreach ($this->blockinner[$block] as $k => $inner) {
582                $this->removeBlockData($inner);
583            }
584
585            unset($this->blockinner[$block]);
586        }
587
588        unset($this->blocklist[$block]);
589        unset($this->blockdata[$block]);
590        unset($this->blockvariables[$block]);
591        unset($this->touchedBlocks[$block]);
592
593    } // end func removeBlockinner
594
595    /**
596     * Returns a list of blocknames in the template.
597     *
598     * @return    array    [blockname => blockname]
599     * @access    public
600     * @see       blockExists()
601     */
602    function getBlocklist()
603    {
604        $blocklist = array();
605        foreach ($this->blocklist as $block => $content) {
606            $blocklist[$block] = $block;
607        }
608
609        return $blocklist;
610    } // end func getBlocklist
611
612    /**
613     * Checks wheter a block exists.
614     *
615     * @param string $blockname Blockname
616     *
617     * @return   boolean
618     * @access   public
619     * @see      getBlocklist()
620     */
621    function blockExists($blockname)
622    {
623        return isset($this->blocklist[$blockname]);
624    } // end func blockExists
625
626    /**
627     * Returns a list of variables of a block.
628     *
629     * @param string $block Blockname
630     *
631     * @return   array    [varname => varname]
632     * @access   public
633     * @see      BlockvariableExists()
634     */
635    function getBlockvariables($block)
636    {
637        if (!isset($this->blockvariables[$block])) {
638            return array();
639        }
640
641        $variables = array();
642        foreach ($this->blockvariables[$block] as $variable => $v) {
643            $variables[$variable] = $variable;
644        }
645
646        return $variables;
647    } // end func getBlockvariables
648
649    /**
650     * Checks wheter a block variable exists.
651     *
652     * @param string $block    Blockname
653     * @param string $variable Variablename
654     *
655     * @return   boolean
656     * @access   public
657     * @see      getBlockvariables()
658     */
659    function BlockvariableExists($block, $variable)
660    {
661        return isset($this->blockvariables[$block][$variable]);
662    } // end func BlockvariableExists
663
664    /**
665     * Builds a functionlist from the template.
666     *
667     * @access private
668     * @return null
669     */
670    function buildFunctionlist()
671    {
672        $this->functions = array();
673
674        $template = $this->template;
675
676        $num = 0;
677
678        while (preg_match($this->functionRegExp, $template, $regs)) {
679
680            $pos = strpos($template, $regs[0]);
681
682            $template = substr($template, $pos + strlen($regs[0]));
683
684            $head = $this->getValue($template, ')');
685            $args = array();
686
687            $search = $regs[0] . $head . ')';
688
689            $replace = $this->openingDelimiter .
690                       '__function' . $num . '__' .
691                       $this->closingDelimiter;
692
693            $this->template = str_replace($search, $replace, $this->template);
694            $template       = str_replace($search, $replace, $template);
695
696            while ($head != '' && $args2 = $this->getValue($head, ',')) {
697                $arg2 = trim($args2);
698
699                $args[] = ('"' == $arg2{0} || "'" == $arg2{0}) ?
700                                    substr($arg2, 1, -1) : $arg2;
701
702                if ($arg2 == $head) {
703                    break;
704                }
705                $head = substr($head, strlen($arg2) + 1);
706            }
707
708            $this->functions[$num++] = array('name'    => $regs[1],
709                                             'args'    => $args);
710        }
711
712    } // end func buildFunctionlist
713
714    /**
715     * Truncates the given code from the first occurence of
716     * $delimiter but ignores $delimiter enclosed by " or '.
717     *
718     * @param string $code      The code which should be parsed
719     * @param string $delimiter The delimiter char
720     *
721     * @access private
722     * @return string
723     * @see    buildFunctionList()
724     */
725    function getValue($code, $delimiter)
726    {
727        if ($code == '') {
728            return '';
729        }
730
731        if (!is_array($delimiter)) {
732            $delimiter = array($delimiter => true);
733        }
734
735        $len         = strlen($code);
736        $enclosed    = false;
737        $enclosed_by = '';
738
739        if (isset($delimiter[$code[0]])) {
740            $i = 1;
741        } else {
742            for ($i = 0; $i < $len; ++$i) {
743                $char = $code[$i];
744
745                if (($char == '"' || $char == "'")
746                    && ($char == $enclosed_by || '' == $enclosed_by)
747                    && (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
748                ) {
749
750                    if (!$enclosed) {
751                        $enclosed_by = $char;
752                    } else {
753                        $enclosed_by = "";
754                    }
755                    $enclosed = !$enclosed;
756
757                }
758
759                if (!$enclosed && isset($delimiter[$char])) {
760                    break;
761                }
762            }
763        }
764
765        return substr($code, 0, $i);
766    } // end func getValue
767
768    /**
769     * Deletes one or many variables from the block variable list.
770     *
771     * @param string $block     Blockname
772     * @param mixed  $variables Name of one variable or array of variables
773     *                          (array (name => true ) ) to be stripped.
774     *
775     * @access   private
776     * @return null
777     */
778    function deleteFromBlockvariablelist($block, $variables)
779    {
780        if (!is_array($variables)) {
781            $variables = array($variables => true);
782        }
783
784        reset($this->blockvariables[$block]);
785        while (list($varname, $val) = each($this->blockvariables[$block])) {
786            if (isset($variables[$varname])) {
787                unset($this->blockvariables[$block][$varname]);
788            }
789        }
790    } // end deleteFromBlockvariablelist
791
792    /**
793     * Updates the variable list of a block.
794     *
795     * @param string $block Blockname
796     *
797     * @access   private
798     * @return null
799     */
800    function updateBlockvariablelist($block)
801    {
802        preg_match_all(
803            $this->variablesRegExp,
804            $this->blocklist[$block], $regs
805        );
806
807        if (count($regs[1]) != 0) {
808            foreach ($regs[1] as $k => $var) {
809                $this->blockvariables[$block][$var] = true;
810            }
811        } else {
812            $this->blockvariables[$block] = array();
813        }
814
815        // check if any inner blocks were found
816        if (isset($this->blockinner[$block])
817            && is_array($this->blockinner[$block])
818            && count($this->blockinner[$block]) > 0
819        ) {
820            /*
821             * loop through inner blocks, registering the variable
822             * placeholders in each
823             */
824            foreach ($this->blockinner[$block] as $childBlock) {
825                $this->updateBlockvariablelist($childBlock);
826            }
827        }
828    } // end func updateBlockvariablelist
829
830    /**
831     * Returns an array of blocknames where the given variable
832     * placeholder is used.
833     *
834     * @param string $variable Variable placeholder
835     *
836     * @return   array     $parents parents[0..n] = blockname
837     * @access   public
838     */
839    function findPlaceholderBlocks($variable)
840    {
841        $parents = array();
842        reset($this->blocklist);
843        while (list($blockname, $content) = each($this->blocklist)) {
844            reset($this->blockvariables[$blockname]);
845
846            while (list($varname, $val) = each($this->blockvariables[$blockname])) {
847                if ($variable == $varname) {
848                    $parents[] = $blockname;
849                }
850            }
851        }
852
853        return $parents;
854    } // end func findPlaceholderBlocks
855
856    /**
857     * Handles warnings, saves them to $warn and prints them or
858     * calls die() depending on the flags
859     *
860     * @param string $message Warning
861     * @param string $file    File where the warning occured
862     * @param int    $line    Linenumber where the warning occured
863     *
864     * @see      $warn, $printWarning, $haltOnWarning
865     * @access   private
866     * @return null
867     */
868    function warning($message, $file = '', $line = 0)
869    {
870        $message = sprintf(
871            'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
872            $message,
873            $file,
874            $line
875        );
876
877        $this->warn[] = $message;
878
879        if ($this->printWarning) {
880            print $message;
881        }
882
883        if ($this->haltOnWarning) {
884            die($message);
885        }
886    } // end func warning
887
888} // end class HTML_Template_ITX
889?>