| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty method Clear_Compiled_Tpl | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * Deletes compiled template files | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * @package Smarty | 
					
						
							|  |  |  | * @subpackage SmartyMethod | 
					
						
							|  |  |  | * @author Uwe Tews  | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  | * Delete compiled template file | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | *  | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  | * @param string $resource_name template name | 
					
						
							|  |  |  | * @param string $compile_id compile id | 
					
						
							|  |  |  | * @param integer $exp_time expiration time | 
					
						
							|  |  |  | * @return integer number of template files deleted | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  | function clear_compiled_tpl($smarty, $resource_name = null, $compile_id = null, $exp_time = null) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-29 22:57:29 +00:00
										 |  |  |     $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |     if (isset($resource_name)) { | 
					
						
							|  |  |  |         $_resource_part_1 = $resource_name . $smarty->php_ext; | 
					
						
							|  |  |  |         $_resource_part_2 = $resource_name . '.cache' . $smarty->php_ext; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $_resource_part = ''; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  |     $_dir = $smarty->compile_dir; | 
					
						
							|  |  |  |     if ($smarty->use_sub_dirs && isset($compile_id)) { | 
					
						
							|  |  |  |         $_dir .= $compile_id . $_dir_sep; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  |     if (isset($compile_id)) { | 
					
						
							|  |  |  |         $_compile_id_part = $smarty->compile_dir . $compile_id . $_dir_sep; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  |     $_count = 0; | 
					
						
							|  |  |  |     $_compileDirs = new RecursiveDirectoryIterator($_dir); | 
					
						
							|  |  |  |     $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); | 
					
						
							|  |  |  |     foreach ($_compile as $_file) { | 
					
						
							|  |  |  |         if (strpos($_file, '.svn') !== false) continue; | 
					
						
							|  |  |  |         if ($_file->isDir()) { | 
					
						
							|  |  |  |             if (!$_compile->isDot()) { | 
					
						
							|  |  |  |                 // delete folder if empty
 | 
					
						
							|  |  |  |                 @rmdir($_file->getPathname()); | 
					
						
							|  |  |  |             }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |             if ((!isset($compile_id) || substr_compare((string)$_file, $_compile_id_part, 0, strlen($_compile_id_part)) == 0) && | 
					
						
							|  |  |  |                     (!isset($resource_name) || substr_compare((string)$_file, $_resource_part_1, - strlen($_resource_part_1), strlen($_resource_part_1)) == 0 || | 
					
						
							|  |  |  |                         substr_compare((string)$_file, $_resource_part_2, - strlen($_resource_part_2), strlen($_resource_part_2)) == 0)) { | 
					
						
							|  |  |  |                 if (isset($exp_time)) { | 
					
						
							|  |  |  |                     if (time() - @filemtime($_file) >= $exp_time) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                         $_count += unlink((string) $_file) ? 1 : 0; | 
					
						
							|  |  |  |                     }  | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                     $_count += unlink((string) $_file) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 }  | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |     return $_count; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |