diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-01-02 15:03:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-02 15:03:07 +0100 |
commit | aac9a1c41adda69e8a1e4e2610b2a1f34b3284db (patch) | |
tree | 8018b98e0f5322c07b1b24f9b71f86fbea01192d /lib | |
parent | 99175c32e5305538e3ded6e80fbaa77cd8f7ebfb (diff) | |
parent | c0c4443ffc6608ea2917a9c5bec1c0150a94b404 (diff) | |
download | nextcloud-server-aac9a1c41adda69e8a1e4e2610b2a1f34b3284db.tar.gz nextcloud-server-aac9a1c41adda69e8a1e4e2610b2a1f34b3284db.zip |
Merge pull request #7631 from nextcloud/fix-scss-webroot-and-url-rewrite
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 | 31 |
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 3c30a9d3356..5ca05d1b953 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -108,7 +108,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']); @@ -145,7 +145,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 8f6cb85a120..a4604425544 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -102,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); @@ -188,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); @@ -283,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); } @@ -315,4 +309,23 @@ class SCSSCacher { $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $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)); + } } |