diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-01-05 17:29:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 17:29:08 +0100 |
commit | 28d77efe804c050ef09757ce41939df5ede1a6be (patch) | |
tree | e6be454f50823e9c0fbc5829301591f5fcc2a747 /lib | |
parent | a3933b99fe9626901c0f9bdad2d1b6a3f97a46d4 (diff) | |
parent | b95d18b85e21e5a19ff0511cf4a37cf9f229eaa5 (diff) | |
download | nextcloud-server-28d77efe804c050ef09757ce41939df5ede1a6be.tar.gz nextcloud-server-28d77efe804c050ef09757ce41939df5ede1a6be.zip |
Merge pull request #7688 from nextcloud/stable12-fix-scss-webroot-and-url-rewrite
[Stable12] fix scss webroot and url rewrite
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Template/CSSResourceLocator.php | 4 | ||||
-rw-r--r-- | lib/private/Template/SCSSCacher.php | 40 |
2 files changed, 32 insertions, 12 deletions
diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index d5e9ce732cc..2226f4f6a39 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -104,7 +104,7 @@ class CSSResourceLocator extends ResourceLocator { if($this->scssCacher !== null) { if($this->scssCacher->process($root, $file, $app)) { - $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true); + $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true); return true; } else { $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); @@ -141,7 +141,7 @@ class CSSResourceLocator extends ResourceLocator { } } - $this->resources[] = array($webRoot? : '/', $webRoot, $file); + $this->resources[] = array($webRoot? : \OC::$WEBROOT, $webRoot, $file); } } } diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index c4ec5f95dc7..0b85af3f27f 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -2,6 +2,13 @@ /** * @copyright Copyright (c) 2016, John Molakvoæ (skjnldsv@protonmail.com) * + * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> + * @author Julius Haertl <jus@bitgrid.net> + * @author Julius Härtl <jus@bitgrid.net> + * @author Lukas Reschke <lukas@statuscode.ch> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Roeland Jago Douma <roeland@famdouma.nl> + * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -95,8 +102,7 @@ class SCSSCacher { $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); $path = implode('/', $path); - - $webDir = substr($path, strlen($this->serverRoot)+1); + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); try { $folder = $this->appData->getFolder($app); @@ -105,10 +111,10 @@ class SCSSCacher { $folder = $this->appData->newFolder($app); } - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { return true; } + return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); } @@ -181,7 +187,7 @@ class SCSSCacher { $scss = new Compiler(); $scss->setImportPaths([ $path, - \OC::$SERVERROOT . '/core/css/', + $this->serverRoot . '/core/css/', ]); // Continue after throw $scss->setIgnoreErrors(true); @@ -276,12 +282,7 @@ class SCSSCacher { */ private function rebaseUrls($css, $webDir) { $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; - // OC\Route\Router:75 - if(($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { - $subst = 'url(\'../../'.$webDir.'/$1\')'; - } else { - $subst = 'url(\'../../../'.$webDir.'/$1\')'; - } + $subst = 'url(\''.$webDir.'/$1\')'; return preg_replace($re, $subst, $css); } @@ -307,4 +308,23 @@ class SCSSCacher { private function prependBaseurlPrefix($cssFile) { return md5($this->urlGenerator->getBaseUrl()) . '-' . $cssFile; } + + /** + * Get WebDir root + * @param string $path the css file path + * @param string $appName the app name + * @param string $serverRoot the server root path + * @param string $webRoot the nextcloud installation root path + * @return string the webDir + */ + private function getWebDir($path, $appName, $serverRoot, $webRoot) { + // Detect if path is within server root AND if path is within an app path + if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { + // Get the file path within the app directory + $appDirectoryPath = explode($appName, $path)[1]; + // Remove the webroot + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); + } + return $webRoot.substr($path, strlen($serverRoot)); + } } |