You are here

function brilliant_gallery_deliver_image in Brilliant Gallery 7.2

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

@todo Please document this function.

See also

http://drupal.org/node/1354

File

./OLD_brilliant_gallery_functions.inc, line 188

Code

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

  //$bgimgproperties_hash_position = sizeof($queryexplode)+1;
  $bgimgproperties_hash = array_pop($queryexplode);

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

  // Remove prefix.

  //return (base64_decode($bgimgproperties_hash));

  //include 'image.inc';

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

  //print_r($bgimgproperties_array); flush(); exit();
  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'];

  //brilliant_gallery_brokenimage($urlpath.' :0: '.time(),1900,500); exit();
  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;

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