| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage PluginsShared | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * evaluate compiler parameter | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-11-14 14:53:16 +00:00
										 |  |  |  * @param array   $params  parameter array as given to the compiler function
 | 
					
						
							|  |  |  |  * @param integer $index   array index of the parameter to convert | 
					
						
							|  |  |  |  * @param mixed   $default value to be returned if the parameter is not present | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-11-14 14:53:16 +00:00
										 |  |  |  * @return mixed evaluated value of parameter or $default | 
					
						
							|  |  |  |  * @throws SmartyException if parameter is not a literal (but an expression, variable, …) | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @author Rodney Rehm | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  | function smarty_literal_compiler_param($params, $index, $default = null) | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     // not set, go default
 | 
					
						
							|  |  |  |     if (!isset($params[$index])) { | 
					
						
							|  |  |  |         return $default; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // test if param is a literal
 | 
					
						
							| 
									
										
										
										
											2014-02-05 19:39:21 +00:00
										 |  |  |     if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[$index])) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $t = null; | 
					
						
							|  |  |  |     eval("\$t = " . $params[$index] . ";"); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     return $t; | 
					
						
							|  |  |  | } |