@@ -44,361 +44,361 @@ |
||
44 | 44 | |
45 | 45 | class ThemingDefaults extends \OC_Defaults { |
46 | 46 | |
47 | - /** @var IConfig */ |
|
48 | - private $config; |
|
49 | - /** @var IL10N */ |
|
50 | - private $l; |
|
51 | - /** @var ImageManager */ |
|
52 | - private $imageManager; |
|
53 | - /** @var IURLGenerator */ |
|
54 | - private $urlGenerator; |
|
55 | - /** @var ICacheFactory */ |
|
56 | - private $cacheFactory; |
|
57 | - /** @var Util */ |
|
58 | - private $util; |
|
59 | - /** @var IAppManager */ |
|
60 | - private $appManager; |
|
61 | - /** @var string */ |
|
62 | - private $name; |
|
63 | - /** @var string */ |
|
64 | - private $title; |
|
65 | - /** @var string */ |
|
66 | - private $entity; |
|
67 | - /** @var string */ |
|
68 | - private $url; |
|
69 | - /** @var string */ |
|
70 | - private $slogan; |
|
71 | - /** @var string */ |
|
72 | - private $color; |
|
73 | - |
|
74 | - /** @var string */ |
|
75 | - private $iTunesAppId; |
|
76 | - /** @var string */ |
|
77 | - private $iOSClientUrl; |
|
78 | - /** @var string */ |
|
79 | - private $AndroidClientUrl; |
|
80 | - |
|
81 | - /** |
|
82 | - * ThemingDefaults constructor. |
|
83 | - * |
|
84 | - * @param IConfig $config |
|
85 | - * @param IL10N $l |
|
86 | - * @param ImageManager $imageManager |
|
87 | - * @param IURLGenerator $urlGenerator |
|
88 | - * @param ICacheFactory $cacheFactory |
|
89 | - * @param Util $util |
|
90 | - * @param IAppManager $appManager |
|
91 | - */ |
|
92 | - public function __construct(IConfig $config, |
|
93 | - IL10N $l, |
|
94 | - IURLGenerator $urlGenerator, |
|
95 | - ICacheFactory $cacheFactory, |
|
96 | - Util $util, |
|
97 | - ImageManager $imageManager, |
|
98 | - IAppManager $appManager |
|
99 | - ) { |
|
100 | - parent::__construct(); |
|
101 | - $this->config = $config; |
|
102 | - $this->l = $l; |
|
103 | - $this->imageManager = $imageManager; |
|
104 | - $this->urlGenerator = $urlGenerator; |
|
105 | - $this->cacheFactory = $cacheFactory; |
|
106 | - $this->util = $util; |
|
107 | - $this->appManager = $appManager; |
|
108 | - |
|
109 | - $this->name = parent::getName(); |
|
110 | - $this->title = parent::getTitle(); |
|
111 | - $this->entity = parent::getEntity(); |
|
112 | - $this->url = parent::getBaseUrl(); |
|
113 | - $this->slogan = parent::getSlogan(); |
|
114 | - $this->color = parent::getColorPrimary(); |
|
115 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
116 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
117 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
118 | - } |
|
119 | - |
|
120 | - public function getName() { |
|
121 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
122 | - } |
|
123 | - |
|
124 | - public function getHTMLName() { |
|
125 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
126 | - } |
|
127 | - |
|
128 | - public function getTitle() { |
|
129 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
130 | - } |
|
131 | - |
|
132 | - public function getEntity() { |
|
133 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
134 | - } |
|
135 | - |
|
136 | - public function getBaseUrl() { |
|
137 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
138 | - } |
|
139 | - |
|
140 | - public function getSlogan() { |
|
141 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
142 | - } |
|
143 | - |
|
144 | - public function getImprintUrl() { |
|
145 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
146 | - } |
|
147 | - |
|
148 | - public function getPrivacyUrl() { |
|
149 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
150 | - } |
|
151 | - |
|
152 | - public function getShortFooter() { |
|
153 | - $slogan = $this->getSlogan(); |
|
154 | - $baseUrl = $this->getBaseUrl(); |
|
155 | - if ($baseUrl !== '') { |
|
156 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
157 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
158 | - } else { |
|
159 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
160 | - } |
|
161 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
162 | - |
|
163 | - $links = [ |
|
164 | - [ |
|
165 | - 'text' => $this->l->t('Legal notice'), |
|
166 | - 'url' => (string)$this->getImprintUrl() |
|
167 | - ], |
|
168 | - [ |
|
169 | - 'text' => $this->l->t('Privacy policy'), |
|
170 | - 'url' => (string)$this->getPrivacyUrl() |
|
171 | - ], |
|
172 | - ]; |
|
173 | - |
|
174 | - $legalLinks = ''; $divider = ''; |
|
175 | - foreach($links as $link) { |
|
176 | - if($link['url'] !== '' |
|
177 | - && filter_var($link['url'], FILTER_VALIDATE_URL, [ |
|
178 | - 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
|
179 | - ]) |
|
180 | - ) { |
|
181 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
182 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
183 | - $divider = ' · '; |
|
184 | - } |
|
185 | - } |
|
186 | - if($legalLinks !== '' ) { |
|
187 | - $footer .= '<br/>' . $legalLinks; |
|
188 | - } |
|
189 | - |
|
190 | - return $footer; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Color that is used for the header as well as for mail headers |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function getColorPrimary() { |
|
199 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Themed logo url |
|
204 | - * |
|
205 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function getLogo($useSvg = true): string { |
|
209 | - $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
210 | - |
|
211 | - $logoExists = true; |
|
212 | - try { |
|
213 | - $this->imageManager->getImage('logo', $useSvg); |
|
214 | - } catch (\Exception $e) { |
|
215 | - $logoExists = false; |
|
216 | - } |
|
217 | - |
|
218 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
219 | - |
|
220 | - if(!$logo || !$logoExists) { |
|
221 | - if($useSvg) { |
|
222 | - $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
223 | - } else { |
|
224 | - $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
225 | - } |
|
226 | - return $logo . '?v=' . $cacheBusterCounter; |
|
227 | - } |
|
228 | - |
|
229 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Themed background image url |
|
234 | - * |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function getBackground(): string { |
|
238 | - return $this->imageManager->getImageUrl('background'); |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function getiTunesAppId() { |
|
245 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function getiOSClientUrl() { |
|
252 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function getAndroidClientUrl() { |
|
259 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return array scss variables to overwrite |
|
265 | - */ |
|
266 | - public function getScssVariables() { |
|
267 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
268 | - if ($value = $cache->get('getScssVariables')) { |
|
269 | - return $value; |
|
270 | - } |
|
271 | - |
|
272 | - $variables = [ |
|
273 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
274 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
275 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
276 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
277 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
278 | - ]; |
|
279 | - |
|
280 | - $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
281 | - $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
282 | - $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
283 | - $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
284 | - $variables['image-login-plain'] = 'false'; |
|
285 | - |
|
286 | - if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
287 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
288 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
289 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
290 | - } |
|
291 | - |
|
292 | - if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
293 | - $variables['image-login-plain'] = 'true'; |
|
294 | - } |
|
295 | - |
|
296 | - $variables['has-legal-links'] = 'false'; |
|
297 | - if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
298 | - $variables['has-legal-links'] = 'true'; |
|
299 | - } |
|
300 | - |
|
301 | - $cache->set('getScssVariables', $variables); |
|
302 | - return $variables; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Check if the image should be replaced by the theming app |
|
307 | - * and return the new image location then |
|
308 | - * |
|
309 | - * @param string $app name of the app |
|
310 | - * @param string $image filename of the image |
|
311 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
312 | - */ |
|
313 | - public function replaceImagePath($app, $image) { |
|
314 | - if($app==='') { |
|
315 | - $app = 'core'; |
|
316 | - } |
|
317 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
318 | - |
|
319 | - try { |
|
320 | - $customFavicon = $this->imageManager->getImage('favicon'); |
|
321 | - } catch (NotFoundException $e) { |
|
322 | - $customFavicon = null; |
|
323 | - } |
|
324 | - |
|
325 | - if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
326 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
327 | - } |
|
328 | - if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
329 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
330 | - } |
|
331 | - if ($image === 'manifest.json') { |
|
332 | - try { |
|
333 | - $appPath = $this->appManager->getAppPath($app); |
|
334 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
335 | - return false; |
|
336 | - } |
|
337 | - } catch (AppPathNotFoundException $e) {} |
|
338 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
339 | - } |
|
340 | - return false; |
|
341 | - } |
|
47 | + /** @var IConfig */ |
|
48 | + private $config; |
|
49 | + /** @var IL10N */ |
|
50 | + private $l; |
|
51 | + /** @var ImageManager */ |
|
52 | + private $imageManager; |
|
53 | + /** @var IURLGenerator */ |
|
54 | + private $urlGenerator; |
|
55 | + /** @var ICacheFactory */ |
|
56 | + private $cacheFactory; |
|
57 | + /** @var Util */ |
|
58 | + private $util; |
|
59 | + /** @var IAppManager */ |
|
60 | + private $appManager; |
|
61 | + /** @var string */ |
|
62 | + private $name; |
|
63 | + /** @var string */ |
|
64 | + private $title; |
|
65 | + /** @var string */ |
|
66 | + private $entity; |
|
67 | + /** @var string */ |
|
68 | + private $url; |
|
69 | + /** @var string */ |
|
70 | + private $slogan; |
|
71 | + /** @var string */ |
|
72 | + private $color; |
|
73 | + |
|
74 | + /** @var string */ |
|
75 | + private $iTunesAppId; |
|
76 | + /** @var string */ |
|
77 | + private $iOSClientUrl; |
|
78 | + /** @var string */ |
|
79 | + private $AndroidClientUrl; |
|
80 | + |
|
81 | + /** |
|
82 | + * ThemingDefaults constructor. |
|
83 | + * |
|
84 | + * @param IConfig $config |
|
85 | + * @param IL10N $l |
|
86 | + * @param ImageManager $imageManager |
|
87 | + * @param IURLGenerator $urlGenerator |
|
88 | + * @param ICacheFactory $cacheFactory |
|
89 | + * @param Util $util |
|
90 | + * @param IAppManager $appManager |
|
91 | + */ |
|
92 | + public function __construct(IConfig $config, |
|
93 | + IL10N $l, |
|
94 | + IURLGenerator $urlGenerator, |
|
95 | + ICacheFactory $cacheFactory, |
|
96 | + Util $util, |
|
97 | + ImageManager $imageManager, |
|
98 | + IAppManager $appManager |
|
99 | + ) { |
|
100 | + parent::__construct(); |
|
101 | + $this->config = $config; |
|
102 | + $this->l = $l; |
|
103 | + $this->imageManager = $imageManager; |
|
104 | + $this->urlGenerator = $urlGenerator; |
|
105 | + $this->cacheFactory = $cacheFactory; |
|
106 | + $this->util = $util; |
|
107 | + $this->appManager = $appManager; |
|
108 | + |
|
109 | + $this->name = parent::getName(); |
|
110 | + $this->title = parent::getTitle(); |
|
111 | + $this->entity = parent::getEntity(); |
|
112 | + $this->url = parent::getBaseUrl(); |
|
113 | + $this->slogan = parent::getSlogan(); |
|
114 | + $this->color = parent::getColorPrimary(); |
|
115 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
116 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
117 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
118 | + } |
|
119 | + |
|
120 | + public function getName() { |
|
121 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
122 | + } |
|
123 | + |
|
124 | + public function getHTMLName() { |
|
125 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
126 | + } |
|
127 | + |
|
128 | + public function getTitle() { |
|
129 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
130 | + } |
|
131 | + |
|
132 | + public function getEntity() { |
|
133 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
134 | + } |
|
135 | + |
|
136 | + public function getBaseUrl() { |
|
137 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
138 | + } |
|
139 | + |
|
140 | + public function getSlogan() { |
|
141 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
142 | + } |
|
143 | + |
|
144 | + public function getImprintUrl() { |
|
145 | + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
146 | + } |
|
147 | + |
|
148 | + public function getPrivacyUrl() { |
|
149 | + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
150 | + } |
|
151 | + |
|
152 | + public function getShortFooter() { |
|
153 | + $slogan = $this->getSlogan(); |
|
154 | + $baseUrl = $this->getBaseUrl(); |
|
155 | + if ($baseUrl !== '') { |
|
156 | + $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
157 | + ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
158 | + } else { |
|
159 | + $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
160 | + } |
|
161 | + $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
162 | + |
|
163 | + $links = [ |
|
164 | + [ |
|
165 | + 'text' => $this->l->t('Legal notice'), |
|
166 | + 'url' => (string)$this->getImprintUrl() |
|
167 | + ], |
|
168 | + [ |
|
169 | + 'text' => $this->l->t('Privacy policy'), |
|
170 | + 'url' => (string)$this->getPrivacyUrl() |
|
171 | + ], |
|
172 | + ]; |
|
173 | + |
|
174 | + $legalLinks = ''; $divider = ''; |
|
175 | + foreach($links as $link) { |
|
176 | + if($link['url'] !== '' |
|
177 | + && filter_var($link['url'], FILTER_VALIDATE_URL, [ |
|
178 | + 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
|
179 | + ]) |
|
180 | + ) { |
|
181 | + $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
182 | + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
183 | + $divider = ' · '; |
|
184 | + } |
|
185 | + } |
|
186 | + if($legalLinks !== '' ) { |
|
187 | + $footer .= '<br/>' . $legalLinks; |
|
188 | + } |
|
189 | + |
|
190 | + return $footer; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Color that is used for the header as well as for mail headers |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function getColorPrimary() { |
|
199 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Themed logo url |
|
204 | + * |
|
205 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function getLogo($useSvg = true): string { |
|
209 | + $logo = $this->config->getAppValue('theming', 'logoMime', false); |
|
210 | + |
|
211 | + $logoExists = true; |
|
212 | + try { |
|
213 | + $this->imageManager->getImage('logo', $useSvg); |
|
214 | + } catch (\Exception $e) { |
|
215 | + $logoExists = false; |
|
216 | + } |
|
217 | + |
|
218 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
219 | + |
|
220 | + if(!$logo || !$logoExists) { |
|
221 | + if($useSvg) { |
|
222 | + $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
|
223 | + } else { |
|
224 | + $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
|
225 | + } |
|
226 | + return $logo . '?v=' . $cacheBusterCounter; |
|
227 | + } |
|
228 | + |
|
229 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Themed background image url |
|
234 | + * |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function getBackground(): string { |
|
238 | + return $this->imageManager->getImageUrl('background'); |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function getiTunesAppId() { |
|
245 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function getiOSClientUrl() { |
|
252 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function getAndroidClientUrl() { |
|
259 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return array scss variables to overwrite |
|
265 | + */ |
|
266 | + public function getScssVariables() { |
|
267 | + $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
268 | + if ($value = $cache->get('getScssVariables')) { |
|
269 | + return $value; |
|
270 | + } |
|
271 | + |
|
272 | + $variables = [ |
|
273 | + 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
274 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
275 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
276 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
277 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
278 | + ]; |
|
279 | + |
|
280 | + $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
281 | + $variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'"; |
|
282 | + $variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'"; |
|
283 | + $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
284 | + $variables['image-login-plain'] = 'false'; |
|
285 | + |
|
286 | + if ($this->config->getAppValue('theming', 'color', null) !== null) { |
|
287 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
288 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
289 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
290 | + } |
|
291 | + |
|
292 | + if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') { |
|
293 | + $variables['image-login-plain'] = 'true'; |
|
294 | + } |
|
295 | + |
|
296 | + $variables['has-legal-links'] = 'false'; |
|
297 | + if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
298 | + $variables['has-legal-links'] = 'true'; |
|
299 | + } |
|
300 | + |
|
301 | + $cache->set('getScssVariables', $variables); |
|
302 | + return $variables; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Check if the image should be replaced by the theming app |
|
307 | + * and return the new image location then |
|
308 | + * |
|
309 | + * @param string $app name of the app |
|
310 | + * @param string $image filename of the image |
|
311 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
312 | + */ |
|
313 | + public function replaceImagePath($app, $image) { |
|
314 | + if($app==='') { |
|
315 | + $app = 'core'; |
|
316 | + } |
|
317 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
318 | + |
|
319 | + try { |
|
320 | + $customFavicon = $this->imageManager->getImage('favicon'); |
|
321 | + } catch (NotFoundException $e) { |
|
322 | + $customFavicon = null; |
|
323 | + } |
|
324 | + |
|
325 | + if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
326 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
327 | + } |
|
328 | + if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
|
329 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
330 | + } |
|
331 | + if ($image === 'manifest.json') { |
|
332 | + try { |
|
333 | + $appPath = $this->appManager->getAppPath($app); |
|
334 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
335 | + return false; |
|
336 | + } |
|
337 | + } catch (AppPathNotFoundException $e) {} |
|
338 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
339 | + } |
|
340 | + return false; |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Increases the cache buster key |
|
345 | - */ |
|
346 | - private function increaseCacheBuster() { |
|
347 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
348 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
349 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
350 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Update setting in the database |
|
356 | - * |
|
357 | - * @param string $setting |
|
358 | - * @param string $value |
|
359 | - */ |
|
360 | - public function set($setting, $value) { |
|
361 | - $this->config->setAppValue('theming', $setting, $value); |
|
362 | - $this->increaseCacheBuster(); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Revert settings to the default value |
|
367 | - * |
|
368 | - * @param string $setting setting which should be reverted |
|
369 | - * @return string default value |
|
370 | - */ |
|
371 | - public function undo($setting) { |
|
372 | - $this->config->deleteAppValue('theming', $setting); |
|
373 | - $this->increaseCacheBuster(); |
|
374 | - |
|
375 | - switch ($setting) { |
|
376 | - case 'name': |
|
377 | - $returnValue = $this->getEntity(); |
|
378 | - break; |
|
379 | - case 'url': |
|
380 | - $returnValue = $this->getBaseUrl(); |
|
381 | - break; |
|
382 | - case 'slogan': |
|
383 | - $returnValue = $this->getSlogan(); |
|
384 | - break; |
|
385 | - case 'color': |
|
386 | - $returnValue = $this->getColorPrimary(); |
|
387 | - break; |
|
388 | - default: |
|
389 | - $returnValue = ''; |
|
390 | - break; |
|
391 | - } |
|
392 | - |
|
393 | - return $returnValue; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Color of text in the header and primary buttons |
|
398 | - * |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function getTextColorPrimary() { |
|
402 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
403 | - } |
|
343 | + /** |
|
344 | + * Increases the cache buster key |
|
345 | + */ |
|
346 | + private function increaseCacheBuster() { |
|
347 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
348 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
349 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
350 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Update setting in the database |
|
356 | + * |
|
357 | + * @param string $setting |
|
358 | + * @param string $value |
|
359 | + */ |
|
360 | + public function set($setting, $value) { |
|
361 | + $this->config->setAppValue('theming', $setting, $value); |
|
362 | + $this->increaseCacheBuster(); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Revert settings to the default value |
|
367 | + * |
|
368 | + * @param string $setting setting which should be reverted |
|
369 | + * @return string default value |
|
370 | + */ |
|
371 | + public function undo($setting) { |
|
372 | + $this->config->deleteAppValue('theming', $setting); |
|
373 | + $this->increaseCacheBuster(); |
|
374 | + |
|
375 | + switch ($setting) { |
|
376 | + case 'name': |
|
377 | + $returnValue = $this->getEntity(); |
|
378 | + break; |
|
379 | + case 'url': |
|
380 | + $returnValue = $this->getBaseUrl(); |
|
381 | + break; |
|
382 | + case 'slogan': |
|
383 | + $returnValue = $this->getSlogan(); |
|
384 | + break; |
|
385 | + case 'color': |
|
386 | + $returnValue = $this->getColorPrimary(); |
|
387 | + break; |
|
388 | + default: |
|
389 | + $returnValue = ''; |
|
390 | + break; |
|
391 | + } |
|
392 | + |
|
393 | + return $returnValue; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Color of text in the header and primary buttons |
|
398 | + * |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function getTextColorPrimary() { |
|
402 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
403 | + } |
|
404 | 404 | } |
@@ -142,49 +142,49 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public function getImprintUrl() { |
145 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
145 | + return (string) $this->config->getAppValue('theming', 'imprintUrl', ''); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | public function getPrivacyUrl() { |
149 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
149 | + return (string) $this->config->getAppValue('theming', 'privacyUrl', ''); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | public function getShortFooter() { |
153 | 153 | $slogan = $this->getSlogan(); |
154 | 154 | $baseUrl = $this->getBaseUrl(); |
155 | 155 | if ($baseUrl !== '') { |
156 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
157 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
156 | + $footer = '<a href="'.$baseUrl.'" target="_blank"'. |
|
157 | + ' rel="noreferrer noopener" class="entity-name">'.$this->getEntity().'</a>'; |
|
158 | 158 | } else { |
159 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
159 | + $footer = '<span class="entity-name">'.$this->getEntity().'</span>'; |
|
160 | 160 | } |
161 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
161 | + $footer .= ($slogan !== '' ? ' – '.$slogan : ''); |
|
162 | 162 | |
163 | 163 | $links = [ |
164 | 164 | [ |
165 | 165 | 'text' => $this->l->t('Legal notice'), |
166 | - 'url' => (string)$this->getImprintUrl() |
|
166 | + 'url' => (string) $this->getImprintUrl() |
|
167 | 167 | ], |
168 | 168 | [ |
169 | 169 | 'text' => $this->l->t('Privacy policy'), |
170 | - 'url' => (string)$this->getPrivacyUrl() |
|
170 | + 'url' => (string) $this->getPrivacyUrl() |
|
171 | 171 | ], |
172 | 172 | ]; |
173 | 173 | |
174 | 174 | $legalLinks = ''; $divider = ''; |
175 | - foreach($links as $link) { |
|
176 | - if($link['url'] !== '' |
|
175 | + foreach ($links as $link) { |
|
176 | + if ($link['url'] !== '' |
|
177 | 177 | && filter_var($link['url'], FILTER_VALIDATE_URL, [ |
178 | 178 | 'flags' => FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
179 | 179 | ]) |
180 | 180 | ) { |
181 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
182 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
181 | + $legalLinks .= $divider.'<a href="'.$link['url'].'" class="legal" target="_blank"'. |
|
182 | + ' rel="noreferrer noopener">'.$link['text'].'</a>'; |
|
183 | 183 | $divider = ' · '; |
184 | 184 | } |
185 | 185 | } |
186 | - if($legalLinks !== '' ) { |
|
187 | - $footer .= '<br/>' . $legalLinks; |
|
186 | + if ($legalLinks !== '') { |
|
187 | + $footer .= '<br/>'.$legalLinks; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $footer; |
@@ -217,16 +217,16 @@ discard block |
||
217 | 217 | |
218 | 218 | $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
219 | 219 | |
220 | - if(!$logo || !$logoExists) { |
|
221 | - if($useSvg) { |
|
220 | + if (!$logo || !$logoExists) { |
|
221 | + if ($useSvg) { |
|
222 | 222 | $logo = $this->urlGenerator->imagePath('core', 'logo.svg'); |
223 | 223 | } else { |
224 | 224 | $logo = $this->urlGenerator->imagePath('core', 'logo.png'); |
225 | 225 | } |
226 | - return $logo . '?v=' . $cacheBusterCounter; |
|
226 | + return $logo.'?v='.$cacheBusterCounter; |
|
227 | 227 | } |
228 | 228 | |
229 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
229 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', ['key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter]); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -264,17 +264,17 @@ discard block |
||
264 | 264 | * @return array scss variables to overwrite |
265 | 265 | */ |
266 | 266 | public function getScssVariables() { |
267 | - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); |
|
267 | + $cache = $this->cacheFactory->createDistributed('theming-'.$this->urlGenerator->getBaseUrl()); |
|
268 | 268 | if ($value = $cache->get('getScssVariables')) { |
269 | 269 | return $value; |
270 | 270 | } |
271 | 271 | |
272 | 272 | $variables = [ |
273 | - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", |
|
274 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
275 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
276 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
277 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
273 | + 'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'", |
|
274 | + 'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime')."'", |
|
275 | + 'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime')."'", |
|
276 | + 'theming-logoheader-mime' => "'".$this->config->getAppValue('theming', 'logoheaderMime')."'", |
|
277 | + 'theming-favicon-mime' => "'".$this->config->getAppValue('theming', 'faviconMime')."'" |
|
278 | 278 | ]; |
279 | 279 | |
280 | 280 | $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | $variables['has-legal-links'] = 'false'; |
297 | - if($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
297 | + if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
298 | 298 | $variables['has-legal-links'] = 'true'; |
299 | 299 | } |
300 | 300 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @return bool|string false if image should not replaced, otherwise the location of the image |
312 | 312 | */ |
313 | 313 | public function replaceImagePath($app, $image) { |
314 | - if($app==='') { |
|
314 | + if ($app === '') { |
|
315 | 315 | $app = 'core'; |
316 | 316 | } |
317 | 317 | $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
@@ -323,19 +323,19 @@ discard block |
||
323 | 323 | } |
324 | 324 | |
325 | 325 | if ($image === 'favicon.ico' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
326 | - return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
326 | + return $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
327 | 327 | } |
328 | 328 | if ($image === 'favicon-touch.png' && ($customFavicon !== null || $this->imageManager->shouldReplaceIcons())) { |
329 | - return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]) . '?v=' . $cacheBusterValue; |
|
329 | + return $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]).'?v='.$cacheBusterValue; |
|
330 | 330 | } |
331 | 331 | if ($image === 'manifest.json') { |
332 | 332 | try { |
333 | 333 | $appPath = $this->appManager->getAppPath($app); |
334 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
334 | + if (file_exists($appPath.'/img/manifest.json')) { |
|
335 | 335 | return false; |
336 | 336 | } |
337 | 337 | } catch (AppPathNotFoundException $e) {} |
338 | - return $this->urlGenerator->linkToRoute('theming.Theming.getManifest') . '?v=' . $cacheBusterValue; |
|
338 | + return $this->urlGenerator->linkToRoute('theming.Theming.getManifest').'?v='.$cacheBusterValue; |
|
339 | 339 | } |
340 | 340 | return false; |
341 | 341 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | private function increaseCacheBuster() { |
347 | 347 | $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
348 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
348 | + $this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1); |
|
349 | 349 | $this->cacheFactory->createDistributed('theming-')->clear(); |
350 | 350 | $this->cacheFactory->createDistributed('imagePath')->clear(); |
351 | 351 |