Signed-off-by: Julius Härtl <jus@bitgrid.net>tags/v14.0.0beta1
@@ -358,12 +358,13 @@ class ThemingController extends Controller { | |||
* @NoCSRFRequired | |||
* | |||
* @param string $key | |||
* @param bool $useSvg | |||
* @return FileDisplayResponse|NotFoundResponse | |||
* @throws \Exception | |||
* @throws NotPermittedException | |||
*/ | |||
public function getImage(string $key, bool $asPng = false) { | |||
public function getImage(string $key, bool $useSvg = true) { | |||
try { | |||
$file = $this->imageManager->getImage($key, $asPng); | |||
$file = $this->imageManager->getImage($key, $useSvg); | |||
} catch (NotFoundException $e) { | |||
return new NotFoundResponse(); | |||
} | |||
@@ -372,7 +373,7 @@ class ThemingController extends Controller { | |||
$response->cacheFor(3600); | |||
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); | |||
$response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); | |||
if ($asPng) { | |||
if (!$useSvg) { | |||
$response->addHeader('Content-Type', 'image/png'); | |||
} else { | |||
$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
@@ -65,10 +65,10 @@ class ImageManager { | |||
$this->cacheFactory = $cacheFactory; | |||
} | |||
public function getImageUrl(string $key): string { | |||
public function getImageUrl(string $key, bool $useSvg = true): string { | |||
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); | |||
try { | |||
$this->getImage($key); | |||
$image = $this->getImage($key, $useSvg); | |||
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; | |||
} catch (NotFoundException $e) { | |||
} | |||
@@ -83,16 +83,18 @@ class ImageManager { | |||
} | |||
} | |||
public function getImageUrlAbsolute(string $key): string { | |||
return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key)); | |||
public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { | |||
return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key, $useSvg)); | |||
} | |||
/** | |||
* @param $key | |||
* @param string $key | |||
* @param bool $useSvg | |||
* @return ISimpleFile | |||
* @throws NotFoundException | |||
* @throws NotPermittedException | |||
*/ | |||
public function getImage(string $key, bool $useSvg = false): ISimpleFile { | |||
public function getImage(string $key, bool $useSvg = true): ISimpleFile { | |||
$logo = $this->config->getAppValue('theming', $key . 'Mime', false); | |||
$folder = $this->appData->getFolder('images'); | |||
if ($logo === false || !$folder->fileExists($key)) { |
@@ -126,7 +126,7 @@ class ImageManagerTest extends TestCase { | |||
$this->urlGenerator->expects($this->once()) | |||
->method('linkToRoute') | |||
->willReturn('url-to-image'); | |||
$this->assertEquals('url-to-image?v=0', $this->imageManager->getImageUrl('logo')); | |||
$this->assertEquals('url-to-image?v=0', $this->imageManager->getImageUrl('logo', false)); | |||
} | |||
public function testGetImageUrlDefault() { | |||
@@ -164,7 +164,7 @@ class ImageManagerTest extends TestCase { | |||
$this->urlGenerator->expects($this->at(2)) | |||
->method('getAbsoluteUrl') | |||
->willReturn('url-to-image-absolute?v=0'); | |||
$this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo')); | |||
$this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo', false)); | |||
} | |||
@@ -175,7 +175,7 @@ class ImageManagerTest extends TestCase { | |||
->willReturn('png'); | |||
$file = $this->createMock(ISimpleFile::class); | |||
$this->mockGetImage('logo', $file); | |||
$this->assertEquals($file, $this->imageManager->getImage('logo')); | |||
$this->assertEquals($file, $this->imageManager->getImage('logo', false)); | |||
} | |||
/** |
@@ -604,7 +604,7 @@ class ThemingDefaultsTest extends TestCase { | |||
$this->urlGenerator->expects($this->once()) | |||
->method('linkToRoute') | |||
->with('theming.Theming.getImage') | |||
->willReturn('custom-logo'); | |||
->willReturn('custom-logo?v=0'); | |||
$this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo()); | |||
} | |||