function resizeimage_wrapper_dbcache in Brilliant Gallery 6.4
Same name and namespace in other branches
- 5.4 image.php \resizeimage_wrapper_dbcache()
- 5.3 image.php \resizeimage_wrapper_dbcache()
- 6 image.php \resizeimage_wrapper_dbcache()
- 6.2 image.php \resizeimage_wrapper_dbcache()
- 6.3 image.php \resizeimage_wrapper_dbcache()
- 7.2 OLD_brilliant_gallery_functions.inc \resizeimage_wrapper_dbcache()
- 7 brilliant_gallery_functions.inc \resizeimage_wrapper_dbcache()
1 call to resizeimage_wrapper_dbcache()
File
- ./
functions.inc, line 291
Code
function resizeimage_wrapper_dbcache($reset = FALSE, $imagepath, $bgimgproperties_hash) {
#global $user;
#$userId = $user->uid;
$bgcachexpire = brilliant_gallery_get_days_in_seconds(variable_get('brilliant_gallery_cache_duration', 90));
// Cache expiration time in days.
$bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
//brilliant_gallery_brokenimage($bgcacheid.' :0: '.time(),1900,500); exit();
#echo $bgcacheid;
static $my_data;
#echo '0.... ';
/*
$reset = true;
if (!isset($my_data) || $reset) {
if (!$reset and ($cache = cache_get($bgcacheid)) and !empty($cache->data)) {
#$my_data = $cache->data; echo '-1.... ' . $my_data;
// Crucial to unserialize for the immediate use!
$my_data = unserialize($cache->data);
#echo $my_data;
//brilliant_gallery_brokenimage($bgcacheid.' :1: '.time(),1900,500); exit();
}
else {
// Do your expensive calculations here, and populate $my_data
// with the correct stuff..
#$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
//$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh'], $_GET['imgcrop'],$imagepath);
#echo ' -2.... ' . $bgcachexpire . ' // ' . $my_data;
# For some reason I could not use: mysql_escape_string($my_data)
#cache_set($bgcacheid, 'cache', time() + $bgcachexpire, $my_data);
cache_set($bgcacheid, $my_data, 'cache', time() + $bgcachexpire);
//brilliant_gallery_brokenimage($_GET['imgp']. $_GET['imgw']. $_GET['imgh']. $_GET['imgcrop'].' :3: '.time(),1900,500); exit();
# FOR DRUPAL6 MUST USE:
#cache_set($bgcacheid, $my_data, time() + $bgcachexpire); # For some reason I could not use: mysql_escape_string($my_data)
// Crucial to unserialize for the immediate use!
$my_data = unserialize($my_data);
}
}
*/
//echo '<br> ... '.$imagepath;
//echo '<br> --- '.$bgimgproperties_hash;
//echo '<br> +++ '.file_create_url(file_directory_path() .'/'. variable_get('brilliant_gallery_pcache', '') .'/bg_cached_resized_'.$bgimgproperties_hash);
//exit();
$pcache = variable_get('brilliant_gallery_pcache', BRILLIANT_GALLERY_DEFAULT_CACHE_DIR);
//brilliant_gallery_check_or_create_dir($pcache);
$foqen = file_directory_path() . '/' . $pcache . '/bg_cached_resized_' . $bgimgproperties_hash;
$lastchanged = @filemtime($foqen);
// Last file modification time, or FALSE on error.
/*
global $user; $userId = $user->uid;
if ($userId == 1){
drupal_set_message('pic '.($timenow - $lastchanged).' > '.$bgcachexpire.' ... '.$foqen);
}
*/
#if ($_GET['fetchnow']==1){ $lastchanged = FALSE; } // Debugging!
if ($lastchanged === FALSE or time() - $lastchanged > $bgcachexpire) {
// If the image is expired, we need to actively delete it, for the case that it was removed / hidden by the owner.
@unlink($foqen);
/*
global $user; $userId = $user->uid;
if ($userId == 1){
drupal_set_message('in!');
}
*/
///*
$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh'], @$_GET['imgcrop'], $imagepath);
$image = $my_data;
//*/
#watchdog('bg', $imager->code.' ... '.$imgurl.' =imgurl');
// It happens that the file size is 0 (image not fetched). In such case, don't write it.
if (strlen($image) > 0) {
$fp = fopen($foqen, 'w');
#drupal_set_message($foqen.'<br>');
#watchdog('bg', $foqen.' ...ok<br>');
fwrite($fp, $image);
fclose($fp);
}
}
return $my_data;
}