| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |  * Smarty Method CompileAllTemplates | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |  * Smarty::compileAllTemplates() method | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  * @author     Uwe Tews | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  | class Smarty_Internal_Method_CompileAllTemplates | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Valid for Smarty object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $objMap = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Compile all template files | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @api  Smarty::compileAllTemplates() | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-05-27 22:22:57 +02:00
										 |  |  |      * @param \Smarty $smarty        passed smarty object | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      * @param  string $extension     file extension | 
					
						
							|  |  |  |      * @param  bool   $force_compile force all to recompile | 
					
						
							|  |  |  |      * @param  int    $time_limit | 
					
						
							|  |  |  |      * @param  int    $max_errors | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return integer number of template files recompiled | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-13 01:49:38 +02:00
										 |  |  |     public function compileAllTemplates(Smarty $smarty, $extension = '.tpl', $force_compile = false, $time_limit = 0, | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                                         $max_errors = null) | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->compileAll($smarty, $extension, $force_compile, $time_limit, $max_errors); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Compile all template or config files | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      * @param \Smarty $smarty | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |      * @param  string $extension     template file name extension | 
					
						
							|  |  |  |      * @param  bool   $force_compile force all to recompile | 
					
						
							|  |  |  |      * @param  int    $time_limit    set maximum execution time | 
					
						
							|  |  |  |      * @param  int    $max_errors    set maximum allowed errors | 
					
						
							|  |  |  |      * @param bool    $isConfig      flag true if called for config files | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int number of template files compiled | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     protected function compileAll(Smarty $smarty, $extension, $force_compile, $time_limit, $max_errors, | 
					
						
							|  |  |  |                                   $isConfig = false) | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         // switch off time limit
 | 
					
						
							|  |  |  |         if (function_exists('set_time_limit')) { | 
					
						
							|  |  |  |             @set_time_limit($time_limit); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $_count = 0; | 
					
						
							|  |  |  |         $_error_count = 0; | 
					
						
							|  |  |  |         $sourceDir = $isConfig ? $smarty->getConfigDir() : $smarty->getTemplateDir(); | 
					
						
							|  |  |  |         // loop over array of source directories
 | 
					
						
							|  |  |  |         foreach ($sourceDir as $_dir) { | 
					
						
							| 
									
										
										
										
											2016-07-14 20:32:41 +02:00
										 |  |  |             $_dir_1 = new RecursiveDirectoryIterator($_dir, defined('FilesystemIterator::FOLLOW_SYMLINKS') ? | 
					
						
							|  |  |  |                 FilesystemIterator::FOLLOW_SYMLINKS : 0); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |             $_dir_2 = new RecursiveIteratorIterator($_dir_1); | 
					
						
							|  |  |  |             foreach ($_dir_2 as $_fileinfo) { | 
					
						
							|  |  |  |                 $_file = $_fileinfo->getFilename(); | 
					
						
							|  |  |  |                 if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) { | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (!substr_compare($_file, $extension, - strlen($extension)) == 0) { | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-12-21 14:27:26 +01:00
										 |  |  |                 if ($_fileinfo->getPath() !== substr($_dir, 0, - 1)) { | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |                     $_file = substr($_fileinfo->getPath(), strlen($_dir)) . $smarty->ds . $_file; | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 echo "\n<br>", $_dir, '---', $_file; | 
					
						
							|  |  |  |                 flush(); | 
					
						
							|  |  |  |                 $_start_time = microtime(true); | 
					
						
							|  |  |  |                 $_smarty = clone $smarty; | 
					
						
							| 
									
										
										
										
											2016-05-27 22:22:57 +02:00
										 |  |  |                 // 
 | 
					
						
							|  |  |  |                 $_smarty->_cache = array(); | 
					
						
							|  |  |  |                 $_smarty->ext = new Smarty_Internal_Extension_Handler(); | 
					
						
							|  |  |  |                 $_smarty->ext->objType = $_smarty->_objType; | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |                 $_smarty->force_compile = $force_compile; | 
					
						
							|  |  |  |                 try { | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |                     /* @var Smarty_Internal_Template $_tpl */ | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |                     $_tpl = new $smarty->template_class($_file, $_smarty); | 
					
						
							|  |  |  |                     $_tpl->caching = Smarty::CACHING_OFF; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     $_tpl->source = | 
					
						
							|  |  |  |                         $isConfig ? Smarty_Template_Config::load($_tpl) : Smarty_Template_Source::load($_tpl); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |                     if ($_tpl->mustCompile()) { | 
					
						
							|  |  |  |                         $_tpl->compileTemplateSource(); | 
					
						
							|  |  |  |                         $_count ++; | 
					
						
							|  |  |  |                         echo ' compiled in  ', microtime(true) - $_start_time, ' seconds'; | 
					
						
							|  |  |  |                         flush(); | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         echo ' is up to date'; | 
					
						
							|  |  |  |                         flush(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 catch (Exception $e) { | 
					
						
							|  |  |  |                     echo "\n<br>        ------>Error: ", $e->getMessage(), "<br><br>\n"; | 
					
						
							|  |  |  |                     $_error_count ++; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 // free memory
 | 
					
						
							|  |  |  |                 unset($_tpl); | 
					
						
							| 
									
										
										
										
											2015-12-27 05:43:11 +01:00
										 |  |  |                 $_smarty->_clearTemplateCache(); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:29:36 +02:00
										 |  |  |                 if ($max_errors !== null && $_error_count == $max_errors) { | 
					
						
							|  |  |  |                     echo "\n<br><br>too many errors\n"; | 
					
						
							|  |  |  |                     exit(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         echo "\n<br>"; | 
					
						
							|  |  |  |         return $_count; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-27 05:43:11 +01:00
										 |  |  | } |