@@ -43,359 +43,359 @@ |
||
43 | 43 | |
44 | 44 | class ThemingDefaults extends \OC_Defaults { |
45 | 45 | |
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
48 | - /** @var IL10N */ |
|
49 | - private $l; |
|
50 | - /** @var ImageManager */ |
|
51 | - private $imageManager; |
|
52 | - /** @var IURLGenerator */ |
|
53 | - private $urlGenerator; |
|
54 | - /** @var ICacheFactory */ |
|
55 | - private $cacheFactory; |
|
56 | - /** @var Util */ |
|
57 | - private $util; |
|
58 | - /** @var IAppManager */ |
|
59 | - private $appManager; |
|
60 | - /** @var string */ |
|
61 | - private $name; |
|
62 | - /** @var string */ |
|
63 | - private $title; |
|
64 | - /** @var string */ |
|
65 | - private $entity; |
|
66 | - /** @var string */ |
|
67 | - private $url; |
|
68 | - /** @var string */ |
|
69 | - private $slogan; |
|
70 | - /** @var string */ |
|
71 | - private $color; |
|
72 | - |
|
73 | - /** @var string */ |
|
74 | - private $iTunesAppId; |
|
75 | - /** @var string */ |
|
76 | - private $iOSClientUrl; |
|
77 | - /** @var string */ |
|
78 | - private $AndroidClientUrl; |
|
79 | - |
|
80 | - /** |
|
81 | - * ThemingDefaults constructor. |
|
82 | - * |
|
83 | - * @param IConfig $config |
|
84 | - * @param IL10N $l |
|
85 | - * @param ImageManager $imageManager |
|
86 | - * @param IURLGenerator $urlGenerator |
|
87 | - * @param ICacheFactory $cacheFactory |
|
88 | - * @param Util $util |
|
89 | - * @param IAppManager $appManager |
|
90 | - */ |
|
91 | - public function __construct(IConfig $config, |
|
92 | - IL10N $l, |
|
93 | - IURLGenerator $urlGenerator, |
|
94 | - ICacheFactory $cacheFactory, |
|
95 | - Util $util, |
|
96 | - ImageManager $imageManager, |
|
97 | - IAppManager $appManager |
|
98 | - ) { |
|
99 | - parent::__construct(); |
|
100 | - $this->config = $config; |
|
101 | - $this->l = $l; |
|
102 | - $this->imageManager = $imageManager; |
|
103 | - $this->urlGenerator = $urlGenerator; |
|
104 | - $this->cacheFactory = $cacheFactory; |
|
105 | - $this->util = $util; |
|
106 | - $this->appManager = $appManager; |
|
107 | - |
|
108 | - $this->name = parent::getName(); |
|
109 | - $this->title = parent::getTitle(); |
|
110 | - $this->entity = parent::getEntity(); |
|
111 | - $this->url = parent::getBaseUrl(); |
|
112 | - $this->slogan = parent::getSlogan(); |
|
113 | - $this->color = parent::getColorPrimary(); |
|
114 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
115 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
116 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
117 | - } |
|
118 | - |
|
119 | - public function getName() { |
|
120 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
121 | - } |
|
122 | - |
|
123 | - public function getHTMLName() { |
|
124 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
125 | - } |
|
126 | - |
|
127 | - public function getTitle() { |
|
128 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
129 | - } |
|
130 | - |
|
131 | - public function getEntity() { |
|
132 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
133 | - } |
|
134 | - |
|
135 | - public function getBaseUrl() { |
|
136 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
137 | - } |
|
138 | - |
|
139 | - public function getSlogan() { |
|
140 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
141 | - } |
|
142 | - |
|
143 | - public function getImprintUrl() { |
|
144 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
145 | - } |
|
146 | - |
|
147 | - public function getPrivacyUrl() { |
|
148 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
149 | - } |
|
150 | - |
|
151 | - public function getShortFooter() { |
|
152 | - $slogan = $this->getSlogan(); |
|
153 | - $baseUrl = $this->getBaseUrl(); |
|
154 | - if ($baseUrl !== '') { |
|
155 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
156 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
157 | - } else { |
|
158 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
159 | - } |
|
160 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
161 | - |
|
162 | - $links = [ |
|
163 | - [ |
|
164 | - 'text' => $this->l->t('Legal notice'), |
|
165 | - 'url' => (string)$this->getImprintUrl() |
|
166 | - ], |
|
167 | - [ |
|
168 | - 'text' => $this->l->t('Privacy policy'), |
|
169 | - 'url' => (string)$this->getPrivacyUrl() |
|
170 | - ], |
|
171 | - ]; |
|
172 | - |
|
173 | - $legalLinks = ''; $divider = ''; |
|
174 | - foreach($links as $link) { |
|
175 | - if($link['url'] !== '' |
|
176 | - && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
177 | - ) { |
|
178 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
179 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
180 | - $divider = ' · '; |
|
181 | - } |
|
182 | - } |
|
183 | - if($legalLinks !== '' ) { |
|
184 | - $footer .= '<br/>' . $legalLinks; |
|
185 | - } |
|
186 | - |
|
187 | - return $footer; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Color that is used for the header as well as for mail headers |
|
192 | - * |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function getColorPrimary() { |
|
196 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Themed logo url |
|
201 | - * |
|
202 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function getLogo($useSvg = true): string { |
|
206 | - $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
207 | - |
|
208 | - $logoExists = true; |
|
209 | - try { |
|
210 | - $this->imageManager->getImage('logo', $useSvg); |
|
211 | - } catch (\Exception $e) { |
|
212 | - $logoExists = false; |
|
213 | - } |
|
214 | - |
|
215 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
216 | - |
|
217 | - if(!$logo || !$logoExists) { |
|
218 | - if($useSvg) { |
|
219 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
220 | - } else { |
|
221 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
222 | - } |
|
223 | - return $logo . '?v=' . $cacheBusterCounter; |
|
224 | - } |
|
225 | - |
|
226 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Themed background image url |
|
231 | - * |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public function getBackground(): string { |
|
235 | - return $this->imageManager->getImageUrl('background'); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public function getiTunesAppId() { |
|
242 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function getiOSClientUrl() { |
|
249 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function getAndroidClientUrl() { |
|
256 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @return array scss variables to overwrite |
|
262 | - */ |
|
263 | - public function getScssVariables() { |
|
264 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
265 | - if ($value = $cache->get('getScssVariables')) { |
|
266 | - return $value; |
|
267 | - } |
|
268 | - |
|
269 | - $variables = [ |
|
270 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
271 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
272 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
273 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
274 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
275 | - ]; |
|
276 | - |
|
277 | - $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
278 | - $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
279 | - $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
280 | - $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
281 | - $variables['image-login-plain'] = 'false'; |
|
282 | - |
|
283 | - if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
284 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
285 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
286 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
287 | - } |
|
288 | - |
|
289 | - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
290 | - $variables['image-login-plain'] = 'true'; |
|
291 | - } |
|
292 | - |
|
293 | - $variables['has-legal-links'] = 'false'; |
|
294 | - if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
295 | - $variables['has-legal-links'] = 'true'; |
|
296 | - } |
|
297 | - |
|
298 | - $cache->set('getScssVariables', $variables); |
|
299 | - return $variables; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Check if the image should be replaced by the theming app |
|
304 | - * and return the new image location then |
|
305 | - * |
|
306 | - * @param string $app name of the app |
|
307 | - * @param string $image filename of the image |
|
308 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
309 | - */ |
|
310 | - public function replaceImagePath($app, $image) { |
|
311 | - if($app==='') { |
|
312 | - $app = 'core'; |
|
313 | - } |
|
314 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
315 | - |
|
316 | - try { |
|
317 | - $customFavicon = $this->imageManager->getImage('favicon'); |
|
318 | - } catch (NotFoundException $e) { |
|
319 | - $customFavicon = null; |
|
320 | - } |
|
321 | - |
|
322 | - if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
323 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
324 | - } |
|
325 | - if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
326 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
327 | - } |
|
328 | - if ($image === 'manifest.json') { |
|
329 | - try { |
|
330 | - $appPath = $this->appManager->getAppPath($app); |
|
331 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
332 | - return false; |
|
333 | - } |
|
334 | - } catch (AppPathNotFoundException $e) {} |
|
335 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
336 | - } |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Increases the cache buster key |
|
342 | - */ |
|
343 | - private function increaseCacheBuster() { |
|
344 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
345 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
346 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
347 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
348 | - |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Update setting in the database |
|
353 | - * |
|
354 | - * @param string $setting |
|
355 | - * @param string $value |
|
356 | - */ |
|
357 | - public function set($setting, $value) { |
|
358 | - $this->config->setAppValue('theming', $setting, $value); |
|
359 | - $this->increaseCacheBuster(); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Revert settings to the default value |
|
364 | - * |
|
365 | - * @param string $setting setting which should be reverted |
|
366 | - * @return string default value |
|
367 | - */ |
|
368 | - public function undo($setting) { |
|
369 | - $this->config->deleteAppValue('theming', $setting); |
|
370 | - $this->increaseCacheBuster(); |
|
371 | - |
|
372 | - switch ($setting) { |
|
373 | - case 'name': |
|
374 | - $returnValue = $this->getEntity(); |
|
375 | - break; |
|
376 | - case 'url': |
|
377 | - $returnValue = $this->getBaseUrl(); |
|
378 | - break; |
|
379 | - case 'slogan': |
|
380 | - $returnValue = $this->getSlogan(); |
|
381 | - break; |
|
382 | - case 'color': |
|
383 | - $returnValue = $this->getColorPrimary(); |
|
384 | - break; |
|
385 | - default: |
|
386 | - $returnValue = ''; |
|
387 | - break; |
|
388 | - } |
|
389 | - |
|
390 | - return $returnValue; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Color of text in the header and primary buttons |
|
395 | - * |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public function getTextColorPrimary() { |
|
399 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
400 | - } |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | + /** @var IL10N */ |
|
49 | + private $l; |
|
50 | + /** @var ImageManager */ |
|
51 | + private $imageManager; |
|
52 | + /** @var IURLGenerator */ |
|
53 | + private $urlGenerator; |
|
54 | + /** @var ICacheFactory */ |
|
55 | + private $cacheFactory; |
|
56 | + /** @var Util */ |
|
57 | + private $util; |
|
58 | + /** @var IAppManager */ |
|
59 | + private $appManager; |
|
60 | + /** @var string */ |
|
61 | + private $name; |
|
62 | + /** @var string */ |
|
63 | + private $title; |
|
64 | + /** @var string */ |
|
65 | + private $entity; |
|
66 | + /** @var string */ |
|
67 | + private $url; |
|
68 | + /** @var string */ |
|
69 | + private $slogan; |
|
70 | + /** @var string */ |
|
71 | + private $color; |
|
72 | + |
|
73 | + /** @var string */ |
|
74 | + private $iTunesAppId; |
|
75 | + /** @var string */ |
|
76 | + private $iOSClientUrl; |
|
77 | + /** @var string */ |
|
78 | + private $AndroidClientUrl; |
|
79 | + |
|
80 | + /** |
|
81 | + * ThemingDefaults constructor. |
|
82 | + * |
|
83 | + * @param IConfig $config |
|
84 | + * @param IL10N $l |
|
85 | + * @param ImageManager $imageManager |
|
86 | + * @param IURLGenerator $urlGenerator |
|
87 | + * @param ICacheFactory $cacheFactory |
|
88 | + * @param Util $util |
|
89 | + * @param IAppManager $appManager |
|
90 | + */ |
|
91 | + public function __construct(IConfig $config, |
|
92 | + IL10N $l, |
|
93 | + IURLGenerator $urlGenerator, |
|
94 | + ICacheFactory $cacheFactory, |
|
95 | + Util $util, |
|
96 | + ImageManager $imageManager, |
|
97 | + IAppManager $appManager |
|
98 | + ) { |
|
99 | + parent::__construct(); |
|
100 | + $this->config = $config; |
|
101 | + $this->l = $l; |
|
102 | + $this->imageManager = $imageManager; |
|
103 | + $this->urlGenerator = $urlGenerator; |
|
104 | + $this->cacheFactory = $cacheFactory; |
|
105 | + $this->util = $util; |
|
106 | + $this->appManager = $appManager; |
|
107 | + |
|
108 | + $this->name = parent::getName(); |
|
109 | + $this->title = parent::getTitle(); |
|
110 | + $this->entity = parent::getEntity(); |
|
111 | + $this->url = parent::getBaseUrl(); |
|
112 | + $this->slogan = parent::getSlogan(); |
|
113 | + $this->color = parent::getColorPrimary(); |
|
114 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
115 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
116 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
117 | + } |
|
118 | + |
|
119 | + public function getName() { |
|
120 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
121 | + } |
|
122 | + |
|
123 | + public function getHTMLName() { |
|
124 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
125 | + } |
|
126 | + |
|
127 | + public function getTitle() { |
|
128 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
129 | + } |
|
130 | + |
|
131 | + public function getEntity() { |
|
132 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
133 | + } |
|
134 | + |
|
135 | + public function getBaseUrl() { |
|
136 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
137 | + } |
|
138 | + |
|
139 | + public function getSlogan() { |
|
140 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
141 | + } |
|
142 | + |
|
143 | + public function getImprintUrl() { |
|
144 | + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
145 | + } |
|
146 | + |
|
147 | + public function getPrivacyUrl() { |
|
148 | + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
149 | + } |
|
150 | + |
|
151 | + public function getShortFooter() { |
|
152 | + $slogan = $this->getSlogan(); |
|
153 | + $baseUrl = $this->getBaseUrl(); |
|
154 | + if ($baseUrl !== '') { |
|
155 | + $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
156 | + ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
157 | + } else { |
|
158 | + $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
159 | + } |
|
160 | + $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
161 | + |
|
162 | + $links = [ |
|
163 | + [ |
|
164 | + 'text' => $this->l->t('Legal notice'), |
|
165 | + 'url' => (string)$this->getImprintUrl() |
|
166 | + ], |
|
167 | + [ |
|
168 | + 'text' => $this->l->t('Privacy policy'), |
|
169 | + 'url' => (string)$this->getPrivacyUrl() |
|
170 | + ], |
|
171 | + ]; |
|
172 | + |
|
173 | + $legalLinks = ''; $divider = ''; |
|
174 | + foreach($links as $link) { |
|
175 | + if($link['url'] !== '' |
|
176 | + && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
177 | + ) { |
|
178 | + $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
179 | + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
180 | + $divider = ' · '; |
|
181 | + } |
|
182 | + } |
|
183 | + if($legalLinks !== '' ) { |
|
184 | + $footer .= '<br/>' . $legalLinks; |
|
185 | + } |
|
186 | + |
|
187 | + return $footer; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Color that is used for the header as well as for mail headers |
|
192 | + * |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function getColorPrimary() { |
|
196 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Themed logo url |
|
201 | + * |
|
202 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function getLogo($useSvg = true): string { |
|
206 | + $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
207 | + |
|
208 | + $logoExists = true; |
|
209 | + try { |
|
210 | + $this->imageManager->getImage('logo', $useSvg); |
|
211 | + } catch (\Exception $e) { |
|
212 | + $logoExists = false; |
|
213 | + } |
|
214 | + |
|
215 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
216 | + |
|
217 | + if(!$logo || !$logoExists) { |
|
218 | + if($useSvg) { |
|
219 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
220 | + } else { |
|
221 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
222 | + } |
|
223 | + return $logo . '?v=' . $cacheBusterCounter; |
|
224 | + } |
|
225 | + |
|
226 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Themed background image url |
|
231 | + * |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public function getBackground(): string { |
|
235 | + return $this->imageManager->getImageUrl('background'); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public function getiTunesAppId() { |
|
242 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function getiOSClientUrl() { |
|
249 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function getAndroidClientUrl() { |
|
256 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @return array scss variables to overwrite |
|
262 | + */ |
|
263 | + public function getScssVariables() { |
|
264 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
265 | + if ($value = $cache->get('getScssVariables')) { |
|
266 | + return $value; |
|
267 | + } |
|
268 | + |
|
269 | + $variables = [ |
|
270 | + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
271 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
272 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
273 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
274 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
275 | + ]; |
|
276 | + |
|
277 | + $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
278 | + $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
279 | + $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
280 | + $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
281 | + $variables['image-login-plain'] = 'false'; |
|
282 | + |
|
283 | + if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
284 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
285 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
286 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
287 | + } |
|
288 | + |
|
289 | + if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
290 | + $variables['image-login-plain'] = 'true'; |
|
291 | + } |
|
292 | + |
|
293 | + $variables['has-legal-links'] = 'false'; |
|
294 | + if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
295 | + $variables['has-legal-links'] = 'true'; |
|
296 | + } |
|
297 | + |
|
298 | + $cache->set('getScssVariables', $variables); |
|
299 | + return $variables; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Check if the image should be replaced by the theming app |
|
304 | + * and return the new image location then |
|
305 | + * |
|
306 | + * @param string $app name of the app |
|
307 | + * @param string $image filename of the image |
|
308 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
309 | + */ |
|
310 | + public function replaceImagePath($app, $image) { |
|
311 | + if($app==='') { |
|
312 | + $app = 'core'; |
|
313 | + } |
|
314 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
315 | + |
|
316 | + try { |
|
317 | + $customFavicon = $this->imageManager->getImage('favicon'); |
|
318 | + } catch (NotFoundException $e) { |
|
319 | + $customFavicon = null; |
|
320 | + } |
|
321 | + |
|
322 | + if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
323 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
324 | + } |
|
325 | + if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
326 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
327 | + } |
|
328 | + if ($image === 'manifest.json') { |
|
329 | + try { |
|
330 | + $appPath = $this->appManager->getAppPath($app); |
|
331 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
332 | + return false; |
|
333 | + } |
|
334 | + } catch (AppPathNotFoundException $e) {} |
|
335 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
336 | + } |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Increases the cache buster key |
|
342 | + */ |
|
343 | + private function increaseCacheBuster() { |
|
344 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
345 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
346 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
347 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Update setting in the database |
|
353 | + * |
|
354 | + * @param string $setting |
|
355 | + * @param string $value |
|
356 | + */ |
|
357 | + public function set($setting, $value) { |
|
358 | + $this->config->setAppValue('theming', $setting, $value); |
|
359 | + $this->increaseCacheBuster(); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Revert settings to the default value |
|
364 | + * |
|
365 | + * @param string $setting setting which should be reverted |
|
366 | + * @return string default value |
|
367 | + */ |
|
368 | + public function undo($setting) { |
|
369 | + $this->config->deleteAppValue('theming', $setting); |
|
370 | + $this->increaseCacheBuster(); |
|
371 | + |
|
372 | + switch ($setting) { |
|
373 | + case 'name': |
|
374 | + $returnValue = $this->getEntity(); |
|
375 | + break; |
|
376 | + case 'url': |
|
377 | + $returnValue = $this->getBaseUrl(); |
|
378 | + break; |
|
379 | + case 'slogan': |
|
380 | + $returnValue = $this->getSlogan(); |
|
381 | + break; |
|
382 | + case 'color': |
|
383 | + $returnValue = $this->getColorPrimary(); |
|
384 | + break; |
|
385 | + default: |
|
386 | + $returnValue = ''; |
|
387 | + break; |
|
388 | + } |
|
389 | + |
|
390 | + return $returnValue; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Color of text in the header and primary buttons |
|
395 | + * |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public function getTextColorPrimary() { |
|
399 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
400 | + } |
|
401 | 401 | } |
@@ -141,47 +141,47 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | public function getImprintUrl() { |
144 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
144 | + return (string) $this->config->getAppValue('theming', 'imprintUrl', ''); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | public function getPrivacyUrl() { |
148 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
148 | + return (string) $this->config->getAppValue('theming', 'privacyUrl', ''); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | public function getShortFooter() { |
152 | 152 | $slogan = $this->getSlogan(); |
153 | 153 | $baseUrl = $this->getBaseUrl(); |
154 | 154 | if ($baseUrl !== '') { |
155 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
156 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
155 | + $footer = '<a href="'.$baseUrl.'" target="_blank"'. |
|
156 | + ' rel="noreferrer noopener" class="entity-name">'.$this->getEntity().'</a>'; |
|
157 | 157 | } else { |
158 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
158 | + $footer = '<span class="entity-name">'.$this->getEntity().'</span>'; |
|
159 | 159 | } |
160 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
160 | + $footer .= ($slogan !== '' ? ' – '.$slogan : ''); |
|
161 | 161 | |
162 | 162 | $links = [ |
163 | 163 | [ |
164 | 164 | 'text' => $this->l->t('Legal notice'), |
165 | - 'url' => (string)$this->getImprintUrl() |
|
165 | + 'url' => (string) $this->getImprintUrl() |
|
166 | 166 | ], |
167 | 167 | [ |
168 | 168 | 'text' => $this->l->t('Privacy policy'), |
169 | - 'url' => (string)$this->getPrivacyUrl() |
|
169 | + 'url' => (string) $this->getPrivacyUrl() |
|
170 | 170 | ], |
171 | 171 | ]; |
172 | 172 | |
173 | 173 | $legalLinks = ''; $divider = ''; |
174 | - foreach($links as $link) { |
|
175 | - if($link['url'] !== '' |
|
174 | + foreach ($links as $link) { |
|
175 | + if ($link['url'] !== '' |
|
176 | 176 | && filter_var($link['url'], FILTER_VALIDATE_URL) |
177 | 177 | ) { |
178 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
179 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
178 | + $legalLinks .= $divider.'<a href="'.$link['url'].'" class="legal" target="_blank"'. |
|
179 | + ' rel="noreferrer noopener">'.$link['text'].'</a>'; |
|
180 | 180 | $divider = ' · '; |
181 | 181 | } |
182 | 182 | } |
183 | - if($legalLinks !== '' ) { |
|
184 | - $footer .= '<br/>' . $legalLinks; |
|
183 | + if ($legalLinks !== '') { |
|
184 | + $footer .= '<br/>'.$legalLinks; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | return $footer; |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | |
215 | 215 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
216 | 216 | |
217 | - if(!$logo || !$logoExists) { |
|
218 | - if($useSvg) { |
|
217 | + if (!$logo || !$logoExists) { |
|
218 | + if ($useSvg) { |
|
219 | 219 | $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
220 | 220 | } else { |
221 | 221 | $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
222 | 222 | } |
223 | - return $logo . '?v=' . $cacheBusterCounter; |
|
223 | + return $logo.'?v='.$cacheBusterCounter; |
|
224 | 224 | } |
225 | 225 | |
226 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
226 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', ['key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter]); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * @return array scss variables to overwrite |
262 | 262 | */ |
263 | 263 | public function getScssVariables() { |
264 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
264 | + $cache = $this->cacheFactory->createDistributed('theming-'.$this->urlGenerator->getBaseUrl()); |
|
265 | 265 | if ($value = $cache->get('getScssVariables')) { |
266 | 266 | return $value; |
267 | 267 | } |
268 | 268 | |
269 | 269 | $variables = [ |
270 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
271 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
272 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
273 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
274 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
270 | + 'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'", |
|
271 | + 'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime')."'", |
|
272 | + 'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime')."'", |
|
273 | + 'theming-logoheader-mime' => "'".$this->config->getAppValue('theming', 'logoheaderMime')."'", |
|
274 | + 'theming-favicon-mime' => "'".$this->config->getAppValue('theming', 'faviconMime')."'" |
|
275 | 275 | ]; |
276 | 276 | |
277 | 277 | $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | $variables['has-legal-links'] = 'false'; |
294 | - if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
294 | + if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
295 | 295 | $variables['has-legal-links'] = 'true'; |
296 | 296 | } |
297 | 297 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return bool|string false if image should not replaced, otherwise the location of the image |
309 | 309 | */ |
310 | 310 | public function replaceImagePath($app, $image) { |
311 | - if($app==='') { |
|
311 | + if ($app === '') { |
|
312 | 312 | $app = 'core'; |
313 | 313 | } |
314 | 314 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
@@ -320,19 +320,19 @@ discard block |
||
320 | 320 | } |
321 | 321 | |
322 | 322 | if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
323 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
323 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
324 | 324 | } |
325 | 325 | if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
326 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
326 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
327 | 327 | } |
328 | 328 | if ($image === 'manifest.json') { |
329 | 329 | try { |
330 | 330 | $appPath = $this->appManager->getAppPath($app); |
331 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
331 | + if (file_exists($appPath.'/img/manifest.json')) { |
|
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | } catch (AppPathNotFoundException $e) {} |
335 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
335 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest').'?v='.$cacheBusterValue; |
|
336 | 336 | } |
337 | 337 | return false; |
338 | 338 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | */ |
343 | 343 | private function increaseCacheBuster() { |
344 | 344 | $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
345 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
345 | + $this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1); |
|
346 | 346 | $this->cacheFactory->createDistributed('theming-')->clear(); |
347 | 347 | $this->cacheFactory->createDistributed('imagePath')->clear(); |
348 | 348 |
@@ -35,215 +35,215 @@ |
||
35 | 35 | |
36 | 36 | class Util { |
37 | 37 | |
38 | - /** @var IConfig */ |
|
39 | - private $config; |
|
40 | - |
|
41 | - /** @var IAppManager */ |
|
42 | - private $appManager; |
|
43 | - |
|
44 | - /** @var IAppData */ |
|
45 | - private $appData; |
|
46 | - |
|
47 | - /** |
|
48 | - * Util constructor. |
|
49 | - * |
|
50 | - * @param IConfig $config |
|
51 | - * @param IAppManager $appManager |
|
52 | - * @param IAppData $appData |
|
53 | - */ |
|
54 | - public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
55 | - $this->config = $config; |
|
56 | - $this->appManager = $appManager; |
|
57 | - $this->appData = $appData; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string $color rgb color value |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function invertTextColor($color) { |
|
65 | - $l = $this->calculateLuma($color); |
|
66 | - if($l>0.6) { |
|
67 | - return true; |
|
68 | - } else { |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * get color for on-page elements: |
|
75 | - * theme color by default, grey if theme color is to bright |
|
76 | - * @param $color |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function elementColor($color) { |
|
80 | - $l = $this->calculateLuminance($color); |
|
81 | - if($l>0.8) { |
|
82 | - return '#dddddd'; |
|
83 | - } |
|
84 | - return $color; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $color rgb color value |
|
89 | - * @return float |
|
90 | - */ |
|
91 | - public function calculateLuminance($color) { |
|
92 | - list($red, $green, $blue) = $this->hexToRGB($color); |
|
93 | - $compiler = new Compiler(); |
|
94 | - $hsl = $compiler->toHSL($red, $green, $blue); |
|
95 | - return $hsl[3]/100; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $color rgb color value |
|
100 | - * @return float |
|
101 | - */ |
|
102 | - public function calculateLuma($color) { |
|
103 | - list($red, $green, $blue) = $this->hexToRGB($color); |
|
104 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $color rgb color value |
|
109 | - * @return int[] |
|
110 | - */ |
|
111 | - public function hexToRGB($color) { |
|
112 | - $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
113 | - if (strlen($hex) === 3) { |
|
114 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
115 | - } |
|
116 | - if (strlen($hex) !== 6) { |
|
117 | - return 0; |
|
118 | - } |
|
119 | - return [ |
|
120 | - hexdec(substr($hex, 0, 2)), |
|
121 | - hexdec(substr($hex, 2, 2)), |
|
122 | - hexdec(substr($hex, 4, 2)) |
|
123 | - ]; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param $color |
|
128 | - * @return string base64 encoded radio button svg |
|
129 | - */ |
|
130 | - public function generateRadioButton($color) { |
|
131 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
132 | - '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
133 | - return base64_encode($radioButtonIcon); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param $app string app name |
|
139 | - * @return string|ISimpleFile path to app icon / file of logo |
|
140 | - */ |
|
141 | - public function getAppIcon($app) { |
|
142 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
143 | - try { |
|
144 | - $appPath = $this->appManager->getAppPath($app); |
|
145 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
146 | - if (file_exists($icon)) { |
|
147 | - return $icon; |
|
148 | - } |
|
149 | - $icon = $appPath . '/img/app.svg'; |
|
150 | - if (file_exists($icon)) { |
|
151 | - return $icon; |
|
152 | - } |
|
153 | - } catch (AppPathNotFoundException $e) {} |
|
154 | - |
|
155 | - if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
156 | - $logoFile = null; |
|
157 | - try { |
|
158 | - $folder = $this->appData->getFolder('images'); |
|
159 | - if ($folder !== null) { |
|
160 | - return $folder->getFile('logo'); |
|
161 | - } |
|
162 | - } catch (NotFoundException $e) {} |
|
163 | - } |
|
164 | - return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $app string app name |
|
169 | - * @param $image string relative path to image in app folder |
|
170 | - * @return string|false absolute path to image |
|
171 | - */ |
|
172 | - public function getAppImage($app, $image) { |
|
173 | - $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
174 | - $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
175 | - if ($app === "core") { |
|
176 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
177 | - if (file_exists($icon)) { |
|
178 | - return $icon; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - try { |
|
183 | - $appPath = $this->appManager->getAppPath($app); |
|
184 | - } catch (AppPathNotFoundException $e) { |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - $icon = $appPath . '/img/' . $image; |
|
189 | - if (file_exists($icon)) { |
|
190 | - return $icon; |
|
191 | - } |
|
192 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
193 | - if (file_exists($icon)) { |
|
194 | - return $icon; |
|
195 | - } |
|
196 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
197 | - if (file_exists($icon)) { |
|
198 | - return $icon; |
|
199 | - } |
|
200 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
201 | - if (file_exists($icon)) { |
|
202 | - return $icon; |
|
203 | - } |
|
204 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
205 | - if (file_exists($icon)) { |
|
206 | - return $icon; |
|
207 | - } |
|
208 | - |
|
209 | - return false; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * replace default color with a custom one |
|
214 | - * |
|
215 | - * @param $svg string content of a svg file |
|
216 | - * @param $color string color to match |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function colorizeSvg($svg, $color) { |
|
220 | - $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
221 | - return $svg; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Check if a custom theme is set in the server configuration |
|
226 | - * |
|
227 | - * @return bool |
|
228 | - */ |
|
229 | - public function isAlreadyThemed() { |
|
230 | - $theme = $this->config->getSystemValue('theme', ''); |
|
231 | - if ($theme !== '') { |
|
232 | - return true; |
|
233 | - } |
|
234 | - return false; |
|
235 | - } |
|
236 | - |
|
237 | - public function isBackgroundThemed() { |
|
238 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); |
|
239 | - |
|
240 | - $backgroundExists = true; |
|
241 | - try { |
|
242 | - $this->appData->getFolder('images')->getFile('background'); |
|
243 | - } catch (\Exception $e) { |
|
244 | - $backgroundExists = false; |
|
245 | - } |
|
246 | - return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists; |
|
247 | - } |
|
38 | + /** @var IConfig */ |
|
39 | + private $config; |
|
40 | + |
|
41 | + /** @var IAppManager */ |
|
42 | + private $appManager; |
|
43 | + |
|
44 | + /** @var IAppData */ |
|
45 | + private $appData; |
|
46 | + |
|
47 | + /** |
|
48 | + * Util constructor. |
|
49 | + * |
|
50 | + * @param IConfig $config |
|
51 | + * @param IAppManager $appManager |
|
52 | + * @param IAppData $appData |
|
53 | + */ |
|
54 | + public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
55 | + $this->config = $config; |
|
56 | + $this->appManager = $appManager; |
|
57 | + $this->appData = $appData; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string $color rgb color value |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function invertTextColor($color) { |
|
65 | + $l = $this->calculateLuma($color); |
|
66 | + if($l>0.6) { |
|
67 | + return true; |
|
68 | + } else { |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * get color for on-page elements: |
|
75 | + * theme color by default, grey if theme color is to bright |
|
76 | + * @param $color |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function elementColor($color) { |
|
80 | + $l = $this->calculateLuminance($color); |
|
81 | + if($l>0.8) { |
|
82 | + return '#dddddd'; |
|
83 | + } |
|
84 | + return $color; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $color rgb color value |
|
89 | + * @return float |
|
90 | + */ |
|
91 | + public function calculateLuminance($color) { |
|
92 | + list($red, $green, $blue) = $this->hexToRGB($color); |
|
93 | + $compiler = new Compiler(); |
|
94 | + $hsl = $compiler->toHSL($red, $green, $blue); |
|
95 | + return $hsl[3]/100; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $color rgb color value |
|
100 | + * @return float |
|
101 | + */ |
|
102 | + public function calculateLuma($color) { |
|
103 | + list($red, $green, $blue) = $this->hexToRGB($color); |
|
104 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $color rgb color value |
|
109 | + * @return int[] |
|
110 | + */ |
|
111 | + public function hexToRGB($color) { |
|
112 | + $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
|
113 | + if (strlen($hex) === 3) { |
|
114 | + $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
115 | + } |
|
116 | + if (strlen($hex) !== 6) { |
|
117 | + return 0; |
|
118 | + } |
|
119 | + return [ |
|
120 | + hexdec(substr($hex, 0, 2)), |
|
121 | + hexdec(substr($hex, 2, 2)), |
|
122 | + hexdec(substr($hex, 4, 2)) |
|
123 | + ]; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param $color |
|
128 | + * @return string base64 encoded radio button svg |
|
129 | + */ |
|
130 | + public function generateRadioButton($color) { |
|
131 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
132 | + '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
133 | + return base64_encode($radioButtonIcon); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param $app string app name |
|
139 | + * @return string|ISimpleFile path to app icon / file of logo |
|
140 | + */ |
|
141 | + public function getAppIcon($app) { |
|
142 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
143 | + try { |
|
144 | + $appPath = $this->appManager->getAppPath($app); |
|
145 | + $icon = $appPath . '/img/' . $app . '.svg'; |
|
146 | + if (file_exists($icon)) { |
|
147 | + return $icon; |
|
148 | + } |
|
149 | + $icon = $appPath . '/img/app.svg'; |
|
150 | + if (file_exists($icon)) { |
|
151 | + return $icon; |
|
152 | + } |
|
153 | + } catch (AppPathNotFoundException $e) {} |
|
154 | + |
|
155 | + if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
156 | + $logoFile = null; |
|
157 | + try { |
|
158 | + $folder = $this->appData->getFolder('images'); |
|
159 | + if ($folder !== null) { |
|
160 | + return $folder->getFile('logo'); |
|
161 | + } |
|
162 | + } catch (NotFoundException $e) {} |
|
163 | + } |
|
164 | + return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $app string app name |
|
169 | + * @param $image string relative path to image in app folder |
|
170 | + * @return string|false absolute path to image |
|
171 | + */ |
|
172 | + public function getAppImage($app, $image) { |
|
173 | + $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
174 | + $image = str_replace(array('\0', '\\', '..'), '', $image); |
|
175 | + if ($app === "core") { |
|
176 | + $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
177 | + if (file_exists($icon)) { |
|
178 | + return $icon; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + try { |
|
183 | + $appPath = $this->appManager->getAppPath($app); |
|
184 | + } catch (AppPathNotFoundException $e) { |
|
185 | + return false; |
|
186 | + } |
|
187 | + |
|
188 | + $icon = $appPath . '/img/' . $image; |
|
189 | + if (file_exists($icon)) { |
|
190 | + return $icon; |
|
191 | + } |
|
192 | + $icon = $appPath . '/img/' . $image . '.svg'; |
|
193 | + if (file_exists($icon)) { |
|
194 | + return $icon; |
|
195 | + } |
|
196 | + $icon = $appPath . '/img/' . $image . '.png'; |
|
197 | + if (file_exists($icon)) { |
|
198 | + return $icon; |
|
199 | + } |
|
200 | + $icon = $appPath . '/img/' . $image . '.gif'; |
|
201 | + if (file_exists($icon)) { |
|
202 | + return $icon; |
|
203 | + } |
|
204 | + $icon = $appPath . '/img/' . $image . '.jpg'; |
|
205 | + if (file_exists($icon)) { |
|
206 | + return $icon; |
|
207 | + } |
|
208 | + |
|
209 | + return false; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * replace default color with a custom one |
|
214 | + * |
|
215 | + * @param $svg string content of a svg file |
|
216 | + * @param $color string color to match |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function colorizeSvg($svg, $color) { |
|
220 | + $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
221 | + return $svg; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Check if a custom theme is set in the server configuration |
|
226 | + * |
|
227 | + * @return bool |
|
228 | + */ |
|
229 | + public function isAlreadyThemed() { |
|
230 | + $theme = $this->config->getSystemValue('theme', ''); |
|
231 | + if ($theme !== '') { |
|
232 | + return true; |
|
233 | + } |
|
234 | + return false; |
|
235 | + } |
|
236 | + |
|
237 | + public function isBackgroundThemed() { |
|
238 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); |
|
239 | + |
|
240 | + $backgroundExists = true; |
|
241 | + try { |
|
242 | + $this->appData->getFolder('images')->getFile('background'); |
|
243 | + } catch (\Exception $e) { |
|
244 | + $backgroundExists = false; |
|
245 | + } |
|
246 | + return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists; |
|
247 | + } |
|
248 | 248 | |
249 | 249 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function invertTextColor($color) { |
65 | 65 | $l = $this->calculateLuma($color); |
66 | - if($l>0.6) { |
|
66 | + if ($l > 0.6) { |
|
67 | 67 | return true; |
68 | 68 | } else { |
69 | 69 | return false; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function elementColor($color) { |
80 | 80 | $l = $this->calculateLuminance($color); |
81 | - if($l>0.8) { |
|
81 | + if ($l > 0.8) { |
|
82 | 82 | return '#dddddd'; |
83 | 83 | } |
84 | 84 | return $color; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | list($red, $green, $blue) = $this->hexToRGB($color); |
93 | 93 | $compiler = new Compiler(); |
94 | 94 | $hsl = $compiler->toHSL($red, $green, $blue); |
95 | - return $hsl[3]/100; |
|
95 | + return $hsl[3] / 100; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function calculateLuma($color) { |
103 | 103 | list($red, $green, $blue) = $this->hexToRGB($color); |
104 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
104 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | public function hexToRGB($color) { |
112 | 112 | $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color); |
113 | 113 | if (strlen($hex) === 3) { |
114 | - $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2}; |
|
114 | + $hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; |
|
115 | 115 | } |
116 | 116 | if (strlen($hex) !== 6) { |
117 | 117 | return 0; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return string base64 encoded radio button svg |
129 | 129 | */ |
130 | 130 | public function generateRadioButton($color) { |
131 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
131 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'. |
|
132 | 132 | '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
133 | 133 | return base64_encode($radioButtonIcon); |
134 | 134 | } |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
143 | 143 | try { |
144 | 144 | $appPath = $this->appManager->getAppPath($app); |
145 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
145 | + $icon = $appPath.'/img/'.$app.'.svg'; |
|
146 | 146 | if (file_exists($icon)) { |
147 | 147 | return $icon; |
148 | 148 | } |
149 | - $icon = $appPath . '/img/app.svg'; |
|
149 | + $icon = $appPath.'/img/app.svg'; |
|
150 | 150 | if (file_exists($icon)) { |
151 | 151 | return $icon; |
152 | 152 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | } |
162 | 162 | } catch (NotFoundException $e) {} |
163 | 163 | } |
164 | - return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
164 | + return \OC::$SERVERROOT.'/core/img/logo/logo.svg'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $app = str_replace(array('\0', '/', '\\', '..'), '', $app); |
174 | 174 | $image = str_replace(array('\0', '\\', '..'), '', $image); |
175 | 175 | if ($app === "core") { |
176 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
176 | + $icon = \OC::$SERVERROOT.'/core/img/'.$image; |
|
177 | 177 | if (file_exists($icon)) { |
178 | 178 | return $icon; |
179 | 179 | } |
@@ -185,23 +185,23 @@ discard block |
||
185 | 185 | return false; |
186 | 186 | } |
187 | 187 | |
188 | - $icon = $appPath . '/img/' . $image; |
|
188 | + $icon = $appPath.'/img/'.$image; |
|
189 | 189 | if (file_exists($icon)) { |
190 | 190 | return $icon; |
191 | 191 | } |
192 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
192 | + $icon = $appPath.'/img/'.$image.'.svg'; |
|
193 | 193 | if (file_exists($icon)) { |
194 | 194 | return $icon; |
195 | 195 | } |
196 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
196 | + $icon = $appPath.'/img/'.$image.'.png'; |
|
197 | 197 | if (file_exists($icon)) { |
198 | 198 | return $icon; |
199 | 199 | } |
200 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
200 | + $icon = $appPath.'/img/'.$image.'.gif'; |
|
201 | 201 | if (file_exists($icon)) { |
202 | 202 | return $icon; |
203 | 203 | } |
204 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
204 | + $icon = $appPath.'/img/'.$image.'.jpg'; |
|
205 | 205 | if (file_exists($icon)) { |
206 | 206 | return $icon; |
207 | 207 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | public function isBackgroundThemed() { |
238 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); |
|
238 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false); |
|
239 | 239 | |
240 | 240 | $backgroundExists = true; |
241 | 241 | try { |
@@ -36,211 +36,211 @@ |
||
36 | 36 | |
37 | 37 | class ImageManager { |
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
41 | - /** @var IAppData */ |
|
42 | - private $appData; |
|
43 | - /** @var IURLGenerator */ |
|
44 | - private $urlGenerator; |
|
45 | - /** @var array */ |
|
46 | - private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon']; |
|
47 | - /** @var ICacheFactory */ |
|
48 | - private $cacheFactory; |
|
49 | - /** @var ILogger */ |
|
50 | - private $logger; |
|
51 | - |
|
52 | - /** |
|
53 | - * ImageManager constructor. |
|
54 | - * |
|
55 | - * @param IConfig $config |
|
56 | - * @param IAppData $appData |
|
57 | - * @param IURLGenerator $urlGenerator |
|
58 | - * @param ICacheFactory $cacheFactory |
|
59 | - * @param ILogger $logger |
|
60 | - */ |
|
61 | - public function __construct(IConfig $config, |
|
62 | - IAppData $appData, |
|
63 | - IURLGenerator $urlGenerator, |
|
64 | - ICacheFactory $cacheFactory, |
|
65 | - ILogger $logger |
|
66 | - ) { |
|
67 | - $this->config = $config; |
|
68 | - $this->appData = $appData; |
|
69 | - $this->urlGenerator = $urlGenerator; |
|
70 | - $this->cacheFactory = $cacheFactory; |
|
71 | - $this->logger = $logger; |
|
72 | - } |
|
73 | - |
|
74 | - public function getImageUrl(string $key, bool $useSvg = true): string { |
|
75 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
76 | - try { |
|
77 | - $image = $this->getImage($key, $useSvg); |
|
78 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; |
|
79 | - } catch (NotFoundException $e) { |
|
80 | - } |
|
81 | - |
|
82 | - switch ($key) { |
|
83 | - case 'logo': |
|
84 | - case 'logoheader': |
|
85 | - case 'favicon': |
|
86 | - return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; |
|
87 | - case 'background': |
|
88 | - return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { |
|
93 | - return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key, $useSvg)); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $key |
|
98 | - * @param bool $useSvg |
|
99 | - * @return ISimpleFile |
|
100 | - * @throws NotFoundException |
|
101 | - * @throws NotPermittedException |
|
102 | - */ |
|
103 | - public function getImage(string $key, bool $useSvg = true): ISimpleFile { |
|
104 | - $pngFile = null; |
|
105 | - $logo = $this->config->getAppValue('theming', $key . 'Mime', false); |
|
106 | - $folder = $this->appData->getFolder('images'); |
|
107 | - if ($logo === false || !$folder->fileExists($key)) { |
|
108 | - throw new NotFoundException(); |
|
109 | - } |
|
110 | - if (!$useSvg && $this->shouldReplaceIcons()) { |
|
111 | - if (!$folder->fileExists($key . '.png')) { |
|
112 | - try { |
|
113 | - $finalIconFile = new \Imagick(); |
|
114 | - $finalIconFile->setBackgroundColor('none'); |
|
115 | - $finalIconFile->readImageBlob($folder->getFile($key)->getContent()); |
|
116 | - $finalIconFile->setImageFormat('png32'); |
|
117 | - $pngFile = $folder->newFile($key . '.png'); |
|
118 | - $pngFile->putContent($finalIconFile->getImageBlob()); |
|
119 | - } catch (\ImagickException $e) { |
|
120 | - $this->logger->info('The image was requested to be no SVG file, but converting it to PNG failed: ' . $e->getMessage()); |
|
121 | - $pngFile = null; |
|
122 | - } |
|
123 | - } else { |
|
124 | - $pngFile = $folder->getFile($key . '.png'); |
|
125 | - } |
|
126 | - } |
|
127 | - if ($pngFile !== null) { |
|
128 | - return $pngFile; |
|
129 | - } |
|
130 | - return $folder->getFile($key); |
|
131 | - } |
|
132 | - |
|
133 | - public function getCustomImages(): array { |
|
134 | - $images = []; |
|
135 | - foreach ($this->supportedImageKeys as $key) { |
|
136 | - $images[$key] = [ |
|
137 | - 'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''), |
|
138 | - 'url' => $this->getImageUrl($key), |
|
139 | - ]; |
|
140 | - } |
|
141 | - return $images; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Get folder for current theming files |
|
146 | - * |
|
147 | - * @return ISimpleFolder |
|
148 | - * @throws NotPermittedException |
|
149 | - */ |
|
150 | - public function getCacheFolder(): ISimpleFolder { |
|
151 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
152 | - try { |
|
153 | - $folder = $this->appData->getFolder($cacheBusterValue); |
|
154 | - } catch (NotFoundException $e) { |
|
155 | - $folder = $this->appData->newFolder($cacheBusterValue); |
|
156 | - $this->cleanup(); |
|
157 | - } |
|
158 | - return $folder; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Get a file from AppData |
|
163 | - * |
|
164 | - * @param string $filename |
|
165 | - * @throws NotFoundException |
|
166 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
167 | - * @throws NotPermittedException |
|
168 | - */ |
|
169 | - public function getCachedImage(string $filename): ISimpleFile { |
|
170 | - $currentFolder = $this->getCacheFolder(); |
|
171 | - return $currentFolder->getFile($filename); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Store a file for theming in AppData |
|
176 | - * |
|
177 | - * @param string $filename |
|
178 | - * @param string $data |
|
179 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
180 | - * @throws NotFoundException |
|
181 | - * @throws NotPermittedException |
|
182 | - */ |
|
183 | - public function setCachedImage(string $filename, string $data): ISimpleFile { |
|
184 | - $currentFolder = $this->getCacheFolder(); |
|
185 | - if ($currentFolder->fileExists($filename)) { |
|
186 | - $file = $currentFolder->getFile($filename); |
|
187 | - } else { |
|
188 | - $file = $currentFolder->newFile($filename); |
|
189 | - } |
|
190 | - $file->putContent($data); |
|
191 | - return $file; |
|
192 | - } |
|
193 | - |
|
194 | - public function delete(string $key) { |
|
195 | - /* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */ |
|
196 | - try { |
|
197 | - $file = $this->appData->getFolder('images')->getFile($key); |
|
198 | - $file->delete(); |
|
199 | - } catch (NotFoundException $e) { |
|
200 | - } catch (NotPermittedException $e) { |
|
201 | - } |
|
202 | - try { |
|
203 | - $file = $this->appData->getFolder('images')->getFile($key . '.png'); |
|
204 | - $file->delete(); |
|
205 | - } catch (NotFoundException $e) { |
|
206 | - } catch (NotPermittedException $e) { |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * remove cached files that are not required any longer |
|
212 | - * |
|
213 | - * @throws NotPermittedException |
|
214 | - * @throws NotFoundException |
|
215 | - */ |
|
216 | - public function cleanup() { |
|
217 | - $currentFolder = $this->getCacheFolder(); |
|
218 | - $folders = $this->appData->getDirectoryListing(); |
|
219 | - foreach ($folders as $folder) { |
|
220 | - if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
221 | - $folder->delete(); |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Check if Imagemagick is enabled and if SVG is supported |
|
228 | - * otherwise we can't render custom icons |
|
229 | - * |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public function shouldReplaceIcons() { |
|
233 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
234 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
235 | - return (bool)$value; |
|
236 | - } |
|
237 | - $value = false; |
|
238 | - if(extension_loaded('imagick')) { |
|
239 | - if (count(\Imagick::queryFormats('SVG')) >= 1) { |
|
240 | - $value = true; |
|
241 | - } |
|
242 | - } |
|
243 | - $cache->set('shouldReplaceIcons', $value); |
|
244 | - return $value; |
|
245 | - } |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | + /** @var IAppData */ |
|
42 | + private $appData; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + private $urlGenerator; |
|
45 | + /** @var array */ |
|
46 | + private $supportedImageKeys = ['background', 'logo', 'logoheader', 'favicon']; |
|
47 | + /** @var ICacheFactory */ |
|
48 | + private $cacheFactory; |
|
49 | + /** @var ILogger */ |
|
50 | + private $logger; |
|
51 | + |
|
52 | + /** |
|
53 | + * ImageManager constructor. |
|
54 | + * |
|
55 | + * @param IConfig $config |
|
56 | + * @param IAppData $appData |
|
57 | + * @param IURLGenerator $urlGenerator |
|
58 | + * @param ICacheFactory $cacheFactory |
|
59 | + * @param ILogger $logger |
|
60 | + */ |
|
61 | + public function __construct(IConfig $config, |
|
62 | + IAppData $appData, |
|
63 | + IURLGenerator $urlGenerator, |
|
64 | + ICacheFactory $cacheFactory, |
|
65 | + ILogger $logger |
|
66 | + ) { |
|
67 | + $this->config = $config; |
|
68 | + $this->appData = $appData; |
|
69 | + $this->urlGenerator = $urlGenerator; |
|
70 | + $this->cacheFactory = $cacheFactory; |
|
71 | + $this->logger = $logger; |
|
72 | + } |
|
73 | + |
|
74 | + public function getImageUrl(string $key, bool $useSvg = true): string { |
|
75 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
76 | + try { |
|
77 | + $image = $this->getImage($key, $useSvg); |
|
78 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; |
|
79 | + } catch (NotFoundException $e) { |
|
80 | + } |
|
81 | + |
|
82 | + switch ($key) { |
|
83 | + case 'logo': |
|
84 | + case 'logoheader': |
|
85 | + case 'favicon': |
|
86 | + return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; |
|
87 | + case 'background': |
|
88 | + return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + public function getImageUrlAbsolute(string $key, bool $useSvg = true): string { |
|
93 | + return $this->urlGenerator->getAbsoluteURL($this->getImageUrl($key, $useSvg)); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $key |
|
98 | + * @param bool $useSvg |
|
99 | + * @return ISimpleFile |
|
100 | + * @throws NotFoundException |
|
101 | + * @throws NotPermittedException |
|
102 | + */ |
|
103 | + public function getImage(string $key, bool $useSvg = true): ISimpleFile { |
|
104 | + $pngFile = null; |
|
105 | + $logo = $this->config->getAppValue('theming', $key . 'Mime', false); |
|
106 | + $folder = $this->appData->getFolder('images'); |
|
107 | + if ($logo === false || !$folder->fileExists($key)) { |
|
108 | + throw new NotFoundException(); |
|
109 | + } |
|
110 | + if (!$useSvg && $this->shouldReplaceIcons()) { |
|
111 | + if (!$folder->fileExists($key . '.png')) { |
|
112 | + try { |
|
113 | + $finalIconFile = new \Imagick(); |
|
114 | + $finalIconFile->setBackgroundColor('none'); |
|
115 | + $finalIconFile->readImageBlob($folder->getFile($key)->getContent()); |
|
116 | + $finalIconFile->setImageFormat('png32'); |
|
117 | + $pngFile = $folder->newFile($key . '.png'); |
|
118 | + $pngFile->putContent($finalIconFile->getImageBlob()); |
|
119 | + } catch (\ImagickException $e) { |
|
120 | + $this->logger->info('The image was requested to be no SVG file, but converting it to PNG failed: ' . $e->getMessage()); |
|
121 | + $pngFile = null; |
|
122 | + } |
|
123 | + } else { |
|
124 | + $pngFile = $folder->getFile($key . '.png'); |
|
125 | + } |
|
126 | + } |
|
127 | + if ($pngFile !== null) { |
|
128 | + return $pngFile; |
|
129 | + } |
|
130 | + return $folder->getFile($key); |
|
131 | + } |
|
132 | + |
|
133 | + public function getCustomImages(): array { |
|
134 | + $images = []; |
|
135 | + foreach ($this->supportedImageKeys as $key) { |
|
136 | + $images[$key] = [ |
|
137 | + 'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''), |
|
138 | + 'url' => $this->getImageUrl($key), |
|
139 | + ]; |
|
140 | + } |
|
141 | + return $images; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Get folder for current theming files |
|
146 | + * |
|
147 | + * @return ISimpleFolder |
|
148 | + * @throws NotPermittedException |
|
149 | + */ |
|
150 | + public function getCacheFolder(): ISimpleFolder { |
|
151 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
152 | + try { |
|
153 | + $folder = $this->appData->getFolder($cacheBusterValue); |
|
154 | + } catch (NotFoundException $e) { |
|
155 | + $folder = $this->appData->newFolder($cacheBusterValue); |
|
156 | + $this->cleanup(); |
|
157 | + } |
|
158 | + return $folder; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Get a file from AppData |
|
163 | + * |
|
164 | + * @param string $filename |
|
165 | + * @throws NotFoundException |
|
166 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
167 | + * @throws NotPermittedException |
|
168 | + */ |
|
169 | + public function getCachedImage(string $filename): ISimpleFile { |
|
170 | + $currentFolder = $this->getCacheFolder(); |
|
171 | + return $currentFolder->getFile($filename); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Store a file for theming in AppData |
|
176 | + * |
|
177 | + * @param string $filename |
|
178 | + * @param string $data |
|
179 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
180 | + * @throws NotFoundException |
|
181 | + * @throws NotPermittedException |
|
182 | + */ |
|
183 | + public function setCachedImage(string $filename, string $data): ISimpleFile { |
|
184 | + $currentFolder = $this->getCacheFolder(); |
|
185 | + if ($currentFolder->fileExists($filename)) { |
|
186 | + $file = $currentFolder->getFile($filename); |
|
187 | + } else { |
|
188 | + $file = $currentFolder->newFile($filename); |
|
189 | + } |
|
190 | + $file->putContent($data); |
|
191 | + return $file; |
|
192 | + } |
|
193 | + |
|
194 | + public function delete(string $key) { |
|
195 | + /* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */ |
|
196 | + try { |
|
197 | + $file = $this->appData->getFolder('images')->getFile($key); |
|
198 | + $file->delete(); |
|
199 | + } catch (NotFoundException $e) { |
|
200 | + } catch (NotPermittedException $e) { |
|
201 | + } |
|
202 | + try { |
|
203 | + $file = $this->appData->getFolder('images')->getFile($key . '.png'); |
|
204 | + $file->delete(); |
|
205 | + } catch (NotFoundException $e) { |
|
206 | + } catch (NotPermittedException $e) { |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * remove cached files that are not required any longer |
|
212 | + * |
|
213 | + * @throws NotPermittedException |
|
214 | + * @throws NotFoundException |
|
215 | + */ |
|
216 | + public function cleanup() { |
|
217 | + $currentFolder = $this->getCacheFolder(); |
|
218 | + $folders = $this->appData->getDirectoryListing(); |
|
219 | + foreach ($folders as $folder) { |
|
220 | + if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
221 | + $folder->delete(); |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Check if Imagemagick is enabled and if SVG is supported |
|
228 | + * otherwise we can't render custom icons |
|
229 | + * |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public function shouldReplaceIcons() { |
|
233 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
234 | + if($value = $cache->get('shouldReplaceIcons')) { |
|
235 | + return (bool)$value; |
|
236 | + } |
|
237 | + $value = false; |
|
238 | + if(extension_loaded('imagick')) { |
|
239 | + if (count(\Imagick::queryFormats('SVG')) >= 1) { |
|
240 | + $value = true; |
|
241 | + } |
|
242 | + } |
|
243 | + $cache->set('shouldReplaceIcons', $value); |
|
244 | + return $value; |
|
245 | + } |
|
246 | 246 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
76 | 76 | try { |
77 | 77 | $image = $this->getImage($key, $useSvg); |
78 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter; |
|
78 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', ['key' => $key]).'?v='.$cacheBusterCounter; |
|
79 | 79 | } catch (NotFoundException $e) { |
80 | 80 | } |
81 | 81 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | case 'logo': |
84 | 84 | case 'logoheader': |
85 | 85 | case 'favicon': |
86 | - return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; |
|
86 | + return $this->urlGenerator->imagePath('core', 'logo/logo.png').'?v='.$cacheBusterCounter; |
|
87 | 87 | case 'background': |
88 | - return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter; |
|
88 | + return $this->urlGenerator->imagePath('core', 'background.png').'?v='.$cacheBusterCounter; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -102,26 +102,26 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function getImage(string $key, bool $useSvg = true): ISimpleFile { |
104 | 104 | $pngFile = null; |
105 | - $logo = $this->config->getAppValue('theming', $key . 'Mime', false); |
|
105 | + $logo = $this->config->getAppValue('theming', $key.'Mime', false); |
|
106 | 106 | $folder = $this->appData->getFolder('images'); |
107 | 107 | if ($logo === false || !$folder->fileExists($key)) { |
108 | 108 | throw new NotFoundException(); |
109 | 109 | } |
110 | 110 | if (!$useSvg && $this->shouldReplaceIcons()) { |
111 | - if (!$folder->fileExists($key . '.png')) { |
|
111 | + if (!$folder->fileExists($key.'.png')) { |
|
112 | 112 | try { |
113 | 113 | $finalIconFile = new \Imagick(); |
114 | 114 | $finalIconFile->setBackgroundColor('none'); |
115 | 115 | $finalIconFile->readImageBlob($folder->getFile($key)->getContent()); |
116 | 116 | $finalIconFile->setImageFormat('png32'); |
117 | - $pngFile = $folder->newFile($key . '.png'); |
|
117 | + $pngFile = $folder->newFile($key.'.png'); |
|
118 | 118 | $pngFile->putContent($finalIconFile->getImageBlob()); |
119 | 119 | } catch (\ImagickException $e) { |
120 | - $this->logger->info('The image was requested to be no SVG file, but converting it to PNG failed: ' . $e->getMessage()); |
|
120 | + $this->logger->info('The image was requested to be no SVG file, but converting it to PNG failed: '.$e->getMessage()); |
|
121 | 121 | $pngFile = null; |
122 | 122 | } |
123 | 123 | } else { |
124 | - $pngFile = $folder->getFile($key . '.png'); |
|
124 | + $pngFile = $folder->getFile($key.'.png'); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | if ($pngFile !== null) { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $images = []; |
135 | 135 | foreach ($this->supportedImageKeys as $key) { |
136 | 136 | $images[$key] = [ |
137 | - 'mime' => $this->config->getAppValue('theming', $key . 'Mime', ''), |
|
137 | + 'mime' => $this->config->getAppValue('theming', $key.'Mime', ''), |
|
138 | 138 | 'url' => $this->getImageUrl($key), |
139 | 139 | ]; |
140 | 140 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } catch (NotPermittedException $e) { |
201 | 201 | } |
202 | 202 | try { |
203 | - $file = $this->appData->getFolder('images')->getFile($key . '.png'); |
|
203 | + $file = $this->appData->getFolder('images')->getFile($key.'.png'); |
|
204 | 204 | $file->delete(); |
205 | 205 | } catch (NotFoundException $e) { |
206 | 206 | } catch (NotPermittedException $e) { |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | * @return bool |
231 | 231 | */ |
232 | 232 | public function shouldReplaceIcons() { |
233 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
234 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
235 | - return (bool)$value; |
|
233 | + $cache = $this->cacheFactory->createDistributed('theming-'.$this->urlGenerator->getBaseUrl()); |
|
234 | + if ($value = $cache->get('shouldReplaceIcons')) { |
|
235 | + return (bool) $value; |
|
236 | 236 | } |
237 | 237 | $value = false; |
238 | - if(extension_loaded('imagick')) { |
|
238 | + if (extension_loaded('imagick')) { |
|
239 | 239 | if (count(\Imagick::queryFormats('SVG')) >= 1) { |
240 | 240 | $value = true; |
241 | 241 | } |
@@ -35,297 +35,297 @@ |
||
35 | 35 | */ |
36 | 36 | class OC_Defaults { |
37 | 37 | |
38 | - private $theme; |
|
39 | - private $l; |
|
38 | + private $theme; |
|
39 | + private $l; |
|
40 | 40 | |
41 | - private $defaultEntity; |
|
42 | - private $defaultName; |
|
43 | - private $defaultTitle; |
|
44 | - private $defaultBaseUrl; |
|
45 | - private $defaultSyncClientUrl; |
|
46 | - private $defaultiOSClientUrl; |
|
47 | - private $defaultiTunesAppId; |
|
48 | - private $defaultAndroidClientUrl; |
|
49 | - private $defaultDocBaseUrl; |
|
50 | - private $defaultDocVersion; |
|
51 | - private $defaultSlogan; |
|
52 | - private $defaultColorPrimary; |
|
53 | - private $defaultTextColorPrimary; |
|
41 | + private $defaultEntity; |
|
42 | + private $defaultName; |
|
43 | + private $defaultTitle; |
|
44 | + private $defaultBaseUrl; |
|
45 | + private $defaultSyncClientUrl; |
|
46 | + private $defaultiOSClientUrl; |
|
47 | + private $defaultiTunesAppId; |
|
48 | + private $defaultAndroidClientUrl; |
|
49 | + private $defaultDocBaseUrl; |
|
50 | + private $defaultDocVersion; |
|
51 | + private $defaultSlogan; |
|
52 | + private $defaultColorPrimary; |
|
53 | + private $defaultTextColorPrimary; |
|
54 | 54 | |
55 | - public function __construct() { |
|
56 | - $this->l = \OC::$server->getL10N('lib'); |
|
57 | - $config = \OC::$server->getConfig(); |
|
55 | + public function __construct() { |
|
56 | + $this->l = \OC::$server->getL10N('lib'); |
|
57 | + $config = \OC::$server->getConfig(); |
|
58 | 58 | |
59 | - $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ |
|
60 | - $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ |
|
61 | - $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ |
|
62 | - $this->defaultBaseUrl = 'https://nextcloud.com'; |
|
63 | - $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
64 | - $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); |
|
65 | - $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); |
|
66 | - $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); |
|
67 | - $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; |
|
68 | - $this->defaultDocVersion = '14'; // used to generate doc links |
|
69 | - $this->defaultSlogan = $this->l->t('a safe home for all your data'); |
|
70 | - $this->defaultColorPrimary = '#0082c9'; |
|
71 | - $this->defaultTextColorPrimary = '#ffffff'; |
|
59 | + $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ |
|
60 | + $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ |
|
61 | + $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ |
|
62 | + $this->defaultBaseUrl = 'https://nextcloud.com'; |
|
63 | + $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
|
64 | + $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); |
|
65 | + $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); |
|
66 | + $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); |
|
67 | + $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; |
|
68 | + $this->defaultDocVersion = '14'; // used to generate doc links |
|
69 | + $this->defaultSlogan = $this->l->t('a safe home for all your data'); |
|
70 | + $this->defaultColorPrimary = '#0082c9'; |
|
71 | + $this->defaultTextColorPrimary = '#ffffff'; |
|
72 | 72 | |
73 | - $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
|
74 | - if (file_exists($themePath)) { |
|
75 | - // prevent defaults.php from printing output |
|
76 | - ob_start(); |
|
77 | - require_once $themePath; |
|
78 | - ob_end_clean(); |
|
79 | - if (class_exists('OC_Theme')) { |
|
80 | - $this->theme = new OC_Theme(); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
73 | + $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
|
74 | + if (file_exists($themePath)) { |
|
75 | + // prevent defaults.php from printing output |
|
76 | + ob_start(); |
|
77 | + require_once $themePath; |
|
78 | + ob_end_clean(); |
|
79 | + if (class_exists('OC_Theme')) { |
|
80 | + $this->theme = new OC_Theme(); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $method |
|
87 | - */ |
|
88 | - private function themeExist($method) { |
|
89 | - if (isset($this->theme) && method_exists($this->theme, $method)) { |
|
90 | - return true; |
|
91 | - } |
|
92 | - return false; |
|
93 | - } |
|
85 | + /** |
|
86 | + * @param string $method |
|
87 | + */ |
|
88 | + private function themeExist($method) { |
|
89 | + if (isset($this->theme) && method_exists($this->theme, $method)) { |
|
90 | + return true; |
|
91 | + } |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Returns the base URL |
|
97 | - * @return string URL |
|
98 | - */ |
|
99 | - public function getBaseUrl() { |
|
100 | - if ($this->themeExist('getBaseUrl')) { |
|
101 | - return $this->theme->getBaseUrl(); |
|
102 | - } else { |
|
103 | - return $this->defaultBaseUrl; |
|
104 | - } |
|
105 | - } |
|
95 | + /** |
|
96 | + * Returns the base URL |
|
97 | + * @return string URL |
|
98 | + */ |
|
99 | + public function getBaseUrl() { |
|
100 | + if ($this->themeExist('getBaseUrl')) { |
|
101 | + return $this->theme->getBaseUrl(); |
|
102 | + } else { |
|
103 | + return $this->defaultBaseUrl; |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Returns the URL where the sync clients are listed |
|
109 | - * @return string URL |
|
110 | - */ |
|
111 | - public function getSyncClientUrl() { |
|
112 | - if ($this->themeExist('getSyncClientUrl')) { |
|
113 | - return $this->theme->getSyncClientUrl(); |
|
114 | - } else { |
|
115 | - return $this->defaultSyncClientUrl; |
|
116 | - } |
|
117 | - } |
|
107 | + /** |
|
108 | + * Returns the URL where the sync clients are listed |
|
109 | + * @return string URL |
|
110 | + */ |
|
111 | + public function getSyncClientUrl() { |
|
112 | + if ($this->themeExist('getSyncClientUrl')) { |
|
113 | + return $this->theme->getSyncClientUrl(); |
|
114 | + } else { |
|
115 | + return $this->defaultSyncClientUrl; |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Returns the URL to the App Store for the iOS Client |
|
121 | - * @return string URL |
|
122 | - */ |
|
123 | - public function getiOSClientUrl() { |
|
124 | - if ($this->themeExist('getiOSClientUrl')) { |
|
125 | - return $this->theme->getiOSClientUrl(); |
|
126 | - } else { |
|
127 | - return $this->defaultiOSClientUrl; |
|
128 | - } |
|
129 | - } |
|
119 | + /** |
|
120 | + * Returns the URL to the App Store for the iOS Client |
|
121 | + * @return string URL |
|
122 | + */ |
|
123 | + public function getiOSClientUrl() { |
|
124 | + if ($this->themeExist('getiOSClientUrl')) { |
|
125 | + return $this->theme->getiOSClientUrl(); |
|
126 | + } else { |
|
127 | + return $this->defaultiOSClientUrl; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Returns the AppId for the App Store for the iOS Client |
|
133 | - * @return string AppId |
|
134 | - */ |
|
135 | - public function getiTunesAppId() { |
|
136 | - if ($this->themeExist('getiTunesAppId')) { |
|
137 | - return $this->theme->getiTunesAppId(); |
|
138 | - } else { |
|
139 | - return $this->defaultiTunesAppId; |
|
140 | - } |
|
141 | - } |
|
131 | + /** |
|
132 | + * Returns the AppId for the App Store for the iOS Client |
|
133 | + * @return string AppId |
|
134 | + */ |
|
135 | + public function getiTunesAppId() { |
|
136 | + if ($this->themeExist('getiTunesAppId')) { |
|
137 | + return $this->theme->getiTunesAppId(); |
|
138 | + } else { |
|
139 | + return $this->defaultiTunesAppId; |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Returns the URL to Google Play for the Android Client |
|
145 | - * @return string URL |
|
146 | - */ |
|
147 | - public function getAndroidClientUrl() { |
|
148 | - if ($this->themeExist('getAndroidClientUrl')) { |
|
149 | - return $this->theme->getAndroidClientUrl(); |
|
150 | - } else { |
|
151 | - return $this->defaultAndroidClientUrl; |
|
152 | - } |
|
153 | - } |
|
143 | + /** |
|
144 | + * Returns the URL to Google Play for the Android Client |
|
145 | + * @return string URL |
|
146 | + */ |
|
147 | + public function getAndroidClientUrl() { |
|
148 | + if ($this->themeExist('getAndroidClientUrl')) { |
|
149 | + return $this->theme->getAndroidClientUrl(); |
|
150 | + } else { |
|
151 | + return $this->defaultAndroidClientUrl; |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Returns the documentation URL |
|
157 | - * @return string URL |
|
158 | - */ |
|
159 | - public function getDocBaseUrl() { |
|
160 | - if ($this->themeExist('getDocBaseUrl')) { |
|
161 | - return $this->theme->getDocBaseUrl(); |
|
162 | - } else { |
|
163 | - return $this->defaultDocBaseUrl; |
|
164 | - } |
|
165 | - } |
|
155 | + /** |
|
156 | + * Returns the documentation URL |
|
157 | + * @return string URL |
|
158 | + */ |
|
159 | + public function getDocBaseUrl() { |
|
160 | + if ($this->themeExist('getDocBaseUrl')) { |
|
161 | + return $this->theme->getDocBaseUrl(); |
|
162 | + } else { |
|
163 | + return $this->defaultDocBaseUrl; |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Returns the title |
|
169 | - * @return string title |
|
170 | - */ |
|
171 | - public function getTitle() { |
|
172 | - if ($this->themeExist('getTitle')) { |
|
173 | - return $this->theme->getTitle(); |
|
174 | - } else { |
|
175 | - return $this->defaultTitle; |
|
176 | - } |
|
177 | - } |
|
167 | + /** |
|
168 | + * Returns the title |
|
169 | + * @return string title |
|
170 | + */ |
|
171 | + public function getTitle() { |
|
172 | + if ($this->themeExist('getTitle')) { |
|
173 | + return $this->theme->getTitle(); |
|
174 | + } else { |
|
175 | + return $this->defaultTitle; |
|
176 | + } |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Returns the short name of the software |
|
181 | - * @return string title |
|
182 | - */ |
|
183 | - public function getName() { |
|
184 | - if ($this->themeExist('getName')) { |
|
185 | - return $this->theme->getName(); |
|
186 | - } else { |
|
187 | - return $this->defaultName; |
|
188 | - } |
|
189 | - } |
|
179 | + /** |
|
180 | + * Returns the short name of the software |
|
181 | + * @return string title |
|
182 | + */ |
|
183 | + public function getName() { |
|
184 | + if ($this->themeExist('getName')) { |
|
185 | + return $this->theme->getName(); |
|
186 | + } else { |
|
187 | + return $this->defaultName; |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Returns the short name of the software containing HTML strings |
|
193 | - * @return string title |
|
194 | - */ |
|
195 | - public function getHTMLName() { |
|
196 | - if ($this->themeExist('getHTMLName')) { |
|
197 | - return $this->theme->getHTMLName(); |
|
198 | - } else { |
|
199 | - return $this->defaultName; |
|
200 | - } |
|
201 | - } |
|
191 | + /** |
|
192 | + * Returns the short name of the software containing HTML strings |
|
193 | + * @return string title |
|
194 | + */ |
|
195 | + public function getHTMLName() { |
|
196 | + if ($this->themeExist('getHTMLName')) { |
|
197 | + return $this->theme->getHTMLName(); |
|
198 | + } else { |
|
199 | + return $this->defaultName; |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Returns entity (e.g. company name) - used for footer, copyright |
|
205 | - * @return string entity name |
|
206 | - */ |
|
207 | - public function getEntity() { |
|
208 | - if ($this->themeExist('getEntity')) { |
|
209 | - return $this->theme->getEntity(); |
|
210 | - } else { |
|
211 | - return $this->defaultEntity; |
|
212 | - } |
|
213 | - } |
|
203 | + /** |
|
204 | + * Returns entity (e.g. company name) - used for footer, copyright |
|
205 | + * @return string entity name |
|
206 | + */ |
|
207 | + public function getEntity() { |
|
208 | + if ($this->themeExist('getEntity')) { |
|
209 | + return $this->theme->getEntity(); |
|
210 | + } else { |
|
211 | + return $this->defaultEntity; |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Returns slogan |
|
217 | - * @return string slogan |
|
218 | - */ |
|
219 | - public function getSlogan() { |
|
220 | - if ($this->themeExist('getSlogan')) { |
|
221 | - return $this->theme->getSlogan(); |
|
222 | - } else { |
|
223 | - return $this->defaultSlogan; |
|
224 | - } |
|
225 | - } |
|
215 | + /** |
|
216 | + * Returns slogan |
|
217 | + * @return string slogan |
|
218 | + */ |
|
219 | + public function getSlogan() { |
|
220 | + if ($this->themeExist('getSlogan')) { |
|
221 | + return $this->theme->getSlogan(); |
|
222 | + } else { |
|
223 | + return $this->defaultSlogan; |
|
224 | + } |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Returns logo claim |
|
229 | - * @return string logo claim |
|
230 | - * @deprecated 13.0.0 |
|
231 | - */ |
|
232 | - public function getLogoClaim() { |
|
233 | - return ''; |
|
234 | - } |
|
227 | + /** |
|
228 | + * Returns logo claim |
|
229 | + * @return string logo claim |
|
230 | + * @deprecated 13.0.0 |
|
231 | + */ |
|
232 | + public function getLogoClaim() { |
|
233 | + return ''; |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Returns short version of the footer |
|
238 | - * @return string short footer |
|
239 | - */ |
|
240 | - public function getShortFooter() { |
|
241 | - if ($this->themeExist('getShortFooter')) { |
|
242 | - $footer = $this->theme->getShortFooter(); |
|
243 | - } else { |
|
244 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
245 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
246 | - ' – ' . $this->getSlogan(); |
|
247 | - } |
|
236 | + /** |
|
237 | + * Returns short version of the footer |
|
238 | + * @return string short footer |
|
239 | + */ |
|
240 | + public function getShortFooter() { |
|
241 | + if ($this->themeExist('getShortFooter')) { |
|
242 | + $footer = $this->theme->getShortFooter(); |
|
243 | + } else { |
|
244 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
245 | + ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
246 | + ' – ' . $this->getSlogan(); |
|
247 | + } |
|
248 | 248 | |
249 | - return $footer; |
|
250 | - } |
|
249 | + return $footer; |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Returns long version of the footer |
|
254 | - * @return string long footer |
|
255 | - */ |
|
256 | - public function getLongFooter() { |
|
257 | - if ($this->themeExist('getLongFooter')) { |
|
258 | - $footer = $this->theme->getLongFooter(); |
|
259 | - } else { |
|
260 | - $footer = $this->getShortFooter(); |
|
261 | - } |
|
252 | + /** |
|
253 | + * Returns long version of the footer |
|
254 | + * @return string long footer |
|
255 | + */ |
|
256 | + public function getLongFooter() { |
|
257 | + if ($this->themeExist('getLongFooter')) { |
|
258 | + $footer = $this->theme->getLongFooter(); |
|
259 | + } else { |
|
260 | + $footer = $this->getShortFooter(); |
|
261 | + } |
|
262 | 262 | |
263 | - return $footer; |
|
264 | - } |
|
263 | + return $footer; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * @param string $key |
|
268 | - * @return string URL to doc with key |
|
269 | - */ |
|
270 | - public function buildDocLinkToKey($key) { |
|
271 | - if ($this->themeExist('buildDocLinkToKey')) { |
|
272 | - return $this->theme->buildDocLinkToKey($key); |
|
273 | - } |
|
274 | - return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
|
275 | - } |
|
266 | + /** |
|
267 | + * @param string $key |
|
268 | + * @return string URL to doc with key |
|
269 | + */ |
|
270 | + public function buildDocLinkToKey($key) { |
|
271 | + if ($this->themeExist('buildDocLinkToKey')) { |
|
272 | + return $this->theme->buildDocLinkToKey($key); |
|
273 | + } |
|
274 | + return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Returns primary color |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - public function getColorPrimary() { |
|
277 | + /** |
|
278 | + * Returns primary color |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + public function getColorPrimary() { |
|
282 | 282 | |
283 | - if ($this->themeExist('getColorPrimary')) { |
|
284 | - return $this->theme->getColorPrimary(); |
|
285 | - } |
|
286 | - if ($this->themeExist('getMailHeaderColor')) { |
|
287 | - return $this->theme->getMailHeaderColor(); |
|
288 | - } |
|
289 | - return $this->defaultColorPrimary; |
|
290 | - } |
|
283 | + if ($this->themeExist('getColorPrimary')) { |
|
284 | + return $this->theme->getColorPrimary(); |
|
285 | + } |
|
286 | + if ($this->themeExist('getMailHeaderColor')) { |
|
287 | + return $this->theme->getMailHeaderColor(); |
|
288 | + } |
|
289 | + return $this->defaultColorPrimary; |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * @return array scss variables to overwrite |
|
294 | - */ |
|
295 | - public function getScssVariables() { |
|
296 | - if($this->themeExist('getScssVariables')) { |
|
297 | - return $this->theme->getScssVariables(); |
|
298 | - } |
|
299 | - return []; |
|
300 | - } |
|
292 | + /** |
|
293 | + * @return array scss variables to overwrite |
|
294 | + */ |
|
295 | + public function getScssVariables() { |
|
296 | + if($this->themeExist('getScssVariables')) { |
|
297 | + return $this->theme->getScssVariables(); |
|
298 | + } |
|
299 | + return []; |
|
300 | + } |
|
301 | 301 | |
302 | - public function shouldReplaceIcons() { |
|
303 | - return false; |
|
304 | - } |
|
302 | + public function shouldReplaceIcons() { |
|
303 | + return false; |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Themed logo url |
|
308 | - * |
|
309 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function getLogo($useSvg = true) { |
|
313 | - if ($this->themeExist('getLogo')) { |
|
314 | - return $this->theme->getLogo($useSvg); |
|
315 | - } |
|
306 | + /** |
|
307 | + * Themed logo url |
|
308 | + * |
|
309 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function getLogo($useSvg = true) { |
|
313 | + if ($this->themeExist('getLogo')) { |
|
314 | + return $this->theme->getLogo($useSvg); |
|
315 | + } |
|
316 | 316 | |
317 | - if($useSvg) { |
|
318 | - $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
|
319 | - } else { |
|
320 | - $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
|
321 | - } |
|
322 | - return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
323 | - } |
|
317 | + if($useSvg) { |
|
318 | + $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
|
319 | + } else { |
|
320 | + $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
|
321 | + } |
|
322 | + return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
323 | + } |
|
324 | 324 | |
325 | - public function getTextColorPrimary() { |
|
326 | - if ($this->themeExist('getTextColorPrimary')) { |
|
327 | - return $this->theme->getTextColorPrimary(); |
|
328 | - } |
|
329 | - return $this->defaultTextColorPrimary; |
|
330 | - } |
|
325 | + public function getTextColorPrimary() { |
|
326 | + if ($this->themeExist('getTextColorPrimary')) { |
|
327 | + return $this->theme->getTextColorPrimary(); |
|
328 | + } |
|
329 | + return $this->defaultTextColorPrimary; |
|
330 | + } |
|
331 | 331 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->defaultColorPrimary = '#0082c9'; |
71 | 71 | $this->defaultTextColorPrimary = '#ffffff'; |
72 | 72 | |
73 | - $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
|
73 | + $themePath = OC::$SERVERROOT.'/themes/'.OC_Util::getTheme().'/defaults.php'; |
|
74 | 74 | if (file_exists($themePath)) { |
75 | 75 | // prevent defaults.php from printing output |
76 | 76 | ob_start(); |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | if ($this->themeExist('getShortFooter')) { |
242 | 242 | $footer = $this->theme->getShortFooter(); |
243 | 243 | } else { |
244 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
245 | - ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
|
246 | - ' – ' . $this->getSlogan(); |
|
244 | + $footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'. |
|
245 | + ' rel="noreferrer noopener">'.$this->getEntity().'</a>'. |
|
246 | + ' – '.$this->getSlogan(); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | return $footer; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | if ($this->themeExist('buildDocLinkToKey')) { |
272 | 272 | return $this->theme->buildDocLinkToKey($key); |
273 | 273 | } |
274 | - return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
|
274 | + return $this->getDocBaseUrl().'/server/'.$this->defaultDocVersion.'/go.php?to='.$key; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @return array scss variables to overwrite |
294 | 294 | */ |
295 | 295 | public function getScssVariables() { |
296 | - if($this->themeExist('getScssVariables')) { |
|
296 | + if ($this->themeExist('getScssVariables')) { |
|
297 | 297 | return $this->theme->getScssVariables(); |
298 | 298 | } |
299 | 299 | return []; |
@@ -314,12 +314,12 @@ discard block |
||
314 | 314 | return $this->theme->getLogo($useSvg); |
315 | 315 | } |
316 | 316 | |
317 | - if($useSvg) { |
|
317 | + if ($useSvg) { |
|
318 | 318 | $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
319 | 319 | } else { |
320 | 320 | $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
321 | 321 | } |
322 | - return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
322 | + return $logo.'?v='.hash('sha1', implode('.', \OCP\Util::getVersion())); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | public function getTextColorPrimary() { |
@@ -34,108 +34,108 @@ |
||
34 | 34 | |
35 | 35 | class SvgController extends Controller { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - protected $serverRoot; |
|
39 | - |
|
40 | - /** @var ITimeFactory */ |
|
41 | - protected $timeFactory; |
|
42 | - |
|
43 | - /** @var IAppManager */ |
|
44 | - protected $appManager; |
|
45 | - |
|
46 | - public function __construct(string $appName, |
|
47 | - IRequest $request, |
|
48 | - ITimeFactory $timeFactory, |
|
49 | - IAppManager $appManager) { |
|
50 | - parent::__construct($appName, $request); |
|
51 | - |
|
52 | - $this->serverRoot = \OC::$SERVERROOT; |
|
53 | - $this->timeFactory = $timeFactory; |
|
54 | - $this->appManager = $appManager; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @PublicPage |
|
59 | - * @NoCSRFRequired |
|
60 | - * |
|
61 | - * Generate svg from filename with the requested color |
|
62 | - * |
|
63 | - * @param string $folder |
|
64 | - * @param string $fileName |
|
65 | - * @param string $color |
|
66 | - * @return DataDisplayResponse|NotFoundResponse |
|
67 | - */ |
|
68 | - public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
69 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
70 | - return $this->getSvg($path, $color, $fileName); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @PublicPage |
|
75 | - * @NoCSRFRequired |
|
76 | - * |
|
77 | - * Generate svg from filename with the requested color |
|
78 | - * |
|
79 | - * @param string $app |
|
80 | - * @param string $fileName |
|
81 | - * @param string $color |
|
82 | - * @return DataDisplayResponse|NotFoundResponse |
|
83 | - */ |
|
84 | - public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
85 | - |
|
86 | - if ($app === 'settings') { |
|
87 | - $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
88 | - return $this->getSvg($path, $color, $fileName); |
|
89 | - } |
|
90 | - |
|
91 | - $appRootPath = $this->appManager->getAppPath($app); |
|
92 | - $appPath = substr($appRootPath, strlen($this->serverRoot)); |
|
93 | - |
|
94 | - if (!$appPath) { |
|
95 | - return new NotFoundResponse(); |
|
96 | - } |
|
97 | - $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
98 | - return $this->getSvg($path, $color, $fileName); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Generate svg from filename with the requested color |
|
103 | - * |
|
104 | - * @param string $path |
|
105 | - * @param string $color |
|
106 | - * @return DataDisplayResponse|NotFoundResponse |
|
107 | - */ |
|
108 | - private function getSvg(string $path, string $color, string $fileName) { |
|
109 | - if (!file_exists($path)) { |
|
110 | - return new NotFoundResponse(); |
|
111 | - } |
|
112 | - |
|
113 | - $svg = file_get_contents($path); |
|
114 | - |
|
115 | - if (is_null($svg)) { |
|
116 | - return new NotFoundResponse(); |
|
117 | - } |
|
118 | - |
|
119 | - // add fill (fill is not present on black elements) |
|
120 | - $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
|
121 | - $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
122 | - |
|
123 | - // replace any fill or stroke colors |
|
124 | - $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
125 | - $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
126 | - |
|
127 | - $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
128 | - |
|
129 | - // Set cache control |
|
130 | - $ttl = 31536000; |
|
131 | - $response->cacheFor($ttl); |
|
132 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
133 | - $expires = new \DateTime(); |
|
134 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
135 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
136 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
137 | - $response->addHeader('Pragma', 'cache'); |
|
138 | - |
|
139 | - return $response; |
|
140 | - } |
|
37 | + /** @var string */ |
|
38 | + protected $serverRoot; |
|
39 | + |
|
40 | + /** @var ITimeFactory */ |
|
41 | + protected $timeFactory; |
|
42 | + |
|
43 | + /** @var IAppManager */ |
|
44 | + protected $appManager; |
|
45 | + |
|
46 | + public function __construct(string $appName, |
|
47 | + IRequest $request, |
|
48 | + ITimeFactory $timeFactory, |
|
49 | + IAppManager $appManager) { |
|
50 | + parent::__construct($appName, $request); |
|
51 | + |
|
52 | + $this->serverRoot = \OC::$SERVERROOT; |
|
53 | + $this->timeFactory = $timeFactory; |
|
54 | + $this->appManager = $appManager; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @PublicPage |
|
59 | + * @NoCSRFRequired |
|
60 | + * |
|
61 | + * Generate svg from filename with the requested color |
|
62 | + * |
|
63 | + * @param string $folder |
|
64 | + * @param string $fileName |
|
65 | + * @param string $color |
|
66 | + * @return DataDisplayResponse|NotFoundResponse |
|
67 | + */ |
|
68 | + public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
69 | + $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
70 | + return $this->getSvg($path, $color, $fileName); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @PublicPage |
|
75 | + * @NoCSRFRequired |
|
76 | + * |
|
77 | + * Generate svg from filename with the requested color |
|
78 | + * |
|
79 | + * @param string $app |
|
80 | + * @param string $fileName |
|
81 | + * @param string $color |
|
82 | + * @return DataDisplayResponse|NotFoundResponse |
|
83 | + */ |
|
84 | + public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
85 | + |
|
86 | + if ($app === 'settings') { |
|
87 | + $path = $this->serverRoot . "/settings/img/$fileName.svg"; |
|
88 | + return $this->getSvg($path, $color, $fileName); |
|
89 | + } |
|
90 | + |
|
91 | + $appRootPath = $this->appManager->getAppPath($app); |
|
92 | + $appPath = substr($appRootPath, strlen($this->serverRoot)); |
|
93 | + |
|
94 | + if (!$appPath) { |
|
95 | + return new NotFoundResponse(); |
|
96 | + } |
|
97 | + $path = $this->serverRoot . $appPath ."/img/$fileName.svg"; |
|
98 | + return $this->getSvg($path, $color, $fileName); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Generate svg from filename with the requested color |
|
103 | + * |
|
104 | + * @param string $path |
|
105 | + * @param string $color |
|
106 | + * @return DataDisplayResponse|NotFoundResponse |
|
107 | + */ |
|
108 | + private function getSvg(string $path, string $color, string $fileName) { |
|
109 | + if (!file_exists($path)) { |
|
110 | + return new NotFoundResponse(); |
|
111 | + } |
|
112 | + |
|
113 | + $svg = file_get_contents($path); |
|
114 | + |
|
115 | + if (is_null($svg)) { |
|
116 | + return new NotFoundResponse(); |
|
117 | + } |
|
118 | + |
|
119 | + // add fill (fill is not present on black elements) |
|
120 | + $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi'; |
|
121 | + $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg); |
|
122 | + |
|
123 | + // replace any fill or stroke colors |
|
124 | + $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg); |
|
125 | + $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg); |
|
126 | + |
|
127 | + $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
128 | + |
|
129 | + // Set cache control |
|
130 | + $ttl = 31536000; |
|
131 | + $response->cacheFor($ttl); |
|
132 | + $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
133 | + $expires = new \DateTime(); |
|
134 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
135 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
136 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
137 | + $response->addHeader('Pragma', 'cache'); |
|
138 | + |
|
139 | + return $response; |
|
140 | + } |
|
141 | 141 | } |
@@ -59,358 +59,358 @@ |
||
59 | 59 | |
60 | 60 | class LoginController extends Controller { |
61 | 61 | |
62 | - const LOGIN_MSG_INVALIDPASSWORD = 'invalidpassword'; |
|
63 | - const LOGIN_MSG_USERDISABLED = 'userdisabled'; |
|
64 | - |
|
65 | - /** @var IUserManager */ |
|
66 | - private $userManager; |
|
67 | - /** @var IConfig */ |
|
68 | - private $config; |
|
69 | - /** @var ISession */ |
|
70 | - private $session; |
|
71 | - /** @var IUserSession|Session */ |
|
72 | - private $userSession; |
|
73 | - /** @var IURLGenerator */ |
|
74 | - private $urlGenerator; |
|
75 | - /** @var ILogger */ |
|
76 | - private $logger; |
|
77 | - /** @var Manager */ |
|
78 | - private $twoFactorManager; |
|
79 | - /** @var Defaults */ |
|
80 | - private $defaults; |
|
81 | - /** @var Throttler */ |
|
82 | - private $throttler; |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $appName |
|
86 | - * @param IRequest $request |
|
87 | - * @param IUserManager $userManager |
|
88 | - * @param IConfig $config |
|
89 | - * @param ISession $session |
|
90 | - * @param IUserSession $userSession |
|
91 | - * @param IURLGenerator $urlGenerator |
|
92 | - * @param ILogger $logger |
|
93 | - * @param Manager $twoFactorManager |
|
94 | - * @param Defaults $defaults |
|
95 | - * @param Throttler $throttler |
|
96 | - */ |
|
97 | - public function __construct($appName, |
|
98 | - IRequest $request, |
|
99 | - IUserManager $userManager, |
|
100 | - IConfig $config, |
|
101 | - ISession $session, |
|
102 | - IUserSession $userSession, |
|
103 | - IURLGenerator $urlGenerator, |
|
104 | - ILogger $logger, |
|
105 | - Manager $twoFactorManager, |
|
106 | - Defaults $defaults, |
|
107 | - Throttler $throttler) { |
|
108 | - parent::__construct($appName, $request); |
|
109 | - $this->userManager = $userManager; |
|
110 | - $this->config = $config; |
|
111 | - $this->session = $session; |
|
112 | - $this->userSession = $userSession; |
|
113 | - $this->urlGenerator = $urlGenerator; |
|
114 | - $this->logger = $logger; |
|
115 | - $this->twoFactorManager = $twoFactorManager; |
|
116 | - $this->defaults = $defaults; |
|
117 | - $this->throttler = $throttler; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @NoAdminRequired |
|
122 | - * @UseSession |
|
123 | - * |
|
124 | - * @return RedirectResponse |
|
125 | - */ |
|
126 | - public function logout() { |
|
127 | - $loginToken = $this->request->getCookie('nc_token'); |
|
128 | - if (!is_null($loginToken)) { |
|
129 | - $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
130 | - } |
|
131 | - $this->userSession->logout(); |
|
132 | - |
|
133 | - $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
134 | - $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
135 | - return $response; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @PublicPage |
|
140 | - * @NoCSRFRequired |
|
141 | - * @UseSession |
|
142 | - * |
|
143 | - * @param string $user |
|
144 | - * @param string $redirect_url |
|
145 | - * |
|
146 | - * @return TemplateResponse|RedirectResponse |
|
147 | - */ |
|
148 | - public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { |
|
149 | - |
|
150 | - if ($this->userSession->isLoggedIn()) { |
|
151 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
152 | - } |
|
153 | - |
|
154 | - $parameters = array(); |
|
155 | - $loginMessages = $this->session->get('loginMessages'); |
|
156 | - $errors = []; |
|
157 | - $messages = []; |
|
158 | - if (is_array($loginMessages)) { |
|
159 | - list($errors, $messages) = $loginMessages; |
|
160 | - } |
|
161 | - $this->session->remove('loginMessages'); |
|
162 | - foreach ($errors as $value) { |
|
163 | - $parameters[$value] = true; |
|
164 | - } |
|
165 | - |
|
166 | - $parameters['messages'] = $messages; |
|
167 | - if ($user !== null && $user !== '') { |
|
168 | - $parameters['loginName'] = $user; |
|
169 | - $parameters['user_autofocus'] = false; |
|
170 | - } else { |
|
171 | - $parameters['loginName'] = ''; |
|
172 | - $parameters['user_autofocus'] = true; |
|
173 | - } |
|
174 | - if (!empty($redirect_url)) { |
|
175 | - $parameters['redirect_url'] = $redirect_url; |
|
176 | - } |
|
177 | - |
|
178 | - $parameters = $this->setPasswordResetParameters($user, $parameters); |
|
179 | - $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
180 | - |
|
181 | - if ($user !== null && $user !== '') { |
|
182 | - $parameters['loginName'] = $user; |
|
183 | - $parameters['user_autofocus'] = false; |
|
184 | - } else { |
|
185 | - $parameters['loginName'] = ''; |
|
186 | - $parameters['user_autofocus'] = true; |
|
187 | - } |
|
188 | - |
|
189 | - $parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress()); |
|
190 | - |
|
191 | - // OpenGraph Support: http://ogp.me/ |
|
192 | - Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
193 | - Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
194 | - Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
195 | - Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
196 | - Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
197 | - Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png'))]); |
|
198 | - |
|
199 | - return new TemplateResponse( |
|
200 | - $this->appName, 'login', $parameters, 'guest' |
|
201 | - ); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Sets the password reset params. |
|
206 | - * |
|
207 | - * Users may not change their passwords if: |
|
208 | - * - The account is disabled |
|
209 | - * - The backend doesn't support password resets |
|
210 | - * - The password reset function is disabled |
|
211 | - * |
|
212 | - * @param string $user |
|
213 | - * @param array $parameters |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - private function setPasswordResetParameters( |
|
217 | - string $user = null, array $parameters): array { |
|
218 | - if ($user !== null && $user !== '') { |
|
219 | - $userObj = $this->userManager->get($user); |
|
220 | - } else { |
|
221 | - $userObj = null; |
|
222 | - } |
|
223 | - |
|
224 | - $parameters['resetPasswordLink'] = $this->config |
|
225 | - ->getSystemValue('lost_password_link', ''); |
|
226 | - |
|
227 | - if (!$parameters['resetPasswordLink'] && $userObj !== null) { |
|
228 | - $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
229 | - } else if ($userObj !== null && $userObj->isEnabled() === false) { |
|
230 | - $parameters['canResetPassword'] = false; |
|
231 | - } else { |
|
232 | - $parameters['canResetPassword'] = true; |
|
233 | - } |
|
234 | - |
|
235 | - return $parameters; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @param string $redirectUrl |
|
240 | - * @return RedirectResponse |
|
241 | - */ |
|
242 | - private function generateRedirect($redirectUrl) { |
|
243 | - if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
244 | - $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
245 | - // Deny the redirect if the URL contains a @ |
|
246 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
247 | - if (strpos($location, '@') === false) { |
|
248 | - return new RedirectResponse($location); |
|
249 | - } |
|
250 | - } |
|
251 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @PublicPage |
|
256 | - * @UseSession |
|
257 | - * @NoCSRFRequired |
|
258 | - * @BruteForceProtection(action=login) |
|
259 | - * |
|
260 | - * @param string $user |
|
261 | - * @param string $password |
|
262 | - * @param string $redirect_url |
|
263 | - * @param boolean $remember_login |
|
264 | - * @param string $timezone |
|
265 | - * @param string $timezone_offset |
|
266 | - * @return RedirectResponse |
|
267 | - */ |
|
268 | - public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') { |
|
269 | - if(!is_string($user)) { |
|
270 | - throw new \InvalidArgumentException('Username must be string'); |
|
271 | - } |
|
272 | - |
|
273 | - // If the user is already logged in and the CSRF check does not pass then |
|
274 | - // simply redirect the user to the correct page as required. This is the |
|
275 | - // case when an user has already logged-in, in another tab. |
|
276 | - if(!$this->request->passesCSRFCheck()) { |
|
277 | - return $this->generateRedirect($redirect_url); |
|
278 | - } |
|
279 | - |
|
280 | - if ($this->userManager instanceof PublicEmitter) { |
|
281 | - $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
282 | - } |
|
283 | - |
|
284 | - $originalUser = $user; |
|
285 | - |
|
286 | - $userObj = $this->userManager->get($user); |
|
287 | - |
|
288 | - if ($userObj !== null && $userObj->isEnabled() === false) { |
|
289 | - $this->logger->warning('Login failed: \''. $user . '\' disabled' . |
|
290 | - ' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
291 | - ['app' => 'core']); |
|
292 | - return $this->createLoginFailedResponse($user, $originalUser, |
|
293 | - $redirect_url, self::LOGIN_MSG_USERDISABLED); |
|
294 | - } |
|
295 | - |
|
296 | - // TODO: Add all the insane error handling |
|
297 | - /* @var $loginResult IUser */ |
|
298 | - $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
299 | - if ($loginResult === false) { |
|
300 | - $users = $this->userManager->getByEmail($user); |
|
301 | - // we only allow login by email if unique |
|
302 | - if (count($users) === 1) { |
|
303 | - $previousUser = $user; |
|
304 | - $user = $users[0]->getUID(); |
|
305 | - if($user !== $previousUser) { |
|
306 | - $loginResult = $this->userManager->checkPassword($user, $password); |
|
307 | - } |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - if ($loginResult === false) { |
|
312 | - $this->logger->warning('Login failed: \''. $user . |
|
313 | - '\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
314 | - ['app' => 'core']); |
|
315 | - return $this->createLoginFailedResponse($user, $originalUser, |
|
316 | - $redirect_url, self::LOGIN_MSG_INVALIDPASSWORD); |
|
317 | - } |
|
318 | - |
|
319 | - // TODO: remove password checks from above and let the user session handle failures |
|
320 | - // requires https://github.com/owncloud/core/pull/24616 |
|
321 | - $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
322 | - $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER); |
|
323 | - $this->userSession->updateTokens($loginResult->getUID(), $password); |
|
324 | - |
|
325 | - // User has successfully logged in, now remove the password reset link, when it is available |
|
326 | - $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
327 | - |
|
328 | - $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
329 | - |
|
330 | - if ($timezone_offset !== '') { |
|
331 | - $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
332 | - $this->session->set('timezone', $timezone_offset); |
|
333 | - } |
|
334 | - |
|
335 | - if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
336 | - $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
337 | - |
|
338 | - $providers = $this->twoFactorManager->getProviderSet($loginResult)->getPrimaryProviders(); |
|
339 | - if (count($providers) === 1) { |
|
340 | - // Single provider, hence we can redirect to that provider's challenge page directly |
|
341 | - /* @var $provider IProvider */ |
|
342 | - $provider = array_pop($providers); |
|
343 | - $url = 'core.TwoFactorChallenge.showChallenge'; |
|
344 | - $urlParams = [ |
|
345 | - 'challengeProviderId' => $provider->getId(), |
|
346 | - ]; |
|
347 | - } else { |
|
348 | - $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
349 | - $urlParams = []; |
|
350 | - } |
|
351 | - |
|
352 | - if (!is_null($redirect_url)) { |
|
353 | - $urlParams['redirect_url'] = $redirect_url; |
|
354 | - } |
|
355 | - |
|
356 | - return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
357 | - } |
|
358 | - |
|
359 | - if ($remember_login) { |
|
360 | - $this->userSession->createRememberMeToken($loginResult); |
|
361 | - } |
|
362 | - |
|
363 | - return $this->generateRedirect($redirect_url); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Creates a login failed response. |
|
368 | - * |
|
369 | - * @param string $user |
|
370 | - * @param string $originalUser |
|
371 | - * @param string $redirect_url |
|
372 | - * @param string $loginMessage |
|
373 | - * @return RedirectResponse |
|
374 | - */ |
|
375 | - private function createLoginFailedResponse( |
|
376 | - $user, $originalUser, $redirect_url, string $loginMessage) { |
|
377 | - // Read current user and append if possible we need to |
|
378 | - // return the unmodified user otherwise we will leak the login name |
|
379 | - $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
380 | - if (!is_null($redirect_url)) { |
|
381 | - $args['redirect_url'] = $redirect_url; |
|
382 | - } |
|
383 | - $response = new RedirectResponse( |
|
384 | - $this->urlGenerator->linkToRoute('core.login.showLoginForm', $args) |
|
385 | - ); |
|
386 | - $response->throttle(['user' => substr($user, 0, 64)]); |
|
387 | - $this->session->set('loginMessages', [ |
|
388 | - [$loginMessage], [] |
|
389 | - ]); |
|
390 | - return $response; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @NoAdminRequired |
|
395 | - * @UseSession |
|
396 | - * @BruteForceProtection(action=sudo) |
|
397 | - * |
|
398 | - * @license GNU AGPL version 3 or any later version |
|
399 | - * |
|
400 | - * @param string $password |
|
401 | - * @return DataResponse |
|
402 | - */ |
|
403 | - public function confirmPassword($password) { |
|
404 | - $loginName = $this->userSession->getLoginName(); |
|
405 | - $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
406 | - if ($loginResult === false) { |
|
407 | - $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
408 | - $response->throttle(); |
|
409 | - return $response; |
|
410 | - } |
|
411 | - |
|
412 | - $confirmTimestamp = time(); |
|
413 | - $this->session->set('last-password-confirm', $confirmTimestamp); |
|
414 | - return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
415 | - } |
|
62 | + const LOGIN_MSG_INVALIDPASSWORD = 'invalidpassword'; |
|
63 | + const LOGIN_MSG_USERDISABLED = 'userdisabled'; |
|
64 | + |
|
65 | + /** @var IUserManager */ |
|
66 | + private $userManager; |
|
67 | + /** @var IConfig */ |
|
68 | + private $config; |
|
69 | + /** @var ISession */ |
|
70 | + private $session; |
|
71 | + /** @var IUserSession|Session */ |
|
72 | + private $userSession; |
|
73 | + /** @var IURLGenerator */ |
|
74 | + private $urlGenerator; |
|
75 | + /** @var ILogger */ |
|
76 | + private $logger; |
|
77 | + /** @var Manager */ |
|
78 | + private $twoFactorManager; |
|
79 | + /** @var Defaults */ |
|
80 | + private $defaults; |
|
81 | + /** @var Throttler */ |
|
82 | + private $throttler; |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $appName |
|
86 | + * @param IRequest $request |
|
87 | + * @param IUserManager $userManager |
|
88 | + * @param IConfig $config |
|
89 | + * @param ISession $session |
|
90 | + * @param IUserSession $userSession |
|
91 | + * @param IURLGenerator $urlGenerator |
|
92 | + * @param ILogger $logger |
|
93 | + * @param Manager $twoFactorManager |
|
94 | + * @param Defaults $defaults |
|
95 | + * @param Throttler $throttler |
|
96 | + */ |
|
97 | + public function __construct($appName, |
|
98 | + IRequest $request, |
|
99 | + IUserManager $userManager, |
|
100 | + IConfig $config, |
|
101 | + ISession $session, |
|
102 | + IUserSession $userSession, |
|
103 | + IURLGenerator $urlGenerator, |
|
104 | + ILogger $logger, |
|
105 | + Manager $twoFactorManager, |
|
106 | + Defaults $defaults, |
|
107 | + Throttler $throttler) { |
|
108 | + parent::__construct($appName, $request); |
|
109 | + $this->userManager = $userManager; |
|
110 | + $this->config = $config; |
|
111 | + $this->session = $session; |
|
112 | + $this->userSession = $userSession; |
|
113 | + $this->urlGenerator = $urlGenerator; |
|
114 | + $this->logger = $logger; |
|
115 | + $this->twoFactorManager = $twoFactorManager; |
|
116 | + $this->defaults = $defaults; |
|
117 | + $this->throttler = $throttler; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @NoAdminRequired |
|
122 | + * @UseSession |
|
123 | + * |
|
124 | + * @return RedirectResponse |
|
125 | + */ |
|
126 | + public function logout() { |
|
127 | + $loginToken = $this->request->getCookie('nc_token'); |
|
128 | + if (!is_null($loginToken)) { |
|
129 | + $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
130 | + } |
|
131 | + $this->userSession->logout(); |
|
132 | + |
|
133 | + $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
134 | + $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
135 | + return $response; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @PublicPage |
|
140 | + * @NoCSRFRequired |
|
141 | + * @UseSession |
|
142 | + * |
|
143 | + * @param string $user |
|
144 | + * @param string $redirect_url |
|
145 | + * |
|
146 | + * @return TemplateResponse|RedirectResponse |
|
147 | + */ |
|
148 | + public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response { |
|
149 | + |
|
150 | + if ($this->userSession->isLoggedIn()) { |
|
151 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
152 | + } |
|
153 | + |
|
154 | + $parameters = array(); |
|
155 | + $loginMessages = $this->session->get('loginMessages'); |
|
156 | + $errors = []; |
|
157 | + $messages = []; |
|
158 | + if (is_array($loginMessages)) { |
|
159 | + list($errors, $messages) = $loginMessages; |
|
160 | + } |
|
161 | + $this->session->remove('loginMessages'); |
|
162 | + foreach ($errors as $value) { |
|
163 | + $parameters[$value] = true; |
|
164 | + } |
|
165 | + |
|
166 | + $parameters['messages'] = $messages; |
|
167 | + if ($user !== null && $user !== '') { |
|
168 | + $parameters['loginName'] = $user; |
|
169 | + $parameters['user_autofocus'] = false; |
|
170 | + } else { |
|
171 | + $parameters['loginName'] = ''; |
|
172 | + $parameters['user_autofocus'] = true; |
|
173 | + } |
|
174 | + if (!empty($redirect_url)) { |
|
175 | + $parameters['redirect_url'] = $redirect_url; |
|
176 | + } |
|
177 | + |
|
178 | + $parameters = $this->setPasswordResetParameters($user, $parameters); |
|
179 | + $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
180 | + |
|
181 | + if ($user !== null && $user !== '') { |
|
182 | + $parameters['loginName'] = $user; |
|
183 | + $parameters['user_autofocus'] = false; |
|
184 | + } else { |
|
185 | + $parameters['loginName'] = ''; |
|
186 | + $parameters['user_autofocus'] = true; |
|
187 | + } |
|
188 | + |
|
189 | + $parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress()); |
|
190 | + |
|
191 | + // OpenGraph Support: http://ogp.me/ |
|
192 | + Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
193 | + Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
194 | + Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
195 | + Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
196 | + Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
197 | + Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png'))]); |
|
198 | + |
|
199 | + return new TemplateResponse( |
|
200 | + $this->appName, 'login', $parameters, 'guest' |
|
201 | + ); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Sets the password reset params. |
|
206 | + * |
|
207 | + * Users may not change their passwords if: |
|
208 | + * - The account is disabled |
|
209 | + * - The backend doesn't support password resets |
|
210 | + * - The password reset function is disabled |
|
211 | + * |
|
212 | + * @param string $user |
|
213 | + * @param array $parameters |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + private function setPasswordResetParameters( |
|
217 | + string $user = null, array $parameters): array { |
|
218 | + if ($user !== null && $user !== '') { |
|
219 | + $userObj = $this->userManager->get($user); |
|
220 | + } else { |
|
221 | + $userObj = null; |
|
222 | + } |
|
223 | + |
|
224 | + $parameters['resetPasswordLink'] = $this->config |
|
225 | + ->getSystemValue('lost_password_link', ''); |
|
226 | + |
|
227 | + if (!$parameters['resetPasswordLink'] && $userObj !== null) { |
|
228 | + $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
229 | + } else if ($userObj !== null && $userObj->isEnabled() === false) { |
|
230 | + $parameters['canResetPassword'] = false; |
|
231 | + } else { |
|
232 | + $parameters['canResetPassword'] = true; |
|
233 | + } |
|
234 | + |
|
235 | + return $parameters; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @param string $redirectUrl |
|
240 | + * @return RedirectResponse |
|
241 | + */ |
|
242 | + private function generateRedirect($redirectUrl) { |
|
243 | + if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
244 | + $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
245 | + // Deny the redirect if the URL contains a @ |
|
246 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
247 | + if (strpos($location, '@') === false) { |
|
248 | + return new RedirectResponse($location); |
|
249 | + } |
|
250 | + } |
|
251 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * @PublicPage |
|
256 | + * @UseSession |
|
257 | + * @NoCSRFRequired |
|
258 | + * @BruteForceProtection(action=login) |
|
259 | + * |
|
260 | + * @param string $user |
|
261 | + * @param string $password |
|
262 | + * @param string $redirect_url |
|
263 | + * @param boolean $remember_login |
|
264 | + * @param string $timezone |
|
265 | + * @param string $timezone_offset |
|
266 | + * @return RedirectResponse |
|
267 | + */ |
|
268 | + public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') { |
|
269 | + if(!is_string($user)) { |
|
270 | + throw new \InvalidArgumentException('Username must be string'); |
|
271 | + } |
|
272 | + |
|
273 | + // If the user is already logged in and the CSRF check does not pass then |
|
274 | + // simply redirect the user to the correct page as required. This is the |
|
275 | + // case when an user has already logged-in, in another tab. |
|
276 | + if(!$this->request->passesCSRFCheck()) { |
|
277 | + return $this->generateRedirect($redirect_url); |
|
278 | + } |
|
279 | + |
|
280 | + if ($this->userManager instanceof PublicEmitter) { |
|
281 | + $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
282 | + } |
|
283 | + |
|
284 | + $originalUser = $user; |
|
285 | + |
|
286 | + $userObj = $this->userManager->get($user); |
|
287 | + |
|
288 | + if ($userObj !== null && $userObj->isEnabled() === false) { |
|
289 | + $this->logger->warning('Login failed: \''. $user . '\' disabled' . |
|
290 | + ' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
291 | + ['app' => 'core']); |
|
292 | + return $this->createLoginFailedResponse($user, $originalUser, |
|
293 | + $redirect_url, self::LOGIN_MSG_USERDISABLED); |
|
294 | + } |
|
295 | + |
|
296 | + // TODO: Add all the insane error handling |
|
297 | + /* @var $loginResult IUser */ |
|
298 | + $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
299 | + if ($loginResult === false) { |
|
300 | + $users = $this->userManager->getByEmail($user); |
|
301 | + // we only allow login by email if unique |
|
302 | + if (count($users) === 1) { |
|
303 | + $previousUser = $user; |
|
304 | + $user = $users[0]->getUID(); |
|
305 | + if($user !== $previousUser) { |
|
306 | + $loginResult = $this->userManager->checkPassword($user, $password); |
|
307 | + } |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + if ($loginResult === false) { |
|
312 | + $this->logger->warning('Login failed: \''. $user . |
|
313 | + '\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
314 | + ['app' => 'core']); |
|
315 | + return $this->createLoginFailedResponse($user, $originalUser, |
|
316 | + $redirect_url, self::LOGIN_MSG_INVALIDPASSWORD); |
|
317 | + } |
|
318 | + |
|
319 | + // TODO: remove password checks from above and let the user session handle failures |
|
320 | + // requires https://github.com/owncloud/core/pull/24616 |
|
321 | + $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
322 | + $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER); |
|
323 | + $this->userSession->updateTokens($loginResult->getUID(), $password); |
|
324 | + |
|
325 | + // User has successfully logged in, now remove the password reset link, when it is available |
|
326 | + $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
327 | + |
|
328 | + $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
329 | + |
|
330 | + if ($timezone_offset !== '') { |
|
331 | + $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
332 | + $this->session->set('timezone', $timezone_offset); |
|
333 | + } |
|
334 | + |
|
335 | + if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
336 | + $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
337 | + |
|
338 | + $providers = $this->twoFactorManager->getProviderSet($loginResult)->getPrimaryProviders(); |
|
339 | + if (count($providers) === 1) { |
|
340 | + // Single provider, hence we can redirect to that provider's challenge page directly |
|
341 | + /* @var $provider IProvider */ |
|
342 | + $provider = array_pop($providers); |
|
343 | + $url = 'core.TwoFactorChallenge.showChallenge'; |
|
344 | + $urlParams = [ |
|
345 | + 'challengeProviderId' => $provider->getId(), |
|
346 | + ]; |
|
347 | + } else { |
|
348 | + $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
349 | + $urlParams = []; |
|
350 | + } |
|
351 | + |
|
352 | + if (!is_null($redirect_url)) { |
|
353 | + $urlParams['redirect_url'] = $redirect_url; |
|
354 | + } |
|
355 | + |
|
356 | + return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
357 | + } |
|
358 | + |
|
359 | + if ($remember_login) { |
|
360 | + $this->userSession->createRememberMeToken($loginResult); |
|
361 | + } |
|
362 | + |
|
363 | + return $this->generateRedirect($redirect_url); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Creates a login failed response. |
|
368 | + * |
|
369 | + * @param string $user |
|
370 | + * @param string $originalUser |
|
371 | + * @param string $redirect_url |
|
372 | + * @param string $loginMessage |
|
373 | + * @return RedirectResponse |
|
374 | + */ |
|
375 | + private function createLoginFailedResponse( |
|
376 | + $user, $originalUser, $redirect_url, string $loginMessage) { |
|
377 | + // Read current user and append if possible we need to |
|
378 | + // return the unmodified user otherwise we will leak the login name |
|
379 | + $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
380 | + if (!is_null($redirect_url)) { |
|
381 | + $args['redirect_url'] = $redirect_url; |
|
382 | + } |
|
383 | + $response = new RedirectResponse( |
|
384 | + $this->urlGenerator->linkToRoute('core.login.showLoginForm', $args) |
|
385 | + ); |
|
386 | + $response->throttle(['user' => substr($user, 0, 64)]); |
|
387 | + $this->session->set('loginMessages', [ |
|
388 | + [$loginMessage], [] |
|
389 | + ]); |
|
390 | + return $response; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @NoAdminRequired |
|
395 | + * @UseSession |
|
396 | + * @BruteForceProtection(action=sudo) |
|
397 | + * |
|
398 | + * @license GNU AGPL version 3 or any later version |
|
399 | + * |
|
400 | + * @param string $password |
|
401 | + * @return DataResponse |
|
402 | + */ |
|
403 | + public function confirmPassword($password) { |
|
404 | + $loginName = $this->userSession->getLoginName(); |
|
405 | + $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
406 | + if ($loginResult === false) { |
|
407 | + $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
408 | + $response->throttle(); |
|
409 | + return $response; |
|
410 | + } |
|
411 | + |
|
412 | + $confirmTimestamp = time(); |
|
413 | + $this->session->set('last-password-confirm', $confirmTimestamp); |
|
414 | + return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
415 | + } |
|
416 | 416 | } |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | * @return RedirectResponse |
267 | 267 | */ |
268 | 268 | public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') { |
269 | - if(!is_string($user)) { |
|
269 | + if (!is_string($user)) { |
|
270 | 270 | throw new \InvalidArgumentException('Username must be string'); |
271 | 271 | } |
272 | 272 | |
273 | 273 | // If the user is already logged in and the CSRF check does not pass then |
274 | 274 | // simply redirect the user to the correct page as required. This is the |
275 | 275 | // case when an user has already logged-in, in another tab. |
276 | - if(!$this->request->passesCSRFCheck()) { |
|
276 | + if (!$this->request->passesCSRFCheck()) { |
|
277 | 277 | return $this->generateRedirect($redirect_url); |
278 | 278 | } |
279 | 279 | |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | $userObj = $this->userManager->get($user); |
287 | 287 | |
288 | 288 | if ($userObj !== null && $userObj->isEnabled() === false) { |
289 | - $this->logger->warning('Login failed: \''. $user . '\' disabled' . |
|
290 | - ' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
289 | + $this->logger->warning('Login failed: \''.$user.'\' disabled'. |
|
290 | + ' (Remote IP: \''.$this->request->getRemoteAddress().'\')', |
|
291 | 291 | ['app' => 'core']); |
292 | 292 | return $this->createLoginFailedResponse($user, $originalUser, |
293 | 293 | $redirect_url, self::LOGIN_MSG_USERDISABLED); |
@@ -302,15 +302,15 @@ discard block |
||
302 | 302 | if (count($users) === 1) { |
303 | 303 | $previousUser = $user; |
304 | 304 | $user = $users[0]->getUID(); |
305 | - if($user !== $previousUser) { |
|
305 | + if ($user !== $previousUser) { |
|
306 | 306 | $loginResult = $this->userManager->checkPassword($user, $password); |
307 | 307 | } |
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | 311 | if ($loginResult === false) { |
312 | - $this->logger->warning('Login failed: \''. $user . |
|
313 | - '\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', |
|
312 | + $this->logger->warning('Login failed: \''.$user. |
|
313 | + '\' (Remote IP: \''.$this->request->getRemoteAddress().'\')', |
|
314 | 314 | ['app' => 'core']); |
315 | 315 | return $this->createLoginFailedResponse($user, $originalUser, |
316 | 316 | $redirect_url, self::LOGIN_MSG_INVALIDPASSWORD); |