cvs: pear /HTML_Template_IT IT.php ITX.php

From: Date: Fri, 28 Oct 2005 10:22:56 +0000
Subject: cvs: pear /HTML_Template_IT IT.php ITX.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35921@lists.php.net to get a copy of this message
dufuz Fri Oct 28 06:22:56 2005 EDT Modified files: /pear/HTML_Template_IT IT.php ITX.php Log: WS fixes and insuring setOptions only takes in arrays and use array_key_exists in setOption instead of isset

http://cvs.php.net/diff.php/pear/HTML_Template_IT/IT.php?r1=1.10&r2=1.11&ty=u Index: pear/HTML_Template_IT/IT.php diff -u pear/HTML_Template_IT/IT.php:1.10 pear/HTML_Template_IT/IT.php:1.11 --- pear/HTML_Template_IT/IT.php:1.10 Fri Oct 28 05:40:22 2005 +++ pear/HTML_Template_IT/IT.php Fri Oct 28 06:22:54 2005 @@ -16,7 +16,7 @@ // | Author: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: IT.php,v 1.10 2005/10/28 09:40:22 dufuz Exp $ +// $Id: IT.php,v 1.11 2005/10/28 10:22:54 dufuz Exp $ // require_once 'PEAR.php'; @@ -118,7 +118,7 @@ * </code> * * @author Ulf Wendel <uw@netuse.de> - * @version $Id: IT.php,v 1.10 2005/10/28 09:40:22 dufuz Exp $ + * @version $Id: IT.php,v 1.11 2005/10/28 10:22:54 dufuz Exp $ * @access public * @package HTML_Template_IT */ @@ -357,7 +357,6 @@ 'use_preg' => true ); - /** * Builds some complex regular expressions and optinally sets the * file root directory. @@ -398,7 +397,7 @@ */ function setOption($option, $value) { - if (isset($this->_options[$option])) { + if (array_key_exists($option, $this->_options)) { $this->_options[$option] = $value; return IT_OK; } @@ -423,10 +422,12 @@ */ function setOptions($options) { - foreach ($options as $option => $value){ - $error = $this->setOption($option, $value); - if (PEAR::isError($error)) { - return $error; + if (is_array($options)) { + foreach ($options as $option => $value) { + $error = $this->setOption($option, $value); + if (PEAR::isError($error)) { + return $error; + } } } @@ -453,14 +454,13 @@ */ function get($block = "__global__") { - if ($block == "__global__" && !$this->flagGlobalParsed) { $this->parse("__global__"); } if (!isset($this->blocklist[$block])) { $this->err[] = PEAR::raiseError( - $this->errorMessage( IT_BLOCK_NOT_FOUND ) . + $this->errorMessage(IT_BLOCK_NOT_FOUND) . '"' . $block . "'", IT_BLOCK_NOT_FOUND ); @@ -566,6 +566,7 @@ } else { $funcReplace = 'str_replace'; } + if ($this->_options['preserve_data']) { $values = array_map( array(&$this, '_preserveOpeningDelimiter'), $values @@ -578,25 +579,18 @@ $outer = preg_replace($this->removeVariablesRegExp, "", $outer); } } - if ($empty) { + if ($empty) { if (!$this->removeEmptyBlocks) { - $this->blockdata[$block ].= $outer; - } else { - if (isset($this->touchedBlocks[$block])) { $this->blockdata[$block] .= $outer; unset($this->touchedBlocks[$block]); } - } - } else { - $this->blockdata[$block] .= $outer; - } return $empty; @@ -672,11 +666,10 @@ */ function touchBlock($block) { - if (!isset($this->blocklist[$block])) { return PEAR::raiseError( - $this->errorMessage( IT_BLOCK_NOT_FOUND ) . - '"' . $block . "'", IT_BLOCK_NOT_FOUND ); + $this->errorMessage(IT_BLOCK_NOT_FOUND) . + '"' . $block . "'", IT_BLOCK_NOT_FOUND); } $this->touchedBlocks[$block] = true; @@ -696,13 +689,11 @@ */ function init() { - $this->free(); $this->findBlocks($this->template); // we don't need it any more $this->template = ''; $this->buildBlockvariablelist(); - } // end func init /** @@ -715,7 +706,6 @@ */ function free() { - $this->err = array(); $this->currentBlock = "__global__"; @@ -726,7 +716,6 @@ $this->flagBlocktrouble = false; $this->flagGlobalParsed = false; - } // end func free /** @@ -744,7 +733,6 @@ function setTemplate( $template, $removeUnknownVariables = true, $removeEmptyBlocks = true) { - $this->removeUnknownVariables = $removeUnknownVariables; $this->removeEmptyBlocks = $removeEmptyBlocks; @@ -781,7 +769,6 @@ $removeUnknownVariables = true, $removeEmptyBlocks = true ) { - $template = ''; if (!$this->flagCacheTemplatefile || $this->lastTemplatefile != $filename @@ -809,7 +796,6 @@ */ function setRoot($root) { - if ($root != '' && substr($root, -1) != '/') { $root .= '/'; } @@ -822,7 +808,6 @@ */ function buildBlockvariablelist() { - foreach ($this->blocklist as $name => $content) { preg_match_all($this->variablesRegExp, $content, $regs); @@ -866,12 +851,8 @@ { $blocklist = array(); - if ( - preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER) - ) { - + if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) { foreach ($regs as $k => $match) { - $blockname = $match[1]; $blockcontent = $match[2]; @@ -892,7 +873,6 @@ $inner = $this->findBlocks($blockcontent); foreach ($inner as $k => $name) { - $pattern = sprintf( '@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm', $name, @@ -908,11 +888,8 @@ ); $this->blockinner[$blockname][] = $name; $this->blockparents[$name] = $blockname; - } - } - } return $blocklist; @@ -948,7 +925,6 @@ ); } // end func getFile - /** * Adds delimiters to a string, so it can be used as a pattern * in preg_* functions @@ -961,7 +937,6 @@ return '@' . $str . '@'; } - /** * Replaces an opening delimiter by a special string * http://cvs.php.net/diff.php/pear/HTML_Template_IT/ITX.php?r1=1.10&r2=1.11&ty=u Index: pear/HTML_Template_IT/ITX.php diff -u pear/HTML_Template_IT/ITX.php:1.10 pear/HTML_Template_IT/ITX.php:1.11 --- pear/HTML_Template_IT/ITX.php:1.10 Fri Oct 28 05:40:22 2005 +++ pear/HTML_Template_IT/ITX.php Fri Oct 28 06:22:54 2005 @@ -16,7 +16,7 @@ // | Author: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: ITX.php,v 1.10 2005/10/28 09:40:22 dufuz Exp $ +// $Id: ITX.php,v 1.11 2005/10/28 10:22:54 dufuz Exp $ // require_once 'HTML/Template/IT.php'; @@ -36,7 +36,7 @@ * * @author Ulf Wendel <uw@netuse.de> * @access public -* @version $Id: ITX.php,v 1.10 2005/10/28 09:40:22 dufuz Exp $ +* @version $Id: ITX.php,v 1.11 2005/10/28 10:22:54 dufuz Exp $ * @package IT[X] */ class HTML_Template_ITX extends HTML_Template_IT { @@ -247,7 +247,6 @@ */ function addBlock($placeholder, $blockname, $template) { - // Don't trust any user even if it's a programmer or yourself... if ($placeholder == '') { return new IT_Error('No variable placeholder given.', @@ -399,7 +398,6 @@ */ function performCallback() { - reset($this->functions); while (list($func_id, $function) = each($this->functions)) { if (isset($this->callback[$function['name']])) { @@ -492,7 +490,6 @@ function setCallbackFunction($tplfunction, $callbackfunction, $callbackobject = '') { - if ($tplfunction == '' || $callbackfunction == '') { return new IT_Error( "No template function "."('$tplfunction')". @@ -655,7 +652,6 @@ } // end func buildFunctionlist - function getValue($code, $delimiter) { if ($code == '') { return ''; @@ -673,7 +669,6 @@ $i = 1; } else { for ($i = 0; $i < $len; ++$i) { - $char = $code[$i]; if ( @@ -695,13 +690,11 @@ break; } } - } return substr($code, 0, $i); } // end func getValue - /** * Deletes one or many variables from the block variable list. * @@ -755,7 +748,6 @@ $this->updateBlockvariablelist($childBlock); } } - } // end func updateBlockvariablelist /**
« previous php.pear.cvs (#35921) next »