reverted {strip} from a block-plugin back into the compiler

This commit is contained in:
messju
2003-08-20 14:48:36 +00:00
parent 7524542a24
commit 60e984f942
3 changed files with 24 additions and 35 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- moved {strip} back into the compiler (messju)
- fixed config_load: handling of section-attribute and use of - fixed config_load: handling of section-attribute and use of
multiple config-files in one template (atu, messju) multiple config-files in one template (atu, messju)

View File

@@ -330,6 +330,26 @@ class Smarty_Compiler extends Smarty {
} }
$compiled_content .= $text_blocks[$i]; $compiled_content .= $text_blocks[$i];
/* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */
if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $compiled_content, $_match)) {
$strip_tags = $_match[0];
$_strip_search = array(
'%([^\\\\]\?>)\n%', // remove newlines after PHP close tags
"!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", // remove leading/trailing space chars
'%[\r\n]+%m', // remove CRs and newlines
'%([^\\\\]\?>)%'); // replace newlines after PHP close tags
$_strip_replace = array(
'\\1',
'',
'',
'\\1' . "\n");
$strip_tags_modified = preg_replace($_strip_search, $_strip_replace, $strip_tags);
for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++)
$compiled_content = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s",
$this->quote_replace($strip_tags_modified[$i]),
$compiled_content, 1);
}
// remove \n from the end of the file, if any // remove \n from the end of the file, if any
if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) { if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) {
$compiled_content = substr($compiled_content, 0, -1); $compiled_content = substr($compiled_content, 0, -1);
@@ -492,6 +512,9 @@ class Smarty_Compiler extends Smarty {
else else
return "<?php endforeach; endif; ?>"; return "<?php endforeach; endif; ?>";
case 'strip':
case '/strip':
return $this->left_delimiter.$tag_command.$this->right_delimiter;
case 'literal': case 'literal':
list (,$literal_block) = each($this->_literal_blocks); list (,$literal_block) = each($this->_literal_blocks);
$this->_current_line_no += substr_count($literal_block, "\n"); $this->_current_line_no += substr_count($literal_block, "\n");

View File

@@ -1,35 +0,0 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {strip}{/strip} block plugin
*
* Type: block function<br>
* Name: strip<br>
* Purpose: strip unwanted white space from text<br>
* @link http://smarty.php.net/manual/en/language.function.strip.php {strip}
* (Smarty online manual)
* @param array unused, no parameters for this block
* @param string content of {strip}{/strip} tags
* @param Smarty clever method emulation
* @return string $content stripped of whitespace
*/
function smarty_block_strip($params, $content, &$smarty)
{
/* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */
$_strip_search = array(
"![\t ]+$|^[\t ]+!m", // remove leading/trailing space chars
'%[\r\n]+%m'); // remove CRs and newlines
$_strip_replace = array(
'',
'');
return preg_replace($_strip_search, $_strip_replace, $content);
}
/* vim: set expandtab: */
?>