Mixin_Cache

The NextGEN Gallery Mixin Cache class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/cache/package.module.cache.php  
  1. class Mixin_Cache extends Mixin 
  2. /** 
  3. * Empties a directory of all of its content 
  4. * @param string $directory Absolute path 
  5. * @param bool $recursive Remove files from subdirectories of the cache 
  6. * @param string $regex (optional) Only remove files matching pattern; '/^.+\.png$/i' will match all .png 
  7. */ 
  8. public function flush_directory($directory, $recursive = TRUE, $regex = NULL) 
  9. // It is possible that the cache directory has not been created yet 
  10. if (!is_dir($directory)) { 
  11. return; 
  12. if ($recursive) { 
  13. $directory = new DirectoryIterator($directory); 
  14. } else { 
  15. $directory = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST); 
  16. if (!is_null($regex)) { 
  17. $iterator = RegexIterator($directory, $regex, RecursiveRegexIterator::GET_MATCH); 
  18. } else { 
  19. $iterator = $directory; 
  20. foreach ($iterator as $file) { 
  21. if ($file->isFile() || $file->isLink()) { 
  22. @unlink($file->getPathname()); 
  23. } elseif ($file->isDir() && !$file->isDot() && $recursive) { 
  24. @rmdir($file->getPathname()); 
  25. /** 
  26. * Flushes cache from all available galleries 
  27. * @param array $galleries When provided only the requested galleries' cache is flushed 
  28. */ 
  29. public function flush_galleries($galleries = array()) 
  30. global $wpdb; 
  31. if (empty($galleries)) { 
  32. $galleries = C_Gallery_Mapper::get_instance()->find_all(); 
  33. foreach ($galleries as $gallery) { 
  34. C_Gallery_Storage::get_instance()->flush_cache($gallery); 
  35. // Remove images still in the DB whose gallery no longer exists 
  36. $wpdb->query("DELETE FROM `{$wpdb->nggpictures}` WHERE `galleryid` NOT IN (SELECT `gid` FROM `{$wpdb->nggallery}`)");