Exemplo n.º 1
0
 function clear_cache($path)
 {
     $base = DOC_ROOT . '/';
     # trim trailing /
     $path = strrpos($path, '/') == strlen($path) - 1 ? substr($path, 0, -1) : $path;
     # parse path
     $dirs = explode('/', $path);
     # if the last item is a * then clear all cache files at that location
     $last = array_pop($dirs);
     if ($last == '*') {
         $targetpath = join('/', $dirs);
         if (file_exists($base . $targetpath)) {
             $dirhandle = opendir($base . $targetpath);
             while (($file = readdir($dirhandle)) !== false) {
                 $pi = pathinfo($file);
                 if ($pi['extension'] == AbstractController::_cache_extension) {
                     unlink($base . $targetpath . '/' . $file);
                 } else {
                     if ($file[0] != '.' && is_dir($base . $targetpath . '/' . $file)) {
                         AbstractController::clear_cache($targetpath . '/' . $file . '/*');
                     }
                 }
             }
             closedir($dirhandle);
         }
         # also delete the cache file for the dir
         if (file_exists($base . $targetpath . '.' . AbstractController::_cache_extension)) {
             unlink($base . $targetpath . '.' . AbstractController::_cache_extension);
         }
     } else {
         unlink($base . $path . '.' . AbstractController::_cache_extension);
     }
 }