}
/**
- * @NoAdminRequired
+ * @PublicPage
* @NoCSRFRequired
*
* @param string $fileName css filename with extension
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$response->addHeader('Pragma', 'cache');
return $response;
- } else {
- return new NotFoundResponse();
}
+ return new NotFoundResponse();
}
}
class CSSResourceLocator extends ResourceLocator {
+ /** @var IAppData */
protected $appData;
+ /** @var \OCP\IURLGenerator */
+ protected $urlGenerator;
+ /** @var \OCP\Files\IConfig */
+ protected $systemConfig;
/**
* @param \OCP\ILogger $logger
* @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);
}
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')
) {
* @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;
}
}
protected $logger;
/** @var \OCP\Files\IAppData */
protected $appData;
+ /** @var \OCP\IURLGenerator */
+ protected $urlGenerator;
+ /** @var \OCP\Files\IConfig */
+ protected $systemConfig;
/**
* @param \OCP\ILogger $logger
* @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);
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);
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;
* @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);
}
}