Update to Smarty 2.6.22

This commit is contained in:
anubis 2009-01-04 17:34:22 -05:00
parent eedd737a97
commit 60b674c776
18 changed files with 473 additions and 216 deletions

View File

@ -17,15 +17,19 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* @link http://smarty.php.net/ * For questions, help, comments, discussion, etc., please join the
* @version 2.6.12 * Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @version 2.6.22
* @copyright Copyright: 2001-2005 New Digital Group, Inc. * @copyright Copyright: 2001-2005 New Digital Group, Inc.
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @access public * @access public
* @package Smarty * @package Smarty
*/ */
/* $Id: Config_File.class.php,v 1.83 2005/12/14 14:53:55 mohrt Exp $ */ /* $Id: Config_File.class.php 2786 2008-09-18 21:04:38Z Uwe.Tews $ */
/** /**
* Config file reading class * Config file reading class

View File

@ -20,17 +20,17 @@
* *
* For questions, help, comments, discussion, etc., please join the * For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to * Smarty mailing list. Send a blank e-mail to
* smarty-general-subscribe@lists.php.net * smarty-discussion-subscribe@googlegroups.com
* *
* @link http://smarty.php.net/ * @link http://www.smarty.net/
* @copyright 2001-2005 New Digital Group, Inc. * @copyright 2001-2005 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @package Smarty * @package Smarty
* @version 2.6.12 * @version 2.6.22
*/ */
/* $Id: Smarty.class.php,v 1.523 2005/12/31 19:17:04 messju Exp $ */ /* $Id: Smarty.class.php 2785 2008-09-18 21:04:12Z Uwe.Tews $ */
/** /**
* DIR_SEP isn't used anymore, but third party apps might * DIR_SEP isn't used anymore, but third party apps might
@ -464,7 +464,7 @@ class Smarty
* *
* @var string * @var string
*/ */
var $_version = '2.6.12'; var $_version = '2.6.22';
/** /**
* current template inclusion depth * current template inclusion depth
@ -838,69 +838,66 @@ class Smarty
* Registers a prefilter function to apply * Registers a prefilter function to apply
* to a template before compiling * to a template before compiling
* *
* @param string $function name of PHP function to register * @param callback $function
*/ */
function register_prefilter($function) function register_prefilter($function)
{ {
$_name = (is_array($function)) ? $function[1] : $function; $this->_plugins['prefilter'][$this->_get_filter_name($function)]
$this->_plugins['prefilter'][$_name]
= array($function, null, null, false); = array($function, null, null, false);
} }
/** /**
* Unregisters a prefilter function * Unregisters a prefilter function
* *
* @param string $function name of PHP function * @param callback $function
*/ */
function unregister_prefilter($function) function unregister_prefilter($function)
{ {
unset($this->_plugins['prefilter'][$function]); unset($this->_plugins['prefilter'][$this->_get_filter_name($function)]);
} }
/** /**
* Registers a postfilter function to apply * Registers a postfilter function to apply
* to a compiled template after compilation * to a compiled template after compilation
* *
* @param string $function name of PHP function to register * @param callback $function
*/ */
function register_postfilter($function) function register_postfilter($function)
{ {
$_name = (is_array($function)) ? $function[1] : $function; $this->_plugins['postfilter'][$this->_get_filter_name($function)]
$this->_plugins['postfilter'][$_name]
= array($function, null, null, false); = array($function, null, null, false);
} }
/** /**
* Unregisters a postfilter function * Unregisters a postfilter function
* *
* @param string $function name of PHP function * @param callback $function
*/ */
function unregister_postfilter($function) function unregister_postfilter($function)
{ {
unset($this->_plugins['postfilter'][$function]); unset($this->_plugins['postfilter'][$this->_get_filter_name($function)]);
} }
/** /**
* Registers an output filter function to apply * Registers an output filter function to apply
* to a template output * to a template output
* *
* @param string $function name of PHP function * @param callback $function
*/ */
function register_outputfilter($function) function register_outputfilter($function)
{ {
$_name = (is_array($function)) ? $function[1] : $function; $this->_plugins['outputfilter'][$this->_get_filter_name($function)]
$this->_plugins['outputfilter'][$_name]
= array($function, null, null, false); = array($function, null, null, false);
} }
/** /**
* Unregisters an outputfilter function * Unregisters an outputfilter function
* *
* @param string $function name of PHP function * @param callback $function
*/ */
function unregister_outputfilter($function) function unregister_outputfilter($function)
{ {
unset($this->_plugins['outputfilter'][$function]); unset($this->_plugins['outputfilter'][$this->_get_filter_name($function)]);
} }
/** /**
@ -1935,6 +1932,25 @@ class Smarty
{ {
return eval($code); return eval($code);
} }
/**
* Extracts the filter name from the given callback
*
* @param callback $function
* @return string
*/
function _get_filter_name($function)
{
if (is_array($function)) {
$_class_name = (is_object($function[0]) ?
get_class($function[0]) : $function[0]);
return $_class_name . '_' . $function[1];
}
else {
return $function;
}
}
/**#@-*/ /**#@-*/
} }

View File

