onokazu
onoka****@users*****
2006年 5月 1日 (月) 11:37:25 JST
Index: xoops2jp/html/class/smarty/Config_File.class.php diff -u xoops2jp/html/class/smarty/Config_File.class.php:1.2 xoops2jp/html/class/smarty/Config_File.class.php:1.3 --- xoops2jp/html/class/smarty/Config_File.class.php:1.2 Fri Mar 18 21:51:55 2005 +++ xoops2jp/html/class/smarty/Config_File.class.php Mon May 1 11:37:25 2006 @@ -18,14 +18,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://smarty.php.net/ - * @version 2.6.5-dev - * @copyright Copyright: 2001-2004 ispi of Lincoln, Inc. + * @version 2.6.12 + * @copyright Copyright: 2001-2005 New Digital Group, Inc. * @author Andrei Zmievski <andre****@php*****> * @access public * @package Smarty */ -/* $Id: Config_File.class.php,v 1.2 2005/03/18 12:51:55 onokazu Exp $ */ +/* $Id: Config_File.class.php,v 1.3 2006/05/01 02:37:25 onokazu Exp $ */ /** * Config file reading class @@ -105,7 +105,7 @@ * @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 +285,9 @@ $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 +347,7 @@ */ 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 Index: xoops2jp/html/class/smarty/Smarty.class.php diff -u xoops2jp/html/class/smarty/Smarty.class.php:1.2 xoops2jp/html/class/smarty/Smarty.class.php:1.3 --- xoops2jp/html/class/smarty/Smarty.class.php:1.2 Fri Mar 18 21:51:55 2005 +++ xoops2jp/html/class/smarty/Smarty.class.php Mon May 1 11:37:25 2006 @@ -23,14 +23,14 @@ * smart****@lists***** * * @link http://smarty.php.net/ - * @copyright 2001-2004 ispi of Lincoln, Inc. - * @author Monte Ohrt <monte****@ispi*****> + * @copyright 2001-2005 New Digital Group, Inc. + * @author Monte Ohrt <monte at ohrt dot com> * @author Andrei Zmievski <andre****@php*****> * @package Smarty - * @version 2.6.5-dev + * @version 2.6.12 */ -/* $Id: Smarty.class.php,v 1.2 2005/03/18 12:51:55 onokazu Exp $ */ +/* $Id: Smarty.class.php,v 1.3 2006/05/01 02:37:25 onokazu Exp $ */ /** * DIR_SEP isn't used anymore, but third party apps might @@ -49,6 +49,10 @@ define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); } +if (!defined('SMARTY_CORE_DIR')) { + define('SMARTY_CORE_DIR', SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR); +} + define('SMARTY_PHP_PASSTHRU', 0); define('SMARTY_PHP_QUOTE', 1); define('SMARTY_PHP_REMOVE', 2); @@ -228,7 +232,7 @@ 'isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', - 'true','false'), + 'true', 'false', 'null'), 'INCLUDE_ANY' => false, 'PHP_TAGS' => false, 'MODIFIER_FUNCS' => array('count'), @@ -460,7 +464,7 @@ * * @var string */ - var $_version = '2.6.5-dev'; + var $_version = '2.6.12'; /** * current template inclusion depth @@ -910,7 +914,7 @@ switch ($type) { case 'output': $_params = array('plugins' => array(array($type . 'filter', $name, null, null, false))); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); smarty_core_load_plugins($_params, $this); break; @@ -950,7 +954,7 @@ 'auto_source' => $tpl_file, 'auto_id' => $_auto_id, 'exp_time' => $exp_time); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php'); + require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); return smarty_core_rm_auto($_params, $this); } @@ -990,7 +994,7 @@ 'cache_id' => $cache_id, 'compile_id' => $compile_id ); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php'); + require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); return smarty_core_read_cache_file($_params, $this); } @@ -1024,7 +1028,7 @@ 'auto_id' => $compile_id, 'exp_time' => $exp_time, 'extensions' => array('.inc', '.php')); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rm_auto.php'); + require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); return smarty_core_rm_auto($_params, $this); } @@ -1051,9 +1055,12 @@ { 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; } } @@ -1070,6 +1077,10 @@ 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; } } @@ -1128,15 +1139,14 @@ $this->debugging = true; } } else { - $_cookie_var = $this->request_use_auto_globals ? $_COOKIE['SMARTY_DEBUG'] : $GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']; - $this->debugging = $_cookie_var ? true : false; + $this->debugging = (bool)($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); } } if ($this->debugging) { // capture time for debugging info $_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, $this); $this->_smarty_debug_info[] = array('type' => 'template', 'filename' => $resource_name, @@ -1161,20 +1171,20 @@ 'compile_id' => $compile_id, 'results' => null ); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.read_cache_file.php'); + require_once(SMARTY_CORE_DIR . 'core.read_cache_file.php'); if (smarty_core_read_cache_file($_params, $this)) { $_smarty_results = $_params['results']; - if (@count($this->_cache_info['insert_tags'])) { + if (!empty($this->_cache_info['insert_tags'])) { $_params = array('plugins' => $this->_cache_info['insert_tags']); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); smarty_core_load_plugins($_params, $this); $_params = array('results' => $_smarty_results); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php'); + require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); $_smarty_results = smarty_core_process_cached_inserts($_params, $this); } - if (@count($this->_cache_info['cache_serials'])) { + if (!empty($this->_cache_info['cache_serials'])) { $_params = array('results' => $_smarty_results); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_compiled_include.php'); + require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php'); $_smarty_results = smarty_core_process_compiled_include($_params, $this); } @@ -1184,9 +1194,9 @@ { // capture time for debugging info $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time; - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php'); + require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); $_smarty_results .= smarty_core_display_debug_console($_params, $this); } if ($this->cache_modified_check) { @@ -1267,9 +1277,9 @@ 'cache_id' => $cache_id, 'compile_id' => $compile_id, 'results' => $_smarty_results); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_cache_file.php'); + require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php'); smarty_core_write_cache_file($_params, $this); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.process_cached_inserts.php'); + require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php'); $_smarty_results = smarty_core_process_cached_inserts($_params, $this); if ($this->_cache_serials) { @@ -1288,9 +1298,9 @@ if ($this->debugging) { // capture time for debugging info $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.display_debug_console.php'); + require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); echo smarty_core_display_debug_console($_params, $this); } error_reporting($_smarty_old_error_level); @@ -1356,7 +1366,7 @@ function _get_plugin_filepath($type, $name) { $_params = array('type' => $type, 'name' => $name); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assemble_plugin_filepath.php'); + require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php'); return smarty_core_assemble_plugin_filepath($_params, $this); } @@ -1414,12 +1424,12 @@ if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) { // if a _cache_serial was set, we also have to write an include-file: if ($this->_cache_include_info) { - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php'); - smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)), $this); + require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php'); + smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)), $this); } $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php'); + require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); smarty_core_write_compiled_resource($_params, $this); return true; @@ -1472,7 +1482,9 @@ $smarty_compiler->_config = $this->_config; $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; - $smarty_compiler->_cache_serial = null; + if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { + $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; + } $smarty_compiler->_cache_include = $cache_include_path; @@ -1579,7 +1591,7 @@ $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"'); } } else if ($_return && $this->security) { - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php'); + require_once(SMARTY_CORE_DIR . 'core.is_secure.php'); if (!smarty_core_is_secure($_params, $this)) { if (!$params['quiet']) $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed'); @@ -1635,7 +1647,7 @@ } // didn't find the file, try include_path $_params = array('file_path' => $_fullpath); - 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, $this)) { $params['resource_name'] = $_params['new_file_path']; return true; @@ -1648,7 +1660,7 @@ } } elseif (empty($this->_plugins['resource'][$params['resource_type']])) { $_params = array('type' => $params['resource_type']); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_resource_plugin.php'); + require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php'); smarty_core_load_resource_plugin($_params, $this); } @@ -1686,8 +1698,8 @@ */ 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; @@ -1695,18 +1707,18 @@ /** - * read in a file from line $start for $lines. - * read the entire file if $start and $lines are null. + * read in a file * * @param string $filename - * @param integer $start - * @param integer $lines * @return string */ function _read_file($filename) { if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) { - $contents = ($size = filesize($filename)) ? fread($fd, $size) : ''; + $contents = ''; + while (!feof($fd)) { + $contents .= fread($fd, 8192); + } fclose($fd); return $contents; } else { @@ -1836,7 +1848,7 @@ { if ($this->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, $this); $this->_smarty_debug_info[] = array('type' => 'template', 'filename' => $params['smarty_include_tpl_file'], @@ -1867,7 +1879,7 @@ if ($this->debugging) { // capture time for debugging info $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; } @@ -1887,7 +1899,7 @@ if ($this->_cache_including) { /* return next set of cache_attrs */ - $_return =& current($_cache_attrs); + $_return = current($_cache_attrs); next($_cache_attrs); return $_return; Index: xoops2jp/html/class/smarty/Smarty_Compiler.class.php diff -u xoops2jp/html/class/smarty/Smarty_Compiler.class.php:1.2 xoops2jp/html/class/smarty/Smarty_Compiler.class.php:1.3 --- xoops2jp/html/class/smarty/Smarty_Compiler.class.php:1.2 Fri Mar 18 21:51:55 2005 +++ xoops2jp/html/class/smarty/Smarty_Compiler.class.php Mon May 1 11:37:25 2006 @@ -19,14 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @link http://smarty.php.net/ - * @author Monte Ohrt <monte****@ispi*****> + * @author Monte Ohrt <monte at ohrt dot com> * @author Andrei Zmievski <andre****@php*****> - * @version 2.6.5-dev - * @copyright 2001-2004 ispi of Lincoln, Inc. + * @version 2.6.12 + * @copyright 2001-2005 New Digital Group, Inc. * @package Smarty */ -/* $Id: Smarty_Compiler.class.php,v 1.2 2005/03/18 12:51:55 onokazu Exp $ */ +/* $Id: Smarty_Compiler.class.php,v 1.3 2006/05/01 02:37:25 onokazu Exp $ */ /** * Template compiling class @@ -49,7 +49,9 @@ var $_si_qstr_regexp = null; var $_qstr_regexp = null; var $_func_regexp = null; + var $_reg_obj_regexp = null; var $_var_bracket_regexp = null; + var $_num_const_regexp = null; var $_dvar_guts_regexp = null; var $_dvar_regexp = null; var $_cvar_regexp = null; @@ -101,7 +103,7 @@ // 30 // -12 // 13.22 - $this->_num_const_regexp = '\-?\d+(?:\.\d+)?'; + $this->_num_const_regexp = '(?:\-?\d+(?:\.\d+)?)'; // matches $ vars (not objects): // $foo @@ -137,7 +139,7 @@ // #foo# // "text" // "text" - $this->_var_regexp = '(?:' . $this->_avar_regexp . '|' . $this->_num_const_regexp . '|' . $this->_qstr_regexp . ')'; + $this->_var_regexp = '(?:' . $this->_avar_regexp . '|' . $this->_qstr_regexp . ')'; // matches valid object call (one level of object nesting allowed in parameters): // $foo->bar @@ -152,8 +154,8 @@ // $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar)) $this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')'; $this->_obj_restricted_param_regexp = '(?:' - . $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp - . '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)'; + . '(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')(?:' . $this->_obj_ext_regexp . '(?:\((?:(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . ')' + . '(?:\s*,\s*(?:' . $this->_var_regexp . '|' . $this->_num_const_regexp . '))*)?\))?)*)'; $this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|' . $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)'; $this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp @@ -169,7 +171,7 @@ // |foo:"bar":$foobar // |foo|bar // |foo:$foo->bar - $this->_mod_regexp = '(?:\|@?\w+(?::(?>-?\w+|' + $this->_mod_regexp = '(?:\|@?\w+(?::(?:\w+|' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; // matches valid function name: @@ -191,7 +193,7 @@ // "text"|bar // $foo->bar $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' - . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; + . $this->_var_regexp . '|' . $this->_num_const_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; // matches valid parenthesised function parameters: // @@ -316,6 +318,36 @@ return; } + /* Reformat $text_blocks between 'strip' and '/strip' tags, + removing spaces, tabs and newlines. */ + $strip = false; + for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { + if ($compiled_tags[$i] == '{strip}') { + $compiled_tags[$i] = ''; + $strip = true; + /* remove leading whitespaces */ + $text_blocks[$i + 1] = ltrim($text_blocks[$i + 1]); + } + if ($strip) { + /* strip all $text_blocks before the next '/strip' */ + for ($j = $i + 1; $j < $for_max; $j++) { + /* remove leading and trailing whitespaces of each line */ + $text_blocks[$j] = preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $text_blocks[$j]); + if ($compiled_tags[$j] == '{/strip}') { + /* remove trailing whitespaces from the last text_block */ + $text_blocks[$j] = rtrim($text_blocks[$j]); + } + $text_blocks[$j] = "<?php echo '" . strtr($text_blocks[$j], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>"; + if ($compiled_tags[$j] == '{/strip}') { + $compiled_tags[$j] = "\n"; /* slurped by php, but necessary + if a newline is following the closing strip-tag */ + $strip = false; + $i = $j; + break; + } + } + } + } $compiled_content = ''; /* Interleave the compiled contents and text blocks to get the final result. */ @@ -328,19 +360,8 @@ } $compiled_content .= $text_blocks[$i]; - /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */ - if (preg_match_all("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s", $compiled_content, $_match)) { - $strip_tags = $_match[0]; - $strip_tags_modified = preg_replace("~{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+~m", '', $strip_tags); - $strip_tags_modified = preg_replace('~[\r\n]+~m', '', $strip_tags_modified); - for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++) - $compiled_content = preg_replace("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s", - $this->_quote_replace($strip_tags_modified[$i]), - $compiled_content, 1); - } - // remove \n from the end of the file, if any - if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) { + if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { $compiled_content = substr($compiled_content, 0, -1); } @@ -375,19 +396,19 @@ $_plugins_params = "array('plugins' => array("; foreach ($this->_plugin_info as $plugin_type => $plugins) { foreach ($plugins as $plugin_name => $plugin_info) { - $_plugins_params .= "array('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], "; + $_plugins_params .= "array('$plugin_type', '$plugin_name', '" . strtr($plugin_info[0], array("'" => "\\'", "\\" => "\\\\")) . "', $plugin_info[1], "; $_plugins_params .= $plugin_info[2] ? 'true),' : 'false),'; } } $_plugins_params .= '))'; - $plugins_code = "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');\nsmarty_core_load_plugins($_plugins_params, \$this); ?>\n"; + $plugins_code = "<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');\nsmarty_core_load_plugins($_plugins_params, \$this); ?>\n"; $template_header .= $plugins_code; $this->_plugin_info = array(); $this->_plugins_code = $plugins_code; } if ($this->_init_smarty_vars) { - $template_header .= "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assign_smarty_interface.php');\nsmarty_core_assign_smarty_interface(null, \$this); ?>\n"; + $template_header .= "<?php require_once(SMARTY_CORE_DIR . 'core.assign_smarty_interface.php');\nsmarty_core_assign_smarty_interface(null, \$this); ?>\n"; $this->_init_smarty_vars = false; } @@ -404,7 +425,7 @@ 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. */ @@ -421,12 +442,8 @@ if (preg_match('~^' . $this->_num_const_regexp . '|' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$~', $tag_command)) { /* tag name is a variable or object */ - $_return = $this->_parse_var_props($tag_command . $tag_modifier, $this->_parse_attrs($tag_args)); - if(isset($_tag_attrs['assign'])) { - return "<?php \$this->assign('" . $this->_dequote($_tag_attrs['assign']) . "', $_return ); ?>\n"; - } else { - return "<?php echo $_return; ?>" . $this->_additional_newline; - } + $_return = $this->_parse_var_props($tag_command . $tag_modifier); + return "<?php echo $_return; ?>" . $this->_additional_newline; } /* If the tag name is a registered object, we process it. */ @@ -500,29 +517,29 @@ case 'foreachelse': $this->_push_tag('foreachelse'); - return "<?php endforeach; unset(\$_from); else: ?>"; + return "<?php endforeach; else: ?>"; case '/foreach': $_open_tag = $this->_pop_tag('foreach'); if ($_open_tag == 'foreachelse') - return "<?php endif; ?>"; + return "<?php endif; unset(\$_from); ?>"; else - return "<?php endforeach; unset(\$_from); endif; ?>"; + return "<?php endforeach; endif; unset(\$_from); ?>"; break; 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"; - return $this->left_delimiter.$tag_command.$this->right_delimiter; + return '{' . $tag_command . '}'; } } else { $this->_push_tag('strip'); if ($this->_strip_depth++==0) { /* outermost opening {strip} */ $this->_additional_newline = ""; - return $this->left_delimiter.$tag_command.$this->right_delimiter; + return '{' . $tag_command . '}'; } } return ''; @@ -647,7 +664,7 @@ */ 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 @@ -709,17 +726,18 @@ if ($start_tag) { $output = '<?php ' . $this->_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 = '<?php $this->_block_content = ob_get_contents(); ob_end_clean(); '; - $_out_tag_text = $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat=false)'; + $output = '<?php $_block_content = ob_get_contents(); ob_end_clean(); '; + $_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) . '?>'; } @@ -784,7 +802,8 @@ $_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 != '') { @@ -809,7 +828,7 @@ */ 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,13 +876,13 @@ // 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 = "\$this->_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], \$this->_obj_block_content, \$this, \$_block_repeat=false)"; + $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); "; + $return = "\$_block_repeat=false; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat)"; $postfix = "} array_pop(\$this->_tag_stack);"; } } else { @@ -924,7 +943,7 @@ $_params = "array('args' => array(".implode(', ', (array)$arg_list)."))"; - return "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>" . $this->_additional_newline; + return "<?php require_once(SMARTY_CORE_DIR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>" . $this->_additional_newline; } /** @@ -1008,7 +1027,7 @@ $_params = "array('smarty_file' => " . $attrs['file'] . ", 'smarty_assign' => '$assign_var', 'smarty_once' => $once_var, 'smarty_include_vars' => array(".implode(',', $arg_list)."))"; - return "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>" . $this->_additional_newline; + return "<?php require_once(SMARTY_CORE_DIR . 'core.smarty_include_php.php');\nsmarty_core_smarty_include_php($_params, \$this); ?>" . $this->_additional_newline; } @@ -1159,19 +1178,15 @@ } $output = '<?php '; + $output .= "\$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array'); }"; if (isset($name)) { $foreach_props = "\$this->_foreach[$name]"; - $output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n"; - $output .= "{$foreach_props}['total'] = count(\$_from = (array)$from);\n"; - $output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n"; - $output .= "if ({$foreach_props}['show']):\n"; - $output .= "{$foreach_props}['iteration'] = 0;\n"; + $output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n"; + $output .= "if ({$foreach_props}['total'] > 0):\n"; $output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n"; $output .= " {$foreach_props}['iteration']++;\n"; - $output .= " {$foreach_props}['first'] = ({$foreach_props}['iteration'] == 1);\n"; - $output .= " {$foreach_props}['last'] = ({$foreach_props}['iteration'] == {$foreach_props}['total']);\n"; } else { - $output .= "if (count(\$_from = (array)$from)):\n"; + $output .= "if (count(\$_from)):\n"; $output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n"; } $output .= '?>'; @@ -1237,6 +1252,13 @@ $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[')']) { @@ -1359,6 +1381,9 @@ !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) && (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)) { // object or variable $token = $this->_parse_var_props($token); @@ -1528,7 +1553,7 @@ $token = 'false'; } else if ($token == 'null') { $token = 'null'; - } else if (preg_match('~^-?([0-9]+|0[xX][0-9a-fA-F]+)$~', $token)) { + } else if (preg_match('~^' . $this->_num_const_regexp . '|0[xX][0-9a-fA-F]+$~', $token)) { /* treat integer literally */ } else if (!preg_match('~^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')*$~', $token)) { /* treat as a string, double-quote it escaping quotes */ @@ -1627,7 +1652,7 @@ } 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; } @@ -1641,7 +1666,7 @@ function _expand_quoted_text($var_expr) { // if contains unescaped $, expand it - if(preg_match_all('~(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) { + if(preg_match_all('~(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '(?:' . $this->_obj_ext_regexp . ')*\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)~', $var_expr, $_match)) { $_match = $_match[0]; rsort($_match); reset($_match); @@ -1707,7 +1732,7 @@ } // prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit) - if(is_numeric($var_expr{0})) + if(is_numeric(substr($var_expr, 0, 1))) $_var_ref = $var_expr; else $_var_ref = substr($var_expr, 1); @@ -1733,7 +1758,7 @@ $_var_name = substr(array_shift($_indexes), 1); $_output = "\$this->_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) { @@ -1746,11 +1771,11 @@ } 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 { @@ -1762,8 +1787,8 @@ $_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) . "']"; @@ -1772,7 +1797,7 @@ $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 { @@ -1781,7 +1806,7 @@ } else { $_output .= $_index; } - } elseif ($_index{0} == '(') { + } elseif (substr($_index, 0, 1) == '(') { $_index = $this->_parse_parenth_args($_index); $_output .= $_index; } else { @@ -1878,7 +1903,7 @@ 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 { @@ -1900,10 +1925,10 @@ 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]; } } @@ -1955,7 +1980,7 @@ /* 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__); } } @@ -1967,13 +1992,41 @@ break; case 'foreach': + array_shift($indexes); + $_var = $this->_parse_var_props(substr($indexes[0], 1)); + $_propname = substr($indexes[1], 1); + $_max_index = 1; + switch ($_propname) { + case 'index': + array_shift($indexes); + $compiled_ref = "(\$this->_foreach[$_var]['iteration']-1)"; + break; + + case 'first': + array_shift($indexes); + $compiled_ref = "(\$this->_foreach[$_var]['iteration'] <= 1)"; + break; + + case 'last': + array_shift($indexes); + $compiled_ref = "(\$this->_foreach[$_var]['iteration'] == \$this->_foreach[$_var]['total'])"; + break; + + case 'show': + array_shift($indexes); + $compiled_ref = "(\$this->_foreach[$_var]['total'] > 0)"; + break; + + default: + unset($_max_index); + $compiled_ref = "\$this->_foreach[$_var]"; + } + break; + case 'section': array_shift($indexes); $_var = $this->_parse_var_props(substr($indexes[0], 1)); - if ($_ref == 'foreach') - $compiled_ref = "\$this->_foreach[$_var]"; - else - $compiled_ref = "\$this->_sections[$_var]"; + $compiled_ref = "\$this->_sections[$_var]"; break; case 'get': @@ -2033,8 +2086,12 @@ return; } array_shift($indexes); - $_val = $this->_parse_var_props(substr($indexes[0],1)); - $compiled_ref = '@constant(' . $_val . ')'; + if (preg_match('!^\.\w+$!', $indexes[0])) { + $compiled_ref = '@' . substr($indexes[0], 1); + } else { + $_val = $this->_parse_var_props(substr($indexes[0], 1)); + $compiled_ref = '@constant(' . $_val . ')'; + } $_max_index = 1; break; @@ -2105,7 +2162,7 @@ if ($prefilter === false) { unset($this->_plugins['prefilter'][$filter_name]); $_params = array('plugins' => array(array('prefilter', $filter_name, null, null, false))); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); smarty_core_load_plugins($_params, $this); } } @@ -2115,7 +2172,7 @@ if ($postfilter === false) { unset($this->_plugins['postfilter'][$filter_name]); $_params = array('plugins' => array(array('postfilter', $filter_name, null, null, false))); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php'); + require_once(SMARTY_CORE_DIR . 'core.load_plugins.php'); smarty_core_load_plugins($_params, $this); } } @@ -2159,9 +2216,9 @@ if ($_cacheable || 0<$this->_cacheable_state++) return ''; if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty')); - $_ret = 'if ($this->caching) { echo \'{nocache:' + $_ret = 'if ($this->caching && !$this->_cache_including) { echo \'{nocache:' . $this->_cache_serial . '#' . $this->_nocache_count - . '}\';}'; + . '}\'; };'; return $_ret; } @@ -2176,9 +2233,9 @@ $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4]; if ($_cacheable || --$this->_cacheable_state>0) return ''; - return 'if ($this->caching) { echo \'{/nocache:' + return 'if ($this->caching && !$this->_cache_including) { echo \'{/nocache:' . $this->_cache_serial . '#' . ($this->_nocache_count++) - . '}\';}'; + . '}\'; };'; } Index: xoops2jp/html/class/smarty/debug.tpl diff -u xoops2jp/html/class/smarty/debug.tpl:1.2 xoops2jp/html/class/smarty/debug.tpl:1.3 --- xoops2jp/html/class/smarty/debug.tpl:1.2 Fri Mar 18 21:51:55 2005 +++ xoops2jp/html/class/smarty/debug.tpl Mon May 1 11:37:25 2006 @@ -36,7 +36,7 @@ var title = 'Console_' + self.name; {rdelim} _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); - _smarty_console.document.write("<HTML><TITLE>Smarty Debug Console_"+self.name+"</TITLE><BODY bgcolor=#ffffff>"); + _smarty_console.document.write("<HTML><HEAD><TITLE>Smarty Debug Console_"+self.name+"</TITLE></HEAD><BODY bgcolor=#ffffff>"); _smarty_console.document.write("<table border=0 width=100%>"); _smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>"); _smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates & config files (load time in seconds):</b></td></tr>");