Changeset 12797 for trunk/admin/include/functions.php
- Timestamp:
- Dec 27, 2011, 9:26:49 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r12763 r12797 2247 2247 return array_from_query($query, 'user_id'); 2248 2248 } 2249 2250 function clear_derivative_cache($type='all') 2251 { 2252 $pattern='#.*-'; 2253 if ($type == 'all') 2254 { 2255 $type_urls = array(); 2256 foreach(ImageStdParams::get_all_types() as $dtype) 2257 { 2258 $type_urls[] = derivative_to_url($dtype); 2259 } 2260 $type_urls[] = derivative_to_url(IMG_CUSTOM); 2261 $pattern .= '(' . implode('|',$type_urls) . ')'; 2262 } 2263 else 2264 { 2265 $pattern .= derivative_to_url($type); 2266 } 2267 $pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#'; 2268 if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR)) 2269 { 2270 while (($node = readdir($contents)) !== false) 2271 { 2272 if ($node != '.' 2273 and $node != '..' 2274 and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node)) 2275 { 2276 clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern); 2277 } 2278 } 2279 closedir($contents); 2280 } 2281 } 2282 2283 function clear_derivative_cache_rec($path, $pattern) 2284 { 2285 $rmdir = true; 2286 $rm_index = false; 2287 2288 if ($contents = opendir($path)) 2289 { 2290 while (($node = readdir($contents)) !== false) 2291 { 2292 if ($node == '.' or $node == '..') 2293 continue; 2294 if (is_dir($path.'/'.$node)) 2295 { 2296 $rmdir &= clear_derivative_cache_rec($path.'/'.$node, $pattern); 2297 } 2298 else 2299 { 2300 if (preg_match($pattern, $node)) 2301 { 2302 unlink($path.'/'.$node); 2303 } 2304 elseif ($node=='index.htm') 2305 { 2306 $rm_index = true; 2307 } 2308 else 2309 { 2310 $rmdir = false; 2311 } 2312 } 2313 } 2314 closedir($contents); 2315 2316 if ($rmdir) 2317 { 2318 if ($rm_index) 2319 { 2320 unlink($path.'/index.htm'); 2321 } 2322 clearstatcache(); 2323 rmdir($path); 2324 } 2325 return $rmdir; 2326 } 2327 } 2249 2328 ?>
Note: See TracChangeset
for help on using the changeset viewer.