patch for IT.php
| From: | Dan Allen | Date: | Tue, 21 May 2002 00:56:16 +0000 |
| Subject: | patch for IT.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-6252@lists.php.net to get a copy of this message | ||
You can throw it back in my face if you don't like it, but here is
the patch to add a delimiter option in the blocks so that the
template may take on this sort of functionality
---------------------------------
<!-- BEGIN block_name {<br />} -->
{foo}
<!-- END block_name -->
result | result | result
---------------------------------
Dan
--- IT.php.orig Mon May 20 17:51:18 2002 +++ IT.php Mon May 20 17:51:54 2002 @@ -224,6 +224,13 @@ var $blocklist = array(); /** + * Array of all blocks which have been parsed at least one + * + * @var array + */ + var $parsedlist = array(); + + /** * Array with the parsed content of a block. * * @var array @@ -231,6 +238,13 @@ var $blockdata = array(); /** + * Array with the delimiter used between iterations of a block. + * + * @var array + */ + var $blockdelimiter = array(); + + /** * Array of variables in a block. * @var array */ @@ -344,7 +358,7 @@ $this->variablesRegExp = "@" . $this->openingDelimiter . "(" . $this->variablenameRegExp . ")" . $this->closingDelimiter . "@sm"; $this->removeVariablesRegExp = "@" . $this->openingDelimiter . "\s*(" . $this->variablenameRegExp . ")\s*" . $this->closingDelimiter . "@sm"; - $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp . ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm'; + $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp . ')(\s+{(.*?)})?\s+-->(.*)<!--\s+END\s+\1\s+-->@sm'; $this->setRoot($root); } // end constructor @@ -433,6 +447,13 @@ } + if (!empty($this->parsedlist[$block])) { + $this->blocklist[$block] = $this->blockdelimiter[$block] . $this->blocklist[$block]; + } + else { + $this->parsedlist[$block] = true; + } + $outer = (0 == count($regs)) ? $this->blocklist[$block] : preg_replace($regs, $values, $this->blocklist[$block]); $empty = (0 == count($values)) ? true : false; @@ -499,18 +520,13 @@ * @param string prefix for variable names * @access public */ - function setVariable($variable, $value = "") { - + function setVariable($variable, $value = "") + { if (is_array($variable)) { - $this->variableCache = array_merge($this->variableCache, $variable); - } else { - $this->variableCache[$variable] = $value; - } - } // end func setVariable /** @@ -729,7 +745,8 @@ foreach ($regs as $k => $match) { $blockname = $match[1]; - $blockcontent = $match[2]; + $blockdelimiter = isset($match[3]) ? $match[3] : ''; + $blockcontent = $match[4]; if (isset($this->blocklist[$blockname])) { new IT_Error("The name of a block must be unique within a template. Found '$blockname' twice. Unpredictable results may appear.", __FILE__, __LINE__); @@ -738,13 +755,14 @@ $this->blocklist[$blockname] = $blockcontent; $this->blockdata[$blockname] = ""; + $this->blockdelimiter[$blockname] = $blockdelimiter; $blocklist[] = $blockname; $inner = $this->findBlocks($blockcontent); foreach ($inner as $k => $name) { - $pattern = sprintf('@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm', + $pattern = sprintf('@<!--\s+BEGIN\s+%s(\s+{(.*?)})?\s+-->.*<!--\s+END\s+%s\s+-->@sm', $name, $name );
--- IT.php.orig Mon May 20 17:51:18 2002 +++ IT.php Mon May 20 17:51:54 2002 @@ -224,6 +224,13 @@ var $blocklist = array(); /** + * Array of all blocks which have been parsed at least one + * + * @var array + */ + var $parsedlist = array(); + + /** * Array with the parsed content of a block. * * @var array @@ -231,6 +238,13 @@ var $blockdata = array(); /** + * Array with the delimiter used between iterations of a block. + * + * @var array + */ + var $blockdelimiter = array(); + + /** * Array of variables in a block. * @var array */ @@ -344,7 +358,7 @@ $this->variablesRegExp = "@" . $this->openingDelimiter . "(" . $this->variablenameRegExp . ")" . $this->closingDelimiter . "@sm"; $this->removeVariablesRegExp = "@" . $this->openingDelimiter . "\s*(" . $this->variablenameRegExp . ")\s*" . $this->closingDelimiter . "@sm"; - $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp . ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm'; + $this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp . ')(\s+{(.*?)})?\s+-->(.*)<!--\s+END\s+\1\s+-->@sm'; $this->setRoot($root); } // end constructor @@ -433,6 +447,13 @@ } + if (!empty($this->parsedlist[$block])) { + $this->blocklist[$block] = $this->blockdelimiter[$block] . $this->blocklist[$block]; + } + else { + $this->parsedlist[$block] = true; + } + $outer = (0 == count($regs)) ? $this->blocklist[$block] : preg_replace($regs, $values, $this->blocklist[$block]); $empty = (0 == count($values)) ? true : false; @@ -499,18 +520,13 @@ * @param string prefix for variable names * @access public */ - function setVariable($variable, $value = "") { - + function setVariable($variable, $value = "") + { if (is_array($variable)) { - $this->variableCache = array_merge($this->variableCache, $variable); - } else { - $this->variableCache[$variable] = $value; - } - } // end func setVariable /** @@ -729,7 +745,8 @@ foreach ($regs as $k => $match) { $blockname = $match[1]; - $blockcontent = $match[2]; + $blockdelimiter = isset($match[3]) ? $match[3] : ''; + $blockcontent = $match[4]; if (isset($this->blocklist[$blockname])) { new IT_Error("The name of a block must be unique within a template. Found '$blockname' twice. Unpredictable results may appear.", __FILE__, __LINE__); @@ -738,13 +755,14 @@ $this->blocklist[$blockname] = $blockcontent; $this->blockdata[$blockname] = ""; + $this->blockdelimiter[$blockname] = $blockdelimiter; $blocklist[] = $blockname; $inner = $this->findBlocks($blockcontent); foreach ($inner as $k => $name) { - $pattern = sprintf('@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm', + $pattern = sprintf('@<!--\s+BEGIN\s+%s(\s+{(.*?)})?\s+-->.*<!--\s+END\s+%s\s+-->@sm', $name, $name );