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