You are here

function brilliant_gallery_deliver_image in Brilliant Gallery 7

Same name and namespace in other branches
  1. 6.4 functions.inc \brilliant_gallery_deliver_image()
  2. 7.2 OLD_brilliant_gallery_functions.inc \brilliant_gallery_deliver_image()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'brilliant_gallery_deliver_image'
brilliant_gallery_menu in ./brilliant_gallery_menu.inc
@todo Please document this function.

File

./brilliant_gallery_functions.inc, line 186

Code

function brilliant_gallery_deliver_image() {
  $queryexplode = explode('/', $_GET['q']);
  $bgimgproperties_hash = array_pop($queryexplode);

  // Get the last item in the query.
  $bgimgproperties_hash = substr($bgimgproperties_hash, strlen('bg_cached_resized_'));

  // Remove prefix.
  // The file name contains a hash token that corresponds to the image parameter array; this relation is in cache.
  $bgimgproperties_hash_array = explode('.', $bgimgproperties_hash);
  $bgimgproperties_hash_array = $bgimgproperties_hash_array[0];
  $bgimgproperties_array = brilliant_gallery_image_properties_get($bgimgproperties_hash_array);
  if (!is_array($bgimgproperties_array)) {
    watchdog('Brilliant Gal', 'Wrong image: ' . $bgimgproperties_hash);
    return;
  }
  foreach ($bgimgproperties_array as $key => $val) {

    //$showthis .= $val.' -- ';
    $_GET[$key] = $val;
  }

  /* Check for bad URL inputs */
  $urlpath = $_GET['imgp'];
  if (sizeof($_GET) > 5 || strpos($urlpath, "://") !== false || strpos($urlpath, "..") !== false || preg_match('/\\D/', $_GET['imgw'] . $_GET['imgh']) > 0 || $_GET['imgw'] + $_GET['imgh'] < 10 || $_GET['imgw'] + $_GET['imgh'] > 20000) {
    header("HTTP/1.0 404 Not Found");
    exit;
  }
  $imagepath = realpath(FILE_DIRECTORY_PATH . $urlpath);

  // Crucial - to suppress Devel (if installed and enabled) output appearing in the generated XML!
  $GLOBALS['devel_shutdown'] = FALSE;
  $my_data = resizeimage_wrapper_dbcache(FALSE, $imagepath, $bgimgproperties_hash);

  // http://be.php.net/getimagesize
  $imgsize = @getimagesize($imagepath);
  $head = "Content-type: {$imgsize['mime']}";
  header($head);
  echo $my_data;
  exit;

  // IMPORTANT to exit() - otherwise some process after BG adds strings and breaks the image!
  return;
}