sbergmann               Wed Jan 17 08:15:18 2001 EDT

  Added files:                 
    /php4/pear/HTML     IT.php ITX.php 

  Removed files:               
    /php4/pear/PHPDoc/redist    IT.php ITX.php 

  Modified files:              
    /php4/pear/PHPDoc   prepend.php 
  Log:
  Move IT[x] to HTML/.
  
Index: php4/pear/PHPDoc/prepend.php
diff -u php4/pear/PHPDoc/prepend.php:1.1 php4/pear/PHPDoc/prepend.php:1.2
--- php4/pear/PHPDoc/prepend.php:1.1    Sun Oct  8 03:03:18 2000
+++ php4/pear/PHPDoc/prepend.php        Wed Jan 17 08:15:18 2001
@@ -44,9 +44,9 @@
 require( PHPDOC_INCLUDE_DIR . "xmlexporter/PhpdocXMLModuleExporter.php" );
 require( PHPDOC_INCLUDE_DIR . "xmlexporter/PhpdocXMLClassExporter.php" );
 
-// Redistributed IT[X] Templates from the PHPLib
-require( PHPDOC_INCLUDE_DIR . "redist/IT.php" );
-require( PHPDOC_INCLUDE_DIR . "redist/ITX.php" );
+// IT[X] Templates
+require_once "HTML/IT.php";
+require_once "HTML/ITX.php";
 
 // XML Reader
 require( PHPDOC_INCLUDE_DIR . "xmlreader/PhpdocXMLReader.php" );

Index: php4/pear/HTML/IT.php
+++ php4/pear/HTML/IT.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2001 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <[EMAIL PROTECTED]>                                   |
// +----------------------------------------------------------------------+
//
// $Id: IT.php,v 1.1 2001/01/17 16:15:17 sbergmann Exp $
//

/**
* Integrated Template - IT
* 
* Well there's not much to say about it. I needed a template class that
* supports a single template file with multiple (nested) blocks inside.
* 
* Usage:
* $tpl = new IntegratedTemplate( [string filerootdir] );
* 
* // load a template or set it with setTemplate()
* $tpl->loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean 
removeEmptyBlocks] )
*
* // set "global" Variables meaning variables not beeing within a (inner) block
* $tpl->setVariable( string variablename, mixed value );
* 
* // like with the Isotopp Templates there's a second way to use setVariable()
* $tpl->setVariable( array ( string varname => mixed value ) );
* 
* // Let's use any block, even a deeply nested one
* $tpl->setCurrentBlock( string blockname );
*
* // repeat this as often as you neer. 
* $tpl->setVariable( array ( string varname => mixed value ) );
* $tpl->parseCurrentBlock();
*
* // get the parsed template or print it: $tpl->show()
* $tpl->get();
* 
* @author         Ulf Wendel <[EMAIL PROTECTED]>
* @version  $Id: IT.php,v 1.1 2001/01/17 16:15:17 sbergmann Exp $
* @access               public
* @package      PHPDoc
*/
class IntegratedTemplate {

        /**
        * Contains the error objects
        * @var          array
        * @access       public
        * @see          halt(), $printError, $haltOnError
        */
        var $err = array();
        
        /**
        * Print error messages?
        * @var          boolean
        * @access       public
        * @see          halt(), $haltOnError, $err
        */
        var $printError = false;
        
        /**
        * Call die() on error?
        * @var          boolean
        * @access       public
        * @see          halt(), $printError, $err
        */
        var $haltOnError = false;
        
        /**
        * Clear cache on get()? 
        * @var  boolean
        */ 
        var $clearCache = false;
                
        /**
        * First character of a variable placeholder ( _{_VARIABLE} ).
        * @var          string
        * @access       public
        * @see          $closingDelimiter, $blocknameRegExp, $variablenameRegExp
        */
        var $openingDelimiter = "{";
        
        /**
        * Last character of a variable placeholder ( {VARIABLE_}_ ).
        * @var          string
        * @access       public
        * @see          $openingDelimiter, $blocknameRegExp, $variablenameRegExp
        */
        var $closingDelimiter   = "}";
        
        /**
        * RegExp matching a block in the template. 
        * Per default "sm" is used as the regexp modifier, "i" is missing.
        * That means a case sensitive search is done.
        * @var          string
        * @access       public
        * @see          $variablenameRegExp, $openingDelimiter, $closingDelimiter
        */
        var $blocknameRegExp    = "[0-9A-Za-z_-]+";
        
