aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Cache/CacheImageMod.php
blob: 5883f7842c50d00df5a3151233ec806a24d876f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace dokuwiki\Cache;

/**
 * Handle the caching of modified (resized/cropped) images
 */
class CacheImageMod extends Cache
{

    /** @var string source file */
    protected $file;

    /**
     * @param string $file Original source file
     * @param int $w new width in pixel
     * @param int $h new height in pixel
     * @param string $ext Image extension - no leading dot
     * @param bool $crop Is this a crop?
     */
    public function __construct($file, $w, $h, $ext, $crop)
    {
        $fullext = '.media.' . $w . 'x' . $h;
        $fullext .= $crop ? '.crop' : '';
        $fullext .= ".$ext";

        $this->file = $file;

        $this->setEvent('IMAGEMOD_CACHE_USE');
        parent::__construct($file, $fullext);
    }

    /** @inheritdoc */
    public function makeDefaultCacheDecision()
    {
        if (!file_exists($this->file)) {
            return false;
        }
        return parent::makeDefaultCacheDecision();
    }

    /**
     * Caching depends on the source and the wiki config
     * @inheritdoc
     */
    protected function addDependencies()
    {
        parent::addDependencies();

        $this->depends['files'] = array_merge(
            [$this->file],
            getConfigFiles('main')
        );
    }

}