mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
assigned vars are no longer in global name space, few debug cleanups
This commit is contained in:
8
NEWS
8
NEWS
@@ -1,9 +1,15 @@
|
||||
- assigned variables are not longer in global
|
||||
namespace, saving extract() calls and speeding
|
||||
up fetch() and display() linearly with no. of
|
||||
assigned variables (Monte)
|
||||
- added trimwhitespace output filter to dist. (Monte)
|
||||
- fix popup function to allow newlines in text (Monte)
|
||||
- escape html entities in html_options (Monte)
|
||||
- fixed bug with label for html_options (Monte)
|
||||
- added caching to config file loading (Monte)
|
||||
- added "extra" parameter to mailto function (Monte,
|
||||
Massimiliano Perantoni)
|
||||
- added mailto function to default plugin list (Monte)
|
||||
- added mailto plugin to dist. (Monte)
|
||||
|
||||
Version 2.3.1
|
||||
-------------
|
||||
|
@@ -185,7 +185,6 @@ class Smarty
|
||||
array('vars' => array(), 'files' => array()));
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '2.3.1'; // Smarty version number
|
||||
var $_extract = false; // flag for custom functions
|
||||
var $_inclusion_depth = 0; // current template inclusion depth
|
||||
var $_compile_id = null; // for different compiled templates
|
||||
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
|
||||
@@ -227,10 +226,11 @@ class Smarty
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($this->debug_tpl)) {
|
||||
// set path to debug template from SMARTY_DIR
|
||||
$this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl';
|
||||
}
|
||||
// setup debugging
|
||||
if (!$this->debugging && $this->debugging_ctrl == 'URL'
|
||||
&& strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) {
|
||||
$this->debugging = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,6 @@ class Smarty
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = $value;
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -261,7 +260,6 @@ class Smarty
|
||||
{
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = &$value;
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -287,7 +285,6 @@ class Smarty
|
||||
$this->_tpl_vars[$tpl_var][] = $value;
|
||||
}
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -302,7 +299,6 @@ class Smarty
|
||||
}
|
||||
$this->_tpl_vars[$tpl_var][] = &$value;
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -620,11 +616,6 @@ class Smarty
|
||||
{
|
||||
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
|
||||
|
||||
if (!$this->debugging && $this->debugging_ctrl == 'URL'
|
||||
&& strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) {
|
||||
$this->debugging = true;
|
||||
}
|
||||
|
||||
if ($this->debugging) {
|
||||
// capture time for debugging info
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
@@ -634,11 +625,11 @@ class Smarty
|
||||
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
|
||||
}
|
||||
|
||||
if (!isset($_smarty_compile_id))
|
||||
if (!isset($_smarty_compile_id)) {
|
||||
$_smarty_compile_id = $this->compile_id;
|
||||
}
|
||||
|
||||
$this->_compile_id = $_smarty_compile_id;
|
||||
|
||||
$this->_inclusion_depth = 0;
|
||||
|
||||
if ($this->caching) {
|
||||
@@ -680,16 +671,9 @@ class Smarty
|
||||
}
|
||||
}
|
||||
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
/* Initialize config array. */
|
||||
/*
|
||||
$this->_config = array(array('vars' => array(),
|
||||
'files' => array()));
|
||||
*/
|
||||
|
||||
if (count($this->autoload_filters))
|
||||
if (count($this->autoload_filters)) {
|
||||
$this->_autoload_filters();
|
||||
}
|
||||
|
||||
$_smarty_compile_path = $this->_get_compile_path($_smarty_tpl_file);
|
||||
|
||||
@@ -772,6 +756,12 @@ class Smarty
|
||||
function _generate_debug_output() {
|
||||
// we must force compile the debug template in case the environment
|
||||
// changed between separate applications.
|
||||
|
||||
if(empty($this->debug_tpl)) {
|
||||
// set path to debug template from SMARTY_DIR
|
||||
$this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl';
|
||||
}
|
||||
|
||||
$_ldelim_orig = $this->left_delimiter;
|
||||
$_rdelim_orig = $this->right_delimiter;
|
||||
|
||||
@@ -878,7 +868,7 @@ function _generate_debug_output() {
|
||||
|
||||
if ($resource_type == 'file') {
|
||||
$readable = false;
|
||||
if(@is_file($resource_name)) {
|
||||
if(file_exists($resource_name) && is_readable($resource_name)) {
|
||||
$readable = true;
|
||||
} else {
|
||||
// test for file in include_path
|
||||
@@ -1011,7 +1001,7 @@ function _generate_debug_output() {
|
||||
// use the first directory where the file is found
|
||||
foreach ((array)$file_base_path as $_curr_path) {
|
||||
$_fullpath = $_curr_path . DIR_SEP . $resource_name;
|
||||
if (@is_file($_fullpath)) {
|
||||
if (file_exists($_fullpath) && is_file($_fullpath)) {
|
||||
$resource_name = $_fullpath;
|
||||
return true;
|
||||
}
|
||||
@@ -1142,7 +1132,6 @@ function _generate_debug_output() {
|
||||
}
|
||||
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
// config vars are treated as local, so push a copy of the
|
||||
// current ones onto the front of the stack
|
||||
@@ -1651,7 +1640,7 @@ function _run_insert_handler($args)
|
||||
\*======================================================================*/
|
||||
function _create_dir_structure($dir)
|
||||
{
|
||||
if (!@file_exists($dir)) {
|
||||
if (!file_exists($dir)) {
|
||||
$_dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$_new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : '';
|
||||
|
||||
@@ -1680,7 +1669,7 @@ function _run_insert_handler($args)
|
||||
$_make_new_dir = true;
|
||||
}
|
||||
|
||||
if ($_make_new_dir && !@file_exists($_new_dir) && !@mkdir($_new_dir, 0771)) {
|
||||
if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, 0771)) {
|
||||
$this->trigger_error("problem creating directory \"$dir\"");
|
||||
return false;
|
||||
}
|
||||
@@ -2078,7 +2067,7 @@ function _run_insert_handler($args)
|
||||
Function: _get_include_path
|
||||
Purpose: Get path to file from include_path
|
||||
\*======================================================================*/
|
||||
function _get_include_path($file_path,&$new_file_path)
|
||||
function _get_include_path($file_path, &$new_file_path)
|
||||
{
|
||||
static $_path_array = null;
|
||||
|
||||
@@ -2093,7 +2082,7 @@ function _run_insert_handler($args)
|
||||
}
|
||||
}
|
||||
foreach ($_path_array as $_include_path) {
|
||||
if (@file_exists($_include_path . DIR_SEP . $file_path)) {
|
||||
if (file_exists($_include_path . DIR_SEP . $file_path)) {
|
||||
$new_file_path = $_include_path . DIR_SEP . $file_path;
|
||||
return true;
|
||||
}
|
||||
|
@@ -235,9 +235,10 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
/* If the tag name matches a variable or section property definition,
|
||||
we simply process it. */
|
||||
|
||||
if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable
|
||||
preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable
|
||||
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
|
||||
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
|
||||
settype($tag_command, 'array');
|
||||
$this->_parse_vars_props($tag_command);
|
||||
return "<?php echo $tag_command[0]; ?>\n";
|
||||
@@ -490,7 +491,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
return "<?php \$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this); if(\$this->_extract) { extract(\$this->_tpl_vars); \$this->_extract=false; } ?>";
|
||||
return "<?php \$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this); ?>";
|
||||
}
|
||||
|
||||
|
||||
@@ -1075,11 +1076,27 @@ class Smarty_Compiler extends Smarty {
|
||||
\*======================================================================*/
|
||||
function _parse_vars_props(&$tokens)
|
||||
{
|
||||
|
||||
$qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
|
||||
|
||||
$var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$quoted_exprs = preg_grep('!^' . $qstr_regexp . '$!', $tokens);
|
||||
|
||||
if (count($quoted_exprs)) {
|
||||
// replace variables embedded in quotes
|
||||
foreach ($quoted_exprs as $expr_index => $var_expr) {
|
||||
if(preg_match_all('|(?<!\\\\)\$\w+|', $var_expr, $match)) {
|
||||
rsort($match[0]);
|
||||
reset($match[0]);
|
||||
foreach($match[0] as $var) {
|
||||
$var_expr = str_replace ($var, '".' . $this->_parse_var($var) . '."', $var_expr);
|
||||
}
|
||||
$tokens[$expr_index] = preg_replace(array('!^""\.!','!\.""\.!'), array('','.'), $var_expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($var_exprs)) {
|
||||
foreach ($var_exprs as $expr_index => $var_expr) {
|
||||
@@ -1098,6 +1115,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$tokens[$expr_index] = $this->_parse_section_prop($section_prop_expr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -185,7 +185,6 @@ class Smarty
|
||||
array('vars' => array(), 'files' => array()));
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '2.3.1'; // Smarty version number
|
||||
var $_extract = false; // flag for custom functions
|
||||
var $_inclusion_depth = 0; // current template inclusion depth
|
||||
var $_compile_id = null; // for different compiled templates
|
||||
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
|
||||
@@ -227,10 +226,11 @@ class Smarty
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($this->debug_tpl)) {
|
||||
// set path to debug template from SMARTY_DIR
|
||||
$this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl';
|
||||
}
|
||||
// setup debugging
|
||||
if (!$this->debugging && $this->debugging_ctrl == 'URL'
|
||||
&& strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) {
|
||||
$this->debugging = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,6 @@ class Smarty
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = $value;
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -261,7 +260,6 @@ class Smarty
|
||||
{
|
||||
if ($tpl_var != '')
|
||||
$this->_tpl_vars[$tpl_var] = &$value;
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -287,7 +285,6 @@ class Smarty
|
||||
$this->_tpl_vars[$tpl_var][] = $value;
|
||||
}
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -302,7 +299,6 @@ class Smarty
|
||||
}
|
||||
$this->_tpl_vars[$tpl_var][] = &$value;
|
||||
}
|
||||
$this->_extract = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -620,11 +616,6 @@ class Smarty
|
||||
{
|
||||
$_smarty_old_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
|
||||
|
||||
if (!$this->debugging && $this->debugging_ctrl == 'URL'
|
||||
&& strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'], $this->_smarty_debug_id)) {
|
||||
$this->debugging = true;
|
||||
}
|
||||
|
||||
if ($this->debugging) {
|
||||
// capture time for debugging info
|
||||
$debug_start_time = $this->_get_microtime();
|
||||
@@ -634,11 +625,11 @@ class Smarty
|
||||
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
|
||||
}
|
||||
|
||||
if (!isset($_smarty_compile_id))
|
||||
if (!isset($_smarty_compile_id)) {
|
||||
$_smarty_compile_id = $this->compile_id;
|
||||
}
|
||||
|
||||
$this->_compile_id = $_smarty_compile_id;
|
||||
|
||||
$this->_inclusion_depth = 0;
|
||||
|
||||
if ($this->caching) {
|
||||
@@ -680,16 +671,9 @@ class Smarty
|
||||
}
|
||||
}
|
||||
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
/* Initialize config array. */
|
||||
/*
|
||||
$this->_config = array(array('vars' => array(),
|
||||
'files' => array()));
|
||||
*/
|
||||
|
||||
if (count($this->autoload_filters))
|
||||
if (count($this->autoload_filters)) {
|
||||
$this->_autoload_filters();
|
||||
}
|
||||
|
||||
$_smarty_compile_path = $this->_get_compile_path($_smarty_tpl_file);
|
||||
|
||||
@@ -772,6 +756,12 @@ class Smarty
|
||||
function _generate_debug_output() {
|
||||
// we must force compile the debug template in case the environment
|
||||
// changed between separate applications.
|
||||
|
||||
if(empty($this->debug_tpl)) {
|
||||
// set path to debug template from SMARTY_DIR
|
||||
$this->debug_tpl = 'file:'.SMARTY_DIR.'debug.tpl';
|
||||
}
|
||||
|
||||
$_ldelim_orig = $this->left_delimiter;
|
||||
$_rdelim_orig = $this->right_delimiter;
|
||||
|
||||
@@ -878,7 +868,7 @@ function _generate_debug_output() {
|
||||
|
||||
if ($resource_type == 'file') {
|
||||
$readable = false;
|
||||
if(@is_file($resource_name)) {
|
||||
if(file_exists($resource_name) && is_readable($resource_name)) {
|
||||
$readable = true;
|
||||
} else {
|
||||
// test for file in include_path
|
||||
@@ -1011,7 +1001,7 @@ function _generate_debug_output() {
|
||||
// use the first directory where the file is found
|
||||
foreach ((array)$file_base_path as $_curr_path) {
|
||||
$_fullpath = $_curr_path . DIR_SEP . $resource_name;
|
||||
if (@is_file($_fullpath)) {
|
||||
if (file_exists($_fullpath) && is_file($_fullpath)) {
|
||||
$resource_name = $_fullpath;
|
||||
return true;
|
||||
}
|
||||
@@ -1142,7 +1132,6 @@ function _generate_debug_output() {
|
||||
}
|
||||
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
// config vars are treated as local, so push a copy of the
|
||||
// current ones onto the front of the stack
|
||||
@@ -1651,7 +1640,7 @@ function _run_insert_handler($args)
|
||||
\*======================================================================*/
|
||||
function _create_dir_structure($dir)
|
||||
{
|
||||
if (!@file_exists($dir)) {
|
||||
if (!file_exists($dir)) {
|
||||
$_dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$_new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : '';
|
||||
|
||||
@@ -1680,7 +1669,7 @@ function _run_insert_handler($args)
|
||||
$_make_new_dir = true;
|
||||
}
|
||||
|
||||
if ($_make_new_dir && !@file_exists($_new_dir) && !@mkdir($_new_dir, 0771)) {
|
||||
if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, 0771)) {
|
||||
$this->trigger_error("problem creating directory \"$dir\"");
|
||||
return false;
|
||||
}
|
||||
@@ -2078,7 +2067,7 @@ function _run_insert_handler($args)
|
||||
Function: _get_include_path
|
||||
Purpose: Get path to file from include_path
|
||||
\*======================================================================*/
|
||||
function _get_include_path($file_path,&$new_file_path)
|
||||
function _get_include_path($file_path, &$new_file_path)
|
||||
{
|
||||
static $_path_array = null;
|
||||
|
||||
@@ -2093,7 +2082,7 @@ function _run_insert_handler($args)
|
||||
}
|
||||
}
|
||||
foreach ($_path_array as $_include_path) {
|
||||
if (@file_exists($_include_path . DIR_SEP . $file_path)) {
|
||||
if (file_exists($_include_path . DIR_SEP . $file_path)) {
|
||||
$new_file_path = $_include_path . DIR_SEP . $file_path;
|
||||
return true;
|
||||
}
|
||||
|
@@ -235,9 +235,10 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
/* If the tag name matches a variable or section property definition,
|
||||
we simply process it. */
|
||||
|
||||
if (preg_match('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // if a variable
|
||||
preg_match('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command) || // or a configuration variable
|
||||
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
|
||||
preg_match('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tag_command)) { // or a section property
|
||||
settype($tag_command, 'array');
|
||||
$this->_parse_vars_props($tag_command);
|
||||
return "<?php echo $tag_command[0]; ?>\n";
|
||||
@@ -490,7 +491,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
return "<?php \$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this); if(\$this->_extract) { extract(\$this->_tpl_vars); \$this->_extract=false; } ?>";
|
||||
return "<?php \$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this); ?>";
|
||||
}
|
||||
|
||||
|
||||
@@ -1075,11 +1076,27 @@ class Smarty_Compiler extends Smarty {
|
||||
\*======================================================================*/
|
||||
function _parse_vars_props(&$tokens)
|
||||
{
|
||||
|
||||
$qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
|
||||
|
||||
$var_exprs = preg_grep('!^\$\w+(?>(\[(\d+|\$\w+|\w+(\.\w+)?)\])|((\.|->)\$?\w+))*(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$conf_var_exprs = preg_grep('!^#(\w+)#(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$sect_prop_exprs = preg_grep('!^%\w+\.\w+%(?>\|@?\w+(:(?>' . $qstr_regexp . '|[^|]+))*)*$!', $tokens);
|
||||
$quoted_exprs = preg_grep('!^' . $qstr_regexp . '$!', $tokens);
|
||||
|
||||
if (count($quoted_exprs)) {
|
||||
// replace variables embedded in quotes
|
||||
foreach ($quoted_exprs as $expr_index => $var_expr) {
|
||||
if(preg_match_all('|(?<!\\\\)\$\w+|', $var_expr, $match)) {
|
||||
rsort($match[0]);
|
||||
reset($match[0]);
|
||||
foreach($match[0] as $var) {
|
||||
$var_expr = str_replace ($var, '".' . $this->_parse_var($var) . '."', $var_expr);
|
||||
}
|
||||
$tokens[$expr_index] = preg_replace(array('!^""\.!','!\.""\.!'), array('','.'), $var_expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($var_exprs)) {
|
||||
foreach ($var_exprs as $expr_index => $var_expr) {
|
||||
@@ -1098,6 +1115,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$tokens[$expr_index] = $this->_parse_section_prop($section_prop_expr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
49
libs/plugins/outputfilter.trimwhitespace.php
Normal file
49
libs/plugins/outputfilter.trimwhitespace.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: outputfilter.trimwhitespace.php
|
||||
* Type: outputfilter
|
||||
* Name: trimwhitespace
|
||||
* Version: 1.2
|
||||
* Date: April 30, 2002
|
||||
* Purpose: trim leading white space and blank lines from
|
||||
* template source after it gets interpreted, cleaning
|
||||
* up code and saving bandwidth. Does not affect
|
||||
* <PRE></PRE> and <SCRIPT></SCRIPT> blocks.
|
||||
* Install: Drop into the plugin directory, call
|
||||
* $smarty->load_filter('output','trimwhitespace');
|
||||
* from application.
|
||||
* Author: Monte Ohrt <monte@ispi.net>
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
||||
{
|
||||
// Pull out the script blocks
|
||||
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
|
||||
$_script_blocks = $match[0];
|
||||
$source = preg_replace("!<script[^>]+>.*?</script>!is",
|
||||
'@@@SMARTY:TRIM:SCRIPT@@@', $source);
|
||||
|
||||
// Pull out the pre blocks
|
||||
preg_match_all("!<pre>.*?</pre>!is", $source, $match);
|
||||
$_pre_blocks = $match[0];
|
||||
$source = preg_replace("!<pre>.*?</pre>!is",
|
||||
'@@@SMARTY:TRIM:PRE@@@', $source);
|
||||
|
||||
// remove all leading spaces, tabs and carriage returns NOT
|
||||
// preceeded by a php close tag.
|
||||
$source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
|
||||
|
||||
// replace script blocks
|
||||
foreach($_script_blocks as $curr_block) {
|
||||
$source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1);
|
||||
}
|
||||
// replace pre blocks
|
||||
foreach($_pre_blocks as $curr_block) {
|
||||
$source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
?>
|
49
plugins/outputfilter.trimwhitespace.php
Normal file
49
plugins/outputfilter.trimwhitespace.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: outputfilter.trimwhitespace.php
|
||||
* Type: outputfilter
|
||||
* Name: trimwhitespace
|
||||
* Version: 1.2
|
||||
* Date: April 30, 2002
|
||||
* Purpose: trim leading white space and blank lines from
|
||||
* template source after it gets interpreted, cleaning
|
||||
* up code and saving bandwidth. Does not affect
|
||||
* <PRE></PRE> and <SCRIPT></SCRIPT> blocks.
|
||||
* Install: Drop into the plugin directory, call
|
||||
* $smarty->load_filter('output','trimwhitespace');
|
||||
* from application.
|
||||
* Author: Monte Ohrt <monte@ispi.net>
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
||||
{
|
||||
// Pull out the script blocks
|
||||
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
|
||||
$_script_blocks = $match[0];
|
||||
$source = preg_replace("!<script[^>]+>.*?</script>!is",
|
||||
'@@@SMARTY:TRIM:SCRIPT@@@', $source);
|
||||
|
||||
// Pull out the pre blocks
|
||||
preg_match_all("!<pre>.*?</pre>!is", $source, $match);
|
||||
$_pre_blocks = $match[0];
|
||||
$source = preg_replace("!<pre>.*?</pre>!is",
|
||||
'@@@SMARTY:TRIM:PRE@@@', $source);
|
||||
|
||||
// remove all leading spaces, tabs and carriage returns NOT
|
||||
// preceeded by a php close tag.
|
||||
$source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
|
||||
|
||||
// replace script blocks
|
||||
foreach($_script_blocks as $curr_block) {
|
||||
$source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1);
|
||||
}
|
||||
// replace pre blocks
|
||||
foreach($_pre_blocks as $curr_block) {
|
||||
$source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user