@@ -65,335 +65,335 @@ |
||
65 | 65 | * @package OCA\Theming\Controller |
66 | 66 | */ |
67 | 67 | class ThemingController extends Controller { |
68 | - private ThemingDefaults $themingDefaults; |
|
69 | - private IL10N $l10n; |
|
70 | - private IConfig $config; |
|
71 | - private ITempManager $tempManager; |
|
72 | - private IAppData $appData; |
|
73 | - private IURLGenerator $urlGenerator; |
|
74 | - private IAppManager $appManager; |
|
75 | - private ImageManager $imageManager; |
|
76 | - private ThemesService $themesService; |
|
68 | + private ThemingDefaults $themingDefaults; |
|
69 | + private IL10N $l10n; |
|
70 | + private IConfig $config; |
|
71 | + private ITempManager $tempManager; |
|
72 | + private IAppData $appData; |
|
73 | + private IURLGenerator $urlGenerator; |
|
74 | + private IAppManager $appManager; |
|
75 | + private ImageManager $imageManager; |
|
76 | + private ThemesService $themesService; |
|
77 | 77 | |
78 | - public function __construct( |
|
79 | - $appName, |
|
80 | - IRequest $request, |
|
81 | - IConfig $config, |
|
82 | - ThemingDefaults $themingDefaults, |
|
83 | - IL10N $l, |
|
84 | - ITempManager $tempManager, |
|
85 | - IAppData $appData, |
|
86 | - IURLGenerator $urlGenerator, |
|
87 | - IAppManager $appManager, |
|
88 | - ImageManager $imageManager, |
|
89 | - ThemesService $themesService |
|
90 | - ) { |
|
91 | - parent::__construct($appName, $request); |
|
78 | + public function __construct( |
|
79 | + $appName, |
|
80 | + IRequest $request, |
|
81 | + IConfig $config, |
|
82 | + ThemingDefaults $themingDefaults, |
|
83 | + IL10N $l, |
|
84 | + ITempManager $tempManager, |
|
85 | + IAppData $appData, |
|
86 | + IURLGenerator $urlGenerator, |
|
87 | + IAppManager $appManager, |
|
88 | + ImageManager $imageManager, |
|
89 | + ThemesService $themesService |
|
90 | + ) { |
|
91 | + parent::__construct($appName, $request); |
|
92 | 92 | |
93 | - $this->themingDefaults = $themingDefaults; |
|
94 | - $this->l10n = $l; |
|
95 | - $this->config = $config; |
|
96 | - $this->tempManager = $tempManager; |
|
97 | - $this->appData = $appData; |
|
98 | - $this->urlGenerator = $urlGenerator; |
|
99 | - $this->appManager = $appManager; |
|
100 | - $this->imageManager = $imageManager; |
|
101 | - $this->themesService = $themesService; |
|
102 | - } |
|
93 | + $this->themingDefaults = $themingDefaults; |
|
94 | + $this->l10n = $l; |
|
95 | + $this->config = $config; |
|
96 | + $this->tempManager = $tempManager; |
|
97 | + $this->appData = $appData; |
|
98 | + $this->urlGenerator = $urlGenerator; |
|
99 | + $this->appManager = $appManager; |
|
100 | + $this->imageManager = $imageManager; |
|
101 | + $this->themesService = $themesService; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
106 | - * @param string $setting |
|
107 | - * @param string $value |
|
108 | - * @return DataResponse |
|
109 | - * @throws NotPermittedException |
|
110 | - */ |
|
111 | - public function updateStylesheet($setting, $value) { |
|
112 | - $value = trim($value); |
|
113 | - $error = null; |
|
114 | - switch ($setting) { |
|
115 | - case 'name': |
|
116 | - if (strlen($value) > 250) { |
|
117 | - $error = $this->l10n->t('The given name is too long'); |
|
118 | - } |
|
119 | - break; |
|
120 | - case 'url': |
|
121 | - if (strlen($value) > 500) { |
|
122 | - $error = $this->l10n->t('The given web address is too long'); |
|
123 | - } |
|
124 | - if (!$this->isValidUrl($value)) { |
|
125 | - $error = $this->l10n->t('The given web address is not a valid URL'); |
|
126 | - } |
|
127 | - break; |
|
128 | - case 'imprintUrl': |
|
129 | - if (strlen($value) > 500) { |
|
130 | - $error = $this->l10n->t('The given legal notice address is too long'); |
|
131 | - } |
|
132 | - if (!$this->isValidUrl($value)) { |
|
133 | - $error = $this->l10n->t('The given legal notice address is not a valid URL'); |
|
134 | - } |
|
135 | - break; |
|
136 | - case 'privacyUrl': |
|
137 | - if (strlen($value) > 500) { |
|
138 | - $error = $this->l10n->t('The given privacy policy address is too long'); |
|
139 | - } |
|
140 | - if (!$this->isValidUrl($value)) { |
|
141 | - $error = $this->l10n->t('The given privacy policy address is not a valid URL'); |
|
142 | - } |
|
143 | - break; |
|
144 | - case 'slogan': |
|
145 | - if (strlen($value) > 500) { |
|
146 | - $error = $this->l10n->t('The given slogan is too long'); |
|
147 | - } |
|
148 | - break; |
|
149 | - case 'color': |
|
150 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
151 | - $error = $this->l10n->t('The given color is invalid'); |
|
152 | - } |
|
153 | - break; |
|
154 | - } |
|
155 | - if ($error !== null) { |
|
156 | - return new DataResponse([ |
|
157 | - 'data' => [ |
|
158 | - 'message' => $error, |
|
159 | - ], |
|
160 | - 'status' => 'error' |
|
161 | - ], Http::STATUS_BAD_REQUEST); |
|
162 | - } |
|
104 | + /** |
|
105 | + * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
106 | + * @param string $setting |
|
107 | + * @param string $value |
|
108 | + * @return DataResponse |
|
109 | + * @throws NotPermittedException |
|
110 | + */ |
|
111 | + public function updateStylesheet($setting, $value) { |
|
112 | + $value = trim($value); |
|
113 | + $error = null; |
|
114 | + switch ($setting) { |
|
115 | + case 'name': |
|
116 | + if (strlen($value) > 250) { |
|
117 | + $error = $this->l10n->t('The given name is too long'); |
|
118 | + } |
|
119 | + break; |
|
120 | + case 'url': |
|
121 | + if (strlen($value) > 500) { |
|
122 | + $error = $this->l10n->t('The given web address is too long'); |
|
123 | + } |
|
124 | + if (!$this->isValidUrl($value)) { |
|
125 | + $error = $this->l10n->t('The given web address is not a valid URL'); |
|
126 | + } |
|
127 | + break; |
|
128 | + case 'imprintUrl': |
|
129 | + if (strlen($value) > 500) { |
|
130 | + $error = $this->l10n->t('The given legal notice address is too long'); |
|
131 | + } |
|
132 | + if (!$this->isValidUrl($value)) { |
|
133 | + $error = $this->l10n->t('The given legal notice address is not a valid URL'); |
|
134 | + } |
|
135 | + break; |
|
136 | + case 'privacyUrl': |
|
137 | + if (strlen($value) > 500) { |
|
138 | + $error = $this->l10n->t('The given privacy policy address is too long'); |
|
139 | + } |
|
140 | + if (!$this->isValidUrl($value)) { |
|
141 | + $error = $this->l10n->t('The given privacy policy address is not a valid URL'); |
|
142 | + } |
|
143 | + break; |
|
144 | + case 'slogan': |
|
145 | + if (strlen($value) > 500) { |
|
146 | + $error = $this->l10n->t('The given slogan is too long'); |
|
147 | + } |
|
148 | + break; |
|
149 | + case 'color': |
|
150 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
151 | + $error = $this->l10n->t('The given color is invalid'); |
|
152 | + } |
|
153 | + break; |
|
154 | + } |
|
155 | + if ($error !== null) { |
|
156 | + return new DataResponse([ |
|
157 | + 'data' => [ |
|
158 | + 'message' => $error, |
|
159 | + ], |
|
160 | + 'status' => 'error' |
|
161 | + ], Http::STATUS_BAD_REQUEST); |
|
162 | + } |
|
163 | 163 | |
164 | - $this->themingDefaults->set($setting, $value); |
|
164 | + $this->themingDefaults->set($setting, $value); |
|
165 | 165 | |
166 | - return new DataResponse([ |
|
167 | - 'data' => [ |
|
168 | - 'message' => $this->l10n->t('Saved'), |
|
169 | - ], |
|
170 | - 'status' => 'success' |
|
171 | - ]); |
|
172 | - } |
|
166 | + return new DataResponse([ |
|
167 | + 'data' => [ |
|
168 | + 'message' => $this->l10n->t('Saved'), |
|
169 | + ], |
|
170 | + 'status' => 'success' |
|
171 | + ]); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Check that a string is a valid http/https url |
|
176 | - */ |
|
177 | - private function isValidUrl(string $url): bool { |
|
178 | - return ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) && |
|
179 | - filter_var($url, FILTER_VALIDATE_URL) !== false); |
|
180 | - } |
|
174 | + /** |
|
175 | + * Check that a string is a valid http/https url |
|
176 | + */ |
|
177 | + private function isValidUrl(string $url): bool { |
|
178 | + return ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) && |
|
179 | + filter_var($url, FILTER_VALIDATE_URL) !== false); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
184 | - * @return DataResponse |
|
185 | - * @throws NotPermittedException |
|
186 | - */ |
|
187 | - public function uploadImage(): DataResponse { |
|
188 | - $key = $this->request->getParam('key'); |
|
189 | - $image = $this->request->getUploadedFile('image'); |
|
190 | - $error = null; |
|
191 | - $phpFileUploadErrors = [ |
|
192 | - UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
193 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
194 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
195 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
196 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
197 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
198 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
199 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
200 | - ]; |
|
201 | - if (empty($image)) { |
|
202 | - $error = $this->l10n->t('No file uploaded'); |
|
203 | - } |
|
204 | - if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
205 | - $error = $phpFileUploadErrors[$image['error']]; |
|
206 | - } |
|
182 | + /** |
|
183 | + * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
184 | + * @return DataResponse |
|
185 | + * @throws NotPermittedException |
|
186 | + */ |
|
187 | + public function uploadImage(): DataResponse { |
|
188 | + $key = $this->request->getParam('key'); |
|
189 | + $image = $this->request->getUploadedFile('image'); |
|
190 | + $error = null; |
|
191 | + $phpFileUploadErrors = [ |
|
192 | + UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
193 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
194 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
195 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
196 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
197 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
198 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
199 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
200 | + ]; |
|
201 | + if (empty($image)) { |
|
202 | + $error = $this->l10n->t('No file uploaded'); |
|
203 | + } |
|
204 | + if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
205 | + $error = $phpFileUploadErrors[$image['error']]; |
|
206 | + } |
|
207 | 207 | |
208 | - if ($error !== null) { |
|
209 | - return new DataResponse( |
|
210 | - [ |
|
211 | - 'data' => [ |
|
212 | - 'message' => $error |
|
213 | - ], |
|
214 | - 'status' => 'failure', |
|
215 | - ], |
|
216 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
217 | - ); |
|
218 | - } |
|
208 | + if ($error !== null) { |
|
209 | + return new DataResponse( |
|
210 | + [ |
|
211 | + 'data' => [ |
|
212 | + 'message' => $error |
|
213 | + ], |
|
214 | + 'status' => 'failure', |
|
215 | + ], |
|
216 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
217 | + ); |
|
218 | + } |
|
219 | 219 | |
220 | - try { |
|
221 | - $mime = $this->imageManager->updateImage($key, $image['tmp_name']); |
|
222 | - $this->themingDefaults->set($key . 'Mime', $mime); |
|
223 | - } catch (\Exception $e) { |
|
224 | - return new DataResponse( |
|
225 | - [ |
|
226 | - 'data' => [ |
|
227 | - 'message' => $e->getMessage() |
|
228 | - ], |
|
229 | - 'status' => 'failure', |
|
230 | - ], |
|
231 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
232 | - ); |
|
233 | - } |
|
220 | + try { |
|
221 | + $mime = $this->imageManager->updateImage($key, $image['tmp_name']); |
|
222 | + $this->themingDefaults->set($key . 'Mime', $mime); |
|
223 | + } catch (\Exception $e) { |
|
224 | + return new DataResponse( |
|
225 | + [ |
|
226 | + 'data' => [ |
|
227 | + 'message' => $e->getMessage() |
|
228 | + ], |
|
229 | + 'status' => 'failure', |
|
230 | + ], |
|
231 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
232 | + ); |
|
233 | + } |
|
234 | 234 | |
235 | - $name = $image['name']; |
|
235 | + $name = $image['name']; |
|
236 | 236 | |
237 | - return new DataResponse( |
|
238 | - [ |
|
239 | - 'data' => |
|
240 | - [ |
|
241 | - 'name' => $name, |
|
242 | - 'url' => $this->imageManager->getImageUrl($key), |
|
243 | - 'message' => $this->l10n->t('Saved'), |
|
244 | - ], |
|
245 | - 'status' => 'success' |
|
246 | - ] |
|
247 | - ); |
|
248 | - } |
|
237 | + return new DataResponse( |
|
238 | + [ |
|
239 | + 'data' => |
|
240 | + [ |
|
241 | + 'name' => $name, |
|
242 | + 'url' => $this->imageManager->getImageUrl($key), |
|
243 | + 'message' => $this->l10n->t('Saved'), |
|
244 | + ], |
|
245 | + 'status' => 'success' |
|
246 | + ] |
|
247 | + ); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * Revert setting to default value |
|
252 | - * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
253 | - * |
|
254 | - * @param string $setting setting which should be reverted |
|
255 | - * @return DataResponse |
|
256 | - * @throws NotPermittedException |
|
257 | - */ |
|
258 | - public function undo(string $setting): DataResponse { |
|
259 | - $value = $this->themingDefaults->undo($setting); |
|
250 | + /** |
|
251 | + * Revert setting to default value |
|
252 | + * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) |
|
253 | + * |
|
254 | + * @param string $setting setting which should be reverted |
|
255 | + * @return DataResponse |
|
256 | + * @throws NotPermittedException |
|
257 | + */ |
|
258 | + public function undo(string $setting): DataResponse { |
|
259 | + $value = $this->themingDefaults->undo($setting); |
|
260 | 260 | |
261 | - return new DataResponse( |
|
262 | - [ |
|
263 | - 'data' => |
|
264 | - [ |
|
265 | - 'value' => $value, |
|
266 | - 'message' => $this->l10n->t('Saved'), |
|
267 | - ], |
|
268 | - 'status' => 'success' |
|
269 | - ] |
|
270 | - ); |
|
271 | - } |
|
261 | + return new DataResponse( |
|
262 | + [ |
|
263 | + 'data' => |
|
264 | + [ |
|
265 | + 'value' => $value, |
|
266 | + 'message' => $this->l10n->t('Saved'), |
|
267 | + ], |
|
268 | + 'status' => 'success' |
|
269 | + ] |
|
270 | + ); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * @PublicPage |
|
275 | - * @NoCSRFRequired |
|
276 | - * @NoSameSiteCookieRequired |
|
277 | - * |
|
278 | - * @param string $key |
|
279 | - * @param bool $useSvg |
|
280 | - * @return FileDisplayResponse|NotFoundResponse |
|
281 | - * @throws NotPermittedException |
|
282 | - */ |
|
283 | - public function getImage(string $key, bool $useSvg = true) { |
|
284 | - try { |
|
285 | - $file = $this->imageManager->getImage($key, $useSvg); |
|
286 | - } catch (NotFoundException $e) { |
|
287 | - return new NotFoundResponse(); |
|
288 | - } |
|
273 | + /** |
|
274 | + * @PublicPage |
|
275 | + * @NoCSRFRequired |
|
276 | + * @NoSameSiteCookieRequired |
|
277 | + * |
|
278 | + * @param string $key |
|
279 | + * @param bool $useSvg |
|
280 | + * @return FileDisplayResponse|NotFoundResponse |
|
281 | + * @throws NotPermittedException |
|
282 | + */ |
|
283 | + public function getImage(string $key, bool $useSvg = true) { |
|
284 | + try { |
|
285 | + $file = $this->imageManager->getImage($key, $useSvg); |
|
286 | + } catch (NotFoundException $e) { |
|
287 | + return new NotFoundResponse(); |
|
288 | + } |
|
289 | 289 | |
290 | - $response = new FileDisplayResponse($file); |
|
291 | - $csp = new Http\ContentSecurityPolicy(); |
|
292 | - $csp->allowInlineStyle(); |
|
293 | - $response->setContentSecurityPolicy($csp); |
|
294 | - $response->cacheFor(3600); |
|
295 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
296 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
297 | - if (!$useSvg) { |
|
298 | - $response->addHeader('Content-Type', 'image/png'); |
|
299 | - } else { |
|
300 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
301 | - } |
|
302 | - return $response; |
|
303 | - } |
|
290 | + $response = new FileDisplayResponse($file); |
|
291 | + $csp = new Http\ContentSecurityPolicy(); |
|
292 | + $csp->allowInlineStyle(); |
|
293 | + $response->setContentSecurityPolicy($csp); |
|
294 | + $response->cacheFor(3600); |
|
295 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
296 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
297 | + if (!$useSvg) { |
|
298 | + $response->addHeader('Content-Type', 'image/png'); |
|
299 | + } else { |
|
300 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
301 | + } |
|
302 | + return $response; |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * @NoCSRFRequired |
|
307 | - * @PublicPage |
|
308 | - * @NoSameSiteCookieRequired |
|
309 | - * @NoTwoFactorRequired |
|
310 | - * |
|
311 | - * @return DataDisplayResponse|NotFoundResponse |
|
312 | - */ |
|
313 | - public function getThemeStylesheet(string $themeId, bool $plain = false, bool $withCustomCss = false) { |
|
314 | - $themes = $this->themesService->getThemes(); |
|
315 | - if (!in_array($themeId, array_keys($themes))) { |
|
316 | - return new NotFoundResponse(); |
|
317 | - } |
|
305 | + /** |
|
306 | + * @NoCSRFRequired |
|
307 | + * @PublicPage |
|
308 | + * @NoSameSiteCookieRequired |
|
309 | + * @NoTwoFactorRequired |
|
310 | + * |
|
311 | + * @return DataDisplayResponse|NotFoundResponse |
|
312 | + */ |
|
313 | + public function getThemeStylesheet(string $themeId, bool $plain = false, bool $withCustomCss = false) { |
|
314 | + $themes = $this->themesService->getThemes(); |
|
315 | + if (!in_array($themeId, array_keys($themes))) { |
|
316 | + return new NotFoundResponse(); |
|
317 | + } |
|
318 | 318 | |
319 | - $theme = $themes[$themeId]; |
|
320 | - $customCss = $theme->getCustomCss(); |
|
319 | + $theme = $themes[$themeId]; |
|
320 | + $customCss = $theme->getCustomCss(); |
|
321 | 321 | |
322 | - // Generate variables |
|
323 | - $variables = ''; |
|
324 | - foreach ($theme->getCSSVariables() as $variable => $value) { |
|
325 | - $variables .= "$variable:$value; "; |
|
326 | - }; |
|
322 | + // Generate variables |
|
323 | + $variables = ''; |
|
324 | + foreach ($theme->getCSSVariables() as $variable => $value) { |
|
325 | + $variables .= "$variable:$value; "; |
|
326 | + }; |
|
327 | 327 | |
328 | - // If plain is set, the browser decides of the css priority |
|
329 | - if ($plain) { |
|
330 | - $css = ":root { $variables } " . $customCss; |
|
331 | - } else { |
|
332 | - // If not set, we'll rely on the body class |
|
333 | - $compiler = new Compiler(); |
|
334 | - $compiledCss = $compiler->compileString("[data-theme-$themeId] { $variables $customCss }"); |
|
335 | - $css = $compiledCss->getCss();; |
|
336 | - } |
|
328 | + // If plain is set, the browser decides of the css priority |
|
329 | + if ($plain) { |
|
330 | + $css = ":root { $variables } " . $customCss; |
|
331 | + } else { |
|
332 | + // If not set, we'll rely on the body class |
|
333 | + $compiler = new Compiler(); |
|
334 | + $compiledCss = $compiler->compileString("[data-theme-$themeId] { $variables $customCss }"); |
|
335 | + $css = $compiledCss->getCss();; |
|
336 | + } |
|
337 | 337 | |
338 | - try { |
|
339 | - $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
340 | - $response->cacheFor(86400); |
|
341 | - return $response; |
|
342 | - } catch (NotFoundException $e) { |
|
343 | - return new NotFoundResponse(); |
|
344 | - } |
|
345 | - } |
|
338 | + try { |
|
339 | + $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
340 | + $response->cacheFor(86400); |
|
341 | + return $response; |
|
342 | + } catch (NotFoundException $e) { |
|
343 | + return new NotFoundResponse(); |
|
344 | + } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
348 | - * @NoCSRFRequired |
|
349 | - * @PublicPage |
|
350 | - * |
|
351 | - * @return Http\JSONResponse |
|
352 | - */ |
|
353 | - public function getManifest($app) { |
|
354 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
355 | - if ($app === 'core' || $app === 'settings') { |
|
356 | - $name = $this->themingDefaults->getName(); |
|
357 | - $shortName = $this->themingDefaults->getName(); |
|
358 | - $startUrl = $this->urlGenerator->getBaseUrl(); |
|
359 | - $description = $this->themingDefaults->getSlogan(); |
|
360 | - } else { |
|
361 | - $info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); |
|
362 | - $name = $info['name'] . ' - ' . $this->themingDefaults->getName(); |
|
363 | - $shortName = $info['name']; |
|
364 | - if (strpos($this->request->getRequestUri(), '/index.php/') !== false) { |
|
365 | - $startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/'; |
|
366 | - } else { |
|
367 | - $startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; |
|
368 | - } |
|
369 | - $description = $info['summary'] ?? ''; |
|
370 | - } |
|
371 | - $responseJS = [ |
|
372 | - 'name' => $name, |
|
373 | - 'short_name' => $shortName, |
|
374 | - 'start_url' => $startUrl, |
|
375 | - 'theme_color' => $this->themingDefaults->getColorPrimary(), |
|
376 | - 'background_color' => $this->themingDefaults->getColorPrimary(), |
|
377 | - 'description' => $description, |
|
378 | - 'icons' => |
|
379 | - [ |
|
380 | - [ |
|
381 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
382 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
383 | - 'type' => 'image/png', |
|
384 | - 'sizes' => '512x512' |
|
385 | - ], |
|
386 | - [ |
|
387 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
388 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
389 | - 'type' => 'image/svg+xml', |
|
390 | - 'sizes' => '16x16' |
|
391 | - ] |
|
392 | - ], |
|
393 | - 'display' => 'standalone' |
|
394 | - ]; |
|
395 | - $response = new Http\JSONResponse($responseJS); |
|
396 | - $response->cacheFor(3600); |
|
397 | - return $response; |
|
398 | - } |
|
347 | + /** |
|
348 | + * @NoCSRFRequired |
|
349 | + * @PublicPage |
|
350 | + * |
|
351 | + * @return Http\JSONResponse |
|
352 | + */ |
|
353 | + public function getManifest($app) { |
|
354 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
355 | + if ($app === 'core' || $app === 'settings') { |
|
356 | + $name = $this->themingDefaults->getName(); |
|
357 | + $shortName = $this->themingDefaults->getName(); |
|
358 | + $startUrl = $this->urlGenerator->getBaseUrl(); |
|
359 | + $description = $this->themingDefaults->getSlogan(); |
|
360 | + } else { |
|
361 | + $info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); |
|
362 | + $name = $info['name'] . ' - ' . $this->themingDefaults->getName(); |
|
363 | + $shortName = $info['name']; |
|
364 | + if (strpos($this->request->getRequestUri(), '/index.php/') !== false) { |
|
365 | + $startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/'; |
|
366 | + } else { |
|
367 | + $startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; |
|
368 | + } |
|
369 | + $description = $info['summary'] ?? ''; |
|
370 | + } |
|
371 | + $responseJS = [ |
|
372 | + 'name' => $name, |
|
373 | + 'short_name' => $shortName, |
|
374 | + 'start_url' => $startUrl, |
|
375 | + 'theme_color' => $this->themingDefaults->getColorPrimary(), |
|
376 | + 'background_color' => $this->themingDefaults->getColorPrimary(), |
|
377 | + 'description' => $description, |
|
378 | + 'icons' => |
|
379 | + [ |
|
380 | + [ |
|
381 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
382 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
383 | + 'type' => 'image/png', |
|
384 | + 'sizes' => '512x512' |
|
385 | + ], |
|
386 | + [ |
|
387 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
388 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
389 | + 'type' => 'image/svg+xml', |
|
390 | + 'sizes' => '16x16' |
|
391 | + ] |
|
392 | + ], |
|
393 | + 'display' => 'standalone' |
|
394 | + ]; |
|
395 | + $response = new Http\JSONResponse($responseJS); |
|
396 | + $response->cacheFor(3600); |
|
397 | + return $response; |
|
398 | + } |
|
399 | 399 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | try { |
221 | 221 | $mime = $this->imageManager->updateImage($key, $image['tmp_name']); |
222 | - $this->themingDefaults->set($key . 'Mime', $mime); |
|
222 | + $this->themingDefaults->set($key.'Mime', $mime); |
|
223 | 223 | } catch (\Exception $e) { |
224 | 224 | return new DataResponse( |
225 | 225 | [ |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | $csp->allowInlineStyle(); |
293 | 293 | $response->setContentSecurityPolicy($csp); |
294 | 294 | $response->cacheFor(3600); |
295 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
296 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . $key . '"'); |
|
295 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key.'Mime', '')); |
|
296 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.$key.'"'); |
|
297 | 297 | if (!$useSvg) { |
298 | 298 | $response->addHeader('Content-Type', 'image/png'); |
299 | 299 | } else { |
300 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
300 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key.'Mime', '')); |
|
301 | 301 | } |
302 | 302 | return $response; |
303 | 303 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | } |
318 | 318 | |
319 | 319 | $theme = $themes[$themeId]; |
320 | - $customCss = $theme->getCustomCss(); |
|
320 | + $customCss = $theme->getCustomCss(); |
|
321 | 321 | |
322 | 322 | // Generate variables |
323 | 323 | $variables = ''; |
@@ -327,12 +327,12 @@ discard block |
||
327 | 327 | |
328 | 328 | // If plain is set, the browser decides of the css priority |
329 | 329 | if ($plain) { |
330 | - $css = ":root { $variables } " . $customCss; |
|
330 | + $css = ":root { $variables } ".$customCss; |
|
331 | 331 | } else { |
332 | 332 | // If not set, we'll rely on the body class |
333 | 333 | $compiler = new Compiler(); |
334 | 334 | $compiledCss = $compiler->compileString("[data-theme-$themeId] { $variables $customCss }"); |
335 | - $css = $compiledCss->getCss();; |
|
335 | + $css = $compiledCss->getCss(); ; |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | try { |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | $description = $this->themingDefaults->getSlogan(); |
360 | 360 | } else { |
361 | 361 | $info = $this->appManager->getAppInfo($app, false, $this->l10n->getLanguageCode()); |
362 | - $name = $info['name'] . ' - ' . $this->themingDefaults->getName(); |
|
362 | + $name = $info['name'].' - '.$this->themingDefaults->getName(); |
|
363 | 363 | $shortName = $info['name']; |
364 | 364 | if (strpos($this->request->getRequestUri(), '/index.php/') !== false) { |
365 | - $startUrl = $this->urlGenerator->getBaseUrl() . '/index.php/apps/' . $app . '/'; |
|
365 | + $startUrl = $this->urlGenerator->getBaseUrl().'/index.php/apps/'.$app.'/'; |
|
366 | 366 | } else { |
367 | - $startUrl = $this->urlGenerator->getBaseUrl() . '/apps/' . $app . '/'; |
|
367 | + $startUrl = $this->urlGenerator->getBaseUrl().'/apps/'.$app.'/'; |
|
368 | 368 | } |
369 | 369 | $description = $info['summary'] ?? ''; |
370 | 370 | } |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | [ |
380 | 380 | [ |
381 | 381 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
382 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
382 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
383 | 383 | 'type' => 'image/png', |
384 | 384 | 'sizes' => '512x512' |
385 | 385 | ], |
386 | 386 | [ |
387 | 387 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
388 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
388 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
389 | 389 | 'type' => 'image/svg+xml', |
390 | 390 | 'sizes' => '16x16' |
391 | 391 | ] |