summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-12-11 14:51:21 +0100
committerGitHub <noreply@github.com>2017-12-11 14:51:21 +0100
commitf4d7afc9500355e94e2ac1c7c921101971d0d29f (patch)
tree1e671bc2aaeb444659b2d4a0f54ccf3c44ec6568 /lib
parent8ed728c1a2126ac11207c498ce6935ef307b3982 (diff)
parent52e7d05163f21993bdcef25c26ebfa4487e55305 (diff)
downloadnextcloud-server-f4d7afc9500355e94e2ac1c7c921101971d0d29f.tar.gz
nextcloud-server-f4d7afc9500355e94e2ac1c7c921101971d0d29f.zip
Merge pull request #7244 from nextcloud/css-file-suffix-with-apps-versions
Use apps versions to generate suffix when possible
Diffstat (limited to 'lib')
-rw-r--r--lib/private/TemplateLayout.php51
1 files changed, 46 insertions, 5 deletions
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 4d49522be78..f0f1378a052 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -90,7 +90,7 @@ class TemplateLayout extends \OC_Template {
break;
}
}
-
+
foreach($settingsNavigation as $entry) {
if ($entry['active']) {
$this->assign( 'application', $entry['name'] );
@@ -125,7 +125,7 @@ class TemplateLayout extends \OC_Template {
if (empty(self::$versionHash)) {
$v = \OC_App::getAppVersions();
$v['core'] = implode('.', \OCP\Util::getVersion());
- self::$versionHash = md5(implode(',', $v));
+ self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
}
} else {
self::$versionHash = md5('not installed');
@@ -188,16 +188,40 @@ class TemplateLayout extends \OC_Template {
if (substr($file, -strlen('print.css')) === 'print.css') {
$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
} else {
- $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
+ $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) );
}
}
}
- protected function getVersionHashSuffix() {
- if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
+ /**
+ * @param string $path
+ * @param string $file
+ * @return string
+ */
+ protected function getVersionHashSuffix($path = false, $file = false) {
+ if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
// allows chrome workspace mapping in debug mode
return "";
}
+ $v = \OC_App::getAppVersions();
+
+ // Try the webroot path for a match
+ if ($path !== false && $path !== '') {
+ $appName = $this->getAppNamefromPath($path);
+ if(array_key_exists($appName, $v)) {
+ $appVersion = $v[$appName];
+ return '?v=' . substr(md5($appVersion), 0, 8) . '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
+ }
+ }
+ // fallback to the file path instead
+ if ($file !== false && $file !== '') {
+ $appName = $this->getAppNamefromPath($file);
+ if(array_key_exists($appName, $v)) {
+ $appVersion = $v[$appName];
+ return '?v=' . substr(md5($appVersion), 0, 8) . '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
+ }
+ }
+
if ($this->config->getSystemValue('installed', false) && \OC::$server->getAppManager()->isInstalled('theming')) {
return '?v=' . self::$versionHash . '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
}
@@ -230,6 +254,23 @@ class TemplateLayout extends \OC_Template {
}
/**
+ * @param string $path
+ * @return string|boolean
+ */
+ public function getAppNamefromPath($path) {
+ if ($path !== '' && is_string($path)) {
+ $pathParts = explode('/', $path);
+ if ($pathParts[0] === 'css') {
+ // This is a scss request
+ return $pathParts[1];
+ }
+ return end($pathParts);
+ }
+ return false;
+
+ }
+
+ /**
* @param array $scripts
* @return array
*/