@@ -44,352 +44,352 @@ |
||
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 ImageManager */ |
|
52 | - private $imageManager; |
|
53 | - /** @var IURLGenerator */ |
|
54 | - private $urlGenerator; |
|
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 ImageManager $imageManager |
|
87 | - * @param IURLGenerator $urlGenerator |
|
88 | - * @param ICacheFactory $cacheFactory |
|
89 | - * @param Util $util |
|
90 | - * @param IAppManager $appManager |
|
91 | - */ |
|
92 | - public function __construct(IConfig $config, |
|
93 | - IL10N $l, |
|
94 | - IURLGenerator $urlGenerator, |
|
95 | - ICacheFactory $cacheFactory, |
|
96 | - Util $util, |
|
97 | - ImageManager $imageManager, |
|
98 | - IAppManager $appManager |
|
99 | - ) { |
|
100 | - parent::__construct(); |
|
101 | - $this->config = $config; |
|
102 | - $this->l = $l; |
|
103 | - $this->imageManager = $imageManager; |
|
104 | - $this->urlGenerator = $urlGenerator; |
|
105 | - $this->cacheFactory = $cacheFactory; |
|
106 | - $this->util = $util; |
|
107 | - $this->appManager = $appManager; |
|
108 | - |
|
109 | - $this->name = parent::getName(); |
|
110 | - $this->title = parent::getTitle(); |
|
111 | - $this->entity = parent::getEntity(); |
|
112 | - $this->url = parent::getBaseUrl(); |
|
113 | - $this->slogan = parent::getSlogan(); |
|
114 | - $this->color = parent::getColorPrimary(); |
|
115 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
116 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
117 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
118 | - } |
|
119 | - |
|
120 | - public function getName() { |
|
121 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
122 | - } |
|
123 | - |
|
124 | - public function getHTMLName() { |
|
125 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
126 | - } |
|
127 | - |
|
128 | - public function getTitle() { |
|
129 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
130 | - } |
|
131 | - |
|
132 | - public function getEntity() { |
|
133 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
134 | - } |
|
135 | - |
|
136 | - public function getBaseUrl() { |
|
137 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
138 | - } |
|
139 | - |
|
140 | - public function getSlogan() { |
|
141 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
142 | - } |
|
143 | - |
|
144 | - public function getImprintUrl() { |
|
145 | - return $this->config->getAppValue('theming', 'imprintUrl', ''); |
|
146 | - } |
|
147 | - |
|
148 | - public function getShortFooter() { |
|
149 | - $slogan = $this->getSlogan(); |
|
150 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
151 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
152 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
153 | - |
|
154 | - $imprintUrl = (string)$this->getImprintUrl(); |
|
155 | - if($imprintUrl !== '' |
|
156 | - && filter_var($imprintUrl, FILTER_VALIDATE_URL, [ |
|
157 | - 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
|
158 | - ]) |
|
159 | - ) { |
|
160 | - $footer .= '<br/><a href="' . $imprintUrl . '" class="legal" target="_blank"' . |
|
161 | - ' rel="noreferrer noopener">' . $this->l->t('Legal notice') . '</a>'; |
|
162 | - } |
|
163 | - |
|
164 | - return $footer; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Color that is used for the header as well as for mail headers |
|
169 | - * |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function getColorPrimary() { |
|
173 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Themed logo url |
|
178 | - * |
|
179 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getLogo($useSvg = true): string { |
|
183 | - $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
184 | - |
|
185 | - $logoExists = true; |
|
186 | - try { |
|
187 | - $this->imageManager->getImage('logo'); |
|
188 | - } catch (\Exception $e) { |
|
189 | - $logoExists = false; |
|
190 | - } |
|
191 | - |
|
192 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
193 | - |
|
194 | - if(!$logo || !$logoExists) { |
|
195 | - if($useSvg) { |
|
196 | - $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
197 | - } else { |
|
198 | - $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
199 | - } |
|
200 | - return $logo . '?v=' . $cacheBusterCounter; |
|
201 | - } |
|
202 | - |
|
203 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Themed background image url |
|
208 | - * |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function getBackground(): string { |
|
212 | - return $this->imageManager->getImageUrl('background'); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function getiTunesAppId() { |
|
219 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function getiOSClientUrl() { |
|
226 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - public function getAndroidClientUrl() { |
|
233 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return array scss variables to overwrite |
|
239 | - */ |
|
240 | - public function getScssVariables() { |
|
241 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
242 | - if ($value = $cache->get('getScssVariables')) { |
|
243 | - return $value; |
|
244 | - } |
|
245 | - |
|
246 | - $variables = [ |
|
247 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
248 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
249 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
250 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
251 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
252 | - ]; |
|
253 | - |
|
254 | - $variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'"; |
|
255 | - $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
256 | - $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
257 | - $variables['image-login-background'] = "'".$this->imageManager->getImageUrl('background')."'"; |
|
258 | - $variables['image-login-plain'] = 'false'; |
|
259 | - |
|
260 | - if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
261 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
262 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
263 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
264 | - } |
|
265 | - |
|
266 | - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
267 | - $variables['image-login-plain'] = 'true'; |
|
268 | - } |
|
269 | - $cache->set('getScssVariables', $variables); |
|
270 | - return $variables; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Check if the image should be replaced by the theming app |
|
275 | - * and return the new image location then |
|
276 | - * |
|
277 | - * @param string $app name of the app |
|
278 | - * @param string $image filename of the image |
|
279 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
280 | - */ |
|
281 | - public function replaceImagePath($app, $image) { |
|
282 | - if($app==='') { |
|
283 | - $app = 'core'; |
|
284 | - } |
|
285 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
286 | - |
|
287 | - try { |
|
288 | - $customFavicon = $this->imageManager->getImage('favicon'); |
|
289 | - } catch (NotFoundException $e) { |
|
290 | - $customFavicon = null; |
|
291 | - } |
|
292 | - |
|
293 | - if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
|
294 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
295 | - } |
|
296 | - if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
|
297 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
298 | - } |
|
299 | - if ($image === 'manifest.json') { |
|
300 | - try { |
|
301 | - $appPath = $this->appManager->getAppPath($app); |
|
302 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
303 | - return false; |
|
304 | - } |
|
305 | - } catch (AppPathNotFoundException $e) {} |
|
306 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
307 | - } |
|
308 | - return false; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Check if Imagemagick is enabled and if SVG is supported |
|
313 | - * otherwise we can't render custom icons |
|
314 | - * |
|
315 | - * @return bool |
|
316 | - */ |
|
317 | - public function shouldReplaceIcons() { |
|
318 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
319 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
320 | - return (bool)$value; |
|
321 | - } |
|
322 | - $value = false; |
|
323 | - if(extension_loaded('imagick')) { |
|
324 | - $checkImagick = new \Imagick(); |
|
325 | - if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
326 | - $value = true; |
|
327 | - } |
|
328 | - $checkImagick->clear(); |
|
329 | - } |
|
330 | - $cache->set('shouldReplaceIcons', $value); |
|
331 | - return $value; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Increases the cache buster key |
|
336 | - */ |
|
337 | - private function increaseCacheBuster() { |
|
338 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
339 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
340 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
341 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Update setting in the database |
|
347 | - * |
|
348 | - * @param string $setting |
|
349 | - * @param string $value |
|
350 | - */ |
|
351 | - public function set($setting, $value) { |
|
352 | - $this->config->setAppValue('theming', $setting, $value); |
|
353 | - $this->increaseCacheBuster(); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Revert settings to the default value |
|
358 | - * |
|
359 | - * @param string $setting setting which should be reverted |
|
360 | - * @return string default value |
|
361 | - */ |
|
362 | - public function undo($setting) { |
|
363 | - $this->config->deleteAppValue('theming', $setting); |
|
364 | - $this->increaseCacheBuster(); |
|
365 | - |
|
366 | - switch ($setting) { |
|
367 | - case 'name': |
|
368 | - $returnValue = $this->getEntity(); |
|
369 | - break; |
|
370 | - case 'url': |
|
371 | - $returnValue = $this->getBaseUrl(); |
|
372 | - break; |
|
373 | - case 'slogan': |
|
374 | - $returnValue = $this->getSlogan(); |
|
375 | - break; |
|
376 | - case 'color': |
|
377 | - $returnValue = $this->getColorPrimary(); |
|
378 | - break; |
|
379 | - default: |
|
380 | - $returnValue = ''; |
|
381 | - break; |
|
382 | - } |
|
383 | - |
|
384 | - return $returnValue; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Color of text in the header and primary buttons |
|
389 | - * |
|
390 | - * @return string |
|
391 | - */ |
|
392 | - public function getTextColorPrimary() { |
|
393 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
394 | - } |
|
47 | + /** @var IConfig */ |
|
48 | + private $config; |
|
49 | + /** @var IL10N */ |
|
50 | + private $l; |
|
51 | + /** @var ImageManager */ |
|
52 | + private $imageManager; |
|
53 | + /** @var IURLGenerator */ |
|
54 | + private $urlGenerator; |
|
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 ImageManager $imageManager |
|
87 | + * @param IURLGenerator $urlGenerator |
|
88 | + * @param ICacheFactory $cacheFactory |
|
89 | + * @param Util $util |
|
90 | + * @param IAppManager $appManager |
|
91 | + */ |
|
92 | + public function __construct(IConfig $config, |
|
93 | + IL10N $l, |
|
94 | + IURLGenerator $urlGenerator, |
|
95 | + ICacheFactory $cacheFactory, |
|
96 | + Util $util, |
|
97 | + ImageManager $imageManager, |
|
98 | + IAppManager $appManager |
|
99 | + ) { |
|
100 | + parent::__construct(); |
|
101 | + $this->config = $config; |
|
102 | + $this->l = $l; |
|
103 | + $this->imageManager = $imageManager; |
|
104 | + $this->urlGenerator = $urlGenerator; |
|
105 | + $this->cacheFactory = $cacheFactory; |
|
106 | + $this->util = $util; |
|
107 | + $this->appManager = $appManager; |
|
108 | + |
|
109 | + $this->name = parent::getName(); |
|
110 | + $this->title = parent::getTitle(); |
|
111 | + $this->entity = parent::getEntity(); |
|
112 | + $this->url = parent::getBaseUrl(); |
|
113 | + $this->slogan = parent::getSlogan(); |
|
114 | + $this->color = parent::getColorPrimary(); |
|
115 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
116 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
117 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
118 | + } |
|
119 | + |
|
120 | + public function getName() { |
|
121 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
122 | + } |
|
123 | + |
|
124 | + public function getHTMLName() { |
|
125 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
126 | + } |
|
127 | + |
|
128 | + public function getTitle() { |
|
129 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
130 | + } |
|
131 | + |
|
132 | + public function getEntity() { |
|
133 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
134 | + } |
|
135 | + |
|
136 | + public function getBaseUrl() { |
|
137 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
138 | + } |
|
139 | + |
|
140 | + public function getSlogan() { |
|
141 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
142 | + } |
|
143 | + |
|
144 | + public function getImprintUrl() { |
|
145 | + return $this->config->getAppValue('theming', 'imprintUrl', ''); |
|
146 | + } |
|
147 | + |
|
148 | + public function getShortFooter() { |
|
149 | + $slogan = $this->getSlogan(); |
|
150 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
151 | + ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
152 | + ($slogan !== '' ? ' – ' . $slogan : ''); |
|
153 | + |
|
154 | + $imprintUrl = (string)$this->getImprintUrl(); |
|
155 | + if($imprintUrl !== '' |
|
156 | + && filter_var($imprintUrl, FILTER_VALIDATE_URL, [ |
|
157 | + 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
|
158 | + ]) |
|
159 | + ) { |
|
160 | + $footer .= '<br/><a href="' . $imprintUrl . '" class="legal" target="_blank"' . |
|
161 | + ' rel="noreferrer noopener">' . $this->l->t('Legal notice') . '</a>'; |
|
162 | + } |
|
163 | + |
|
164 | + return $footer; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Color that is used for the header as well as for mail headers |
|
169 | + * |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function getColorPrimary() { |
|
173 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Themed logo url |
|
178 | + * |
|
179 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getLogo($useSvg = true): string { |
|
183 | + $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
184 | + |
|
185 | + $logoExists = true; |
|
186 | + try { |
|
187 | + $this->imageManager->getImage('logo'); |
|
188 | + } catch (\Exception $e) { |
|
189 | + $logoExists = false; |
|
190 | + } |
|
191 | + |
|
192 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
193 | + |
|
194 | + if(!$logo || !$logoExists) { |
|
195 | + if($useSvg) { |
|
196 | + $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
197 | + } else { |
|
198 | + $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
199 | + } |
|
200 | + return $logo . '?v=' . $cacheBusterCounter; |
|
201 | + } |
|
202 | + |
|
203 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Themed background image url |
|
208 | + * |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function getBackground(): string { |
|
212 | + return $this->imageManager->getImageUrl('background'); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function getiTunesAppId() { |
|
219 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function getiOSClientUrl() { |
|
226 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + public function getAndroidClientUrl() { |
|
233 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return array scss variables to overwrite |
|
239 | + */ |
|
240 | + public function getScssVariables() { |
|
241 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
242 | + if ($value = $cache->get('getScssVariables')) { |
|
243 | + return $value; |
|
244 | + } |
|
245 | + |
|
246 | + $variables = [ |
|
247 | + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
248 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
249 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
250 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
251 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
252 | + ]; |
|
253 | + |
|
254 | + $variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'"; |
|
255 | + $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
256 | + $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
257 | + $variables['image-login-background'] = "'".$this->imageManager->getImageUrl('background')."'"; |
|
258 | + $variables['image-login-plain'] = 'false'; |
|
259 | + |
|
260 | + if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
261 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
262 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
263 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
264 | + } |
|
265 | + |
|
266 | + if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
267 | + $variables['image-login-plain'] = 'true'; |
|
268 | + } |
|
269 | + $cache->set('getScssVariables', $variables); |
|
270 | + return $variables; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Check if the image should be replaced by the theming app |
|
275 | + * and return the new image location then |
|
276 | + * |
|
277 | + * @param string $app name of the app |
|
278 | + * @param string $image filename of the image |
|
279 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
280 | + */ |
|
281 | + public function replaceImagePath($app, $image) { |
|
282 | + if($app==='') { |
|
283 | + $app = 'core'; |
|
284 | + } |
|
285 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
286 | + |
|
287 | + try { |
|
288 | + $customFavicon = $this->imageManager->getImage('favicon'); |
|
289 | + } catch (NotFoundException $e) { |
|
290 | + $customFavicon = null; |
|
291 | + } |
|
292 | + |
|
293 | + if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
|
294 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
295 | + } |
|
296 | + if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
|
297 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
298 | + } |
|
299 | + if ($image === 'manifest.json') { |
|
300 | + try { |
|
301 | + $appPath = $this->appManager->getAppPath($app); |
|
302 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
303 | + return false; |
|
304 | + } |
|
305 | + } catch (AppPathNotFoundException $e) {} |
|
306 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
307 | + } |
|
308 | + return false; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Check if Imagemagick is enabled and if SVG is supported |
|
313 | + * otherwise we can't render custom icons |
|
314 | + * |
|
315 | + * @return bool |
|
316 | + */ |
|
317 | + public function shouldReplaceIcons() { |
|
318 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
319 | + if($value = $cache->get('shouldReplaceIcons')) { |
|
320 | + return (bool)$value; |
|
321 | + } |
|
322 | + $value = false; |
|
323 | + if(extension_loaded('imagick')) { |
|
324 | + $checkImagick = new \Imagick(); |
|
325 | + if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
326 | + $value = true; |
|
327 | + } |
|
328 | + $checkImagick->clear(); |
|
329 | + } |
|
330 | + $cache->set('shouldReplaceIcons', $value); |
|
331 | + return $value; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Increases the cache buster key |
|
336 | + */ |
|
337 | + private function increaseCacheBuster() { |
|
338 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
339 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
340 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
341 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Update setting in the database |
|
347 | + * |
|
348 | + * @param string $setting |
|
349 | + * @param string $value |
|
350 | + */ |
|
351 | + public function set($setting, $value) { |
|
352 | + $this->config->setAppValue('theming', $setting, $value); |
|
353 | + $this->increaseCacheBuster(); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Revert settings to the default value |
|
358 | + * |
|
359 | + * @param string $setting setting which should be reverted |
|
360 | + * @return string default value |
|
361 | + */ |
|
362 | + public function undo($setting) { |
|
363 | + $this->config->deleteAppValue('theming', $setting); |
|
364 | + $this->increaseCacheBuster(); |
|
365 | + |
|
366 | + switch ($setting) { |
|
367 | + case 'name': |
|
368 | + $returnValue = $this->getEntity(); |
|
369 | + break; |
|
370 | + case 'url': |
|
371 | + $returnValue = $this->getBaseUrl(); |
|
372 | + break; |
|
373 | + case 'slogan': |
|
374 | + $returnValue = $this->getSlogan(); |
|
375 | + break; |
|
376 | + case 'color': |
|
377 | + $returnValue = $this->getColorPrimary(); |
|
378 | + break; |
|
379 | + default: |
|
380 | + $returnValue = ''; |
|
381 | + break; |
|
382 | + } |
|
383 | + |
|
384 | + return $returnValue; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Color of text in the header and primary buttons |
|
389 | + * |
|
390 | + * @return string |
|
391 | + */ |
|
392 | + public function getTextColorPrimary() { |
|
393 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
394 | + } |
|
395 | 395 | } |
@@ -147,18 +147,18 @@ discard block |
||
147 | 147 | |
148 | 148 | public function getShortFooter() { |
149 | 149 | $slogan = $this->getSlogan(); |
150 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
151 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
152 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
150 | + $footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'. |
|
151 | + ' rel="noreferrer noopener">'.$this->getEntity().'</a>'. |
|
152 | + ($slogan !== '' ? ' – '.$slogan : ''); |
|
153 | 153 | |
154 | - $imprintUrl = (string)$this->getImprintUrl(); |
|
155 | - if($imprintUrl !== '' |
|
154 | + $imprintUrl = (string) $this->getImprintUrl(); |
|
155 | + if ($imprintUrl !== '' |
|
156 | 156 | && filter_var($imprintUrl, FILTER_VALIDATE_URL, [ |
157 | 157 | 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
158 | 158 | ]) |
159 | 159 | ) { |
160 | - $footer .= '<br/><a href="' . $imprintUrl . '" class="legal" target="_blank"' . |
|
161 | - ' rel="noreferrer noopener">' . $this->l->t('Legal notice') . '</a>'; |
|
160 | + $footer .= '<br/><a href="'.$imprintUrl.'" class="legal" target="_blank"'. |
|
161 | + ' rel="noreferrer noopener">'.$this->l->t('Legal notice').'</a>'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return $footer; |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | |
192 | 192 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
193 | 193 | |
194 | - if(!$logo || !$logoExists) { |
|
195 | - if($useSvg) { |
|
194 | + if (!$logo || !$logoExists) { |
|
195 | + if ($useSvg) { |
|
196 | 196 | $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
197 | 197 | } else { |
198 | 198 | $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
199 | 199 | } |
200 | - return $logo . '?v=' . $cacheBusterCounter; |
|
200 | + return $logo.'?v='.$cacheBusterCounter; |
|
201 | 201 | } |
202 | 202 | |
203 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo' ]) . '?v=' . $cacheBusterCounter; |
|
203 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', ['key' => 'logo']).'?v='.$cacheBusterCounter; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * @return array scss variables to overwrite |
239 | 239 | */ |
240 | 240 | public function getScssVariables() { |
241 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
241 | + $cache = $this->cacheFactory->createDistributed('theming-'.$this->urlGenerator->getBaseUrl()); |
|
242 | 242 | if ($value = $cache->get('getScssVariables')) { |
243 | 243 | return $value; |
244 | 244 | } |
245 | 245 | |
246 | 246 | $variables = [ |
247 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
248 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
249 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
250 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
251 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
247 | + 'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'", |
|
248 | + 'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime')."'", |
|
249 | + 'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime')."'", |
|
250 | + 'theming-logoheader-mime' => "'".$this->config->getAppValue('theming', 'logoheaderMime')."'", |
|
251 | + 'theming-favicon-mime' => "'".$this->config->getAppValue('theming', 'faviconMime')."'" |
|
252 | 252 | ]; |
253 | 253 | |
254 | 254 | $variables['image-logo'] = "'".$this->imageManager->getImageUrl('logo')."'"; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @return bool|string false if image should not replaced, otherwise the location of the image |
280 | 280 | */ |
281 | 281 | public function replaceImagePath($app, $image) { |
282 | - if($app==='') { |
|
282 | + if ($app === '') { |
|
283 | 283 | $app = 'core'; |
284 | 284 | } |
285 | 285 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | if ($image === 'favicon.ico' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
294 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
294 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
295 | 295 | } |
296 | 296 | if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->shouldReplaceIcons())) { |
297 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
297 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
298 | 298 | } |
299 | 299 | if ($image === 'manifest.json') { |
300 | 300 | try { |
301 | 301 | $appPath = $this->appManager->getAppPath($app); |
302 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
302 | + if (file_exists($appPath.'/img/manifest.json')) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | } catch (AppPathNotFoundException $e) {} |
306 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
306 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest').'?v='.$cacheBusterValue; |
|
307 | 307 | } |
308 | 308 | return false; |
309 | 309 | } |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | * @return bool |
316 | 316 | */ |
317 | 317 | public function shouldReplaceIcons() { |
318 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
319 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
320 | - return (bool)$value; |
|
318 | + $cache = $this->cacheFactory->createDistributed('theming-'.$this->urlGenerator->getBaseUrl()); |
|
319 | + if ($value = $cache->get('shouldReplaceIcons')) { |
|
320 | + return (bool) $value; |
|
321 | 321 | } |
322 | 322 | $value = false; |
323 | - if(extension_loaded('imagick')) { |
|
323 | + if (extension_loaded('imagick')) { |
|
324 | 324 | $checkImagick = new \Imagick(); |
325 | 325 | if (count($checkImagick->queryFormats('SVG')) >= 1) { |
326 | 326 | $value = true; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | */ |
337 | 337 | private function increaseCacheBuster() { |
338 | 338 | $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
339 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
339 | + $this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1); |
|
340 | 340 | $this->cacheFactory->createDistributed('theming-')->clear(); |
341 | 341 | $this->cacheFactory->createDistributed('imagePath')->clear(); |
342 | 342 |
@@ -62,355 +62,355 @@ discard block |
||
62 | 62 | * @package OCA\Theming\Controller |
63 | 63 | */ |
64 | 64 | class ThemingController extends Controller { |
65 | - /** @var ThemingDefaults */ |
|
66 | - private $themingDefaults; |
|
67 | - /** @var Util */ |
|
68 | - private $util; |
|
69 | - /** @var ITimeFactory */ |
|
70 | - private $timeFactory; |
|
71 | - /** @var IL10N */ |
|
72 | - private $l10n; |
|
73 | - /** @var IConfig */ |
|
74 | - private $config; |
|
75 | - /** @var ITempManager */ |
|
76 | - private $tempManager; |
|
77 | - /** @var IAppData */ |
|
78 | - private $appData; |
|
79 | - /** @var SCSSCacher */ |
|
80 | - private $scssCacher; |
|
81 | - /** @var IURLGenerator */ |
|
82 | - private $urlGenerator; |
|
83 | - /** @var IAppManager */ |
|
84 | - private $appManager; |
|
85 | - /** @var ImageManager */ |
|
86 | - private $imageManager; |
|
65 | + /** @var ThemingDefaults */ |
|
66 | + private $themingDefaults; |
|
67 | + /** @var Util */ |
|
68 | + private $util; |
|
69 | + /** @var ITimeFactory */ |
|
70 | + private $timeFactory; |
|
71 | + /** @var IL10N */ |
|
72 | + private $l10n; |
|
73 | + /** @var IConfig */ |
|
74 | + private $config; |
|
75 | + /** @var ITempManager */ |
|
76 | + private $tempManager; |
|
77 | + /** @var IAppData */ |
|
78 | + private $appData; |
|
79 | + /** @var SCSSCacher */ |
|
80 | + private $scssCacher; |
|
81 | + /** @var IURLGenerator */ |
|
82 | + private $urlGenerator; |
|
83 | + /** @var IAppManager */ |
|
84 | + private $appManager; |
|
85 | + /** @var ImageManager */ |
|
86 | + private $imageManager; |
|
87 | 87 | |
88 | - /** |
|
89 | - * ThemingController constructor. |
|
90 | - * |
|
91 | - * @param string $appName |
|
92 | - * @param IRequest $request |
|
93 | - * @param IConfig $config |
|
94 | - * @param ThemingDefaults $themingDefaults |
|
95 | - * @param Util $util |
|
96 | - * @param ITimeFactory $timeFactory |
|
97 | - * @param IL10N $l |
|
98 | - * @param ITempManager $tempManager |
|
99 | - * @param IAppData $appData |
|
100 | - * @param SCSSCacher $scssCacher |
|
101 | - * @param IURLGenerator $urlGenerator |
|
102 | - * @param IAppManager $appManager |
|
103 | - * @param ImageManager $imageManager |
|
104 | - */ |
|
105 | - public function __construct( |
|
106 | - $appName, |
|
107 | - IRequest $request, |
|
108 | - IConfig $config, |
|
109 | - ThemingDefaults $themingDefaults, |
|
110 | - Util $util, |
|
111 | - ITimeFactory $timeFactory, |
|
112 | - IL10N $l, |
|
113 | - ITempManager $tempManager, |
|
114 | - IAppData $appData, |
|
115 | - SCSSCacher $scssCacher, |
|
116 | - IURLGenerator $urlGenerator, |
|
117 | - IAppManager $appManager, |
|
118 | - ImageManager $imageManager |
|
119 | - ) { |
|
120 | - parent::__construct($appName, $request); |
|
88 | + /** |
|
89 | + * ThemingController constructor. |
|
90 | + * |
|
91 | + * @param string $appName |
|
92 | + * @param IRequest $request |
|
93 | + * @param IConfig $config |
|
94 | + * @param ThemingDefaults $themingDefaults |
|
95 | + * @param Util $util |
|
96 | + * @param ITimeFactory $timeFactory |
|
97 | + * @param IL10N $l |
|
98 | + * @param ITempManager $tempManager |
|
99 | + * @param IAppData $appData |
|
100 | + * @param SCSSCacher $scssCacher |
|
101 | + * @param IURLGenerator $urlGenerator |
|
102 | + * @param IAppManager $appManager |
|
103 | + * @param ImageManager $imageManager |
|
104 | + */ |
|
105 | + public function __construct( |
|
106 | + $appName, |
|
107 | + IRequest $request, |
|
108 | + IConfig $config, |
|
109 | + ThemingDefaults $themingDefaults, |
|
110 | + Util $util, |
|
111 | + ITimeFactory $timeFactory, |
|
112 | + IL10N $l, |
|
113 | + ITempManager $tempManager, |
|
114 | + IAppData $appData, |
|
115 | + SCSSCacher $scssCacher, |
|
116 | + IURLGenerator $urlGenerator, |
|
117 | + IAppManager $appManager, |
|
118 | + ImageManager $imageManager |
|
119 | + ) { |
|
120 | + parent::__construct($appName, $request); |
|
121 | 121 | |
122 | - $this->themingDefaults = $themingDefaults; |
|
123 | - $this->util = $util; |
|
124 | - $this->timeFactory = $timeFactory; |
|
125 | - $this->l10n = $l; |
|
126 | - $this->config = $config; |
|
127 | - $this->tempManager = $tempManager; |
|
128 | - $this->appData = $appData; |
|
129 | - $this->scssCacher = $scssCacher; |
|
130 | - $this->urlGenerator = $urlGenerator; |
|
131 | - $this->appManager = $appManager; |
|
132 | - $this->imageManager = $imageManager; |
|
133 | - } |
|
122 | + $this->themingDefaults = $themingDefaults; |
|
123 | + $this->util = $util; |
|
124 | + $this->timeFactory = $timeFactory; |
|
125 | + $this->l10n = $l; |
|
126 | + $this->config = $config; |
|
127 | + $this->tempManager = $tempManager; |
|
128 | + $this->appData = $appData; |
|
129 | + $this->scssCacher = $scssCacher; |
|
130 | + $this->urlGenerator = $urlGenerator; |
|
131 | + $this->appManager = $appManager; |
|
132 | + $this->imageManager = $imageManager; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $setting |
|
137 | - * @param string $value |
|
138 | - * @return DataResponse |
|
139 | - * @throws NotPermittedException |
|
140 | - */ |
|
141 | - public function updateStylesheet($setting, $value) { |
|
142 | - $value = trim($value); |
|
143 | - switch ($setting) { |
|
144 | - case 'name': |
|
145 | - if (strlen($value) > 250) { |
|
146 | - return new DataResponse([ |
|
147 | - 'data' => [ |
|
148 | - 'message' => $this->l10n->t('The given name is too long'), |
|
149 | - ], |
|
150 | - 'status' => 'error' |
|
151 | - ]); |
|
152 | - } |
|
153 | - break; |
|
154 | - case 'url': |
|
155 | - if (strlen($value) > 500) { |
|
156 | - return new DataResponse([ |
|
157 | - 'data' => [ |
|
158 | - 'message' => $this->l10n->t('The given web address is too long'), |
|
159 | - ], |
|
160 | - 'status' => 'error' |
|
161 | - ]); |
|
162 | - } |
|
163 | - break; |
|
164 | - case 'imprintUrl': |
|
165 | - if (strlen($value) > 500) { |
|
166 | - return new DataResponse([ |
|
167 | - 'data' => [ |
|
168 | - 'message' => $this->l10n->t('The given legal notice address is too long'), |
|
169 | - ], |
|
170 | - 'status' => 'error' |
|
171 | - ]); |
|
172 | - } |
|
173 | - break; |
|
174 | - case 'slogan': |
|
175 | - if (strlen($value) > 500) { |
|
176 | - return new DataResponse([ |
|
177 | - 'data' => [ |
|
178 | - 'message' => $this->l10n->t('The given slogan is too long'), |
|
179 | - ], |
|
180 | - 'status' => 'error' |
|
181 | - ]); |
|
182 | - } |
|
183 | - break; |
|
184 | - case 'color': |
|
185 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
186 | - return new DataResponse([ |
|
187 | - 'data' => [ |
|
188 | - 'message' => $this->l10n->t('The given color is invalid'), |
|
189 | - ], |
|
190 | - 'status' => 'error' |
|
191 | - ]); |
|
192 | - } |
|
193 | - break; |
|
194 | - } |
|
135 | + /** |
|
136 | + * @param string $setting |
|
137 | + * @param string $value |
|
138 | + * @return DataResponse |
|
139 | + * @throws NotPermittedException |
|
140 | + */ |
|
141 | + public function updateStylesheet($setting, $value) { |
|
142 | + $value = trim($value); |
|
143 | + switch ($setting) { |
|
144 | + case 'name': |
|
145 | + if (strlen($value) > 250) { |
|
146 | + return new DataResponse([ |
|
147 | + 'data' => [ |
|
148 | + 'message' => $this->l10n->t('The given name is too long'), |
|
149 | + ], |
|
150 | + 'status' => 'error' |
|
151 | + ]); |
|
152 | + } |
|
153 | + break; |
|
154 | + case 'url': |
|
155 | + if (strlen($value) > 500) { |
|
156 | + return new DataResponse([ |
|
157 | + 'data' => [ |
|
158 | + 'message' => $this->l10n->t('The given web address is too long'), |
|
159 | + ], |
|
160 | + 'status' => 'error' |
|
161 | + ]); |
|
162 | + } |
|
163 | + break; |
|
164 | + case 'imprintUrl': |
|
165 | + if (strlen($value) > 500) { |
|
166 | + return new DataResponse([ |
|
167 | + 'data' => [ |
|
168 | + 'message' => $this->l10n->t('The given legal notice address is too long'), |
|
169 | + ], |
|
170 | + 'status' => 'error' |
|
171 | + ]); |
|
172 | + } |
|
173 | + break; |
|
174 | + case 'slogan': |
|
175 | + if (strlen($value) > 500) { |
|
176 | + return new DataResponse([ |
|
177 | + 'data' => [ |
|
178 | + 'message' => $this->l10n->t('The given slogan is too long'), |
|
179 | + ], |
|
180 | + 'status' => 'error' |
|
181 | + ]); |
|
182 | + } |
|
183 | + break; |
|
184 | + case 'color': |
|
185 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
186 | + return new DataResponse([ |
|
187 | + 'data' => [ |
|
188 | + 'message' => $this->l10n->t('The given color is invalid'), |
|
189 | + ], |
|
190 | + 'status' => 'error' |
|
191 | + ]); |
|
192 | + } |
|
193 | + break; |
|
194 | + } |
|
195 | 195 | |
196 | - $this->themingDefaults->set($setting, $value); |
|
196 | + $this->themingDefaults->set($setting, $value); |
|
197 | 197 | |
198 | - // reprocess server scss for preview |
|
199 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
198 | + // reprocess server scss for preview |
|
199 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
200 | 200 | |
201 | - return new DataResponse( |
|
202 | - [ |
|
203 | - 'data' => |
|
204 | - [ |
|
205 | - 'message' => $this->l10n->t('Saved'), |
|
206 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
207 | - ], |
|
208 | - 'status' => 'success' |
|
209 | - ] |
|
210 | - ); |
|
211 | - } |
|
201 | + return new DataResponse( |
|
202 | + [ |
|
203 | + 'data' => |
|
204 | + [ |
|
205 | + 'message' => $this->l10n->t('Saved'), |
|
206 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
207 | + ], |
|
208 | + 'status' => 'success' |
|
209 | + ] |
|
210 | + ); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * @return DataResponse |
|
215 | - * @throws NotPermittedException |
|
216 | - */ |
|
217 | - public function uploadImage(): DataResponse { |
|
218 | - // logo / background |
|
219 | - // new: favicon logo-header |
|
220 | - // |
|
221 | - $key = $this->request->getParam('key'); |
|
222 | - $image = $this->request->getUploadedFile('image'); |
|
223 | - $error = null; |
|
224 | - $phpFileUploadErrors = [ |
|
225 | - UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
226 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
227 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
228 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
229 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
230 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
231 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
232 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
233 | - ]; |
|
234 | - if (empty($image)) { |
|
235 | - $error = $this->l10n->t('No file uploaded'); |
|
236 | - } |
|
237 | - if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
238 | - $error = $phpFileUploadErrors[$image['error']]; |
|
239 | - } |
|
213 | + /** |
|
214 | + * @return DataResponse |
|
215 | + * @throws NotPermittedException |
|
216 | + */ |
|
217 | + public function uploadImage(): DataResponse { |
|
218 | + // logo / background |
|
219 | + // new: favicon logo-header |
|
220 | + // |
|
221 | + $key = $this->request->getParam('key'); |
|
222 | + $image = $this->request->getUploadedFile('image'); |
|
223 | + $error = null; |
|
224 | + $phpFileUploadErrors = [ |
|
225 | + UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
226 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
227 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
228 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
229 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
230 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
231 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
232 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
233 | + ]; |
|
234 | + if (empty($image)) { |
|
235 | + $error = $this->l10n->t('No file uploaded'); |
|
236 | + } |
|
237 | + if (!empty($image) && array_key_exists('error', $image) && $image['error'] !== UPLOAD_ERR_OK) { |
|
238 | + $error = $phpFileUploadErrors[$image['error']]; |
|
239 | + } |
|
240 | 240 | |
241 | - if ($error !== null) { |
|
242 | - return new DataResponse( |
|
243 | - [ |
|
244 | - 'data' => [ |
|
245 | - 'message' => $error |
|
246 | - ], |
|
247 | - 'status' => 'failure', |
|
248 | - ], |
|
249 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
250 | - ); |
|
251 | - } |
|
241 | + if ($error !== null) { |
|
242 | + return new DataResponse( |
|
243 | + [ |
|
244 | + 'data' => [ |
|
245 | + 'message' => $error |
|
246 | + ], |
|
247 | + 'status' => 'failure', |
|
248 | + ], |
|
249 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
250 | + ); |
|
251 | + } |
|
252 | 252 | |
253 | - $name = ''; |
|
254 | - try { |
|
255 | - $folder = $this->appData->getFolder('images'); |
|
256 | - } catch (NotFoundException $e) { |
|
257 | - $folder = $this->appData->newFolder('images'); |
|
258 | - } |
|
253 | + $name = ''; |
|
254 | + try { |
|
255 | + $folder = $this->appData->getFolder('images'); |
|
256 | + } catch (NotFoundException $e) { |
|
257 | + $folder = $this->appData->newFolder('images'); |
|
258 | + } |
|
259 | 259 | |
260 | - $target = $folder->newFile($key); |
|
261 | - $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; |
|
262 | - if (!in_array($image['type'], $supportedFormats)) { |
|
263 | - return new DataResponse( |
|
264 | - [ |
|
265 | - 'data' => [ |
|
266 | - 'message' => $this->l10n->t('Unsupported image type'), |
|
267 | - ], |
|
268 | - 'status' => 'failure', |
|
269 | - ], |
|
270 | - Http::STATUS_UNPROCESSABLE_ENTITY |
|
271 | - ); |
|
272 | - } |
|
260 | + $target = $folder->newFile($key); |
|
261 | + $supportedFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'text/svg']; |
|
262 | + if (!in_array($image['type'], $supportedFormats)) { |
|
263 | + return new DataResponse( |
|
264 | + [ |
|
265 | + 'data' => [ |
|
266 | + 'message' => $this->l10n->t('Unsupported image type'), |
|
267 | + ], |
|
268 | + 'status' => 'failure', |
|
269 | + ], |
|
270 | + Http::STATUS_UNPROCESSABLE_ENTITY |
|
271 | + ); |
|
272 | + } |
|
273 | 273 | |
274 | - $resizeKeys = ['background']; |
|
275 | - if (in_array($key, $resizeKeys, true)) { |
|
276 | - // Optimize the image since some people may upload images that will be |
|
277 | - // either to big or are not progressive rendering. |
|
278 | - $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
274 | + $resizeKeys = ['background']; |
|
275 | + if (in_array($key, $resizeKeys, true)) { |
|
276 | + // Optimize the image since some people may upload images that will be |
|
277 | + // either to big or are not progressive rendering. |
|
278 | + $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r')); |
|
279 | 279 | |
280 | - $tmpFile = $this->tempManager->getTemporaryFile(); |
|
281 | - $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
282 | - $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
283 | - $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
280 | + $tmpFile = $this->tempManager->getTemporaryFile(); |
|
281 | + $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096; |
|
282 | + $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth); |
|
283 | + $outputImage = imagescale($newImage, $newWidth, $newHeight); |
|
284 | 284 | |
285 | - imageinterlace($outputImage, 1); |
|
286 | - imagejpeg($outputImage, $tmpFile, 75); |
|
287 | - imagedestroy($outputImage); |
|
285 | + imageinterlace($outputImage, 1); |
|
286 | + imagejpeg($outputImage, $tmpFile, 75); |
|
287 | + imagedestroy($outputImage); |
|
288 | 288 | |
289 | - $target->putContent(file_get_contents($tmpFile, 'r')); |
|
290 | - } else { |
|
291 | - $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
292 | - } |
|
293 | - $name = $image['name']; |
|
289 | + $target->putContent(file_get_contents($tmpFile, 'r')); |
|
290 | + } else { |
|
291 | + $target->putContent(file_get_contents($image['tmp_name'], 'r')); |
|
292 | + } |
|
293 | + $name = $image['name']; |
|
294 | 294 | |
295 | - $this->themingDefaults->set($key.'Mime', $image['type']); |
|
295 | + $this->themingDefaults->set($key.'Mime', $image['type']); |
|
296 | 296 | |
297 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
297 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
298 | 298 | |
299 | - return new DataResponse( |
|
300 | - [ |
|
301 | - 'data' => |
|
302 | - [ |
|
303 | - 'name' => $name, |
|
304 | - 'url' => $this->imageManager->getImageUrl($key), |
|
305 | - 'message' => $this->l10n->t('Saved'), |
|
306 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
307 | - ], |
|
308 | - 'status' => 'success' |
|
309 | - ] |
|
310 | - ); |
|
311 | - } |
|
299 | + return new DataResponse( |
|
300 | + [ |
|
301 | + 'data' => |
|
302 | + [ |
|
303 | + 'name' => $name, |
|
304 | + 'url' => $this->imageManager->getImageUrl($key), |
|
305 | + 'message' => $this->l10n->t('Saved'), |
|
306 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
307 | + ], |
|
308 | + 'status' => 'success' |
|
309 | + ] |
|
310 | + ); |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * Revert setting to default value |
|
315 | - * |
|
316 | - * @param string $setting setting which should be reverted |
|
317 | - * @return DataResponse |
|
318 | - * @throws NotPermittedException |
|
319 | - */ |
|
320 | - public function undo(string $setting): DataResponse { |
|
321 | - $value = $this->themingDefaults->undo($setting); |
|
322 | - // reprocess server scss for preview |
|
323 | - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
313 | + /** |
|
314 | + * Revert setting to default value |
|
315 | + * |
|
316 | + * @param string $setting setting which should be reverted |
|
317 | + * @return DataResponse |
|
318 | + * @throws NotPermittedException |
|
319 | + */ |
|
320 | + public function undo(string $setting): DataResponse { |
|
321 | + $value = $this->themingDefaults->undo($setting); |
|
322 | + // reprocess server scss for preview |
|
323 | + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); |
|
324 | 324 | |
325 | - if (strpos($setting, 'Mime') !== -1) { |
|
326 | - $imageKey = str_replace('Mime', '', $setting); |
|
327 | - $this->imageManager->delete($imageKey); |
|
328 | - } |
|
325 | + if (strpos($setting, 'Mime') !== -1) { |
|
326 | + $imageKey = str_replace('Mime', '', $setting); |
|
327 | + $this->imageManager->delete($imageKey); |
|
328 | + } |
|
329 | 329 | |
330 | - return new DataResponse( |
|
331 | - [ |
|
332 | - 'data' => |
|
333 | - [ |
|
334 | - 'value' => $value, |
|
335 | - 'message' => $this->l10n->t('Saved'), |
|
336 | - 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
337 | - ], |
|
338 | - 'status' => 'success' |
|
339 | - ] |
|
340 | - ); |
|
341 | - } |
|
330 | + return new DataResponse( |
|
331 | + [ |
|
332 | + 'data' => |
|
333 | + [ |
|
334 | + 'value' => $value, |
|
335 | + 'message' => $this->l10n->t('Saved'), |
|
336 | + 'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss')) |
|
337 | + ], |
|
338 | + 'status' => 'success' |
|
339 | + ] |
|
340 | + ); |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * @PublicPage |
|
345 | - * @NoCSRFRequired |
|
346 | - * |
|
347 | - * @param string $key |
|
348 | - * @return FileDisplayResponse|NotFoundResponse |
|
349 | - * @throws \Exception |
|
350 | - */ |
|
351 | - public function getImage(string $key) { |
|
352 | - try { |
|
353 | - $file = $this->imageManager->getImage($key); |
|
354 | - } catch (NotFoundException $e) { |
|
355 | - return new NotFoundResponse(); |
|
356 | - } |
|
343 | + /** |
|
344 | + * @PublicPage |
|
345 | + * @NoCSRFRequired |
|
346 | + * |
|
347 | + * @param string $key |
|
348 | + * @return FileDisplayResponse|NotFoundResponse |
|
349 | + * @throws \Exception |
|
350 | + */ |
|
351 | + public function getImage(string $key) { |
|
352 | + try { |
|
353 | + $file = $this->imageManager->getImage($key); |
|
354 | + } catch (NotFoundException $e) { |
|
355 | + return new NotFoundResponse(); |
|
356 | + } |
|
357 | 357 | |
358 | - $response = new FileDisplayResponse($file); |
|
359 | - $response->cacheFor(3600); |
|
360 | - $expires = new \DateTime(); |
|
361 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
362 | - $expires->add(new \DateInterval('PT24H')); |
|
363 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
364 | - $response->addHeader('Pragma', 'cache'); |
|
365 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
366 | - return $response; |
|
367 | - } |
|
358 | + $response = new FileDisplayResponse($file); |
|
359 | + $response->cacheFor(3600); |
|
360 | + $expires = new \DateTime(); |
|
361 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
362 | + $expires->add(new \DateInterval('PT24H')); |
|
363 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
364 | + $response->addHeader('Pragma', 'cache'); |
|
365 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
366 | + return $response; |
|
367 | + } |
|
368 | 368 | |
369 | - /** |
|
370 | - * @NoCSRFRequired |
|
371 | - * @PublicPage |
|
372 | - * |
|
373 | - * @return FileDisplayResponse|NotFoundResponse |
|
374 | - * @throws NotPermittedException |
|
375 | - * @throws \Exception |
|
376 | - * @throws \OCP\App\AppPathNotFoundException |
|
377 | - */ |
|
378 | - public function getStylesheet() { |
|
379 | - $appPath = $this->appManager->getAppPath('theming'); |
|
369 | + /** |
|
370 | + * @NoCSRFRequired |
|
371 | + * @PublicPage |
|
372 | + * |
|
373 | + * @return FileDisplayResponse|NotFoundResponse |
|
374 | + * @throws NotPermittedException |
|
375 | + * @throws \Exception |
|
376 | + * @throws \OCP\App\AppPathNotFoundException |
|
377 | + */ |
|
378 | + public function getStylesheet() { |
|
379 | + $appPath = $this->appManager->getAppPath('theming'); |
|
380 | 380 | |
381 | - /* SCSSCacher is required here |
|
381 | + /* SCSSCacher is required here |
|
382 | 382 | * We cannot rely on automatic caching done by \OC_Util::addStyle, |
383 | 383 | * since we need to add the cacheBuster value to the url |
384 | 384 | */ |
385 | - $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
386 | - if(!$cssCached) { |
|
387 | - return new NotFoundResponse(); |
|
388 | - } |
|
385 | + $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
|
386 | + if(!$cssCached) { |
|
387 | + return new NotFoundResponse(); |
|
388 | + } |
|
389 | 389 | |
390 | - try { |
|
391 | - $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
392 | - $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
393 | - $response->cacheFor(86400); |
|
394 | - $expires = new \DateTime(); |
|
395 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
396 | - $expires->add(new \DateInterval('PT24H')); |
|
397 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
398 | - $response->addHeader('Pragma', 'cache'); |
|
399 | - return $response; |
|
400 | - } catch (NotFoundException $e) { |
|
401 | - return new NotFoundResponse(); |
|
402 | - } |
|
403 | - } |
|
390 | + try { |
|
391 | + $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css'); |
|
392 | + $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
393 | + $response->cacheFor(86400); |
|
394 | + $expires = new \DateTime(); |
|
395 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
396 | + $expires->add(new \DateInterval('PT24H')); |
|
397 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
398 | + $response->addHeader('Pragma', 'cache'); |
|
399 | + return $response; |
|
400 | + } catch (NotFoundException $e) { |
|
401 | + return new NotFoundResponse(); |
|
402 | + } |
|
403 | + } |
|
404 | 404 | |
405 | - /** |
|
406 | - * @NoCSRFRequired |
|
407 | - * @PublicPage |
|
408 | - * |
|
409 | - * @return DataDownloadResponse |
|
410 | - */ |
|
411 | - public function getJavascript() { |
|
412 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
413 | - $responseJS = '(function() { |
|
405 | + /** |
|
406 | + * @NoCSRFRequired |
|
407 | + * @PublicPage |
|
408 | + * |
|
409 | + * @return DataDownloadResponse |
|
410 | + */ |
|
411 | + public function getJavascript() { |
|
412 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
413 | + $responseJS = '(function() { |
|
414 | 414 | OCA.Theming = { |
415 | 415 | name: ' . json_encode($this->themingDefaults->getName()) . ', |
416 | 416 | url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
@@ -421,45 +421,45 @@ discard block |
||
421 | 421 | cacheBuster: ' . json_encode($cacheBusterValue) . ' |
422 | 422 | }; |
423 | 423 | })();'; |
424 | - $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
425 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
426 | - $response->addHeader('Pragma', 'cache'); |
|
427 | - $response->cacheFor(3600); |
|
428 | - return $response; |
|
429 | - } |
|
424 | + $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
|
425 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
426 | + $response->addHeader('Pragma', 'cache'); |
|
427 | + $response->cacheFor(3600); |
|
428 | + return $response; |
|
429 | + } |
|
430 | 430 | |
431 | - /** |
|
432 | - * @NoCSRFRequired |
|
433 | - * @PublicPage |
|
434 | - * |
|
435 | - * @return Http\JSONResponse |
|
436 | - */ |
|
437 | - public function getManifest($app) { |
|
438 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
439 | - $responseJS = [ |
|
440 | - 'name' => $this->themingDefaults->getName(), |
|
441 | - 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
442 | - 'icons' => |
|
443 | - [ |
|
444 | - [ |
|
445 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
446 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
447 | - 'type'=> 'image/png', |
|
448 | - 'sizes'=> '128x128' |
|
449 | - ], |
|
450 | - [ |
|
451 | - 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
452 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
453 | - 'type' => 'image/svg+xml', |
|
454 | - 'sizes' => '16x16' |
|
455 | - ] |
|
456 | - ], |
|
457 | - 'display' => 'standalone' |
|
458 | - ]; |
|
459 | - $response = new Http\JSONResponse($responseJS); |
|
460 | - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
461 | - $response->addHeader('Pragma', 'cache'); |
|
462 | - $response->cacheFor(3600); |
|
463 | - return $response; |
|
464 | - } |
|
431 | + /** |
|
432 | + * @NoCSRFRequired |
|
433 | + * @PublicPage |
|
434 | + * |
|
435 | + * @return Http\JSONResponse |
|
436 | + */ |
|
437 | + public function getManifest($app) { |
|
438 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
439 | + $responseJS = [ |
|
440 | + 'name' => $this->themingDefaults->getName(), |
|
441 | + 'start_url' => $this->urlGenerator->getBaseUrl(), |
|
442 | + 'icons' => |
|
443 | + [ |
|
444 | + [ |
|
445 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
|
446 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
447 | + 'type'=> 'image/png', |
|
448 | + 'sizes'=> '128x128' |
|
449 | + ], |
|
450 | + [ |
|
451 | + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
|
452 | + ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
453 | + 'type' => 'image/svg+xml', |
|
454 | + 'sizes' => '16x16' |
|
455 | + ] |
|
456 | + ], |
|
457 | + 'display' => 'standalone' |
|
458 | + ]; |
|
459 | + $response = new Http\JSONResponse($responseJS); |
|
460 | + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); |
|
461 | + $response->addHeader('Pragma', 'cache'); |
|
462 | + $response->cacheFor(3600); |
|
463 | + return $response; |
|
464 | + } |
|
465 | 465 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $expires->add(new \DateInterval('PT24H')); |
363 | 363 | $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
364 | 364 | $response->addHeader('Pragma', 'cache'); |
365 | - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key . 'Mime', '')); |
|
365 | + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, $key.'Mime', '')); |
|
366 | 366 | return $response; |
367 | 367 | } |
368 | 368 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * since we need to add the cacheBuster value to the url |
384 | 384 | */ |
385 | 385 | $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); |
386 | - if(!$cssCached) { |
|
386 | + if (!$cssCached) { |
|
387 | 387 | return new NotFoundResponse(); |
388 | 388 | } |
389 | 389 | |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
413 | 413 | $responseJS = '(function() { |
414 | 414 | OCA.Theming = { |
415 | - name: ' . json_encode($this->themingDefaults->getName()) . ', |
|
416 | - url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ', |
|
417 | - slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ', |
|
418 | - color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ', |
|
419 | - imprintUrl: ' . json_encode($this->themingDefaults->getImprintUrl()) . ', |
|
420 | - inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ', |
|
421 | - cacheBuster: ' . json_encode($cacheBusterValue) . ' |
|
415 | + name: ' . json_encode($this->themingDefaults->getName()).', |
|
416 | + url: ' . json_encode($this->themingDefaults->getBaseUrl()).', |
|
417 | + slogan: ' . json_encode($this->themingDefaults->getSlogan()).', |
|
418 | + color: ' . json_encode($this->themingDefaults->getColorPrimary()).', |
|
419 | + imprintUrl: ' . json_encode($this->themingDefaults->getImprintUrl()).', |
|
420 | + inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).', |
|
421 | + cacheBuster: ' . json_encode($cacheBusterValue).' |
|
422 | 422 | }; |
423 | 423 | })();'; |
424 | 424 | $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript'); |
@@ -443,13 +443,13 @@ discard block |
||
443 | 443 | [ |
444 | 444 | [ |
445 | 445 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', |
446 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
446 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
447 | 447 | 'type'=> 'image/png', |
448 | 448 | 'sizes'=> '128x128' |
449 | 449 | ], |
450 | 450 | [ |
451 | 451 | 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', |
452 | - ['app' => $app]) . '?v=' . $cacheBusterValue, |
|
452 | + ['app' => $app]).'?v='.$cacheBusterValue, |
|
453 | 453 | 'type' => 'image/svg+xml', |
454 | 454 | 'sizes' => '16x16' |
455 | 455 | ] |
@@ -38,74 +38,74 @@ |
||
38 | 38 | use OCP\Settings\ISettings; |
39 | 39 | |
40 | 40 | class Admin implements ISettings { |
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IL10N */ |
|
44 | - private $l; |
|
45 | - /** @var ThemingDefaults */ |
|
46 | - private $themingDefaults; |
|
47 | - /** @var IURLGenerator */ |
|
48 | - private $urlGenerator; |
|
49 | - /** @var ImageManager */ |
|
50 | - private $imageManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IL10N */ |
|
44 | + private $l; |
|
45 | + /** @var ThemingDefaults */ |
|
46 | + private $themingDefaults; |
|
47 | + /** @var IURLGenerator */ |
|
48 | + private $urlGenerator; |
|
49 | + /** @var ImageManager */ |
|
50 | + private $imageManager; |
|
51 | 51 | |
52 | - public function __construct(IConfig $config, |
|
53 | - IL10N $l, |
|
54 | - ThemingDefaults $themingDefaults, |
|
55 | - IURLGenerator $urlGenerator, |
|
56 | - ImageManager $imageManager) { |
|
57 | - $this->config = $config; |
|
58 | - $this->l = $l; |
|
59 | - $this->themingDefaults = $themingDefaults; |
|
60 | - $this->urlGenerator = $urlGenerator; |
|
61 | - $this->imageManager = $imageManager; |
|
62 | - } |
|
52 | + public function __construct(IConfig $config, |
|
53 | + IL10N $l, |
|
54 | + ThemingDefaults $themingDefaults, |
|
55 | + IURLGenerator $urlGenerator, |
|
56 | + ImageManager $imageManager) { |
|
57 | + $this->config = $config; |
|
58 | + $this->l = $l; |
|
59 | + $this->themingDefaults = $themingDefaults; |
|
60 | + $this->urlGenerator = $urlGenerator; |
|
61 | + $this->imageManager = $imageManager; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return TemplateResponse |
|
66 | - */ |
|
67 | - public function getForm(): TemplateResponse { |
|
68 | - $themable = true; |
|
69 | - $errorMessage = ''; |
|
70 | - $theme = $this->config->getSystemValue('theme', ''); |
|
71 | - if ($theme !== '') { |
|
72 | - $themable = false; |
|
73 | - $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.'); |
|
74 | - } |
|
64 | + /** |
|
65 | + * @return TemplateResponse |
|
66 | + */ |
|
67 | + public function getForm(): TemplateResponse { |
|
68 | + $themable = true; |
|
69 | + $errorMessage = ''; |
|
70 | + $theme = $this->config->getSystemValue('theme', ''); |
|
71 | + if ($theme !== '') { |
|
72 | + $themable = false; |
|
73 | + $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.'); |
|
74 | + } |
|
75 | 75 | |
76 | - $parameters = [ |
|
77 | - 'themable' => $themable, |
|
78 | - 'errorMessage' => $errorMessage, |
|
79 | - 'name' => $this->themingDefaults->getEntity(), |
|
80 | - 'url' => $this->themingDefaults->getBaseUrl(), |
|
81 | - 'slogan' => $this->themingDefaults->getSlogan(), |
|
82 | - 'color' => $this->themingDefaults->getColorPrimary(), |
|
83 | - 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), |
|
84 | - 'canThemeIcons' => $this->themingDefaults->shouldReplaceIcons(), |
|
85 | - 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), |
|
86 | - 'images' => $this->imageManager->getCustomImages(), |
|
87 | - 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
88 | - ]; |
|
76 | + $parameters = [ |
|
77 | + 'themable' => $themable, |
|
78 | + 'errorMessage' => $errorMessage, |
|
79 | + 'name' => $this->themingDefaults->getEntity(), |
|
80 | + 'url' => $this->themingDefaults->getBaseUrl(), |
|
81 | + 'slogan' => $this->themingDefaults->getSlogan(), |
|
82 | + 'color' => $this->themingDefaults->getColorPrimary(), |
|
83 | + 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'), |
|
84 | + 'canThemeIcons' => $this->themingDefaults->shouldReplaceIcons(), |
|
85 | + 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'), |
|
86 | + 'images' => $this->imageManager->getCustomImages(), |
|
87 | + 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
88 | + ]; |
|
89 | 89 | |
90 | - return new TemplateResponse('theming', 'settings-admin', $parameters, ''); |
|
91 | - } |
|
90 | + return new TemplateResponse('theming', 'settings-admin', $parameters, ''); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return string the section ID, e.g. 'sharing' |
|
95 | - */ |
|
96 | - public function getSection(): string { |
|
97 | - return 'theming'; |
|
98 | - } |
|
93 | + /** |
|
94 | + * @return string the section ID, e.g. 'sharing' |
|
95 | + */ |
|
96 | + public function getSection(): string { |
|
97 | + return 'theming'; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return int whether the form should be rather on the top or bottom of |
|
102 | - * the admin section. The forms are arranged in ascending order of the |
|
103 | - * priority values. It is required to return a value between 0 and 100. |
|
104 | - * |
|
105 | - * E.g.: 70 |
|
106 | - */ |
|
107 | - public function getPriority(): int { |
|
108 | - return 5; |
|
109 | - } |
|
100 | + /** |
|
101 | + * @return int whether the form should be rather on the top or bottom of |
|
102 | + * the admin section. The forms are arranged in ascending order of the |
|
103 | + * priority values. It is required to return a value between 0 and 100. |
|
104 | + * |
|
105 | + * E.g.: 70 |
|
106 | + */ |
|
107 | + public function getPriority(): int { |
|
108 | + return 5; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | } |