Changeset 5675
- Timestamp:
- 10/25/07 03:11:28 (6 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfThumbnailCachePlugin/config/app.yml.dist
r4126 r5675 1 1 all: 2 image_magick_convert: /usr/bin/convert 3 image_magick_identify: /usr/bin/identify 2 thumbnail_cache: 3 cache_file_life: 3600 # Keep cached files for 1 hour 4 image_magick_convert: /usr/bin/convert 5 image_magick_identify: /usr/bin/identify plugins/sfThumbnailCachePlugin/lib/sfThumbnailCache.class.php
r4880 r5675 100 100 function __construct($file_master = null, $width = null, $height = null, 101 101 $scale = true, $inflate = true, $type = null, 102 $file_thumb = null )102 $file_thumb = null, $mtime = null, $create_thumb = true) 103 103 { 104 104 if(!$file_master) … … 125 125 $this->cache_url_path = '/uploads/sfThumbnailCache'; 126 126 127 $this->createThumbnail(); 128 127 $this->mtime = $mtime ? $mtime : null; 128 129 if($create_thumb) 130 { 131 if(!$this->cacheIsValid()) 132 { 133 //echo "<br>Making thumb<BR>"; 134 $this->createThumbnail(); 135 } 136 } 129 137 } 130 138 … … 134 142 public static function getInstance($file_master = null, $width = null, $height = null, 135 143 $scale = true, $inflate = true, $type = null, 136 $ file_thumb = null)144 $mtime = null, $file_thumb = null) 137 145 { 138 146 static $sfThumbnailCache; … … 142 150 // Get instance 143 151 $className = 'sfThumbnailCache'; 144 $sfThumbnailCache = new $className($file_master, $width, $height, $scale, $inflate, $type, $ file_thumb);152 $sfThumbnailCache = new $className($file_master, $width, $height, $scale, $inflate, $type, $mtime, $file_thumb); 145 153 } 146 154 … … 153 161 public static function getNewInstance($file_master = null, $width = null, $height = null, 154 162 $scale = true, $inflate = true, $type = null, 155 $ file_thumb = null)163 $mtime = null, $file_thumb = null) 156 164 { 157 165 // Get instance 158 166 $className = 'sfThumbnailCache'; 159 $sfThumbnailCache = new $className($file_master, $width, $height, $scale, $inflate, $type, $ file_thumb);167 $sfThumbnailCache = new $className($file_master, $width, $height, $scale, $inflate, $type, $mtime, $file_thumb); 160 168 return $sfThumbnailCache; 161 169 } 162 170 171 /** 172 * Instantiates and returns a new sfThumbnailCache object without trying to create thumbnail 173 */ 174 public static function getNewInstanceNoMaster($file_thumb = null,$width = null, $height = null, 175 $scale = true, $inflate = true, $type = null, $mtime = null) 176 { 177 // Get instance 178 $className = 'sfThumbnailCache'; 179 $sfThumbnailCache = new $className('none', $width, $height, $scale, $inflate, $type, $file_thumb, $mtime, false); 180 return $sfThumbnailCache; 181 } 163 182 164 183 public function exists() … … 217 236 218 237 /** 238 * Is the cached file still valid based on mtime and cache time limit 239 * 240 * If mtime is set and is older or equal to cached file then cache is valid 241 * If mtime is not set and cache life is less than cache time limit then cache is valid 242 */ 243 public function cacheIsValid() 244 { 245 246 if(!$this->exists()) 247 return false; 248 249 // Use mtime if it's set 250 if($this->mtime) 251 { 252 // File requested is newer than cache 253 if($this->mtime > $this->getMTime()) 254 return false; 255 256 // File requested is older or same as cache 257 return true ; 258 } 259 260 // Use cache life time 261 $cache_life = time() - $this->getMTime(); 262 $valid_cache_life = sfConfig::get('app_thumbnail_cache_cache_file_life'); 263 return ($cache_life > $valid_cache_life) ? false : true; 264 265 } 266 267 public function getMTime() 268 { 269 return filemtime($this->getPath()); 270 } 271 272 /** 219 273 * Get name of thumbnail file 220 274 */ … … 232 286 private function createThumbnail() 233 287 { 234 235 // Do we already have thumb of the given size236 if($this->exists())237 return $this->getPath();238 288 239 289 // Create thumb dir if it doesn't exist … … 242 292 // We need to create a thumbnail 243 293 $thumb = new sfThumbnail($this->width, $this->height, $this->scale, $this->inflate, $this->quality); 244 $thumb = new sfThumbnail($this->width, $this->height, $this->scale, $this->inflate, $this->quality, 'sfImageMagickAdapter', array('convert' => sfConfig::get('app_ image_magick_convert'), 'identify' => sfConfig::get('app_image_magick_identify')));294 $thumb = new sfThumbnail($this->width, $this->height, $this->scale, $this->inflate, $this->quality, 'sfImageMagickAdapter', array('convert' => sfConfig::get('app_thumbnail_cache_image_magick_convert'), 'identify' => sfConfig::get('app_thumbnail_cache_image_magick_identify'))); 245 295 $thumb->loadFile($this->file_master); 246 296 $thumb->save($this->getPath(), $this->type); 247 297 $thumb->freeAll(); 298 299 // Set the access and modification to match S3 time 300 if($this->mtime) 301 { 302 if(!touch($this->getPath(),$this->mtime)) 303 throw new Exception("Could not set last modification time"); 304 } 248 305 249 306 return $this->getPath();