From 58f3cc81303e57d58fd339ccd68870d525fb222a Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 17 Nov 2009 09:01:56 +0000 Subject: [PATCH] MDL-20638 importing latest smarty 2.6.26 --- lib/smarty/Config_File.class.php | 16 +- lib/smarty/Smarty.class.php | 87 +++++--- lib/smarty/Smarty_Compiler.class.php | 195 ++++++++++------ lib/smarty/core/core.is_secure.php | 59 ----- .../core/core.write_compiled_include.php | 59 ----- lib/smarty/core/core.write_file.php | 51 ----- lib/smarty/debug.tpl | 209 +++++++++++++----- .../core.assemble_plugin_filepath.php | 5 +- .../core.assign_smarty_interface.php | 4 +- .../core.create_dir_structure.php | 2 +- .../core.display_debug_console.php | 7 +- .../core.get_include_path.php | 0 .../core.get_microtime.php | 0 .../core.get_php_resource.php | 4 +- lib/smarty/internals/core.is_secure.php | 59 +++++ .../{core => internals}/core.is_trusted.php | 5 +- .../{core => internals}/core.load_plugins.php | 0 .../core.load_resource_plugin.php | 0 .../core.process_cached_inserts.php | 8 +- .../core.process_compiled_include.php | 7 +- .../core.read_cache_file.php | 20 +- .../{core => internals}/core.rm_auto.php | 4 +- lib/smarty/{core => internals}/core.rmdir.php | 1 - .../core.run_insert_handler.php | 6 +- .../core.smarty_include_php.php | 2 +- .../core.write_cache_file.php | 41 +++- .../internals/core.write_compiled_include.php | 91 ++++++++ .../core.write_compiled_resource.php | 5 +- lib/smarty/internals/core.write_file.php | 54 +++++ lib/smarty/plugins/block.textformat.php | 1 + lib/smarty/plugins/compiler.assign.php | 2 + .../plugins/function.assign_debug_info.php | 1 + lib/smarty/plugins/function.config_load.php | 2 + lib/smarty/plugins/function.counter.php | 1 + lib/smarty/plugins/function.eval.php | 1 + lib/smarty/plugins/function.fetch.php | 1 + lib/smarty/plugins/function.html_image.php | 27 ++- lib/smarty/plugins/function.html_options.php | 1 + lib/smarty/plugins/function.html_radios.php | 20 +- .../plugins/function.html_select_date.php | 47 ++-- .../plugins/function.html_select_time.php | 2 + lib/smarty/plugins/function.html_table.php | 60 ++++- lib/smarty/plugins/function.mailto.php | 4 +- lib/smarty/plugins/function.math.php | 6 +- lib/smarty/plugins/function.popup.php | 2 + lib/smarty/plugins/function.popup_init.php | 1 + lib/smarty/plugins/modifier.capitalize.php | 5 +- .../plugins/modifier.count_characters.php | 1 + .../plugins/modifier.count_paragraphs.php | 1 + .../plugins/modifier.count_sentences.php | 1 + lib/smarty/plugins/modifier.count_words.php | 1 + lib/smarty/plugins/modifier.date_format.php | 32 ++- .../plugins/modifier.debug_print_var.php | 86 ++++--- lib/smarty/plugins/modifier.default.php | 1 + lib/smarty/plugins/modifier.escape.php | 14 +- lib/smarty/plugins/modifier.indent.php | 1 + lib/smarty/plugins/modifier.lower.php | 1 + lib/smarty/plugins/modifier.regex_replace.php | 23 +- lib/smarty/plugins/modifier.replace.php | 1 + lib/smarty/plugins/modifier.spacify.php | 1 + lib/smarty/plugins/modifier.string_format.php | 1 + lib/smarty/plugins/modifier.strip_tags.php | 1 + lib/smarty/plugins/modifier.truncate.php | 21 +- lib/smarty/plugins/modifier.upper.php | 1 + lib/smarty/plugins/modifier.wordwrap.php | 1 + .../plugins/outputfilter.trimwhitespace.php | 22 +- .../plugins/shared.escape_special_chars.php | 1 + lib/smarty/plugins/shared.make_timestamp.php | 37 ++-- lib/smarty/readme_moodle.txt | 6 + 69 files changed, 926 insertions(+), 514 deletions(-) delete mode 100644 lib/smarty/core/core.is_secure.php delete mode 100644 lib/smarty/core/core.write_compiled_include.php delete mode 100644 lib/smarty/core/core.write_file.php rename lib/smarty/{core => internals}/core.assemble_plugin_filepath.php (91%) rename lib/smarty/{core => internals}/core.assign_smarty_interface.php (94%) rename lib/smarty/{core => internals}/core.create_dir_structure.php (97%) rename lib/smarty/{core => internals}/core.display_debug_console.php (87%) rename lib/smarty/{core => internals}/core.get_include_path.php (100%) rename lib/smarty/{core => internals}/core.get_microtime.php (100%) rename lib/smarty/{core => internals}/core.get_php_resource.php (92%) create mode 100644 lib/smarty/internals/core.is_secure.php rename lib/smarty/{core => internals}/core.is_trusted.php (92%) rename lib/smarty/{core => internals}/core.load_plugins.php (100%) rename lib/smarty/{core => internals}/core.load_resource_plugin.php (100%) rename lib/smarty/{core => internals}/core.process_cached_inserts.php (84%) rename lib/smarty/{core => internals}/core.process_compiled_include.php (75%) rename lib/smarty/{core => internals}/core.read_cache_file.php (85%) rename lib/smarty/{core => internals}/core.rm_auto.php (92%) rename lib/smarty/{core => internals}/core.rmdir.php (93%) rename lib/smarty/{core => internals}/core.run_insert_handler.php (89%) rename lib/smarty/{core => internals}/core.smarty_include_php.php (94%) rename lib/smarty/{core => internals}/core.write_cache_file.php (59%) create mode 100644 lib/smarty/internals/core.write_compiled_include.php rename lib/smarty/{core => internals}/core.write_compiled_resource.php (75%) create mode 100644 lib/smarty/internals/core.write_file.php create mode 100644 lib/smarty/readme_moodle.txt diff --git a/lib/smarty/Config_File.class.php b/lib/smarty/Config_File.class.php index 247d78084e..ae0c3be315 100644 --- a/lib/smarty/Config_File.class.php +++ b/lib/smarty/Config_File.class.php @@ -17,8 +17,12 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * @link http://smarty.php.net/ - * @version 2.6.9 + * For questions, help, comments, discussion, etc., please join the + * Smarty mailing list. Send a blank e-mail to + * smarty-discussion-subscribe@googlegroups.com + * + * @link http://www.smarty.net/ + * @version 2.6.26 * @copyright Copyright: 2001-2005 New Digital Group, Inc. * @author Andrei Zmievski * @access public @@ -105,7 +109,7 @@ class Config_File { * @param string $var_name (optional) variable to get info for * @return string|array a value or array of values */ - function &get($file_name, $section_name = NULL, $var_name = NULL) + function get($file_name, $section_name = NULL, $var_name = NULL) { if (empty($file_name)) { $this->_trigger_error_msg('Empty config file name'); @@ -285,9 +289,9 @@ class Config_File { $line = $lines[$i]; if (empty($line)) continue; - if ( $line{0} == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) { + if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) { /* section found */ - if ($match[1]{0} == '.') { + if (substr($match[1], 0, 1) == '.') { /* hidden section */ if ($this->read_hidden) { $section_name = substr($match[1], 1); @@ -347,7 +351,7 @@ class Config_File { */ function _set_config_var(&$container, $var_name, $var_value, $booleanize) { - if ($var_name{0} == '.') { + if (substr($var_name, 0, 1) == '.') { if (!$this->read_hidden) return; else diff --git a/lib/smarty/Smarty.class.php b/lib/smarty/Smarty.class.php index 5aa560eb2f..a3e2ed8a0f 100644 --- a/lib/smarty/Smarty.class.php +++ b/lib/smarty/Smarty.class.php @@ -20,14 +20,14 @@ * * For questions, help, comments, discussion, etc., please join the * 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. * @author Monte Ohrt * @author Andrei Zmievski * @package Smarty - * @version 2.6.9 + * @version 2.6.26 */ /* $Id$ */ @@ -50,7 +50,7 @@ if (!defined('SMARTY_DIR')) { } if (!defined('SMARTY_CORE_DIR')) { - define('SMARTY_CORE_DIR', SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR); + define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR); } define('SMARTY_PHP_PASSTHRU', 0); @@ -107,7 +107,7 @@ class Smarty /** * When set, smarty does uses this value as error_reporting-level. * - * @var boolean + * @var integer */ var $error_reporting = null; @@ -236,7 +236,8 @@ class Smarty 'INCLUDE_ANY' => false, 'PHP_TAGS' => false, 'MODIFIER_FUNCS' => array('count'), - 'ALLOW_CONSTANTS' => false + 'ALLOW_CONSTANTS' => false, + 'ALLOW_SUPER_GLOBALS' => true ); /** @@ -464,7 +465,7 @@ class Smarty * * @var string */ - var $_version = '2.6.9'; + var $_version = '2.6.26'; /** * current template inclusion depth @@ -838,69 +839,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)]); } /** @@ -1055,9 +1053,12 @@ class Smarty { if(!isset($name)) { return $this->_tpl_vars; - } - if(isset($this->_tpl_vars[$name])) { + } elseif(isset($this->_tpl_vars[$name])) { return $this->_tpl_vars[$name]; + } else { + // var non-existant, return valid reference + $_tmp = null; + return $_tmp; } } @@ -1074,6 +1075,10 @@ class Smarty return $this->_config[0]['vars']; } else if(isset($this->_config[0]['vars'][$name])) { return $this->_config[0]['vars'][$name]; + } else { + // var non-existant, return valid reference + $_tmp = null; + return $_tmp; } } @@ -1544,7 +1549,7 @@ class Smarty $params['source_content'] = $this->_read_file($_resource_name); } $params['resource_timestamp'] = filemtime($_resource_name); - $_return = is_file($_resource_name); + $_return = is_file($_resource_name) && is_readable($_resource_name); break; default: @@ -1691,8 +1696,8 @@ class Smarty */ function _dequote($string) { - if (($string{0} == "'" || $string{0} == '"') && - $string{strlen($string)-1} == $string{0}) + if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') && + substr($string, -1) == substr($string, 0, 1)) return substr($string, 1, -1); else return $string; @@ -1707,8 +1712,11 @@ class Smarty */ function _read_file($filename) { - if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { - $contents = ($size = filesize($filename)) ? fread($fd, $size) : ''; + if ( file_exists($filename) && is_readable($filename) && ($fd = @fopen($filename, 'rb')) ) { + $contents = ''; + while (!feof($fd)) { + $contents .= fread($fd, 8192); + } fclose($fd); return $contents; } else { @@ -1889,7 +1897,7 @@ class Smarty if ($this->_cache_including) { /* return next set of cache_attrs */ - $_return =& current($_cache_attrs); + $_return = current($_cache_attrs); next($_cache_attrs); return $_return; @@ -1925,6 +1933,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/lib/smarty/Smarty_Compiler.class.php b/lib/smarty/Smarty_Compiler.class.php index aba1fb65f3..f6a278d4a4 100644 --- a/lib/smarty/Smarty_Compiler.class.php +++ b/lib/smarty/Smarty_Compiler.class.php @@ -21,7 +21,7 @@ * @link http://smarty.php.net/ * @author Monte Ohrt * @author Andrei Zmievski - * @version 2.6.9 + * @version 2.6.26 * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ @@ -278,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'); @@ -304,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++) { @@ -349,19 +349,32 @@ 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) { @@ -425,7 +435,7 @@ class Smarty_Compiler extends Smarty { function _compile_tag($template_tag) { /* Matched comment. */ - if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') + if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*') return ''; /* Split tag into two three parts: command, command modifiers and the arguments. */ @@ -529,7 +539,7 @@ class Smarty_Compiler extends Smarty { case 'strip': case '/strip': - if ($tag_command{0}=='/') { + if (substr($tag_command, 0, 1)=='/') { $this->_pop_tag('strip'); if (--$this->_strip_depth==0) { /* outermost closing {/strip} */ $this->_additional_newline = "\n"; @@ -664,7 +674,7 @@ class Smarty_Compiler extends Smarty { */ function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) { - if ($tag_command{0} == '/') { + if (substr($tag_command, 0, 1) == '/') { $start_tag = false; $tag_command = substr($tag_command, 1); } else @@ -726,17 +736,18 @@ class Smarty_Compiler extends Smarty { if ($start_tag) { $output = '_push_cacheable_state('block', $tag_command); $attrs = $this->_parse_attrs($tag_args); - $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs=''); + $_cache_attrs=''; + $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs); $output .= "$_cache_attrs\$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); '; - $output .= $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat=true);'; + $output .= '$_block_repeat=true;' . $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);'; $output .= 'while ($_block_repeat) { ob_start(); ?>'; } else { $output = '_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat=false)'; + $_out_tag_text = $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat)'; if ($tag_modifier != '') { $this->_parse_modifiers($_out_tag_text, $tag_modifier); } - $output .= 'echo '.$_out_tag_text.'; } '; + $output .= '$_block_repeat=false;echo ' . $_out_tag_text . '; } '; $output .= " array_pop(\$this->_tag_stack); " . $this->_pop_cacheable_state('block', $tag_command) . '?>'; } @@ -801,7 +812,8 @@ class Smarty_Compiler extends Smarty { $_cacheable_state = $this->_push_cacheable_state('function', $tag_command); $attrs = $this->_parse_attrs($tag_args); - $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs=''); + $_cache_attrs = ''; + $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs); $output = $this->_compile_plugin_call('function', $tag_command).'(array('.implode(',', $arg_list)."), \$this)"; if($tag_modifier != '') { @@ -826,7 +838,7 @@ class Smarty_Compiler extends Smarty { */ function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) { - if ($tag_command{0} == '/') { + if (substr($tag_command, 0, 1) == '/') { $start_tag = false; $tag_command = substr($tag_command, 1); } else { @@ -857,7 +869,7 @@ class Smarty_Compiler extends Smarty { // traditional argument format $args = implode(',', array_values($attrs)); if (empty($args)) { - $args = 'null'; + $args = ''; } } @@ -874,13 +886,13 @@ class Smarty_Compiler extends Smarty { // block method if ($start_tag) { $prefix = "\$this->_tag_stack[] = array('$obj_comp', $args); "; - $prefix .= "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat=true); "; + $prefix .= "\$_block_repeat=true; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat); "; $prefix .= "while (\$_block_repeat) { ob_start();"; $return = null; $postfix = ''; - } else { - $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); "; - $return = "\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat=false)"; + } else { + $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;"; + $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);"; } } else { @@ -922,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'])) { @@ -1155,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'])) { @@ -1206,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(); ?>"; } @@ -1250,6 +1264,13 @@ class Smarty_Compiler extends Smarty { $tokens = $match[0]; + if(empty($tokens)) { + $_error_msg = $elseif ? "'elseif'" : "'if'"; + $_error_msg .= ' statement requires arguments'; + $this->_syntax_error($_error_msg, E_USER_ERROR, __FILE__, __LINE__); + } + + // make sure we have balanced parenthesis $token_count = array_count_values($tokens); if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { @@ -1342,9 +1363,14 @@ class Smarty_Compiler extends Smarty { /* If last token was a ')', we operate on the parenthesized expression. The start of the expression is on the stack. Otherwise, we operate on the last encountered token. */ - if ($tokens[$i-1] == ')') + if ($tokens[$i-1] == ')') { $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; /* Construct the argument for 'is' expression, so it knows what to operate on. */ @@ -1372,7 +1398,7 @@ class Smarty_Compiler extends Smarty { !in_array($token, $this->security_settings['IF_FUNCS'])) { $this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); } - } elseif(preg_match('~^' . $this->_var_regexp . '$~', $token) && isset($tokens[$i+1]) && $tokens[$i+1] == '(') { + } elseif(preg_match('~^' . $this->_var_regexp . '$~', $token) && (strpos('+-*/^%&|', substr($token, -1)) === false) && isset($tokens[$i+1]) && $tokens[$i+1] == '(') { // variable function call $this->_syntax_error("variable function call '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); } elseif(preg_match('~^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$~', $token)) { @@ -1643,7 +1669,7 @@ class Smarty_Compiler extends Smarty { } elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { // literal string - return $this->_expand_quoted_text('"' . $val .'"'); + return $this->_expand_quoted_text('"' . strtr($val, array('\\' => '\\\\', '"' => '\\"')) .'"'); } return $val; } @@ -1659,11 +1685,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('~\.""|(?_smarty_vars['$_var_name']"; } - } elseif(is_numeric($_var_name) && is_numeric($var_expr{0})) { + } elseif(is_numeric($_var_name) && is_numeric(substr($var_expr, 0, 1))) { // because . is the operator for accessing arrays thru inidizes we need to put it together again for floating point numbers if(count($_indexes) > 0) { @@ -1762,11 +1788,11 @@ class Smarty_Compiler extends Smarty { } foreach ($_indexes as $_index) { - if ($_index{0} == '[') { + if (substr($_index, 0, 1) == '[') { $_index = substr($_index, 1, -1); if (is_numeric($_index)) { $_output .= "[$_index]"; - } elseif ($_index{0} == '$') { + } elseif (substr($_index, 0, 1) == '$') { if (strpos($_index, '.') !== false) { $_output .= '[' . $this->_parse_var($_index) . ']'; } else { @@ -1778,8 +1804,8 @@ class Smarty_Compiler extends Smarty { $_var_section_prop = isset($_var_parts[1]) ? $_var_parts[1] : 'index'; $_output .= "[\$this->_sections['$_var_section']['$_var_section_prop']]"; } - } else if ($_index{0} == '.') { - if ($_index{1} == '$') + } else if (substr($_index, 0, 1) == '.') { + if (substr($_index, 1, 1) == '$') $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]"; else $_output .= "['" . substr($_index, 1) . "']"; @@ -1788,7 +1814,7 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__); } elseif($this->security && substr($_index, 2, 1) == '_') { $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); - } elseif ($_index{2} == '$') { + } elseif (substr($_index, 2, 1) == '$') { if ($this->security) { $this->_syntax_error('(secure) call to dynamic object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); } else { @@ -1797,7 +1823,7 @@ class Smarty_Compiler extends Smarty { } else { $_output .= $_index; } - } elseif ($_index{0} == '(') { + } elseif (substr($_index, 0, 1) == '(') { $_index = $this->_parse_parenth_args($_index); $_output .= $_index; } else { @@ -1894,7 +1920,7 @@ class Smarty_Compiler extends Smarty { preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match); $_modifier_args = $_match[1]; - if ($_modifier_name{0} == '@') { + if (substr($_modifier_name, 0, 1) == '@') { $_map_array = false; $_modifier_name = substr($_modifier_name, 1); } else { @@ -1916,10 +1942,10 @@ class Smarty_Compiler extends Smarty { if($_modifier_name == 'default') { // supress notifications of default modifier vars and args - if($output{0} == '$') { + if(substr($output, 0, 1) == '$') { $output = '@' . $output; } - if(isset($_modifier_args[0]) && $_modifier_args[0]{0} == '$') { + if(isset($_modifier_args[0]) && substr($_modifier_args[0], 0, 1) == '$') { $_modifier_args[0] = '@' . $_modifier_args[0]; } } @@ -1971,7 +1997,7 @@ class Smarty_Compiler extends Smarty { /* Extract the reference name. */ $_ref = substr($indexes[0], 1); foreach($indexes as $_index_no=>$_index) { - if ($_index{0} != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) { + if (substr($_index, 0, 1) != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) { $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); } } @@ -2021,27 +2047,57 @@ class Smarty_Compiler extends Smarty { break; case 'get': - $compiled_ref = ($this->request_use_auto_globals) ? '$_GET' : "\$GLOBALS['HTTP_GET_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_GET"; break; case 'post': - $compiled_ref = ($this->request_use_auto_globals) ? '$_POST' : "\$GLOBALS['HTTP_POST_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_POST"; break; case 'cookies': - $compiled_ref = ($this->request_use_auto_globals) ? '$_COOKIE' : "\$GLOBALS['HTTP_COOKIE_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_COOKIE"; break; case 'env': - $compiled_ref = ($this->request_use_auto_globals) ? '$_ENV' : "\$GLOBALS['HTTP_ENV_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_ENV"; break; case 'server': - $compiled_ref = ($this->request_use_auto_globals) ? '$_SERVER' : "\$GLOBALS['HTTP_SERVER_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_SERVER"; break; case 'session': - $compiled_ref = ($this->request_use_auto_globals) ? '$_SESSION' : "\$GLOBALS['HTTP_SESSION_VARS']"; + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } + $compiled_ref = "\$_SESSION"; break; /* @@ -2049,8 +2105,13 @@ class Smarty_Compiler extends Smarty { * compiler. */ case 'request': + if ($this->security && !$this->security_settings['ALLOW_SUPER_GLOBALS']) { + $this->_syntax_error("(secure mode) super global access not permitted", + E_USER_WARNING, __FILE__, __LINE__); + return; + } if ($this->request_use_auto_globals) { - $compiled_ref = '$_REQUEST'; + $compiled_ref = "\$_REQUEST"; break; } else { $this->_init_smarty_vars = true; @@ -2207,9 +2268,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; } @@ -2224,9 +2285,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/lib/smarty/core/core.is_secure.php b/lib/smarty/core/core.is_secure.php deleted file mode 100644 index 877886b885..0000000000 --- a/lib/smarty/core/core.is_secure.php +++ /dev/null @@ -1,59 +0,0 @@ -security || $smarty->security_settings['INCLUDE_ANY']) { - return true; - } - - $_smarty_secure = false; - if ($params['resource_type'] == 'file') { - if($check_template_dir) { - if (!in_array($smarty->template_dir, $smarty->secure_dir)) - // add template_dir to secure_dir array - array_unshift($smarty->secure_dir, $smarty->template_dir); - $check_template_dir = false; - } - if (!empty($smarty->secure_dir)) { - $_rp = realpath($params['resource_name']); - foreach ((array)$smarty->secure_dir as $curr_dir) { - if ( !empty($curr_dir) && is_readable ($curr_dir)) { - $_cd = realpath($curr_dir); - if (strncmp($_rp, $_cd, strlen($_cd)) == 0 - && $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) { - $_smarty_secure = true; - break; - } - } - } - } - } else { - // resource is not on local file system - $_smarty_secure = call_user_func_array( - $smarty->_plugins['resource'][$params['resource_type']][0][2], - array($params['resource_name'], &$_smarty_secure, &$smarty)); - } - - return $_smarty_secure; -} - -/* vim: set expandtab: */ - -?> diff --git a/lib/smarty/core/core.write_compiled_include.php b/lib/smarty/core/core.write_compiled_include.php deleted file mode 100644 index 9c6a49199c..0000000000 --- a/lib/smarty/core/core.write_compiled_include.php +++ /dev/null @@ -1,59 +0,0 @@ -caching\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}'; - $_tag_end = 'if \(\$this->caching\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}'; - - 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; - - // convert the matched php-code to functions - $_include_compiled = "_cache_serials[$_compile_path] = $params['cache_serial']; - $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>"; - - $_include_compiled .= $params['plugins_code']; - $_include_compiled .= "\n"; - - $_params = array('filename' => $_compile_path, - 'contents' => $_include_compiled, 'create_dirs' => true); - - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); - smarty_core_write_file($_params, $smarty); - return true; -} - - -?> diff --git a/lib/smarty/core/core.write_file.php b/lib/smarty/core/core.write_file.php deleted file mode 100644 index b4fa92e5e6..0000000000 --- a/lib/smarty/core/core.write_file.php +++ /dev/null @@ -1,51 +0,0 @@ - $_dirname); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.create_dir_structure.php'); - smarty_core_create_dir_structure($_params, $smarty); - } - - // write to tmp file, then rename it to avoid - // file locking race condition - $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid(''); - - if (!($fd = @fopen($_tmp_file, 'w'))) { - $smarty->trigger_error("problem writing temporary file '$_tmp_file'"); - return false; - } - - fwrite($fd, $params['contents']); - if (isset($params['timestamp'])) { - touch($_tmp_file, $params['timestamp']); - } - fclose($fd); - if(file_exists($params['filename'])) { - @unlink($params['filename']); - } - @rename($_tmp_file, $params['filename']); - @chmod($params['filename'], $smarty->_file_perms); - - return true; -} - -/* vim: set expandtab: */ - -?> diff --git a/lib/smarty/debug.tpl b/lib/smarty/debug.tpl index 7f1c9d4258..c05ef5d0b5 100644 --- a/lib/smarty/debug.tpl +++ b/lib/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/lib/smarty/core/core.assemble_plugin_filepath.php b/lib/smarty/internals/core.assemble_plugin_filepath.php similarity index 91% rename from lib/smarty/core/core.assemble_plugin_filepath.php rename to lib/smarty/internals/core.assemble_plugin_filepath.php index c0d9d8665a..690d3ddbc2 100644 --- a/lib/smarty/core/core.assemble_plugin_filepath.php +++ b/lib/smarty/internals/core.assemble_plugin_filepath.php @@ -50,9 +50,10 @@ function smarty_core_assemble_plugin_filepath($params, &$smarty) $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; $_params = array('file_path' => $_plugin_filepath); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); + require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); if(smarty_core_get_include_path($_params, $smarty)) { - return $_params['new_file_path']; + $_return = $_params['new_file_path']; + break; } } } diff --git a/lib/smarty/core/core.assign_smarty_interface.php b/lib/smarty/internals/core.assign_smarty_interface.php similarity index 94% rename from lib/smarty/core/core.assign_smarty_interface.php rename to lib/smarty/internals/core.assign_smarty_interface.php index 8660f3d96f..7e65a73ec2 100644 --- a/lib/smarty/core/core.assign_smarty_interface.php +++ b/lib/smarty/internals/core.assign_smarty_interface.php @@ -8,8 +8,8 @@ /** * Smarty assign_smarty_interface core plugin * - * Type: core
- * Name: assign_smarty_interface
+ * Type: core
+ * Name: assign_smarty_interface
* Purpose: assign the $smarty interface variable * @param array Format: null * @param Smarty diff --git a/lib/smarty/core/core.create_dir_structure.php b/lib/smarty/internals/core.create_dir_structure.php similarity index 97% rename from lib/smarty/core/core.create_dir_structure.php rename to lib/smarty/internals/core.create_dir_structure.php index 999cf59302..3eecc49723 100644 --- a/lib/smarty/core/core.create_dir_structure.php +++ b/lib/smarty/internals/core.create_dir_structure.php @@ -22,7 +22,7 @@ function smarty_core_create_dir_structure($params, &$smarty) /* unix-style paths */ $_dir = $params['dir']; $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY); - $_new_dir = ($_dir{0}=='/') ? '/' : getcwd().'/'; + $_new_dir = (substr($_dir, 0, 1)=='/') ? '/' : getcwd().'/'; if($_use_open_basedir = !empty($_open_basedir_ini)) { $_open_basedirs = explode(':', $_open_basedir_ini); } diff --git a/lib/smarty/core/core.display_debug_console.php b/lib/smarty/internals/core.display_debug_console.php similarity index 87% rename from lib/smarty/core/core.display_debug_console.php rename to lib/smarty/internals/core.display_debug_console.php index d67091eb35..1a80f39096 100644 --- a/lib/smarty/core/core.display_debug_console.php +++ b/lib/smarty/internals/core.display_debug_console.php @@ -8,8 +8,8 @@ /** * Smarty debug_console function plugin * - * Type: core
- * Name: display_debug_console
+ * Type: core
+ * Name: display_debug_console
* Purpose: display the javascript debug console window * @param array Format: null * @param Smarty @@ -23,8 +23,9 @@ function smarty_core_display_debug_console($params, &$smarty) // set path to debug template from SMARTY_DIR $smarty->debug_tpl = SMARTY_DIR . 'debug.tpl'; if($smarty->security && is_file($smarty->debug_tpl)) { - $smarty->secure_dir[] = dirname(realpath($smarty->debug_tpl)); + $smarty->secure_dir[] = realpath($smarty->debug_tpl); } + $smarty->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl'; } $_ldelim_orig = $smarty->left_delimiter; diff --git a/lib/smarty/core/core.get_include_path.php b/lib/smarty/internals/core.get_include_path.php similarity index 100% rename from lib/smarty/core/core.get_include_path.php rename to lib/smarty/internals/core.get_include_path.php diff --git a/lib/smarty/core/core.get_microtime.php b/lib/smarty/internals/core.get_microtime.php similarity index 100% rename from lib/smarty/core/core.get_microtime.php rename to lib/smarty/internals/core.get_microtime.php diff --git a/lib/smarty/core/core.get_php_resource.php b/lib/smarty/internals/core.get_php_resource.php similarity index 92% rename from lib/smarty/core/core.get_php_resource.php rename to lib/smarty/internals/core.get_php_resource.php index 8121acf8b0..786d4e78e8 100644 --- a/lib/smarty/core/core.get_php_resource.php +++ b/lib/smarty/internals/core.get_php_resource.php @@ -32,7 +32,7 @@ function smarty_core_get_php_resource(&$params, &$smarty) } else { // test for file in include_path $_params = array('file_path' => $params['resource_name']); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php'); + require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); if(smarty_core_get_include_path($_params, $smarty)) { $_include_path = $_params['new_file_path']; $_readable = true; @@ -56,7 +56,7 @@ function smarty_core_get_php_resource(&$params, &$smarty) if ($_readable) { if ($smarty->security) { - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_trusted.php'); + require_once(SMARTY_CORE_DIR . 'core.is_trusted.php'); if (!smarty_core_is_trusted($params, $smarty)) { $smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted'); return false; diff --git a/lib/smarty/internals/core.is_secure.php b/lib/smarty/internals/core.is_secure.php new file mode 100644 index 0000000000..d54abd4322 --- /dev/null +++ b/lib/smarty/internals/core.is_secure.php @@ -0,0 +1,59 @@ +security || $smarty->security_settings['INCLUDE_ANY']) { + return true; + } + + if ($params['resource_type'] == 'file') { + $_rp = realpath($params['resource_name']); + if (isset($params['resource_base_path'])) { + foreach ((array)$params['resource_base_path'] as $curr_dir) { + if ( ($_cd = realpath($curr_dir)) !== false && + strncmp($_rp, $_cd, strlen($_cd)) == 0 && + substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) { + return true; + } + } + } + if (!empty($smarty->secure_dir)) { + foreach ((array)$smarty->secure_dir as $curr_dir) { + if ( ($_cd = realpath($curr_dir)) !== false) { + if($_cd == $_rp) { + return true; + } elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && + substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) { + return true; + } + } + } + } + } else { + // resource is not on local file system + return call_user_func_array( + $smarty->_plugins['resource'][$params['resource_type']][0][2], + array($params['resource_name'], &$smarty)); + } + + return false; +} + +/* vim: set expandtab: */ + +?> diff --git a/lib/smarty/core/core.is_trusted.php b/lib/smarty/internals/core.is_trusted.php similarity index 92% rename from lib/smarty/core/core.is_trusted.php rename to lib/smarty/internals/core.is_trusted.php index c90e3ef992..429973158d 100644 --- a/lib/smarty/core/core.is_trusted.php +++ b/lib/smarty/internals/core.is_trusted.php @@ -5,9 +5,6 @@ * @subpackage plugins */ -/**#@+ - * @access private - */ /** * determines if a resource is trusted or not * @@ -28,7 +25,7 @@ function smarty_core_is_trusted($params, &$smarty) if (!empty($curr_dir) && is_readable ($curr_dir)) { $_cd = realpath($curr_dir); if (strncmp($_rp, $_cd, strlen($_cd)) == 0 - && $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) { + && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) { $_smarty_trusted = true; break; } diff --git a/lib/smarty/core/core.load_plugins.php b/lib/smarty/internals/core.load_plugins.php similarity index 100% rename from lib/smarty/core/core.load_plugins.php rename to lib/smarty/internals/core.load_plugins.php diff --git a/lib/smarty/core/core.load_resource_plugin.php b/lib/smarty/internals/core.load_resource_plugin.php similarity index 100% rename from lib/smarty/core/core.load_resource_plugin.php rename to lib/smarty/internals/core.load_resource_plugin.php diff --git a/lib/smarty/core/core.process_cached_inserts.php b/lib/smarty/internals/core.process_cached_inserts.php similarity index 84% rename from lib/smarty/core/core.process_cached_inserts.php rename to lib/smarty/internals/core.process_cached_inserts.php index 0e368fdd60..1d78edd937 100644 --- a/lib/smarty/core/core.process_cached_inserts.php +++ b/lib/smarty/internals/core.process_cached_inserts.php @@ -20,7 +20,7 @@ function smarty_core_process_cached_inserts($params, &$smarty) for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { if ($smarty->debugging) { $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $debug_start_time = smarty_core_get_microtime($_params, $smarty); } @@ -29,7 +29,7 @@ function smarty_core_process_cached_inserts($params, &$smarty) if (isset($args['script'])) { $_params = array('resource_name' => $smarty->_dequote($args['script'])); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); + require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); if(!smarty_core_get_php_resource($_params, $smarty)) { return false; } @@ -52,10 +52,10 @@ function smarty_core_process_cached_inserts($params, &$smarty) $replace = ''; } - $params['results'] = str_replace($cached_inserts[$i], $replace, $params['results']); + $params['results'] = substr_replace($params['results'], $replace, strpos($params['results'], $cached_inserts[$i]), strlen($cached_inserts[$i])); if ($smarty->debugging) { $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $smarty->_smarty_debug_info[] = array('type' => 'insert', 'filename' => 'insert_'.$name, 'depth' => $smarty->_inclusion_depth, diff --git a/lib/smarty/core/core.process_compiled_include.php b/lib/smarty/internals/core.process_compiled_include.php similarity index 75% rename from lib/smarty/core/core.process_compiled_include.php rename to lib/smarty/internals/core.process_compiled_include.php index 3e1d4c15a0..904d597452 100644 --- a/lib/smarty/core/core.process_compiled_include.php +++ b/lib/smarty/internals/core.process_compiled_include.php @@ -20,7 +20,12 @@ function smarty_core_process_compiled_include($params, &$smarty) $smarty->_cache_including = true; $_return = $params['results']; - foreach ($smarty->_cache_serials as $_include_file_path=>$_cache_serial) { + + foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) { + $smarty->_include($_include_file_path, true); + } + + foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) { $_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s', array(&$smarty, '_process_compiled_include_callback'), $_return); diff --git a/lib/smarty/core/core.read_cache_file.php b/lib/smarty/internals/core.read_cache_file.php similarity index 85% rename from lib/smarty/core/core.read_cache_file.php rename to lib/smarty/internals/core.read_cache_file.php index 2ab428111d..c60e113a71 100644 --- a/lib/smarty/core/core.read_cache_file.php +++ b/lib/smarty/internals/core.read_cache_file.php @@ -48,10 +48,11 @@ function smarty_core_read_cache_file(&$params, &$smarty) return false; } - $cache_split = explode("\n", $params['results'], 2); - $cache_header = $cache_split[0]; - - $_cache_info = unserialize($cache_header); + $_contents = $params['results']; + $_info_start = strpos($_contents, "\n") + 1; + $_info_len = (int)substr($_contents, 0, $_info_start - 1); + $_cache_info = unserialize(substr($_contents, $_info_start, $_info_len)); + $params['results'] = substr($_contents, $_info_start + $_info_len); if ($smarty->caching == 2 && isset ($_cache_info['expires'])){ // caching by expiration time @@ -89,17 +90,6 @@ function smarty_core_read_cache_file(&$params, &$smarty) } } - foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) { - if (empty($smarty->_cache_serials[$_include_file_path])) { - $smarty->_include($_include_file_path, true); - } - - if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) { - /* regenerate */ - return false; - } - } - $params['results'] = $cache_split[1]; $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info); $smarty->_cache_info = $_cache_info; diff --git a/lib/smarty/core/core.rm_auto.php b/lib/smarty/internals/core.rm_auto.php similarity index 92% rename from lib/smarty/core/core.rm_auto.php rename to lib/smarty/internals/core.rm_auto.php index b7cdaf8c5d..b251f64911 100644 --- a/lib/smarty/core/core.rm_auto.php +++ b/lib/smarty/internals/core.rm_auto.php @@ -28,7 +28,7 @@ function smarty_core_rm_auto($params, &$smarty) 'level' => 0, 'exp_time' => $params['exp_time'] ); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); + require_once(SMARTY_CORE_DIR . 'core.rmdir.php'); $_res = smarty_core_rmdir($_params, $smarty); } else { $_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']); @@ -47,7 +47,7 @@ function smarty_core_rm_auto($params, &$smarty) 'level' => 1, 'exp_time' => $params['exp_time'] ); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); + require_once(SMARTY_CORE_DIR . 'core.rmdir.php'); $_res = smarty_core_rmdir($_params, $smarty); } else { // remove matching file names diff --git a/lib/smarty/core/core.rmdir.php b/lib/smarty/internals/core.rmdir.php similarity index 93% rename from lib/smarty/core/core.rmdir.php rename to lib/smarty/internals/core.rmdir.php index 38df822cea..2166c44d28 100644 --- a/lib/smarty/core/core.rmdir.php +++ b/lib/smarty/internals/core.rmdir.php @@ -32,7 +32,6 @@ function smarty_core_rmdir($params, &$smarty) 'level' => $params['level'] + 1, 'exp_time' => $params['exp_time'] ); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php'); smarty_core_rmdir($_params, $smarty); } else { diff --git a/lib/smarty/core/core.run_insert_handler.php b/lib/smarty/internals/core.run_insert_handler.php similarity index 89% rename from lib/smarty/core/core.run_insert_handler.php rename to lib/smarty/internals/core.run_insert_handler.php index aa391ab3b2..71c3845080 100644 --- a/lib/smarty/core/core.run_insert_handler.php +++ b/lib/smarty/internals/core.run_insert_handler.php @@ -14,7 +14,7 @@ function smarty_core_run_insert_handler($params, &$smarty) { - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); if ($smarty->debugging) { $_params = array(); $_debug_start_time = smarty_core_get_microtime($_params, $smarty); @@ -34,7 +34,7 @@ function smarty_core_run_insert_handler($params, &$smarty) } else { if (isset($params['args']['script'])) { $_params = array('resource_name' => $smarty->_dequote($params['args']['script'])); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); + require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); if(!smarty_core_get_php_resource($_params, $smarty)) { return false; } @@ -51,7 +51,7 @@ function smarty_core_run_insert_handler($params, &$smarty) $_content = $_funcname($params['args'], $smarty); if ($smarty->debugging) { $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $smarty->_smarty_debug_info[] = array('type' => 'insert', 'filename' => 'insert_'.$params['args']['name'], 'depth' => $smarty->_inclusion_depth, diff --git a/lib/smarty/core/core.smarty_include_php.php b/lib/smarty/internals/core.smarty_include_php.php similarity index 94% rename from lib/smarty/core/core.smarty_include_php.php rename to lib/smarty/internals/core.smarty_include_php.php index 4b3164801a..30c6e76549 100644 --- a/lib/smarty/core/core.smarty_include_php.php +++ b/lib/smarty/internals/core.smarty_include_php.php @@ -21,7 +21,7 @@ function smarty_core_smarty_include_php($params, &$smarty) { $_params = array('resource_name' => $params['smarty_file']); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); + require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); smarty_core_get_php_resource($_params, $smarty); $_smarty_resource_type = $_params['resource_type']; $_smarty_php_resource = $_params['php_resource']; diff --git a/lib/smarty/core/core.write_cache_file.php b/lib/smarty/internals/core.write_cache_file.php similarity index 59% rename from lib/smarty/core/core.write_cache_file.php rename to lib/smarty/internals/core.write_cache_file.php index 7429ad98a8..fa3cdd746d 100644 --- a/lib/smarty/core/core.write_cache_file.php +++ b/lib/smarty/internals/core.write_cache_file.php @@ -31,21 +31,44 @@ function smarty_core_write_cache_file($params, &$smarty) $smarty->_cache_info['expires'] = -1; } - // collapse {nocache...}-tags - $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})' - .'.*' - .'{/nocache\:\\3#\\4\})!Us' - ,'\\2' - ,$params['results']); + // collapse nocache.../nocache-tags + if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) { + // remove everything between every pair of outermost noache.../nocache-tags + // and replace it by a single nocache-tag + // this new nocache-tag will be replaced by dynamic contents in + // smarty_core_process_compiled_includes() on a cache-read + + $match_count = count($match[0]); + $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE); + + $level = 0; + $j = 0; + for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) { + if ($results[$i] == $match[0][$j]) { + // nocache tag + if ($match[1][$j]) { // closing tag + $level--; + unset($results[$i]); + } else { // opening tag + if ($level++ > 0) unset($results[$i]); + } + $j++; + } elseif ($level > 0) { + unset($results[$i]); + } + } + $params['results'] = implode('', $results); + } $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials; // prepend the cache header info into cache file - $params['results'] = serialize($smarty->_cache_info)."\n".$params['results']; + $_cache_info = serialize($smarty->_cache_info); + $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $params['results']; if (!empty($smarty->cache_handler_func)) { // use cache_handler function 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 { // use local cache file @@ -62,7 +85,7 @@ function smarty_core_write_cache_file($params, &$smarty) $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']); $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id); $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); + require_once(SMARTY_CORE_DIR . 'core.write_file.php'); smarty_core_write_file($_params, $smarty); return true; } diff --git a/lib/smarty/internals/core.write_compiled_include.php b/lib/smarty/internals/core.write_compiled_include.php new file mode 100644 index 0000000000..c14adb5f42 --- /dev/null +++ b/lib/smarty/internals/core.write_compiled_include.php @@ -0,0 +1,91 @@ +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; + + // convert the matched php-code to functions + $_include_compiled = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; + $_include_compiled .= " compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n"; + + $_compile_path = $params['include_file_path']; + + $smarty->_cache_serials[$_compile_path] = $params['cache_serial']; + $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>"; + + $_include_compiled .= $params['plugins_code']; + $_include_compiled .= "= 5.0) ? '_smarty' : 'this'; + for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) { + $_match =& $_match_source[$_i]; + $source = $_match[4]; + if ($this_varname == '_smarty') { + /* rename $this to $_smarty in the sourcecode */ + $tokens = token_get_all('\n"; + + $_params = array('filename' => $_compile_path, + 'contents' => $_include_compiled, 'create_dirs' => true); + + require_once(SMARTY_CORE_DIR . 'core.write_file.php'); + smarty_core_write_file($_params, $smarty); + return true; +} + + +?> diff --git a/lib/smarty/core/core.write_compiled_resource.php b/lib/smarty/internals/core.write_compiled_resource.php similarity index 75% rename from lib/smarty/core/core.write_compiled_resource.php rename to lib/smarty/internals/core.write_compiled_resource.php index c701448cd1..b902eff3cb 100644 --- a/lib/smarty/core/core.write_compiled_resource.php +++ b/lib/smarty/internals/core.write_compiled_resource.php @@ -10,7 +10,6 @@ * * @param string $compile_path * @param string $compiled_content - * @param integer $resource_timestamp * @return true */ function smarty_core_write_compiled_resource($params, &$smarty) @@ -25,8 +24,8 @@ function smarty_core_write_compiled_resource($params, &$smarty) return false; } - $_params = array('filename' => $params['compile_path'], 'timestamp'=>$params['resource_timestamp'], 'contents' => $params['compiled_content'], 'create_dirs' => true); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php'); + $_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true); + require_once(SMARTY_CORE_DIR . 'core.write_file.php'); smarty_core_write_file($_params, $smarty); return true; } diff --git a/lib/smarty/internals/core.write_file.php b/lib/smarty/internals/core.write_file.php new file mode 100644 index 0000000000..8a3a3b3984 --- /dev/null +++ b/lib/smarty/internals/core.write_file.php @@ -0,0 +1,54 @@ + $_dirname); + require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php'); + smarty_core_create_dir_structure($_params, $smarty); + } + + // write to tmp file, then rename it to avoid file locking race condition + $_tmp_file = tempnam($_dirname, 'wrt'); + + if (!($fd = @fopen($_tmp_file, 'wb'))) { + $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt'); + if (!($fd = @fopen($_tmp_file, 'wb'))) { + $smarty->trigger_error("problem writing temporary file '$_tmp_file'"); + return false; + } + } + + fwrite($fd, $params['contents']); + fclose($fd); + + 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']); + } + @chmod($params['filename'], $smarty->_file_perms); + + return true; +} + +/* vim: set expandtab: */ + +?> \ No newline at end of file diff --git a/lib/smarty/plugins/block.textformat.php b/lib/smarty/plugins/block.textformat.php index aaebab2f51..8cd010acb4 100644 --- a/lib/smarty/plugins/block.textformat.php +++ b/lib/smarty/plugins/block.textformat.php @@ -23,6 +23,7 @@ * indent_char: string (" ") * wrap_boundary: boolean (true) * + * @author Monte Ohrt * @param string contents of the block * @param Smarty clever simulation of a method * @return string string $content re-formatted diff --git a/lib/smarty/plugins/compiler.assign.php b/lib/smarty/plugins/compiler.assign.php index 2e02017796..abef377f8c 100644 --- a/lib/smarty/plugins/compiler.assign.php +++ b/lib/smarty/plugins/compiler.assign.php @@ -13,6 +13,8 @@ * Purpose: assign a value to a template variable * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign} * (Smarty online manual) + * @author Monte Ohrt (initial author) + * @author messju mohr (conversion to compiler function) * @param string containing var-attribute and value-attribute * @param Smarty_Compiler */ diff --git a/lib/smarty/plugins/function.assign_debug_info.php b/lib/smarty/plugins/function.assign_debug_info.php index 8015624b1f..654049876a 100644 --- a/lib/smarty/plugins/function.assign_debug_info.php +++ b/lib/smarty/plugins/function.assign_debug_info.php @@ -11,6 +11,7 @@ * Type: function
* Name: assign_debug_info
* Purpose: assign debug info to the template
+ * @author Monte Ohrt * @param array unused in this plugin, this plugin uses {@link Smarty::$_config}, * {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info} * @param Smarty diff --git a/lib/smarty/plugins/function.config_load.php b/lib/smarty/plugins/function.config_load.php index db7f8f6b9b..db89f638c2 100644 --- a/lib/smarty/plugins/function.config_load.php +++ b/lib/smarty/plugins/function.config_load.php @@ -13,6 +13,8 @@ * Purpose: load config file vars * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load} * (Smarty online manual) + * @author Monte Ohrt + * @author messju mohr (added use of resources) * @param array Format: *
  * array('file' => required config file name,
diff --git a/lib/smarty/plugins/function.counter.php b/lib/smarty/plugins/function.counter.php
index cfe5dd886f..1f26db5fb6 100644
--- a/lib/smarty/plugins/function.counter.php
+++ b/lib/smarty/plugins/function.counter.php
@@ -12,6 +12,7 @@
  * Type:     function
* Name: counter
* Purpose: print out a counter value + * @author Monte Ohrt * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} * (Smarty online manual) * @param array parameters diff --git a/lib/smarty/plugins/function.eval.php b/lib/smarty/plugins/function.eval.php index 3a4b8b2b8c..ff0472de25 100644 --- a/lib/smarty/plugins/function.eval.php +++ b/lib/smarty/plugins/function.eval.php @@ -14,6 +14,7 @@ * Purpose: evaluate a template variable as a template
* @link http://smarty.php.net/manual/en/language.function.eval.php {eval} * (Smarty online manual) + * @author Monte Ohrt * @param array * @param Smarty */ diff --git a/lib/smarty/plugins/function.fetch.php b/lib/smarty/plugins/function.fetch.php index f5a6987a90..81b1bfc6b9 100644 --- a/lib/smarty/plugins/function.fetch.php +++ b/lib/smarty/plugins/function.fetch.php @@ -14,6 +14,7 @@ * Purpose: fetch file, web or ftp data and display results * @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch} * (Smarty online manual) + * @author Monte Ohrt * @param array * @param Smarty * @return string|null if the assign parameter is passed, Smarty assigns the diff --git a/lib/smarty/plugins/function.html_image.php b/lib/smarty/plugins/function.html_image.php index c62b0fea69..9abae72ef7 100644 --- a/lib/smarty/plugins/function.html_image.php +++ b/lib/smarty/plugins/function.html_image.php @@ -19,9 +19,10 @@ * - width = image width (optional, default actual width) * - basedir = base directory for absolute paths, default * is environment variable DOCUMENT_ROOT + * - path_prefix = prefix for path output (optional, default empty) * - * Examples: {html_image file="images/masthead.gif"} - * Output: + * Examples: {html_image file="/images/masthead.gif"} + * Output: * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} * (Smarty online manual) * @author Monte Ohrt @@ -44,6 +45,7 @@ function smarty_function_html_image($params, &$smarty) $extra = ''; $prefix = ''; $suffix = ''; + $path_prefix = ''; $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; foreach($params as $_key => $_val) { @@ -52,6 +54,7 @@ function smarty_function_html_image($params, &$smarty) case 'height': case 'width': case 'dpi': + case 'path_prefix': case 'basedir': $$_key = $_val; break; @@ -90,15 +93,9 @@ function smarty_function_html_image($params, &$smarty) } else { $_image_path = $file; } - + if(!isset($params['width']) || !isset($params['height'])) { - if ($smarty->security && - ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && - (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && - (!smarty_core_is_secure($_params, $smarty)) ) { - $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); - - } elseif (!$_image_data = @getimagesize($_image_path)) { + if(!$_image_data = @getimagesize($_image_path)) { if(!file_exists($_image_path)) { $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); return; @@ -110,7 +107,13 @@ function smarty_function_html_image($params, &$smarty) return; } } - + if ($smarty->security && + ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && + (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && + (!smarty_core_is_secure($_params, $smarty)) ) { + $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); + } + if(!isset($params['width'])) { $width = $_image_data[0]; } @@ -131,7 +134,7 @@ function smarty_function_html_image($params, &$smarty) $height = round($height * $_resize); } - return $prefix . ''.$alt.'' . $suffix; + return $prefix . ''.$alt.'' . $suffix; } /* vim: set expandtab: */ diff --git a/lib/smarty/plugins/function.html_options.php b/lib/smarty/plugins/function.html_options.php index ae864f7327..cebadde479 100644 --- a/lib/smarty/plugins/function.html_options.php +++ b/lib/smarty/plugins/function.html_options.php @@ -21,6 +21,7 @@ * the passed parameters * @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image} * (Smarty online manual) + * @author Monte Ohrt * @param array * @param Smarty * @return string diff --git a/lib/smarty/plugins/function.html_radios.php b/lib/smarty/plugins/function.html_radios.php index dc7baee84f..7503cfaca8 100644 --- a/lib/smarty/plugins/function.html_radios.php +++ b/lib/smarty/plugins/function.html_radios.php @@ -48,6 +48,7 @@ function smarty_function_html_radios($params, &$smarty) $selected = null; $separator = ''; $labels = true; + $label_ids = false; $output = null; $extra = ''; @@ -68,6 +69,7 @@ function smarty_function_html_radios($params, &$smarty) break; case 'labels': + case 'label_ids': $$_key = (bool)$_val; break; @@ -106,13 +108,13 @@ function smarty_function_html_radios($params, &$smarty) if (isset($options)) { foreach ($options as $_key=>$_val) - $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels); + $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); } else { foreach ($values as $_i=>$_key) { $_val = isset($output[$_i]) ? $output[$_i] : ''; - $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels); + $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids); } } @@ -125,19 +127,23 @@ function smarty_function_html_radios($params, &$smarty) } -function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) { +function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) { $_output = ''; if ($labels) { - $_id = smarty_function_escape_special_chars($name . '_' . $value); - $_output .= '
!is", $source, $match); $_pre_blocks = $match[0]; - $source = preg_replace("!
.*?
!is", + $source = preg_replace("!]*?>.*?!is", '@@@SMARTY:TRIM:PRE@@@', $source); - + // Pull out the textarea blocks - preg_match_all("!]+>.*?!is", $source, $match); + preg_match_all("!]*?>.*?!is", $source, $match); $_textarea_blocks = $match[0]; - $source = preg_replace("!]+>.*?!is", + $source = preg_replace("!]*?>.*?!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source); // remove all leading spaces, tabs and carriage returns NOT // 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; } diff --git a/lib/smarty/plugins/shared.escape_special_chars.php b/lib/smarty/plugins/shared.escape_special_chars.php index 515763abed..c07ce31be2 100644 --- a/lib/smarty/plugins/shared.escape_special_chars.php +++ b/lib/smarty/plugins/shared.escape_special_chars.php @@ -12,6 +12,7 @@ * Function: smarty_function_escape_special_chars
* Purpose: used by other smarty functions to escape * special chars except for already escaped ones + * @author Monte Ohrt * @param string * @return string */ diff --git a/lib/smarty/plugins/shared.make_timestamp.php b/lib/smarty/plugins/shared.make_timestamp.php index acdd777359..b42eb11d85 100644 --- a/lib/smarty/plugins/shared.make_timestamp.php +++ b/lib/smarty/plugins/shared.make_timestamp.php @@ -10,32 +10,35 @@ * Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp * from a string. + * @author Monte Ohrt * @param string * @return string */ function smarty_make_timestamp($string) { if(empty($string)) { - $string = "now"; - } - $time = strtotime($string); - if (is_numeric($time) && $time != -1) - return $time; - - // is mysql timestamp format of YYYYMMDDHHMMSS? - if (preg_match('/^\d{14}$/', $string)) { - $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), - substr($string,4,2),substr($string,6,2),substr($string,0,4)); + // use "now": + $time = time(); - return $time; + } elseif (preg_match('/^\d{14}$/', $string)) { + // it is mysql timestamp format of YYYYMMDDHHMMSS? + $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), + substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); + + } elseif (is_numeric($string)) { + // it is a numeric string, we handle it as timestamp + $time = (int)$string; + + } else { + // strtotime should handle it + $time = strtotime($string); + if ($time == -1 || $time === false) { + // strtotime() was not able to parse $string, use "now": + $time = time(); + } } + return $time; - // couldn't recognize it, try to return a time - $time = (int) $string; - if ($time > 0) - return $time; - else - return time(); } /* vim: set expandtab: */ diff --git a/lib/smarty/readme_moodle.txt b/lib/smarty/readme_moodle.txt new file mode 100644 index 0000000000..55d37ed6b7 --- /dev/null +++ b/lib/smarty/readme_moodle.txt @@ -0,0 +1,6 @@ +Description of Smarty 2.6.26 library import + +* no changes +* please do not use Smarty in any code, we are going to remove it from distribution in Moodle 2.0 + +skodak \ No newline at end of file -- 2.39.5