| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |  * Smarty Internal Plugin CompileBase | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |  * This class does extend all internal compile plugins | 
					
						
							| 
									
										
										
										
											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 Compiler | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | abstract class Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Array of names of required attribute required by tag | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $required_attributes = array(); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Array of names of optional attribute required by tag | 
					
						
							|  |  |  |      * use array('_any') if there is no restriction of attributes names | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $optional_attributes = array(); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Shorttag attribute order defined by its names | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $shorttag_order = array(); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Array of names of valid option flags | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $option_flags = array('nocache'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-14 20:57:21 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-08-06 05:01:15 +02:00
										 |  |  |      * Mapping array for boolean option value | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-02-14 20:57:21 +01:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |     public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-14 20:57:21 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Mapping array with attributes as key | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-02-14 20:57:21 +01:00
										 |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |     public $mapCache = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * This function checks if the attributes passed are valid | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * The attributes passed for the tag to compile are checked against the list of required and | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * optional attributes. Required attributes must be present. Optional attributes are check against | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * the corresponding list. The keyword '_any' specifies that any attribute will be accepted | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * as valid | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param object $compiler   compiler object | 
					
						
							|  |  |  |      * @param array  $attributes attributes applied to the tag | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return array  of mapped attributes for further processing | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function getAttributes($compiler, $attributes) | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_indexed_attr = array(); | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |         if (!isset($this->mapCache[ 'option' ])) { | 
					
						
							|  |  |  |             $this->mapCache[ 'option' ] = array_fill_keys($this->option_flags, true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         foreach ($attributes as $key => $mixed) { | 
					
						
							|  |  |  |             // shorthand ?
 | 
					
						
							|  |  |  |             if (!is_array($mixed)) { | 
					
						
							|  |  |  |                 // option flag ?
 | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                 if (isset($this->mapCache[ 'option' ][ trim($mixed, '\'"') ])) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     $_indexed_attr[ trim($mixed, '\'"') ] = true; | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |                     // shorthand attribute ?
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 } elseif (isset($this->shorttag_order[ $key ])) { | 
					
						
							|  |  |  |                     $_indexed_attr[ $this->shorttag_order[ $key ] ] = $mixed; | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                     // too many shorthands
 | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |                     $compiler->trigger_template_error('too many shorthand attributes', null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |                 // named attribute
 | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                 foreach ($mixed as $k => $v) { | 
					
						
							|  |  |  |                     // option flag?
 | 
					
						
							|  |  |  |                     if (isset($this->mapCache[ 'option' ][ $k ])) { | 
					
						
							|  |  |  |                         if (is_bool($v)) { | 
					
						
							|  |  |  |                             $_indexed_attr[ $k ] = $v; | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |                         } else { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                             if (is_string($v)) { | 
					
						
							|  |  |  |                                 $v = trim($v, '\'" '); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             if (isset($this->optionMap[ $v ])) { | 
					
						
							|  |  |  |                                 $_indexed_attr[ $k ] = $this->optionMap[ $v ]; | 
					
						
							|  |  |  |                             } else { | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                                 $compiler->trigger_template_error( | 
					
						
							|  |  |  |                                     "illegal value '" . var_export($v, true) . | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                                     "' for option flag '{$k}'", | 
					
						
							|  |  |  |                                     null, | 
					
						
							|  |  |  |                                     true | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                                 ); | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                         // must be named attribute
 | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |                     } else { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                         $_indexed_attr[ $k ] = $v; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // check if all required attributes present
 | 
					
						
							|  |  |  |         foreach ($this->required_attributes as $attr) { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |             if (!isset($_indexed_attr[ $attr ])) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                 $compiler->trigger_template_error("missing '{$attr}' attribute", null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         // check for not allowed attributes
 | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($this->optional_attributes !== array('_any')) { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |             if (!isset($this->mapCache[ 'all' ])) { | 
					
						
							|  |  |  |                 $this->mapCache[ 'all' ] = | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                     array_fill_keys( | 
					
						
							|  |  |  |                         array_merge( | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                             $this->required_attributes, | 
					
						
							|  |  |  |                             $this->optional_attributes, | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                             $this->option_flags | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                         ), | 
					
						
							|  |  |  |                         true | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             foreach ($_indexed_attr as $key => $dummy) { | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |                 if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                     $compiler->trigger_template_error("unexpected '{$key}' attribute", null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         // default 'false' for all option flags not set
 | 
					
						
							|  |  |  |         foreach ($this->option_flags as $flag) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (!isset($_indexed_attr[ $flag ])) { | 
					
						
							|  |  |  |                 $_indexed_attr[ $flag ] = false; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-14 19:58:55 +01:00
										 |  |  |         if (isset($_indexed_attr[ 'nocache' ]) && $_indexed_attr[ 'nocache' ]) { | 
					
						
							|  |  |  |             $compiler->tag_nocache = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         return $_indexed_attr; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * Push opening tag name on stack | 
					
						
							|  |  |  |      * Optionally additional data can be saved on stack | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param object $compiler compiler object | 
					
						
							|  |  |  |      * @param string $openTag  the opening tag's name | 
					
						
							|  |  |  |      * @param mixed  $data     optional data saved | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function openTag($compiler, $openTag, $data = null) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         array_push($compiler->_tag_stack, array($openTag, $data)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      * Pop closing tag | 
					
						
							|  |  |  |      * Raise an error if this stack-top doesn't match with expected opening tags | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param object       $compiler    compiler object | 
					
						
							|  |  |  |      * @param array|string $expectedTag the expected opening tag names | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return mixed        any type the opening tag's name or saved data | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function closeTag($compiler, $expectedTag) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if (count($compiler->_tag_stack) > 0) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // get stacked info
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             list($_openTag, $_data) = array_pop($compiler->_tag_stack); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // open tag must match with the expected ones
 | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             if (in_array($_openTag, (array)$expectedTag)) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 if (is_null($_data)) { | 
					
						
							|  |  |  |                     // return opening tag
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                     return $_openTag; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                     // return restored data
 | 
					
						
							|  |  |  |                     return $_data; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // wrong nesting of tags
 | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             $compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag"); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // wrong nesting of tags
 | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         $compiler->trigger_template_error('unexpected closing tag', null, true); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |