From: Andreas Gohr Date: Wed, 13 Jun 2007 14:39:06 +0000 (+0200) Subject: Smarty Update to 2.6.18 X-Git-Tag: 0.7.1~68 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fdc0d8d266386b90091ff6ad423244f746edb424;p=contagged Smarty Update to 2.6.18 darcs-hash:20070613143906-6e07b-b854f23a72e15f289e5bc6ecf8e52cd476fae1dc.gz --- diff --git a/smarty/Config_File.class.php b/smarty/Config_File.class.php index 622c0e8..3d7c1b4 100644 --- a/smarty/Config_File.class.php +++ b/smarty/Config_File.class.php @@ -18,14 +18,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://smarty.php.net/ - * @version 2.6.14 + * @version 2.6.18 * @copyright Copyright: 2001-2005 New Digital Group, Inc. * @author Andrei Zmievski * @access public * @package Smarty */ -/* $Id: Config_File.class.php,v 1.84 2006/01/18 19:02:52 mohrt Exp $ */ +/* $Id: Config_File.class.php,v 1.88 2007/03/06 10:40:06 messju Exp $ */ /** * Config file reading class diff --git a/smarty/Smarty.class.php b/smarty/Smarty.class.php index 47ec24e..f05e0da 100644 --- a/smarty/Smarty.class.php +++ b/smarty/Smarty.class.php @@ -27,10 +27,10 @@ * @author Monte Ohrt * @author Andrei Zmievski * @package Smarty - * @version 2.6.14 + * @version 2.6.18 */ -/* $Id: Smarty.class.php,v 1.524 2006/01/18 19:02:52 mohrt Exp $ */ +/* $Id: Smarty.class.php,v 1.528 2007/03/06 10:40:06 messju Exp $ */ /** * DIR_SEP isn't used anymore, but third party apps might @@ -464,7 +464,7 @@ class Smarty * * @var string */ - var $_version = '2.6.14'; + var $_version = '2.6.18'; /** * current template inclusion depth diff --git a/smarty/Smarty_Compiler.class.php b/smarty/Smarty_Compiler.class.php index cbcbddb..f54cc21 100644 --- a/smarty/Smarty_Compiler.class.php +++ b/smarty/Smarty_Compiler.class.php @@ -21,12 +21,12 @@ * @link http://smarty.php.net/ * @author Monte Ohrt * @author Andrei Zmievski - * @version 2.6.14 + * @version 2.6.18 * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.381 2006/05/25 14:46:18 boots Exp $ */ +/* $Id: Smarty_Compiler.class.php,v 1.395 2007/03/06 10:40:06 messju Exp $ */ /** * Template compiling class @@ -240,9 +240,6 @@ class Smarty_Compiler extends Smarty { $ldq = preg_quote($this->left_delimiter, '~'); $rdq = preg_quote($this->right_delimiter, '~'); - /* un-hide hidden xml open tags */ - $source_content = preg_replace("~<({$ldq}(.*?){$rdq})[?]~s", '< \\1', $source_content); - // run template source through prefilter functions if (count($this->_plugins['prefilter']) > 0) { foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { @@ -281,7 +278,7 @@ class Smarty_Compiler extends Smarty { /* loop through text blocks */ for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { /* 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 */ $sp_match[1] = array_unique($sp_match[1]); usort($sp_match[1], '_smarty_sort_length'); @@ -307,7 +304,7 @@ class Smarty_Compiler extends Smarty { } } } - + /* Compile the template tags into PHP code. */ $compiled_tags = array(); for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { @@ -352,17 +349,30 @@ class Smarty_Compiler extends Smarty { } } $compiled_content = ''; - + + $tag_guard = '%%%SMARTYOTG' . md5(uniqid(rand(), true)) . '%%%'; + /* Interleave the compiled contents and text blocks to get the final result. */ for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { if ($compiled_tags[$i] == '') { // tag result empty, remove first newline from following text block $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('\n", $compiled_content); + $compiled_content = preg_replace("~(?\n", $compiled_content); + // recover legit tags + $compiled_content = str_replace($tag_guard, '_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 if (count($this->_plugins['postfilter']) > 0) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { @@ -927,7 +934,11 @@ class Smarty_Compiler extends Smarty { $name = $this->_dequote($attrs['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'])) { @@ -1160,7 +1171,7 @@ class Smarty_Compiler extends Smarty { } $item = $this->_dequote($attrs['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'])) { @@ -1671,11 +1682,11 @@ class Smarty_Compiler extends Smarty { // if contains unescaped $, expand it if(preg_match_all('~(?:\`(?_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?_parse_var(str_replace('`','',$_var)) . ')."', $var_expr); + $_replace[$_var] = '".(' . $this->_parse_var(str_replace('`','',$_var)) . ')."'; } + $var_expr = strtr($var_expr, $_replace); $_return = preg_replace('~\.""|(?_cacheable_state++) return ''; 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 - . '}\'; };'; + . '}\'; endif;'; return $_ret; } @@ -2236,9 +2247,9 @@ class Smarty_Compiler extends Smarty { $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4]; if ($_cacheable || --$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++) - . '}\'; };'; + . '}\'; endif;'; } diff --git a/smarty/debug.tpl b/smarty/debug.tpl index 7f1c9d4..c05ef5d 100644 --- a/smarty/debug.tpl +++ b/smarty/debug.tpl @@ -1,64 +1,157 @@ {* Smarty *} +{* debug.tpl, last updated version 2.1.0 *} +{assign_debug_info} +{capture assign=debug_output} + + + + Smarty Debug Console +{literal} + +{/literal} + + + +

