function brilliant_gallery_deliver_image in Brilliant Gallery 6.4
Same name and namespace in other branches
- 7.2 OLD_brilliant_gallery_functions.inc \brilliant_gallery_deliver_image()
- 7 brilliant_gallery_functions.inc \brilliant_gallery_deliver_image()
1 string reference to 'brilliant_gallery_deliver_image'
File
- ./
functions.inc, line 147
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;
}
/*
drupalize();
function drupalize() {
while (!@stat('./includes/bootstrap.inc')) {
chdir('..');
}
#module_load_include('/includes/bootstrap.inc', 'image', 'includes/bootstrap');
require_once './includes/bootstrap.inc';
require_once './includes/file.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // See http://drupal.org/node/211378#comment-924059
#drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
#drupal_cron_run();
}
*/
$imagepath = realpath(file_directory_path() . $urlpath);
#watchdog('Brilliant Gal','imgp: '.$imagepath);
// Crucial - to suppress Devel (if installed and enabled) output appearing in the generated XML!
$GLOBALS['devel_shutdown'] = FALSE;
#chdir ('../../../../');
#module_load_include('/includes/bootstrap.inc', 'image', 'includes/bootstrap');
#module_load_include('./../../../../includes/bootstrap.inc', 'image', '');
#drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
#if ( $_SERVER['SERVER_ADDR'] == '64.13.192.90' ) {
/*
if (variable_get('brilliant_gallery_cache', 'd') == 'f') {
#echo '.....................' . $_SERVER['SERVER_ADDR'];
#drupal_set_message('cachetype1 '.variable_get('brilliant_gallery_cache', 'd'));
#watchdog('Brilliant Gal', '1 '.variable_get('brilliant_gallery_cache'));
$my_data = resizeimage_wrapper_filecache();
}
else {
#drupal_set_message('cachetype2 '.variable_get('brilliant_gallery_cache', 'd'));
#watchdog('Brilliant Gal', '2 '.variable_get('brilliant_gallery_cache'));
$my_data = resizeimage_wrapper_dbcache();
}
*/
//brilliant_gallery_brokenimage($bgcacheid.' :g: '.time(),1900,500); exit();
$my_data = resizeimage_wrapper_dbcache(FALSE, $imagepath, $bgimgproperties_hash);
#echo '....'. sess_read('vacilando');
$imgsize = @getimagesize($imagepath);
# http://be.php.net/getimagesize
$head = "Content-type: {$imgsize['mime']}";
header($head);
//header($my_data[0]);
echo $my_data;
// IMPORTANT to exit() - otherwise some process after BG adds strings and breaks the image!
exit;
/*
function resizeimage_wrapper_filecache() {
$bgcacheid = 'bg_'. md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
#echo '. 0.... ';
$bgcachexpire = variable_get('brilliant_gallery_cache_duration',90) * 24 * 3600; // Cache expiration time in days.
// Tested that both relative (eg sites/all/files/cache) and absolute (eg /home/data/tmp) tmp path settings work OK here.
$cachetemp = variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR);
$cachedfile = $cachetemp .'/'. $bgcacheid;
$fileexists = false;
$fileexists = file_exists($cachedfile);
$timenow = time();
$lastchanged = $timenow;
$lastchanged = @filemtime($cachedfile);
$fileexpired = false;
if ($timenow - $lastchanged > $bgcachexpire){
$fileexpired = true;
// If the image is expired, we need to actively delete it, for the case that it was removed / hidden by the owner.
@unlink($cachedfile);
}
if (!$fileexists or $fileexpired) {
#echo '. 1.... ';
// Cache file does not exist or is too old.
#$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh'], $_GET['imgcrop']);
// Now put $my_data to cache!
$fh = fopen($cachedfile, "w+");
fwrite($fh, $my_data);
fclose($fh);
$my_data = unserialize($my_data);
}
else {
#echo '. 2.... ';
// Cache file exists.
$my_data = unserialize(file_get_contents($cachedfile));
}
return $my_data;
}
*/
/*
brilliant_gallery_brokenimage($showthis,500,500); exit();
*/
/*
$result = '';
// $bgimgproperties_hash looks like d48a36adcaff5b04858e6ae8e8d2b81a.bgimg -- let's lose the extension.
$bgimgproperties_hash = explode('.',$bgimgproperties_hash);
$bgimgproperties_hash = $bgimgproperties_hash[0];
drupal_set_message('hashed array: '.$bgimgproperties_hash);
$result .= $bgimgproperties_hash;
*/
return $result;
}