1<?php 2 3namespace dokuwiki\Cache; 4 5/** 6 * Handle the caching of modified (resized/cropped) images 7 */ 8class CacheImageMod extends Cache 9{ 10 /** @var string source file */ 11 protected $file; 12 13 /** 14 * @param string $file Original source file 15 * @param int $w new width in pixel 16 * @param int $h new height in pixel 17 * @param string $ext Image extension - no leading dot 18 * @param bool $crop Is this a crop? 19 * @param bool $upscale Was upscaling allowed? Same dimensions yield different output when disabled 20 */ 21 public function __construct($file, $w, $h, $ext, $crop, $upscale = true) 22 { 23 $fullext = '.media.' . $w . 'x' . $h; 24 $fullext .= $crop ? '.crop' : ''; 25 $fullext .= $upscale ? '' : '.noup'; 26 $fullext .= ".$ext"; 27 28 $this->file = $file; 29 30 $this->setEvent('IMAGEMOD_CACHE_USE'); 31 parent::__construct($file, $fullext); 32 } 33 34 /** @inheritdoc */ 35 public function makeDefaultCacheDecision() 36 { 37 if (!file_exists($this->file)) { 38 return false; 39 } 40 return parent::makeDefaultCacheDecision(); 41 } 42 43 /** 44 * Caching depends on the source and the wiki config 45 * @inheritdoc 46 */ 47 protected function addDependencies() 48 { 49 parent::addDependencies(); 50 51 $this->depends['files'] = array_merge( 52 [$this->file], 53 getConfigFiles('main') 54 ); 55 } 56} 57