| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2001-03-07 04:52:27 +00:00
										 |  |  |  * Project:     Smarty: the PHP compiling template engine | 
					
						
							|  |  |  |  * File:        Smarty_Compiler.class.php | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You may contact the authors of Smarty by e-mail at: | 
					
						
							|  |  |  |  * monte@ispi.net | 
					
						
							| 
									
										
										
										
											2001-04-25 15:49:51 +00:00
										 |  |  |  * andrei@php.net | 
					
						
							| 
									
										
										
										
											2001-03-07 04:52:27 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Or, write to: | 
					
						
							|  |  |  |  * Monte Ohrt | 
					
						
							| 
									
										
										
										
											2001-10-10 23:58:36 +00:00
										 |  |  |  * Director of Technology, ispi | 
					
						
							| 
									
										
										
										
											2001-03-07 04:52:27 +00:00
										 |  |  |  * 237 S. 70th suite 220 | 
					
						
							|  |  |  |  * Lincoln, NE 68510 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The latest version of Smarty can be obtained from: | 
					
						
							|  |  |  |  * http://www.phpinsider.com/ | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |  * @link http://www.phpinsider.com/ | 
					
						
							|  |  |  |  * @author Monte Ohrt <monte@ispi.net> | 
					
						
							|  |  |  |  * @author Andrei Zmievski <andrei@php.net> | 
					
						
							| 
									
										
										
										
											2003-04-11 13:40:40 +00:00
										 |  |  |  * @version 2.5.0 | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |  * @copyright 2001,2002 ispi of Lincoln, Inc. | 
					
						
							|  |  |  |  * @package Smarty | 
					
						
							| 
									
										
										
										
											2001-03-07 04:52:27 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-01 15:23:16 +00:00
										 |  |  | /* $Id$ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | class Smarty_Compiler extends Smarty { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // internal vars
 | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |     /**#@+
 | 
					
						
							|  |  |  |      * @access private | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     var $_sectionelse_stack     =   array();    // keeps track of whether section had 'else' part
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |     var $_foreachelse_stack     =   array();    // keeps track of whether foreach had 'else' part
 | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     var $_literal_blocks        =   array();    // keeps literal template blocks
 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |     var $_php_blocks            =   array();    // keeps php code blocks
 | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     var $_current_file          =   null;       // the current template being compiled
 | 
					
						
							|  |  |  |     var $_current_line_no       =   1;          // line number for error messages
 | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |     var $_capture_stack         =   array();    // keeps track of nested capture buffers
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |     var $_plugin_info           =   array();    // keeps track of plugins to load
 | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |     var $_init_smarty_vars      =   false; | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  | 	var $_permitted_tokens		=	array('true','false','yes','no','on','off','null'); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |     var $_db_qstr_regexp		=	null;		// regexps are setup in the constructor
 | 
					
						
							|  |  |  |     var $_si_qstr_regexp		=	null; | 
					
						
							|  |  |  |     var $_qstr_regexp			=	null; | 
					
						
							|  |  |  |     var $_func_regexp			=	null; | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  |     var $_var_bracket_regexp	=	null; | 
					
						
							| 
									
										
										
										
											2003-02-03 15:46:11 +00:00
										 |  |  |     var $_dvar_guts_regexp		=	null; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |     var $_dvar_regexp			=	null; | 
					
						
							|  |  |  |     var $_cvar_regexp			=	null; | 
					
						
							|  |  |  |     var $_svar_regexp			=	null; | 
					
						
							|  |  |  |     var $_avar_regexp			=	null; | 
					
						
							|  |  |  |     var $_mod_regexp			=	null; | 
					
						
							|  |  |  |     var $_var_regexp			=	null; | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  |     var $_parenth_param_regexp	=	null; | 
					
						
							|  |  |  | 	var $_func_call_regexp		=	null; | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 	var $_obj_ext_regexp		=	null; | 
					
						
							|  |  |  | 	var $_obj_start_regexp		=	null; | 
					
						
							|  |  |  | 	var $_obj_params_regexp		=	null; | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 	var $_obj_call_regexp		=	null; | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |     /**#@-*/ | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * The class constructor. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |     function Smarty_Compiler() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 		// matches double quoted strings:
 | 
					
						
							|  |  |  | 		// "foobar"
 | 
					
						
							|  |  |  | 		// "foo\"bar"
 | 
					
						
							|  |  |  |     	$this->_db_qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// matches single quoted strings:
 | 
					
						
							|  |  |  | 		// 'foobar'
 | 
					
						
							|  |  |  | 		// 'foo\'bar'
 | 
					
						
							|  |  |  |     	$this->_si_qstr_regexp = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// matches single or double quoted strings
 | 
					
						
							|  |  |  |     	$this->_qstr_regexp = '(?:' . $this->_db_qstr_regexp . '|' . $this->_si_qstr_regexp . ')'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 		// matches bracket portion of vars
 | 
					
						
							|  |  |  | 		// [0]
 | 
					
						
							|  |  |  | 		// [foo]
 | 
					
						
							|  |  |  | 		// [$bar]
 | 
					
						
							|  |  |  | 		$this->_var_bracket_regexp = '\[\$?[\w\.]+\]'; | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// matches $ vars (not objects):
 | 
					
						
							| 
									
										
										
										
											2003-02-03 15:46:11 +00:00
										 |  |  | 		// $foo
 | 
					
						
							|  |  |  | 		// $foo.bar
 | 
					
						
							|  |  |  | 		// $foo.bar.foobar
 | 
					
						
							|  |  |  | 		// $foo[0]
 | 
					
						
							|  |  |  | 		// $foo[$bar]
 | 
					
						
							|  |  |  | 		// $foo[5][blah]
 | 
					
						
							|  |  |  | 		// $foo[5].bar[$foobar][4]
 | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 		$this->_dvar_guts_regexp = '\w+(?:' . $this->_var_bracket_regexp | 
					
						
							|  |  |  | 				. ')*(?:\.\$?\w+(?:' . $this->_var_bracket_regexp . ')*)*'; | 
					
						
							| 
									
										
										
										
											2003-02-03 15:39:47 +00:00
										 |  |  | 		$this->_dvar_regexp = '\$' . $this->_dvar_guts_regexp; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// matches config vars:
 | 
					
						
							|  |  |  | 		// #foo#
 | 
					
						
							|  |  |  | 		// #foobar123_foo#
 | 
					
						
							|  |  |  | 		$this->_cvar_regexp = '\#\w+\#'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// matches section vars:
 | 
					
						
							|  |  |  | 		// %foo.bar%
 | 
					
						
							|  |  |  | 		$this->_svar_regexp = '\%\w+\.\w+\%'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// matches all valid variables (no quotes, no modifiers)
 | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  | 		$this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' | 
					
						
							|  |  |  | 		   . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		// matches valid variable syntax:
 | 
					
						
							|  |  |  | 		// $foo
 | 
					
						
							|  |  |  | 		// $foo
 | 
					
						
							|  |  |  | 		// #foo#
 | 
					
						
							|  |  |  | 		// #foo#
 | 
					
						
							|  |  |  | 		// "text"
 | 
					
						
							|  |  |  | 		// "text"
 | 
					
						
							|  |  |  | 		$this->_var_regexp = '(?:' . $this->_avar_regexp . '|' . $this->_qstr_regexp . ')'; | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 		// matches valid object call (no objects allowed in parameters):
 | 
					
						
							|  |  |  | 		// $foo->bar
 | 
					
						
							|  |  |  | 		// $foo->bar()
 | 
					
						
							|  |  |  | 		// $foo->bar("text")
 | 
					
						
							|  |  |  | 		// $foo->bar($foo, $bar, "text")
 | 
					
						
							| 
									
										
										
										
											2003-02-12 22:34:05 +00:00
										 |  |  | 		// $foo->bar($foo, "foo")
 | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 		// $foo->bar->foo()
 | 
					
						
							|  |  |  | 		// $foo->bar->foo->bar()
 | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 		$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')'; | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  |     	$this->_obj_params_regexp = '\((?:\w+|' | 
					
						
							| 
									
										
										
										
											2003-02-12 22:34:05 +00:00
										 |  |  | 				. $this->_var_regexp . '(?:\s*,\s*(?:(?:\w+|' | 
					
						
							|  |  |  | 				. $this->_var_regexp . ')))*)?\)';		 | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  |     	$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)'; | 
					
						
							|  |  |  | 		$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?)'; | 
					
						
							| 
									
										
										
										
											2003-02-12 22:34:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// matches valid modifier syntax:
 | 
					
						
							|  |  |  | 		// |foo
 | 
					
						
							|  |  |  | 		// |@foo
 | 
					
						
							|  |  |  | 		// |foo:"bar"
 | 
					
						
							|  |  |  | 		// |foo:$bar
 | 
					
						
							|  |  |  | 		// |foo:"bar":$foobar
 | 
					
						
							|  |  |  | 		// |foo|bar
 | 
					
						
							|  |  |  | 		// |foo:$foo->bar
 | 
					
						
							|  |  |  | 		$this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' | 
					
						
							|  |  |  | 		   . $this->_obj_call_regexp . '|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)';		 | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		// matches valid function name:
 | 
					
						
							|  |  |  | 		// foo123
 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// _foo_bar
 | 
					
						
							| 
									
										
										
										
											2002-12-20 17:25:01 +00:00
										 |  |  | 		$this->_func_regexp = '[a-zA-Z_]\w*'; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// matches valid registered object:
 | 
					
						
							| 
									
										
										
										
											2003-02-13 15:28:14 +00:00
										 |  |  | 		// foo->bar
 | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 		$this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// matches valid parameter values:
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		// true
 | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		// $foo
 | 
					
						
							|  |  |  | 		// $foo|bar
 | 
					
						
							|  |  |  | 		// #foo#
 | 
					
						
							|  |  |  | 		// #foo#|bar
 | 
					
						
							|  |  |  | 		// "text"
 | 
					
						
							|  |  |  | 		// "text"|bar
 | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 		// $foo->bar
 | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  | 		$this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' | 
					
						
							|  |  |  | 		   . $this->_var_regexp  . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';		 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// matches valid parenthesised function parameters:
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		// 
 | 
					
						
							|  |  |  | 		// "text"
 | 
					
						
							|  |  |  | 		//	$foo, $bar, "text"
 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// $foo|bar, "foo"|bar, $foo->bar($foo)|bar
 | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  |     	$this->_parenth_param_regexp = '(?:\((?:\w+|' | 
					
						
							|  |  |  | 				. $this->_param_regexp . '(?:\s*,\s*(?:(?:\w+|' | 
					
						
							|  |  |  | 				. $this->_param_regexp . ')))*)?\))'; | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 		// matches valid function call:
 | 
					
						
							|  |  |  | 		// foo()
 | 
					
						
							|  |  |  | 		// foo_bar($foo)
 | 
					
						
							|  |  |  | 		// _foo_bar($foo,"bar")
 | 
					
						
							|  |  |  | 		// foo123($foo,$foo->bar(),"foo")
 | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  |     	$this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' | 
					
						
							|  |  |  | 		   . $this->_parenth_param_regexp . '))';		 | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 	}			 | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile a template file | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |      * sets $template_compiled to the compiled source | 
					
						
							|  |  |  | 	 * @param string $tpl_file | 
					
						
							|  |  |  | 	 * @param string $template_source | 
					
						
							|  |  |  | 	 * @param string $template_compiled | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |     function _compile_file($tpl_file, $template_source, &$template_compiled) | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-06-19 15:30:29 +00:00
										 |  |  |         if ($this->security) { | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             // do not allow php syntax to be executed unless specified
 | 
					
						
							|  |  |  |             if ($this->php_handling == SMARTY_PHP_ALLOW && | 
					
						
							|  |  |  |                 !$this->security_settings['PHP_HANDLING']) { | 
					
						
							|  |  |  |                 $this->php_handling = SMARTY_PHP_PASSTHRU; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-16 20:04:06 +00:00
										 |  |  |         $this->_load_filters(); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-21 16:24:43 +00:00
										 |  |  |         $this->_current_file = $tpl_file; | 
					
						
							|  |  |  |         $this->_current_line_no = 1; | 
					
						
							|  |  |  |         $ldq = preg_quote($this->left_delimiter, '!'); | 
					
						
							|  |  |  |         $rdq = preg_quote($this->right_delimiter, '!'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-28 21:39:57 +00:00
										 |  |  |         // run template source through prefilter functions
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         if (count($this->_plugins['prefilter']) > 0) { | 
					
						
							|  |  |  |             foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { | 
					
						
							| 
									
										
										
										
											2002-04-05 17:16:52 +00:00
										 |  |  |                 if ($prefilter === false) continue; | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |                 if ($prefilter[3] || function_exists($prefilter[0])) { | 
					
						
							|  |  |  |                     $template_source = $prefilter[0]($template_source, $this); | 
					
						
							|  |  |  |                     $this->_plugins['prefilter'][$filter_name][3] = true; | 
					
						
							| 
									
										
										
										
											2001-04-19 21:08:17 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2003-01-25 20:31:45 +00:00
										 |  |  |                     $this->_trigger_fatal_error("[plugin] prefilter '$filter_name' is not implemented"); | 
					
						
							| 
									
										
										
										
											2001-04-19 21:08:17 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-04-24 16:43:05 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-04-19 21:08:17 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |         /* Annihilate the comments. */ | 
					
						
							| 
									
										
										
										
											2001-09-25 21:34:08 +00:00
										 |  |  |         $template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se", | 
					
						
							|  |  |  |                                         "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'", | 
					
						
							|  |  |  |                                         $template_source); | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Pull out the literal blocks. */ | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         preg_match_all("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", $template_source, $match); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $this->_literal_blocks = $match[1]; | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         $template_source = preg_replace("!{$ldq}literal{$rdq}(.*?){$ldq}/literal{$rdq}!s", | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                                         $this->quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $template_source); | 
					
						
							| 
									
										
										
										
											2001-04-26 17:27:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Pull out the php code blocks. */ | 
					
						
							|  |  |  |         preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $template_source, $match); | 
					
						
							|  |  |  |         $this->_php_blocks = $match[1]; | 
					
						
							|  |  |  |         $template_source = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  |                                         $this->quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $template_source); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Gather all template tags. */ | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $template_source, $match); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $template_tags = $match[1]; | 
					
						
							|  |  |  |         /* Split content by template tags to obtain non-template content. */ | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); | 
					
						
							| 
									
										
										
										
											2003-01-30 16:09:53 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* loop through text blocks */ | 
					
						
							| 
									
										
										
										
											2002-06-03 16:05:33 +00:00
										 |  |  |         for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { | 
					
						
							| 
									
										
										
										
											2003-01-30 16:09:53 +00:00
										 |  |  |             /* match anything resembling php tags */ | 
					
						
							|  |  |  |             if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { | 
					
						
							|  |  |  | 				/* replace tags with placeholders to prevent recursive replacements */ | 
					
						
							| 
									
										
										
										
											2003-01-30 16:48:55 +00:00
										 |  |  | 				$sp_match[1] = array_unique($sp_match[1]); | 
					
						
							|  |  |  | 				usort($sp_match[1], '_smarty_sort_length'); | 
					
						
							| 
									
										
										
										
											2003-01-30 16:09:53 +00:00
										 |  |  |                 for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) { | 
					
						
							|  |  |  | 					$text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$text_blocks[$curr_tb]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  |                 /* process each one */ | 
					
						
							| 
									
										
										
										
											2002-06-03 16:05:33 +00:00
										 |  |  |                 for ($curr_sp = 0, $for_max2 = count($sp_match[0]); $curr_sp < $for_max2; $curr_sp++) { | 
					
						
							| 
									
										
										
										
											2003-01-30 16:09:53 +00:00
										 |  |  |                     if ($this->php_handling == SMARTY_PHP_PASSTHRU) { | 
					
						
							|  |  |  |                         /* echo php contents */ | 
					
						
							|  |  |  |                         $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '<?php echo \''.str_replace("'", "\'", $sp_match[1][$curr_sp]).'\'; ?>'."\n", $text_blocks[$curr_tb]); | 
					
						
							|  |  |  |                     } else if ($this->php_handling == SMARTY_PHP_QUOTE) { | 
					
						
							|  |  |  |                         /* quote php tags */ | 
					
						
							|  |  |  |                         $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', htmlspecialchars($sp_match[1][$curr_sp]), $text_blocks[$curr_tb]); | 
					
						
							|  |  |  |                     } else if ($this->php_handling == SMARTY_PHP_REMOVE) { | 
					
						
							|  |  |  |                         /* remove php tags */ | 
					
						
							|  |  |  |                         $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '', $text_blocks[$curr_tb]); | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  | 						/* SMARTY_PHP_ALLOW, but echo non php starting tags */ | 
					
						
							|  |  |  | 						$sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\n", $sp_match[1][$curr_sp]); | 
					
						
							| 
									
										
										
										
											2003-01-30 16:48:55 +00:00
										 |  |  | 						$text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', $sp_match[1][$curr_sp], $text_blocks[$curr_tb]); | 
					
						
							| 
									
										
										
										
											2003-01-30 16:09:53 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Compile the template tags into PHP code. */ | 
					
						
							|  |  |  |         $compiled_tags = array(); | 
					
						
							| 
									
										
										
										
											2002-06-03 16:05:33 +00:00
										 |  |  |         for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             $this->_current_line_no += substr_count($text_blocks[$i], "\n"); | 
					
						
							|  |  |  |             $compiled_tags[] = $this->_compile_tag($template_tags[$i]); | 
					
						
							|  |  |  |             $this->_current_line_no += substr_count($template_tags[$i], "\n"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         $template_compiled = ''; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Interleave the compiled contents and text blocks to get the final result. */ | 
					
						
							| 
									
										
										
										
											2002-06-03 16:05:33 +00:00
										 |  |  |         for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |             $template_compiled .= $text_blocks[$i].$compiled_tags[$i]; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         $template_compiled .= $text_blocks[$i]; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */ | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |         if (preg_match_all("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $template_compiled, $match)) { | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             $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); | 
					
						
							| 
									
										
										
										
											2002-06-03 16:05:33 +00:00
										 |  |  |             for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++) | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |                 $template_compiled = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", | 
					
						
							| 
									
										
										
										
											2001-06-04 14:37:32 +00:00
										 |  |  |                                                   $this->quote_replace($strip_tags_modified[$i]), | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                                                   $template_compiled, 1); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  |         // remove \n from the end of the file, if any
 | 
					
						
							|  |  |  |         if ($template_compiled{strlen($template_compiled) - 1} == "\n" ) { | 
					
						
							|  |  |  |             $template_compiled = substr($template_compiled, 0, -1); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-09-28 21:39:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // run compiled template through postfilter functions
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         if (count($this->_plugins['postfilter']) > 0) { | 
					
						
							|  |  |  |             foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { | 
					
						
							| 
									
										
										
										
											2002-04-05 17:16:52 +00:00
										 |  |  |                 if ($postfilter === false) continue; | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |                 if ($postfilter[3] || function_exists($postfilter[0])) { | 
					
						
							|  |  |  |                     $template_compiled = $postfilter[0]($template_compiled, $this); | 
					
						
							|  |  |  |                     $this->_plugins['postfilter'][$filter_name][3] = true; | 
					
						
							| 
									
										
										
										
											2001-09-28 21:39:57 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2003-03-31 21:57:41 +00:00
										 |  |  |                     $this->_trigger_fatal_error("Smarty plugin error: postfilter '$filter_name' is not implemented"); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-05 19:05:39 +00:00
										 |  |  |         // put header at the top of the compiled template
 | 
					
						
							|  |  |  |         $template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; | 
					
						
							|  |  |  |         $template_header .= "         compiled from ".$tpl_file." */ ?>\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         /* Emit code to load needed plugins. */ | 
					
						
							|  |  |  |         if (count($this->_plugin_info)) { | 
					
						
							|  |  |  |             $plugins_code = '<?php $this->_load_plugins(array('; | 
					
						
							|  |  |  |             foreach ($this->_plugin_info as $plugin_type => $plugins) { | 
					
						
							|  |  |  |                 foreach ($plugins as $plugin_name => $plugin_info) { | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |                     $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], "; | 
					
						
							|  |  |  |                     $plugins_code .= $plugin_info[2] ? 'true),' : 'false),'; | 
					
						
							| 
									
										
										
										
											2001-09-28 21:39:57 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             $plugins_code .= ")); ?>"; | 
					
						
							| 
									
										
										
										
											2002-02-05 19:05:39 +00:00
										 |  |  |             $template_header .= $plugins_code; | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             $this->_plugin_info = array(); | 
					
						
							| 
									
										
										
										
											2001-09-28 21:39:57 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |         if ($this->_init_smarty_vars) { | 
					
						
							|  |  |  |             $template_header .= "<?php \$this->_assign_smarty_interface(); ?>\n"; | 
					
						
							|  |  |  |             $this->_init_smarty_vars = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-02-05 19:05:39 +00:00
										 |  |  |         $template_compiled = $template_header . $template_compiled; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile a template tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $template_tag | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_tag($template_tag) | 
					
						
							| 
									
										
										
										
											2002-12-12 16:28:29 +00:00
										 |  |  |     {		 | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-09-25 21:34:08 +00:00
										 |  |  |         /* Matched comment. */ | 
					
						
							|  |  |  |         if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') | 
					
						
							|  |  |  |             return ''; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |         /* Split tag into two three parts: command, command modifiers and the arguments. */ | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  |         if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp | 
					
						
							|  |  |  | 				. '|' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*)) | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |                       (?:\s+(.*))?$ | 
					
						
							|  |  |  |                     /xs', $template_tag, $match)) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  | 			$this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         $tag_command = $match[1]; | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  |         $tag_modifier = isset($match[2]) ? $match[2] : null; | 
					
						
							|  |  |  |         $tag_args = isset($match[3]) ? $match[3] : null; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  |         /* If the tag name is a variable or object, we process it. */ | 
					
						
							|  |  |  |         if (preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$!', $tag_command)) { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |             $_return = $this->_parse_var_props($tag_command . $tag_modifier, $this->_parse_attrs($tag_args)); | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 			if(isset($_tag_attrs['assign'])) { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  | 				return "<?php \$this->assign('" . $this->_dequote($_tag_attrs['assign']) . "', $_return ); ?>\n";   | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |             	return "<?php echo $_return; ?>\n"; | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 	    /* If the tag name is a registered object, we process it. */ | 
					
						
							|  |  |  |         if (preg_match('!^' . $this->_reg_obj_regexp . '$!', $tag_command)) { | 
					
						
							|  |  |  | 			return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args), $tag_modifier); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         switch ($tag_command) { | 
					
						
							|  |  |  |             case 'include': | 
					
						
							|  |  |  |                 return $this->_compile_include_tag($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-04 22:31:47 +00:00
										 |  |  |             case 'include_php': | 
					
						
							|  |  |  |                 return $this->_compile_include_php_tag($tag_args); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'if': | 
					
						
							|  |  |  |                 return $this->_compile_if_tag($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'else': | 
					
						
							|  |  |  |                 return '<?php else: ?>'; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'elseif': | 
					
						
							|  |  |  |                 return $this->_compile_if_tag($tag_args, true); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case '/if': | 
					
						
							|  |  |  |                 return '<?php endif; ?>'; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             case 'capture': | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |                 return $this->_compile_capture_tag(true, $tag_args); | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             case '/capture': | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |                 return $this->_compile_capture_tag(false); | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'ldelim': | 
					
						
							|  |  |  |                 return $this->left_delimiter; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'rdelim': | 
					
						
							|  |  |  |                 return $this->right_delimiter; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'section': | 
					
						
							|  |  |  |                 array_push($this->_sectionelse_stack, false); | 
					
						
							|  |  |  |                 return $this->_compile_section_start($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'sectionelse': | 
					
						
							|  |  |  |                 $this->_sectionelse_stack[count($this->_sectionelse_stack)-1] = true; | 
					
						
							|  |  |  |                 return "<?php endfor; else: ?>"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case '/section': | 
					
						
							|  |  |  |                 if (array_pop($this->_sectionelse_stack)) | 
					
						
							|  |  |  |                     return "<?php endif; ?>"; | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     return "<?php endfor; endif; ?>"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'foreach': | 
					
						
							|  |  |  |                 array_push($this->_foreachelse_stack, false); | 
					
						
							|  |  |  |                 return $this->_compile_foreach_start($tag_args); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'foreachelse': | 
					
						
							|  |  |  |                 $this->_foreachelse_stack[count($this->_foreachelse_stack)-1] = true; | 
					
						
							|  |  |  |                 return "<?php endforeach; else: ?>"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case '/foreach': | 
					
						
							|  |  |  |                 if (array_pop($this->_foreachelse_stack)) | 
					
						
							|  |  |  |                     return "<?php endif; ?>"; | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                     return "<?php endforeach; endif; ?>"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'config_load': | 
					
						
							|  |  |  |                 return $this->_compile_config_load_tag($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'strip': | 
					
						
							|  |  |  |             case '/strip': | 
					
						
							|  |  |  |                 return $this->left_delimiter.$tag_command.$this->right_delimiter; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'literal': | 
					
						
							|  |  |  |                 list (,$literal_block) = each($this->_literal_blocks); | 
					
						
							|  |  |  |                 $this->_current_line_no += substr_count($literal_block, "\n"); | 
					
						
							| 
									
										
										
										
											2001-11-20 22:36:56 +00:00
										 |  |  |                 return "<?php echo '".str_replace("'", "\'", str_replace("\\", "\\\\", $literal_block))."'; ?>\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-26 17:27:40 +00:00
										 |  |  |             case 'php': | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                 if ($this->security && !$this->security_settings['PHP_TAGS']) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                     $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-06-19 15:30:29 +00:00
										 |  |  |                     return; | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-04-26 17:27:40 +00:00
										 |  |  |                 list (,$php_block) = each($this->_php_blocks); | 
					
						
							|  |  |  |                 $this->_current_line_no += substr_count($php_block, "\n"); | 
					
						
							|  |  |  |                 return '<?php '.$php_block.' ?>'; | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'insert': | 
					
						
							|  |  |  |                 return $this->_compile_insert_tag($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  |             default: | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |                 if ($this->_compile_compiler_tag($tag_command, $tag_args, $output)) { | 
					
						
							|  |  |  |                     return $output; | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |                 } else if ($this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) { | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |                     return $output; | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |                     return $this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile the custom compiler tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |      * sets $output to the compiled custom compiler tag | 
					
						
							|  |  |  | 	 * @param string $tag_command | 
					
						
							|  |  |  | 	 * @param string $tag_args | 
					
						
							|  |  |  | 	 * @param string $output | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |     function _compile_compiler_tag($tag_command, $tag_args, &$output) | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         $found = false; | 
					
						
							|  |  |  |         $have_function = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |          * First we check if the compiler function has already been registered | 
					
						
							|  |  |  |          * or loaded from a plugin file. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         if (isset($this->_plugins['compiler'][$tag_command])) { | 
					
						
							|  |  |  |             $found = true; | 
					
						
							|  |  |  |             $plugin_func = $this->_plugins['compiler'][$tag_command][0]; | 
					
						
							|  |  |  |             if (!function_exists($plugin_func)) { | 
					
						
							|  |  |  |                 $message = "compiler function '$tag_command' is not implemented"; | 
					
						
							|  |  |  |                 $have_function = false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |          * Otherwise we need to load plugin file and look for the function
 | 
					
						
							|  |  |  |          * inside it. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2002-06-26 14:51:12 +00:00
										 |  |  |         else if ($plugin_file = $this->_get_plugin_filepath('compiler', $tag_command)) { | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             $found = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             include_once $plugin_file; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $plugin_func = 'smarty_compiler_' . $tag_command; | 
					
						
							|  |  |  |             if (!function_exists($plugin_func)) { | 
					
						
							|  |  |  |                 $message = "plugin function $plugin_func() not found in $plugin_file\n"; | 
					
						
							|  |  |  |                 $have_function = false; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->_plugins['compiler'][$tag_command] = array($plugin_func, null, null); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-04-24 16:43:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         /* | 
					
						
							|  |  |  |          * True return value means that we either found a plugin or a | 
					
						
							|  |  |  |          * dynamically registered function. False means that we didn't and the | 
					
						
							|  |  |  |          * compiler should now emit code to load custom function plugin for this | 
					
						
							|  |  |  |          * tag. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         if ($found) { | 
					
						
							|  |  |  |             if ($have_function) { | 
					
						
							|  |  |  |                 $output = '<?php ' . $plugin_func($tag_args, $this) . ' ?>'; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                 $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-24 16:43:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile block function tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |      * sets $output to compiled block function tag | 
					
						
							|  |  |  | 	 * @param string $tag_command | 
					
						
							|  |  |  | 	 * @param string $tag_args | 
					
						
							|  |  |  | 	 * @param string $tag_modifier | 
					
						
							|  |  |  | 	 * @param string $output | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |     function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ($tag_command{0} == '/') { | 
					
						
							|  |  |  |             $start_tag = false; | 
					
						
							|  |  |  |             $tag_command = substr($tag_command, 1); | 
					
						
							|  |  |  |         } else | 
					
						
							|  |  |  |             $start_tag = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $found = false; | 
					
						
							|  |  |  |         $have_function = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |          * First we check if the block function has already been registered | 
					
						
							|  |  |  |          * or loaded from a plugin file. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         if (isset($this->_plugins['block'][$tag_command])) { | 
					
						
							|  |  |  |             $found = true; | 
					
						
							|  |  |  |             $plugin_func = $this->_plugins['block'][$tag_command][0]; | 
					
						
							|  |  |  |             if (!function_exists($plugin_func)) { | 
					
						
							|  |  |  |                 $message = "block function '$tag_command' is not implemented"; | 
					
						
							|  |  |  |                 $have_function = false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |          * Otherwise we need to load plugin file and look for the function
 | 
					
						
							|  |  |  |          * inside it. | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2002-06-26 14:51:12 +00:00
										 |  |  |         else if ($plugin_file = $this->_get_plugin_filepath('block', $tag_command)) { | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |             $found = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             include_once $plugin_file; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $plugin_func = 'smarty_block_' . $tag_command; | 
					
						
							|  |  |  |             if (!function_exists($plugin_func)) { | 
					
						
							|  |  |  |                 $message = "plugin function $plugin_func() not found in $plugin_file\n"; | 
					
						
							|  |  |  |                 $have_function = false; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->_plugins['block'][$tag_command] = array($plugin_func, null, null); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$found) { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } else if (!$have_function) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |          * Even though we've located the plugin function, compilation | 
					
						
							|  |  |  |          * happens only once, so the plugin will still need to be loaded | 
					
						
							|  |  |  |          * at runtime for future requests. | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         $this->_add_plugin('block', $tag_command); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($start_tag) { | 
					
						
							| 
									
										
										
										
											2002-03-26 21:01:52 +00:00
										 |  |  |             $arg_list = array(); | 
					
						
							|  |  |  |             $attrs = $this->_parse_attrs($tag_args); | 
					
						
							|  |  |  |             foreach ($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  |                 if (is_bool($arg_value)) | 
					
						
							|  |  |  |                     $arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							|  |  |  |                 $arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $output = "<?php \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>"; | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |             $output = "<?php \$this->_block_content = ob_get_contents(); ob_end_clean(); "; | 
					
						
							|  |  |  | 			$out_tag_text = "\$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this)"; | 
					
						
							|  |  |  | 			if($tag_modifier != '') { | 
					
						
							|  |  |  | 				$this->_parse_modifiers($out_tag_text, $tag_modifier); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			$output .= 'echo ' . $out_tag_text . ';'; | 
					
						
							|  |  |  | 			$output .= " array_pop(\$this->_tag_stack); ?>"; | 
					
						
							| 
									
										
										
										
											2002-03-25 22:32:05 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile custom function tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_command | 
					
						
							|  |  |  | 	 * @param string $tag_args | 
					
						
							|  |  |  | 	 * @param string $tag_modifier | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |     function _compile_custom_tag($tag_command, $tag_args, $tag_modifier) | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |         $this->_add_plugin('function', $tag_command); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |         $arg_list = array(); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         foreach ($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  |             if (is_bool($arg_value)) | 
					
						
							|  |  |  |                 $arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  |             if (is_null($arg_value)) | 
					
						
							|  |  |  |                 $arg_value = 'null'; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             $arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		$return = "\$this->_plugins['function']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this)"; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if($tag_modifier != '') { | 
					
						
							|  |  |  | 			$this->_parse_modifiers($return, $tag_modifier); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  |         return '<?php echo ' . $return . " ; ?>\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile a registered object tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_command | 
					
						
							|  |  |  | 	 * @param array $attrs | 
					
						
							|  |  |  | 	 * @param string $tag_modifier | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  |     function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 		list($object, $obj_comp) = explode('->', $tag_command); | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $arg_list = array(); | 
					
						
							|  |  |  | 		if(count($attrs)) { | 
					
						
							|  |  |  | 			$_assign_var = false; | 
					
						
							|  |  |  |         	foreach ($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  | 				if($arg_name == 'assign') { | 
					
						
							|  |  |  | 					$_assign_var = $arg_value; | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 					unset($attrs['assign']); | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  |             	if (is_bool($arg_value)) | 
					
						
							|  |  |  |                 	$arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							|  |  |  |             	$arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |         	} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-01-25 20:31:45 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 		if(!is_object($this->_reg_objects[$object][0])) { | 
					
						
							| 
									
										
										
										
											2003-01-25 20:31:45 +00:00
										 |  |  | 			$this->_trigger_fatal_error("registered '$object' is not an object"); | 
					
						
							|  |  |  | 		} elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) { | 
					
						
							|  |  |  | 			$this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'"); | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 		} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) { | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 			// method
 | 
					
						
							| 
									
										
										
										
											2003-01-25 20:31:45 +00:00
										 |  |  | 			if($this->_reg_objects[$object][2]) { | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 				// smarty object argument format
 | 
					
						
							|  |  |  | 				$return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// traditional argument format
 | 
					
						
							|  |  |  | 				$return = "\$this->_reg_objects['$object'][0]->$obj_comp(".implode(',', array_values($attrs)).")"; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			// property
 | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  | 			$return = "\$this->_reg_objects['$object'][0]->$obj_comp"; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if($tag_modifier != '') { | 
					
						
							|  |  |  | 			$this->_parse_modifiers($return, $tag_modifier); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if($_assign_var) { | 
					
						
							|  |  |  | 			return "<?php \$this->assign('" . $this->_dequote($_assign_var) ."',  $return); ?>\n"; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2003-01-24 15:02:15 +00:00
										 |  |  |         	return '<?php echo ' . $return . "; ?>\n"; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {insert ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_insert_tag($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         $name = $this->_dequote($attrs['name']); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if (empty($name)) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |         if (!empty($attrs['script'])) { | 
					
						
							|  |  |  |             $delayed_loading = true; | 
					
						
							| 
									
										
										
										
											2002-11-22 14:33:03 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $delayed_loading = false;			 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         foreach ($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  |             if (is_bool($arg_value)) | 
					
						
							|  |  |  |                 $arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							|  |  |  |             $arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |         $this->_add_plugin('insert', $name, $delayed_loading); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-10 20:58:15 +00:00
										 |  |  |         return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {config_load ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_config_load_tag($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if (empty($attrs['file'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-19 15:30:29 +00:00
										 |  |  |         if (empty($attrs['section'])) { | 
					
						
							|  |  |  |             $attrs['section'] = 'null'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-14 16:50:40 +00:00
										 |  |  |         if (isset($attrs['scope'])) { | 
					
						
							|  |  |  | 			$scope = @$this->_dequote($attrs['scope']); | 
					
						
							| 
									
										
										
										
											2001-06-15 18:55:28 +00:00
										 |  |  |             if ($scope != 'local' && | 
					
						
							|  |  |  |                 $scope != 'parent' && | 
					
						
							|  |  |  |                 $scope != 'global') { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                 $this->_syntax_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-06-15 18:55:28 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2002-12-14 16:50:40 +00:00
										 |  |  |             if (isset($attrs['global']) && $attrs['global']) | 
					
						
							| 
									
										
										
										
											2001-06-15 18:55:28 +00:00
										 |  |  |                 $scope = 'parent'; | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 $scope = 'local'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-16 23:02:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-14 16:50:40 +00:00
										 |  |  |         return '<?php $this->config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {include ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * $param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_include_tag($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							| 
									
										
										
										
											2001-11-20 22:36:56 +00:00
										 |  |  |         $arg_list = array(); | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if (empty($attrs['file'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-04-27 19:39:31 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         foreach ($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  |             if ($arg_name == 'file') { | 
					
						
							|  |  |  |                 $include_file = $arg_value; | 
					
						
							| 
									
										
										
										
											2001-04-11 18:35:17 +00:00
										 |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2001-12-05 20:08:12 +00:00
										 |  |  |             } else if ($arg_name == 'assign') { | 
					
						
							| 
									
										
										
										
											2001-12-05 16:36:58 +00:00
										 |  |  |                 $assign_var = $arg_value; | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             if (is_bool($arg_value)) | 
					
						
							|  |  |  |                 $arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							|  |  |  |             $arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-12-05 20:08:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $output = '<?php '; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-12-05 16:36:58 +00:00
										 |  |  |         if (isset($assign_var)) { | 
					
						
							| 
									
										
										
										
											2001-12-05 20:08:12 +00:00
										 |  |  | 			$output .= "ob_start();\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $output .=   | 
					
						
							|  |  |  |             "\$_smarty_tpl_vars = \$this->_tpl_vars;\n" . | 
					
						
							|  |  |  |             "\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" . | 
					
						
							|  |  |  |             "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . | 
					
						
							|  |  |  |             "unset(\$_smarty_tpl_vars);\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($assign_var)) { | 
					
						
							|  |  |  | 			$output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $output .= ' ?>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $output; | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {include ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-12-04 22:31:47 +00:00
										 |  |  |     function _compile_include_php_tag($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($attrs['file'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing 'file' attribute in include_php tag", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-12-04 22:31:47 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-28 15:45:42 +00:00
										 |  |  |         $assign_var = $this->_dequote($attrs['assign']);		 | 
					
						
							|  |  |  | 		$once_var = ( $attrs['once'] == 'false' ) ? 'false' : 'true'; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2003-02-05 20:36:26 +00:00
										 |  |  |     	foreach($attrs as $arg_name => $arg_value) { | 
					
						
							|  |  |  |         	if($arg_name != 'file' AND $arg_name != 'once' AND $arg_name != 'assign') { | 
					
						
							|  |  |  |             	if(is_bool($arg_value)) | 
					
						
							|  |  |  |                 	$arg_value = $arg_value ? 'true' : 'false'; | 
					
						
							|  |  |  |             	$arg_list[] = "'$arg_name' => $arg_value"; | 
					
						
							|  |  |  |         	} | 
					
						
							|  |  |  |     	} | 
					
						
							| 
									
										
										
										
											2003-02-05 14:56:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-05 20:36:26 +00:00
										 |  |  |     	$output = | 
					
						
							|  |  |  |         	"<?php \$this->_smarty_include_php($attrs[file], '$assign_var', $once_var, " . | 
					
						
							|  |  |  |         	"array(".implode(',', (array)$arg_list).")); ?>"; | 
					
						
							| 
									
										
										
										
											2002-05-16 16:15:50 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2003-02-05 14:56:27 +00:00
										 |  |  | 		return $output; | 
					
						
							| 
									
										
										
										
											2001-12-04 22:31:47 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {section ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_section_start($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |         $arg_list = array(); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |         $output = '<?php '; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $section_name = $attrs['name']; | 
					
						
							|  |  |  |         if (empty($section_name)) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing section name", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  |         $output .= "if (isset(\$this->_sections[$section_name])) unset(\$this->_sections[$section_name]);\n"; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         $section_props = "\$this->_sections[$section_name]"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         foreach ($attrs as $attr_name => $attr_value) { | 
					
						
							|  |  |  |             switch ($attr_name) { | 
					
						
							|  |  |  |                 case 'loop': | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |                     $output .= "{$section_props}['loop'] = is_array($attr_value) ? count($attr_value) : max(0, (int)$attr_value);\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 case 'show': | 
					
						
							|  |  |  |                     if (is_bool($attr_value)) | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |                         $show_attr_value = $attr_value ? 'true' : 'false'; | 
					
						
							|  |  |  |                     else | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |                         $show_attr_value = "(bool)$attr_value"; | 
					
						
							|  |  |  |                     $output .= "{$section_props}['show'] = $show_attr_value;\n"; | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'name': | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $output .= "{$section_props}['$attr_name'] = $attr_value;\n"; | 
					
						
							|  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |                 case 'max': | 
					
						
							|  |  |  |                 case 'start': | 
					
						
							|  |  |  |                     $output .= "{$section_props}['$attr_name'] = (int)$attr_value;\n"; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |                 case 'step': | 
					
						
							|  |  |  |                     $output .= "{$section_props}['$attr_name'] = ((int)$attr_value) == 0 ? 1 : (int)$attr_value;\n"; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 default: | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                     $this->_syntax_error("unknown section attribute - '$attr_name'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |         if (!isset($attrs['show'])) | 
					
						
							|  |  |  |             $output .= "{$section_props}['show'] = true;\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |         if (!isset($attrs['loop'])) | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             $output .= "{$section_props}['loop'] = 1;\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |         if (!isset($attrs['max'])) | 
					
						
							|  |  |  |             $output .= "{$section_props}['max'] = {$section_props}['loop'];\n"; | 
					
						
							| 
									
										
										
										
											2001-06-27 16:44:26 +00:00
										 |  |  |         else | 
					
						
							|  |  |  |             $output .= "if ({$section_props}['max'] < 0)\n" . | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  |                        "    {$section_props}['max'] = {$section_props}['loop'];\n"; | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |         if (!isset($attrs['step'])) | 
					
						
							|  |  |  |             $output .= "{$section_props}['step'] = 1;\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |         if (!isset($attrs['start'])) | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |             $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n"; | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |             $output .= "if ({$section_props}['start'] < 0)\n" . | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |                        "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . | 
					
						
							|  |  |  |                        "else\n" . | 
					
						
							|  |  |  |                        "    {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 20:14:46 +00:00
										 |  |  |         $output .= "if ({$section_props}['show']) {\n"; | 
					
						
							|  |  |  |         if (!isset($attrs['start']) && !isset($attrs['step']) && !isset($attrs['max'])) { | 
					
						
							|  |  |  |             $output .= "    {$section_props}['total'] = {$section_props}['loop'];\n"; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $output .= "    {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $output .= "    if ({$section_props}['total'] == 0)\n" . | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |                    "        {$section_props}['show'] = false;\n" . | 
					
						
							|  |  |  |                    "} else\n" . | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |                    "    {$section_props}['total'] = 0;\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |         $output .= "if ({$section_props}['show']):\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $output .= "
 | 
					
						
							| 
									
										
										
										
											2001-06-26 21:12:54 +00:00
										 |  |  |             for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1; | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |                  {$section_props}['iteration'] <= {$section_props}['total']; | 
					
						
							|  |  |  |                  {$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
 | 
					
						
							| 
									
										
										
										
											2001-06-27 19:27:29 +00:00
										 |  |  |         $output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n"; | 
					
						
							| 
									
										
										
										
											2001-06-27 19:21:53 +00:00
										 |  |  |         $output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n"; | 
					
						
							|  |  |  |         $output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n"; | 
					
						
							|  |  |  |         $output .= "{$section_props}['first']      = ({$section_props}['iteration'] == 1);\n"; | 
					
						
							|  |  |  |         $output .= "{$section_props}['last']       = ({$section_props}['iteration'] == {$section_props}['total']);\n"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $output .= "?>"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {foreach ...} tag. | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |     function _compile_foreach_start($tag_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							|  |  |  |         $arg_list = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($attrs['from'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing 'from' attribute", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($attrs['item'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |             $this->_syntax_error("missing 'item' attribute", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $from = $attrs['from']; | 
					
						
							|  |  |  |         $item = $this->_dequote($attrs['item']); | 
					
						
							| 
									
										
										
										
											2001-11-29 17:05:39 +00:00
										 |  |  |         if (isset($attrs['name'])) | 
					
						
							|  |  |  |             $name = $attrs['name']; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $output = '<?php '; | 
					
						
							| 
									
										
										
										
											2001-11-29 17:05:39 +00:00
										 |  |  |         if (isset($name)) { | 
					
						
							|  |  |  |             $output .= "if (isset(\$this->_foreach[$name])) unset(\$this->_foreach[$name]);\n"; | 
					
						
							|  |  |  |             $foreach_props = "\$this->_foreach[$name]"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $key_part = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($attrs as $attr_name => $attr_value) { | 
					
						
							|  |  |  |             switch ($attr_name) { | 
					
						
							|  |  |  |                 case 'key': | 
					
						
							|  |  |  |                     $key  = $this->_dequote($attrs['key']); | 
					
						
							|  |  |  |                     $key_part = "\$this->_tpl_vars['$key'] => "; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'name': | 
					
						
							|  |  |  |                     $output .= "{$foreach_props}['$attr_name'] = $attr_value;\n"; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-29 17:05:39 +00:00
										 |  |  |         if (isset($name)) { | 
					
						
							|  |  |  |             $output .= "{$foreach_props}['total'] = count((array)$from);\n"; | 
					
						
							|  |  |  |             $output .= "{$foreach_props}['show'] = {$foreach_props}['total'] > 0;\n"; | 
					
						
							|  |  |  |             $output .= "if ({$foreach_props}['show']):\n"; | 
					
						
							|  |  |  |             $output .= "{$foreach_props}['iteration'] = 0;\n"; | 
					
						
							| 
									
										
										
										
											2003-01-24 16:08:31 +00:00
										 |  |  |             $output .= "    foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n"; | 
					
						
							| 
									
										
										
										
											2001-11-29 17:05:39 +00:00
										 |  |  |             $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((array)$from)):\n"; | 
					
						
							| 
									
										
										
										
											2003-01-24 16:08:31 +00:00
										 |  |  |             $output .= "    foreach ((array)$from as $key_part\$this->_tpl_vars['$item']):\n"; | 
					
						
							| 
									
										
										
										
											2001-11-29 17:05:39 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         $output .= '?>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {capture} .. {/capture} tags | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param boolean $start true if this is the {capture} tag | 
					
						
							|  |  |  | 	 * @param string $tag_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |     function _compile_capture_tag($start, $tag_args = '') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attrs = $this->_parse_attrs($tag_args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($start) { | 
					
						
							|  |  |  |             if (isset($attrs['name'])) | 
					
						
							|  |  |  |                 $buffer = $attrs['name']; | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 $buffer = "'default'"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $output = "<?php ob_start(); ?>"; | 
					
						
							|  |  |  |             $this->_capture_stack[] = $buffer; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $buffer = array_pop($this->_capture_stack); | 
					
						
							| 
									
										
										
										
											2001-11-27 20:04:47 +00:00
										 |  |  |             $output = "<?php \$this->_smarty_vars['capture'][$buffer] = ob_get_contents(); ob_end_clean(); ?>"; | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compile {if ...} tag | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							|  |  |  | 	 * @param boolean $elseif if true, uses elseif instead of if | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _compile_if_tag($tag_args, $elseif = false) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Tokenize args for 'if' tag. */ | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  |         preg_match_all('/(?>
 | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 				' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)? | # valid object call
 | 
					
						
							|  |  |  | 				' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)?	| # var or quoted string
 | 
					
						
							| 
									
										
										
										
											2003-02-24 16:24:29 +00:00
										 |  |  | 				\-?\d+(?:\.\d+)?|\.\d+|!==|===|==|!=|<>|<<|>>|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@	| # valid non-word token
 | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 				\b\w+\b														| # valid word token
 | 
					
						
							| 
									
										
										
										
											2002-12-20 17:25:01 +00:00
										 |  |  | 				\S+                                                           # anything else
 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 				)/x', $tag_args, $match); | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $tokens = $match[0]; | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  | 		// make sure we have balanced parenthesis
 | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 		$token_count = array_count_values($tokens); | 
					
						
							|  |  |  | 		if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  | 			$this->_syntax_error("unbalanced parenthesis in if statement", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 												 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $is_arg_stack = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  |         for ($i = 0; $i < count($tokens); $i++) { | 
					
						
							| 
									
										
										
										
											2001-10-26 14:15:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             $token = &$tokens[$i]; | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2003-02-06 14:37:49 +00:00
										 |  |  |             switch (strtolower($token)) { | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  |                 case '!': | 
					
						
							|  |  |  |                 case '%': | 
					
						
							|  |  |  |                 case '!==': | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  |                 case '==': | 
					
						
							| 
									
										
										
										
											2003-02-17 14:47:21 +00:00
										 |  |  |                 case '===': | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  |                 case '>': | 
					
						
							|  |  |  |                 case '<': | 
					
						
							|  |  |  |                 case '!=': | 
					
						
							| 
									
										
										
										
											2003-02-24 16:24:29 +00:00
										 |  |  |                 case '<>': | 
					
						
							|  |  |  |                 case '<<': | 
					
						
							|  |  |  |                 case '>>': | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  |                 case '<=': | 
					
						
							|  |  |  |                 case '>=': | 
					
						
							|  |  |  |                 case '&&': | 
					
						
							|  |  |  |                 case '||': | 
					
						
							|  |  |  | 				case '|': | 
					
						
							|  |  |  | 				case '^': | 
					
						
							|  |  |  | 				case '&': | 
					
						
							|  |  |  | 				case '~': | 
					
						
							|  |  |  | 				case ')': | 
					
						
							|  |  |  | 				case ',': | 
					
						
							| 
									
										
										
										
											2003-02-05 14:56:27 +00:00
										 |  |  | 				case '+': | 
					
						
							|  |  |  | 				case '-': | 
					
						
							|  |  |  | 				case '*': | 
					
						
							|  |  |  | 				case '/': | 
					
						
							| 
									
										
										
										
											2003-02-17 14:47:21 +00:00
										 |  |  | 				case '@': | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  | 					break;					 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'eq': | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $token = '=='; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'ne': | 
					
						
							|  |  |  |                 case 'neq': | 
					
						
							|  |  |  |                     $token = '!='; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'lt': | 
					
						
							|  |  |  |                     $token = '<'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'le': | 
					
						
							|  |  |  |                 case 'lte': | 
					
						
							|  |  |  |                     $token = '<='; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'gt': | 
					
						
							|  |  |  |                     $token = '>'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'ge': | 
					
						
							|  |  |  |                 case 'gte': | 
					
						
							|  |  |  |                     $token = '>='; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'and': | 
					
						
							|  |  |  |                     $token = '&&'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'or': | 
					
						
							|  |  |  |                     $token = '||'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'not': | 
					
						
							|  |  |  |                     $token = '!'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 'mod': | 
					
						
							|  |  |  |                     $token = '%'; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case '(': | 
					
						
							|  |  |  |                     array_push($is_arg_stack, $i); | 
					
						
							|  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2003-01-15 15:23:13 +00:00
										 |  |  | 					 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 case 'is': | 
					
						
							|  |  |  |                     /* 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] == ')') | 
					
						
							|  |  |  |                         $is_arg_start = array_pop($is_arg_stack); | 
					
						
							|  |  |  |                     else | 
					
						
							|  |  |  |                         $is_arg_start = $i-1; | 
					
						
							|  |  |  |                     /* Construct the argument for 'is' expression, so it knows | 
					
						
							|  |  |  |                        what to operate on. */ | 
					
						
							|  |  |  |                     $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 					 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     /* Pass all tokens from next one until the end to the | 
					
						
							|  |  |  |                        'is' expression parsing function. The function will | 
					
						
							|  |  |  |                        return modified tokens, where the first one is the result | 
					
						
							|  |  |  |                        of the 'is' expression and the rest are the tokens it | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |                        didn't touch. */					 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 										 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     /* Replace the old tokens with the new ones. */ | 
					
						
							|  |  |  |                     array_splice($tokens, $is_arg_start, count($tokens), $new_tokens); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     /* Adjust argument start so that it won't change from the | 
					
						
							|  |  |  |                        current position for the next iteration. */ | 
					
						
							|  |  |  |                     $i = $is_arg_start; | 
					
						
							|  |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 					 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                 default: | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 					if(preg_match('!^' . $this->_func_regexp . '$!', $token) ) { | 
					
						
							| 
									
										
										
										
											2002-12-20 17:25:01 +00:00
										 |  |  | 							// function call	
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |                     		if($this->security && | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  |                     		   !in_array($token, $this->security_settings['IF_FUNCS'])) { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                         		$this->_syntax_error("(secure mode) '$token' not allowed in if statement", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-12-19 23:55:17 +00:00
										 |  |  | 							}							 | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 					} elseif(preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) { | 
					
						
							|  |  |  | 						// object or variable
 | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |         				$token = $this->_parse_var_props($token); | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 					} elseif(is_numeric($token)) { | 
					
						
							|  |  |  | 						// number, skip it
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                 		$this->_syntax_error("unidentified token '$token'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |                     break; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if ($elseif) | 
					
						
							|  |  |  |             return '<?php elseif ('.implode(' ', $tokens).'): ?>'; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             return '<?php if ('.implode(' ', $tokens).'): ?>'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Parse is expression | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $is_arg | 
					
						
							|  |  |  | 	 * @param array $tokens | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_is_expr($is_arg, $tokens) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expr_end = 0; | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |         $negate_expr = false; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if (($first_token = array_shift($tokens)) == 'not') { | 
					
						
							|  |  |  |             $negate_expr = true; | 
					
						
							|  |  |  |             $expr_type = array_shift($tokens); | 
					
						
							|  |  |  |         } else | 
					
						
							|  |  |  |             $expr_type = $first_token; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch ($expr_type) { | 
					
						
							|  |  |  |             case 'even': | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |                 if (@$tokens[$expr_end] == 'by') { | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $expr_end++; | 
					
						
							|  |  |  |                     $expr_arg = $tokens[$expr_end++]; | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |                     $expr = "!(($is_arg / $expr_arg) % " . $this->_parse_var_props($expr_arg) . ")"; | 
					
						
							| 
									
										
										
										
											2002-02-04 17:20:36 +00:00
										 |  |  |                 } else | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $expr = "!($is_arg % 2)"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'odd': | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |                 if (@$tokens[$expr_end] == 'by') { | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $expr_end++; | 
					
						
							|  |  |  |                     $expr_arg = $tokens[$expr_end++]; | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |                     $expr = "(($is_arg / $expr_arg) % ". $this->_parse_var_props($expr_arg) . ")"; | 
					
						
							| 
									
										
										
										
											2002-02-04 17:20:36 +00:00
										 |  |  |                 } else | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $expr = "($is_arg % 2)"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             case 'div': | 
					
						
							| 
									
										
										
										
											2001-08-01 16:22:55 +00:00
										 |  |  |                 if (@$tokens[$expr_end] == 'by') { | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     $expr_end++; | 
					
						
							|  |  |  |                     $expr_arg = $tokens[$expr_end++]; | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |                     $expr = "!($is_arg % " . $this->_parse_var_props($expr_arg) . ")"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                     $this->_syntax_error("expecting 'by' after 'div'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             default: | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                 $this->_syntax_error("unknown 'is' expression - '$expr_type'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         if ($negate_expr) { | 
					
						
							|  |  |  |             $expr = "!($expr)"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  |         array_splice($tokens, 0, $expr_end, $expr);		 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $tokens; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Parse attribute string | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $tag_args | 
					
						
							|  |  |  | 	 * @param true $quote unused? | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_attrs($tag_args, $quote = true) | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         /* Tokenize tag attributes. */ | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |         preg_match_all('/(?:' . $this->_obj_call_regexp . '|' . $this->_qstr_regexp . ' | (?>[^"\'=\s]+)
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                          )+ | | 
					
						
							|  |  |  |                          [=] | 
					
						
							|  |  |  |                         /x', $tag_args, $match); | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |         $tokens       = $match[0];		 | 
					
						
							| 
									
										
										
										
											2003-02-13 15:28:14 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $attrs = array(); | 
					
						
							|  |  |  |         /* Parse state: | 
					
						
							|  |  |  |             0 - expecting attribute name | 
					
						
							|  |  |  |             1 - expecting '=' | 
					
						
							|  |  |  |             2 - expecting attribute value (not '=') */ | 
					
						
							|  |  |  |         $state = 0; | 
					
						
							| 
									
										
										
										
											2003-01-23 23:33:29 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         foreach ($tokens as $token) { | 
					
						
							|  |  |  |             switch ($state) { | 
					
						
							|  |  |  |                 case 0: | 
					
						
							|  |  |  |                     /* If the token is a valid identifier, we set attribute name | 
					
						
							|  |  |  |                        and go to state 1. */ | 
					
						
							|  |  |  |                     if (preg_match('!^\w+$!', $token)) { | 
					
						
							|  |  |  |                         $attr_name = $token; | 
					
						
							|  |  |  |                         $state = 1; | 
					
						
							|  |  |  |                     } else | 
					
						
							| 
									
										
										
										
											2003-02-13 15:28:14 +00:00
										 |  |  |                         $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 1: | 
					
						
							|  |  |  |                     /* If the token is '=', then we go to state 2. */ | 
					
						
							|  |  |  |                     if ($token == '=') { | 
					
						
							|  |  |  |                         $state = 2; | 
					
						
							|  |  |  |                     } else | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  |                         $this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 case 2: | 
					
						
							|  |  |  |                     /* If token is not '=', we set the attribute value and go to | 
					
						
							|  |  |  |                        state 0. */ | 
					
						
							|  |  |  |                     if ($token != '=') { | 
					
						
							|  |  |  |                         /* We booleanize the token if it's a non-quoted possible | 
					
						
							|  |  |  |                            boolean value. */ | 
					
						
							| 
									
										
										
										
											2003-02-13 15:28:14 +00:00
										 |  |  |                         if (preg_match('!^(on|yes|true)$!', $token)) { | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  |                             $token = 'true'; | 
					
						
							| 
									
										
										
										
											2003-02-13 15:28:14 +00:00
										 |  |  | 						} else if (preg_match('!^(off|no|false)$!', $token)) { | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  |                             $token = 'false'; | 
					
						
							|  |  |  | 						} else if ($token == 'null') { | 
					
						
							|  |  |  |                             $token = 'null'; | 
					
						
							| 
									
										
										
										
											2003-04-03 17:00:17 +00:00
										 |  |  | 						} else if (preg_match('!^-?[0-9]+$!', $token)) { | 
					
						
							|  |  |  |                             /* treat integer literally */ | 
					
						
							| 
									
										
										
										
											2003-03-18 14:47:41 +00:00
										 |  |  | 						} else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')*$!', $token)) { | 
					
						
							| 
									
										
										
										
											2003-02-17 17:11:42 +00:00
										 |  |  |                         	/* treat as a string, double-quote it escaping quotes */ | 
					
						
							|  |  |  |                             $token = '"'.addslashes($token).'"'; | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                         $attrs[$attr_name] = $token; | 
					
						
							|  |  |  |                         $state = 0; | 
					
						
							|  |  |  |                     } else | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |                         $this->_syntax_error("'=' cannot be an attribute value", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 			$last_token = $token; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  | 		if($state != 0) { | 
					
						
							|  |  |  | 			if($state == 1) { | 
					
						
							|  |  |  | 				$this->_syntax_error("expecting '=' after attribute name '$last_token'", E_USER_ERROR, __FILE__, __LINE__);				 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$this->_syntax_error("missing attribute value", E_USER_ERROR, __FILE__, __LINE__);								 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $this->_parse_vars_props($attrs); | 
					
						
							| 
									
										
										
										
											2003-02-19 15:58:03 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $attrs; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile multiple variables and section properties tokens into | 
					
						
							|  |  |  | 	 * PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param array $tokens | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_vars_props(&$tokens) | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 		foreach($tokens as $key => $val) {			 | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |     		$tokens[$key] = $this->_parse_var_props($val); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * compile single variable and section properties token into | 
					
						
							|  |  |  | 	 * PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $val | 
					
						
							|  |  |  | 	 * @param string $tag_attrs | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2003-01-17 23:54:29 +00:00
										 |  |  |     function _parse_var_props($val, $tag_attrs = null) | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |     {					 | 
					
						
							| 
									
										
										
										
											2002-12-20 17:25:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$val = trim($val); | 
					
						
							| 
									
										
										
										
											2002-12-23 22:52:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  |         if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) { | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				// $ variable or object
 | 
					
						
							| 
									
										
										
										
											2003-02-17 14:47:21 +00:00
										 |  |  |                 return $this->_parse_var($val); | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 			}			 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  |         elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				// double quoted text
 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  | 				preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match); | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  |                 $return = $this->_expand_quoted_text($match[1]); | 
					
						
							|  |  |  | 				if($match[2] != '') { | 
					
						
							|  |  |  | 					$this->_parse_modifiers($return, $match[2]); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				return $return; | 
					
						
							|  |  |  | 			}			 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  |         elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				// single quoted text
 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  | 				preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match); | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				if($match[2] != '') { | 
					
						
							|  |  |  | 					$this->_parse_modifiers($match[1], $match[2]); | 
					
						
							|  |  |  |                 	return $match[1]; | 
					
						
							|  |  |  | 				}	 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 			}			 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  |         elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				// config var
 | 
					
						
							|  |  |  |                 return $this->_parse_conf_var($val); | 
					
						
							|  |  |  | 			}			 | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  |         elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 				// section var
 | 
					
						
							|  |  |  |                 return $this->_parse_section_prop($val); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { | 
					
						
							|  |  |  | 			// literal string
 | 
					
						
							| 
									
										
										
										
											2002-12-20 17:25:01 +00:00
										 |  |  | 			return $this->_expand_quoted_text('"' . $val .'"'); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-12-20 01:12:43 +00:00
										 |  |  | 		return $val; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * expand quoted text with embedded variables | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $var_expr | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |     function _expand_quoted_text($var_expr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 		// if contains unescaped $, expand it
 | 
					
						
							| 
									
										
										
										
											2003-04-04 23:19:02 +00:00
										 |  |  | 		if(preg_match_all('%(?:\`(?<!\\\\)\$' . $this->_dvar_guts_regexp . '\`)|(?:(?<!\\\\)\$\w+(\[[a-zA-Z0-9]+\])*)%', $var_expr, $_match)) { | 
					
						
							| 
									
										
										
										
											2003-02-28 15:08:15 +00:00
										 |  |  | 			$_match = $_match[0]; | 
					
						
							|  |  |  | 			rsort($_match); | 
					
						
							|  |  |  | 			reset($_match); | 
					
						
							|  |  |  | 			foreach($_match as $_var) { | 
					
						
							|  |  |  |                 $var_expr = str_replace ($_var, '".' . $this->_parse_var(str_replace('`','',$_var)) . '."', $var_expr); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-03-17 14:56:39 +00:00
										 |  |  |             $_return = preg_replace('%\.""|(?<!\\\\)""\.%', '', $var_expr); | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2003-02-28 15:08:15 +00:00
										 |  |  | 			$_return = $var_expr; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-03-14 16:28:47 +00:00
										 |  |  | 		// replace double quoted literal string with single quotes
 | 
					
						
							|  |  |  | 		$_return = preg_replace('!^"([\s\w]+)"$!',"'\\1'",$_return); | 
					
						
							| 
									
										
										
										
											2003-02-28 15:08:15 +00:00
										 |  |  | 		return $_return; | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * parse variable expression into PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $var_expr | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |     function _parse_var($var_expr) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-12-24 14:56:43 +00:00
										 |  |  | 		preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . '*)$!', $var_expr, $match); | 
					
						
							| 
									
										
										
										
											2003-02-28 15:08:15 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  |         $var_ref = substr($match[1],1); | 
					
						
							|  |  |  |         $modifiers = $match[2]; | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2002-07-18 13:29:16 +00:00
										 |  |  | 		if(!empty($this->default_modifiers) && !preg_match('!(^|\|)smarty:nodefaults($|\|)!',$modifiers)) { | 
					
						
							| 
									
										
										
										
											2002-07-17 21:33:12 +00:00
										 |  |  | 			$_default_mod_string = implode('|',(array)$this->default_modifiers); | 
					
						
							|  |  |  | 			$modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' . $modifiers; | 
					
						
							| 
									
										
										
										
											2002-07-17 21:16:43 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-12-18 16:51:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 		// get [foo] and .foo and ->foo and (...) pieces			
 | 
					
						
							|  |  |  |         preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' . $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match);		 | 
					
						
							| 
									
										
										
										
											2003-02-28 15:08:15 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         $indexes = $match[0]; | 
					
						
							| 
									
										
										
										
											2001-04-13 21:55:30 +00:00
										 |  |  |         $var_name = array_shift($indexes); | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         /* Handle $smarty.* variable references as a special case. */ | 
					
						
							|  |  |  |         if ($var_name == 'smarty') { | 
					
						
							|  |  |  |             /* | 
					
						
							|  |  |  |              * If the reference could be compiled, use the compiled output; | 
					
						
							|  |  |  |              * otherwise, fall back on the $smarty variable generated at | 
					
						
							|  |  |  |              * run-time. | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             if (($smarty_ref = $this->_compile_smarty_ref($indexes)) !== null) { | 
					
						
							|  |  |  |                 $output = $smarty_ref; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $var_name = substr(array_shift($indexes), 1); | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |                 $output = "\$this->_smarty_vars['$var_name']"; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |             $output = "\$this->_tpl_vars['$var_name']"; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2003-02-10 20:59:08 +00:00
										 |  |  |         foreach ($indexes as $index) {			 | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             if ($index{0} == '[') { | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |                 $index = substr($index, 1, -1); | 
					
						
							|  |  |  |                 if (is_numeric($index)) { | 
					
						
							|  |  |  |                     $output .= "[$index]"; | 
					
						
							| 
									
										
										
										
											2002-05-17 15:11:49 +00:00
										 |  |  |                 } elseif ($index{0} == '$') { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |                     $output .= "[\$this->_tpl_vars['" . substr($index, 1) . "']]"; | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                     $parts = explode('.', $index); | 
					
						
							|  |  |  |                     $section = $parts[0]; | 
					
						
							|  |  |  |                     $section_prop = isset($parts[1]) ? $parts[1] : 'index'; | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |                     $output .= "[\$this->_sections['$section']['$section_prop']]"; | 
					
						
							| 
									
										
										
										
											2001-07-24 18:39:03 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             } else if ($index{0} == '.') { | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |                 if ($index{1} == '$') | 
					
						
							| 
									
										
										
										
											2003-03-15 20:03:46 +00:00
										 |  |  |                     $output .= "[\$this->_tpl_vars['" . substr($index, 2) . "']]"; | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |                 else | 
					
						
							| 
									
										
										
										
											2002-04-11 16:22:50 +00:00
										 |  |  |                     $output .= "['" . substr($index, 1) . "']"; | 
					
						
							| 
									
										
										
										
											2002-12-16 17:50:29 +00:00
										 |  |  |             } else if (substr($index,0,2) == '->') { | 
					
						
							| 
									
										
										
										
											2003-02-10 17:46:58 +00:00
										 |  |  | 				if(substr($index,2,2) == '__') { | 
					
						
							|  |  |  | 					$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							|  |  |  | 				} elseif($this->security && substr($index,2,1) == '_') { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  | 					$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2002-12-16 17:50:29 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-02-18 19:58:32 +00:00
										 |  |  |                 $output .= $index; | 
					
						
							|  |  |  | 			} elseif ($index{0} == '(') { | 
					
						
							|  |  |  | 				$index = $this->_parse_parenth_args($index); | 
					
						
							|  |  |  |                 $output .= $index; | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 $output .= $index; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2002-12-16 17:50:29 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $this->_parse_modifiers($output, $modifiers); | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * parse arguments in function call parenthesis | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $parenth_args | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2003-01-21 20:39:09 +00:00
										 |  |  |     function _parse_parenth_args($parenth_args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 		preg_match_all('!' . $this->_param_regexp . '!',$parenth_args, $match); | 
					
						
							|  |  |  | 		$match = $match[0]; | 
					
						
							|  |  |  | 		rsort($match); | 
					
						
							|  |  |  | 		reset($match);						 | 
					
						
							|  |  |  | 		$orig_vals = $match; | 
					
						
							|  |  |  | 		$this->_parse_vars_props($match); | 
					
						
							|  |  |  | 		return str_replace($orig_vals, $match, $parenth_args); | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * parse configuration variable expression into PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $conf_var_expr | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_conf_var($conf_var_expr) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-05-15 14:24:06 +00:00
										 |  |  |         $parts = explode('|', $conf_var_expr, 2); | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         $var_ref = $parts[0]; | 
					
						
							|  |  |  |         $modifiers = isset($parts[1]) ? $parts[1] : ''; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $var_name = substr($var_ref, 1, -1); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 17:17:53 +00:00
										 |  |  |         $output = "\$this->_config[0]['vars']['$var_name']"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $this->_parse_modifiers($output, $modifiers); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * parse section property expression into PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $section_prop_expr | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_section_prop($section_prop_expr) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2001-05-15 14:24:06 +00:00
										 |  |  |         $parts = explode('|', $section_prop_expr, 2); | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |         $var_ref = $parts[0]; | 
					
						
							|  |  |  |         $modifiers = isset($parts[1]) ? $parts[1] : ''; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         preg_match('!%(\w+)\.(\w+)%!', $var_ref, $match); | 
					
						
							|  |  |  |         $section_name = $match[1]; | 
					
						
							|  |  |  |         $prop_name = $match[2]; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         $output = "\$this->_sections['$section_name']['$prop_name']"; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         $this->_parse_modifiers($output, $modifiers); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * parse modifier chain into PHP code | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |      * sets $output to parsed modified chain | 
					
						
							|  |  |  | 	 * @param string $output | 
					
						
							|  |  |  | 	 * @param string $modifier_string | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |     function _parse_modifiers(&$output, $modifier_string) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |         preg_match_all('!\|(@?\w+)((?>:(?:'. $this->_qstr_regexp . '|[^|]+))*)!', '|' . $modifier_string, $_match); | 
					
						
							|  |  |  |         list(, $_modifiers, $modifier_arg_strings) = $_match; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |         for ($_i = 0, $_for_max = count($_modifiers); $_i < $_for_max; $_i++) { | 
					
						
							|  |  |  |             $_modifier_name = $_modifiers[$_i]; | 
					
						
							| 
									
										
										
										
											2002-07-17 21:56:41 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  | 			if($_modifier_name == 'smarty') { | 
					
						
							| 
									
										
										
										
											2002-07-17 21:56:41 +00:00
										 |  |  | 				// skip smarty modifier
 | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |             preg_match_all('!:(' . $this->_qstr_regexp . '|[^:]+)!', $modifier_arg_strings[$_i], $_match); | 
					
						
							|  |  |  |             $_modifier_args = $_match[1]; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |             if ($_modifier_name{0} == '@') { | 
					
						
							|  |  |  |                 $_map_array = 'false'; | 
					
						
							|  |  |  |                 $_modifier_name = substr($_modifier_name, 1); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |                 $_map_array = 'true'; | 
					
						
							| 
									
										
										
										
											2001-06-15 14:52:48 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2002-07-17 21:56:41 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |             $this->_add_plugin('modifier', $_modifier_name); | 
					
						
							|  |  |  |             $this->_parse_vars_props($_modifier_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  | 			if($_modifier_name == 'default') { | 
					
						
							|  |  |  | 				// supress notifications of default modifier vars and args
 | 
					
						
							|  |  |  | 				if($output{0} == '$') { | 
					
						
							|  |  |  | 					$output = '@' . $output; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-03-20 14:31:18 +00:00
										 |  |  | 				if(isset($_modifier_args[0]) && $_modifier_args[0]{0} == '$') { | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  | 					$_modifier_args[0] = '@' . $_modifier_args[0]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  |             if (count($_modifier_args) > 0) | 
					
						
							|  |  |  |                 $_modifier_args = ', '.implode(', ', $_modifier_args); | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |                 $_modifier_args = ''; | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-15 20:47:29 +00:00
										 |  |  |             $output = "\$this->_run_mod_handler('$_modifier_name', $_map_array, $output$_modifier_args)"; | 
					
						
							| 
									
										
										
										
											2001-03-02 23:13:01 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * add plugin | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $type | 
					
						
							|  |  |  | 	 * @param string $name | 
					
						
							|  |  |  | 	 * @param boolean? $delayed_loading | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |     function _add_plugin($type, $name, $delayed_loading = null) | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (!isset($this->_plugin_info[$type])) { | 
					
						
							|  |  |  |             $this->_plugin_info[$type] = array(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!isset($this->_plugin_info[$type][$name])) { | 
					
						
							|  |  |  |             $this->_plugin_info[$type][$name] = array($this->_current_file, | 
					
						
							| 
									
										
										
										
											2002-03-19 22:21:22 +00:00
										 |  |  |                                                       $this->_current_line_no, | 
					
						
							|  |  |  |                                                       $delayed_loading); | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Compiles references of type $smarty.foo | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $indexes | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |     function _compile_smarty_ref(&$indexes) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /* Extract the reference name. */ | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  |         $_ref = substr($indexes[0], 1); | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 		foreach($indexes as $_index) {		 | 
					
						
							|  |  |  |         	if ($_index{0} != '.') { | 
					
						
							|  |  |  |             	$this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							|  |  |  |         	} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  |         switch ($_ref) { | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'now': | 
					
						
							|  |  |  |                 $compiled_ref = 'time()'; | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_max_index = 1; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'foreach': | 
					
						
							| 
									
										
										
										
											2001-11-29 21:19:39 +00:00
										 |  |  |             case 'section': | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |                 array_shift($indexes); | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  |                 $_var = $this->_parse_var_props(substr($indexes[0], 1)); | 
					
						
							|  |  |  |                 if ($_ref == 'foreach') | 
					
						
							|  |  |  |                     $compiled_ref = "\$this->_foreach[$_var]"; | 
					
						
							| 
									
										
										
										
											2001-11-29 21:19:39 +00:00
										 |  |  |                 else | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  |                     $compiled_ref = "\$this->_sections[$_var]"; | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'get': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_GET_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'post': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_POST_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'cookies': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_COOKIE_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'env': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_ENV_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'server': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_SERVER_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'session': | 
					
						
							| 
									
										
										
										
											2002-09-24 19:31:31 +00:00
										 |  |  |                 $compiled_ref = "\$GLOBALS['HTTP_SESSION_VARS']"; | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             /* | 
					
						
							|  |  |  |              * These cases are handled either at run-time or elsewhere in the | 
					
						
							|  |  |  |              * compiler. | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             case 'request': | 
					
						
							| 
									
										
										
										
											2002-02-15 20:50:44 +00:00
										 |  |  |                 $this->_init_smarty_vars = true; | 
					
						
							|  |  |  |                 return null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 20:04:47 +00:00
										 |  |  |             case 'capture': | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |                 return null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-03 16:31:59 +00:00
										 |  |  |             case 'template': | 
					
						
							|  |  |  |                 $compiled_ref = "'$this->_current_file'"; | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_max_index = 1; | 
					
						
							| 
									
										
										
										
											2002-04-03 16:31:59 +00:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2002-06-27 14:25:25 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 			case 'version': | 
					
						
							|  |  |  | 				$compiled_ref = "'$this->_version'"; | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_max_index = 1; | 
					
						
							| 
									
										
										
										
											2002-06-27 14:25:25 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2002-04-03 16:31:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  | 			case 'const': | 
					
						
							|  |  |  |                 array_shift($indexes); | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_val = $this->_parse_var_props(substr($indexes[0],1)); | 
					
						
							| 
									
										
										
										
											2003-02-28 16:36:19 +00:00
										 |  |  | 				$compiled_ref = '@constant(' . $_val . ')'; | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_max_index = 1; | 
					
						
							| 
									
										
										
										
											2002-12-19 17:02:11 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-24 14:51:47 +00:00
										 |  |  |             case 'config': | 
					
						
							|  |  |  |                 $compiled_ref = "\$this->_config[0]['vars']"; | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  | 				$_max_index = 2; | 
					
						
							| 
									
										
										
										
											2003-02-24 14:51:47 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |             default: | 
					
						
							| 
									
										
										
										
											2003-03-19 12:51:34 +00:00
										 |  |  |                 $this->_syntax_error('$smarty.' . $_ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-27 17:32:08 +00:00
										 |  |  |         if (isset($_max_index) && count($indexes) > $_max_index) { | 
					
						
							|  |  |  |             $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-27 15:27:22 +00:00
										 |  |  |         array_shift($indexes); | 
					
						
							|  |  |  |         return $compiled_ref; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-05-22 15:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-16 20:04:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * load pre- and post-filters | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |     function _load_filters() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-04-16 20:04:06 +00:00
										 |  |  |         if (count($this->_plugins['prefilter']) > 0) { | 
					
						
							|  |  |  |             foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { | 
					
						
							|  |  |  |                 if ($prefilter === false) { | 
					
						
							|  |  |  |                     unset($this->_plugins['prefilter'][$filter_name]); | 
					
						
							|  |  |  |                     $this->_load_plugins(array(array('prefilter', $filter_name, null, null, false))); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (count($this->_plugins['postfilter']) > 0) { | 
					
						
							|  |  |  |             foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { | 
					
						
							|  |  |  |                 if ($postfilter === false) { | 
					
						
							|  |  |  |                     unset($this->_plugins['postfilter'][$filter_name]); | 
					
						
							|  |  |  |                     $this->_load_plugins(array(array('postfilter', $filter_name, null, null, false))); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-04-16 20:04:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-31 20:49:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * display Smarty syntax error | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  | 	 * @param string $error_msg | 
					
						
							|  |  |  | 	 * @param integer $error_type | 
					
						
							|  |  |  | 	 * @param string $file | 
					
						
							|  |  |  | 	 * @param integer $line | 
					
						
							| 
									
										
										
										
											2003-01-29 22:51:20 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  |     function _syntax_error($error_msg, $error_type = E_USER_ERROR, $file=null, $line=null) | 
					
						
							| 
									
										
										
										
											2001-03-08 20:24:38 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2002-12-24 17:07:43 +00:00
										 |  |  | 		if(isset($file) && isset($line)) { | 
					
						
							|  |  |  | 			$info = ' ('.basename($file).", line $line)"; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$info = null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  |         trigger_error('Smarty: [in ' . $this->_current_file . ' line ' . | 
					
						
							|  |  |  |                       $this->_current_line_no . "]: syntax error: $error_msg$info", $error_type); | 
					
						
							| 
									
										
										
										
											2001-03-08 20:24:38 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-30 16:48:55 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * compare to values by their string length | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @access private | 
					
						
							| 
									
										
										
										
											2003-02-16 05:09:19 +00:00
										 |  |  |  * @param string $a | 
					
						
							|  |  |  |  * @param string $b | 
					
						
							| 
									
										
										
										
											2003-01-30 16:48:55 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | function _smarty_sort_length($a, $b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if($a == $b) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(strlen($a) == strlen($b)) | 
					
						
							|  |  |  | 		return ($a > $b) ? -1 : 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (strlen($a) > strlen($b)) ? -1 : 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 18:55:28 +00:00
										 |  |  | /* vim: set et: */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-02 21:38:42 +00:00
										 |  |  | ?>
 |