Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer custom theme over the theming app #5070

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions apps/theming/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,39 @@
*
*/

$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getStylesheet',
[
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
]
);
\OCP\Util::addHeader(
'link',
[
'rel' => 'stylesheet',
'href' => $linkToCSS,
]
);
$app = new \OCP\AppFramework\App('theming');
/** @var \OCA\Theming\Util $util */
$util = $app->getContainer()->query(\OCA\Theming\Util::class);
if(!$util->isAlreadyThemed()) {

$linkToJs = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getJavascript',
[
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
]
);
\OCP\Util::addHeader(
'script',
[
'src' => $linkToJs,
'nonce' => \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
], ''
);
$app->getContainer()->registerCapability(\OCA\Theming\Capabilities::class);

$app = new \OCP\AppFramework\App('theming');
$app->getContainer()->registerCapability(\OCA\Theming\Capabilities::class);
$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getStylesheet',
[
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
]
);
\OCP\Util::addHeader(
'link',
[
'rel' => 'stylesheet',
'href' => $linkToCSS,
]
);

$linkToJs = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getJavascript',
[
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
]
);
\OCP\Util::addHeader(
'script',
[
'src' => $linkToJs,
'nonce' => \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
], ''
);

}
13 changes: 13 additions & 0 deletions apps/theming/lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,17 @@ public function colorizeSvg($svg, $color) {
return $svg;
}

/**
* Check if a custom theme is set in the server configuration
*
* @return bool
*/
public function isAlreadyThemed() {
$theme = $this->config->getSystemValue('theme', '');
if ($theme !== '') {
return true;
}
return false;
}

}
20 changes: 20 additions & 0 deletions apps/theming/tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,24 @@ public function testColorizeSvg() {
$this->assertEquals($expected, $result);
}

public function testIsAlreadyThemedFalse() {
$theme = $this->config->getSystemValue('theme', '');
$this->config->expects($this->once())
->method('getSystemValue')
->with('theme', '')
->willReturn('');
$actual = $this->util->isAlreadyThemed();
$this->assertFalse($actual);
}

public function testIsAlreadyThemedTrue() {
$theme = $this->config->getSystemValue('theme', '');
$this->config->expects($this->once())
->method('getSystemValue')
->with('theme', '')
->willReturn('example');
$actual = $this->util->isAlreadyThemed();
$this->assertTrue($actual);
}

}
2 changes: 1 addition & 1 deletion core/js/mimetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ OC.MimeType = {
path += icon;
}
}
if(OCA.Theming) {
if(OCA.Theming && gotIcon === null) {
path = OC.generateUrl('/apps/theming/img/core/filetypes/');
path += OC.MimeType._getFile(mimeType, OC.MimeTypeList.files);
gotIcon = true;
Expand Down
22 changes: 9 additions & 13 deletions lib/private/URLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,7 @@ public function imagePath($app, $image) {
// Check if the app is in the app folder
$path = '';
$themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming');
if($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 && $image === 'favicon-fb.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 (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$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")
&& file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
Expand All @@ -193,6 +181,14 @@ public function imagePath($app, $image) {
} 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 ($appPath && file_exists($appPath . "/img/$image")) {
$path = \OC_App::getAppWebPath($app) . "/img/$image";
} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
Expand Down