Updated the thumbnail generator to use the egw_cache_file class to generate a temp filename

This commit is contained in:
Andreas Stöckel 2011-02-21 18:37:45 +00:00
parent 76c981d20d
commit 43e4fa2c3c
3 changed files with 10 additions and 10 deletions

View File

@ -112,11 +112,11 @@ function read_thumbnail($src)
// will be 0 // will be 0
$maxsize = get_maxsize(); $maxsize = get_maxsize();
// Check whether the destination directory exists, if not, create it. If this // Generate the destination filename and check whether the destination directory
// process failes, dont' return an image. // had been successfully created (the cache class used in gen_dstfile does that).
$dst = gen_dstfile($src, $maxsize); $dst = gen_dstfile($src, $maxsize);
$dst_dir = dirname($dst); $dst_dir = dirname($dst);
if(file_exists($dst_dir) || mkdir($dst_dir, 0700, true)) if(file_exists($dst_dir))
{ {
// Check whether the destination file already exists and is newer than // Check whether the destination file already exists and is newer than
// the source file. Assume the file doesn't exist if thumbnailing is turned off. // the source file. Assume the file doesn't exist if thumbnailing is turned off.
@ -166,11 +166,11 @@ function read_thumbnail($src)
function gen_dstfile($src, $maxsize) function gen_dstfile($src, $maxsize)
{ {
// Previous versions of this code didn't use an md5-sum of $src but appended // Use the egroupware file cache to store the thumbnails on a per instance
// it directly - this might have been an security issue as thumbnails from // basis
// multiple instances might get mixed up. $cachefile = new egw_cache_files(array());
return $GLOBALS['egw_info']['server']['temp_dir'] . '/egw-thumbs/thumb_' . return $cachefile->filename(egw_cache::keys(egw_cache::INSTANCE, 'etemplate',
md5($src . $GLOBALS['egw_info']['server']['webserver_url'] . $maxsize).'.png'; 'thumb_'.md5($src.$maxsize).'.png'), true);
} }
/** /**

View File

@ -479,7 +479,7 @@ class egw_cache
* @param string $location * @param string $location
* @return array * @return array
*/ */
static protected function keys($level,$app,$location) static public function keys($level,$app,$location)
{ {
static $bases = array(); static $bases = array();

View File

@ -135,7 +135,7 @@ class egw_cache_files implements egw_cache_provider
* @param boolean $mkdir=false should we create the directory * @param boolean $mkdir=false should we create the directory
* @return string * @return string
*/ */
private function filename(array $keys,$mkdir=false) function filename(array $keys,$mkdir=false)
{ {
$fname = $this->base_path.'/'.str_replace(array(':','*'),'-',implode('/',$keys)); $fname = $this->base_path.'/'.str_replace(array(':','*'),'-',implode('/',$keys));