Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-03-05 17:05:14 +0300
committerGitHub <noreply@github.com>2018-03-05 17:05:14 +0300
commit66cba3e01b51a40b7b9cfe1ae5c87ecdb1a56ebe (patch)
tree16c9ba07ef94cf61b99c2af8f5a378300a1380cb /lib
parent2dc82d49e3fedc45eb663528839347b4f881c6d6 (diff)
parenta7e7b874e48739e0d492d60e4a4df45171e1a51a (diff)
Merge pull request #8611 from nextcloud/css-file-suffix-with-apps-versions-backport
[stable12] Use apps versions to generate suffix when possible
Diffstat (limited to 'lib')
-rw-r--r--lib/private/TemplateLayout.php49
1 files changed, 45 insertions, 4 deletions
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 8a3a8e1e36b..2f51eb533c2 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -131,7 +131,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');
@@ -194,16 +194,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');
}
@@ -236,6 +260,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
*/