Smarty Debug Console

+ +

included templates & config files (load time in seconds)

+ +
+{section name=templates loop=$_debug_tpls} + {section name=indent loop=$_debug_tpls[templates].depth}   {/section} + + {$_debug_tpls[templates].filename|escape:html} + {if isset($_debug_tpls[templates].exec_time)} + + ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}) + {if %templates.index% eq 0}(total){/if} + + {/if} +
+{sectionelse} +

no templates included

+{/section} +
+ +

assigned template variables

+ + + {section name=vars loop=$_debug_keys} + + + + {sectionelse} + + {/section} +
{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}{$_debug_vals[vars]|@debug_print_var}

no template variables assigned

+ +

assigned config file variables (outer template scope)

+ + {section name=config_vars loop=$_debug_config_keys} + + + + {sectionelse} + + {/section} +
{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}{$_debug_config_vals[config_vars]|@debug_print_var}

no config vars assigned

+ + +{/capture} {if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"} - - - - {section name=templates loop=$_debug_tpls} - - {sectionelse} - - {/section} - - {section name=vars loop=$_debug_keys} - - {sectionelse} - - {/section} - - {section name=config_vars loop=$_debug_config_keys} - - {sectionelse} - - {/section} -
Smarty Debug Console
included templates & config files (load time in seconds):
{section name=indent loop=$_debug_tpls[templates].depth}   {/section}{$_debug_tpls[templates].filename|escape:html}{if isset($_debug_tpls[templates].exec_time)} ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}{/if}
no templates included
assigned template variables:
{ldelim}${$_debug_keys[vars]}{rdelim}{$_debug_vals[vars]|@debug_print_var}
no template variables assigned
assigned config file variables (outer template scope):
{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}{$_debug_config_vals[config_vars]|@debug_print_var}
no config vars assigned
- + {$debug_output} {else} - -{/if} + +{/if} \ No newline at end of file diff --git a/smarty/internals/core.write_compiled_include.php b/smarty/internals/core.write_compiled_include.php index 3a78094..c14adb5 100644 --- a/smarty/internals/core.write_compiled_include.php +++ b/smarty/internals/core.write_compiled_include.php @@ -15,12 +15,12 @@ function smarty_core_write_compiled_include($params, &$smarty) { - $_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; \};'; - $_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\'; \};'; + $_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)\}\'; endif;'; preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', $params['compiled_content'], $_match_source, PREG_SET_ORDER); - + // no nocache-parts found: done if (count($_match_source)==0) return; diff --git a/smarty/internals/core.write_file.php b/smarty/internals/core.write_file.php index 09e1698..8a3a3b3 100644 --- a/smarty/internals/core.write_file.php +++ b/smarty/internals/core.write_file.php @@ -23,8 +23,7 @@ function smarty_core_write_file($params, &$smarty) smarty_core_create_dir_structure($_params, $smarty); } - // write to tmp file, then rename it to avoid - // file locking race condition + // write to tmp file, then rename it to avoid file locking race condition $_tmp_file = tempnam($_dirname, 'wrt'); if (!($fd = @fopen($_tmp_file, 'wb'))) { @@ -38,12 +37,13 @@ function smarty_core_write_file($params, &$smarty) fwrite($fd, $params['contents']); fclose($fd); - // Delete the file if it allready exists (this is needed on Win, - // because it cannot overwrite files with rename() - if (file_exists($params['filename'])) { + if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) { + // On platforms and filesystems that cannot overwrite with rename() + // delete the file before renaming it -- because windows always suffers + // this, it is short-circuited to avoid the initial rename() attempt @unlink($params['filename']); + @rename($_tmp_file, $params['filename']); } - @rename($_tmp_file, $params['filename']); @chmod($params['filename'], $smarty->_file_perms); return true; @@ -51,4 +51,4 @@ function smarty_core_write_file($params, &$smarty) /* vim: set expandtab: */ -?> +?> \ No newline at end of file diff --git a/smarty/plugins/function.html_select_date.php b/smarty/plugins/function.html_select_date.php index 6153c59..e5eb183 100644 --- a/smarty/plugins/function.html_select_date.php +++ b/smarty/plugins/function.html_select_date.php @@ -24,9 +24,11 @@ * day values (Marcus Bointon) * - 1.3.2 support negative timestamps, force year * 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} * (Smarty online manual) - * @version 1.3.2 + * @version 1.3.4 * @author Andrei Zmievski * @author Monte Ohrt * @param array @@ -131,19 +133,21 @@ function smarty_function_html_select_date($params, &$smarty) } } - if(preg_match('!^-\d+$!',$time)) { + if (preg_match('!^-\d+$!', $time)) { // 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 (!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 // strftime to make yyyy-mm-dd $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); } // Now split this in pieces, which later can be used to set the select $time = explode("-", $time); - + // make syntax "+N" or "-N" work with start_year and end_year if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { if ($match[1] == '+') { @@ -159,7 +163,7 @@ function smarty_function_html_select_date($params, &$smarty) $start_year = strftime('%Y') - $match[2]; } } - if (strlen($time[0]) > 0) { + if (strlen($time[0]) > 0) { if ($start_year > $time[0] && !isset($params['start_year'])) { // force start year to include given date if not explicitly set $start_year = $time[0]; @@ -174,7 +178,9 @@ function smarty_function_html_select_date($params, &$smarty) $html_result = $month_result = $day_result = $year_result = ""; + $field_separator_count = -1; if ($display_months) { + $field_separator_count++; $month_names = array(); $month_values = array(); if(isset($month_empty)) { @@ -212,6 +218,7 @@ function smarty_function_html_select_date($params, &$smarty) } if ($display_days) { + $field_separator_count++; $days = array(); if (isset($day_empty)) { $days[''] = $day_empty; @@ -247,6 +254,7 @@ function smarty_function_html_select_date($params, &$smarty) } if ($display_years) { + $field_separator_count++; if (null !== $field_array){ $year_name = $field_array . '[' . $prefix . 'Year]'; } else { @@ -310,7 +318,7 @@ function smarty_function_html_select_date($params, &$smarty) break; } // Add the field seperator - if($i != 2) { + if($i < $field_separator_count) { $html_result .= $field_separator; } } diff --git a/smarty/plugins/function.html_table.php b/smarty/plugins/function.html_table.php index 62d7410..32aeba8 100644 --- a/smarty/plugins/function.html_table.php +++ b/smarty/plugins/function.html_table.php @@ -15,12 +15,15 @@ * Purpose: make an html table from an array of data
* Input:
* - 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 * - table_attr = table attributes + * - th_attr = table heading attributes (arrays are cycled) * - tr_attr = table row attributes (arrays are cycled) * - td_attr = table cell attributes (arrays are cycled) * - trailpad = value to pad trailing cells with + * - caption = text for caption element * - vdir = vertical direction (default: "down", means top-to-bottom) * - hdir = horizontal direction (default: "right", means left-to-right) * - inner = inner loop (default "cols": print $loop line by line, @@ -31,10 +34,12 @@ *
  * {table loop=$data}
  * {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}
  * 
* @author Monte Ohrt - * @version 1.0 + * @author credit to Messju Mohr + * @author credit to boots + * @version 1.1 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table} * (Smarty online manual) * @param array @@ -45,13 +50,15 @@ function smarty_function_html_table($params, &$smarty) { $table_attr = 'border="1"'; $tr_attr = ''; + $th_attr = ''; $td_attr = ''; - $cols = 3; + $cols = $cols_count = 3; $rows = 3; $trailpad = ' '; $vdir = 'down'; $hdir = 'right'; $inner = 'cols'; + $caption = ''; if (!isset($params['loop'])) { $smarty->trigger_error("html_table: missing 'loop' parameter"); @@ -65,6 +72,19 @@ function smarty_function_html_table($params, &$smarty) break; 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': $$_key = (int)$_value; break; @@ -74,11 +94,13 @@ function smarty_function_html_table($params, &$smarty) case 'hdir': case 'vdir': case 'inner': + case 'caption': $$_key = (string)$_value; break; case 'tr_attr': case 'td_attr': + case 'th_attr': $$_key = $_value; break; } @@ -87,25 +109,42 @@ function smarty_function_html_table($params, &$smarty) $loop_count = count($loop); if (empty($params['rows'])) { /* no rows specified */ - $rows = ceil($loop_count/$cols); + $rows = ceil($loop_count/$cols_count); } elseif (empty($params['cols'])) { if (!empty($params['rows'])) { /* no cols specified, but rows */ - $cols = ceil($loop_count/$rows); + $cols_count = ceil($loop_count/$rows); } } $output = "\n"; + if (!empty($caption)) { + $output .= '\n"; + } + + if (is_array($cols)) { + $cols = ($hdir == 'right') ? $cols : array_reverse($cols); + $output .= "\n"; + + for ($r=0; $r<$cols_count; $r++) { + $output .= ''; + $output .= $cols[$r]; + $output .= "\n"; + } + $output .= "\n"; + } + + $output .= "\n"; for ($r=0; $r<$rows; $r++) { $output .= "\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++) { - $x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c; + for ($c=0; $c<$cols_count; $c++) { + $x = ($hdir == 'right') ? $rx+$c : $rx+$cols_count-1-$c; if ($inner!='cols') { /* 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) { @@ -116,6 +155,7 @@ function smarty_function_html_table($params, &$smarty) } $output .= "\n"; } + $output .= "\n"; $output .= "
' . $caption . "
\n"; return $output; diff --git a/smarty/plugins/function.mailto.php b/smarty/plugins/function.mailto.php index 64c122c..20e9ed9 100644 --- a/smarty/plugins/function.mailto.php +++ b/smarty/plugins/function.mailto.php @@ -62,6 +62,8 @@ function smarty_function_mailto($params, &$smarty) // netscape and mozilla do not decode %40 (@) in BCC field (bug?) // so, don't encode it. + $search = array('%40', '%2C'); + $replace = array('@', ','); $mail_parms = array(); foreach ($params as $var=>$value) { switch ($var) { @@ -69,7 +71,7 @@ function smarty_function_mailto($params, &$smarty) case 'bcc': case 'followupto': if (!empty($value)) - $mail_parms[] = $var.'='.str_replace('%40','@',rawurlencode($value)); + $mail_parms[] = $var.'='.str_replace($search,$replace,rawurlencode($value)); break; case 'subject': diff --git a/smarty/plugins/modifier.capitalize.php b/smarty/plugins/modifier.capitalize.php index bca951a..4a611d9 100644 --- a/smarty/plugins/modifier.capitalize.php +++ b/smarty/plugins/modifier.capitalize.php @@ -21,7 +21,7 @@ function smarty_modifier_capitalize($string, $uc_digits = false) { 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) @@ -33,7 +33,7 @@ function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null) 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]); else return $string[0]; diff --git a/smarty/plugins/modifier.date_format.php b/smarty/plugins/modifier.date_format.php index 523c144..8cf7d5e 100644 --- a/smarty/plugins/modifier.date_format.php +++ b/smarty/plugins/modifier.date_format.php @@ -8,7 +8,7 @@ /** * 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 * @@ -28,20 +28,29 @@ require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); * @return string|void * @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') { - $_win_from = array ('%e', '%T', '%D'); - $_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y'); - $format = str_replace($_win_from, $_win_to, $format); - } - if($string != '') { - return strftime($format, smarty_make_timestamp($string)); - } elseif (isset($default_date) && $default_date != '') { - return strftime($format, smarty_make_timestamp($default_date)); + if ($string != '') { + $timestamp = smarty_make_timestamp($string); + } elseif ($default_date != '') { + $timestamp = smarty_make_timestamp($default_date); } else { 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: */ diff --git a/smarty/plugins/modifier.debug_print_var.php b/smarty/plugins/modifier.debug_print_var.php index d28956a..e4f7bc0 100644 --- a/smarty/plugins/modifier.debug_print_var.php +++ b/smarty/plugins/modifier.debug_print_var.php @@ -22,33 +22,66 @@ */ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) { - $_replace = array("\n"=>'\n', "\r"=>'\r', "\t"=>'\t'); - if (is_array($var)) { - $results = "Array (".count($var).")"; - foreach ($var as $curr_key => $curr_val) { - $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); - $results .= "
".str_repeat(' ', $depth*2)."".strtr($curr_key, $_replace)." => $return"; - } - } else if (is_object($var)) { - $object_vars = get_object_vars($var); - $results = "".get_class($var)." Object (".count($object_vars).")"; - foreach ($object_vars as $curr_key => $curr_val) { - $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); - $results .= "
".str_repeat(' ', $depth*2)."$curr_key => $return"; - } - } else if (is_resource($var)) { - $results = ''.(string)$var.''; - } else if (empty($var) && $var != "0") { - $results = 'empty'; - } else { - if (strlen($var) > $length ) { - $results = substr($var, 0, $length-3).'...'; - } else { - $results = $var; - } - $results = htmlspecialchars($results); - $results = strtr($results, $_replace); + $_replace = array( + "\n" => '\n', + "\r" => '\r', + "\t" => '\t' + ); + + switch (gettype($var)) { + case 'array' : + $results = 'Array (' . count($var) . ')'; + foreach ($var as $curr_key => $curr_val) { + $results .= '
' . str_repeat(' ', $depth * 2) + . '' . strtr($curr_key, $_replace) . ' => ' + . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); + $depth--; + } + break; + case 'object' : + $object_vars = get_object_vars($var); + $results = '' . get_class($var) . ' Object (' . count($object_vars) . ')'; + foreach ($object_vars as $curr_key => $curr_val) { + $results .= '
' . str_repeat(' ', $depth * 2) + . ' ->' . strtr($curr_key, $_replace) . ' = ' + . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); + $depth--; + } + 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 = '' . $results . ''; + 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; } diff --git a/smarty/plugins/modifier.truncate.php b/smarty/plugins/modifier.truncate.php index d96de5f..35c8969 100644 --- a/smarty/plugins/modifier.truncate.php +++ b/smarty/plugins/modifier.truncate.php @@ -31,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', return ''; if (strlen($string) > $length) { - $length -= strlen($etc); + $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); } if(!$middle) { - return substr($string, 0, $length).$etc; + return substr($string, 0, $length) . $etc; } else { return substr($string, 0, $length/2) . $etc . substr($string, -$length/2); } diff --git a/smarty/plugins/outputfilter.trimwhitespace.php b/smarty/plugins/outputfilter.trimwhitespace.php index 01e35e0..97b0d21 100644 --- a/smarty/plugins/outputfilter.trimwhitespace.php +++ b/smarty/plugins/outputfilter.trimwhitespace.php @@ -49,14 +49,14 @@ function smarty_outputfilter_trimwhitespace($source, &$smarty) // preceeded by a php close tag. $source = trim(preg_replace('/((?)\n)[\s]+/m', '\1', $source)); - // replace script blocks - smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); + // replace textarea blocks + smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); // replace pre blocks smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source); - // replace textarea blocks - smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); + // replace script blocks + smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); return $source; }