diff --git a/core/Controller/CssController.php b/core/Controller/CssController.php index 45a188adba..31ec801d21 100644 --- a/core/Controller/CssController.php +++ b/core/Controller/CssController.php @@ -54,7 +54,7 @@ class CssController extends Controller { } /** - * @NoAdminRequired + * @PublicPage * @NoCSRFRequired * * @param string $fileName css filename with extension @@ -76,8 +76,7 @@ class CssController extends Controller { $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); $response->addHeader('Pragma', 'cache'); return $response; - } else { - return new NotFoundResponse(); } + return new NotFoundResponse(); } } diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 0d190959ea..8e1cb3a761 100755 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -27,7 +27,12 @@ namespace OC\Template; class CSSResourceLocator extends ResourceLocator { + /** @var IAppData */ protected $appData; + /** @var \OCP\IURLGenerator */ + protected $urlGenerator; + /** @var \OCP\Files\IConfig */ + protected $systemConfig; /** * @param \OCP\ILogger $logger @@ -36,8 +41,11 @@ class CSSResourceLocator extends ResourceLocator { * @param array $party_map * @param IAppData $appData */ - public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, $appData) { + public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) { $this->appData = $appData; + $this->urlGenerator = $urlGenerator; + $this->systemConfig = $systemConfig; + parent::__construct($logger, $theme, $core_map, $party_map); } @@ -47,8 +55,8 @@ class CSSResourceLocator extends ResourceLocator { public function doFind($style) { if (strpos($style, '3rdparty') === 0 && $this->appendIfExist($this->thirdpartyroot, $style.'.css') - || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData) - || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData) + || $this->cacheAndAppendScssIfExist($this->serverroot, $style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig) + || $this->cacheAndAppendScssIfExist($this->serverroot, 'core/'.$style.'.scss', $this->appData, $this->urlGenerator, $this->systemConfig) || $this->appendIfExist($this->serverroot, $style.'.css') || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') ) { diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php index bb4cfa94f6..d5187ef071 100755 --- a/lib/private/Template/ResourceLocator.php +++ b/lib/private/Template/ResourceLocator.php @@ -115,19 +115,21 @@ abstract class ResourceLocator { * @param string|null $webRoot base for path, default map $root to $webRoot * @return bool True if the resource was found and cached, false otherwise */ - protected function cacheAndAppendScssIfExist($root, $file, $appData, $webRoot = null) { + protected function cacheAndAppendScssIfExist($root, $file, $appData, $urlGenerator, $systemConfig, $webRoot = null) { if (is_file($root.'/'.$file)) { $scssCache = new \OC\Template\SCSSCacher( $this->logger, $root, $file, - $appData); + $appData, + $urlGenerator, + $systemConfig); if($scssCache->process()) { $this->append($root, $scssCache->getCachedSCSS(), $webRoot, false); return true; } else { - $this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'server']); + $this->logger->error('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); return false; } } diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 42f3e1758f..a5f4f51020 100755 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -40,6 +40,10 @@ class SCSSCacher { protected $logger; /** @var \OCP\Files\IAppData */ protected $appData; + /** @var \OCP\IURLGenerator */ + protected $urlGenerator; + /** @var \OCP\Files\IConfig */ + protected $systemConfig; /** * @param \OCP\ILogger $logger @@ -47,9 +51,12 @@ class SCSSCacher { * @param string $file * @param \OCP\Files\IAppData $appData */ - public function __construct(\OCP\ILogger $logger, $root, $file, $appData) { + public function __construct(\OCP\ILogger $logger, $root, $file, \OCP\Files\IAppData $appData, \OCP\IURLGenerator $urlGenerator, $systemConfig) { $this->logger = $logger; $this->appData = $appData; + $this->urlGenerator = $urlGenerator; + $this->systemConfig = $systemConfig; + $this->root = $root; $this->file = explode('/', $root.'/'.$file); @@ -110,7 +117,7 @@ class SCSSCacher { private function cache() { $scss = new Compiler(); $scss->setImportPaths($this->fileLoc); - if(\OC::$server->getSystemConfig()->getValue('debug')) { + if($this->systemConfig->getValue('debug')) { // Debug mode $scss->setFormatter('Leafo\ScssPhp\Formatter\Expanded'); $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); @@ -129,13 +136,13 @@ class SCSSCacher { try { $compiledScss = $scss->compile('@import "'.$this->fileNameSCSS.'";'); } catch(ParserException $e) { - $this->logger->error($e, ['app' => 'server']); + $this->logger->error($e, ['app' => 'core']); return false; } try { $cachedfile->putContent($this->rebaseUrls($compiledScss)); - $this->logger->debug($this->rootCssLoc.'/'.$this->fileNameSCSS.' compiled and successfully cached', ['app' => 'server']); + $this->logger->debug($this->rootCssLoc.'/'.$this->fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); return true; } catch(NotFoundException $e) { return false; @@ -159,6 +166,6 @@ class SCSSCacher { * @return string */ public function getCachedSCSS() { - return substr(\OC::$server->getURLGenerator()->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS)), 1); + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $this->fileNameCSS)), 1); } }