@@ -45,56 +45,56 @@ |
||
45 | 45 | |
46 | 46 | class Application extends App implements IBootstrap { |
47 | 47 | |
48 | - /** @var string */ |
|
49 | - public const APP_ID = 'accessibility'; |
|
48 | + /** @var string */ |
|
49 | + public const APP_ID = 'accessibility'; |
|
50 | 50 | |
51 | - public function __construct() { |
|
52 | - parent::__construct(self::APP_ID); |
|
53 | - } |
|
51 | + public function __construct() { |
|
52 | + parent::__construct(self::APP_ID); |
|
53 | + } |
|
54 | 54 | |
55 | - public function register(IRegistrationContext $context): void { |
|
56 | - } |
|
55 | + public function register(IRegistrationContext $context): void { |
|
56 | + } |
|
57 | 57 | |
58 | - public function boot(IBootContext $context): void { |
|
59 | - $this->injectCss( |
|
60 | - $context->getAppContainer()->query(IUserSession::class), |
|
61 | - $context->getAppContainer()->query(IConfig::class), |
|
62 | - $context->getAppContainer()->query(IURLGenerator::class) |
|
63 | - ); |
|
58 | + public function boot(IBootContext $context): void { |
|
59 | + $this->injectCss( |
|
60 | + $context->getAppContainer()->query(IUserSession::class), |
|
61 | + $context->getAppContainer()->query(IConfig::class), |
|
62 | + $context->getAppContainer()->query(IURLGenerator::class) |
|
63 | + ); |
|
64 | 64 | |
65 | - $this->registerInitialState($context->getAppContainer()); |
|
66 | - } |
|
65 | + $this->registerInitialState($context->getAppContainer()); |
|
66 | + } |
|
67 | 67 | |
68 | - private function injectCss(IUserSession $userSession, |
|
69 | - IConfig $config, |
|
70 | - IURLGenerator $urlGenerator) { |
|
71 | - // Inject the fake css on all pages if enabled and user is logged |
|
72 | - $loggedUser = $userSession->getUser(); |
|
73 | - if ($loggedUser !== null) { |
|
74 | - $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID); |
|
75 | - // we want to check if any theme or font is enabled. |
|
76 | - if (count($userValues) > 0) { |
|
77 | - $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); |
|
78 | - $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); |
|
79 | - \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); |
|
80 | - } |
|
81 | - } else { |
|
82 | - $userValues = ['dark']; |
|
68 | + private function injectCss(IUserSession $userSession, |
|
69 | + IConfig $config, |
|
70 | + IURLGenerator $urlGenerator) { |
|
71 | + // Inject the fake css on all pages if enabled and user is logged |
|
72 | + $loggedUser = $userSession->getUser(); |
|
73 | + if ($loggedUser !== null) { |
|
74 | + $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID); |
|
75 | + // we want to check if any theme or font is enabled. |
|
76 | + if (count($userValues) > 0) { |
|
77 | + $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); |
|
78 | + $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); |
|
79 | + \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); |
|
80 | + } |
|
81 | + } else { |
|
82 | + $userValues = ['dark']; |
|
83 | 83 | |
84 | - $hash = md5(implode('-', $userValues)); |
|
85 | - $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]); |
|
86 | - \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]); |
|
87 | - } |
|
88 | - } |
|
84 | + $hash = md5(implode('-', $userValues)); |
|
85 | + $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]); |
|
86 | + \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - private function registerInitialState(IAppContainer $container) { |
|
91 | - /** @var IInitialStateService $initialState */ |
|
92 | - $initialState = $container->query(IInitialStateService::class); |
|
90 | + private function registerInitialState(IAppContainer $container) { |
|
91 | + /** @var IInitialStateService $initialState */ |
|
92 | + $initialState = $container->query(IInitialStateService::class); |
|
93 | 93 | |
94 | - $initialState->provideLazyInitialState(self::APP_ID, 'data', function () use ($container) { |
|
95 | - /** @var JSDataService $data */ |
|
96 | - $data = $container->query(JSDataService::class); |
|
97 | - return $data; |
|
98 | - }); |
|
99 | - } |
|
94 | + $initialState->provideLazyInitialState(self::APP_ID, 'data', function () use ($container) { |
|
95 | + /** @var JSDataService $data */ |
|
96 | + $data = $container->query(JSDataService::class); |
|
97 | + return $data; |
|
98 | + }); |
|
99 | + } |
|
100 | 100 | } |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | // we want to check if any theme or font is enabled. |
76 | 76 | if (count($userValues) > 0) { |
77 | 77 | $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); |
78 | - $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); |
|
78 | + $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID.'.accessibility.getCss', ['md5' => $hash]); |
|
79 | 79 | \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); |
80 | 80 | } |
81 | 81 | } else { |
82 | 82 | $userValues = ['dark']; |
83 | 83 | |
84 | 84 | $hash = md5(implode('-', $userValues)); |
85 | - $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]); |
|
85 | + $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME.'.accessibility.getCss', ['md5' => $hash]); |
|
86 | 86 | \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'media' => '(prefers-color-scheme: dark)', 'href' => $linkToCSS]); |
87 | 87 | } |
88 | 88 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | /** @var IInitialStateService $initialState */ |
92 | 92 | $initialState = $container->query(IInitialStateService::class); |
93 | 93 | |
94 | - $initialState->provideLazyInitialState(self::APP_ID, 'data', function () use ($container) { |
|
94 | + $initialState->provideLazyInitialState(self::APP_ID, 'data', function() use ($container) { |
|
95 | 95 | /** @var JSDataService $data */ |
96 | 96 | $data = $container->query(JSDataService::class); |
97 | 97 | return $data; |
@@ -52,239 +52,239 @@ |
||
52 | 52 | |
53 | 53 | class AccessibilityController extends Controller { |
54 | 54 | |
55 | - /** @var string */ |
|
56 | - protected $appName; |
|
57 | - |
|
58 | - /** @var string */ |
|
59 | - protected $serverRoot; |
|
60 | - |
|
61 | - /** @var IConfig */ |
|
62 | - private $config; |
|
63 | - |
|
64 | - /** @var IUserManager */ |
|
65 | - private $userManager; |
|
66 | - |
|
67 | - /** @var ILogger */ |
|
68 | - private $logger; |
|
69 | - |
|
70 | - /** @var IURLGenerator */ |
|
71 | - private $urlGenerator; |
|
72 | - |
|
73 | - /** @var ITimeFactory */ |
|
74 | - protected $timeFactory; |
|
75 | - |
|
76 | - /** @var IUserSession */ |
|
77 | - private $userSession; |
|
78 | - |
|
79 | - /** @var IAppManager */ |
|
80 | - private $appManager; |
|
81 | - |
|
82 | - /** @var IconsCacher */ |
|
83 | - protected $iconsCacher; |
|
84 | - |
|
85 | - /** @var \OC_Defaults */ |
|
86 | - private $defaults; |
|
87 | - |
|
88 | - /** @var null|string */ |
|
89 | - private $injectedVariables; |
|
90 | - |
|
91 | - /** |
|
92 | - * Account constructor. |
|
93 | - * |
|
94 | - * @param string $appName |
|
95 | - * @param IRequest $request |
|
96 | - * @param IConfig $config |
|
97 | - * @param IUserManager $userManager |
|
98 | - * @param ILogger $logger |
|
99 | - * @param IURLGenerator $urlGenerator |
|
100 | - * @param ITimeFactory $timeFactory |
|
101 | - * @param IUserSession $userSession |
|
102 | - * @param IAppManager $appManager |
|
103 | - * @param \OC_Defaults $defaults |
|
104 | - */ |
|
105 | - public function __construct(string $appName, |
|
106 | - IRequest $request, |
|
107 | - IConfig $config, |
|
108 | - IUserManager $userManager, |
|
109 | - ILogger $logger, |
|
110 | - IURLGenerator $urlGenerator, |
|
111 | - ITimeFactory $timeFactory, |
|
112 | - IUserSession $userSession, |
|
113 | - IAppManager $appManager, |
|
114 | - IconsCacher $iconsCacher, |
|
115 | - \OC_Defaults $defaults) { |
|
116 | - parent::__construct($appName, $request); |
|
117 | - $this->appName = $appName; |
|
118 | - $this->config = $config; |
|
119 | - $this->userManager = $userManager; |
|
120 | - $this->logger = $logger; |
|
121 | - $this->urlGenerator = $urlGenerator; |
|
122 | - $this->timeFactory = $timeFactory; |
|
123 | - $this->userSession = $userSession; |
|
124 | - $this->appManager = $appManager; |
|
125 | - $this->iconsCacher = $iconsCacher; |
|
126 | - $this->defaults = $defaults; |
|
127 | - |
|
128 | - $this->serverRoot = \OC::$SERVERROOT; |
|
129 | - $this->appRoot = $this->appManager->getAppPath($this->appName); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @PublicPage |
|
134 | - * @NoCSRFRequired |
|
135 | - * @NoSameSiteCookieRequired |
|
136 | - * |
|
137 | - * @return DataDisplayResponse |
|
138 | - */ |
|
139 | - public function getCss(): DataDisplayResponse { |
|
140 | - $css = ''; |
|
141 | - $imports = ''; |
|
142 | - if ($this->userSession->isLoggedIn()) { |
|
143 | - $userValues = $this->getUserValues(); |
|
144 | - } else { |
|
145 | - $userValues = ['dark']; |
|
146 | - } |
|
147 | - |
|
148 | - foreach ($userValues as $key => $scssFile) { |
|
149 | - if ($scssFile !== false) { |
|
150 | - if ($scssFile === 'highcontrast' && in_array('dark', $userValues)) { |
|
151 | - $scssFile .= 'dark'; |
|
152 | - } |
|
153 | - $imports .= '@import "' . $scssFile . '";'; |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - if ($imports !== '') { |
|
158 | - $scss = new Compiler(); |
|
159 | - $scss->setImportPaths([ |
|
160 | - $this->appRoot . '/css/', |
|
161 | - $this->serverRoot . '/core/css/' |
|
162 | - ]); |
|
163 | - |
|
164 | - // Continue after throw |
|
165 | - $scss->setIgnoreErrors(true); |
|
166 | - $scss->setFormatter(Crunched::class); |
|
167 | - |
|
168 | - // Import theme, variables and compile css4 variables |
|
169 | - try { |
|
170 | - $css .= $scss->compile( |
|
171 | - $imports . |
|
172 | - $this->getInjectedVariables() . |
|
173 | - '@import "variables.scss";' . |
|
174 | - '@import "css-variables.scss";' |
|
175 | - ); |
|
176 | - } catch (ParserException $e) { |
|
177 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - // We don't want to override vars with url since path is different |
|
182 | - $css = $this->filterOutRule('/--[a-z-:]+url\([^;]+\)/mi', $css); |
|
183 | - |
|
184 | - // Rebase all urls |
|
185 | - $appWebRoot = substr($this->appRoot, strlen($this->serverRoot) - strlen(\OC::$WEBROOT)); |
|
186 | - $css = $this->rebaseUrls($css, $appWebRoot . '/css'); |
|
187 | - |
|
188 | - if (in_array('dark', $userValues) && $this->iconsCacher->getCachedList() && $this->iconsCacher->getCachedList()->getSize() > 0) { |
|
189 | - $iconsCss = $this->invertSvgIconsColor($this->iconsCacher->getCachedList()->getContent()); |
|
190 | - $css = $css . $iconsCss; |
|
191 | - } |
|
192 | - |
|
193 | - $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
194 | - |
|
195 | - // Set cache control |
|
196 | - $ttl = 31536000; |
|
197 | - $response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
|
198 | - $expires = new \DateTime(); |
|
199 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
200 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
201 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
202 | - $response->addHeader('Pragma', 'cache'); |
|
203 | - |
|
204 | - // store current cache hash |
|
205 | - if ($this->userSession->isLoggedIn()) { |
|
206 | - $this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, 'icons-css', md5($css)); |
|
207 | - } |
|
208 | - |
|
209 | - return $response; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Return an array with the user theme & font settings |
|
214 | - * |
|
215 | - * @return array |
|
216 | - */ |
|
217 | - private function getUserValues(): array { |
|
218 | - $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false); |
|
219 | - $userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false); |
|
220 | - $userHighContrast = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false); |
|
221 | - |
|
222 | - return [$userTheme, $userHighContrast, $userFont]; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Remove all matches from the $rule regex |
|
227 | - * |
|
228 | - * @param string $rule regex to match |
|
229 | - * @param string $css string to parse |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - private function filterOutRule(string $rule, string $css): string { |
|
233 | - return preg_replace($rule, '', $css); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Add the correct uri prefix to make uri valid again |
|
238 | - * |
|
239 | - * @param string $css |
|
240 | - * @param string $webDir |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - private function rebaseUrls(string $css, string $webDir): string { |
|
244 | - $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
245 | - $subst = 'url(\'' . $webDir . '/$1\')'; |
|
246 | - |
|
247 | - return preg_replace($re, $subst, $css); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Remove all matches from the $rule regex |
|
252 | - * |
|
253 | - * @param string $css string to parse |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - private function invertSvgIconsColor(string $css) { |
|
257 | - return str_replace( |
|
258 | - ['color=000&', 'color=fff&', 'color=***&'], |
|
259 | - ['color=***&', 'color=000&', 'color=fff&'], |
|
260 | - str_replace( |
|
261 | - ['color=000000&', 'color=ffffff&', 'color=******&'], |
|
262 | - ['color=******&', 'color=000000&', 'color=ffffff&'], |
|
263 | - $css |
|
264 | - ) |
|
265 | - ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return string SCSS code for variables from OC_Defaults |
|
270 | - */ |
|
271 | - private function getInjectedVariables(): string { |
|
272 | - if ($this->injectedVariables !== null) { |
|
273 | - return $this->injectedVariables; |
|
274 | - } |
|
275 | - $variables = ''; |
|
276 | - foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
277 | - $variables .= '$' . $key . ': ' . $value . ';'; |
|
278 | - } |
|
279 | - |
|
280 | - // check for valid variables / otherwise fall back to defaults |
|
281 | - try { |
|
282 | - $scss = new Compiler(); |
|
283 | - $scss->compile($variables); |
|
284 | - $this->injectedVariables = $variables; |
|
285 | - } catch (ParserException $e) { |
|
286 | - $this->logger->logException($e, ['app' => 'core']); |
|
287 | - } |
|
288 | - return $variables; |
|
289 | - } |
|
55 | + /** @var string */ |
|
56 | + protected $appName; |
|
57 | + |
|
58 | + /** @var string */ |
|
59 | + protected $serverRoot; |
|
60 | + |
|
61 | + /** @var IConfig */ |
|
62 | + private $config; |
|
63 | + |
|
64 | + /** @var IUserManager */ |
|
65 | + private $userManager; |
|
66 | + |
|
67 | + /** @var ILogger */ |
|
68 | + private $logger; |
|
69 | + |
|
70 | + /** @var IURLGenerator */ |
|
71 | + private $urlGenerator; |
|
72 | + |
|
73 | + /** @var ITimeFactory */ |
|
74 | + protected $timeFactory; |
|
75 | + |
|
76 | + /** @var IUserSession */ |
|
77 | + private $userSession; |
|
78 | + |
|
79 | + /** @var IAppManager */ |
|
80 | + private $appManager; |
|
81 | + |
|
82 | + /** @var IconsCacher */ |
|
83 | + protected $iconsCacher; |
|
84 | + |
|
85 | + /** @var \OC_Defaults */ |
|
86 | + private $defaults; |
|
87 | + |
|
88 | + /** @var null|string */ |
|
89 | + private $injectedVariables; |
|
90 | + |
|
91 | + /** |
|
92 | + * Account constructor. |
|
93 | + * |
|
94 | + * @param string $appName |
|
95 | + * @param IRequest $request |
|
96 | + * @param IConfig $config |
|
97 | + * @param IUserManager $userManager |
|
98 | + * @param ILogger $logger |
|
99 | + * @param IURLGenerator $urlGenerator |
|
100 | + * @param ITimeFactory $timeFactory |
|
101 | + * @param IUserSession $userSession |
|
102 | + * @param IAppManager $appManager |
|
103 | + * @param \OC_Defaults $defaults |
|
104 | + */ |
|
105 | + public function __construct(string $appName, |
|
106 | + IRequest $request, |
|
107 | + IConfig $config, |
|
108 | + IUserManager $userManager, |
|
109 | + ILogger $logger, |
|
110 | + IURLGenerator $urlGenerator, |
|
111 | + ITimeFactory $timeFactory, |
|
112 | + IUserSession $userSession, |
|
113 | + IAppManager $appManager, |
|
114 | + IconsCacher $iconsCacher, |
|
115 | + \OC_Defaults $defaults) { |
|
116 | + parent::__construct($appName, $request); |
|
117 | + $this->appName = $appName; |
|
118 | + $this->config = $config; |
|
119 | + $this->userManager = $userManager; |
|
120 | + $this->logger = $logger; |
|
121 | + $this->urlGenerator = $urlGenerator; |
|
122 | + $this->timeFactory = $timeFactory; |
|
123 | + $this->userSession = $userSession; |
|
124 | + $this->appManager = $appManager; |
|
125 | + $this->iconsCacher = $iconsCacher; |
|
126 | + $this->defaults = $defaults; |
|
127 | + |
|
128 | + $this->serverRoot = \OC::$SERVERROOT; |
|
129 | + $this->appRoot = $this->appManager->getAppPath($this->appName); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @PublicPage |
|
134 | + * @NoCSRFRequired |
|
135 | + * @NoSameSiteCookieRequired |
|
136 | + * |
|
137 | + * @return DataDisplayResponse |
|
138 | + */ |
|
139 | + public function getCss(): DataDisplayResponse { |
|
140 | + $css = ''; |
|
141 | + $imports = ''; |
|
142 | + if ($this->userSession->isLoggedIn()) { |
|
143 | + $userValues = $this->getUserValues(); |
|
144 | + } else { |
|
145 | + $userValues = ['dark']; |
|
146 | + } |
|
147 | + |
|
148 | + foreach ($userValues as $key => $scssFile) { |
|
149 | + if ($scssFile !== false) { |
|
150 | + if ($scssFile === 'highcontrast' && in_array('dark', $userValues)) { |
|
151 | + $scssFile .= 'dark'; |
|
152 | + } |
|
153 | + $imports .= '@import "' . $scssFile . '";'; |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + if ($imports !== '') { |
|
158 | + $scss = new Compiler(); |
|
159 | + $scss->setImportPaths([ |
|
160 | + $this->appRoot . '/css/', |
|
161 | + $this->serverRoot . '/core/css/' |
|
162 | + ]); |
|
163 | + |
|
164 | + // Continue after throw |
|
165 | + $scss->setIgnoreErrors(true); |
|
166 | + $scss->setFormatter(Crunched::class); |
|
167 | + |
|
168 | + // Import theme, variables and compile css4 variables |
|
169 | + try { |
|
170 | + $css .= $scss->compile( |
|
171 | + $imports . |
|
172 | + $this->getInjectedVariables() . |
|
173 | + '@import "variables.scss";' . |
|
174 | + '@import "css-variables.scss";' |
|
175 | + ); |
|
176 | + } catch (ParserException $e) { |
|
177 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + // We don't want to override vars with url since path is different |
|
182 | + $css = $this->filterOutRule('/--[a-z-:]+url\([^;]+\)/mi', $css); |
|
183 | + |
|
184 | + // Rebase all urls |
|
185 | + $appWebRoot = substr($this->appRoot, strlen($this->serverRoot) - strlen(\OC::$WEBROOT)); |
|
186 | + $css = $this->rebaseUrls($css, $appWebRoot . '/css'); |
|
187 | + |
|
188 | + if (in_array('dark', $userValues) && $this->iconsCacher->getCachedList() && $this->iconsCacher->getCachedList()->getSize() > 0) { |
|
189 | + $iconsCss = $this->invertSvgIconsColor($this->iconsCacher->getCachedList()->getContent()); |
|
190 | + $css = $css . $iconsCss; |
|
191 | + } |
|
192 | + |
|
193 | + $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
194 | + |
|
195 | + // Set cache control |
|
196 | + $ttl = 31536000; |
|
197 | + $response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
|
198 | + $expires = new \DateTime(); |
|
199 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
200 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
201 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
202 | + $response->addHeader('Pragma', 'cache'); |
|
203 | + |
|
204 | + // store current cache hash |
|
205 | + if ($this->userSession->isLoggedIn()) { |
|
206 | + $this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, 'icons-css', md5($css)); |
|
207 | + } |
|
208 | + |
|
209 | + return $response; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Return an array with the user theme & font settings |
|
214 | + * |
|
215 | + * @return array |
|
216 | + */ |
|
217 | + private function getUserValues(): array { |
|
218 | + $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false); |
|
219 | + $userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false); |
|
220 | + $userHighContrast = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false); |
|
221 | + |
|
222 | + return [$userTheme, $userHighContrast, $userFont]; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Remove all matches from the $rule regex |
|
227 | + * |
|
228 | + * @param string $rule regex to match |
|
229 | + * @param string $css string to parse |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + private function filterOutRule(string $rule, string $css): string { |
|
233 | + return preg_replace($rule, '', $css); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Add the correct uri prefix to make uri valid again |
|
238 | + * |
|
239 | + * @param string $css |
|
240 | + * @param string $webDir |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + private function rebaseUrls(string $css, string $webDir): string { |
|
244 | + $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x'; |
|
245 | + $subst = 'url(\'' . $webDir . '/$1\')'; |
|
246 | + |
|
247 | + return preg_replace($re, $subst, $css); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Remove all matches from the $rule regex |
|
252 | + * |
|
253 | + * @param string $css string to parse |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + private function invertSvgIconsColor(string $css) { |
|
257 | + return str_replace( |
|
258 | + ['color=000&', 'color=fff&', 'color=***&'], |
|
259 | + ['color=***&', 'color=000&', 'color=fff&'], |
|
260 | + str_replace( |
|
261 | + ['color=000000&', 'color=ffffff&', 'color=******&'], |
|
262 | + ['color=******&', 'color=000000&', 'color=ffffff&'], |
|
263 | + $css |
|
264 | + ) |
|
265 | + ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return string SCSS code for variables from OC_Defaults |
|
270 | + */ |
|
271 | + private function getInjectedVariables(): string { |
|
272 | + if ($this->injectedVariables !== null) { |
|
273 | + return $this->injectedVariables; |
|
274 | + } |
|
275 | + $variables = ''; |
|
276 | + foreach ($this->defaults->getScssVariables() as $key => $value) { |
|
277 | + $variables .= '$' . $key . ': ' . $value . ';'; |
|
278 | + } |
|
279 | + |
|
280 | + // check for valid variables / otherwise fall back to defaults |
|
281 | + try { |
|
282 | + $scss = new Compiler(); |
|
283 | + $scss->compile($variables); |
|
284 | + $this->injectedVariables = $variables; |
|
285 | + } catch (ParserException $e) { |
|
286 | + $this->logger->logException($e, ['app' => 'core']); |
|
287 | + } |
|
288 | + return $variables; |
|
289 | + } |
|
290 | 290 | } |