| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |  * Smarty Internal Plugin Config File Compiler | 
					
						
							|  |  |  |  * This is the config file compiler class. It calls the lexer and parser to | 
					
						
							|  |  |  |  * perform the compiling. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |  * @subpackage Config | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |  * Main config file compiler class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Config | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Config_File_Compiler | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Lexer class name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $lexer_class; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Parser class name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $parser_class; | 
					
						
							| 
									
										
										
										
											2015-07-20 03:15:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Lexer object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var object | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $lex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Parser object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var object | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Smarty object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var Smarty object | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $smarty; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Smarty object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |      * @var Smarty_Internal_Template object | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |     public $template; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Compiled config data sections and variables | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $config_data = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * compiled config data must always be written | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $write_compiled_code = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Initialize compiler | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |      * @param string $lexer_class  class name | 
					
						
							|  |  |  |      * @param string $parser_class class name | 
					
						
							|  |  |  |      * @param Smarty $smarty       global instance | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |     public function __construct($lexer_class, $parser_class, Smarty $smarty) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         $this->smarty = $smarty; | 
					
						
							|  |  |  |         // get required plugins
 | 
					
						
							|  |  |  |         $this->lexer_class = $lexer_class; | 
					
						
							|  |  |  |         $this->parser_class = $parser_class; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $this->smarty = $smarty; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $this->config_data['sections'] = array(); | 
					
						
							|  |  |  |         $this->config_data['vars'] = array(); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |      * Method to compile Smarty config source. | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |      * @param Smarty_Internal_Template $template | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |      * @return bool true if compiling succeeded, false if it failed | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |     public function compileTemplate(Smarty_Internal_Template $template) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         $this->template = $template; | 
					
						
							| 
									
										
										
										
											2015-08-09 21:14:16 +02:00
										 |  |  |         $this->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, | 
					
						
							| 
									
										
										
										
											2015-07-20 03:15:45 +02:00
										 |  |  |                                                                                              $this->template->source->getTimeStamp(), | 
					
						
							|  |  |  |                                                                                              $this->template->source->type); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         if ($this->smarty->debugging) { | 
					
						
							| 
									
										
										
										
											2015-08-19 00:58:47 +02:00
										 |  |  |             $this->smarty->_debug->start_compile($this->template); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // init the lexer/parser to compile the config file
 | 
					
						
							| 
									
										
										
										
											2015-07-20 03:15:45 +02:00
										 |  |  |         $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . | 
					
						
							|  |  |  |                                       "\n", $this); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         $parser = new $this->parser_class($lex, $this); | 
					
						
							| 
									
										
										
										
											2014-06-17 20:24:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { | 
					
						
							|  |  |  |             $mbEncoding = mb_internal_encoding(); | 
					
						
							|  |  |  |             mb_internal_encoding('ASCII'); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $mbEncoding = null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         if ($this->smarty->_parserdebug) { | 
					
						
							|  |  |  |             $parser->PrintTrace(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // get tokens from lexer and parse them
 | 
					
						
							|  |  |  |         while ($lex->yylex()) { | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             if ($this->smarty->_parserdebug) { | 
					
						
							|  |  |  |                 echo "<br>Parsing  {$parser->yyTokenName[$lex->token]} Token {$lex->value} Line {$lex->line} \n"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             $parser->doParse($lex->token, $lex->value); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // finish parsing process
 | 
					
						
							|  |  |  |         $parser->doParse(0, 0); | 
					
						
							| 
									
										
										
										
											2014-06-17 20:24:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($mbEncoding) { | 
					
						
							|  |  |  |             mb_internal_encoding($mbEncoding); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         if ($this->smarty->debugging) { | 
					
						
							| 
									
										
										
										
											2015-08-19 00:58:47 +02:00
										 |  |  |             $this->smarty->_debug->end_compile($this->template); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         // template header code
 | 
					
						
							| 
									
										
										
										
											2015-07-20 03:15:45 +02:00
										 |  |  |         $template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . | 
					
						
							|  |  |  |             strftime("%Y-%m-%d %H:%M:%S") . "\n"; | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         $template_header .= "         compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; | 
					
						
							| 
									
										
										
										
											2014-06-17 20:24:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         $code = '<?php Smarty_Internal_Method_ConfigLoad::_loadConfigVars($_smarty_tpl, ' . | 
					
						
							| 
									
										
										
										
											2015-07-20 03:15:45 +02:00
										 |  |  |             var_export($this->config_data, true) . '); ?>'; | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |      * display compiler error messages without dying | 
					
						
							|  |  |  |      * If parameter $args is empty it is a parser detected syntax error. | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * In this case the parser is called to obtain information about expected tokens. | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |      * If parameter $args contains a string this is used as error message | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param string $args individual error message or null | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     public function trigger_config_file_error($args = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->lex = Smarty_Internal_Configfilelexer::instance(); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $this->parser = Smarty_Internal_Configfileparser::instance(); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         // get config source line which has error
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $line = $this->lex->line; | 
					
						
							|  |  |  |         if (isset($args)) { | 
					
						
							| 
									
										
										
										
											2010-03-29 15:41:01 +00:00
										 |  |  |             // $line--;
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $match = preg_split("/\n/", $this->lex->data); | 
					
						
							| 
									
										
										
										
											2015-01-02 12:11:21 +01:00
										 |  |  |         $error_text = "Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' "; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         if (isset($args)) { | 
					
						
							|  |  |  |             // individual error message
 | 
					
						
							|  |  |  |             $error_text .= $args; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             // expected token from parser
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { | 
					
						
							|  |  |  |                 $exp_token = $this->parser->yyTokenName[$token]; | 
					
						
							|  |  |  |                 if (isset($this->lex->smarty_token_names[$exp_token])) { | 
					
						
							|  |  |  |                     // token type from lexer
 | 
					
						
							|  |  |  |                     $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     // otherwise internal token name
 | 
					
						
							|  |  |  |                     $expect[] = $this->parser->yyTokenName[$token]; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // output parser error message
 | 
					
						
							|  |  |  |             $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-08-13 10:39:51 +00:00
										 |  |  |         throw new SmartyCompilerException($error_text); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |