@@ -44,333 +44,333 @@ |
||
| 44 | 44 | |
| 45 | 45 | class ThemingDefaults extends \OC_Defaults { |
| 46 | 46 | |
| 47 | - /** @var IConfig */ |
|
| 48 | - private $config; |
|
| 49 | - /** @var IL10N */ |
|
| 50 | - private $l; |
|
| 51 | - /** @var IURLGenerator */ |
|
| 52 | - private $urlGenerator; |
|
| 53 | - /** @var IAppData */ |
|
| 54 | - private $appData; |
|
| 55 | - /** @var ICacheFactory */ |
|
| 56 | - private $cacheFactory; |
|
| 57 | - /** @var Util */ |
|
| 58 | - private $util; |
|
| 59 | - /** @var IAppManager */ |
|
| 60 | - private $appManager; |
|
| 61 | - /** @var string */ |
|
| 62 | - private $name; |
|
| 63 | - /** @var string */ |
|
| 64 | - private $title; |
|
| 65 | - /** @var string */ |
|
| 66 | - private $entity; |
|
| 67 | - /** @var string */ |
|
| 68 | - private $url; |
|
| 69 | - /** @var string */ |
|
| 70 | - private $slogan; |
|
| 71 | - /** @var string */ |
|
| 72 | - private $color; |
|
| 73 | - |
|
| 74 | - /** @var string */ |
|
| 75 | - private $iTunesAppId; |
|
| 76 | - /** @var string */ |
|
| 77 | - private $iOSClientUrl; |
|
| 78 | - /** @var string */ |
|
| 79 | - private $AndroidClientUrl; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * ThemingDefaults constructor. |
|
| 83 | - * |
|
| 84 | - * @param IConfig $config |
|
| 85 | - * @param IL10N $l |
|
| 86 | - * @param IURLGenerator $urlGenerator |
|
| 87 | - * @param \OC_Defaults $defaults |
|
| 88 | - * @param IAppData $appData |
|
| 89 | - * @param ICacheFactory $cacheFactory |
|
| 90 | - * @param Util $util |
|
| 91 | - * @param IAppManager $appManager |
|
| 92 | - */ |
|
| 93 | - public function __construct(IConfig $config, |
|
| 94 | - IL10N $l, |
|
| 95 | - IURLGenerator $urlGenerator, |
|
| 96 | - IAppData $appData, |
|
| 97 | - ICacheFactory $cacheFactory, |
|
| 98 | - Util $util, |
|
| 99 | - IAppManager $appManager |
|
| 100 | - ) { |
|
| 101 | - parent::__construct(); |
|
| 102 | - $this->config = $config; |
|
| 103 | - $this->l = $l; |
|
| 104 | - $this->urlGenerator = $urlGenerator; |
|
| 105 | - $this->appData = $appData; |
|
| 106 | - $this->cacheFactory = $cacheFactory; |
|
| 107 | - $this->util = $util; |
|
| 108 | - $this->appManager = $appManager; |
|
| 109 | - |
|
| 110 | - $this->name = parent::getName(); |
|
| 111 | - $this->title = parent::getTitle(); |
|
| 112 | - $this->entity = parent::getEntity(); |
|
| 113 | - $this->url = parent::getBaseUrl(); |
|
| 114 | - $this->slogan = parent::getSlogan(); |
|
| 115 | - $this->color = parent::getColorPrimary(); |
|
| 116 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 117 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 118 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function getName() { |
|
| 122 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function getHTMLName() { |
|
| 126 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function getTitle() { |
|
| 130 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function getEntity() { |
|
| 134 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getBaseUrl() { |
|
| 138 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function getSlogan() { |
|
| 142 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function getShortFooter() { |
|
| 146 | - $slogan = $this->getSlogan(); |
|
| 147 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 148 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
| 149 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 150 | - |
|
| 151 | - return $footer; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Color that is used for the header as well as for mail headers |
|
| 156 | - * |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function getColorPrimary() { |
|
| 160 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Themed logo url |
|
| 165 | - * |
|
| 166 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function getLogo($useSvg = true) { |
|
| 170 | - $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
| 171 | - |
|
| 172 | - $logoExists = true; |
|
| 173 | - try { |
|
| 174 | - $this->appData->getFolder('images')->getFile('logo'); |
|
| 175 | - } catch (\Exception $e) { |
|
| 176 | - $logoExists = false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 180 | - |
|
| 181 | - if(!$logo || !$logoExists) { |
|
| 182 | - if($useSvg) { |
|
| 183 | - $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
| 184 | - } else { |
|
| 185 | - $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
| 186 | - } |
|
| 187 | - return $logo . '?v=' . $cacheBusterCounter; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Themed background image url |
|
| 195 | - * |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public function getBackground() { |
|
| 199 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 200 | - |
|
| 201 | - if($this->util->isBackgroundThemed()) { |
|
| 202 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - public function getiTunesAppId() { |
|
| 212 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function getiOSClientUrl() { |
|
| 219 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function getAndroidClientUrl() { |
|
| 226 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @return array scss variables to overwrite |
|
| 232 | - */ |
|
| 233 | - public function getScssVariables() { |
|
| 234 | - $cache = $this->cacheFactory->createDistributed('theming'); |
|
| 235 | - if ($value = $cache->get('getScssVariables')) { |
|
| 236 | - return $value; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $variables = [ |
|
| 240 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
| 241 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", |
|
| 242 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" |
|
| 243 | - ]; |
|
| 244 | - |
|
| 245 | - $variables['image-logo'] = "'".$this->getLogo()."'"; |
|
| 246 | - $variables['image-login-background'] = "'".$this->getBackground()."'"; |
|
| 247 | - $variables['image-login-plain'] = 'false'; |
|
| 248 | - |
|
| 249 | - if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
| 250 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
| 251 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 252 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
| 256 | - $variables['image-login-plain'] = 'true'; |
|
| 257 | - } |
|
| 258 | - $cache->set('getScssVariables', $variables); |
|
| 259 | - return $variables; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Check if the image should be replaced by the theming app |
|
| 264 | - * and return the new image location then |
|
| 265 | - * |
|
| 266 | - * @param string $app name of the app |
|
| 267 | - * @param string $image filename of the image |
|
| 268 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 269 | - */ |
|
| 270 | - public function replaceImagePath($app, $image) { |
|
| 271 | - if($app==='') { |
|
| 272 | - $app = 'core'; |
|
| 273 | - } |
|
| 274 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 275 | - |
|
| 276 | - if ($image === 'favicon.ico' && $this->shouldReplaceIcons()) { |
|
| 277 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 278 | - } |
|
| 279 | - if ($image === 'favicon-touch.png' && $this->shouldReplaceIcons()) { |
|
| 280 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 281 | - } |
|
| 282 | - if ($image === 'manifest.json') { |
|
| 283 | - try { |
|
| 284 | - $appPath = $this->appManager->getAppPath($app); |
|
| 285 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 288 | - } catch (AppPathNotFoundException $e) {} |
|
| 289 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
| 290 | - } |
|
| 291 | - return false; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Check if Imagemagick is enabled and if SVG is supported |
|
| 296 | - * otherwise we can't render custom icons |
|
| 297 | - * |
|
| 298 | - * @return bool |
|
| 299 | - */ |
|
| 300 | - public function shouldReplaceIcons() { |
|
| 301 | - $cache = $this->cacheFactory->createDistributed('theming'); |
|
| 302 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
| 303 | - return (bool)$value; |
|
| 304 | - } |
|
| 305 | - $value = false; |
|
| 306 | - if(extension_loaded('imagick')) { |
|
| 307 | - $checkImagick = new \Imagick(); |
|
| 308 | - if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
| 309 | - $value = true; |
|
| 310 | - } |
|
| 311 | - $checkImagick->clear(); |
|
| 312 | - } |
|
| 313 | - $cache->set('shouldReplaceIcons', $value); |
|
| 314 | - return $value; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Increases the cache buster key |
|
| 319 | - */ |
|
| 320 | - private function increaseCacheBuster() { |
|
| 321 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 322 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 323 | - $this->cacheFactory->createDistributed('theming')->clear('getScssVariables'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Update setting in the database |
|
| 328 | - * |
|
| 329 | - * @param string $setting |
|
| 330 | - * @param string $value |
|
| 331 | - */ |
|
| 332 | - public function set($setting, $value) { |
|
| 333 | - $this->config->setAppValue('theming', $setting, $value); |
|
| 334 | - $this->increaseCacheBuster(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Revert settings to the default value |
|
| 339 | - * |
|
| 340 | - * @param string $setting setting which should be reverted |
|
| 341 | - * @return string default value |
|
| 342 | - */ |
|
| 343 | - public function undo($setting) { |
|
| 344 | - $this->config->deleteAppValue('theming', $setting); |
|
| 345 | - $this->increaseCacheBuster(); |
|
| 346 | - |
|
| 347 | - switch ($setting) { |
|
| 348 | - case 'name': |
|
| 349 | - $returnValue = $this->getEntity(); |
|
| 350 | - break; |
|
| 351 | - case 'url': |
|
| 352 | - $returnValue = $this->getBaseUrl(); |
|
| 353 | - break; |
|
| 354 | - case 'slogan': |
|
| 355 | - $returnValue = $this->getSlogan(); |
|
| 356 | - break; |
|
| 357 | - case 'color': |
|
| 358 | - $returnValue = $this->getColorPrimary(); |
|
| 359 | - break; |
|
| 360 | - default: |
|
| 361 | - $returnValue = ''; |
|
| 362 | - break; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return $returnValue; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Color of text in the header and primary buttons |
|
| 370 | - * |
|
| 371 | - * @return string |
|
| 372 | - */ |
|
| 373 | - public function getTextColorPrimary() { |
|
| 374 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 375 | - } |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + private $config; |
|
| 49 | + /** @var IL10N */ |
|
| 50 | + private $l; |
|
| 51 | + /** @var IURLGenerator */ |
|
| 52 | + private $urlGenerator; |
|
| 53 | + /** @var IAppData */ |
|
| 54 | + private $appData; |
|
| 55 | + /** @var ICacheFactory */ |
|
| 56 | + private $cacheFactory; |
|
| 57 | + /** @var Util */ |
|
| 58 | + private $util; |
|
| 59 | + /** @var IAppManager */ |
|
| 60 | + private $appManager; |
|
| 61 | + /** @var string */ |
|
| 62 | + private $name; |
|
| 63 | + /** @var string */ |
|
| 64 | + private $title; |
|
| 65 | + /** @var string */ |
|
| 66 | + private $entity; |
|
| 67 | + /** @var string */ |
|
| 68 | + private $url; |
|
| 69 | + /** @var string */ |
|
| 70 | + private $slogan; |
|
| 71 | + /** @var string */ |
|
| 72 | + private $color; |
|
| 73 | + |
|
| 74 | + /** @var string */ |
|
| 75 | + private $iTunesAppId; |
|
| 76 | + /** @var string */ |
|
| 77 | + private $iOSClientUrl; |
|
| 78 | + /** @var string */ |
|
| 79 | + private $AndroidClientUrl; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * ThemingDefaults constructor. |
|
| 83 | + * |
|
| 84 | + * @param IConfig $config |
|
| 85 | + * @param IL10N $l |
|
| 86 | + * @param IURLGenerator $urlGenerator |
|
| 87 | + * @param \OC_Defaults $defaults |
|
| 88 | + * @param IAppData $appData |
|
| 89 | + * @param ICacheFactory $cacheFactory |
|
| 90 | + * @param Util $util |
|
| 91 | + * @param IAppManager $appManager |
|
| 92 | + */ |
|
| 93 | + public function __construct(IConfig $config, |
|
| 94 | + IL10N $l, |
|
| 95 | + IURLGenerator $urlGenerator, |
|
| 96 | + IAppData $appData, |
|
| 97 | + ICacheFactory $cacheFactory, |
|
| 98 | + Util $util, |
|
| 99 | + IAppManager $appManager |
|
| 100 | + ) { |
|
| 101 | + parent::__construct(); |
|
| 102 | + $this->config = $config; |
|
| 103 | + $this->l = $l; |
|
| 104 | + $this->urlGenerator = $urlGenerator; |
|
| 105 | + $this->appData = $appData; |
|
| 106 | + $this->cacheFactory = $cacheFactory; |
|
| 107 | + $this->util = $util; |
|
| 108 | + $this->appManager = $appManager; |
|
| 109 | + |
|
| 110 | + $this->name = parent::getName(); |
|
| 111 | + $this->title = parent::getTitle(); |
|
| 112 | + $this->entity = parent::getEntity(); |
|
| 113 | + $this->url = parent::getBaseUrl(); |
|
| 114 | + $this->slogan = parent::getSlogan(); |
|
| 115 | + $this->color = parent::getColorPrimary(); |
|
| 116 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
| 117 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
| 118 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function getName() { |
|
| 122 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function getHTMLName() { |
|
| 126 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function getTitle() { |
|
| 130 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function getEntity() { |
|
| 134 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getBaseUrl() { |
|
| 138 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function getSlogan() { |
|
| 142 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function getShortFooter() { |
|
| 146 | + $slogan = $this->getSlogan(); |
|
| 147 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 148 | + ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
| 149 | + ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 150 | + |
|
| 151 | + return $footer; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Color that is used for the header as well as for mail headers |
|
| 156 | + * |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function getColorPrimary() { |
|
| 160 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Themed logo url |
|
| 165 | + * |
|
| 166 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function getLogo($useSvg = true) { |
|
| 170 | + $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
| 171 | + |
|
| 172 | + $logoExists = true; |
|
| 173 | + try { |
|
| 174 | + $this->appData->getFolder('images')->getFile('logo'); |
|
| 175 | + } catch (\Exception $e) { |
|
| 176 | + $logoExists = false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 180 | + |
|
| 181 | + if(!$logo || !$logoExists) { |
|
| 182 | + if($useSvg) { |
|
| 183 | + $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
| 184 | + } else { |
|
| 185 | + $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
| 186 | + } |
|
| 187 | + return $logo . '?v=' . $cacheBusterCounter; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Themed background image url |
|
| 195 | + * |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public function getBackground() { |
|
| 199 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 200 | + |
|
| 201 | + if($this->util->isBackgroundThemed()) { |
|
| 202 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + public function getiTunesAppId() { |
|
| 212 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function getiOSClientUrl() { |
|
| 219 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function getAndroidClientUrl() { |
|
| 226 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @return array scss variables to overwrite |
|
| 232 | + */ |
|
| 233 | + public function getScssVariables() { |
|
| 234 | + $cache = $this->cacheFactory->createDistributed('theming'); |
|
| 235 | + if ($value = $cache->get('getScssVariables')) { |
|
| 236 | + return $value; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $variables = [ |
|
| 240 | + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
| 241 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", |
|
| 242 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" |
|
| 243 | + ]; |
|
| 244 | + |
|
| 245 | + $variables['image-logo'] = "'".$this->getLogo()."'"; |
|
| 246 | + $variables['image-login-background'] = "'".$this->getBackground()."'"; |
|
| 247 | + $variables['image-login-plain'] = 'false'; |
|
| 248 | + |
|
| 249 | + if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
| 250 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
| 251 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
| 252 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
| 256 | + $variables['image-login-plain'] = 'true'; |
|
| 257 | + } |
|
| 258 | + $cache->set('getScssVariables', $variables); |
|
| 259 | + return $variables; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Check if the image should be replaced by the theming app |
|
| 264 | + * and return the new image location then |
|
| 265 | + * |
|
| 266 | + * @param string $app name of the app |
|
| 267 | + * @param string $image filename of the image |
|
| 268 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
| 269 | + */ |
|
| 270 | + public function replaceImagePath($app, $image) { |
|
| 271 | + if($app==='') { |
|
| 272 | + $app = 'core'; |
|
| 273 | + } |
|
| 274 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 275 | + |
|
| 276 | + if ($image === 'favicon.ico' && $this->shouldReplaceIcons()) { |
|
| 277 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 278 | + } |
|
| 279 | + if ($image === 'favicon-touch.png' && $this->shouldReplaceIcons()) { |
|
| 280 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 281 | + } |
|
| 282 | + if ($image === 'manifest.json') { |
|
| 283 | + try { |
|
| 284 | + $appPath = $this->appManager->getAppPath($app); |
|
| 285 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | + } catch (AppPathNotFoundException $e) {} |
|
| 289 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
| 290 | + } |
|
| 291 | + return false; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Check if Imagemagick is enabled and if SVG is supported |
|
| 296 | + * otherwise we can't render custom icons |
|
| 297 | + * |
|
| 298 | + * @return bool |
|
| 299 | + */ |
|
| 300 | + public function shouldReplaceIcons() { |
|
| 301 | + $cache = $this->cacheFactory->createDistributed('theming'); |
|
| 302 | + if($value = $cache->get('shouldReplaceIcons')) { |
|
| 303 | + return (bool)$value; |
|
| 304 | + } |
|
| 305 | + $value = false; |
|
| 306 | + if(extension_loaded('imagick')) { |
|
| 307 | + $checkImagick = new \Imagick(); |
|
| 308 | + if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
| 309 | + $value = true; |
|
| 310 | + } |
|
| 311 | + $checkImagick->clear(); |
|
| 312 | + } |
|
| 313 | + $cache->set('shouldReplaceIcons', $value); |
|
| 314 | + return $value; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Increases the cache buster key |
|
| 319 | + */ |
|
| 320 | + private function increaseCacheBuster() { |
|
| 321 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 322 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 323 | + $this->cacheFactory->createDistributed('theming')->clear('getScssVariables'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Update setting in the database |
|
| 328 | + * |
|
| 329 | + * @param string $setting |
|
| 330 | + * @param string $value |
|
| 331 | + */ |
|
| 332 | + public function set($setting, $value) { |
|
| 333 | + $this->config->setAppValue('theming', $setting, $value); |
|
| 334 | + $this->increaseCacheBuster(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Revert settings to the default value |
|
| 339 | + * |
|
| 340 | + * @param string $setting setting which should be reverted |
|
| 341 | + * @return string default value |
|
| 342 | + */ |
|
| 343 | + public function undo($setting) { |
|
| 344 | + $this->config->deleteAppValue('theming', $setting); |
|
| 345 | + $this->increaseCacheBuster(); |
|
| 346 | + |
|
| 347 | + switch ($setting) { |
|
| 348 | + case 'name': |
|
| 349 | + $returnValue = $this->getEntity(); |
|
| 350 | + break; |
|
| 351 | + case 'url': |
|
| 352 | + $returnValue = $this->getBaseUrl(); |
|
| 353 | + break; |
|
| 354 | + case 'slogan': |
|
| 355 | + $returnValue = $this->getSlogan(); |
|
| 356 | + break; |
|
| 357 | + case 'color': |
|
| 358 | + $returnValue = $this->getColorPrimary(); |
|
| 359 | + break; |
|
| 360 | + default: |
|
| 361 | + $returnValue = ''; |
|
| 362 | + break; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return $returnValue; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Color of text in the header and primary buttons |
|
| 370 | + * |
|
| 371 | + * @return string |
|
| 372 | + */ |
|
| 373 | + public function getTextColorPrimary() { |
|
| 374 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
| 375 | + } |
|
| 376 | 376 | } |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public function getShortFooter() { |
| 146 | 146 | $slogan = $this->getSlogan(); |
| 147 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 148 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
| 149 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 147 | + $footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'. |
|
| 148 | + ' rel="noreferrer noopener">'.$this->getEntity().'</a>'. |
|
| 149 | + ($slogan !== '' ? ' – '.$slogan : ''); |
|
| 150 | 150 | |
| 151 | 151 | return $footer; |
| 152 | 152 | } |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 180 | 180 | |
| 181 | - if(!$logo || !$logoExists) { |
|
| 182 | - if($useSvg) { |
|
| 181 | + if (!$logo || !$logoExists) { |
|
| 182 | + if ($useSvg) { |
|
| 183 | 183 | $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
| 184 | 184 | } else { |
| 185 | 185 | $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
| 186 | 186 | } |
| 187 | - return $logo . '?v=' . $cacheBusterCounter; |
|
| 187 | + return $logo.'?v='.$cacheBusterCounter; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; |
|
| 190 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo').'?v='.$cacheBusterCounter; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -198,11 +198,11 @@ discard block |
||
| 198 | 198 | public function getBackground() { |
| 199 | 199 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 200 | 200 | |
| 201 | - if($this->util->isBackgroundThemed()) { |
|
| 202 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; |
|
| 201 | + if ($this->util->isBackgroundThemed()) { |
|
| 202 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground').'?v='.$cacheBusterCounter; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; |
|
| 205 | + return $this->urlGenerator->imagePath('core', 'background.png').'?v='.$cacheBusterCounter; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $variables = [ |
| 240 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
| 241 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'", |
|
| 242 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'" |
|
| 240 | + 'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'", |
|
| 241 | + 'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime', '')."'", |
|
| 242 | + 'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime', '')."'" |
|
| 243 | 243 | ]; |
| 244 | 244 | |
| 245 | 245 | $variables['image-logo'] = "'".$this->getLogo()."'"; |
@@ -268,25 +268,25 @@ discard block |
||
| 268 | 268 | * @return bool|string false if image should not replaced, otherwise the location of the image |
| 269 | 269 | */ |
| 270 | 270 | public function replaceImagePath($app, $image) { |
| 271 | - if($app==='') { |
|
| 271 | + if ($app === '') { |
|
| 272 | 272 | $app = 'core'; |
| 273 | 273 | } |
| 274 | 274 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 275 | 275 | |
| 276 | 276 | if ($image === 'favicon.ico' && $this->shouldReplaceIcons()) { |
| 277 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 277 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
| 278 | 278 | } |
| 279 | 279 | if ($image === 'favicon-touch.png' && $this->shouldReplaceIcons()) { |
| 280 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
| 280 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
| 281 | 281 | } |
| 282 | 282 | if ($image === 'manifest.json') { |
| 283 | 283 | try { |
| 284 | 284 | $appPath = $this->appManager->getAppPath($app); |
| 285 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
| 285 | + if (file_exists($appPath.'/img/manifest.json')) { |
|
| 286 | 286 | return false; |
| 287 | 287 | } |
| 288 | 288 | } catch (AppPathNotFoundException $e) {} |
| 289 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
| 289 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest').'?v='.$cacheBusterValue; |
|
| 290 | 290 | } |
| 291 | 291 | return false; |
| 292 | 292 | } |
@@ -299,11 +299,11 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | public function shouldReplaceIcons() { |
| 301 | 301 | $cache = $this->cacheFactory->createDistributed('theming'); |
| 302 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
| 303 | - return (bool)$value; |
|
| 302 | + if ($value = $cache->get('shouldReplaceIcons')) { |
|
| 303 | + return (bool) $value; |
|
| 304 | 304 | } |
| 305 | 305 | $value = false; |
| 306 | - if(extension_loaded('imagick')) { |
|
| 306 | + if (extension_loaded('imagick')) { |
|
| 307 | 307 | $checkImagick = new \Imagick(); |
| 308 | 308 | if (count($checkImagick->queryFormats('SVG')) >= 1) { |
| 309 | 309 | $value = true; |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | private function increaseCacheBuster() { |
| 321 | 321 | $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
| 322 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 322 | + $this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1); |
|
| 323 | 323 | $this->cacheFactory->createDistributed('theming')->clear('getScssVariables'); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -45,304 +45,304 @@ |
||
| 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 | - /** @var null|string */ |
|
| 67 | - protected $injectedVariables = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param ILogger $logger |
|
| 71 | - * @param Factory $appDataFactory |
|
| 72 | - * @param IURLGenerator $urlGenerator |
|
| 73 | - * @param IConfig $config |
|
| 74 | - * @param \OC_Defaults $defaults |
|
| 75 | - * @param string $serverRoot |
|
| 76 | - * @param ICache $depsCache |
|
| 77 | - */ |
|
| 78 | - public function __construct(ILogger $logger, |
|
| 79 | - Factory $appDataFactory, |
|
| 80 | - IURLGenerator $urlGenerator, |
|
| 81 | - IConfig $config, |
|
| 82 | - \OC_Defaults $defaults, |
|
| 83 | - $serverRoot, |
|
| 84 | - ICache $depsCache) { |
|
| 85 | - $this->logger = $logger; |
|
| 86 | - $this->appData = $appDataFactory->get('css'); |
|
| 87 | - $this->urlGenerator = $urlGenerator; |
|
| 88 | - $this->config = $config; |
|
| 89 | - $this->defaults = $defaults; |
|
| 90 | - $this->serverRoot = $serverRoot; |
|
| 91 | - $this->depsCache = $depsCache; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Process the caching process if needed |
|
| 96 | - * @param string $root Root path to the nextcloud installation |
|
| 97 | - * @param string $file |
|
| 98 | - * @param string $app The app name |
|
| 99 | - * @return boolean |
|
| 100 | - */ |
|
| 101 | - public function process($root, $file, $app) { |
|
| 102 | - $path = explode('/', $root . '/' . $file); |
|
| 103 | - |
|
| 104 | - $fileNameSCSS = array_pop($path); |
|
| 105 | - $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
|
| 106 | - |
|
| 107 | - $path = implode('/', $path); |
|
| 108 | - $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 109 | - |
|
| 110 | - try { |
|
| 111 | - $folder = $this->appData->getFolder($app); |
|
| 112 | - } catch(NotFoundException $e) { |
|
| 113 | - // creating css appdata folder |
|
| 114 | - $folder = $this->appData->newFolder($app); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 121 | - return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param $appName |
|
| 126 | - * @param $fileName |
|
| 127 | - * @return ISimpleFile |
|
| 128 | - */ |
|
| 129 | - public function getCachedCSS($appName, $fileName) { |
|
| 130 | - $folder = $this->appData->getFolder($appName); |
|
| 131 | - return $folder->getFile($this->prependBaseurlPrefix($fileName)); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Check if the file is cached or not |
|
| 136 | - * @param string $fileNameCSS |
|
| 137 | - * @param ISimpleFolder $folder |
|
| 138 | - * @return boolean |
|
| 139 | - */ |
|
| 140 | - private function isCached($fileNameCSS, ISimpleFolder $folder) { |
|
| 141 | - try { |
|
| 142 | - $cachedFile = $folder->getFile($fileNameCSS); |
|
| 143 | - if ($cachedFile->getSize() > 0) { |
|
| 144 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 145 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 146 | - if ($deps === null) { |
|
| 147 | - $depFile = $folder->getFile($depFileName); |
|
| 148 | - $deps = $depFile->getContent(); |
|
| 149 | - //Set to memcache for next run |
|
| 150 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 151 | - } |
|
| 152 | - $deps = json_decode($deps, true); |
|
| 153 | - |
|
| 154 | - foreach ($deps as $file=>$mtime) { |
|
| 155 | - if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 161 | - return false; |
|
| 162 | - } catch(NotFoundException $e) { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Check if the variables file has changed |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - private function variablesChanged() { |
|
| 172 | - $injectedVariables = $this->getInjectedVariables(); |
|
| 173 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 174 | - $this->resetCache(); |
|
| 175 | - $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Cache the file with AppData |
|
| 183 | - * @param string $path |
|
| 184 | - * @param string $fileNameCSS |
|
| 185 | - * @param string $fileNameSCSS |
|
| 186 | - * @param ISimpleFolder $folder |
|
| 187 | - * @param string $webDir |
|
| 188 | - * @return boolean |
|
| 189 | - */ |
|
| 190 | - private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) { |
|
| 191 | - $scss = new Compiler(); |
|
| 192 | - $scss->setImportPaths([ |
|
| 193 | - $path, |
|
| 194 | - $this->serverRoot . '/core/css/', |
|
| 195 | - ]); |
|
| 196 | - // Continue after throw |
|
| 197 | - $scss->setIgnoreErrors(true); |
|
| 198 | - if($this->config->getSystemValue('debug')) { |
|
| 199 | - // Debug mode |
|
| 200 | - $scss->setFormatter(Expanded::class); |
|
| 201 | - $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 202 | - } else { |
|
| 203 | - // Compression |
|
| 204 | - $scss->setFormatter(Crunched::class); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - try { |
|
| 208 | - $cachedfile = $folder->getFile($fileNameCSS); |
|
| 209 | - } catch(NotFoundException $e) { |
|
| 210 | - $cachedfile = $folder->newFile($fileNameCSS); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 214 | - try { |
|
| 215 | - $depFile = $folder->getFile($depFileName); |
|
| 216 | - } catch (NotFoundException $e) { |
|
| 217 | - $depFile = $folder->newFile($depFileName); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // Compile |
|
| 221 | - try { |
|
| 222 | - $compiledScss = $scss->compile( |
|
| 223 | - '@import "variables.scss";' . |
|
| 224 | - $this->getInjectedVariables() . |
|
| 225 | - '@import "'.$fileNameSCSS.'";'); |
|
| 226 | - } catch(ParserException $e) { |
|
| 227 | - $this->logger->error($e, ['app' => 'core']); |
|
| 228 | - return false; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Gzip file |
|
| 232 | - try { |
|
| 233 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 234 | - } catch (NotFoundException $e) { |
|
| 235 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - try { |
|
| 239 | - $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 240 | - $cachedfile->putContent($data); |
|
| 241 | - $deps = json_encode($scss->getParsedFiles()); |
|
| 242 | - $depFile->putContent($deps); |
|
| 243 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 244 | - $gzipFile->putContent(gzencode($data, 9)); |
|
| 245 | - $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 246 | - return true; |
|
| 247 | - } catch(NotPermittedException $e) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Reset scss cache by deleting all generated css files |
|
| 254 | - * We need to regenerate all files when variables change |
|
| 255 | - */ |
|
| 256 | - private function resetCache() { |
|
| 257 | - $this->injectedVariables = null; |
|
| 258 | - $appDirectory = $this->appData->getDirectoryListing(); |
|
| 259 | - if(empty($appDirectory)){ |
|
| 260 | - return; |
|
| 261 | - } |
|
| 262 | - foreach ($appDirectory as $folder) { |
|
| 263 | - foreach ($folder->getDirectoryListing() as $file) { |
|
| 264 | - if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") { |
|
| 265 | - $file->delete(); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @return string SCSS code for variables from OC_Defaults |
|
| 273 | - */ |
|
| 274 | - private function getInjectedVariables() { |
|
| 275 | - if ($this->injectedVariables !== null) |
|
| 276 | - return $this->injectedVariables; |
|
| 277 | - $variables = ''; |
|
| 278 | - foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 279 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // check for valid variables / otherwise fall back to defaults |
|
| 283 | - try { |
|
| 284 | - $scss = new Compiler(); |
|
| 285 | - $scss->compile($variables); |
|
| 286 | - $this->injectedVariables = $variables; |
|
| 287 | - } catch (ParserException $e) { |
|
| 288 | - $this->logger->error($e, ['app' => 'core']); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $variables; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Add the correct uri prefix to make uri valid again |
|
| 296 | - * @param string $css |
|
| 297 | - * @param string $webDir |
|
| 298 | - * @return string |
|
| 299 | - */ |
|
| 300 | - private function rebaseUrls($css, $webDir) { |
|
| 301 | - $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
| 302 | - $subst = 'url(\''.$webDir.'/$1\')'; |
|
| 303 | - return preg_replace($re, $subst, $css); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Return the cached css file uri |
|
| 308 | - * @param string $appName the app name |
|
| 309 | - * @param string $fileName |
|
| 310 | - * @return string |
|
| 311 | - */ |
|
| 312 | - public function getCachedSCSS($appName, $fileName) { |
|
| 313 | - $tmpfileLoc = explode('/', $fileName); |
|
| 314 | - $fileName = array_pop($tmpfileLoc); |
|
| 315 | - $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); |
|
| 316 | - |
|
| 317 | - return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Prepend hashed base url to the css file |
|
| 322 | - * @param $cssFile |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - private function prependBaseurlPrefix($cssFile) { |
|
| 326 | - $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 327 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get WebDir root |
|
| 332 | - * @param string $path the css file path |
|
| 333 | - * @param string $appName the app name |
|
| 334 | - * @param string $serverRoot the server root path |
|
| 335 | - * @param string $webRoot the nextcloud installation root path |
|
| 336 | - * @return string the webDir |
|
| 337 | - */ |
|
| 338 | - private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
|
| 339 | - // Detect if path is within server root AND if path is within an app path |
|
| 340 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 341 | - // Get the file path within the app directory |
|
| 342 | - $appDirectoryPath = explode($appName, $path)[1]; |
|
| 343 | - // Remove the webroot |
|
| 344 | - return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 345 | - } |
|
| 346 | - return $webRoot.substr($path, strlen($serverRoot)); |
|
| 347 | - } |
|
| 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 | + /** @var null|string */ |
|
| 67 | + protected $injectedVariables = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param ILogger $logger |
|
| 71 | + * @param Factory $appDataFactory |
|
| 72 | + * @param IURLGenerator $urlGenerator |
|
| 73 | + * @param IConfig $config |
|
| 74 | + * @param \OC_Defaults $defaults |
|
| 75 | + * @param string $serverRoot |
|
| 76 | + * @param ICache $depsCache |
|
| 77 | + */ |
|
| 78 | + public function __construct(ILogger $logger, |
|
| 79 | + Factory $appDataFactory, |
|
| 80 | + IURLGenerator $urlGenerator, |
|
| 81 | + IConfig $config, |
|
| 82 | + \OC_Defaults $defaults, |
|
| 83 | + $serverRoot, |
|
| 84 | + ICache $depsCache) { |
|
| 85 | + $this->logger = $logger; |
|
| 86 | + $this->appData = $appDataFactory->get('css'); |
|
| 87 | + $this->urlGenerator = $urlGenerator; |
|
| 88 | + $this->config = $config; |
|
| 89 | + $this->defaults = $defaults; |
|
| 90 | + $this->serverRoot = $serverRoot; |
|
| 91 | + $this->depsCache = $depsCache; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Process the caching process if needed |
|
| 96 | + * @param string $root Root path to the nextcloud installation |
|
| 97 | + * @param string $file |
|
| 98 | + * @param string $app The app name |
|
| 99 | + * @return boolean |
|
| 100 | + */ |
|
| 101 | + public function process($root, $file, $app) { |
|
| 102 | + $path = explode('/', $root . '/' . $file); |
|
| 103 | + |
|
| 104 | + $fileNameSCSS = array_pop($path); |
|
| 105 | + $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
|
| 106 | + |
|
| 107 | + $path = implode('/', $path); |
|
| 108 | + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); |
|
| 109 | + |
|
| 110 | + try { |
|
| 111 | + $folder = $this->appData->getFolder($app); |
|
| 112 | + } catch(NotFoundException $e) { |
|
| 113 | + // creating css appdata folder |
|
| 114 | + $folder = $this->appData->newFolder($app); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | + return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param $appName |
|
| 126 | + * @param $fileName |
|
| 127 | + * @return ISimpleFile |
|
| 128 | + */ |
|
| 129 | + public function getCachedCSS($appName, $fileName) { |
|
| 130 | + $folder = $this->appData->getFolder($appName); |
|
| 131 | + return $folder->getFile($this->prependBaseurlPrefix($fileName)); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Check if the file is cached or not |
|
| 136 | + * @param string $fileNameCSS |
|
| 137 | + * @param ISimpleFolder $folder |
|
| 138 | + * @return boolean |
|
| 139 | + */ |
|
| 140 | + private function isCached($fileNameCSS, ISimpleFolder $folder) { |
|
| 141 | + try { |
|
| 142 | + $cachedFile = $folder->getFile($fileNameCSS); |
|
| 143 | + if ($cachedFile->getSize() > 0) { |
|
| 144 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 145 | + $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 146 | + if ($deps === null) { |
|
| 147 | + $depFile = $folder->getFile($depFileName); |
|
| 148 | + $deps = $depFile->getContent(); |
|
| 149 | + //Set to memcache for next run |
|
| 150 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 151 | + } |
|
| 152 | + $deps = json_decode($deps, true); |
|
| 153 | + |
|
| 154 | + foreach ($deps as $file=>$mtime) { |
|
| 155 | + if (!file_exists($file) || filemtime($file) > $mtime) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | + return false; |
|
| 162 | + } catch(NotFoundException $e) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Check if the variables file has changed |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + private function variablesChanged() { |
|
| 172 | + $injectedVariables = $this->getInjectedVariables(); |
|
| 173 | + if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 174 | + $this->resetCache(); |
|
| 175 | + $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Cache the file with AppData |
|
| 183 | + * @param string $path |
|
| 184 | + * @param string $fileNameCSS |
|
| 185 | + * @param string $fileNameSCSS |
|
| 186 | + * @param ISimpleFolder $folder |
|
| 187 | + * @param string $webDir |
|
| 188 | + * @return boolean |
|
| 189 | + */ |
|
| 190 | + private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) { |
|
| 191 | + $scss = new Compiler(); |
|
| 192 | + $scss->setImportPaths([ |
|
| 193 | + $path, |
|
| 194 | + $this->serverRoot . '/core/css/', |
|
| 195 | + ]); |
|
| 196 | + // Continue after throw |
|
| 197 | + $scss->setIgnoreErrors(true); |
|
| 198 | + if($this->config->getSystemValue('debug')) { |
|
| 199 | + // Debug mode |
|
| 200 | + $scss->setFormatter(Expanded::class); |
|
| 201 | + $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
|
| 202 | + } else { |
|
| 203 | + // Compression |
|
| 204 | + $scss->setFormatter(Crunched::class); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + try { |
|
| 208 | + $cachedfile = $folder->getFile($fileNameCSS); |
|
| 209 | + } catch(NotFoundException $e) { |
|
| 210 | + $cachedfile = $folder->newFile($fileNameCSS); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $depFileName = $fileNameCSS . '.deps'; |
|
| 214 | + try { |
|
| 215 | + $depFile = $folder->getFile($depFileName); |
|
| 216 | + } catch (NotFoundException $e) { |
|
| 217 | + $depFile = $folder->newFile($depFileName); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // Compile |
|
| 221 | + try { |
|
| 222 | + $compiledScss = $scss->compile( |
|
| 223 | + '@import "variables.scss";' . |
|
| 224 | + $this->getInjectedVariables() . |
|
| 225 | + '@import "'.$fileNameSCSS.'";'); |
|
| 226 | + } catch(ParserException $e) { |
|
| 227 | + $this->logger->error($e, ['app' => 'core']); |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Gzip file |
|
| 232 | + try { |
|
| 233 | + $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 234 | + } catch (NotFoundException $e) { |
|
| 235 | + $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + try { |
|
| 239 | + $data = $this->rebaseUrls($compiledScss, $webDir); |
|
| 240 | + $cachedfile->putContent($data); |
|
| 241 | + $deps = json_encode($scss->getParsedFiles()); |
|
| 242 | + $depFile->putContent($deps); |
|
| 243 | + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 244 | + $gzipFile->putContent(gzencode($data, 9)); |
|
| 245 | + $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
|
| 246 | + return true; |
|
| 247 | + } catch(NotPermittedException $e) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Reset scss cache by deleting all generated css files |
|
| 254 | + * We need to regenerate all files when variables change |
|
| 255 | + */ |
|
| 256 | + private function resetCache() { |
|
| 257 | + $this->injectedVariables = null; |
|
| 258 | + $appDirectory = $this->appData->getDirectoryListing(); |
|
| 259 | + if(empty($appDirectory)){ |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | + foreach ($appDirectory as $folder) { |
|
| 263 | + foreach ($folder->getDirectoryListing() as $file) { |
|
| 264 | + if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") { |
|
| 265 | + $file->delete(); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @return string SCSS code for variables from OC_Defaults |
|
| 273 | + */ |
|
| 274 | + private function getInjectedVariables() { |
|
| 275 | + if ($this->injectedVariables !== null) |
|
| 276 | + return $this->injectedVariables; |
|
| 277 | + $variables = ''; |
|
| 278 | + foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
| 279 | + $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // check for valid variables / otherwise fall back to defaults |
|
| 283 | + try { |
|
| 284 | + $scss = new Compiler(); |
|
| 285 | + $scss->compile($variables); |
|
| 286 | + $this->injectedVariables = $variables; |
|
| 287 | + } catch (ParserException $e) { |
|
| 288 | + $this->logger->error($e, ['app' => 'core']); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $variables; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Add the correct uri prefix to make uri valid again |
|
| 296 | + * @param string $css |
|
| 297 | + * @param string $webDir |
|
| 298 | + * @return string |
|
| 299 | + */ |
|
| 300 | + private function rebaseUrls($css, $webDir) { |
|
| 301 | + $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
| 302 | + $subst = 'url(\''.$webDir.'/$1\')'; |
|
| 303 | + return preg_replace($re, $subst, $css); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Return the cached css file uri |
|
| 308 | + * @param string $appName the app name |
|
| 309 | + * @param string $fileName |
|
| 310 | + * @return string |
|
| 311 | + */ |
|
| 312 | + public function getCachedSCSS($appName, $fileName) { |
|
| 313 | + $tmpfileLoc = explode('/', $fileName); |
|
| 314 | + $fileName = array_pop($tmpfileLoc); |
|
| 315 | + $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); |
|
| 316 | + |
|
| 317 | + return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Prepend hashed base url to the css file |
|
| 322 | + * @param $cssFile |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + private function prependBaseurlPrefix($cssFile) { |
|
| 326 | + $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
| 327 | + return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get WebDir root |
|
| 332 | + * @param string $path the css file path |
|
| 333 | + * @param string $appName the app name |
|
| 334 | + * @param string $serverRoot the server root path |
|
| 335 | + * @param string $webRoot the nextcloud installation root path |
|
| 336 | + * @return string the webDir |
|
| 337 | + */ |
|
| 338 | + private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
|
| 339 | + // Detect if path is within server root AND if path is within an app path |
|
| 340 | + if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 341 | + // Get the file path within the app directory |
|
| 342 | + $appDirectoryPath = explode($appName, $path)[1]; |
|
| 343 | + // Remove the webroot |
|
| 344 | + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); |
|
| 345 | + } |
|
| 346 | + return $webRoot.substr($path, strlen($serverRoot)); |
|
| 347 | + } |
|
| 348 | 348 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @return boolean |
| 100 | 100 | */ |
| 101 | 101 | public function process($root, $file, $app) { |
| 102 | - $path = explode('/', $root . '/' . $file); |
|
| 102 | + $path = explode('/', $root.'/'.$file); |
|
| 103 | 103 | |
| 104 | 104 | $fileNameSCSS = array_pop($path); |
| 105 | 105 | $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | try { |
| 111 | 111 | $folder = $this->appData->getFolder($app); |
| 112 | - } catch(NotFoundException $e) { |
|
| 112 | + } catch (NotFoundException $e) { |
|
| 113 | 113 | // creating css appdata folder |
| 114 | 114 | $folder = $this->appData->newFolder($app); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 118 | + if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { |
|
| 119 | 119 | return true; |
| 120 | 120 | } |
| 121 | 121 | return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | try { |
| 142 | 142 | $cachedFile = $folder->getFile($fileNameCSS); |
| 143 | 143 | if ($cachedFile->getSize() > 0) { |
| 144 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 145 | - $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
|
| 144 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 145 | + $deps = $this->depsCache->get($folder->getName().'-'.$depFileName); |
|
| 146 | 146 | if ($deps === null) { |
| 147 | 147 | $depFile = $folder->getFile($depFileName); |
| 148 | 148 | $deps = $depFile->getContent(); |
| 149 | 149 | //Set to memcache for next run |
| 150 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 150 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 151 | 151 | } |
| 152 | 152 | $deps = json_decode($deps, true); |
| 153 | 153 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | return true; |
| 160 | 160 | } |
| 161 | 161 | return false; |
| 162 | - } catch(NotFoundException $e) { |
|
| 162 | + } catch (NotFoundException $e) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | private function variablesChanged() { |
| 172 | 172 | $injectedVariables = $this->getInjectedVariables(); |
| 173 | - if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 173 | + if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { |
|
| 174 | 174 | $this->resetCache(); |
| 175 | 175 | $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
| 176 | 176 | return true; |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | $scss = new Compiler(); |
| 192 | 192 | $scss->setImportPaths([ |
| 193 | 193 | $path, |
| 194 | - $this->serverRoot . '/core/css/', |
|
| 194 | + $this->serverRoot.'/core/css/', |
|
| 195 | 195 | ]); |
| 196 | 196 | // Continue after throw |
| 197 | 197 | $scss->setIgnoreErrors(true); |
| 198 | - if($this->config->getSystemValue('debug')) { |
|
| 198 | + if ($this->config->getSystemValue('debug')) { |
|
| 199 | 199 | // Debug mode |
| 200 | 200 | $scss->setFormatter(Expanded::class); |
| 201 | 201 | $scss->setLineNumberStyle(Compiler::LINE_COMMENTS); |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | try { |
| 208 | 208 | $cachedfile = $folder->getFile($fileNameCSS); |
| 209 | - } catch(NotFoundException $e) { |
|
| 209 | + } catch (NotFoundException $e) { |
|
| 210 | 210 | $cachedfile = $folder->newFile($fileNameCSS); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $depFileName = $fileNameCSS . '.deps'; |
|
| 213 | + $depFileName = $fileNameCSS.'.deps'; |
|
| 214 | 214 | try { |
| 215 | 215 | $depFile = $folder->getFile($depFileName); |
| 216 | 216 | } catch (NotFoundException $e) { |
@@ -220,19 +220,19 @@ discard block |
||
| 220 | 220 | // Compile |
| 221 | 221 | try { |
| 222 | 222 | $compiledScss = $scss->compile( |
| 223 | - '@import "variables.scss";' . |
|
| 224 | - $this->getInjectedVariables() . |
|
| 223 | + '@import "variables.scss";'. |
|
| 224 | + $this->getInjectedVariables(). |
|
| 225 | 225 | '@import "'.$fileNameSCSS.'";'); |
| 226 | - } catch(ParserException $e) { |
|
| 226 | + } catch (ParserException $e) { |
|
| 227 | 227 | $this->logger->error($e, ['app' => 'core']); |
| 228 | 228 | return false; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Gzip file |
| 232 | 232 | try { |
| 233 | - $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 233 | + $gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 234 | 234 | } catch (NotFoundException $e) { |
| 235 | - $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz |
|
| 235 | + $gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | try { |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | $cachedfile->putContent($data); |
| 241 | 241 | $deps = json_encode($scss->getParsedFiles()); |
| 242 | 242 | $depFile->putContent($deps); |
| 243 | - $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
|
| 243 | + $this->depsCache->set($folder->getName().'-'.$depFileName, $deps); |
|
| 244 | 244 | $gzipFile->putContent(gzencode($data, 9)); |
| 245 | 245 | $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']); |
| 246 | 246 | return true; |
| 247 | - } catch(NotPermittedException $e) { |
|
| 247 | + } catch (NotPermittedException $e) { |
|
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | private function resetCache() { |
| 257 | 257 | $this->injectedVariables = null; |
| 258 | 258 | $appDirectory = $this->appData->getDirectoryListing(); |
| 259 | - if(empty($appDirectory)){ |
|
| 259 | + if (empty($appDirectory)) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | foreach ($appDirectory as $folder) { |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | return $this->injectedVariables; |
| 277 | 277 | $variables = ''; |
| 278 | 278 | foreach ($this->defaults->getScssVariables() as $key => $value) { |
| 279 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
| 279 | + $variables .= '$'.$key.': '.$value.';'; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // check for valid variables / otherwise fall back to defaults |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | private function prependBaseurlPrefix($cssFile) { |
| 326 | 326 | $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
| 327 | - return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile; |
|
| 327 | + return substr(md5($this->urlGenerator->getBaseUrl().$frontendController), 0, 8).'-'.$cssFile; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | private function getWebDir($path, $appName, $serverRoot, $webRoot) { |
| 339 | 339 | // Detect if path is within server root AND if path is within an app path |
| 340 | - if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 340 | + if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { |
|
| 341 | 341 | // Get the file path within the app directory |
| 342 | 342 | $appDirectoryPath = explode($appName, $path)[1]; |
| 343 | 343 | // Remove the webroot |
@@ -272,8 +272,9 @@ |
||
| 272 | 272 | * @return string SCSS code for variables from OC_Defaults |
| 273 | 273 | */ |
| 274 | 274 | private function getInjectedVariables() { |
| 275 | - if ($this->injectedVariables !== null) |
|
| 276 | - return $this->injectedVariables; |
|
| 275 | + if ($this->injectedVariables !== null) { |
|
| 276 | + return $this->injectedVariables; |
|
| 277 | + } |
|
| 277 | 278 | $variables = ''; |
| 278 | 279 | foreach ($this->defaults->getScssVariables() as $key => $value) { |
| 279 | 280 | $variables .= '$' . $key . ': ' . $value . ';'; |