        /**
        * RegExp matching a variable placeholder in the template.
        * Per default "sm" is used as the regexp modifier, "i" is missing.
        * That means a case sensitive search is done.
        * @var          string  
        * @access       public
        * @see          $blocknameRegExp, $openingDelimiter, $closingDelimiter
        */
        var $variablenameRegExp = "[0-9A-Za-z_-]+";
        
        /**
        * Full RegExp used to find variable placeholder, filled by the constructor.
        * @var  string  Looks somewhat like @(delimiter varname delimiter)@
        * @see  IntegratedTemplate()
        */
        var $variablesRegExp = "";
        
        /**
        * Full RegExp used to find blocks an their content, filled by the constructor.
        * @var  string
        * @see  IntegratedTemplate()
        */
        var $blockRegExp = "";
        
        /**
        * Name of the current block.
        * @var          string
        */
        var $currentBlock = "__global__";

        /**
        * Content of the template.
        * @var          string
        */      
        var $template = "";
        
        /**
        * Array of all blocks and their content.
        * 
        * @var  array
        * @see  findBlocks()
        */      
        var $blocklist                  = array();
  
  /**
  * Array with the parsed content of a block.
  *
  * @var  array
  */
  var $blockdata      = array();
        
        /**
        * Array of variables in a block.
        * @var  array
        */
        var $blockvariables = array();

        /**
        * Array of inner blocks of a block.
        * @var  array
        */      
        var $blockinner                 = array();
        
  /**
  * Future versions will use this...
  * @var  array
  */
  var $blocktypes = array();
  
        /**
        * Variable cache.
        *
        * Variables get cached before any replacement is done.
        * Advantage: empty blocks can be removed automatically.
        * Disadvantage: might take some more memory
        * 
        * @var  array
        * @see  setVariable(), $clearCacheOnParse
        */
        var $variableCache = array();
        
        /**
        * @var  boolean
        */
        var $clearCacheOnParse = true;
        
        /**
        * Controls the handling of unknown variables, default is remove.
        * @var  boolean
        */
        var $removeUnknownVariables = true;
        
        /**
        * Controls the handling of empty blocks, default is remove.
        * @var  boolean
        */
        var $removeEmptyBlocks = true;
        
        /**
        * Root directory for all file operations. 
        * The string gets prefixed to all filenames given.
        * @var  string
        * @see  IntegratedTemplate(), setRoot()
        */
        var $fileRoot = "";
        
        /**
        * Internal flag indicating that a blockname was used multiple times.
        * @var  boolean
        */
        var $flagBlocktrouble = false;
        
        /**
        * Flag indicating that the global block was parsed.
        * @var  boolean
        */
        var $flagGlobalParsed = false;
        
        /**
        * Builds some complex regular expressions and optinally sets the file root 
directory.
        *
        * Make sure that you call this constructor if you derive your template 
        * class from this one. 
        *
        * @param        string  File root directory, prefix for all filenames given to 
the object.
        * @see  setRoot()
        */
        function IntegratedTemplate($root = "") {
        
                $this->variablesRegExp = 
"@".$this->openingDelimiter."(".$this->variablenameRegExp.")".$this->closingDelimiter."@sm";
                $this->blockRegExp = 
'@!--\s+BEGIN\s+('.$this->blocknameRegExp.')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm';

                $this->setRoot($root);          
                
        } // end constructor
        
        /**
        * Print a certain block with all replacements done.
        * @brother get()
        */
        function show($block = "__global__") {
                print $this->get($block);
        } // end func show
        
