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