cvs: php4 /pear/HTML ITX.php

From: Date: Fri, 27 Jul 2001 12:47:17 +0000
Subject: cvs: php4 /pear/HTML ITX.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-354@lists.php.net to get a copy of this message
mansion Fri Jul 27 08:47:17 2001 EDT Modified files: /php4/pear/HTML ITX.php Log: Fixes for methods addBlock and addBlockfile. It is now possible to use external files to replace internal template variables. Index: php4/pear/HTML/ITX.php diff -u php4/pear/HTML/ITX.php:1.5 php4/pear/HTML/ITX.php:1.6 --- php4/pear/HTML/ITX.php:1.5 Thu Mar 29 16:49:15 2001 +++ php4/pear/HTML/ITX.php Fri Jul 27 08:47:17 2001 @@ -16,7 +16,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: ITX.php,v 1.5 2001/03/29 21:49:15 uw Exp $ +// $Id: ITX.php,v 1.6 2001/07/27 12:47:17 mansion Exp $ // require_once "HTML/IT.php"; @@ -28,14 +28,14 @@ * 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. +* you to modify some parts of your layout easily. * -* Note that you can replace an existing block and add new blocks add runtime. +* Note that you can replace an existing block and add new blocks at runtime. * Adding new blocks means changing a variable placeholder to a block. * * @author Ulf Wendel <uw@netuse.de> * @access public -* @version $Id: ITX.php,v 1.5 2001/03/29 21:49:15 uw Exp $ +* @version $Id: ITX.php,v 1.6 2001/07/27 12:47:17 mansion Exp $ * @package IT[X] */ class IntegratedTemplateExtension extends IntegratedTemplate { @@ -109,7 +109,7 @@ /** * Builds some complex regexps and calls the constructor of the parent class. * - * Make sure that you call this constructor if you derive you own + * Make sure that you call this constructor if you derive your own * template class from this one. * * @see IntegratedTemplate() @@ -211,7 +211,7 @@ * @access public */ function addBlock($placeholder, $blockname, $template) { - + // Don't trust any user even if it's a programmer or yourself... if ("" == $placeholder) { @@ -219,7 +219,6 @@ } else if ("" == $blockname || !preg_match($this->checkblocknameRegExp, $blockname) ) { - print $this->checkblocknameRegExp; return new IT_Error("No or invalid blockname '$blockname' given.", __FILE__, __LINE__); } else if ("" == $template) { @@ -231,8 +230,7 @@ return new IT_Error("The block already exists.", __FILE__, __LINE__); } - - // Hmm, we should do some more tests. + $parents = $this->findPlaceholderBlocks($placeholder); if (0 == count($parents)) { @@ -253,13 +251,13 @@ $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->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); @@ -584,10 +582,10 @@ $variables = array($variables => true); reset($this->blockvariables[$block]); - while (list($k, $varname) = each($this->blockvariables[$block])) + while (list($varname, $val) = each($this->blockvariables[$block])) if (isset($variables[$varname])) - unset($this->blockvariables[$block][$k]); - + unset($this->blockvariables[$block][$varname]); + } // end deleteFromBlockvariablelist /** @@ -598,7 +596,9 @@ function updateBlockvariablelist($block) { preg_match_all( $this->variablesRegExp, $this->blocklist[$block], $regs ); - $this->blockvariables[$block] = $regs[1]; + while (list($k,$varname) = each($regs[1])) { + $this->blockvariables[$block][$varname] = true; + } } // end func updateBlockvariablelist @@ -609,18 +609,17 @@ * @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) + while (list($varname, $val) = each($this->blockvariables[$blockname])) { + if ($variable == $varname) { $parents[] = $blockname; + } + } } - + return $parents; } // end func findPlaceholderBlocks

« previous php.pear.cvs (#354) next »