You are here

function brilliant_gallery_rmdir_recursive in Brilliant Gallery 6.3

Same name and namespace in other branches
  1. 6.4 cron.inc \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 ./brilliant_gallery.module

File

./brilliant_gallery.module, line 1135

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','file: '.$file . '('.@filemtime($file));
    if (is_dir($file)) {
      if (substr(strtolower($filename), 0, strlen('bg_picasa_')) == 'bg_picasa_') {

        // Only delete folders that start 'bg_picasa_'
        brilliant_gallery_rmdir_recursive($file, $timestampexpired);

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

      #unlink($file);
      $suffix = strtolower(substr($filename, -4));
      if ($suffix == '.jpg' or $suffix == 'jpeg' or $suffix == '.png' or $suffix == '.gif' or strtolower(substr($filename, 0, 3)) == 'bg_') {

        # It is a file in the specified BG cache directory

        #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);

          #drupal_set_message('file: '.$filepathname);
          if ($unlinked) {
            $GLOBALS['bg_removedcnt']++;
          }
        }
      }
    }
  }
}