@@ -39,220 +39,220 @@ |
||
39 | 39 | * @since 6.0.0 |
40 | 40 | */ |
41 | 41 | class Defaults { |
42 | - /** |
|
43 | - * \OC_Defaults instance to retrieve the defaults |
|
44 | - * @since 6.0.0 |
|
45 | - */ |
|
46 | - private $defaults; |
|
42 | + /** |
|
43 | + * \OC_Defaults instance to retrieve the defaults |
|
44 | + * @since 6.0.0 |
|
45 | + */ |
|
46 | + private $defaults; |
|
47 | 47 | |
48 | - /** |
|
49 | - * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
50 | - * actual defaults |
|
51 | - * @since 6.0.0 |
|
52 | - */ |
|
53 | - public function __construct(\OC_Defaults $defaults = null) { |
|
54 | - if ($defaults === null) { |
|
55 | - $defaults = \OC::$server->getThemingDefaults(); |
|
56 | - } |
|
57 | - $this->defaults = $defaults; |
|
58 | - } |
|
48 | + /** |
|
49 | + * creates a \OC_Defaults instance which is used in all methods to retrieve the |
|
50 | + * actual defaults |
|
51 | + * @since 6.0.0 |
|
52 | + */ |
|
53 | + public function __construct(\OC_Defaults $defaults = null) { |
|
54 | + if ($defaults === null) { |
|
55 | + $defaults = \OC::$server->getThemingDefaults(); |
|
56 | + } |
|
57 | + $this->defaults = $defaults; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * get base URL for the organisation behind your ownCloud instance |
|
62 | - * @return string |
|
63 | - * @since 6.0.0 |
|
64 | - */ |
|
65 | - public function getBaseUrl(): string { |
|
66 | - return $this->defaults->getBaseUrl(); |
|
67 | - } |
|
60 | + /** |
|
61 | + * get base URL for the organisation behind your ownCloud instance |
|
62 | + * @return string |
|
63 | + * @since 6.0.0 |
|
64 | + */ |
|
65 | + public function getBaseUrl(): string { |
|
66 | + return $this->defaults->getBaseUrl(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * link to the desktop sync client |
|
71 | - * @return string |
|
72 | - * @since 6.0.0 |
|
73 | - */ |
|
74 | - public function getSyncClientUrl(): string { |
|
75 | - return $this->defaults->getSyncClientUrl(); |
|
76 | - } |
|
69 | + /** |
|
70 | + * link to the desktop sync client |
|
71 | + * @return string |
|
72 | + * @since 6.0.0 |
|
73 | + */ |
|
74 | + public function getSyncClientUrl(): string { |
|
75 | + return $this->defaults->getSyncClientUrl(); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * link to the iOS client |
|
80 | - * @return string |
|
81 | - * @since 8.0.0 |
|
82 | - */ |
|
83 | - public function getiOSClientUrl(): string { |
|
84 | - return $this->defaults->getiOSClientUrl(); |
|
85 | - } |
|
78 | + /** |
|
79 | + * link to the iOS client |
|
80 | + * @return string |
|
81 | + * @since 8.0.0 |
|
82 | + */ |
|
83 | + public function getiOSClientUrl(): string { |
|
84 | + return $this->defaults->getiOSClientUrl(); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * link to the Android client |
|
89 | - * @return string |
|
90 | - * @since 8.0.0 |
|
91 | - */ |
|
92 | - public function getAndroidClientUrl(): string { |
|
93 | - return $this->defaults->getAndroidClientUrl(); |
|
94 | - } |
|
87 | + /** |
|
88 | + * link to the Android client |
|
89 | + * @return string |
|
90 | + * @since 8.0.0 |
|
91 | + */ |
|
92 | + public function getAndroidClientUrl(): string { |
|
93 | + return $this->defaults->getAndroidClientUrl(); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * link to the Android client on F-Droid |
|
98 | - * @return string |
|
99 | - * @since 23.0.0 |
|
100 | - */ |
|
101 | - public function getFDroidClientUrl() { |
|
102 | - return $this->defaults->getFDroidClientUrl(); |
|
103 | - } |
|
96 | + /** |
|
97 | + * link to the Android client on F-Droid |
|
98 | + * @return string |
|
99 | + * @since 23.0.0 |
|
100 | + */ |
|
101 | + public function getFDroidClientUrl() { |
|
102 | + return $this->defaults->getFDroidClientUrl(); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * base URL to the documentation of your ownCloud instance |
|
107 | - * @return string |
|
108 | - * @since 6.0.0 |
|
109 | - */ |
|
110 | - public function getDocBaseUrl(): string { |
|
111 | - return $this->defaults->getDocBaseUrl(); |
|
112 | - } |
|
105 | + /** |
|
106 | + * base URL to the documentation of your ownCloud instance |
|
107 | + * @return string |
|
108 | + * @since 6.0.0 |
|
109 | + */ |
|
110 | + public function getDocBaseUrl(): string { |
|
111 | + return $this->defaults->getDocBaseUrl(); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * name of your Nextcloud instance (e.g. MyPrivateCloud) |
|
116 | - * @return string |
|
117 | - * @since 6.0.0 |
|
118 | - */ |
|
119 | - public function getName(): string { |
|
120 | - return $this->defaults->getName(); |
|
121 | - } |
|
114 | + /** |
|
115 | + * name of your Nextcloud instance (e.g. MyPrivateCloud) |
|
116 | + * @return string |
|
117 | + * @since 6.0.0 |
|
118 | + */ |
|
119 | + public function getName(): string { |
|
120 | + return $this->defaults->getName(); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Name of the software product (defaults to Nextcloud) |
|
125 | - * |
|
126 | - * @return string |
|
127 | - * @since 22.0.0 |
|
128 | - */ |
|
129 | - public function getProductName(): string { |
|
130 | - return $this->defaults->getProductName(); |
|
131 | - } |
|
123 | + /** |
|
124 | + * Name of the software product (defaults to Nextcloud) |
|
125 | + * |
|
126 | + * @return string |
|
127 | + * @since 22.0.0 |
|
128 | + */ |
|
129 | + public function getProductName(): string { |
|
130 | + return $this->defaults->getProductName(); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * name of your ownCloud instance containing HTML styles |
|
135 | - * @return string |
|
136 | - * @since 8.0.0 |
|
137 | - * @deprecated 22.0.0 |
|
138 | - */ |
|
139 | - public function getHTMLName(): string { |
|
140 | - return $this->defaults->getHTMLName(); |
|
141 | - } |
|
133 | + /** |
|
134 | + * name of your ownCloud instance containing HTML styles |
|
135 | + * @return string |
|
136 | + * @since 8.0.0 |
|
137 | + * @deprecated 22.0.0 |
|
138 | + */ |
|
139 | + public function getHTMLName(): string { |
|
140 | + return $this->defaults->getHTMLName(); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Entity behind your onwCloud instance |
|
145 | - * @return string |
|
146 | - * @since 6.0.0 |
|
147 | - */ |
|
148 | - public function getEntity(): string { |
|
149 | - return $this->defaults->getEntity(); |
|
150 | - } |
|
143 | + /** |
|
144 | + * Entity behind your onwCloud instance |
|
145 | + * @return string |
|
146 | + * @since 6.0.0 |
|
147 | + */ |
|
148 | + public function getEntity(): string { |
|
149 | + return $this->defaults->getEntity(); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * ownCloud slogan |
|
154 | - * @return string |
|
155 | - * @since 6.0.0 |
|
156 | - */ |
|
157 | - public function getSlogan(?string $lang = null): string { |
|
158 | - return $this->defaults->getSlogan($lang); |
|
159 | - } |
|
152 | + /** |
|
153 | + * ownCloud slogan |
|
154 | + * @return string |
|
155 | + * @since 6.0.0 |
|
156 | + */ |
|
157 | + public function getSlogan(?string $lang = null): string { |
|
158 | + return $this->defaults->getSlogan($lang); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * footer, short version |
|
163 | - * @return string |
|
164 | - * @since 6.0.0 |
|
165 | - */ |
|
166 | - public function getShortFooter(): string { |
|
167 | - return $this->defaults->getShortFooter(); |
|
168 | - } |
|
161 | + /** |
|
162 | + * footer, short version |
|
163 | + * @return string |
|
164 | + * @since 6.0.0 |
|
165 | + */ |
|
166 | + public function getShortFooter(): string { |
|
167 | + return $this->defaults->getShortFooter(); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * footer, long version |
|
172 | - * @return string |
|
173 | - * @since 6.0.0 |
|
174 | - */ |
|
175 | - public function getLongFooter(): string { |
|
176 | - return $this->defaults->getLongFooter(); |
|
177 | - } |
|
170 | + /** |
|
171 | + * footer, long version |
|
172 | + * @return string |
|
173 | + * @since 6.0.0 |
|
174 | + */ |
|
175 | + public function getLongFooter(): string { |
|
176 | + return $this->defaults->getLongFooter(); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Returns the AppId for the App Store for the iOS Client |
|
181 | - * @return string AppId |
|
182 | - * @since 8.0.0 |
|
183 | - */ |
|
184 | - public function getiTunesAppId(): string { |
|
185 | - return $this->defaults->getiTunesAppId(); |
|
186 | - } |
|
179 | + /** |
|
180 | + * Returns the AppId for the App Store for the iOS Client |
|
181 | + * @return string AppId |
|
182 | + * @since 8.0.0 |
|
183 | + */ |
|
184 | + public function getiTunesAppId(): string { |
|
185 | + return $this->defaults->getiTunesAppId(); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Themed logo url |
|
190 | - * |
|
191 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
192 | - * @return string |
|
193 | - * @since 12.0.0 |
|
194 | - */ |
|
195 | - public function getLogo(bool $useSvg = true): string { |
|
196 | - return $this->defaults->getLogo($useSvg); |
|
197 | - } |
|
188 | + /** |
|
189 | + * Themed logo url |
|
190 | + * |
|
191 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
192 | + * @return string |
|
193 | + * @since 12.0.0 |
|
194 | + */ |
|
195 | + public function getLogo(bool $useSvg = true): string { |
|
196 | + return $this->defaults->getLogo($useSvg); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Returns primary color |
|
201 | - * @return string |
|
202 | - * @since 12.0.0 |
|
203 | - */ |
|
204 | - public function getColorPrimary(): string { |
|
205 | - return $this->defaults->getColorPrimary(); |
|
206 | - } |
|
199 | + /** |
|
200 | + * Returns primary color |
|
201 | + * @return string |
|
202 | + * @since 12.0.0 |
|
203 | + */ |
|
204 | + public function getColorPrimary(): string { |
|
205 | + return $this->defaults->getColorPrimary(); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Return the default color primary |
|
210 | - * @return string |
|
211 | - * @since 25.0.4 |
|
212 | - */ |
|
213 | - public function getDefaultColorPrimary(): string { |
|
214 | - if (method_exists($this->defaults, 'getDefaultColorPrimary')) { |
|
215 | - return $this->defaults->getDefaultColorPrimary(); |
|
216 | - } |
|
217 | - return $this->defaults->getColorPrimary(); |
|
218 | - } |
|
208 | + /** |
|
209 | + * Return the default color primary |
|
210 | + * @return string |
|
211 | + * @since 25.0.4 |
|
212 | + */ |
|
213 | + public function getDefaultColorPrimary(): string { |
|
214 | + if (method_exists($this->defaults, 'getDefaultColorPrimary')) { |
|
215 | + return $this->defaults->getDefaultColorPrimary(); |
|
216 | + } |
|
217 | + return $this->defaults->getColorPrimary(); |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * @param string $key |
|
222 | - * @return string URL to doc with key |
|
223 | - * @since 12.0.0 |
|
224 | - */ |
|
225 | - public function buildDocLinkToKey(string $key): string { |
|
226 | - return $this->defaults->buildDocLinkToKey($key); |
|
227 | - } |
|
220 | + /** |
|
221 | + * @param string $key |
|
222 | + * @return string URL to doc with key |
|
223 | + * @since 12.0.0 |
|
224 | + */ |
|
225 | + public function buildDocLinkToKey(string $key): string { |
|
226 | + return $this->defaults->buildDocLinkToKey($key); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Returns the title |
|
231 | - * @return string title |
|
232 | - * @since 12.0.0 |
|
233 | - */ |
|
234 | - public function getTitle(): string { |
|
235 | - return $this->defaults->getTitle(); |
|
236 | - } |
|
229 | + /** |
|
230 | + * Returns the title |
|
231 | + * @return string title |
|
232 | + * @since 12.0.0 |
|
233 | + */ |
|
234 | + public function getTitle(): string { |
|
235 | + return $this->defaults->getTitle(); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * Returns primary color |
|
240 | - * @return string |
|
241 | - * @since 13.0.0 |
|
242 | - */ |
|
243 | - public function getTextColorPrimary(): string { |
|
244 | - return $this->defaults->getTextColorPrimary(); |
|
245 | - } |
|
238 | + /** |
|
239 | + * Returns primary color |
|
240 | + * @return string |
|
241 | + * @since 13.0.0 |
|
242 | + */ |
|
243 | + public function getTextColorPrimary(): string { |
|
244 | + return $this->defaults->getTextColorPrimary(); |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Returns primary color |
|
249 | - * @return string |
|
250 | - * @since 25.0.4 |
|
251 | - */ |
|
252 | - public function getDefaultTextColorPrimary(): string { |
|
253 | - if (method_exists($this->defaults, 'getDefaultTextColorPrimary')) { |
|
254 | - return $this->defaults->getDefaultTextColorPrimary(); |
|
255 | - } |
|
256 | - return $this->defaults->getTextColorPrimary(); |
|
257 | - } |
|
247 | + /** |
|
248 | + * Returns primary color |
|
249 | + * @return string |
|
250 | + * @since 25.0.4 |
|
251 | + */ |
|
252 | + public function getDefaultTextColorPrimary(): string { |
|
253 | + if (method_exists($this->defaults, 'getDefaultTextColorPrimary')) { |
|
254 | + return $this->defaults->getDefaultTextColorPrimary(); |
|
255 | + } |
|
256 | + return $this->defaults->getTextColorPrimary(); |
|
257 | + } |
|
258 | 258 | } |
@@ -52,33 +52,33 @@ discard block |
||
52 | 52 | * @package OC\Mail |
53 | 53 | */ |
54 | 54 | class EMailTemplate implements IEMailTemplate { |
55 | - /** @var Defaults */ |
|
56 | - protected $themingDefaults; |
|
57 | - /** @var IURLGenerator */ |
|
58 | - protected $urlGenerator; |
|
59 | - /** @var IFactory */ |
|
60 | - protected $l10nFactory; |
|
61 | - /** @var string */ |
|
62 | - protected $emailId; |
|
63 | - /** @var array */ |
|
64 | - protected $data; |
|
65 | - |
|
66 | - /** @var string */ |
|
67 | - protected $subject = ''; |
|
68 | - /** @var string */ |
|
69 | - protected $htmlBody = ''; |
|
70 | - /** @var string */ |
|
71 | - protected $plainBody = ''; |
|
72 | - /** @var bool indicated if the footer is added */ |
|
73 | - protected $headerAdded = false; |
|
74 | - /** @var bool indicated if the body is already opened */ |
|
75 | - protected $bodyOpened = false; |
|
76 | - /** @var bool indicated if there is a list open in the body */ |
|
77 | - protected $bodyListOpened = false; |
|
78 | - /** @var bool indicated if the footer is added */ |
|
79 | - protected $footerAdded = false; |
|
80 | - |
|
81 | - protected $head = <<<EOF |
|
55 | + /** @var Defaults */ |
|
56 | + protected $themingDefaults; |
|
57 | + /** @var IURLGenerator */ |
|
58 | + protected $urlGenerator; |
|
59 | + /** @var IFactory */ |
|
60 | + protected $l10nFactory; |
|
61 | + /** @var string */ |
|
62 | + protected $emailId; |
|
63 | + /** @var array */ |
|
64 | + protected $data; |
|
65 | + |
|
66 | + /** @var string */ |
|
67 | + protected $subject = ''; |
|
68 | + /** @var string */ |
|
69 | + protected $htmlBody = ''; |
|
70 | + /** @var string */ |
|
71 | + protected $plainBody = ''; |
|
72 | + /** @var bool indicated if the footer is added */ |
|
73 | + protected $headerAdded = false; |
|
74 | + /** @var bool indicated if the body is already opened */ |
|
75 | + protected $bodyOpened = false; |
|
76 | + /** @var bool indicated if there is a list open in the body */ |
|
77 | + protected $bodyListOpened = false; |
|
78 | + /** @var bool indicated if the footer is added */ |
|
79 | + protected $footerAdded = false; |
|
80 | + |
|
81 | + protected $head = <<<EOF |
|
82 | 82 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
83 | 83 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important"> |
84 | 84 | <head> |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | <center data-parsed="" style="min-width:580px;width:100%"> |
97 | 97 | EOF; |
98 | 98 | |
99 | - protected $tail = <<<EOF |
|
99 | + protected $tail = <<<EOF |
|
100 | 100 | </center> |
101 | 101 | </td> |
102 | 102 | </tr> |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | EOF; |
110 | 110 | |
111 | - protected $header = <<<EOF |
|
111 | + protected $header = <<<EOF |
|
112 | 112 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
113 | 113 | <tr style="padding:0;text-align:left;vertical-align:top"> |
114 | 114 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | </table> |
142 | 142 | EOF; |
143 | 143 | |
144 | - protected $heading = <<<EOF |
|
144 | + protected $heading = <<<EOF |
|
145 | 145 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
146 | 146 | <tbody> |
147 | 147 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | </table> |
161 | 161 | EOF; |
162 | 162 | |
163 | - protected $bodyBegin = <<<EOF |
|
163 | + protected $bodyBegin = <<<EOF |
|
164 | 164 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
165 | 165 | <tr style="padding:0;text-align:left;vertical-align:top"> |
166 | 166 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
171 | 171 | EOF; |
172 | 172 | |
173 | - protected $bodyText = <<<EOF |
|
173 | + protected $bodyText = <<<EOF |
|
174 | 174 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
175 | 175 | <tbody> |
176 | 176 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | </table> |
190 | 190 | EOF; |
191 | 191 | |
192 | - // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
193 | - protected $listBegin = <<<EOF |
|
192 | + // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151) |
|
193 | + protected $listBegin = <<<EOF |
|
194 | 194 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%"> |
195 | 195 | <tbody> |
196 | 196 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%"> |
199 | 199 | EOF; |
200 | 200 | |
201 | - protected $listItem = <<<EOF |
|
201 | + protected $listItem = <<<EOF |
|
202 | 202 | <tr style="padding:0;text-align:left;vertical-align:top"> |
203 | 203 | <td style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;"> |
204 | 204 | <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p> |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | </tr> |
211 | 211 | EOF; |
212 | 212 | |
213 | - protected $listEnd = <<<EOF |
|
213 | + protected $listEnd = <<<EOF |
|
214 | 214 | </table> |
215 | 215 | </th> |
216 | 216 | </tr> |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | </table> |
219 | 219 | EOF; |
220 | 220 | |
221 | - protected $buttonGroup = <<<EOF |
|
221 | + protected $buttonGroup = <<<EOF |
|
222 | 222 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
223 | 223 | <tbody> |
224 | 224 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | </table> |
272 | 272 | EOF; |
273 | 273 | |
274 | - protected $button = <<<EOF |
|
274 | + protected $button = <<<EOF |
|
275 | 275 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
276 | 276 | <tbody> |
277 | 277 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | </table> |
312 | 312 | EOF; |
313 | 313 | |
314 | - protected $bodyEnd = <<<EOF |
|
314 | + protected $bodyEnd = <<<EOF |
|
315 | 315 | |
316 | 316 | </td> |
317 | 317 | </tr> |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | </table> |
323 | 323 | EOF; |
324 | 324 | |
325 | - protected $footer = <<<EOF |
|
325 | + protected $footer = <<<EOF |
|
326 | 326 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
327 | 327 | <tbody> |
328 | 328 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -348,331 +348,331 @@ discard block |
||
348 | 348 | </table> |
349 | 349 | EOF; |
350 | 350 | |
351 | - public function __construct(Defaults $themingDefaults, |
|
352 | - IURLGenerator $urlGenerator, |
|
353 | - IFactory $l10nFactory, |
|
354 | - $emailId, |
|
355 | - array $data) { |
|
356 | - $this->themingDefaults = $themingDefaults; |
|
357 | - $this->urlGenerator = $urlGenerator; |
|
358 | - $this->l10nFactory = $l10nFactory; |
|
359 | - $this->htmlBody .= $this->head; |
|
360 | - $this->emailId = $emailId; |
|
361 | - $this->data = $data; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Sets the subject of the email |
|
366 | - * |
|
367 | - * @param string $subject |
|
368 | - */ |
|
369 | - public function setSubject(string $subject) { |
|
370 | - $this->subject = $subject; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Adds a header to the email |
|
375 | - */ |
|
376 | - public function addHeader() { |
|
377 | - if ($this->headerAdded) { |
|
378 | - return; |
|
379 | - } |
|
380 | - $this->headerAdded = true; |
|
381 | - |
|
382 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
383 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Adds a heading to the email |
|
388 | - * |
|
389 | - * @param string $title |
|
390 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
391 | - * if empty the $title is used, if false none will be used |
|
392 | - */ |
|
393 | - public function addHeading(string $title, $plainTitle = '') { |
|
394 | - if ($this->footerAdded) { |
|
395 | - return; |
|
396 | - } |
|
397 | - if ($plainTitle === '') { |
|
398 | - $plainTitle = $title; |
|
399 | - } |
|
400 | - |
|
401 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
402 | - if ($plainTitle !== false) { |
|
403 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Open the HTML body when it is not already |
|
409 | - */ |
|
410 | - protected function ensureBodyIsOpened() { |
|
411 | - if ($this->bodyOpened) { |
|
412 | - return; |
|
413 | - } |
|
414 | - |
|
415 | - $this->htmlBody .= $this->bodyBegin; |
|
416 | - $this->bodyOpened = true; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Adds a paragraph to the body of the email |
|
421 | - * |
|
422 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
423 | - * @param string|bool $plainText Text that is used in the plain text email |
|
424 | - * if empty the $text is used, if false none will be used |
|
425 | - */ |
|
426 | - public function addBodyText(string $text, $plainText = '') { |
|
427 | - if ($this->footerAdded) { |
|
428 | - return; |
|
429 | - } |
|
430 | - if ($plainText === '') { |
|
431 | - $plainText = $text; |
|
432 | - $text = htmlspecialchars($text); |
|
433 | - } |
|
434 | - |
|
435 | - $this->ensureBodyListClosed(); |
|
436 | - $this->ensureBodyIsOpened(); |
|
437 | - |
|
438 | - $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
439 | - if ($plainText !== false) { |
|
440 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Adds a list item to the body of the email |
|
446 | - * |
|
447 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
448 | - * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
449 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
450 | - * @param string|bool $plainText Text that is used in the plain text email |
|
451 | - * if empty or true the $text is used, if false none will be used |
|
452 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
453 | - * if empty or true the $metaInfo is used, if false none will be used |
|
454 | - * @param integer plainIndent If > 0, Indent plainText by this amount. |
|
455 | - * @since 12.0.0 |
|
456 | - */ |
|
457 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) { |
|
458 | - $this->ensureBodyListOpened(); |
|
459 | - |
|
460 | - if ($plainText === '' || $plainText === true) { |
|
461 | - $plainText = $text; |
|
462 | - $text = htmlspecialchars($text); |
|
463 | - $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks |
|
464 | - } |
|
465 | - if ($plainMetaInfo === '' || $plainMetaInfo === true) { |
|
466 | - $plainMetaInfo = $metaInfo; |
|
467 | - $metaInfo = htmlspecialchars($metaInfo); |
|
468 | - } |
|
469 | - |
|
470 | - $htmlText = $text; |
|
471 | - if ($metaInfo) { |
|
472 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
473 | - } |
|
474 | - if ($icon !== '') { |
|
475 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
476 | - } else { |
|
477 | - $icon = '•'; |
|
478 | - } |
|
479 | - $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
480 | - if ($plainText !== false) { |
|
481 | - if ($plainIndent === 0) { |
|
482 | - /* |
|
351 | + public function __construct(Defaults $themingDefaults, |
|
352 | + IURLGenerator $urlGenerator, |
|
353 | + IFactory $l10nFactory, |
|
354 | + $emailId, |
|
355 | + array $data) { |
|
356 | + $this->themingDefaults = $themingDefaults; |
|
357 | + $this->urlGenerator = $urlGenerator; |
|
358 | + $this->l10nFactory = $l10nFactory; |
|
359 | + $this->htmlBody .= $this->head; |
|
360 | + $this->emailId = $emailId; |
|
361 | + $this->data = $data; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Sets the subject of the email |
|
366 | + * |
|
367 | + * @param string $subject |
|
368 | + */ |
|
369 | + public function setSubject(string $subject) { |
|
370 | + $this->subject = $subject; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Adds a header to the email |
|
375 | + */ |
|
376 | + public function addHeader() { |
|
377 | + if ($this->headerAdded) { |
|
378 | + return; |
|
379 | + } |
|
380 | + $this->headerAdded = true; |
|
381 | + |
|
382 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
383 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Adds a heading to the email |
|
388 | + * |
|
389 | + * @param string $title |
|
390 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
391 | + * if empty the $title is used, if false none will be used |
|
392 | + */ |
|
393 | + public function addHeading(string $title, $plainTitle = '') { |
|
394 | + if ($this->footerAdded) { |
|
395 | + return; |
|
396 | + } |
|
397 | + if ($plainTitle === '') { |
|
398 | + $plainTitle = $title; |
|
399 | + } |
|
400 | + |
|
401 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
402 | + if ($plainTitle !== false) { |
|
403 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Open the HTML body when it is not already |
|
409 | + */ |
|
410 | + protected function ensureBodyIsOpened() { |
|
411 | + if ($this->bodyOpened) { |
|
412 | + return; |
|
413 | + } |
|
414 | + |
|
415 | + $this->htmlBody .= $this->bodyBegin; |
|
416 | + $this->bodyOpened = true; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Adds a paragraph to the body of the email |
|
421 | + * |
|
422 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
423 | + * @param string|bool $plainText Text that is used in the plain text email |
|
424 | + * if empty the $text is used, if false none will be used |
|
425 | + */ |
|
426 | + public function addBodyText(string $text, $plainText = '') { |
|
427 | + if ($this->footerAdded) { |
|
428 | + return; |
|
429 | + } |
|
430 | + if ($plainText === '') { |
|
431 | + $plainText = $text; |
|
432 | + $text = htmlspecialchars($text); |
|
433 | + } |
|
434 | + |
|
435 | + $this->ensureBodyListClosed(); |
|
436 | + $this->ensureBodyIsOpened(); |
|
437 | + |
|
438 | + $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
439 | + if ($plainText !== false) { |
|
440 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Adds a list item to the body of the email |
|
446 | + * |
|
447 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
448 | + * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
449 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
450 | + * @param string|bool $plainText Text that is used in the plain text email |
|
451 | + * if empty or true the $text is used, if false none will be used |
|
452 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
453 | + * if empty or true the $metaInfo is used, if false none will be used |
|
454 | + * @param integer plainIndent If > 0, Indent plainText by this amount. |
|
455 | + * @since 12.0.0 |
|
456 | + */ |
|
457 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) { |
|
458 | + $this->ensureBodyListOpened(); |
|
459 | + |
|
460 | + if ($plainText === '' || $plainText === true) { |
|
461 | + $plainText = $text; |
|
462 | + $text = htmlspecialchars($text); |
|
463 | + $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks |
|
464 | + } |
|
465 | + if ($plainMetaInfo === '' || $plainMetaInfo === true) { |
|
466 | + $plainMetaInfo = $metaInfo; |
|
467 | + $metaInfo = htmlspecialchars($metaInfo); |
|
468 | + } |
|
469 | + |
|
470 | + $htmlText = $text; |
|
471 | + if ($metaInfo) { |
|
472 | + $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
473 | + } |
|
474 | + if ($icon !== '') { |
|
475 | + $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
476 | + } else { |
|
477 | + $icon = '•'; |
|
478 | + } |
|
479 | + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
480 | + if ($plainText !== false) { |
|
481 | + if ($plainIndent === 0) { |
|
482 | + /* |
|
483 | 483 | * If plainIndent is not set by caller, this is the old NC17 layout code. |
484 | 484 | */ |
485 | - $this->plainBody .= ' * ' . $plainText; |
|
486 | - if ($plainMetaInfo !== false) { |
|
487 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
488 | - } |
|
489 | - $this->plainBody .= PHP_EOL; |
|
490 | - } else { |
|
491 | - /* |
|
485 | + $this->plainBody .= ' * ' . $plainText; |
|
486 | + if ($plainMetaInfo !== false) { |
|
487 | + $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
488 | + } |
|
489 | + $this->plainBody .= PHP_EOL; |
|
490 | + } else { |
|
491 | + /* |
|
492 | 492 | * Caller can set plainIndent > 0 to format plainText in tabular fashion. |
493 | 493 | * with plainMetaInfo in column 1, and plainText in column 2. |
494 | 494 | * The plainMetaInfo label is right justified in a field of width |
495 | 495 | * "plainIndent". Multilines after the first are indented plainIndent+1 |
496 | 496 | * (to account for space after label). Fixes: #12391 |
497 | 497 | */ |
498 | - /** @var string $label */ |
|
499 | - $label = ($plainMetaInfo !== false)? $plainMetaInfo : ''; |
|
500 | - $this->plainBody .= sprintf("%{$plainIndent}s %s\n", |
|
501 | - $label, |
|
502 | - str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText)); |
|
503 | - } |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - protected function ensureBodyListOpened() { |
|
508 | - if ($this->bodyListOpened) { |
|
509 | - return; |
|
510 | - } |
|
511 | - |
|
512 | - $this->ensureBodyIsOpened(); |
|
513 | - $this->bodyListOpened = true; |
|
514 | - $this->htmlBody .= $this->listBegin; |
|
515 | - } |
|
516 | - |
|
517 | - protected function ensureBodyListClosed() { |
|
518 | - if (!$this->bodyListOpened) { |
|
519 | - return; |
|
520 | - } |
|
521 | - |
|
522 | - $this->bodyListOpened = false; |
|
523 | - $this->htmlBody .= $this->listEnd; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Adds a button group of two buttons to the body of the email |
|
528 | - * |
|
529 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
530 | - * @param string $urlLeft URL of left button |
|
531 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
532 | - * @param string $urlRight URL of right button |
|
533 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
534 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
535 | - */ |
|
536 | - public function addBodyButtonGroup(string $textLeft, |
|
537 | - string $urlLeft, |
|
538 | - string $textRight, |
|
539 | - string $urlRight, |
|
540 | - string $plainTextLeft = '', |
|
541 | - string $plainTextRight = '') { |
|
542 | - if ($this->footerAdded) { |
|
543 | - return; |
|
544 | - } |
|
545 | - if ($plainTextLeft === '') { |
|
546 | - $plainTextLeft = $textLeft; |
|
547 | - $textLeft = htmlspecialchars($textLeft); |
|
548 | - } |
|
549 | - |
|
550 | - if ($plainTextRight === '') { |
|
551 | - $plainTextRight = $textRight; |
|
552 | - $textRight = htmlspecialchars($textRight); |
|
553 | - } |
|
554 | - |
|
555 | - $this->ensureBodyIsOpened(); |
|
556 | - $this->ensureBodyListClosed(); |
|
557 | - |
|
558 | - $color = $this->themingDefaults->getDefaultColorPrimary(); |
|
559 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
560 | - |
|
561 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
562 | - $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
563 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Adds a button to the body of the email |
|
568 | - * |
|
569 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
570 | - * @param string $url URL of button |
|
571 | - * @param string|false $plainText Text of button in plain text version |
|
572 | - * if empty the $text is used, if false none will be used |
|
573 | - * |
|
574 | - * @since 12.0.0 |
|
575 | - */ |
|
576 | - public function addBodyButton(string $text, string $url, $plainText = '') { |
|
577 | - if ($this->footerAdded) { |
|
578 | - return; |
|
579 | - } |
|
580 | - |
|
581 | - $this->ensureBodyIsOpened(); |
|
582 | - $this->ensureBodyListClosed(); |
|
583 | - |
|
584 | - if ($plainText === '') { |
|
585 | - $plainText = $text; |
|
586 | - $text = htmlspecialchars($text); |
|
587 | - } |
|
588 | - |
|
589 | - $color = $this->themingDefaults->getDefaultColorPrimary(); |
|
590 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
591 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
592 | - |
|
593 | - if ($plainText !== false) { |
|
594 | - $this->plainBody .= $plainText . ': '; |
|
595 | - } |
|
596 | - |
|
597 | - $this->plainBody .= $url . PHP_EOL; |
|
598 | - } |
|
599 | - |
|
600 | - /** |
|
601 | - * Close the HTML body when it is open |
|
602 | - */ |
|
603 | - protected function ensureBodyIsClosed() { |
|
604 | - if (!$this->bodyOpened) { |
|
605 | - return; |
|
606 | - } |
|
607 | - |
|
608 | - $this->ensureBodyListClosed(); |
|
609 | - |
|
610 | - $this->htmlBody .= $this->bodyEnd; |
|
611 | - $this->bodyOpened = false; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
616 | - * |
|
617 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
618 | - */ |
|
619 | - public function addFooter(string $text = '', ?string $lang = null) { |
|
620 | - if ($text === '') { |
|
621 | - $l10n = $this->l10nFactory->get('lib', $lang); |
|
622 | - $slogan = $this->themingDefaults->getSlogan($lang); |
|
623 | - if ($slogan !== '') { |
|
624 | - $slogan = ' - ' . $slogan; |
|
625 | - } |
|
626 | - $text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); |
|
627 | - } |
|
628 | - |
|
629 | - if ($this->footerAdded) { |
|
630 | - return; |
|
631 | - } |
|
632 | - $this->footerAdded = true; |
|
633 | - |
|
634 | - $this->ensureBodyIsClosed(); |
|
635 | - |
|
636 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
637 | - $this->htmlBody .= $this->tail; |
|
638 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
639 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * Returns the rendered email subject as string |
|
644 | - * |
|
645 | - * @return string |
|
646 | - */ |
|
647 | - public function renderSubject(): string { |
|
648 | - return $this->subject; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Returns the rendered HTML email as string |
|
653 | - * |
|
654 | - * @return string |
|
655 | - */ |
|
656 | - public function renderHtml(): string { |
|
657 | - if (!$this->footerAdded) { |
|
658 | - $this->footerAdded = true; |
|
659 | - $this->ensureBodyIsClosed(); |
|
660 | - $this->htmlBody .= $this->tail; |
|
661 | - } |
|
662 | - return $this->htmlBody; |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Returns the rendered plain text email as string |
|
667 | - * |
|
668 | - * @return string |
|
669 | - */ |
|
670 | - public function renderText(): string { |
|
671 | - if (!$this->footerAdded) { |
|
672 | - $this->footerAdded = true; |
|
673 | - $this->ensureBodyIsClosed(); |
|
674 | - $this->htmlBody .= $this->tail; |
|
675 | - } |
|
676 | - return $this->plainBody; |
|
677 | - } |
|
498 | + /** @var string $label */ |
|
499 | + $label = ($plainMetaInfo !== false)? $plainMetaInfo : ''; |
|
500 | + $this->plainBody .= sprintf("%{$plainIndent}s %s\n", |
|
501 | + $label, |
|
502 | + str_replace("\n", "\n" . str_repeat(' ', $plainIndent + 1), $plainText)); |
|
503 | + } |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + protected function ensureBodyListOpened() { |
|
508 | + if ($this->bodyListOpened) { |
|
509 | + return; |
|
510 | + } |
|
511 | + |
|
512 | + $this->ensureBodyIsOpened(); |
|
513 | + $this->bodyListOpened = true; |
|
514 | + $this->htmlBody .= $this->listBegin; |
|
515 | + } |
|
516 | + |
|
517 | + protected function ensureBodyListClosed() { |
|
518 | + if (!$this->bodyListOpened) { |
|
519 | + return; |
|
520 | + } |
|
521 | + |
|
522 | + $this->bodyListOpened = false; |
|
523 | + $this->htmlBody .= $this->listEnd; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Adds a button group of two buttons to the body of the email |
|
528 | + * |
|
529 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
530 | + * @param string $urlLeft URL of left button |
|
531 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
532 | + * @param string $urlRight URL of right button |
|
533 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
534 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
535 | + */ |
|
536 | + public function addBodyButtonGroup(string $textLeft, |
|
537 | + string $urlLeft, |
|
538 | + string $textRight, |
|
539 | + string $urlRight, |
|
540 | + string $plainTextLeft = '', |
|
541 | + string $plainTextRight = '') { |
|
542 | + if ($this->footerAdded) { |
|
543 | + return; |
|
544 | + } |
|
545 | + if ($plainTextLeft === '') { |
|
546 | + $plainTextLeft = $textLeft; |
|
547 | + $textLeft = htmlspecialchars($textLeft); |
|
548 | + } |
|
549 | + |
|
550 | + if ($plainTextRight === '') { |
|
551 | + $plainTextRight = $textRight; |
|
552 | + $textRight = htmlspecialchars($textRight); |
|
553 | + } |
|
554 | + |
|
555 | + $this->ensureBodyIsOpened(); |
|
556 | + $this->ensureBodyListClosed(); |
|
557 | + |
|
558 | + $color = $this->themingDefaults->getDefaultColorPrimary(); |
|
559 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
560 | + |
|
561 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
562 | + $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
563 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Adds a button to the body of the email |
|
568 | + * |
|
569 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
570 | + * @param string $url URL of button |
|
571 | + * @param string|false $plainText Text of button in plain text version |
|
572 | + * if empty the $text is used, if false none will be used |
|
573 | + * |
|
574 | + * @since 12.0.0 |
|
575 | + */ |
|
576 | + public function addBodyButton(string $text, string $url, $plainText = '') { |
|
577 | + if ($this->footerAdded) { |
|
578 | + return; |
|
579 | + } |
|
580 | + |
|
581 | + $this->ensureBodyIsOpened(); |
|
582 | + $this->ensureBodyListClosed(); |
|
583 | + |
|
584 | + if ($plainText === '') { |
|
585 | + $plainText = $text; |
|
586 | + $text = htmlspecialchars($text); |
|
587 | + } |
|
588 | + |
|
589 | + $color = $this->themingDefaults->getDefaultColorPrimary(); |
|
590 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
591 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
592 | + |
|
593 | + if ($plainText !== false) { |
|
594 | + $this->plainBody .= $plainText . ': '; |
|
595 | + } |
|
596 | + |
|
597 | + $this->plainBody .= $url . PHP_EOL; |
|
598 | + } |
|
599 | + |
|
600 | + /** |
|
601 | + * Close the HTML body when it is open |
|
602 | + */ |
|
603 | + protected function ensureBodyIsClosed() { |
|
604 | + if (!$this->bodyOpened) { |
|
605 | + return; |
|
606 | + } |
|
607 | + |
|
608 | + $this->ensureBodyListClosed(); |
|
609 | + |
|
610 | + $this->htmlBody .= $this->bodyEnd; |
|
611 | + $this->bodyOpened = false; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
616 | + * |
|
617 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
618 | + */ |
|
619 | + public function addFooter(string $text = '', ?string $lang = null) { |
|
620 | + if ($text === '') { |
|
621 | + $l10n = $this->l10nFactory->get('lib', $lang); |
|
622 | + $slogan = $this->themingDefaults->getSlogan($lang); |
|
623 | + if ($slogan !== '') { |
|
624 | + $slogan = ' - ' . $slogan; |
|
625 | + } |
|
626 | + $text = $this->themingDefaults->getName() . $slogan . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.'); |
|
627 | + } |
|
628 | + |
|
629 | + if ($this->footerAdded) { |
|
630 | + return; |
|
631 | + } |
|
632 | + $this->footerAdded = true; |
|
633 | + |
|
634 | + $this->ensureBodyIsClosed(); |
|
635 | + |
|
636 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
637 | + $this->htmlBody .= $this->tail; |
|
638 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
639 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * Returns the rendered email subject as string |
|
644 | + * |
|
645 | + * @return string |
|
646 | + */ |
|
647 | + public function renderSubject(): string { |
|
648 | + return $this->subject; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Returns the rendered HTML email as string |
|
653 | + * |
|
654 | + * @return string |
|
655 | + */ |
|
656 | + public function renderHtml(): string { |
|
657 | + if (!$this->footerAdded) { |
|
658 | + $this->footerAdded = true; |
|
659 | + $this->ensureBodyIsClosed(); |
|
660 | + $this->htmlBody .= $this->tail; |
|
661 | + } |
|
662 | + return $this->htmlBody; |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Returns the rendered plain text email as string |
|
667 | + * |
|
668 | + * @return string |
|
669 | + */ |
|
670 | + public function renderText(): string { |
|
671 | + if (!$this->footerAdded) { |
|
672 | + $this->footerAdded = true; |
|
673 | + $this->ensureBodyIsClosed(); |
|
674 | + $this->htmlBody .= $this->tail; |
|
675 | + } |
|
676 | + return $this->plainBody; |
|
677 | + } |
|
678 | 678 | } |
@@ -38,65 +38,65 @@ |
||
38 | 38 | use OCP\Settings\ISettings; |
39 | 39 | |
40 | 40 | class Personal implements ISettings { |
41 | - private FederatedShareProvider $federatedShareProvider; |
|
42 | - private IUserSession $userSession; |
|
43 | - private Defaults $defaults; |
|
44 | - private IInitialState $initialState; |
|
45 | - private IURLGenerator $urlGenerator; |
|
41 | + private FederatedShareProvider $federatedShareProvider; |
|
42 | + private IUserSession $userSession; |
|
43 | + private Defaults $defaults; |
|
44 | + private IInitialState $initialState; |
|
45 | + private IURLGenerator $urlGenerator; |
|
46 | 46 | |
47 | - public function __construct( |
|
48 | - FederatedShareProvider $federatedShareProvider, |
|
49 | - IUserSession $userSession, |
|
50 | - Defaults $defaults, |
|
51 | - IInitialState $initialState, |
|
52 | - IURLGenerator $urlGenerator |
|
53 | - ) { |
|
54 | - $this->federatedShareProvider = $federatedShareProvider; |
|
55 | - $this->userSession = $userSession; |
|
56 | - $this->defaults = $defaults; |
|
57 | - $this->initialState = $initialState; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - } |
|
47 | + public function __construct( |
|
48 | + FederatedShareProvider $federatedShareProvider, |
|
49 | + IUserSession $userSession, |
|
50 | + Defaults $defaults, |
|
51 | + IInitialState $initialState, |
|
52 | + IURLGenerator $urlGenerator |
|
53 | + ) { |
|
54 | + $this->federatedShareProvider = $federatedShareProvider; |
|
55 | + $this->userSession = $userSession; |
|
56 | + $this->defaults = $defaults; |
|
57 | + $this->initialState = $initialState; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
63 | - * @since 9.1 |
|
64 | - */ |
|
65 | - public function getForm(): TemplateResponse { |
|
66 | - $cloudID = $this->userSession->getUser()->getCloudId(); |
|
67 | - $url = 'https://nextcloud.com/sharing#' . $cloudID; |
|
61 | + /** |
|
62 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
63 | + * @since 9.1 |
|
64 | + */ |
|
65 | + public function getForm(): TemplateResponse { |
|
66 | + $cloudID = $this->userSession->getUser()->getCloudId(); |
|
67 | + $url = 'https://nextcloud.com/sharing#' . $cloudID; |
|
68 | 68 | |
69 | - $this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary()); |
|
70 | - $this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary()); |
|
71 | - $this->initialState->provideInitialState('logoPath', $this->defaults->getLogo()); |
|
72 | - $this->initialState->provideInitialState('reference', $url); |
|
73 | - $this->initialState->provideInitialState('cloudId', $cloudID); |
|
74 | - $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated')); |
|
69 | + $this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary()); |
|
70 | + $this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary()); |
|
71 | + $this->initialState->provideInitialState('logoPath', $this->defaults->getLogo()); |
|
72 | + $this->initialState->provideInitialState('reference', $url); |
|
73 | + $this->initialState->provideInitialState('cloudId', $cloudID); |
|
74 | + $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated')); |
|
75 | 75 | |
76 | - return new TemplateResponse('federatedfilesharing', 'settings-personal', [], TemplateResponse::RENDER_AS_BLANK); |
|
77 | - } |
|
76 | + return new TemplateResponse('federatedfilesharing', 'settings-personal', [], TemplateResponse::RENDER_AS_BLANK); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return string the section ID, e.g. 'sharing' |
|
81 | - * @since 9.1 |
|
82 | - */ |
|
83 | - public function getSection(): ?string { |
|
84 | - if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() || |
|
85 | - $this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) { |
|
86 | - return 'sharing'; |
|
87 | - } |
|
88 | - return null; |
|
89 | - } |
|
79 | + /** |
|
80 | + * @return string the section ID, e.g. 'sharing' |
|
81 | + * @since 9.1 |
|
82 | + */ |
|
83 | + public function getSection(): ?string { |
|
84 | + if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() || |
|
85 | + $this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) { |
|
86 | + return 'sharing'; |
|
87 | + } |
|
88 | + return null; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return int whether the form should be rather on the top or bottom of |
|
93 | - * the admin section. The forms are arranged in ascending order of the |
|
94 | - * priority values. It is required to return a value between 0 and 100. |
|
95 | - * |
|
96 | - * E.g.: 70 |
|
97 | - * @since 9.1 |
|
98 | - */ |
|
99 | - public function getPriority(): int { |
|
100 | - return 40; |
|
101 | - } |
|
91 | + /** |
|
92 | + * @return int whether the form should be rather on the top or bottom of |
|
93 | + * the admin section. The forms are arranged in ascending order of the |
|
94 | + * priority values. It is required to return a value between 0 and 100. |
|
95 | + * |
|
96 | + * E.g.: 70 |
|
97 | + * @since 9.1 |
|
98 | + */ |
|
99 | + public function getPriority(): int { |
|
100 | + return 40; |
|
101 | + } |
|
102 | 102 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | */ |
65 | 65 | public function getForm(): TemplateResponse { |
66 | 66 | $cloudID = $this->userSession->getUser()->getCloudId(); |
67 | - $url = 'https://nextcloud.com/sharing#' . $cloudID; |
|
67 | + $url = 'https://nextcloud.com/sharing#'.$cloudID; |
|
68 | 68 | |
69 | 69 | $this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary()); |
70 | 70 | $this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary()); |
@@ -55,460 +55,460 @@ |
||
55 | 55 | |
56 | 56 | class ThemingDefaults extends \OC_Defaults { |
57 | 57 | |
58 | - private IConfig $config; |
|
59 | - private IL10N $l; |
|
60 | - private ImageManager $imageManager; |
|
61 | - private IUserSession $userSession; |
|
62 | - private IURLGenerator $urlGenerator; |
|
63 | - private ICacheFactory $cacheFactory; |
|
64 | - private Util $util; |
|
65 | - private IAppManager $appManager; |
|
66 | - private INavigationManager $navigationManager; |
|
67 | - |
|
68 | - private string $name; |
|
69 | - private string $title; |
|
70 | - private string $entity; |
|
71 | - private string $productName; |
|
72 | - private string $url; |
|
73 | - private string $color; |
|
74 | - |
|
75 | - private string $iTunesAppId; |
|
76 | - private string $iOSClientUrl; |
|
77 | - private string $AndroidClientUrl; |
|
78 | - private string $FDroidClientUrl; |
|
79 | - |
|
80 | - /** |
|
81 | - * ThemingDefaults constructor. |
|
82 | - * |
|
83 | - * @param IConfig $config |
|
84 | - * @param IL10N $l |
|
85 | - * @param ImageManager $imageManager |
|
86 | - * @param IUserSession $userSession |
|
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 | - IUserSession $userSession, |
|
95 | - IURLGenerator $urlGenerator, |
|
96 | - ICacheFactory $cacheFactory, |
|
97 | - Util $util, |
|
98 | - ImageManager $imageManager, |
|
99 | - IAppManager $appManager, |
|
100 | - INavigationManager $navigationManager |
|
101 | - ) { |
|
102 | - parent::__construct(); |
|
103 | - $this->config = $config; |
|
104 | - $this->l = $l; |
|
105 | - $this->imageManager = $imageManager; |
|
106 | - $this->userSession = $userSession; |
|
107 | - $this->urlGenerator = $urlGenerator; |
|
108 | - $this->cacheFactory = $cacheFactory; |
|
109 | - $this->util = $util; |
|
110 | - $this->appManager = $appManager; |
|
111 | - $this->navigationManager = $navigationManager; |
|
112 | - |
|
113 | - $this->name = parent::getName(); |
|
114 | - $this->title = parent::getTitle(); |
|
115 | - $this->entity = parent::getEntity(); |
|
116 | - $this->productName = parent::getProductName(); |
|
117 | - $this->url = parent::getBaseUrl(); |
|
118 | - $this->color = parent::getColorPrimary(); |
|
119 | - $this->iTunesAppId = parent::getiTunesAppId(); |
|
120 | - $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
121 | - $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
122 | - $this->FDroidClientUrl = parent::getFDroidClientUrl(); |
|
123 | - } |
|
124 | - |
|
125 | - public function getName() { |
|
126 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
127 | - } |
|
128 | - |
|
129 | - public function getHTMLName() { |
|
130 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
131 | - } |
|
132 | - |
|
133 | - public function getTitle() { |
|
134 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
135 | - } |
|
136 | - |
|
137 | - public function getEntity() { |
|
138 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
139 | - } |
|
140 | - |
|
141 | - public function getProductName() { |
|
142 | - return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName)); |
|
143 | - } |
|
144 | - |
|
145 | - public function getBaseUrl() { |
|
146 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * We pass a string and sanitizeHTML will return a string too in that case |
|
151 | - * @psalm-suppress InvalidReturnStatement |
|
152 | - * @psalm-suppress InvalidReturnType |
|
153 | - */ |
|
154 | - public function getSlogan(?string $lang = null) { |
|
155 | - return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
156 | - } |
|
157 | - |
|
158 | - public function getImprintUrl() { |
|
159 | - return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
160 | - } |
|
161 | - |
|
162 | - public function getPrivacyUrl() { |
|
163 | - return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
164 | - } |
|
165 | - |
|
166 | - public function getShortFooter() { |
|
167 | - $slogan = $this->getSlogan(); |
|
168 | - $baseUrl = $this->getBaseUrl(); |
|
169 | - if ($baseUrl !== '') { |
|
170 | - $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
171 | - ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
172 | - } else { |
|
173 | - $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
174 | - } |
|
175 | - $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
176 | - |
|
177 | - $links = [ |
|
178 | - [ |
|
179 | - 'text' => $this->l->t('Legal notice'), |
|
180 | - 'url' => (string)$this->getImprintUrl() |
|
181 | - ], |
|
182 | - [ |
|
183 | - 'text' => $this->l->t('Privacy policy'), |
|
184 | - 'url' => (string)$this->getPrivacyUrl() |
|
185 | - ], |
|
186 | - ]; |
|
187 | - |
|
188 | - $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
189 | - $guestNavigation = array_map(function ($nav) { |
|
190 | - return [ |
|
191 | - 'text' => $nav['name'], |
|
192 | - 'url' => $nav['href'] |
|
193 | - ]; |
|
194 | - }, $navigation); |
|
195 | - $links = array_merge($links, $guestNavigation); |
|
196 | - |
|
197 | - $legalLinks = ''; |
|
198 | - $divider = ''; |
|
199 | - foreach ($links as $link) { |
|
200 | - if ($link['url'] !== '' |
|
201 | - && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
202 | - ) { |
|
203 | - $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
204 | - ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
205 | - $divider = ' · '; |
|
206 | - } |
|
207 | - } |
|
208 | - if ($legalLinks !== '') { |
|
209 | - $footer .= '<br/>' . $legalLinks; |
|
210 | - } |
|
211 | - |
|
212 | - return $footer; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Color that is used for the header as well as for mail headers |
|
217 | - */ |
|
218 | - public function getColorPrimary(): string { |
|
219 | - $user = $this->userSession->getUser(); |
|
220 | - |
|
221 | - // admin-defined primary color |
|
222 | - $defaultColor = $this->getDefaultColorPrimary(); |
|
223 | - |
|
224 | - if ($this->isUserThemingDisabled()) { |
|
225 | - return $defaultColor; |
|
226 | - } |
|
227 | - |
|
228 | - // user-defined primary color |
|
229 | - if (!empty($user)) { |
|
230 | - $themingBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', ''); |
|
231 | - // If the user selected a specific colour |
|
232 | - if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackgroundColor)) { |
|
233 | - return $themingBackgroundColor; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - // If the default color is not valid, return the default background one |
|
238 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { |
|
239 | - return BackgroundService::DEFAULT_COLOR; |
|
240 | - } |
|
241 | - |
|
242 | - // Finally, return the system global primary color |
|
243 | - return $defaultColor; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Return the default color primary |
|
248 | - */ |
|
249 | - public function getDefaultColorPrimary(): string { |
|
250 | - $color = $this->config->getAppValue(Application::APP_ID, 'color', ''); |
|
251 | - if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
252 | - $color = '#0082c9'; |
|
253 | - } |
|
254 | - return $color; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Themed logo url |
|
259 | - * |
|
260 | - * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function getLogo($useSvg = true): string { |
|
264 | - $logo = $this->config->getAppValue('theming', 'logoMime', ''); |
|
265 | - |
|
266 | - // short cut to avoid setting up the filesystem just to check if the logo is there |
|
267 | - // |
|
268 | - // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. |
|
269 | - // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which |
|
270 | - // needs to be called then) |
|
271 | - if ($useSvg === true && $logo !== false) { |
|
272 | - $logoExists = true; |
|
273 | - } else { |
|
274 | - try { |
|
275 | - $this->imageManager->getImage('logo', $useSvg); |
|
276 | - $logoExists = true; |
|
277 | - } catch (\Exception $e) { |
|
278 | - $logoExists = false; |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
283 | - |
|
284 | - if (!$logo || !$logoExists) { |
|
285 | - if ($useSvg) { |
|
286 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
287 | - } else { |
|
288 | - $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
289 | - } |
|
290 | - return $logo . '?v=' . $cacheBusterCounter; |
|
291 | - } |
|
292 | - |
|
293 | - return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Themed background image url |
|
298 | - * |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function getBackground(): string { |
|
302 | - return $this->imageManager->getImageUrl('background'); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function getiTunesAppId() { |
|
309 | - return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function getiOSClientUrl() { |
|
316 | - return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - public function getAndroidClientUrl() { |
|
323 | - return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public function getFDroidClientUrl() { |
|
330 | - return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @return array scss variables to overwrite |
|
335 | - */ |
|
336 | - public function getScssVariables() { |
|
337 | - $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
338 | - $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); |
|
339 | - if ($value = $cache->get('getScssVariables')) { |
|
340 | - return $value; |
|
341 | - } |
|
342 | - |
|
343 | - $variables = [ |
|
344 | - 'theming-cachebuster' => "'" . $cacheBuster . "'", |
|
345 | - 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
346 | - 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
347 | - 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
348 | - 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
349 | - ]; |
|
350 | - |
|
351 | - $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
352 | - $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
353 | - $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
354 | - $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
355 | - $variables['image-login-plain'] = 'false'; |
|
356 | - |
|
357 | - if ($this->config->getAppValue('theming', 'color', '') !== '') { |
|
358 | - $variables['color-primary'] = $this->getColorPrimary(); |
|
359 | - $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
360 | - $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
361 | - } |
|
362 | - |
|
363 | - if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { |
|
364 | - $variables['image-login-plain'] = 'true'; |
|
365 | - } |
|
366 | - |
|
367 | - $variables['has-legal-links'] = 'false'; |
|
368 | - if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
369 | - $variables['has-legal-links'] = 'true'; |
|
370 | - } |
|
371 | - |
|
372 | - $cache->set('getScssVariables', $variables); |
|
373 | - return $variables; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Check if the image should be replaced by the theming app |
|
378 | - * and return the new image location then |
|
379 | - * |
|
380 | - * @param string $app name of the app |
|
381 | - * @param string $image filename of the image |
|
382 | - * @return bool|string false if image should not replaced, otherwise the location of the image |
|
383 | - */ |
|
384 | - public function replaceImagePath($app, $image) { |
|
385 | - if ($app === '' || $app === 'files_sharing') { |
|
386 | - $app = 'core'; |
|
387 | - } |
|
388 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
389 | - |
|
390 | - $route = false; |
|
391 | - if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) { |
|
392 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
393 | - } |
|
394 | - if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) { |
|
395 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
396 | - } |
|
397 | - if ($image === 'manifest.json') { |
|
398 | - try { |
|
399 | - $appPath = $this->appManager->getAppPath($app); |
|
400 | - if (file_exists($appPath . '/img/manifest.json')) { |
|
401 | - return false; |
|
402 | - } |
|
403 | - } catch (AppPathNotFoundException $e) { |
|
404 | - } |
|
405 | - $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]); |
|
406 | - } |
|
407 | - if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
408 | - $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
409 | - } |
|
410 | - |
|
411 | - if ($route) { |
|
412 | - return $route . '?v=' . $this->util->getCacheBuster(); |
|
413 | - } |
|
414 | - |
|
415 | - return false; |
|
416 | - } |
|
417 | - |
|
418 | - protected function getCustomFavicon(): ?ISimpleFile { |
|
419 | - try { |
|
420 | - return $this->imageManager->getImage('favicon'); |
|
421 | - } catch (NotFoundException $e) { |
|
422 | - return null; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Increases the cache buster key |
|
428 | - */ |
|
429 | - public function increaseCacheBuster(): void { |
|
430 | - $cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
431 | - $this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1)); |
|
432 | - $this->cacheFactory->createDistributed('theming-')->clear(); |
|
433 | - $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Update setting in the database |
|
438 | - * |
|
439 | - * @param string $setting |
|
440 | - * @param string $value |
|
441 | - */ |
|
442 | - public function set($setting, $value): void { |
|
443 | - $this->config->setAppValue('theming', $setting, $value); |
|
444 | - $this->increaseCacheBuster(); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Revert all settings to the default value |
|
449 | - */ |
|
450 | - public function undoAll(): void { |
|
451 | - $this->config->deleteAppValues('theming'); |
|
452 | - $this->increaseCacheBuster(); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Revert settings to the default value |
|
457 | - * |
|
458 | - * @param string $setting setting which should be reverted |
|
459 | - * @return string default value |
|
460 | - */ |
|
461 | - public function undo($setting): string { |
|
462 | - $this->config->deleteAppValue('theming', $setting); |
|
463 | - $this->increaseCacheBuster(); |
|
464 | - |
|
465 | - $returnValue = ''; |
|
466 | - switch ($setting) { |
|
467 | - case 'name': |
|
468 | - $returnValue = $this->getEntity(); |
|
469 | - break; |
|
470 | - case 'url': |
|
471 | - $returnValue = $this->getBaseUrl(); |
|
472 | - break; |
|
473 | - case 'slogan': |
|
474 | - $returnValue = $this->getSlogan(); |
|
475 | - break; |
|
476 | - case 'color': |
|
477 | - $returnValue = $this->getDefaultColorPrimary(); |
|
478 | - break; |
|
479 | - case 'logo': |
|
480 | - case 'logoheader': |
|
481 | - case 'background': |
|
482 | - case 'favicon': |
|
483 | - $this->imageManager->delete($setting); |
|
484 | - break; |
|
485 | - } |
|
486 | - |
|
487 | - return $returnValue; |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Color of text in the header and primary buttons |
|
492 | - * |
|
493 | - * @return string |
|
494 | - */ |
|
495 | - public function getTextColorPrimary() { |
|
496 | - return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Color of text in the header and primary buttons |
|
501 | - * |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function getDefaultTextColorPrimary() { |
|
505 | - return $this->util->invertTextColor($this->getDefaultColorPrimary()) ? '#000000' : '#ffffff'; |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Has the admin disabled user customization |
|
510 | - */ |
|
511 | - public function isUserThemingDisabled(): bool { |
|
512 | - return $this->config->getAppValue('theming', 'disable-user-theming', 'no') === 'yes'; |
|
513 | - } |
|
58 | + private IConfig $config; |
|
59 | + private IL10N $l; |
|
60 | + private ImageManager $imageManager; |
|
61 | + private IUserSession $userSession; |
|
62 | + private IURLGenerator $urlGenerator; |
|
63 | + private ICacheFactory $cacheFactory; |
|
64 | + private Util $util; |
|
65 | + private IAppManager $appManager; |
|
66 | + private INavigationManager $navigationManager; |
|
67 | + |
|
68 | + private string $name; |
|
69 | + private string $title; |
|
70 | + private string $entity; |
|
71 | + private string $productName; |
|
72 | + private string $url; |
|
73 | + private string $color; |
|
74 | + |
|
75 | + private string $iTunesAppId; |
|
76 | + private string $iOSClientUrl; |
|
77 | + private string $AndroidClientUrl; |
|
78 | + private string $FDroidClientUrl; |
|
79 | + |
|
80 | + /** |
|
81 | + * ThemingDefaults constructor. |
|
82 | + * |
|
83 | + * @param IConfig $config |
|
84 | + * @param IL10N $l |
|
85 | + * @param ImageManager $imageManager |
|
86 | + * @param IUserSession $userSession |
|
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 | + IUserSession $userSession, |
|
95 | + IURLGenerator $urlGenerator, |
|
96 | + ICacheFactory $cacheFactory, |
|
97 | + Util $util, |
|
98 | + ImageManager $imageManager, |
|
99 | + IAppManager $appManager, |
|
100 | + INavigationManager $navigationManager |
|
101 | + ) { |
|
102 | + parent::__construct(); |
|
103 | + $this->config = $config; |
|
104 | + $this->l = $l; |
|
105 | + $this->imageManager = $imageManager; |
|
106 | + $this->userSession = $userSession; |
|
107 | + $this->urlGenerator = $urlGenerator; |
|
108 | + $this->cacheFactory = $cacheFactory; |
|
109 | + $this->util = $util; |
|
110 | + $this->appManager = $appManager; |
|
111 | + $this->navigationManager = $navigationManager; |
|
112 | + |
|
113 | + $this->name = parent::getName(); |
|
114 | + $this->title = parent::getTitle(); |
|
115 | + $this->entity = parent::getEntity(); |
|
116 | + $this->productName = parent::getProductName(); |
|
117 | + $this->url = parent::getBaseUrl(); |
|
118 | + $this->color = parent::getColorPrimary(); |
|
119 | + $this->iTunesAppId = parent::getiTunesAppId(); |
|
120 | + $this->iOSClientUrl = parent::getiOSClientUrl(); |
|
121 | + $this->AndroidClientUrl = parent::getAndroidClientUrl(); |
|
122 | + $this->FDroidClientUrl = parent::getFDroidClientUrl(); |
|
123 | + } |
|
124 | + |
|
125 | + public function getName() { |
|
126 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
127 | + } |
|
128 | + |
|
129 | + public function getHTMLName() { |
|
130 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
131 | + } |
|
132 | + |
|
133 | + public function getTitle() { |
|
134 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->title)); |
|
135 | + } |
|
136 | + |
|
137 | + public function getEntity() { |
|
138 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->entity)); |
|
139 | + } |
|
140 | + |
|
141 | + public function getProductName() { |
|
142 | + return strip_tags($this->config->getAppValue('theming', 'productName', $this->productName)); |
|
143 | + } |
|
144 | + |
|
145 | + public function getBaseUrl() { |
|
146 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * We pass a string and sanitizeHTML will return a string too in that case |
|
151 | + * @psalm-suppress InvalidReturnStatement |
|
152 | + * @psalm-suppress InvalidReturnType |
|
153 | + */ |
|
154 | + public function getSlogan(?string $lang = null) { |
|
155 | + return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang))); |
|
156 | + } |
|
157 | + |
|
158 | + public function getImprintUrl() { |
|
159 | + return (string)$this->config->getAppValue('theming', 'imprintUrl', ''); |
|
160 | + } |
|
161 | + |
|
162 | + public function getPrivacyUrl() { |
|
163 | + return (string)$this->config->getAppValue('theming', 'privacyUrl', ''); |
|
164 | + } |
|
165 | + |
|
166 | + public function getShortFooter() { |
|
167 | + $slogan = $this->getSlogan(); |
|
168 | + $baseUrl = $this->getBaseUrl(); |
|
169 | + if ($baseUrl !== '') { |
|
170 | + $footer = '<a href="' . $baseUrl . '" target="_blank"' . |
|
171 | + ' rel="noreferrer noopener" class="entity-name">' . $this->getEntity() . '</a>'; |
|
172 | + } else { |
|
173 | + $footer = '<span class="entity-name">' .$this->getEntity() . '</span>'; |
|
174 | + } |
|
175 | + $footer .= ($slogan !== '' ? ' – ' . $slogan : ''); |
|
176 | + |
|
177 | + $links = [ |
|
178 | + [ |
|
179 | + 'text' => $this->l->t('Legal notice'), |
|
180 | + 'url' => (string)$this->getImprintUrl() |
|
181 | + ], |
|
182 | + [ |
|
183 | + 'text' => $this->l->t('Privacy policy'), |
|
184 | + 'url' => (string)$this->getPrivacyUrl() |
|
185 | + ], |
|
186 | + ]; |
|
187 | + |
|
188 | + $navigation = $this->navigationManager->getAll(INavigationManager::TYPE_GUEST); |
|
189 | + $guestNavigation = array_map(function ($nav) { |
|
190 | + return [ |
|
191 | + 'text' => $nav['name'], |
|
192 | + 'url' => $nav['href'] |
|
193 | + ]; |
|
194 | + }, $navigation); |
|
195 | + $links = array_merge($links, $guestNavigation); |
|
196 | + |
|
197 | + $legalLinks = ''; |
|
198 | + $divider = ''; |
|
199 | + foreach ($links as $link) { |
|
200 | + if ($link['url'] !== '' |
|
201 | + && filter_var($link['url'], FILTER_VALIDATE_URL) |
|
202 | + ) { |
|
203 | + $legalLinks .= $divider . '<a href="' . $link['url'] . '" class="legal" target="_blank"' . |
|
204 | + ' rel="noreferrer noopener">' . $link['text'] . '</a>'; |
|
205 | + $divider = ' · '; |
|
206 | + } |
|
207 | + } |
|
208 | + if ($legalLinks !== '') { |
|
209 | + $footer .= '<br/>' . $legalLinks; |
|
210 | + } |
|
211 | + |
|
212 | + return $footer; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Color that is used for the header as well as for mail headers |
|
217 | + */ |
|
218 | + public function getColorPrimary(): string { |
|
219 | + $user = $this->userSession->getUser(); |
|
220 | + |
|
221 | + // admin-defined primary color |
|
222 | + $defaultColor = $this->getDefaultColorPrimary(); |
|
223 | + |
|
224 | + if ($this->isUserThemingDisabled()) { |
|
225 | + return $defaultColor; |
|
226 | + } |
|
227 | + |
|
228 | + // user-defined primary color |
|
229 | + if (!empty($user)) { |
|
230 | + $themingBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', ''); |
|
231 | + // If the user selected a specific colour |
|
232 | + if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $themingBackgroundColor)) { |
|
233 | + return $themingBackgroundColor; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + // If the default color is not valid, return the default background one |
|
238 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { |
|
239 | + return BackgroundService::DEFAULT_COLOR; |
|
240 | + } |
|
241 | + |
|
242 | + // Finally, return the system global primary color |
|
243 | + return $defaultColor; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Return the default color primary |
|
248 | + */ |
|
249 | + public function getDefaultColorPrimary(): string { |
|
250 | + $color = $this->config->getAppValue(Application::APP_ID, 'color', ''); |
|
251 | + if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
252 | + $color = '#0082c9'; |
|
253 | + } |
|
254 | + return $color; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Themed logo url |
|
259 | + * |
|
260 | + * @param bool $useSvg Whether to point to the SVG image or a fallback |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function getLogo($useSvg = true): string { |
|
264 | + $logo = $this->config->getAppValue('theming', 'logoMime', ''); |
|
265 | + |
|
266 | + // short cut to avoid setting up the filesystem just to check if the logo is there |
|
267 | + // |
|
268 | + // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. |
|
269 | + // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which |
|
270 | + // needs to be called then) |
|
271 | + if ($useSvg === true && $logo !== false) { |
|
272 | + $logoExists = true; |
|
273 | + } else { |
|
274 | + try { |
|
275 | + $this->imageManager->getImage('logo', $useSvg); |
|
276 | + $logoExists = true; |
|
277 | + } catch (\Exception $e) { |
|
278 | + $logoExists = false; |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
283 | + |
|
284 | + if (!$logo || !$logoExists) { |
|
285 | + if ($useSvg) { |
|
286 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.svg'); |
|
287 | + } else { |
|
288 | + $logo = $this->urlGenerator->imagePath('core', 'logo/logo.png'); |
|
289 | + } |
|
290 | + return $logo . '?v=' . $cacheBusterCounter; |
|
291 | + } |
|
292 | + |
|
293 | + return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'logo', 'useSvg' => $useSvg, 'v' => $cacheBusterCounter ]); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Themed background image url |
|
298 | + * |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function getBackground(): string { |
|
302 | + return $this->imageManager->getImageUrl('background'); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function getiTunesAppId() { |
|
309 | + return $this->config->getAppValue('theming', 'iTunesAppId', $this->iTunesAppId); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function getiOSClientUrl() { |
|
316 | + return $this->config->getAppValue('theming', 'iOSClientUrl', $this->iOSClientUrl); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + public function getAndroidClientUrl() { |
|
323 | + return $this->config->getAppValue('theming', 'AndroidClientUrl', $this->AndroidClientUrl); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public function getFDroidClientUrl() { |
|
330 | + return $this->config->getAppValue('theming', 'FDroidClientUrl', $this->FDroidClientUrl); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @return array scss variables to overwrite |
|
335 | + */ |
|
336 | + public function getScssVariables() { |
|
337 | + $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
338 | + $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); |
|
339 | + if ($value = $cache->get('getScssVariables')) { |
|
340 | + return $value; |
|
341 | + } |
|
342 | + |
|
343 | + $variables = [ |
|
344 | + 'theming-cachebuster' => "'" . $cacheBuster . "'", |
|
345 | + 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", |
|
346 | + 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", |
|
347 | + 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", |
|
348 | + 'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'" |
|
349 | + ]; |
|
350 | + |
|
351 | + $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')"; |
|
352 | + $variables['image-logoheader'] = "url('".$this->imageManager->getImageUrl('logoheader')."')"; |
|
353 | + $variables['image-favicon'] = "url('".$this->imageManager->getImageUrl('favicon')."')"; |
|
354 | + $variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')"; |
|
355 | + $variables['image-login-plain'] = 'false'; |
|
356 | + |
|
357 | + if ($this->config->getAppValue('theming', 'color', '') !== '') { |
|
358 | + $variables['color-primary'] = $this->getColorPrimary(); |
|
359 | + $variables['color-primary-text'] = $this->getTextColorPrimary(); |
|
360 | + $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary()); |
|
361 | + } |
|
362 | + |
|
363 | + if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') { |
|
364 | + $variables['image-login-plain'] = 'true'; |
|
365 | + } |
|
366 | + |
|
367 | + $variables['has-legal-links'] = 'false'; |
|
368 | + if ($this->getImprintUrl() !== '' || $this->getPrivacyUrl() !== '') { |
|
369 | + $variables['has-legal-links'] = 'true'; |
|
370 | + } |
|
371 | + |
|
372 | + $cache->set('getScssVariables', $variables); |
|
373 | + return $variables; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Check if the image should be replaced by the theming app |
|
378 | + * and return the new image location then |
|
379 | + * |
|
380 | + * @param string $app name of the app |
|
381 | + * @param string $image filename of the image |
|
382 | + * @return bool|string false if image should not replaced, otherwise the location of the image |
|
383 | + */ |
|
384 | + public function replaceImagePath($app, $image) { |
|
385 | + if ($app === '' || $app === 'files_sharing') { |
|
386 | + $app = 'core'; |
|
387 | + } |
|
388 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
389 | + |
|
390 | + $route = false; |
|
391 | + if ($image === 'favicon.ico' && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) { |
|
392 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', ['app' => $app]); |
|
393 | + } |
|
394 | + if (($image === 'favicon-touch.png' || $image === 'favicon-fb.png') && ($this->imageManager->shouldReplaceIcons() || $this->getCustomFavicon() !== null)) { |
|
395 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', ['app' => $app]); |
|
396 | + } |
|
397 | + if ($image === 'manifest.json') { |
|
398 | + try { |
|
399 | + $appPath = $this->appManager->getAppPath($app); |
|
400 | + if (file_exists($appPath . '/img/manifest.json')) { |
|
401 | + return false; |
|
402 | + } |
|
403 | + } catch (AppPathNotFoundException $e) { |
|
404 | + } |
|
405 | + $route = $this->urlGenerator->linkToRoute('theming.Theming.getManifest', ['app' => $app ]); |
|
406 | + } |
|
407 | + if (strpos($image, 'filetypes/') === 0 && file_exists(\OC::$SERVERROOT . '/core/img/' . $image)) { |
|
408 | + $route = $this->urlGenerator->linkToRoute('theming.Icon.getThemedIcon', ['app' => $app, 'image' => $image]); |
|
409 | + } |
|
410 | + |
|
411 | + if ($route) { |
|
412 | + return $route . '?v=' . $this->util->getCacheBuster(); |
|
413 | + } |
|
414 | + |
|
415 | + return false; |
|
416 | + } |
|
417 | + |
|
418 | + protected function getCustomFavicon(): ?ISimpleFile { |
|
419 | + try { |
|
420 | + return $this->imageManager->getImage('favicon'); |
|
421 | + } catch (NotFoundException $e) { |
|
422 | + return null; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Increases the cache buster key |
|
428 | + */ |
|
429 | + public function increaseCacheBuster(): void { |
|
430 | + $cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
431 | + $this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1)); |
|
432 | + $this->cacheFactory->createDistributed('theming-')->clear(); |
|
433 | + $this->cacheFactory->createDistributed('imagePath')->clear(); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Update setting in the database |
|
438 | + * |
|
439 | + * @param string $setting |
|
440 | + * @param string $value |
|
441 | + */ |
|
442 | + public function set($setting, $value): void { |
|
443 | + $this->config->setAppValue('theming', $setting, $value); |
|
444 | + $this->increaseCacheBuster(); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Revert all settings to the default value |
|
449 | + */ |
|
450 | + public function undoAll(): void { |
|
451 | + $this->config->deleteAppValues('theming'); |
|
452 | + $this->increaseCacheBuster(); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Revert settings to the default value |
|
457 | + * |
|
458 | + * @param string $setting setting which should be reverted |
|
459 | + * @return string default value |
|
460 | + */ |
|
461 | + public function undo($setting): string { |
|
462 | + $this->config->deleteAppValue('theming', $setting); |
|
463 | + $this->increaseCacheBuster(); |
|
464 | + |
|
465 | + $returnValue = ''; |
|
466 | + switch ($setting) { |
|
467 | + case 'name': |
|
468 | + $returnValue = $this->getEntity(); |
|
469 | + break; |
|
470 | + case 'url': |
|
471 | + $returnValue = $this->getBaseUrl(); |
|
472 | + break; |
|
473 | + case 'slogan': |
|
474 | + $returnValue = $this->getSlogan(); |
|
475 | + break; |
|
476 | + case 'color': |
|
477 | + $returnValue = $this->getDefaultColorPrimary(); |
|
478 | + break; |
|
479 | + case 'logo': |
|
480 | + case 'logoheader': |
|
481 | + case 'background': |
|
482 | + case 'favicon': |
|
483 | + $this->imageManager->delete($setting); |
|
484 | + break; |
|
485 | + } |
|
486 | + |
|
487 | + return $returnValue; |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Color of text in the header and primary buttons |
|
492 | + * |
|
493 | + * @return string |
|
494 | + */ |
|
495 | + public function getTextColorPrimary() { |
|
496 | + return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff'; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Color of text in the header and primary buttons |
|
501 | + * |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function getDefaultTextColorPrimary() { |
|
505 | + return $this->util->invertTextColor($this->getDefaultColorPrimary()) ? '#000000' : '#ffffff'; |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Has the admin disabled user customization |
|
510 | + */ |
|
511 | + public function isUserThemingDisabled(): bool { |
|
512 | + return $this->config->getAppValue('theming', 'disable-user-theming', 'no') === 'yes'; |
|
513 | + } |
|
514 | 514 | } |