HTML_Template_IT
[ class tree: HTML_Template_IT ] [ index: HTML_Template_IT ] [ all elements ]

Source for file ITX.php

Documentation is available at ITX.php

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

Documentation generated on Mon, 11 Mar 2019 14:43:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.