Signed-off-by: Julius Haertl <jus@bitgrid.net>tags/v13.0.0beta1
@@ -248,6 +248,36 @@ class ThemingDefaults extends \OC_Defaults { | |||
return $variables; | |||
} | |||
/** | |||
* 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 |
@@ -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)); | |||
} | |||
} |
@@ -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") |