| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Internal Plugin Function Call Handler | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @subpackage PluginsInternal | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |  * This class does handles template functions defined with the {function} tag missing in cache file. | 
					
						
							|  |  |  |  * It can happen when the template function was called with the nocache option or within a nocache section. | 
					
						
							|  |  |  |  * The template function will be loaded from it's compiled template file, executed and added to the cache file | 
					
						
							|  |  |  |  * for later use. | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Smarty_Internal_Function_Call_Handler | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * This function handles calls to template functions defined by {function} | 
					
						
							|  |  |  |      * It does create a PHP function at the first call | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-12-30 16:43:42 +01:00
										 |  |  |      * @param string                   $_name     template function name | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |      * @param Smarty_Internal_Template $_smarty_tpl | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |      * @param string                   $_function PHP function name | 
					
						
							| 
									
										
										
										
											2014-12-30 16:43:42 +01:00
										 |  |  |      * @param array                    $_params   Smarty variables passed as call parameter | 
					
						
							|  |  |  |      * @param bool                     $_nocache  nocache flag | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |     public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache) | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |         $funcParam = $_smarty_tpl->properties['tpl_function']['param'][$_name]; | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |         if (is_file($funcParam['compiled_filepath'])) { | 
					
						
							|  |  |  |             // read compiled file
 | 
					
						
							|  |  |  |             $code = file_get_contents($funcParam['compiled_filepath']); | 
					
						
							|  |  |  |             // grab template function
 | 
					
						
							|  |  |  |             if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) { | 
					
						
							| 
									
										
										
										
											2014-11-10 23:57:30 +01:00
										 |  |  |                 // grab source info from file dependency
 | 
					
						
							| 
									
										
										
										
											2014-12-30 16:43:42 +01:00
										 |  |  |                 preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1); | 
					
						
							|  |  |  |                 unset($code); | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |                 $output = ''; | 
					
						
							|  |  |  |                 // make PHP function known
 | 
					
						
							| 
									
										
										
										
											2014-11-10 23:57:30 +01:00
										 |  |  |                 eval($match[0]); | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |                 if (function_exists($_function)) { | 
					
						
							|  |  |  |                     // search cache file template
 | 
					
						
							|  |  |  |                     $tplPtr = $_smarty_tpl; | 
					
						
							|  |  |  |                     while (!isset($tplPtr->cached) && isset($tplPtr->parent)) { | 
					
						
							|  |  |  |                         $tplPtr = $tplPtr->parent; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     // add template function code to cache file
 | 
					
						
							|  |  |  |                     if (isset($tplPtr->cached)) { | 
					
						
							|  |  |  |                         $cache = $tplPtr->cached; | 
					
						
							|  |  |  |                         $content = $cache->read($tplPtr); | 
					
						
							|  |  |  |                         if ($content) { | 
					
						
							| 
									
										
										
										
											2014-12-30 16:43:42 +01:00
										 |  |  |                             // check if we must update file dependency
 | 
					
						
							| 
									
										
										
										
											2015-01-02 08:20:57 +01:00
										 |  |  |                             if (!preg_match("/'{$funcParam['uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) { | 
					
						
							| 
									
										
										
										
											2014-11-10 23:57:30 +01:00
										 |  |  |                                 $content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             $cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n"); | 
					
						
							| 
									
										
										
										
											2014-11-08 17:19:53 +01:00
										 |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |