CacheImageMod.php 1.2 KB

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