]> source.dussan.org Git - nextcloud-server.git/commitdiff
Injection fix and log appname fix
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Thu, 10 Nov 2016 15:16:33 +0000 (16:16 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Fri, 6 Jan 2017 08:42:13 +0000 (09:42 +0100)
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
core/Controller/CssController.php
lib/private/Template/CSSResourceLocator.php
lib/private/Template/ResourceLocator.php
lib/private/Template/SCSSCacher.php

index 45a188adba6fa391212ef5b5a84ba57bacec3154..31ec801d21ce51728fc318ac00d8e4635dee404b 100644 (file)
@@ -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();
        }
 }
index 0d190959ea16838bf3db82035e55173b7e68ade8..8e1cb3a761a07b3300793e064cd1959afeda7e79 100755 (executable)
@@ -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')
                ) {
index bb4cfa94f6cc0a10f9cd9935b334133ec93e9004..d5187ef071086b71566e9a97adcc81044e5e0739 100755 (executable)
@@ -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;
                        }
                }
index 42f3e1758f8aff0649a67e2e1eaa4cb23f6032e0..a5f4f510204f5b5b0f4e0e80ee82e23776b74424 100755 (executable)
@@ -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);
        }
 }