summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-09-11 15:03:47 +0200
committerJulius Härtl <jus@bitgrid.net>2017-09-12 09:22:57 +0200
commitb49ab065b783b3ec041ca395739d747d20e2e187 (patch)
treedaa0369e10cd7959258337d9048aac404711101a
parent88731848c609a454aa90a533e7361bca5f4e66b8 (diff)
downloadnextcloud-server-b49ab065b783b3ec041ca395739d747d20e2e187.tar.gz
nextcloud-server-b49ab065b783b3ec041ca395739d747d20e2e187.zip
Move theming related imagePath logic to ThemingDefaults
Signed-off-by: Julius Haertl <jus@bitgrid.net>
-rw-r--r--apps/theming/lib/ThemingDefaults.php30
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php32
-rw-r--r--lib/private/URLGenerator.php15
3 files changed, 69 insertions, 8 deletions
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index 8200957edc0..0a9d5a6cc1f 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -249,6 +249,36 @@ class ThemingDefaults extends \OC_Defaults {
}
/**
+ * Check if the image should be replaced by the theming app
+ * and return the new image location then
+ *
+ * @param string $app name of the app
+ * @param string $image filename of the image
+ * @return bool|string false if image should not replaced, otherwise the location of the image
+ */
+ public function replaceImagePath($app, $image) {
+ if($app==='') {
+ $app = 'core';
+ }
+ $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
+
+ if ($image === 'favicon.ico' && $this->shouldReplaceIcons()) {
+ return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue;
+ }
+ if ($image === 'favicon-touch.png' && $this->shouldReplaceIcons()) {
+ return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue;
+ }
+ if ($image === 'manifest.json') {
+ $appPath = \OC_App::getAppPath($app);
+ if ($appPath && file_exists($appPath . '/img/manifest.json')) {
+ return false;
+ }
+ return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue;
+ }
+ return false;
+ }
+
+ /**
* Check if Imagemagick is enabled and if SVG is supported
* otherwise we can't render custom icons
*
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index c6d1fec91dd..48099e8be0f 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -607,4 +607,36 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('1234567890', $this->template->getiTunesAppId());
}
+ public function dataReplaceImagePath() {
+ return [
+ ['core', 'test.png', false],
+ ['core', 'manifest.json'],
+ ['core', 'favicon.ico'],
+ ['core', 'favicon-touch.png']
+ ];
+ }
+
+ /** @dataProvider dataReplaceImagePath */
+ public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=0') {
+ $cache = $this->createMock(ICache::class);
+ $cache->expects($this->any())
+ ->method('get')
+ ->with('shouldReplaceIcons')
+ ->willReturn(true);
+ $this->cacheFactory->expects($this->any())
+ ->method('create')
+ ->with('theming')
+ ->willReturn($cache);
+ $this->config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->urlGenerator
+ ->expects($this->any())
+ ->method('linkToRoute')
+ ->willReturn('themingRoute');
+ $this->assertEquals($result, $this->template->replaceImagePath($app, $image));
+ }
+
}
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index 9c73ba4cbc7..ee75f8b21bb 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -166,6 +166,11 @@ class URLGenerator implements IURLGenerator {
// Check if the app is in the app folder
$path = '';
$themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
+ $themingImagePath = false;
+ if($themingEnabled) {
+ $themingImagePath = \OC::$server->getThemingDefaults()->replaceImagePath($app, $image);
+ }
+
if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
@@ -181,14 +186,8 @@ class URLGenerator implements IURLGenerator {
} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
&& file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
$path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
- } elseif($themingEnabled && $image === "favicon.ico" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) {
- $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
- if($app==="") { $app = "core"; }
- $path = $this->linkToRoute('theming.Icon.getFavicon', [ 'app' => $app ]) . '?v='. $cacheBusterValue;
- } elseif($themingEnabled && $image === "favicon-touch.png" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) {
- $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
- if($app==="") { $app = "core"; }
- $path = $this->linkToRoute('theming.Icon.getTouchIcon', [ 'app' => $app ]) . '?v='. $cacheBusterValue;
+ } elseif($themingEnabled && $themingImagePath) {
+ $path = $themingImagePath;
} elseif ($appPath && file_exists($appPath . "/img/$image")) {
$path = \OC_App::getAppWebPath($app) . "/img/$image";
} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")