From 820e7b5abac0618755f1aafd5fece78d14bd6789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 22 Nov 2017 13:58:44 +0100 Subject: [PATCH 1/4] Use apps versions to generate suffix when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/TemplateLayout.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 4d49522be7..2868d48a91 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,25 @@ 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) ); } } } - protected function getVersionHashSuffix() { - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { + protected function getVersionHashSuffix($app=false) { + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { // allows chrome workspace mapping in debug mode return ""; } + if ($app !== false && $app !== '') { + $v = \OC_App::getAppVersions(); + $appName = end(explode('/', $app)); + if(array_key_exists($appName, $v)) { + $appVersion = $v[$appName]; + return '?v=' . substr(md5(implode(',', $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'); } From f018bfc7de7322651473edbfe65bd440b9c9e85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 5 Dec 2017 18:10:33 +0100 Subject: [PATCH 2/4] Fixed md5 generation and added fallback for scss requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/TemplateLayout.php | 38 ++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 2868d48a91..1bd9004265 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -188,22 +188,32 @@ 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($web) ); + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); } } } - protected function getVersionHashSuffix($app=false) { + protected function getVersionHashSuffix($path = false, $file = false) { if (\OC::$server->getConfig()->getSystemValue('debug', false)) { // allows chrome workspace mapping in debug mode return ""; } - if ($app !== false && $app !== '') { - $v = \OC_App::getAppVersions(); - $appName = end(explode('/', $app)); + $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(implode(',', $appVersion)), 0, 8) . '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); + 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'); } } @@ -238,6 +248,22 @@ class TemplateLayout extends \OC_Template { return $locator->getResources(); } + /** + * @param string $path + * @return string + */ + static 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); + } + + } + /** * @param array $scripts * @return array From 1ac31260acc0a10970196a28dd48ad71440d72b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 8 Dec 2017 17:42:03 +0100 Subject: [PATCH 3/4] Fixed phpdoc and function type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/TemplateLayout.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 1bd9004265..5118bb3bc1 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -193,6 +193,11 @@ class TemplateLayout extends \OC_Template { } } + /** + * @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 @@ -250,9 +255,9 @@ class TemplateLayout extends \OC_Template { /** * @param string $path - * @return string + * @return string|boolean */ - static public function getAppNamefromPath($path) { + public function getAppNamefromPath($path) { if ($path !== '' && is_string($path)) { $pathParts = explode('/', $path); if ($pathParts[0] === 'css') { @@ -261,6 +266,7 @@ class TemplateLayout extends \OC_Template { } return end($pathParts); } + return false } From 52e7d05163f21993bdcef25c26ebfa4487e55305 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 11 Dec 2017 13:55:04 +0100 Subject: [PATCH 4/4] Fix syntax error Signed-off-by: Morris Jobke --- lib/private/TemplateLayout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 5118bb3bc1..f0f1378a05 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -266,7 +266,7 @@ class TemplateLayout extends \OC_Template { } return end($pathParts); } - return false + return false; }