From c209d24f0b4a4a0ad374bf8c4588aaa76cea613d Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 3 Mar 2008 16:32:04 +0000 Subject: [PATCH] Updated smarty git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@9260 594d385d-05f5-0310-b6e9-bd551577e9d8 --- Changelog | 1 + include/smarty/Config_File.class.php | 4 +- include/smarty/Smarty.class.php | 52 ++++++++++----- include/smarty/Smarty_Compiler.class.php | 65 ++++++++++--------- .../internals/core.write_compiled_include.php | 6 +- include/smarty/internals/core.write_file.php | 2 +- include/smarty/plugins/compiler.assign.php | 2 +- .../plugins/function.html_select_date.php | 6 +- .../smarty/plugins/modifier.date_format.php | 33 ++++++---- .../smarty/plugins/modifier.regex_replace.php | 2 + include/smarty/plugins/modifier.truncate.php | 4 +- 11 files changed, 106 insertions(+), 71 deletions(-) diff --git a/Changelog b/Changelog index 1b7f95afb..4ba763a09 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,7 @@ GOsa2 changelog * gosa 2.5.16 - ridbase may be undefined in domain objects - Fixed postremove/-create/-modify parameter expansion + - Updated built in smarty to 2.6.19 * gosa 2.5.15 - Changed order of sys-action commandline parameters diff --git a/include/smarty/Config_File.class.php b/include/smarty/Config_File.class.php index da3b7328b..e3c3ca25c 100644 --- a/include/smarty/Config_File.class.php +++ b/include/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.16 + * @version 2.6.19 * @copyright Copyright: 2001-2005 New Digital Group, Inc. * @author Andrei Zmievski * @access public * @package Smarty */ -/* $Id: Config_File.class.php,v 1.86 2006/11/30 17:01:28 mohrt Exp $ */ +/* $Id: Config_File.class.php 2702 2007-03-08 19:11:22Z mohrt $ */ /** * Config file reading class diff --git a/include/smarty/Smarty.class.php b/include/smarty/Smarty.class.php index e11a6dc7c..5eda787bd 100644 --- a/include/smarty/Smarty.class.php +++ b/include/smarty/Smarty.class.php @@ -27,10 +27,10 @@ * @author Monte Ohrt * @author Andrei Zmievski * @package Smarty - * @version 2.6.16 + * @version 2.6.19 */ -/* $Id: Smarty.class.php,v 1.526 2006/11/30 17:01:28 mohrt Exp $ */ +/* $Id: Smarty.class.php 2722 2007-06-18 14:29:00Z danilo $ */ /** * DIR_SEP isn't used anymore, but third party apps might @@ -464,7 +464,7 @@ class Smarty * * @var string */ - var $_version = '2.6.16'; + var $_version = '2.6.19'; /** * current template inclusion depth @@ -838,69 +838,66 @@ class Smarty * Registers a prefilter function to apply * to a template before compiling * - * @param string $function name of PHP function to register + * @param callback $function */ function register_prefilter($function) { - $_name = (is_array($function)) ? $function[1] : $function; - $this->_plugins['prefilter'][$_name] + $this->_plugins['prefilter'][$this->_get_filter_name($function)] = array($function, null, null, false); } /** * Unregisters a prefilter function * - * @param string $function name of PHP function + * @param callback $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 * to a compiled template after compilation * - * @param string $function name of PHP function to register + * @param callback $function */ function register_postfilter($function) { - $_name = (is_array($function)) ? $function[1] : $function; - $this->_plugins['postfilter'][$_name] + $this->_plugins['postfilter'][$this->_get_filter_name($function)] = array($function, null, null, false); } /** * Unregisters a postfilter function * - * @param string $function name of PHP function + * @param callback $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 * to a template output * - * @param string $function name of PHP function + * @param callback $function */ function register_outputfilter($function) { - $_name = (is_array($function)) ? $function[1] : $function; - $this->_plugins['outputfilter'][$_name] + $this->_plugins['outputfilter'][$this->_get_filter_name($function)] = array($function, null, null, false); } /** * Unregisters an outputfilter function * - * @param string $function name of PHP function + * @param callback $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); } + + /** + * 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; + } + } + /**#@-*/ } diff --git a/include/smarty/Smarty_Compiler.class.php b/include/smarty/Smarty_Compiler.class.php index 2b13a6d41..52466d318 100644 --- a/include/smarty/Smarty_Compiler.class.php +++ b/include/smarty/Smarty_Compiler.class.php @@ -21,12 +21,12 @@ * @link http://smarty.php.net/ * @author Monte Ohrt * @author Andrei Zmievski - * @version 2.6.16 + * @version 2.6.19 * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.386 2006/11/30 17:01:28 mohrt Exp $ */ +/* $Id: Smarty_Compiler.class.php 2736 2007-09-16 14:47:53Z mohrt $ */ /** * 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) { @@ -862,7 +869,7 @@ class Smarty_Compiler extends Smarty { // traditional argument format $args = implode(',', array_values($attrs)); if (empty($args)) { - $args = 'null'; + $args = ''; } } @@ -1164,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'])) { @@ -1215,23 +1222,21 @@ class Smarty_Compiler extends Smarty { $attrs = $this->_parse_attrs($tag_args); if ($start) { - if (isset($attrs['name'])) - $buffer = $attrs['name']; - else - $buffer = "'default'"; - - if (isset($attrs['assign'])) - $assign = $attrs['assign']; - else - $assign = null; + $buffer = isset($attrs['name']) ? $attrs['name'] : "'default'"; + $assign = isset($attrs['assign']) ? $attrs['assign'] : null; + $append = isset($attrs['append']) ? $attrs['append'] : null; + $output = ""; - $this->_capture_stack[] = array($buffer, $assign); + $this->_capture_stack[] = array($buffer, $assign, $append); } else { - list($buffer, $assign) = array_pop($this->_capture_stack); + list($buffer, $assign, $append) = array_pop($this->_capture_stack); $output = "_smarty_vars['capture'][$buffer] = ob_get_contents(); "; if (isset($assign)) { $output .= " \$this->assign($assign, ob_get_contents());"; } + if (isset($append)) { + $output .= " \$this->append($append, ob_get_contents());"; + } $output .= "ob_end_clean(); ?>"; } @@ -2223,9 +2228,9 @@ class Smarty_Compiler extends Smarty { if ($_cacheable || 0<$this->_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; } @@ -2240,9 +2245,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/include/smarty/internals/core.write_compiled_include.php b/include/smarty/internals/core.write_compiled_include.php index 3a7809417..c14adb5f4 100644 --- a/include/smarty/internals/core.write_compiled_include.php +++ b/include/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/include/smarty/internals/core.write_file.php b/include/smarty/internals/core.write_file.php index 48a3b1a7d..8a3a3b398 100644 --- a/include/smarty/internals/core.write_file.php +++ b/include/smarty/internals/core.write_file.php @@ -37,7 +37,7 @@ function smarty_core_write_file($params, &$smarty) fwrite($fd, $params['contents']); fclose($fd); - if (PHP_OS == 'Windows' || !@rename($_tmp_file, $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 diff --git a/include/smarty/plugins/compiler.assign.php b/include/smarty/plugins/compiler.assign.php index be1729850..abef377f8 100644 --- a/include/smarty/plugins/compiler.assign.php +++ b/include/smarty/plugins/compiler.assign.php @@ -14,7 +14,7 @@ * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign} * (Smarty online manual) * @author Monte Ohrt (initial author) - * @auther messju mohr (conversion to compiler function) + * @author messju mohr (conversion to compiler function) * @param string containing var-attribute and value-attribute * @param Smarty_Compiler */ diff --git a/include/smarty/plugins/function.html_select_date.php b/include/smarty/plugins/function.html_select_date.php index ff920e435..e5eb18307 100644 --- a/include/smarty/plugins/function.html_select_date.php +++ b/include/smarty/plugins/function.html_select_date.php @@ -178,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)) { @@ -216,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; @@ -251,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 { @@ -314,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/include/smarty/plugins/modifier.date_format.php b/include/smarty/plugins/modifier.date_format.php index 8266e9d71..8cf7d5e14 100644 --- a/include/smarty/plugins/modifier.date_format.php +++ b/include/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,22 +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') { - $hours = strftime('%I', $string); - $short_hours = ( $hours < 10 ) ? substr( $hours, -1) : $hours; - $_win_from = array ('%e', '%T', '%D', '%l'); - $_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y', $short_hours); - $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/include/smarty/plugins/modifier.regex_replace.php b/include/smarty/plugins/modifier.regex_replace.php index d4d20309d..d1f1545d8 100644 --- a/include/smarty/plugins/modifier.regex_replace.php +++ b/include/smarty/plugins/modifier.regex_replace.php @@ -22,6 +22,8 @@ */ function smarty_modifier_regex_replace($string, $search, $replace) { + 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]); diff --git a/include/smarty/plugins/modifier.truncate.php b/include/smarty/plugins/modifier.truncate.php index d96de5f12..35c89690a 100644 --- a/include/smarty/plugins/modifier.truncate.php +++ b/include/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); } -- 2.30.2