        /**
        * Returns a block with all replacements done.
        * 
        * @param        string  name of the block
        * @return       string          
        * @access       public
        * @see  show()
        */
        function get($block = "__global__") {

                if ("__global__" == $block && !$this->flagGlobalParsed)
                        $this->parse("__global__");
                        
                if (!isset($this->blocklist[$block])) {
                        $this->halt("The block '$block' was not found in the 
template.", __FILE__, __LINE__);
                        return true;
                }
                
    if ($this->clearCache) {
    
      $data = (isset($this->blockdata[$block])) ? $this->blockdata[$block] : "";
      unset($this->blockdata[$block]);
      return $data;
       
    } else {
    
      return (isset($this->blockdata[$block])) ? $this->blockdata[$block] : "";
      
    }

        } // end func get()
                
        /**
        * Parses the given block.
        *       
        * @param        string  name of the block to be parsed
        * @access       public
        * @see          parseCurrentBlock()
        */
        function parse($block = "__global__", $flag_recursion = false) {

                if (!isset($this->blocklist[$block])) {
                        $this->halt("The block '$block' was not found in the 
template.", __FILE__, __LINE__);
                        return false;
                }

                if ("__global__" == $block)
                        $this->flagGlobalParsed = true;
                        
    $regs = array();
    $values = array();

                if ($this->clearCacheOnParse) {
                        
                        reset($this->variableCache);
                        while (list($name, $value)=each($this->variableCache)) {
                                $regs[] = 
"@".$this->openingDelimiter.$name.$this->closingDelimiter."@";
                                $values[] = $value;
                        }
                        $this->variableCache = array();
                
                } else {
                
                        reset($this->blockvariables[$block]);
                        while (list($k, 
$allowedvar)=each($this->blockvariables[$block])) {
                
                                if (isset($this->variableCache[$allowedvar])) {
                  $regs[]   = 
"@".$this->openingDelimiter.$allowedvar.$this->closingDelimiter."@";
                    $values[] = $this->variableCache[$allowedvar];
                                        unset($this->variableCache[$allowedvar]);
                                }

                        }               
                        
                }

                $outer = (0 == count($regs)) ? $this->blocklist[$block] : 
preg_replace($regs, $values, $this->blocklist[$block]);
                $empty = (0 == count($values)) ? true : false;

    if (isset($this->blockinner[$block])) {
                
      reset($this->blockinner[$block]);
      while (list($k, $innerblock)=each($this->blockinner[$block])) {

        $this->parse($innerblock, true);
                                if (""!=$this->blockdata[$innerblock])
                                        $empty = false;

                                $placeholder = 
$this->openingDelimiter."__".$innerblock."__".$this->closingDelimiter;                 
          
        $outer = str_replace($placeholder, $this->blockdata[$innerblock], $outer);
                                $this->blockdata[$innerblock] = "";                    
         
      }
    }

    if ($this->removeUnknownVariables)
                        $outer = preg_replace($this->variablesRegExp, "", $outer);
                
                if ($empty) {
                
                        if (!$this->removeEmptyBlocks) 
                                $this->blockdata[$block].= $outer;
                                
                } else {
                
                        $this->blockdata[$block].= $outer;
                
                }

    return $empty;
        } // end func parse

        /**
        * Parses the current block
        * @see  parse(), setCurrentBlock(), $currentBlock
        *       @access public
        */
        function parseCurrentBlock() {
                return $this->parse($this->currentBlock);
        } // end func parseCurrentBlock

        /**
        * Sets a variable value.
        * 
        * The function can be used eighter like setVariable( "varname", "value")
        * or with one array $variables["varname"] = "value" given 
setVariable($variables)
        * quite like phplib templates set_var().
        * 
        * @param        mixed           string with the variable name or an array 
%variables["varname"] = "value"
        * @param        string  value of the variable or empty if $variable is an 
array.
        * @param        string  prefix for variable names
        * @access       public
        */      
        function setVariable($variable, $value="") {
                
                if (is_array($variable)) {
                
                        reset($variable);
                        while (list($var, $value)=each($variable)) 
                                $this->variableCache[$var]      = $value;
                                
                } else {
                        
                        $this->variableCache[$variable]         = $value;
                        
                }
        
        } // end func setVariable
        
        /**
        * Sets the name of the current block that is the block where variables are 
added.
        *
        * @param        string  name of the block 
        * @return       boolean false on failure otherwise true
        *       @access public
        */
        function setCurrentBlock($block = "__global__") {
        
                if (!isset($this->blocklist[$block])) {
                        $this->halt("Can't find the block '$block' in the template.", 
__FILE__, __LINE__);
                        return false;
                }
                        
                $this->currentBlock = $block;
                
                return true;
        } // end func setCurrentBlock
        
        /**
        * Clears all datafields of the object and rebuild the internal blocklist
        * 
        * LoadTemplatefile() and setTemplate() automatically call this function 
        * when a new template is given. Don't use this function 
        * unless you know what you're doing.
        *
        * @access       public
        * @see  free()
        */
        function init() {
        
                $this->free();
                $this->findBlocks($this->template);
                $this->buildBlockvariablelist();
                
        } // end func init
        
        /**
        * Clears all datafields of the object.
        * 
        * Don't use this function unless you know what you're doing.
        *
        * @access       public
        * @see  init()
        */
        function free() {
        
                $this->err[] = "";
                
                $this->currentBlock = "__global__";
                
                $this->variableCache    = array();              
                $this->blocklist                        = array();
                $this->blockvariables   = array();
                $this->blockinner                       = array();
                $this->blockdata                        = array();
                $this->blocklookup              = array();
    $this->blocktypes     = array();
                
                $this->flagBlocktrouble = false;
                $this->flagGlobalParsed = false;
                
        } // end func free
        
        /**
        * Sets the template.
        *  
        * You can eighter load a template file from disk with LoadTemplatefile() or 
set the
        * template manually using this function.
        * 
        * @param                string  template content
        * @param                boolean Unbekannte, nicht ersetzte Platzhalter 
entfernen?
        * @param                boolean remove unknown/unused variables?
        * @param                boolean remove empty blocks?
        * @see                  LoadTemplatefile(), $template
        * @access               public
        */
        function setTemplate($template, $removeUnknownVariables = true, 
$removeEmptyBlocks = false) {
                if (""==$template) {
                        $this->halt("The given string is empty.", __FILE__, __LINE__);
                        return false;
                }
                
                $this->removeUnknownVariables = $removeUnknownVariables;
                $this->removeEmptyBlocks = $removeEmptyBlocks;
                
                $this->template = '<!-- BEGIN __global__ -->'.$template.'<!-- END 
__global__ -->';
                $this->init();
                
                if ($this->flagBlocktrouble)
                        return false;
                
                return true;
        } // end func setTemplate
        
        /**
        * Reads a template file from the disk.
        *
        * @param                string  name of the template file, full path!
        * @param                boolean remove unknown/unused variables?
        * @param                boolean remove empty blocks?
        * @access               public
        * @return               boolean false on failure, otherwise true
        * @see                  $template, setTemplate()
        */
        function loadTemplatefile($filename, $removeUnknownVariables = true, 
$removeEmptyBlocks = true) {
        
                $template = $this->getfile($filename);
                
                return $this->setTemplate($this->getFile($filename), 
$removeUnknownVariables, $removeEmptyBlocks);
        } // end func LoadTemplatefile
        
        /**
        * Sets the file root. The file root gets prefixed to all filenames passed to 
the object.
        * 
        * Make sure that you override this function when using the class
        * on windows.
        * 
        * @param        string
        * @see          IntegratedTemplate()
        * @access       public
        */
        function setRoot($root) {
                
                if (""!=$root && "/"!= substr($root, -1))
                        $root.="/";
                
                $this->fileRoot = $root;
                
        } // end func setRoot

        /**
        * Build a list of all variables within a block
        */      
        function buildBlockvariablelist() {

                reset($this->blocklist);
                while (list($name, $content)=each($this->blocklist)) {
                        preg_match_all( $this->variablesRegExp, $content, $regs );
                        $this->blockvariables[$name] = $regs[1];
                }       
                
        } // end func buildBlockvariablelist
        
        /**
        * Returns a list of all 
        */
        function getGlobalvariables() {

    $regs   = array();
    $values = array();
    
                reset($this->blockvariables["__global__"]);
                while (list($k, 
$allowedvar)=each($this->blockvariables["__global__"])) {
                        
                        if (isset($this->variableCache[$allowedvar])) {
                                $regs[]   = 
"@".$this->openingDelimiter.$allowedvar.$this->closingDelimiter."@";
                                $values[] = $this->variableCache[$allowedvar];
                                unset($this->variableCache[$allowedvar]);
                        }
                        
                }
                
    return array($regs, $values);
        } // end func getGlobalvariables

        /**
        * Recusively builds a list of all blocks within the template.
        *
        * @param        string  string that gets scanned
        * @access       private
        * @see  $blocklist
        */      
        function findBlocks($string) {

                $blocklist = array();

                if (preg_match_all($this->blockRegExp, $string, $regs, 
PREG_SET_ORDER)) {
                        
                        reset($regs);
                        while (list($k, $match)=each($regs)) {
                        
                                $blockname              = $match[1];
                                $blockcontent = $match[2];
                        
                                if (isset($this->blocklist[$blockname])) {
                                        $this->halt("The name of a block must be 
unique within a template. Found '$blockname' twice. Unpredictable results may 
appear.", __FILE__, __LINE__);
                                        $this->flagBlocktrouble = true;
                                }                               

                                $this->blocklist[$blockname] = $blockcontent;
                                $this->blockdata[$blockname] = "";

                                $blocklist[] = $blockname;
                                
                                $inner = $this->findBlocks($blockcontent);
                                reset($inner);
                                while (list($k, $name)=each($inner)) {

                                        $pattern = 
sprintf('@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm', 
                                                                                       
                 $name,
                                                                                       
                 $name
                                                                                       
         );

                                        $this->blocklist[$blockname] = preg_replace(   
 $pattern, 
                                                                                       
                                                                                       
                                                  
$this->openingDelimiter."__".$name."__".$this->closingDelimiter, 
                                                                                       
                                                                                       
                                                  $this->blocklist[$blockname]
                                                                                       
                                                                                       
                                          );
                                        $this->blockinner[$blockname][] = $name;
                                        $this->blockparents[$name] = $blockname;
                                        
                                }
                                
                        }
                        
                }

                return $blocklist;
        } // end func findBlocks

        /**
        * Reads a file from disk and returns its content.
        * @param        string  Filename
        * @return       string  Filecontent
        */      
        function getFile($filename) {
                
                if ("/" == substr($filename, 0, 1)) 
                        $filename = substr($filename, 1);
                        
                $filename = $this->fileRoot.$filename;
                
                if ( !($fh = @fopen($filename, "r")) ) {
                        $this->halt("Can't read '$filename'.", __FILE__, __LINE__);
                        return "";
                }
        
                $content = fread($fh, filesize($filename));
                fclose($fh);
                
                return $content; 
        } // end func getFile
        
        /**
        * Error Handling function.
        * @param        string  error message
        * @param        mixed           File where the error occured
        * @param        int                     Line where the error occured
        * @see          $err
        */
        function halt($message, $file="", $line=0) {
                
                $message = sprintf("IntegratedTemplate Error: %s [File: %s, Line: %d]",
                                                                                       
                                 $message,
                                                                                       
                                 $file,
                                                                                       
                                 $line
                                                                                       
                 );

                $this->err[] = $message;
                                                                                       
                                         
                if ($this->printError)
                        print $message;
                        
                if ($this->haltOnError)
                        die($message);                                                 
                                                                 

        } // end func halt
        
} // end class IntegratedTemplate
?>
Index: php4/pear/HTML/ITX.php
+++ php4/pear/HTML/ITX.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2001 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <[EMAIL PROTECTED]>                                   |
// +----------------------------------------------------------------------+
//
// $Id: ITX.php,v 1.1 2001/01/17 16:15:17 sbergmann Exp $
//

require_once "HTML/IT.php";

/**
* Integrated Template Extension - ITX
*
* With this class you get the full power of the phplib template class. 
* You may have one file with blocks in it but you have as well one main file 
* and multiple files one for each block. This is quite usefull when you have
* user configurable websites. Using blocks not in the main template allows
* you to some parts of your layout easily. 
*
* Note that you can replace an existing block and add new blocks add runtime.
* Adding new blocks means changing a variable placeholder to a block.
*
* @author       Ulf Wendel <[EMAIL PROTECTED]>
* @access               public
* @version      $ID: $
* @package      PHPDoc
*/
class IntegratedTemplateExtension extends IntegratedTemplate {

        /**
        * Array with all warnings.
        * @var          array
        * @access       public
        * @see          $printWarning, $haltOnWarning, warning()
        */
        var $warn = array();
        
        /**
        * Print warnings?
        * @var          array
        * @access       public
        * @see          $haltOnWarning, $warn, warning()
        */
        var $printWarning = false;
        
        /**
        * Call die() on warning?
        * @var          boolean
        * @access       public
        * @see          $warn, $printWarning, warning()
        */
        var $haltOnWarning = false;
                
        /**
        * RegExp used to test for a valid blockname.
        * @var  string
        */      
        var $checkblocknameRegExp = "";
        
        /**
        * Builds some complex regexps and calls the constructor of the parent class.
        *
        * Make sure that you call this constructor if you derive you own 
        * template class from this one.
        *
        * @see  IntegratedTemplate()
        */
        function IntegratedTemplateExtension() {
        
                $this->checkblocknameRegExp = "@".$this->blocknameRegExp."@";
                $this->IntegratedTemplate();
                                                                                       
                                                                                       
          
        } // end func IntegratedTemplateExtension
        
        /**
        * Replaces an existing block with new content. Warning: not implemented yet.
        * 
        * The Replacement does not affect previously added variables. All data is 
cached.
        * In case the new block does contain less or other variable placeholder the 
previously
        * passed data that is no longer referenced will be deleted. The internal list 
        * of allowed variables gets updated as well.
        *
        * In case the original block contains other blocks it must eighter have 
placeholder
        * for the inner blocks or contain them. If you want to use placeholder the 
placeholder must
        * look like openingDelimiter."__".blockname."__".closingDelimiter .
        *
        * Due to the cache updates replaceBlock() and replaceBlockfile() are 
"expensive" operations 
        * which means extensive usage will slow down your script. So try to avoid them 
and if 
        * you can't do so try to use them before you pass lots of variables to the 
block you're 
        * replacing.
        * 
        * @param        string  Blockname
        * @param        string  Blockcontent
        * @return       boolean 
        * @see          replaceBlockfile(), addBlock(), addBlockfile()
        * @access       public
        */
        function replaceBlock($block, $template) {
                if (!isset($this->blocklist[$block])) {
                        $this->halt("The block '$block' does not exist in the template 
and thus it can't be replaced.", __FILE__, __LINE__);
                        return false;
                }
                if (""==$template) {
                        $this->halt("No block content given.", __FILE__, __LINE__);
                        return false;
                }
                
                print "This function has not been coded yet.";
                
                // find inner blocks
                // add to variablelist
                // compare variable list
                // update caches
                
                return true;
        } // end func replaceBlock
        
        /**
        * Replaces an existing block with new content from a file. Warning: not 
implemented yet.
        * @brother replaceBlock()
        * @param        string  Blockname
        * @param        string  Name of the file that contains the blockcontent
        */
        function replaceBlockfile($block, $filename) {
                return $this->replaceBlock($block, $this->getFile($filename));  
        } // end func replaceBlockfile
        
        /**
        * Adds a block to the template changing a variable placeholder to a block 
placeholder.
        *
        * Add means "replace a variable placeholder by a new block". 
        * This is different to PHPLibs templates. The function loads a 
        * block, creates a handle for it and assigns it to a certain 
        * variable placeholder. To to the same with PHPLibs templates you would 
        * call set_file() to create the handle and parse() to assign the
        * parsed block to a variable. By this PHPLibs templates assume that you tend
        * to assign a block to more than one one placeholder. To assign a parsed block
        * to more than only the placeholder you specify in this function you have
        * to use a combination of getBlock() and setVariable().
        *
        * As no updates to cached data is necessary addBlock() and addBlockfile() 
        * are rather "cheap" meaning quick operations.
        *
        * The block content must not start with <!-- BEGIN blockname --> and end with 
        * <!-- END blockname --> this would cause overhead and produce an error.
        * 
        * @param        string  Name of the variable placeholder, the name must be 
unique within the template.
        * @param        string  Name of the block to be added
        * @param        string  Content of the block
        * @return       boolean
        * @see          addBlockfile()
        * @access       public
        */      
        function addBlock($placeholder, $blockname, $template) {
        
                // Don't trust any user even if it's a programmer or yourself...
                if (""==$placeholder) {
                
                        $this->halt("No variable placeholder given.", __FILE__, 
__LINE__);
                        return false;
                        
                }       else if (""==$blockname || 
!preg_match($this->checkblocknameRegExp, $blockname) ) {
                        
                        print $this->checkblocknameRegExp;
                        $this->halt("No or invalid blockname '$blockname' given.", 
__FILE__, __LINE__);
                        return false;
                        
                } else if (""==$template) {
                
                        $this->halt("No block content given.", __FILE__, __LINE__);
                        return false;
                        
                } else if (isset($this->blocklist[$blockname])) {
                
                        $this->halt("The block already exists.", __FILE__, __LINE__);
                        return false;
                        
                }
                
                // Hmm, we should do some more tests.
                $parents = $this->findPlaceholderBlocks($placeholder);
                if (0==count($parents)) {
                
                        $this->halt("The variable placeholder '$placeholder' was not 
found in the template.", __FILE__, __LINE__);
                        return false;
                        
                } else if ( count($parents)>1 ) {
                        
                        reset($parents);
                        while (list($k, $parent)=each($parents)) 
                                $msg.= "$parent, ";
                        $msg = substr($parent, -2);
                        
                        $this->halt("The variable placeholder '$placeholder' must be 
unique, found in multiple blocks '$msg'.", __FILE__, __LINE__);
                        return false;
                                                
                }
                
                $template = "<!-- BEGIN $blockname -->".$template."<!-- END $blockname 
-->";
                $this->findBlocks($template);
                if ($this->flagBlocktrouble) 
                        return false;   // findBlocks() already throws an exception
                
                $this->blockinner[$parents[0]][] = $blockname;
                $this->blocklist[$parents[0]] = preg_replace(   
"@".$this->openingDelimiter.$placeholder.$this->closingDelimiter."@", 
                                                                                       
                                                                                       
                          
$this->openingDelimiter."__".$blockname."__".$this->closingDelimiter, 
                                                                                       
                                                                                       
                          $this->blocklist[$parents[0]]
                                                                                       
                                                                                       
                  );
                                                                                       
                                                                                       
                  
                $this->deleteFromBlockvariablelist($parents[0], $placeholder);
                $this->updateBlockvariablelist($blockname);
                
                return true;
        } // end func addBlock
        
        /**
        * Adds a block taken from a file to the template changing a variable 
placeholder to a block placeholder. 
        * 
        * @param                string  Name of the variable placeholder to be 
converted
        * @param                string  Name of the block to be added
        * @param                string  File that contains the block
        * @brother      addBlock()
        */
        function addBlockfile($placeholder, $blockname, $filename) {
                return $this->addBlock($placeholder, $blockname, 
$this->getFile($filename));
        } // end func addBlockfile
        
        /**
        * Deletes one or many variables from the block variable list.
        * @param        string  Blockname
        * @param        mixed           Name of one variable or array of variables ( 
array ( name => true ) ) to be stripped.
        */
        function deleteFromBlockvariablelist($block, $variables) {
        
                if (!is_array($variables))
                        $variables = array( $variables => true);
                        
                reset($this->blockvariables[$block]);
                while (list($k, $varname)=each($this->blockvariables[$block])) 
                        if (isset($variables[$varname])) 
                                unset($this->blockvariables[$block][$k]);
                                        
        } // end deleteFromBlockvariablelist

        /**
        * Updates the variable list of a block.
        * @param        string  Blockname
        */      
        function updateBlockvariablelist($block) {
                
                preg_match_all( $this->variablesRegExp, $this->blocklist[$block], 
$regs );
                $this->blockvariables[$block] = $regs[1];
                        
        } // end func updateBlockvariablelist
        
        /**
        * Returns an array of blocknames where the given variable placeholder is used.
        * @param        string  Variable placeholder
        * @return       array   $parents        parents[0..n] = blockname
        */
        function findPlaceholderBlocks($variable) {
                
                $parents = array();
                
                reset($this->blocklist);
                while (list($blockname, $content)=each($this->blocklist)) {
                        
                        reset($this->blockvariables[$blockname]);
                        while (list($k, 
$varname)=each($this->blockvariables[$blockname]))
                                if ($variable == $varname) 
                                        $parents[] = $blockname;
                }
                        
                return $parents;
        } // end func findPlaceholderBlocks

        /**
        * Handles warnings, saves them to $warn and prints them or calls die() 
depending on the flags
        * @param        string  Warning
        * @param        string  File where the warning occured
        * @param        int                     Linenumber where thr warning occured
        * @see          $warn, $printWarning, $haltOnWarning
        */
        function warning($message, $file="", $line=0) {
                
                $message = sprintf("IntegratedTemplateExtension Warning: %s [File: %s, 
Line: %d]",
                                                                                       
                 $message,
                                                                                       
                 $file, 
                                                                                       
                 $line );

                $this->warn[] = $message;
                
                if ($this->printWarning)
                        print $message;
                        
                if ($this->haltOnError) 
                        die($message);
                
        } // end func warning
        
} // end class IntegratedTemplateExtension
?>
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to