You are here

private function LocalFolderProvider::getImages in Devel images provider 7

Same name and namespace in other branches
  1. 8 plugins/devel_image_provider/provider/LocalFolderProvider.class.php \LocalFolderProvider::getImages()

Helper function to get all the images from the configured folder.

1 call to LocalFolderProvider::getImages()
LocalFolderProvider::generateImage in plugins/devel_image_provider/provider/LocalFolderProvider.class.php
Image generation handler.

File

plugins/devel_image_provider/provider/LocalFolderProvider.class.php, line 111
Local folder support class.

Class

LocalFolderProvider
Add support for local images.

Code

private function getImages() {
  if ($files = cache_get('devel_image_provider_local')) {
    return $files->data;
  }
  $files = array();
  $count = 1;

  // Limiting number of images to find to 100.
  // @TODO: add this as a setting.
  $max_count = 100;

  // Remove trailing slash.
  $dir = rtrim($this->settings['devel_image_provider_path'], '/');
  if (is_dir($dir) && ($handle = opendir($dir))) {
    while (FALSE !== ($filename = readdir($handle)) && $count <= $max_count) {
      $path = "{$dir}/{$filename}";
      if ($filename[0] != '.' && preg_match('/.*\\.(jpg|jpeg|png)$/i', $filename) && ($image = image_get_info($path))) {
        $file = new stdClass();
        $file->uri = file_stream_wrapper_uri_normalize($path);
        $file->filename = $filename;
        $file->filemime = $image['mime_type'];
        $file->name = pathinfo($filename, PATHINFO_FILENAME);
        $files[$file->uri] = $file;
        $count++;
      }
    }
    closedir($handle);
  }
  cache_set('devel_image_provider_local', $files, 'cache', CACHE_TEMPORARY);
  return $files;
}