@ -18,15 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* @link http://smarty.php.net/ * @link http://www.smarty.net/
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @version 2.6.12 * @version 2.6.22
* @copyright 2001-2005 New Digital Group, Inc. * @copyright 2001-2005 New Digital Group, Inc.
* @package Smarty * @package Smarty
*/ */
/* $Id: Smarty_Compiler.class.php,v 1.376 2006/01/15 19:29:45 messju Exp $ */ /* $Id: Smarty_Compiler.class.php 2966 2008-12-08 15:10:03Z monte.ohrt $ */
/** /**
* Template compiling class * Template compiling class
@ -74,12 +74,17 @@ class Smarty_Compiler extends Smarty {
var $_strip_depth = 0; var $_strip_depth = 0;
var $_additional_newline = "\n"; var $_additional_newline = "\n";
var $_phpversion = 0;
/**#@-*/ /**#@-*/
/** /**
* The class constructor. * The class constructor.
*/ */
function Smarty_Compiler() function Smarty_Compiler()
{ {
$this->_phpversion = substr(phpversion(),0,1);
// matches double quoted strings: // matches double quoted strings:
// "foobar" // "foobar"
// "foo\"bar" // "foo\"bar"
@ -152,16 +157,20 @@ class Smarty_Compiler extends Smarty {
// $foo->bar($foo->bar) // $foo->bar($foo->bar)
// $foo->bar($foo->bar()) // $foo->bar($foo->bar())
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar)) // $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
// $foo->getBar()->getFoo()
// $foo->getBar()->foo
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')'; $this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
$this->_obj_restricted_param_regexp = '(?:' $this->_obj_restricted_param_regexp = '(?:'
. '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')' . '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')'
. '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)'; . '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)';
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)'; . $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)'; . '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)'; $this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)'; $this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?(?:' . $this->_dvar_math_regexp . '(?:' . $this->_num_const_regexp . '|' . $this->_dvar_math_var_regexp . ')*)?)';
// matches valid modifier syntax: // matches valid modifier syntax:
// |foo // |foo
@ -278,7 +287,7 @@ class Smarty_Compiler extends Smarty {
/* loop through text blocks */ /* loop through text blocks */
for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) {
/* match anything resembling php tags */ /* match anything resembling php tags */
if (preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)~is', $text_blocks[$curr_tb], $sp_match)) { if (preg_match_all('~(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?\s*php\s*[\"\']?)~is', $text_blocks[$curr_tb], $sp_match)) {
/* replace tags with placeholders to prevent recursive replacements */ /* replace tags with placeholders to prevent recursive replacements */
$sp_match[1] = array_unique($sp_match[1]); $sp_match[1] = array_unique($sp_match[1]);
usort($sp_match[1], '_smarty_sort_length'); usort($sp_match[1], '_smarty_sort_length');
@ -350,15 +359,28 @@ class Smarty_Compiler extends Smarty {
} }
$compiled_content = ''; $compiled_content = '';
$tag_guard = '%%%SMARTYOTG' . md5(uniqid(rand(), true)) . '%%%';
/* Interleave the compiled contents and text blocks to get the final result. */ /* Interleave the compiled contents and text blocks to get the final result. */
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
if ($compiled_tags[$i] == '') { if ($compiled_tags[$i] == '') {
// tag result empty, remove first newline from following text block // tag result empty, remove first newline from following text block
$text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]); $text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]);
} }
$compiled_content .= $text_blocks[$i].$compiled_tags[$i]; // replace legit PHP tags with placeholder
$text_blocks[$i] = str_replace('<?', $tag_guard, $text_blocks[$i]);
$compiled_tags[$i] = str_replace('<?', $tag_guard, $compiled_tags[$i]);
$compiled_content .= $text_blocks[$i] . $compiled_tags[$i];
} }
$compiled_content .= $text_blocks[$i]; $compiled_content .= str_replace('<?', $tag_guard, $text_blocks[$i]);
// escape php tags created by interleaving
$compiled_content = str_replace('<?', "<?php echo '<?' ?>\n", $compiled_content);
$compiled_content = preg_replace("~(?<!')language\s*=\s*[\"\']?\s*php\s*[\"\']?~", "<?php echo 'language=php' ?>\n", $compiled_content);
// recover legit tags
$compiled_content = str_replace($tag_guard, '<?', $compiled_content);
// remove \n from the end of the file, if any // remove \n from the end of the file, if any
if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {
@ -369,9 +391,6 @@ class Smarty_Compiler extends Smarty {
$compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content; $compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content;
} }
// remove unnecessary close/open tags
$compiled_content = preg_replace('~\?>\n?<\?php~', '', $compiled_content);
// run compiled template through postfilter functions // run compiled template through postfilter functions
if (count($this->_plugins['postfilter']) > 0) { if (count($this->_plugins['postfilter']) > 0) {
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
@ -859,7 +878,7 @@ class Smarty_Compiler extends Smarty {
// traditional argument format // traditional argument format
$args = implode(',', array_values($attrs)); $args = implode(',', array_values($attrs));
if (empty($args)) { if (empty($args)) {
$args = 'null'; $args = '';
} }
} }
@ -880,9 +899,9 @@ class Smarty_Compiler extends Smarty {
$prefix .= "while (\$_block_repeat) { ob_start();"; $prefix .= "while (\$_block_repeat) { ob_start();";
$return = null; $return = null;
$postfix = ''; $postfix = '';
} else { } else {
$prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); "; $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;";
$return = "\$_block_repeat=false; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat)"; $return = "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat)";
$postfix = "} array_pop(\$this->_tag_stack);"; $postfix = "} array_pop(\$this->_tag_stack);";
} }
} else { } else {
@ -924,7 +943,11 @@ class Smarty_Compiler extends Smarty {
$name = $this->_dequote($attrs['name']); $name = $this->_dequote($attrs['name']);
if (empty($name)) { if (empty($name)) {
$this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); return $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__);
}
if (!preg_match('~^\w+$~', $name)) {
return $this->_syntax_error("'insert: 'name' must be an insert function name", E_USER_ERROR, __FILE__, __LINE__);
} }
if (!empty($attrs['script'])) { if (!empty($attrs['script'])) {
@ -1157,7 +1180,7 @@ class Smarty_Compiler extends Smarty {
} }
$item = $this->_dequote($attrs['item']); $item = $this->_dequote($attrs['item']);
if (!preg_match('~^\w+$~', $item)) { if (!preg_match('~^\w+$~', $item)) {
return $this->_syntax_error("'foreach: item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__); return $this->_syntax_error("foreach: 'item' must be a variable name (literal string)", E_USER_ERROR, __FILE__, __LINE__);
} }
if (isset($attrs['key'])) { if (isset($attrs['key'])) {
@ -1208,23 +1231,21 @@ class Smarty_Compiler extends Smarty {
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
if ($start) { if ($start) {
if (isset($attrs['name'])) $buffer = isset($attrs['name']) ? $attrs['name'] : "'default'";
$buffer = $attrs['name']; $assign = isset($attrs['assign']) ? $attrs['assign'] : null;
else $append = isset($attrs['append']) ? $attrs['append'] : null;
$buffer = "'default'";
if (isset($attrs['assign']))
$assign = $attrs['assign'];
else
$assign = null;
$output = "<?php ob_start(); ?>"; $output = "<?php ob_start(); ?>";
$this->_capture_stack[] = array($buffer, $assign); $this->_capture_stack[] = array($buffer, $assign, $append);
} else { } else {
list($buffer, $assign) = array_pop($this->_capture_stack); list($buffer, $assign, $append) = array_pop($this->_capture_stack);
$output = "<?php \$this->_smarty_vars['capture'][$buffer] = ob_get_contents(); "; $output = "<?php \$this->_smarty_vars['capture'][$buffer] = ob_get_contents(); ";
if (isset($assign)) { if (isset($assign)) {
$output .= " \$this->assign($assign, ob_get_contents());"; $output .= " \$this->assign($assign, ob_get_contents());";
} }
if (isset($append)) {
$output .= " \$this->append($append, ob_get_contents());";
}
$output .= "ob_end_clean(); ?>"; $output .= "ob_end_clean(); ?>";
} }
@ -1253,7 +1274,7 @@ class Smarty_Compiler extends Smarty {
$tokens = $match[0]; $tokens = $match[0];
if(empty($tokens)) { if(empty($tokens)) {
$_error_msg .= $elseif ? "'elseif'" : "'if'"; $_error_msg = $elseif ? "'elseif'" : "'if'";
$_error_msg .= ' statement requires arguments'; $_error_msg .= ' statement requires arguments';
$this->_syntax_error($_error_msg, E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error($_error_msg, E_USER_ERROR, __FILE__, __LINE__);
} }
@ -1351,9 +1372,14 @@ class Smarty_Compiler extends Smarty {
/* If last token was a ')', we operate on the parenthesized /* If last token was a ')', we operate on the parenthesized
expression. The start of the expression is on the stack. expression. The start of the expression is on the stack.
Otherwise, we operate on the last encountered token. */ Otherwise, we operate on the last encountered token. */
if ($tokens[$i-1] == ')') if ($tokens[$i-1] == ')') {
$is_arg_start = array_pop($is_arg_stack); $is_arg_start = array_pop($is_arg_stack);
else if ($is_arg_start != 0) {
if (preg_match('~^' . $this->_func_regexp . '$~', $tokens[$is_arg_start-1])) {
$is_arg_start--;
}
}
} else
$is_arg_start = $i-1; $is_arg_start = $i-1;
/* Construct the argument for 'is' expression, so it knows /* Construct the argument for 'is' expression, so it knows
what to operate on. */ what to operate on. */
@ -1668,17 +1694,19 @@ class Smarty_Compiler extends Smarty {
// if contains unescaped $, expand it // if contains unescaped $, expand it
if(preg_match_all('~(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) { if(preg_match_all('~(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) {
$_match = $_match[0]; $_match = $_match[0];
rsort($_match); $_replace = array();
reset($_match);
foreach($_match as $_var) { foreach($_match as $_var) {
$var_expr = str_replace ($_var, '".(' . $this->_parse_var(str_replace('`','',$_var)) . ')."', $var_expr); $_replace[$_var] = '".(' . $this->_parse_var(str_replace('`','',$_var)) . ')."';
} }
$var_expr = strtr($var_expr, $_replace);
$_return = preg_replace('~\.""|(?<!\\\\)""\.~', '', $var_expr); $_return = preg_replace('~\.""|(?<!\\\\)""\.~', '', $var_expr);
} else { } else {
$_return = $var_expr; $_return = $var_expr;
} }
// replace double quoted literal string with single quotes // replace double quoted literal string with single quotes
$_return = preg_replace('~^"([\s\w]+)"$~',"'\\1'",$_return); $_return = preg_replace('~^"([\s\w]+)"$~',"'\\1'",$_return);
// escape dollar sign if not printing a var
$_return = preg_replace('~\$(\W)~',"\\\\\$\\1",$_return);
return $_return; return $_return;
} }
@ -1692,6 +1720,7 @@ class Smarty_Compiler extends Smarty {
function _parse_var($var_expr) function _parse_var($var_expr)
{ {
$_has_math = false; $_has_math = false;
$_has_php4_method_chaining = false;
$_math_vars = preg_split('~('.$this->_dvar_math_regexp.'|'.$this->_qstr_regexp.')~', $var_expr, -1, PREG_SPLIT_DELIM_CAPTURE); $_math_vars = preg_split('~('.$this->_dvar_math_regexp.'|'.$this->_qstr_regexp.')~', $var_expr, -1, PREG_SPLIT_DELIM_CAPTURE);
if(count($_math_vars) > 1) { if(count($_math_vars) > 1) {
@ -1804,6 +1833,10 @@ class Smarty_Compiler extends Smarty {
$_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index,3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}'; $_output .= '->{(($_var=$this->_tpl_vars[\''.substr($_index,3).'\']) && substr($_var,0,2)!=\'__\') ? $_var : $this->trigger_error("cannot access property \\"$_var\\"")}';
} }
} else { } else {
if ($this->_phpversion < 5) {
$_has_php4_method_chaining = true;
$_output .= "; \$_foo = \$_foo";
}
$_output .= $_index; $_output .= $_index;
} }
} elseif (substr($_index, 0, 1) == '(') { } elseif (substr($_index, 0, 1) == '(') {
@ -1815,7 +1848,12 @@ class Smarty_Compiler extends Smarty {
} }
} }
return $_output; if ($_has_php4_method_chaining) {
$_tmp = str_replace("'","\'",'$_foo = '.$_output.'; return $_foo;');
return "eval('".$_tmp."')";
} else {
return $_output;
}
} }
/** /**
@ -2216,9 +2254,9 @@ class Smarty_Compiler extends Smarty {
if ($_cacheable if ($_cacheable
|| 0<$this->_cacheable_state++) return ''; || 0<$this->_cacheable_state++) return '';
if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty')); if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty'));
$_ret = 'if ($this->caching && !$this->_cache_including) { echo \'{nocache:' $_ret = 'if ($this->caching && !$this->_cache_including): echo \'{nocache:'
. $this->_cache_serial . '#' . $this->_nocache_count . $this->_cache_serial . '#' . $this->_nocache_count
. '}\'; };'; . '}\'; endif;';
return $_ret; return $_ret;
} }
@ -2233,9 +2271,9 @@ class Smarty_Compiler extends Smarty {
$_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4]; $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
if ($_cacheable if ($_cacheable
|| --$this->_cacheable_state>0) return ''; || --$this->_cacheable_state>0) return '';
return 'if ($this->caching && !$this->_cache_including) { echo \'{/nocache:' return 'if ($this->caching && !$this->_cache_including): echo \'{/nocache:'
. $this->_cache_serial . '#' . ($this->_nocache_count++) . $this->_cache_serial . '#' . ($this->_nocache_count++)
. '}\'; };'; . '}\'; endif;';
} }

View File

@ -1,64 +1,157 @@
{* Smarty *} {* Smarty *}
{* debug.tpl, last updated version 2.1.0 *}
{* debug.tpl, last updated version 2.0.1 *}
{assign_debug_info} {assign_debug_info}
{capture assign=debug_output}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Smarty Debug Console</title>
{literal}
<style type="text/css">
/* <![CDATA[ */
body, h1, h2, td, th, p {
font-family: sans-serif;
font-weight: normal;
font-size: 0.9em;
margin: 1px;
padding: 0;
}
h1 {
margin: 0;
text-align: left;
padding: 2px;
background-color: #f0c040;
color: black;
font-weight: bold;
font-size: 1.2em;
}
h2 {
background-color: #9B410E;
color: white;
text-align: left;
font-weight: bold;
padding: 2px;
border-top: 1px solid black;
}
body {
background: black;
}
p, table, div {
background: #f0ead8;
}
p {
margin: 0;
font-style: italic;
text-align: center;
}
table {
width: 100%;
}
th, td {
font-family: monospace;
vertical-align: top;
text-align: left;
width: 50%;
}
td {
color: green;
}
.odd {
background-color: #eeeeee;
}
.even {
background-color: #fafafa;
}
.exectime {
font-size: 0.8em;
font-style: italic;
}
#table_assigned_vars th {
color: blue;
}
#table_config_vars th {
color: maroon;
}
/* ]]> */
</style>
{/literal}
</head>
<body>
<h1>Smarty Debug Console</h1>
<h2>included templates &amp; config files (load time in seconds)</h2>
<div>
{section name=templates loop=$_debug_tpls}
{section name=indent loop=$_debug_tpls[templates].depth}&nbsp;&nbsp;&nbsp;{/section}
<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>
{$_debug_tpls[templates].filename|escape:html}</font>
{if isset($_debug_tpls[templates].exec_time)}
<span class="exectime">
({$_debug_tpls[templates].exec_time|string_format:"%.5f"})
{if %templates.index% eq 0}(total){/if}
</span>
{/if}
<br />
{sectionelse}
<p>no templates included</p>
{/section}
</div>
<h2>assigned template variables</h2>
<table id="table_assigned_vars">
{section name=vars loop=$_debug_keys}
<tr class="{cycle values="odd,even"}">
<th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th>
<td>{$_debug_vals[vars]|@debug_print_var}</td></tr>
{sectionelse}
<tr><td><p>no template variables assigned</p></td></tr>
{/section}
</table>
<h2>assigned config file variables (outer template scope)</h2>
<table id="table_config_vars">
{section name=config_vars loop=$_debug_config_keys}
<tr class="{cycle values="odd,even"}">
<th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th>
<td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr>
{sectionelse}
<tr><td><p>no config vars assigned</p></td></tr>
{/section}
</table>
</body>
</html>
{/capture}
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"} {if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
<table border=0 width=100%> {$debug_output}
<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>
<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>
{section name=templates loop=$_debug_tpls}
<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth}&nbsp;&nbsp;&nbsp;{/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>
{sectionelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>
{/section}
<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>
{section name=vars loop=$_debug_keys}
<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</font></tt></td></tr>
{sectionelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>
{/section}
<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>
{section name=config_vars loop=$_debug_config_keys}
<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var}</font></tt></td></tr>
{sectionelse}
<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>
{/section}
</table>
</BODY></HTML>
{else} {else}
<SCRIPT language=javascript> <script type="text/javascript">
if( self.name == '' ) {ldelim} // <![CDATA[
var title = 'Console'; if ( self.name == '' ) {ldelim}
{rdelim} var title = 'Console';
else {ldelim} {rdelim}
var title = 'Console_' + self.name; else {ldelim}
{rdelim} var title = 'Console_' + self.name;
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); {rdelim}
_smarty_console.document.write("<HTML><HEAD><TITLE>Smarty Debug Console_"+self.name+"</TITLE></HEAD><BODY bgcolor=#ffffff>"); _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("<table border=0 width=100%>"); _smarty_console.document.write('{$debug_output|escape:'javascript'}');
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>"); _smarty_console.document.close();
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>"); // ]]>
{section name=templates loop=$_debug_tpls} </script>
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth}&nbsp;&nbsp;&nbsp;{/section}<font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html|escape:javascript}</font>{if isset($_debug_tpls[templates].exec_time)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>");
{sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no templates included</i></tt></td></tr>");
{/section}
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>");
{section name=vars loop=$_debug_keys}
_smarty_console.document.write("<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
{sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>");
{/section}
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>");
{section name=config_vars loop=$_debug_config_keys}
_smarty_console.document.write("<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
{sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
{/section}
_smarty_console.document.write("</table>");
_smarty_console.document.write("</BODY></HTML>");
_smarty_console.document.close();
</SCRIPT>
{/if} {/if}

View File

@ -25,7 +25,7 @@ function smarty_core_process_compiled_include($params, &$smarty)
$smarty->_include($_include_file_path, true); $smarty->_include($_include_file_path, true);
} }
foreach ($smarty->_cache_serials as $_include_file_path=>$_cache_serial) { foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
$_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s', $_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s',
array(&$smarty, '_process_compiled_include_callback'), array(&$smarty, '_process_compiled_include_callback'),
$_return); $_return);

View File

@ -68,7 +68,7 @@ function smarty_core_write_cache_file($params, &$smarty)
if (!empty($smarty->cache_handler_func)) { if (!empty($smarty->cache_handler_func)) {
// use cache_handler function // use cache_handler function
call_user_func_array($smarty->cache_handler_func, call_user_func_array($smarty->cache_handler_func,
array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null)); array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], $smarty->_cache_info['expires']));
} else { } else {
// use local cache file // use local cache file

View File

@ -15,8 +15,8 @@
function smarty_core_write_compiled_include($params, &$smarty) function smarty_core_write_compiled_include($params, &$smarty)
{ {
$_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; \};'; $_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; endif;';
$_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\'; \};'; $_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\)\: echo \'\{/nocache\:(\\2)#(\\3)\}\'; endif;';
preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
$params['compiled_content'], $_match_source, PREG_SET_ORDER); $params['compiled_content'], $_match_source, PREG_SET_ORDER);

View File

@ -23,8 +23,7 @@ function smarty_core_write_file($params, &$smarty)
smarty_core_create_dir_structure($_params, $smarty); smarty_core_create_dir_structure($_params, $smarty);
} }
// write to tmp file, then rename it to avoid // write to tmp file, then rename it to avoid file locking race condition
// file locking race condition
$_tmp_file = tempnam($_dirname, 'wrt'); $_tmp_file = tempnam($_dirname, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) { if (!($fd = @fopen($_tmp_file, 'wb'))) {
@ -38,12 +37,13 @@ function smarty_core_write_file($params, &$smarty)
fwrite($fd, $params['contents']); fwrite($fd, $params['contents']);
fclose($fd); fclose($fd);
// Delete the file if it allready exists (this is needed on Win, if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
// because it cannot overwrite files with rename() // On platforms and filesystems that cannot overwrite with rename()
if (file_exists($params['filename'])) { // delete the file before renaming it -- because windows always suffers
// this, it is short-circuited to avoid the initial rename() attempt
@unlink($params['filename']); @unlink($params['filename']);
@rename($_tmp_file, $params['filename']);
} }
@rename($_tmp_file, $params['filename']);
@chmod($params['filename'], $smarty->_file_perms); @chmod($params['filename'], $smarty->_file_perms);
return true; return true;

View File

@ -14,7 +14,7 @@
* @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign} * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> (initial author) * @author Monte Ohrt <monte at ohrt dot com> (initial author)
* @auther messju mohr <messju at lammfellpuschen dot de> (conversion to compiler function) * @author messju mohr <messju at lammfellpuschen dot de> (conversion to compiler function)
* @param string containing var-attribute and value-attribute * @param string containing var-attribute and value-attribute
* @param Smarty_Compiler * @param Smarty_Compiler
*/ */

View File

@ -22,11 +22,13 @@
* month values (Gary Loescher) * month values (Gary Loescher)
* - 1.3.1 added support for choosing format for * - 1.3.1 added support for choosing format for
* day values (Marcus Bointon) * day values (Marcus Bointon)
* - 1.3.2 suppport negative timestamps, force year * - 1.3.2 support negative timestamps, force year
* dropdown to include given date unless explicitly set (Monte) * dropdown to include given date unless explicitly set (Monte)
* - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
* of 0000-00-00 dates (cybot, boots)
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date} * @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual) * (Smarty online manual)
* @version 1.3.2 * @version 1.3.4
* @author Andrei Zmievski * @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param array * @param array
@ -131,12 +133,14 @@ function smarty_function_html_select_date($params, &$smarty)
} }
} }
if(preg_match('!^-\d+$!',$time)) { if (preg_match('!^-\d+$!', $time)) {
// negative timestamp, use date() // negative timestamp, use date()
$time = date('Y-m-d',$time); $time = date('Y-m-d', $time);
} }
// If $time is not in format yyyy-mm-dd // If $time is not in format yyyy-mm-dd
if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) { if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) {
$time = $found[1];
} else {
// use smarty_make_timestamp to get an unix timestamp and // use smarty_make_timestamp to get an unix timestamp and
// strftime to make yyyy-mm-dd // strftime to make yyyy-mm-dd
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
@ -174,7 +178,9 @@ function smarty_function_html_select_date($params, &$smarty)
$html_result = $month_result = $day_result = $year_result = ""; $html_result = $month_result = $day_result = $year_result = "";
$field_separator_count = -1;
if ($display_months) { if ($display_months) {
$field_separator_count++;
$month_names = array(); $month_names = array();
$month_values = array(); $month_values = array();
if(isset($month_empty)) { if(isset($month_empty)) {
@ -212,6 +218,7 @@ function smarty_function_html_select_date($params, &$smarty)
} }
if ($display_days) { if ($display_days) {
$field_separator_count++;
$days = array(); $days = array();
if (isset($day_empty)) { if (isset($day_empty)) {
$days[''] = $day_empty; $days[''] = $day_empty;
@ -247,6 +254,7 @@ function smarty_function_html_select_date($params, &$smarty)
} }
if ($display_years) { if ($display_years) {
$field_separator_count++;
if (null !== $field_array){ if (null !== $field_array){
$year_name = $field_array . '[' . $prefix . 'Year]'; $year_name = $field_array . '[' . $prefix . 'Year]';
} else { } else {
@ -310,7 +318,7 @@ function smarty_function_html_select_date($params, &$smarty)
break; break;
} }
// Add the field seperator // Add the field seperator
if($i != 2) { if($i < $field_separator_count) {
$html_result .= $field_separator; $html_result .= $field_separator;
} }
} }

View File

@ -15,12 +15,15 @@
* Purpose: make an html table from an array of data<br> * Purpose: make an html table from an array of data<br>
* Input:<br> * Input:<br>
* - loop = array to loop through * - loop = array to loop through
* - cols = number of columns * - cols = number of columns, comma separated list of column names
* or array of column names
* - rows = number of rows * - rows = number of rows
* - table_attr = table attributes * - table_attr = table attributes
* - th_attr = table heading attributes (arrays are cycled)
* - tr_attr = table row attributes (arrays are cycled) * - tr_attr = table row attributes (arrays are cycled)
* - td_attr = table cell attributes (arrays are cycled) * - td_attr = table cell attributes (arrays are cycled)
* - trailpad = value to pad trailing cells with * - trailpad = value to pad trailing cells with
* - caption = text for caption element
* - vdir = vertical direction (default: "down", means top-to-bottom) * - vdir = vertical direction (default: "down", means top-to-bottom)
* - hdir = horizontal direction (default: "right", means left-to-right) * - hdir = horizontal direction (default: "right", means left-to-right)
* - inner = inner loop (default "cols": print $loop line by line, * - inner = inner loop (default "cols": print $loop line by line,
@ -31,10 +34,12 @@
* <pre> * <pre>
* {table loop=$data} * {table loop=$data}
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'} * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols=4 tr_attr=$colors} * {table loop=$data cols="first,second,third" tr_attr=$colors}
* </pre> * </pre>
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0 * @author credit to Messju Mohr <messju at lammfellpuschen dot de>
* @author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1
* @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table} * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual) * (Smarty online manual)
* @param array * @param array
@ -45,13 +50,15 @@ function smarty_function_html_table($params, &$smarty)
{ {
$table_attr = 'border="1"'; $table_attr = 'border="1"';
$tr_attr = ''; $tr_attr = '';
$th_attr = '';
$td_attr = ''; $td_attr = '';
$cols = 3; $cols = $cols_count = 3;
$rows = 3; $rows = 3;
$trailpad = '&nbsp;'; $trailpad = '&nbsp;';
$vdir = 'down'; $vdir = 'down';
$hdir = 'right'; $hdir = 'right';
$inner = 'cols'; $inner = 'cols';
$caption = '';
if (!isset($params['loop'])) { if (!isset($params['loop'])) {
$smarty->trigger_error("html_table: missing 'loop' parameter"); $smarty->trigger_error("html_table: missing 'loop' parameter");
@ -65,6 +72,19 @@ function smarty_function_html_table($params, &$smarty)
break; break;
case 'cols': case 'cols':
if (is_array($_value) && !empty($_value)) {
$cols = $_value;
$cols_count = count($_value);
} elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
$cols = explode(',', $_value);
$cols_count = count($cols);
} elseif (!empty($_value)) {
$cols_count = (int)$_value;
} else {
$cols_count = $cols;
}
break;
case 'rows': case 'rows':
$$_key = (int)$_value; $$_key = (int)$_value;
break; break;
@ -74,11 +94,13 @@ function smarty_function_html_table($params, &$smarty)
case 'hdir': case 'hdir':
case 'vdir': case 'vdir':
case 'inner': case 'inner':
case 'caption':
$$_key = (string)$_value; $$_key = (string)$_value;
break; break;
case 'tr_attr': case 'tr_attr':
case 'td_attr': case 'td_attr':
case 'th_attr':
$$_key = $_value; $$_key = $_value;
break; break;
} }
@ -87,25 +109,42 @@ function smarty_function_html_table($params, &$smarty)
$loop_count = count($loop); $loop_count = count($loop);
if (empty($params['rows'])) { if (empty($params['rows'])) {
/* no rows specified */ /* no rows specified */
$rows = ceil($loop_count/$cols); $rows = ceil($loop_count/$cols_count);
} elseif (empty($params['cols'])) { } elseif (empty($params['cols'])) {
if (!empty($params['rows'])) { if (!empty($params['rows'])) {
/* no cols specified, but rows */ /* no cols specified, but rows */
$cols = ceil($loop_count/$rows); $cols_count = ceil($loop_count/$rows);
} }
} }
$output = "<table $table_attr>\n"; $output = "<table $table_attr>\n";
if (!empty($caption)) {
$output .= '<caption>' . $caption . "</caption>\n";
}
if (is_array($cols)) {
$cols = ($hdir == 'right') ? $cols : array_reverse($cols);
$output .= "<thead><tr>\n";
for ($r=0; $r<$cols_count; $r++) {
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
$output .= $cols[$r];
$output .= "</th>\n";
}
$output .= "</tr></thead>\n";
}
$output .= "<tbody>\n";
for ($r=0; $r<$rows; $r++) { for ($r=0; $r<$rows; $r++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n"; $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols; $rx = ($vdir == 'down') ? $r*$cols_count : ($rows-1-$r)*$cols_count;
for ($c=0; $c<$cols; $c++) { for ($c=0; $c<$cols_count; $c++) {
$x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c; $x = ($hdir == 'right') ? $rx+$c : $rx+$cols_count-1-$c;
if ($inner!='cols') { if ($inner!='cols') {
/* shuffle x to loop over rows*/ /* shuffle x to loop over rows*/
$x = floor($x/$cols) + ($x%$cols)*$rows; $x = floor($x/$cols_count) + ($x%$cols_count)*$rows;
} }
if ($x<$loop_count) { if ($x<$loop_count) {
@ -116,6 +155,7 @@ function smarty_function_html_table($params, &$smarty)
} }
$output .= "</tr>\n"; $output .= "</tr>\n";
} }
$output .= "</tbody>\n";
$output .= "</table>\n"; $output .= "</table>\n";
return $output; return $output;

View File

@ -62,6 +62,8 @@ function smarty_function_mailto($params, &$smarty)
// netscape and mozilla do not decode %40 (@) in BCC field (bug?) // netscape and mozilla do not decode %40 (@) in BCC field (bug?)
// so, don't encode it. // so, don't encode it.
$search = array('%40', '%2C');
$replace = array('@', ',');
$mail_parms = array(); $mail_parms = array();
foreach ($params as $var=>$value) { foreach ($params as $var=>$value) {
switch ($var) { switch ($var) {
@ -69,7 +71,7 @@ function smarty_function_mailto($params, &$smarty)
case 'bcc': case 'bcc':
case 'followupto': case 'followupto':
if (!empty($value)) if (!empty($value))
$mail_parms[] = $var.'='.str_replace('%40','@',rawurlencode($value)); $mail_parms[] = $var.'='.str_replace($search,$replace,rawurlencode($value));
break; break;
case 'subject': case 'subject':

View File

@ -21,7 +21,7 @@
function smarty_modifier_capitalize($string, $uc_digits = false) function smarty_modifier_capitalize($string, $uc_digits = false)
{ {
smarty_modifier_capitalize_ucfirst(null, $uc_digits); smarty_modifier_capitalize_ucfirst(null, $uc_digits);
return preg_replace_callback('!\b\w+\b!', 'smarty_modifier_capitalize_ucfirst', $string); return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string);
} }
function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null) function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
@ -33,7 +33,7 @@ function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
return; return;
} }
if(!preg_match('!\d!',$string[0]) || $_uc_digits) if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits)
return ucfirst($string[0]); return ucfirst($string[0]);
else else
return $string[0]; return $string[0];

View File

@ -8,7 +8,7 @@
/** /**
* Include the {@link shared.make_timestamp.php} plugin * Include the {@link shared.make_timestamp.php} plugin
*/ */
require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); require_once $smarty->_get_plugin_filepath('shared', 'make_timestamp');
/** /**
* Smarty date_format modifier plugin * Smarty date_format modifier plugin
* *
@ -28,20 +28,29 @@ require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
* @return string|void * @return string|void
* @uses smarty_make_timestamp() * @uses smarty_make_timestamp()
*/ */
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null) function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
{ {
if (substr(PHP_OS,0,3) == 'WIN') { if ($string != '') {
$_win_from = array ('%e', '%T', '%D'); $timestamp = smarty_make_timestamp($string);
$_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y'); } elseif ($default_date != '') {
$format = str_replace($_win_from, $_win_to, $format); $timestamp = smarty_make_timestamp($default_date);
}
if($string != '') {
return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date));
} else { } else {
return; return;
} }
if (DIRECTORY_SEPARATOR == '\\') {
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if (strpos($format, '%e') !== false) {
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
}
if (strpos($format, '%l') !== false) {
$_win_from[] = '%l';
$_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
}
$format = str_replace($_win_from, $_win_to, $format);
}
return strftime($format, $timestamp);
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@ -22,33 +22,66 @@
*/ */
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{ {
$_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>'); $_replace = array(
if (is_array($var)) { "\n" => '<i>\n</i>',
$results = "<b>Array (".count($var).")</b>"; "\r" => '<i>\r</i>',
foreach ($var as $curr_key => $curr_val) { "\t" => '<i>\t</i>'
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); );
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
} switch (gettype($var)) {
} else if (is_object($var)) { case 'array' :
$object_vars = get_object_vars($var); $results = '<b>Array (' . count($var) . ')</b>';
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>"; foreach ($var as $curr_key => $curr_val) {
foreach ($object_vars as $curr_key => $curr_val) { $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return"; . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
} $depth--;
} else if (is_resource($var)) { }
$results = '<i>'.(string)$var.'</i>'; break;
} else if (empty($var) && $var != "0") { case 'object' :
$results = '<i>empty</i>'; $object_vars = get_object_vars($var);
} else { $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
if (strlen($var) > $length ) { foreach ($object_vars as $curr_key => $curr_val) {
$results = substr($var, 0, $length-3).'...'; $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
} else { . '<b> -&gt;' . strtr($curr_key, $_replace) . '</b> = '
$results = $var; . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
} $depth--;
$results = htmlspecialchars($results); }
$results = strtr($results, $_replace); break;
case 'boolean' :
case 'NULL' :
case 'resource' :
if (true === $var) {
$results = 'true';
} elseif (false === $var) {
$results = 'false';
} elseif (null === $var) {
$results = 'null';
} else {
$results = htmlspecialchars((string) $var);
}
$results = '<i>' . $results . '</i>';
break;
case 'integer' :
case 'float' :
$results = htmlspecialchars((string) $var);
break;
case 'string' :
$results = strtr($var, $_replace);
if (strlen($var) > $length ) {
$results = substr($var, 0, $length - 3) . '...';
}
$results = htmlspecialchars('"' . $results . '"');
break;
case 'unknown type' :
default :
$results = strtr((string) $var, $_replace);
if (strlen($results) > $length ) {
$results = substr($results, 0, $length - 3) . '...';
}
$results = htmlspecialchars($results);
} }
return $results; return $results;
} }

View File

@ -11,7 +11,7 @@
* *
* Type: modifier<br> * Type: modifier<br>
* Name: regex_replace<br> * Name: regex_replace<br>
* Purpose: regular epxression search/replace * Purpose: regular expression search/replace
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual) * regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
@ -22,13 +22,27 @@
*/ */
function smarty_modifier_regex_replace($string, $search, $replace) function smarty_modifier_regex_replace($string, $search, $replace)
{ {
if (preg_match('!\W(\w+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { if(is_array($search)) {
/* remove eval-modifier from $search */ foreach($search as $idx => $s)
$search = substr($search, 0, -strlen($match[1])) . str_replace('e', '', $match[1]); $search[$idx] = _smarty_regex_replace_check($s);
} else {
$search = _smarty_regex_replace_check($search);
} }
return preg_replace($search, $replace, $string); return preg_replace($search, $replace, $string);
} }
function _smarty_regex_replace_check($search)
{
if (($pos = strpos($search,"\0")) !== false)
$search = substr($search,0,$pos);
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
/* remove eval-modifier from $search */
$search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
}
return $search;
}
/* vim: set expandtab: */ /* vim: set expandtab: */
?> ?>

