@@ -45,286 +45,286 @@ |
||
| 45 | 45 | |
| 46 | 46 | class SCSSCacher { |
| 47 | 47 | |
| 48 | - /** @var ILogger */ |
|
| 49 | - protected $logger; |
|
| 50 | - |
|
| 51 | - /** @var IAppData */ |
|
| 52 | - protected $appData; |
|
| 53 | - |
|
| 54 | - /** @var IURLGenerator */ |
|
| 55 | - protected $urlGenerator; |
|
| 56 | - |
|
| 57 | - /** @var IConfig */ |
|
| 58 | - protected $config; |
|
| 59 | - |
|
| 60 | - /** @var string */ |
|
| 61 | - protected $serverRoot; |
|
| 62 | - |
|
| 63 | - /** @var ICache */ |
|
| 64 | - protected $depsCache; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param ILogger $logger |
|
| 68 | - * @param Factory $appDataFactory |
|
| 69 | - * @param IURLGenerator $urlGenerator |
|
| 70 | - * @param IConfig $config |
|
| 71 | - * @param \OC_Defaults $defaults |
|
| 72 | - * @param string $serverRoot |
|
| 73 | - * @param ICache $depsCache |
|
| 74 | - */ |
|
| 75 | - public function __construct(ILogger $logger, |
|
| 76 | - Factory $appDataFactory, |
|
| 77 | - IURLGenerator $urlGenerator, |
|
| 78 | - IConfig $config, |
|
| 79 | - \OC_Defaults $defaults, |
|
| 80 | - $serverRoot, |
|
| 81 | - ICache $depsCache) { |
|
| 82 | - $this->logger = $logger; |
|
| 83 | - $this->appData = $appDataFactory->get('css'); |
|
| 84 | - $this->urlGenerator = $urlGenerator; |
|
| 85 | - $this->config = $config; |
|
| 86 | - $this->defaults = $defaults; |
|
| 87 | - $this->serverRoot = $serverRoot; |
|
| 88 | - $this->depsCache = $depsCache; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Process the caching process if needed |
|
| 93 | - * @param string $root Root path to the nextcloud installation |
|
| 94 | - * @param string $file |
|
| 95 | - * @param string $app The app name |
|
| 96 | - * @return boolean |
|
| 97 | - */ |
|
| 98 | - public function process($root, $file, $app) { |
|
| 99 | - $path = explode('/', $root . '/' . $file); |
|
| 100 | - |
|
| 101 | - $fileNameSCSS = array_pop($path); |
|
| 102 | - $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
|
| 103 | - |
|
| 104 | - $path = implode('/', $path); |
|
| 105 | - $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 106 | - |
|
| 107 | - try { |
|
| 108 | - $folder = $this->appData->getFolder($app); |
|
| 109 | - } catch(NotFoundException $e) { |
|
| 110 | - // creating css appdata folder |
|
| 111 | - $folder = $this->appData->newFolder($app); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param $appName |
|
| 119 | - * @param $fileName |
|
| 120 | - * @return ISimpleFile |
|
| 121 | - */ |
|
| 122 | - public function getCachedCSS($appName, $fileName) { |
|
| 123 | - $folder = $this->appData->getFolder($appName); |
|
| 124 | - return $folder->getFile($this->prependBaseurlPrefix($fileName)); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Check if the file is cached or not |
|
| 129 | - * @param string $fileNameCSS |
|
| 130 | - * @param ISimpleFolder $folder |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - private function isCached($fileNameCSS, ISimpleFolder $folder) { |
|
| 134 | - if ($this->variablesChanged()) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - try { |
|
| 138 | - $cachedFile = $folder->getFile($fileNameCSS); |
|
| 139 | - if ($cachedFile->getSize() > 0) { |
|
| 140 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 141 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 142 | - if ($deps === null) { |
|
| 143 | - $depFile = $folder->getFile($depFileName); |
|
| 144 | - $deps = $depFile->getContent(); |
|
| 145 | - //Set to memcache for next run |
|
| 146 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 147 | - } |
|
| 148 | - $deps = json_decode($deps, true); |
|
| 149 | - |
|
| 150 | - foreach ($deps as $file=>$mtime) { |
|
| 151 | - if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - return true; |
|
| 157 | - } catch(NotFoundException $e) { |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Check if the variables file has changed |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - private function variablesChanged() { |
|
| 167 | - $injectedVariables = $this->getInjectedVariables(); |
|
| 168 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 169 | - $this->resetCache(); |
|
| 170 | - $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Cache the file with AppData |
|
| 178 | - * @param string $path |
|
| 179 | - * @param string $fileNameCSS |
|
| 180 | - * @param string $fileNameSCSS |
|
| 181 | - * @param ISimpleFolder $folder |
|
| 182 | - * @param string $webDir |
|
| 183 | - * @return boolean |
|
| 184 | - */ |
|
| 185 | - private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) { |
|
| 186 | - $scss = new Compiler(); |
|
| 187 | - $scss->setImportPaths([ |
|
| 188 | - $path, |
|
| 189 | - $this->serverRoot . '/core/css/', |
|
| 190 | - ]); |
|
| 191 | - // Continue after throw |
|
| 192 | - $scss->setIgnoreErrors(true); |
|
| 193 | - if($this->config->getSystemValue('debug')) { |
|
| 194 | - // Debug mode |
|
| 195 | - $scss->setFormatter(Expanded::class); |
|
| 196 | - $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 197 | - } else { |
|
| 198 | - // Compression |
|
| 199 | - $scss->setFormatter(Crunched::class); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - try { |
|
| 203 | - $cachedfile = $folder->getFile($fileNameCSS); |
|
| 204 | - } catch(NotFoundException $e) { |
|
| 205 | - $cachedfile = $folder->newFile($fileNameCSS); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 209 | - try { |
|
| 210 | - $depFile = $folder->getFile($depFileName); |
|
| 211 | - } catch (NotFoundException $e) { |
|
| 212 | - $depFile = $folder->newFile($depFileName); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // Compile |
|
| 216 | - try { |
|
| 217 | - $compiledScss = $scss->compile( |
|
| 218 | - '@import "variables.scss";' . |
|
| 219 | - $this->getInjectedVariables() . |
|
| 220 | - '@import "'.$fileNameSCSS.'";'); |
|
| 221 | - } catch(ParserException $e) { |
|
| 222 | - $this->logger->error($e, ['app' => 'core']); |
|
| 223 | - return false; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Gzip file |
|
| 227 | - try { |
|
| 228 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 229 | - } catch (NotFoundException $e) { |
|
| 230 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - try { |
|
| 234 | - $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 235 | - $cachedfile->putContent($data); |
|
| 236 | - $deps = json_encode($scss->getParsedFiles()); |
|
| 237 | - $depFile->putContent($deps); |
|
| 238 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 239 | - $gzipFile->putContent(gzencode($data, 9)); |
|
| 240 | - $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 241 | - return true; |
|
| 242 | - } catch(NotPermittedException $e) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Reset scss cache by deleting all generated css files |
|
| 249 | - * We need to regenerate all files when variables change |
|
| 250 | - */ |
|
| 251 | - private function resetCache() { |
|
| 252 | - $appDirectory = $this->appData->getDirectoryListing(); |
|
| 253 | - if(empty($appDirectory)){ |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - foreach ($appDirectory as $folder) { |
|
| 257 | - foreach ($folder->getDirectoryListing() as $file) { |
|
| 258 | - if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") { |
|
| 259 | - $file->delete(); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @return string SCSS code for variables from OC_Defaults |
|
| 267 | - */ |
|
| 268 | - private function getInjectedVariables() { |
|
| 269 | - $variables = ''; |
|
| 270 | - foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 271 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 272 | - } |
|
| 273 | - return $variables; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Add the correct uri prefix to make uri valid again |
|
| 278 | - * @param string $css |
|
| 279 | - * @param string $webDir |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - private function rebaseUrls($css, $webDir) { |
|
| 283 | - $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; |
|
| 284 | - $subst = 'url('.$webDir.'/$1)'; |
|
| 285 | - return preg_replace($re, $subst, $css); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Return the cached css file uri |
|
| 290 | - * @param string $appName the app name |
|
| 291 | - * @param string $fileName |
|
| 292 | - * @return string |
|
| 293 | - */ |
|
| 294 | - public function getCachedSCSS($appName, $fileName) { |
|
| 295 | - $tmpfileLoc = explode('/', $fileName); |
|
| 296 | - $fileName = array_pop($tmpfileLoc); |
|
| 297 | - $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); |
|
| 298 | - |
|
| 299 | - return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Prepend hashed base url to the css file |
|
| 304 | - * @param $cssFile |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 307 | - private function prependBaseurlPrefix($cssFile) { |
|
| 308 | - $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 309 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Get WebDir root |
|
| 314 | - * @param string $path the css file path |
|
| 315 | - * @param string $appName the app name |
|
| 316 | - * @param string $serverRoot the server root path |
|
| 317 | - * @param string $webRoot the nextcloud installation root path |
|
| 318 | - * @return string the webDir |
|
| 319 | - */ |
|
| 320 | - private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
|
| 321 | - // Detect if path is within server root AND if path is within an app path |
|
| 322 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 323 | - // Get the file path within the app directory |
|
| 324 | - $appDirectoryPath = explode($appName, $path)[1]; |
|
| 325 | - // Remove the webroot |
|
| 326 | - return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 327 | - } |
|
| 328 | - return $webRoot.substr($path, strlen($serverRoot)); |
|
| 329 | - } |
|
| 48 | + /** @var ILogger */ |
|
| 49 | + protected $logger; |
|
| 50 | + |
|
| 51 | + /** @var IAppData */ |
|
| 52 | + protected $appData; |
|
| 53 | + |
|
| 54 | + /** @var IURLGenerator */ |
|
| 55 | + protected $urlGenerator; |
|
| 56 | + |
|
| 57 | + /** @var IConfig */ |
|
| 58 | + protected $config; |
|
| 59 | + |
|
| 60 | + /** @var string */ |
|
| 61 | + protected $serverRoot; |
|
| 62 | + |
|
| 63 | + /** @var ICache */ |
|
| 64 | + protected $depsCache; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param ILogger $logger |
|
| 68 | + * @param Factory $appDataFactory |
|
| 69 | + * @param IURLGenerator $urlGenerator |
|
| 70 | + * @param IConfig $config |
|
| 71 | + * @param \OC_Defaults $defaults |
|
| 72 | + * @param string $serverRoot |
|
| 73 | + * @param ICache $depsCache |
|
| 74 | + */ |
|
| 75 | + public function __construct(ILogger $logger, |
|
| 76 | + Factory $appDataFactory, |
|
| 77 | + IURLGenerator $urlGenerator, |
|
| 78 | + IConfig $config, |
|
| 79 | + \OC_Defaults $defaults, |
|
| 80 | + $serverRoot, |
|
| 81 | + ICache $depsCache) { |
|
| 82 | + $this->logger = $logger; |
|
| 83 | + $this->appData = $appDataFactory->get('css'); |
|
| 84 | + $this->urlGenerator = $urlGenerator; |
|
| 85 | + $this->config = $config; |
|
| 86 | + $this->defaults = $defaults; |
|
| 87 | + $this->serverRoot = $serverRoot; |
|
| 88 | + $this->depsCache = $depsCache; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Process the caching process if needed |
|
| 93 | + * @param string $root Root path to the nextcloud installation |
|
| 94 | + * @param string $file |
|
| 95 | + * @param string $app The app name |
|
| 96 | + * @return boolean |
|
| 97 | + */ |
|
| 98 | + public function process($root, $file, $app) { |
|
| 99 | + $path = explode('/', $root . '/' . $file); |
|
| 100 | + |
|
| 101 | + $fileNameSCSS = array_pop($path); |
|
| 102 | + $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
|
| 103 | + |
|
| 104 | + $path = implode('/', $path); |
|
| 105 | + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 106 | + |
|
| 107 | + try { |
|
| 108 | + $folder = $this->appData->getFolder($app); |
|
| 109 | + } catch(NotFoundException $e) { |
|
| 110 | + // creating css appdata folder |
|
| 111 | + $folder = $this->appData->newFolder($app); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param $appName |
|
| 119 | + * @param $fileName |
|
| 120 | + * @return ISimpleFile |
|
| 121 | + */ |
|
| 122 | + public function getCachedCSS($appName, $fileName) { |
|
| 123 | + $folder = $this->appData->getFolder($appName); |
|
| 124 | + return $folder->getFile($this->prependBaseurlPrefix($fileName)); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Check if the file is cached or not |
|
| 129 | + * @param string $fileNameCSS |
|
| 130 | + * @param ISimpleFolder $folder |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + private function isCached($fileNameCSS, ISimpleFolder $folder) { |
|
| 134 | + if ($this->variablesChanged()) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + try { |
|
| 138 | + $cachedFile = $folder->getFile($fileNameCSS); |
|
| 139 | + if ($cachedFile->getSize() > 0) { |
|
| 140 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 141 | + $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 142 | + if ($deps === null) { |
|
| 143 | + $depFile = $folder->getFile($depFileName); |
|
| 144 | + $deps = $depFile->getContent(); |
|
| 145 | + //Set to memcache for next run |
|
| 146 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 147 | + } |
|
| 148 | + $deps = json_decode($deps, true); |
|
| 149 | + |
|
| 150 | + foreach ($deps as $file=>$mtime) { |
|
| 151 | + if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + return true; |
|
| 157 | + } catch(NotFoundException $e) { |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Check if the variables file has changed |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + private function variablesChanged() { |
|
| 167 | + $injectedVariables = $this->getInjectedVariables(); |
|
| 168 | + if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 169 | + $this->resetCache(); |
|
| 170 | + $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Cache the file with AppData |
|
| 178 | + * @param string $path |
|
| 179 | + * @param string $fileNameCSS |
|
| 180 | + * @param string $fileNameSCSS |
|
| 181 | + * @param ISimpleFolder $folder |
|
| 182 | + * @param string $webDir |
|
| 183 | + * @return boolean |
|
| 184 | + */ |
|
| 185 | + private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) { |
|
| 186 | + $scss = new Compiler(); |
|
| 187 | + $scss->setImportPaths([ |
|
| 188 | + $path, |
|
| 189 | + $this->serverRoot . '/core/css/', |
|
| 190 | + ]); |
|
| 191 | + // Continue after throw |
|
| 192 | + $scss->setIgnoreErrors(true); |
|
| 193 | + if($this->config->getSystemValue('debug')) { |
|
| 194 | + // Debug mode |
|
| 195 | + $scss->setFormatter(Expanded::class); |
|
| 196 | + $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 197 | + } else { |
|
| 198 | + // Compression |
|
| 199 | + $scss->setFormatter(Crunched::class); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + try { |
|
| 203 | + $cachedfile = $folder->getFile($fileNameCSS); |
|
| 204 | + } catch(NotFoundException $e) { |
|
| 205 | + $cachedfile = $folder->newFile($fileNameCSS); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 209 | + try { |
|
| 210 | + $depFile = $folder->getFile($depFileName); |
|
| 211 | + } catch (NotFoundException $e) { |
|
| 212 | + $depFile = $folder->newFile($depFileName); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // Compile |
|
| 216 | + try { |
|
| 217 | + $compiledScss = $scss->compile( |
|
| 218 | + '@import "variables.scss";' . |
|
| 219 | + $this->getInjectedVariables() . |
|
| 220 | + '@import "'.$fileNameSCSS.'";'); |
|
| 221 | + } catch(ParserException $e) { |
|
| 222 | + $this->logger->error($e, ['app' => 'core']); |
|
| 223 | + return false; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Gzip file |
|
| 227 | + try { |
|
| 228 | + $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 229 | + } catch (NotFoundException $e) { |
|
| 230 | + $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + try { |
|
| 234 | + $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 235 | + $cachedfile->putContent($data); |
|
| 236 | + $deps = json_encode($scss->getParsedFiles()); |
|
| 237 | + $depFile->putContent($deps); |
|
| 238 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 239 | + $gzipFile->putContent(gzencode($data, 9)); |
|
| 240 | + $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 241 | + return true; |
|
| 242 | + } catch(NotPermittedException $e) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Reset scss cache by deleting all generated css files |
|
| 249 | + * We need to regenerate all files when variables change |
|
| 250 | + */ |
|
| 251 | + private function resetCache() { |
|
| 252 | + $appDirectory = $this->appData->getDirectoryListing(); |
|
| 253 | + if(empty($appDirectory)){ |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + foreach ($appDirectory as $folder) { |
|
| 257 | + foreach ($folder->getDirectoryListing() as $file) { |
|
| 258 | + if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") { |
|
| 259 | + $file->delete(); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return string SCSS code for variables from OC_Defaults |
|
| 267 | + */ |
|
| 268 | + private function getInjectedVariables() { |
|
| 269 | + $variables = ''; |
|
| 270 | + foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 271 | + $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 272 | + } |
|
| 273 | + return $variables; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Add the correct uri prefix to make uri valid again |
|
| 278 | + * @param string $css |
|
| 279 | + * @param string $webDir |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + private function rebaseUrls($css, $webDir) { |
|
| 283 | + $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; |
|
| 284 | + $subst = 'url('.$webDir.'/$1)'; |
|
| 285 | + return preg_replace($re, $subst, $css); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Return the cached css file uri |
|
| 290 | + * @param string $appName the app name |
|
| 291 | + * @param string $fileName |
|
| 292 | + * @return string |
|
| 293 | + */ |
|
| 294 | + public function getCachedSCSS($appName, $fileName) { |
|
| 295 | + $tmpfileLoc = explode('/', $fileName); |
|
| 296 | + $fileName = array_pop($tmpfileLoc); |
|
| 297 | + $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); |
|
| 298 | + |
|
| 299 | + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Prepend hashed base url to the css file |
|
| 304 | + * @param $cssFile |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | + private function prependBaseurlPrefix($cssFile) { |
|
| 308 | + $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 309 | + return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Get WebDir root |
|
| 314 | + * @param string $path the css file path |
|
| 315 | + * @param string $appName the app name |
|
| 316 | + * @param string $serverRoot the server root path |
|
| 317 | + * @param string $webRoot the nextcloud installation root path |
|
| 318 | + * @return string the webDir |
|
| 319 | + */ |
|
| 320 | + private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
|
| 321 | + // Detect if path is within server root AND if path is within an app path |
|
| 322 | + if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 323 | + // Get the file path within the app directory |
|
| 324 | + $appDirectoryPath = explode($appName, $path)[1]; |
|
| 325 | + // Remove the webroot |
|
| 326 | + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 327 | + } |
|
| 328 | + return $webRoot.substr($path, strlen($serverRoot)); |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return boolean |
| 97 | 97 | */ |
| 98 | 98 | public function process($root, $file, $app) { |
| 99 | - $path = explode('/', $root . '/' . $file); |
|
| 99 | + $path = explode('/', $root.'/'.$file); |
|
| 100 | 100 | |
| 101 | 101 | $fileNameSCSS = array_pop($path); |
| 102 | 102 | $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | try { |
| 108 | 108 | $folder = $this->appData->getFolder($app); |
| 109 | - } catch(NotFoundException $e) { |
|
| 109 | + } catch (NotFoundException $e) { |
|
| 110 | 110 | // creating css appdata folder |
| 111 | 111 | $folder = $this->appData->newFolder($app); |
| 112 | 112 | } |
@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | try { |
| 138 | 138 | $cachedFile = $folder->getFile($fileNameCSS); |
| 139 | 139 | if ($cachedFile->getSize() > 0) { |
| 140 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 141 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 140 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 141 | + $deps = $this->depsCache->get($folder->getName().'-'.$depFileName); |
|
| 142 | 142 | if ($deps === null) { |
| 143 | 143 | $depFile = $folder->getFile($depFileName); |
| 144 | 144 | $deps = $depFile->getContent(); |
| 145 | 145 | //Set to memcache for next run |
| 146 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 146 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 147 | 147 | } |
| 148 | 148 | $deps = json_decode($deps, true); |
| 149 | 149 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | return true; |
| 157 | - } catch(NotFoundException $e) { |
|
| 157 | + } catch (NotFoundException $e) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | private function variablesChanged() { |
| 167 | 167 | $injectedVariables = $this->getInjectedVariables(); |
| 168 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 168 | + if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 169 | 169 | $this->resetCache(); |
| 170 | 170 | $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
| 171 | 171 | return true; |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | $scss = new Compiler(); |
| 187 | 187 | $scss->setImportPaths([ |
| 188 | 188 | $path, |
| 189 | - $this->serverRoot . '/core/css/', |
|
| 189 | + $this->serverRoot.'/core/css/', |
|
| 190 | 190 | ]); |
| 191 | 191 | // Continue after throw |
| 192 | 192 | $scss->setIgnoreErrors(true); |
| 193 | - if($this->config->getSystemValue('debug')) { |
|
| 193 | + if ($this->config->getSystemValue('debug')) { |
|
| 194 | 194 | // Debug mode |
| 195 | 195 | $scss->setFormatter(Expanded::class); |
| 196 | 196 | $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | try { |
| 203 | 203 | $cachedfile = $folder->getFile($fileNameCSS); |
| 204 | - } catch(NotFoundException $e) { |
|
| 204 | + } catch (NotFoundException $e) { |
|
| 205 | 205 | $cachedfile = $folder->newFile($fileNameCSS); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 208 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 209 | 209 | try { |
| 210 | 210 | $depFile = $folder->getFile($depFileName); |
| 211 | 211 | } catch (NotFoundException $e) { |
@@ -215,19 +215,19 @@ discard block |
||
| 215 | 215 | // Compile |
| 216 | 216 | try { |
| 217 | 217 | $compiledScss = $scss->compile( |
| 218 | - '@import "variables.scss";' . |
|
| 219 | - $this->getInjectedVariables() . |
|
| 218 | + '@import "variables.scss";'. |
|
| 219 | + $this->getInjectedVariables(). |
|
| 220 | 220 | '@import "'.$fileNameSCSS.'";'); |
| 221 | - } catch(ParserException $e) { |
|
| 221 | + } catch (ParserException $e) { |
|
| 222 | 222 | $this->logger->error($e, ['app' => 'core']); |
| 223 | 223 | return false; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Gzip file |
| 227 | 227 | try { |
| 228 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 228 | + $gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 229 | 229 | } catch (NotFoundException $e) { |
| 230 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 230 | + $gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | try { |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | $cachedfile->putContent($data); |
| 236 | 236 | $deps = json_encode($scss->getParsedFiles()); |
| 237 | 237 | $depFile->putContent($deps); |
| 238 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 238 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 239 | 239 | $gzipFile->putContent(gzencode($data, 9)); |
| 240 | 240 | $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
| 241 | 241 | return true; |
| 242 | - } catch(NotPermittedException $e) { |
|
| 242 | + } catch (NotPermittedException $e) { |
|
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | private function resetCache() { |
| 252 | 252 | $appDirectory = $this->appData->getDirectoryListing(); |
| 253 | - if(empty($appDirectory)){ |
|
| 253 | + if (empty($appDirectory)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | foreach ($appDirectory as $folder) { |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | private function getInjectedVariables() { |
| 269 | 269 | $variables = ''; |
| 270 | 270 | foreach ($this->defaults->getScssVariables() as $key => $value) { |
| 271 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 271 | + $variables .= '$'.$key.': '.$value.';'; |
|
| 272 | 272 | } |
| 273 | 273 | return $variables; |
| 274 | 274 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | private function prependBaseurlPrefix($cssFile) { |
| 308 | 308 | $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
| 309 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 309 | + return substr(md5($this->urlGenerator->getBaseUrl().$frontendController), 0, 8).'-'.$cssFile; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
| 321 | 321 | // Detect if path is within server root AND if path is within an app path |
| 322 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 322 | + if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 323 | 323 | // Get the file path within the app directory |
| 324 | 324 | $appDirectoryPath = explode($appName, $path)[1]; |
| 325 | 325 | // Remove the webroot |
@@ -62,391 +62,391 @@ discard block |
||
| 62 | 62 | * @package OCA\Theming\Controller |
| 63 | 63 | */ |
| 64 | 64 | class ThemingController extends Controller { |
| 65 | - /** @var ThemingDefaults */ |
|
| 66 | - private $themingDefaults; |
|
| 67 | - /** @var Util */ |
|
| 68 | - private $util; |
|
| 69 | - /** @var ITimeFactory */ |
|
| 70 | - private $timeFactory; |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - private $l10n; |
|
| 73 | - /** @var IConfig */ |
|
| 74 | - private $config; |
|
| 75 | - /** @var ITempManager */ |
|
| 76 | - private $tempManager; |
|
| 77 | - /** @var IAppData */ |
|
| 78 | - private $appData; |
|
| 79 | - /** @var SCSSCacher */ |
|
| 80 | - private $scssCacher; |
|
| 81 | - /** @var IURLGenerator */ |
|
| 82 | - private $urlGenerator; |
|
| 65 | + /** @var ThemingDefaults */ |
|
| 66 | + private $themingDefaults; |
|
| 67 | + /** @var Util */ |
|
| 68 | + private $util; |
|
| 69 | + /** @var ITimeFactory */ |
|
| 70 | + private $timeFactory; |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + private $l10n; |
|
| 73 | + /** @var IConfig */ |
|
| 74 | + private $config; |
|
| 75 | + /** @var ITempManager */ |
|
| 76 | + private $tempManager; |
|
| 77 | + /** @var IAppData */ |
|
| 78 | + private $appData; |
|
| 79 | + /** @var SCSSCacher */ |
|
| 80 | + private $scssCacher; |
|
| 81 | + /** @var IURLGenerator */ |
|
| 82 | + private $urlGenerator; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * ThemingController constructor. |
|
| 86 | - * |
|
| 87 | - * @param string $appName |
|
| 88 | - * @param IRequest $request |
|
| 89 | - * @param IConfig $config |
|
| 90 | - * @param ThemingDefaults $themingDefaults |
|
| 91 | - * @param Util $util |
|
| 92 | - * @param ITimeFactory $timeFactory |
|
| 93 | - * @param IL10N $l |
|
| 94 | - * @param ITempManager $tempManager |
|
| 95 | - * @param IAppData $appData |
|
| 96 | - * @param SCSSCacher $scssCacher |
|
| 97 | - * @param IURLGenerator $urlGenerator |
|
| 98 | - */ |
|
| 99 | - public function __construct( |
|
| 100 | - $appName, |
|
| 101 | - IRequest $request, |
|
| 102 | - IConfig $config, |
|
| 103 | - ThemingDefaults $themingDefaults, |
|
| 104 | - Util $util, |
|
| 105 | - ITimeFactory $timeFactory, |
|
| 106 | - IL10N $l, |
|
| 107 | - ITempManager $tempManager, |
|
| 108 | - IAppData $appData, |
|
| 109 | - SCSSCacher $scssCacher, |
|
| 110 | - IURLGenerator $urlGenerator |
|
| 111 | - ) { |
|
| 112 | - parent::__construct($appName, $request); |
|
| 84 | + /** |
|
| 85 | + * ThemingController constructor. |
|
| 86 | + * |
|
| 87 | + * @param string $appName |
|
| 88 | + * @param IRequest $request |
|
| 89 | + * @param IConfig $config |
|
| 90 | + * @param ThemingDefaults $themingDefaults |
|
| 91 | + * @param Util $util |
|
| 92 | + * @param ITimeFactory $timeFactory |
|
| 93 | + * @param IL10N $l |
|
| 94 | + * @param ITempManager $tempManager |
|
| 95 | + * @param IAppData $appData |
|
| 96 | + * @param SCSSCacher $scssCacher |
|
| 97 | + * @param IURLGenerator $urlGenerator |
|
| 98 | + */ |
|
| 99 | + public function __construct( |
|
| 100 | + $appName, |
|
| 101 | + IRequest $request, |
|
| 102 | + IConfig $config, |
|
| 103 | + ThemingDefaults $themingDefaults, |
|
| 104 | + Util $util, |
|
| 105 | + ITimeFactory $timeFactory, |
|
| 106 | + IL10N $l, |
|
| 107 | + ITempManager $tempManager, |
|
| 108 | + IAppData $appData, |
|
| 109 | + SCSSCacher $scssCacher, |
|
| 110 | + IURLGenerator $urlGenerator |
|
| 111 | + ) { |
|
| 112 | + parent::__construct($appName, $request); |
|
| 113 | 113 | |
| 114 | - $this->themingDefaults = $themingDefaults; |
|
| 115 | - $this->util = $util; |
|
| 116 | - $this->timeFactory = $timeFactory; |
|
| 117 | - $this->l10n = $l; |
|
| 118 | - $this->config = $config; |
|
| 119 | - $this->tempManager = $tempManager; |
|
| 120 | - $this->appData = $appData; |
|
| 121 | - $this->scssCacher = $scssCacher; |
|
| 122 | - $this->urlGenerator = $urlGenerator; |
|
| 123 | - } |
|
| 114 | + $this->themingDefaults = $themingDefaults; |
|
| 115 | + $this->util = $util; |
|
| 116 | + $this->timeFactory = $timeFactory; |
|
| 117 | + $this->l10n = $l; |
|
| 118 | + $this->config = $config; |
|
| 119 | + $this->tempManager = $tempManager; |
|
| 120 | + $this->appData = $appData; |
|
| 121 | + $this->scssCacher = $scssCacher; |
|
| 122 | + $this->urlGenerator = $urlGenerator; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @param string $setting |
|
| 127 | - * @param string $value |
|
| 128 | - * @return DataResponse |
|
| 129 | - * @internal param string $color |
|
| 130 | - */ |
|
| 131 | - public function updateStylesheet($setting, $value) { |
|
| 132 | - $value = trim($value); |
|
| 133 | - switch ($setting) { |
|
| 134 | - case 'name': |
|
| 135 | - if (strlen($value) > 250) { |
|
| 136 | - return new DataResponse([ |
|
| 137 | - 'data' => [ |
|
| 138 | - 'message' => $this->l10n->t('The given name is too long'), |
|
| 139 | - ], |
|
| 140 | - 'status' => 'error' |
|
| 141 | - ]); |
|
| 142 | - } |
|
| 143 | - break; |
|
| 144 | - case 'url': |
|
| 145 | - if (strlen($value) > 500) { |
|
| 146 | - return new DataResponse([ |
|
| 147 | - 'data' => [ |
|
| 148 | - 'message' => $this->l10n->t('The given web address is too long'), |
|
| 149 | - ], |
|
| 150 | - 'status' => 'error' |
|
| 151 | - ]); |
|
| 152 | - } |
|
| 153 | - break; |
|
| 154 | - case 'slogan': |
|
| 155 | - if (strlen($value) > 500) { |
|
| 156 | - return new DataResponse([ |
|
| 157 | - 'data' => [ |
|
| 158 | - 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 159 | - ], |
|
| 160 | - 'status' => 'error' |
|
| 161 | - ]); |
|
| 162 | - } |
|
| 163 | - break; |
|
| 164 | - case 'color': |
|
| 165 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 166 | - return new DataResponse([ |
|
| 167 | - 'data' => [ |
|
| 168 | - 'message' => $this->l10n->t('The given color is invalid'), |
|
| 169 | - ], |
|
| 170 | - 'status' => 'error' |
|
| 171 | - ]); |
|
| 172 | - } |
|
| 173 | - break; |
|
| 174 | - } |
|
| 125 | + /** |
|
| 126 | + * @param string $setting |
|
| 127 | + * @param string $value |
|
| 128 | + * @return DataResponse |
|
| 129 | + * @internal param string $color |
|
| 130 | + */ |
|
| 131 | + public function updateStylesheet($setting, $value) { |
|
| 132 | + $value = trim($value); |
|
| 133 | + switch ($setting) { |
|
| 134 | + case 'name': |
|
| 135 | + if (strlen($value) > 250) { |
|
| 136 | + return new DataResponse([ |
|
| 137 | + 'data' => [ |
|
| 138 | + 'message' => $this->l10n->t('The given name is too long'), |
|
| 139 | + ], |
|
| 140 | + 'status' => 'error' |
|
| 141 | + ]); |
|
| 142 | + } |
|
| 143 | + break; |
|
| 144 | + case 'url': |
|
| 145 | + if (strlen($value) > 500) { |
|
| 146 | + return new DataResponse([ |
|
| 147 | + 'data' => [ |
|
| 148 | + 'message' => $this->l10n->t('The given web address is too long'), |
|
| 149 | + ], |
|
| 150 | + 'status' => 'error' |
|
| 151 | + ]); |
|
| 152 | + } |
|
| 153 | + break; |
|
| 154 | + case 'slogan': |
|
| 155 | + if (strlen($value) > 500) { |
|
| 156 | + return new DataResponse([ |
|
| 157 | + 'data' => [ |
|
| 158 | + 'message' => $this->l10n->t('The given slogan is too long'), |
|
| 159 | + ], |
|
| 160 | + 'status' => 'error' |
|
| 161 | + ]); |
|
| 162 | + } |
|
| 163 | + break; |
|
| 164 | + case 'color': |
|
| 165 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 166 | + return new DataResponse([ |
|
| 167 | + 'data' => [ |
|
| 168 | + 'message' => $this->l10n->t('The given color is invalid'), |
|
| 169 | + ], |
|
| 170 | + 'status' => 'error' |
|
| 171 | + ]); |
|
| 172 | + } |
|
| 173 | + break; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - $this->themingDefaults->set($setting, $value); |
|
| 176 | + $this->themingDefaults->set($setting, $value); |
|
| 177 | 177 | |
| 178 | - // reprocess server scss for preview |
|
| 179 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 178 | + // reprocess server scss for preview |
|
| 179 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
| 180 | 180 | |
| 181 | - return new DataResponse( |
|
| 182 | - [ |
|
| 183 | - 'data' => |
|
| 184 | - [ |
|
| 185 | - 'message' => $this->l10n->t('Saved'), |
|
| 186 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 187 | - ], |
|
| 188 | - 'status' => 'success' |
|
| 189 | - ] |
|
| 190 | - ); |
|
| 191 | - } |
|
| 181 | + return new DataResponse( |
|
| 182 | + [ |
|
| 183 | + 'data' => |
|
| 184 | + [ |
|
| 185 | + 'message' => $this->l10n->t('Saved'), |
|
| 186 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 187 | + ], |
|
| 188 | + 'status' => 'success' |
|
| 189 | + ] |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Update the logos and background image |
|
| 195 | - * |
|
| 196 | - * @return DataResponse |
|
| 197 | - */ |
|
| 198 | - public function updateLogo() { |
|
| 199 | - $backgroundColor = $this->request->getParam('backgroundColor', false); |
|
| 200 | - if($backgroundColor) { |
|
| 201 | - $this->themingDefaults->set('backgroundMime', 'backgroundColor'); |
|
| 202 | - return new DataResponse( |
|
| 203 | - [ |
|
| 204 | - 'data' => |
|
| 205 | - [ |
|
| 206 | - 'name' => 'backgroundColor', |
|
| 207 | - 'message' => $this->l10n->t('Saved') |
|
| 208 | - ], |
|
| 209 | - 'status' => 'success' |
|
| 210 | - ] |
|
| 211 | - ); |
|
| 212 | - } |
|
| 213 | - $newLogo = $this->request->getUploadedFile('uploadlogo'); |
|
| 214 | - $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); |
|
| 215 | - $error = null; |
|
| 216 | - $phpFileUploadErrors = [ |
|
| 217 | - UPLOAD_ERR_OK => $this->l10n->t('There is no error, the file uploaded with success'), |
|
| 218 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 219 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 220 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The uploaded file was only partially uploaded'), |
|
| 221 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 222 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 223 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Failed to write file to disk.'), |
|
| 224 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload.'), |
|
| 225 | - ]; |
|
| 226 | - if (empty($newLogo) && empty($newBackgroundLogo)) { |
|
| 227 | - $error = $this->l10n->t('No file uploaded'); |
|
| 228 | - } |
|
| 229 | - if (!empty($newLogo) && array_key_exists('error', $newLogo) && $newLogo['error'] !== UPLOAD_ERR_OK) { |
|
| 230 | - $error = $phpFileUploadErrors[$newLogo['error']]; |
|
| 231 | - } |
|
| 232 | - if (!empty($newBackgroundLogo) && array_key_exists('error', $newBackgroundLogo) && $newBackgroundLogo['error'] !== UPLOAD_ERR_OK) { |
|
| 233 | - $error = $phpFileUploadErrors[$newBackgroundLogo['error']]; |
|
| 234 | - } |
|
| 193 | + /** |
|
| 194 | + * Update the logos and background image |
|
| 195 | + * |
|
| 196 | + * @return DataResponse |
|
| 197 | + */ |
|
| 198 | + public function updateLogo() { |
|
| 199 | + $backgroundColor = $this->request->getParam('backgroundColor', false); |
|
| 200 | + if($backgroundColor) { |
|
| 201 | + $this->themingDefaults->set('backgroundMime', 'backgroundColor'); |
|
| 202 | + return new DataResponse( |
|
| 203 | + [ |
|
| 204 | + 'data' => |
|
| 205 | + [ |
|
| 206 | + 'name' => 'backgroundColor', |
|
| 207 | + 'message' => $this->l10n->t('Saved') |
|
| 208 | + ], |
|
| 209 | + 'status' => 'success' |
|
| 210 | + ] |
|
| 211 | + ); |
|
| 212 | + } |
|
| 213 | + $newLogo = $this->request->getUploadedFile('uploadlogo'); |
|
| 214 | + $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background'); |
|
| 215 | + $error = null; |
|
| 216 | + $phpFileUploadErrors = [ |
|
| 217 | + UPLOAD_ERR_OK => $this->l10n->t('There is no error, the file uploaded with success'), |
|
| 218 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 219 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 220 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The uploaded file was only partially uploaded'), |
|
| 221 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 222 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 223 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Failed to write file to disk.'), |
|
| 224 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload.'), |
|
| 225 | + ]; |
|
| 226 | + if (empty($newLogo) && empty($newBackgroundLogo)) { |
|
| 227 | + $error = $this->l10n->t('No file uploaded'); |
|
| 228 | + } |
|
| 229 | + if (!empty($newLogo) && array_key_exists('error', $newLogo) && $newLogo['error'] !== UPLOAD_ERR_OK) { |
|
| 230 | + $error = $phpFileUploadErrors[$newLogo['error']]; |
|
| 231 | + } |
|
| 232 | + if (!empty($newBackgroundLogo) && array_key_exists('error', $newBackgroundLogo) && $newBackgroundLogo['error'] !== UPLOAD_ERR_OK) { |
|
| 233 | + $error = $phpFileUploadErrors[$newBackgroundLogo['error']]; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - if ($error !== null) { |
|
| 237 | - return new DataResponse( |
|
| 238 | - [ |
|
| 239 | - 'data' => [ |
|
| 240 | - 'message' => $error |
|
| 241 | - ], |
|
| 242 | - 'status' => 'failure', |
|
| 243 | - ], |
|
| 244 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 245 | - ); |
|
| 246 | - } |
|
| 236 | + if ($error !== null) { |
|
| 237 | + return new DataResponse( |
|
| 238 | + [ |
|
| 239 | + 'data' => [ |
|
| 240 | + 'message' => $error |
|
| 241 | + ], |
|
| 242 | + 'status' => 'failure', |
|
| 243 | + ], |
|
| 244 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 245 | + ); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - $name = ''; |
|
| 249 | - try { |
|
| 250 | - $folder = $this->appData->getFolder('images'); |
|
| 251 | - } catch (NotFoundException $e) { |
|
| 252 | - $folder = $this->appData->newFolder('images'); |
|
| 253 | - } |
|
| 248 | + $name = ''; |
|
| 249 | + try { |
|
| 250 | + $folder = $this->appData->getFolder('images'); |
|
| 251 | + } catch (NotFoundException $e) { |
|
| 252 | + $folder = $this->appData->newFolder('images'); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - if (!empty($newLogo)) { |
|
| 256 | - $target = $folder->newFile('logo'); |
|
| 257 | - $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; |
|
| 258 | - if (!in_array($newLogo['type'], $supportedFormats)) { |
|
| 259 | - return new DataResponse( |
|
| 260 | - [ |
|
| 261 | - 'data' => [ |
|
| 262 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
| 263 | - ], |
|
| 264 | - 'status' => 'failure', |
|
| 265 | - ], |
|
| 266 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); |
|
| 270 | - $this->themingDefaults->set('logoMime', $newLogo['type']); |
|
| 271 | - $name = $newLogo['name']; |
|
| 272 | - } |
|
| 273 | - if (!empty($newBackgroundLogo)) { |
|
| 274 | - $target = $folder->newFile('background'); |
|
| 275 | - $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); |
|
| 276 | - if ($image === false) { |
|
| 277 | - return new DataResponse( |
|
| 278 | - [ |
|
| 279 | - 'data' => [ |
|
| 280 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
| 281 | - ], |
|
| 282 | - 'status' => 'failure', |
|
| 283 | - ], |
|
| 284 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 285 | - ); |
|
| 286 | - } |
|
| 255 | + if (!empty($newLogo)) { |
|
| 256 | + $target = $folder->newFile('logo'); |
|
| 257 | + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; |
|
| 258 | + if (!in_array($newLogo['type'], $supportedFormats)) { |
|
| 259 | + return new DataResponse( |
|
| 260 | + [ |
|
| 261 | + 'data' => [ |
|
| 262 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
| 263 | + ], |
|
| 264 | + 'status' => 'failure', |
|
| 265 | + ], |
|
| 266 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); |
|
| 270 | + $this->themingDefaults->set('logoMime', $newLogo['type']); |
|
| 271 | + $name = $newLogo['name']; |
|
| 272 | + } |
|
| 273 | + if (!empty($newBackgroundLogo)) { |
|
| 274 | + $target = $folder->newFile('background'); |
|
| 275 | + $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); |
|
| 276 | + if ($image === false) { |
|
| 277 | + return new DataResponse( |
|
| 278 | + [ |
|
| 279 | + 'data' => [ |
|
| 280 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
| 281 | + ], |
|
| 282 | + 'status' => 'failure', |
|
| 283 | + ], |
|
| 284 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - // Optimize the image since some people may upload images that will be |
|
| 289 | - // either to big or are not progressive rendering. |
|
| 290 | - $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 291 | - if (function_exists('imagescale')) { |
|
| 292 | - // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed |
|
| 293 | - // Workaround for https://bugs.php.net/bug.php?id=65171 |
|
| 294 | - $newHeight = imagesy($image) / (imagesx($image) / 1920); |
|
| 295 | - $image = imagescale($image, 1920, $newHeight); |
|
| 296 | - } |
|
| 297 | - imageinterlace($image, 1); |
|
| 298 | - imagejpeg($image, $tmpFile, 75); |
|
| 299 | - imagedestroy($image); |
|
| 288 | + // Optimize the image since some people may upload images that will be |
|
| 289 | + // either to big or are not progressive rendering. |
|
| 290 | + $tmpFile = $this->tempManager->getTemporaryFile(); |
|
| 291 | + if (function_exists('imagescale')) { |
|
| 292 | + // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed |
|
| 293 | + // Workaround for https://bugs.php.net/bug.php?id=65171 |
|
| 294 | + $newHeight = imagesy($image) / (imagesx($image) / 1920); |
|
| 295 | + $image = imagescale($image, 1920, $newHeight); |
|
| 296 | + } |
|
| 297 | + imageinterlace($image, 1); |
|
| 298 | + imagejpeg($image, $tmpFile, 75); |
|
| 299 | + imagedestroy($image); |
|
| 300 | 300 | |
| 301 | - $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 302 | - $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']); |
|
| 303 | - $name = $newBackgroundLogo['name']; |
|
| 304 | - } |
|
| 301 | + $target->putContent(file_get_contents($tmpFile, 'r')); |
|
| 302 | + $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']); |
|
| 303 | + $name = $newBackgroundLogo['name']; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - return new DataResponse( |
|
| 307 | - [ |
|
| 308 | - 'data' => |
|
| 309 | - [ |
|
| 310 | - 'name' => $name, |
|
| 311 | - 'message' => $this->l10n->t('Saved') |
|
| 312 | - ], |
|
| 313 | - 'status' => 'success' |
|
| 314 | - ] |
|
| 315 | - ); |
|
| 316 | - } |
|
| 306 | + return new DataResponse( |
|
| 307 | + [ |
|
| 308 | + 'data' => |
|
| 309 | + [ |
|
| 310 | + 'name' => $name, |
|
| 311 | + 'message' => $this->l10n->t('Saved') |
|
| 312 | + ], |
|
| 313 | + 'status' => 'success' |
|
| 314 | + ] |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * Revert setting to default value |
|
| 320 | - * |
|
| 321 | - * @param string $setting setting which should be reverted |
|
| 322 | - * @return DataResponse |
|
| 323 | - */ |
|
| 324 | - public function undo($setting) { |
|
| 325 | - $value = $this->themingDefaults->undo($setting); |
|
| 326 | - // reprocess server scss for preview |
|
| 327 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core'); |
|
| 318 | + /** |
|
| 319 | + * Revert setting to default value |
|
| 320 | + * |
|
| 321 | + * @param string $setting setting which should be reverted |
|
| 322 | + * @return DataResponse |
|
| 323 | + */ |
|
| 324 | + public function undo($setting) { |
|
| 325 | + $value = $this->themingDefaults->undo($setting); |
|
| 326 | + // reprocess server scss for preview |
|
| 327 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core'); |
|
| 328 | 328 | |
| 329 | - if($setting === 'logoMime') { |
|
| 330 | - try { |
|
| 331 | - $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 332 | - $file->delete(); |
|
| 333 | - } catch (NotFoundException $e) { |
|
| 334 | - } catch (NotPermittedException $e) { |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - if($setting === 'backgroundMime') { |
|
| 338 | - try { |
|
| 339 | - $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 340 | - $file->delete(); |
|
| 341 | - } catch (NotFoundException $e) { |
|
| 342 | - } catch (NotPermittedException $e) { |
|
| 343 | - } |
|
| 344 | - } |
|
| 329 | + if($setting === 'logoMime') { |
|
| 330 | + try { |
|
| 331 | + $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 332 | + $file->delete(); |
|
| 333 | + } catch (NotFoundException $e) { |
|
| 334 | + } catch (NotPermittedException $e) { |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + if($setting === 'backgroundMime') { |
|
| 338 | + try { |
|
| 339 | + $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 340 | + $file->delete(); |
|
| 341 | + } catch (NotFoundException $e) { |
|
| 342 | + } catch (NotPermittedException $e) { |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - return new DataResponse( |
|
| 347 | - [ |
|
| 348 | - 'data' => |
|
| 349 | - [ |
|
| 350 | - 'value' => $value, |
|
| 351 | - 'message' => $this->l10n->t('Saved'), |
|
| 352 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 353 | - ], |
|
| 354 | - 'status' => 'success' |
|
| 355 | - ] |
|
| 356 | - ); |
|
| 357 | - } |
|
| 346 | + return new DataResponse( |
|
| 347 | + [ |
|
| 348 | + 'data' => |
|
| 349 | + [ |
|
| 350 | + 'value' => $value, |
|
| 351 | + 'message' => $this->l10n->t('Saved'), |
|
| 352 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
| 353 | + ], |
|
| 354 | + 'status' => 'success' |
|
| 355 | + ] |
|
| 356 | + ); |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * @PublicPage |
|
| 361 | - * @NoCSRFRequired |
|
| 362 | - * |
|
| 363 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 364 | - */ |
|
| 365 | - public function getLogo() { |
|
| 366 | - try { |
|
| 367 | - /** @var File $file */ |
|
| 368 | - $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 369 | - } catch (NotFoundException $e) { |
|
| 370 | - return new NotFoundResponse(); |
|
| 371 | - } |
|
| 359 | + /** |
|
| 360 | + * @PublicPage |
|
| 361 | + * @NoCSRFRequired |
|
| 362 | + * |
|
| 363 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 364 | + */ |
|
| 365 | + public function getLogo() { |
|
| 366 | + try { |
|
| 367 | + /** @var File $file */ |
|
| 368 | + $file = $this->appData->getFolder('images')->getFile('logo'); |
|
| 369 | + } catch (NotFoundException $e) { |
|
| 370 | + return new NotFoundResponse(); |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - $response = new FileDisplayResponse($file); |
|
| 374 | - $response->cacheFor(3600); |
|
| 375 | - $expires = new \DateTime(); |
|
| 376 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 377 | - $expires->add(new \DateInterval('PT24H')); |
|
| 378 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 379 | - $response->addHeader('Pragma', 'cache'); |
|
| 380 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); |
|
| 381 | - return $response; |
|
| 382 | - } |
|
| 373 | + $response = new FileDisplayResponse($file); |
|
| 374 | + $response->cacheFor(3600); |
|
| 375 | + $expires = new \DateTime(); |
|
| 376 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 377 | + $expires->add(new \DateInterval('PT24H')); |
|
| 378 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 379 | + $response->addHeader('Pragma', 'cache'); |
|
| 380 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); |
|
| 381 | + return $response; |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | - /** |
|
| 385 | - * @PublicPage |
|
| 386 | - * @NoCSRFRequired |
|
| 387 | - * |
|
| 388 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 389 | - */ |
|
| 390 | - public function getLoginBackground() { |
|
| 391 | - try { |
|
| 392 | - /** @var File $file */ |
|
| 393 | - $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 394 | - } catch (NotFoundException $e) { |
|
| 395 | - return new NotFoundResponse(); |
|
| 396 | - } |
|
| 384 | + /** |
|
| 385 | + * @PublicPage |
|
| 386 | + * @NoCSRFRequired |
|
| 387 | + * |
|
| 388 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 389 | + */ |
|
| 390 | + public function getLoginBackground() { |
|
| 391 | + try { |
|
| 392 | + /** @var File $file */ |
|
| 393 | + $file = $this->appData->getFolder('images')->getFile('background'); |
|
| 394 | + } catch (NotFoundException $e) { |
|
| 395 | + return new NotFoundResponse(); |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - $response = new FileDisplayResponse($file); |
|
| 399 | - $response->cacheFor(3600); |
|
| 400 | - $expires = new \DateTime(); |
|
| 401 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 402 | - $expires->add(new \DateInterval('PT24H')); |
|
| 403 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 404 | - $response->addHeader('Pragma', 'cache'); |
|
| 405 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); |
|
| 406 | - return $response; |
|
| 407 | - } |
|
| 398 | + $response = new FileDisplayResponse($file); |
|
| 399 | + $response->cacheFor(3600); |
|
| 400 | + $expires = new \DateTime(); |
|
| 401 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 402 | + $expires->add(new \DateInterval('PT24H')); |
|
| 403 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 404 | + $response->addHeader('Pragma', 'cache'); |
|
| 405 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); |
|
| 406 | + return $response; |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * @NoCSRFRequired |
|
| 411 | - * @PublicPage |
|
| 412 | - * |
|
| 413 | - * @return FileDisplayResponse|NotFoundResponse |
|
| 414 | - */ |
|
| 415 | - public function getStylesheet() { |
|
| 416 | - $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); |
|
| 417 | - /* SCSSCacher is required here |
|
| 409 | + /** |
|
| 410 | + * @NoCSRFRequired |
|
| 411 | + * @PublicPage |
|
| 412 | + * |
|
| 413 | + * @return FileDisplayResponse|NotFoundResponse |
|
| 414 | + */ |
|
| 415 | + public function getStylesheet() { |
|
| 416 | + $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); |
|
| 417 | + /* SCSSCacher is required here |
|
| 418 | 418 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
| 419 | 419 | * since we need to add the cacheBuster value to the url |
| 420 | 420 | */ |
| 421 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); |
|
| 422 | - if(!$cssCached) { |
|
| 423 | - return new NotFoundResponse(); |
|
| 424 | - } |
|
| 421 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); |
|
| 422 | + if(!$cssCached) { |
|
| 423 | + return new NotFoundResponse(); |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - try { |
|
| 427 | - $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 428 | - $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 429 | - $response->cacheFor(86400); |
|
| 430 | - $expires = new \DateTime(); |
|
| 431 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 432 | - $expires->add(new \DateInterval('PT24H')); |
|
| 433 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 434 | - $response->addHeader('Pragma', 'cache'); |
|
| 435 | - return $response; |
|
| 436 | - } catch (NotFoundException $e) { |
|
| 437 | - return new NotFoundResponse(); |
|
| 438 | - } |
|
| 439 | - } |
|
| 426 | + try { |
|
| 427 | + $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
| 428 | + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 429 | + $response->cacheFor(86400); |
|
| 430 | + $expires = new \DateTime(); |
|
| 431 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 432 | + $expires->add(new \DateInterval('PT24H')); |
|
| 433 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 434 | + $response->addHeader('Pragma', 'cache'); |
|
| 435 | + return $response; |
|
| 436 | + } catch (NotFoundException $e) { |
|
| 437 | + return new NotFoundResponse(); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - /** |
|
| 442 | - * @NoCSRFRequired |
|
| 443 | - * @PublicPage |
|
| 444 | - * |
|
| 445 | - * @return DataDownloadResponse |
|
| 446 | - */ |
|
| 447 | - public function getJavascript() { |
|
| 448 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 449 | - $responseJS = '(function() { |
|
| 441 | + /** |
|
| 442 | + * @NoCSRFRequired |
|
| 443 | + * @PublicPage |
|
| 444 | + * |
|
| 445 | + * @return DataDownloadResponse |
|
| 446 | + */ |
|
| 447 | + public function getJavascript() { |
|
| 448 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 449 | + $responseJS = '(function() { |
|
| 450 | 450 | OCA.Theming = { |
| 451 | 451 | name: ' . json_encode($this->themingDefaults->getName()) . ', |
| 452 | 452 | url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
@@ -456,45 +456,45 @@ discard block |
||
| 456 | 456 | cacheBuster: ' . json_encode($cacheBusterValue) . ' |
| 457 | 457 | }; |
| 458 | 458 | })();'; |
| 459 | - $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 460 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 461 | - $response->addHeader('Pragma', 'cache'); |
|
| 462 | - $response->cacheFor(3600); |
|
| 463 | - return $response; |
|
| 464 | - } |
|
| 459 | + $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
| 460 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 461 | + $response->addHeader('Pragma', 'cache'); |
|
| 462 | + $response->cacheFor(3600); |
|
| 463 | + return $response; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - /** |
|
| 467 | - * @NoCSRFRequired |
|
| 468 | - * @PublicPage |
|
| 469 | - * |
|
| 470 | - * @return Http\JSONResponse |
|
| 471 | - */ |
|
| 472 | - public function getManifest($app) { |
|
| 473 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 474 | - $responseJS = [ |
|
| 475 | - 'name' => $this->themingDefaults->getName(), |
|
| 476 | - 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
| 477 | - 'icons' => |
|
| 478 | - [ |
|
| 479 | - [ |
|
| 480 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
| 481 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 482 | - 'type'=> 'image/png', |
|
| 483 | - 'sizes'=> '128x128' |
|
| 484 | - ], |
|
| 485 | - [ |
|
| 486 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
| 487 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 488 | - 'type' => 'image/svg+xml', |
|
| 489 | - 'sizes' => '16x16' |
|
| 490 | - ] |
|
| 491 | - ], |
|
| 492 | - 'display' => 'standalone' |
|
| 493 | - ]; |
|
| 494 | - $response = new Http\JSONResponse($responseJS); |
|
| 495 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 496 | - $response->addHeader('Pragma', 'cache'); |
|
| 497 | - $response->cacheFor(3600); |
|
| 498 | - return $response; |
|
| 499 | - } |
|
| 466 | + /** |
|
| 467 | + * @NoCSRFRequired |
|
| 468 | + * @PublicPage |
|
| 469 | + * |
|
| 470 | + * @return Http\JSONResponse |
|
| 471 | + */ |
|
| 472 | + public function getManifest($app) { |
|
| 473 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 474 | + $responseJS = [ |
|
| 475 | + 'name' => $this->themingDefaults->getName(), |
|
| 476 | + 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
| 477 | + 'icons' => |
|
| 478 | + [ |
|
| 479 | + [ |
|
| 480 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
| 481 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 482 | + 'type'=> 'image/png', |
|
| 483 | + 'sizes'=> '128x128' |
|
| 484 | + ], |
|
| 485 | + [ |
|
| 486 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
| 487 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
| 488 | + 'type' => 'image/svg+xml', |
|
| 489 | + 'sizes' => '16x16' |
|
| 490 | + ] |
|
| 491 | + ], |
|
| 492 | + 'display' => 'standalone' |
|
| 493 | + ]; |
|
| 494 | + $response = new Http\JSONResponse($responseJS); |
|
| 495 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
| 496 | + $response->addHeader('Pragma', 'cache'); |
|
| 497 | + $response->cacheFor(3600); |
|
| 498 | + return $response; |
|
| 499 | + } |
|
| 500 | 500 | } |