You are here

function brilliant_gallery_rmdir_recursive in Brilliant Gallery 6.4

Same name and namespace in other branches
  1. 6.3 brilliant_gallery.module \brilliant_gallery_rmdir_recursive()
  2. 7 brilliant_gallery_cron.inc \brilliant_gallery_rmdir_recursive()
1 call to brilliant_gallery_rmdir_recursive()
brilliant_gallery_cleantmpdir in ./cron.inc

File

./cron.inc, line 59

Code

function brilliant_gallery_rmdir_recursive($dir, $timestampexpired) {

  #return; // TEMP SAFETY - TO BE CORRECTED LATER!

  // Remove '/' at the end, if any
  $slash = '/';
  if (substr($dir, -1) == '/') {
    $slash = '';
  }
  $files = scandir($dir);
  array_shift($files);

  // remove '.' from array
  array_shift($files);

  // remove '..' from array
  foreach ($files as $file) {
    $filename = $file;
    $file = $dir . $slash . $file;

    //watchdog('Brilliant Gal Cron','1: '.$timestampexpired);

    //drupal_set_message('1: '.$timestampexpired);
    if (is_dir($file)) {
      if (substr(strtolower($filename), 0, strlen('bg_picasa_orig_')) == 'bg_picasa_orig_') {

        // Only delete files that start 'bg_picasa_orig_' OR 'bg_cached_resized_'

        //drupal_set_message('folder: '.$filename);

        //watchdog('Brilliant Gal Cron','folder: '.$filename);

        //brilliant_gallery_rmdir_recursive($file, $timestampexpired);

        #drupal_set_message('dir: '.$file.' ('.$timestampexpired.')'); flush();
        @rmdir($file);
      }
    }
    else {

      #unlink($file);
      $suffix = strtolower(brilliant_gallery_get_extension($filename));

      //drupal_set_message('2: '.$filename.'...'.$suffix);
      if ($suffix == 'jpg' or $suffix == 'jpeg' or $suffix == 'png' or $suffix == 'gif') {

        # It is a file in the specified BG cache directory

        //drupal_set_message('3: '.$file.'...'.$suffix);

        //watchdog('Brilliant Gal Cron','3: '.$file.'...'.$suffix);

        #watchdog('Brilliant Gal Cron','file: '.$file . '('.@filemtime($file));
        if (@filemtime($file) < $timestampexpired) {

          #drupal_set_message('file: '.$file . '('.filemtime($file).' = '.date('Y-m-d H:i:s',filemtime($file)).') (++'.$GLOBALS['bg_removedcnt'].')');
          $unlinked = unlink($file);
          if ($unlinked) {
            $GLOBALS['bg_removedcnt']++;
          }
        }
      }
    }
  }
}