View File

@ -31,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...',
return ''; return '';
if (strlen($string) > $length) { if (strlen($string) > $length) {
$length -= strlen($etc); $length -= min($length, strlen($etc));
if (!$break_words && !$middle) { if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
} }
if(!$middle) { if(!$middle) {
return substr($string, 0, $length).$etc; return substr($string, 0, $length) . $etc;
} else { } else {
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2); return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
} }

View File

@ -28,35 +28,35 @@
function smarty_outputfilter_trimwhitespace($source, &$smarty) function smarty_outputfilter_trimwhitespace($source, &$smarty)
{ {
// Pull out the script blocks // Pull out the script blocks
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match); preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
$_script_blocks = $match[0]; $_script_blocks = $match[0];
$source = preg_replace("!<script[^>]+>.*?</script>!is", $source = preg_replace("!<script[^>]*?>.*?</script>!is",
'@@@SMARTY:TRIM:SCRIPT@@@', $source); '@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks // Pull out the pre blocks
preg_match_all("!<pre>.*?</pre>!is", $source, $match); preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0]; $_pre_blocks = $match[0];
$source = preg_replace("!<pre>.*?</pre>!is", $source = preg_replace("!<pre[^>]*?>.*?</pre>!is",
'@@@SMARTY:TRIM:PRE@@@', $source); '@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks // Pull out the textarea blocks
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match); preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0]; $_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is",
'@@@SMARTY:TRIM:TEXTAREA@@@', $source); '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT // remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag. // preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
// replace script blocks // replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
// replace pre blocks // replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
// replace textarea blocks // replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
return $source; return $source;
} }