Completed
Push — master ( 7eb8b3...c1c676 )
by Lukas
12:54
created
apps/theming/lib/ThemingDefaults.php 2 patches
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -31,264 +31,264 @@
 block discarded – undo
31 31
 
32 32
 class ThemingDefaults extends \OC_Defaults {
33 33
 
34
-	/** @var IConfig */
35
-	private $config;
36
-	/** @var IL10N */
37
-	private $l;
38
-	/** @var IURLGenerator */
39
-	private $urlGenerator;
40
-	/** @var IAppData */
41
-	private $appData;
42
-	/** @var ICacheFactory */
43
-	private $cacheFactory;
44
-	/** @var string */
45
-	private $name;
46
-	/** @var string */
47
-	private $url;
48
-	/** @var string */
49
-	private $slogan;
50
-	/** @var string */
51
-	private $color;
52
-	/** @var Util */
53
-	private $util;
54
-
55
-	/**
56
-	 * ThemingDefaults constructor.
57
-	 *
58
-	 * @param IConfig $config
59
-	 * @param IL10N $l
60
-	 * @param IURLGenerator $urlGenerator
61
-	 * @param \OC_Defaults $defaults
62
-	 * @param IAppData $appData
63
-	 * @param ICacheFactory $cacheFactory
64
-	 * @param Util $util
65
-	 */
66
-	public function __construct(IConfig $config,
67
-								IL10N $l,
68
-								IURLGenerator $urlGenerator,
69
-								IAppData $appData,
70
-								ICacheFactory $cacheFactory,
71
-								Util $util
72
-	) {
73
-		parent::__construct();
74
-		$this->config = $config;
75
-		$this->l = $l;
76
-		$this->urlGenerator = $urlGenerator;
77
-		$this->appData = $appData;
78
-		$this->cacheFactory = $cacheFactory;
79
-		$this->util = $util;
80
-
81
-		$this->name = parent::getName();
82
-		$this->url = parent::getBaseUrl();
83
-		$this->slogan = parent::getSlogan();
84
-		$this->color = parent::getColorPrimary();
85
-	}
86
-
87
-	public function getName() {
88
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
89
-	}
90
-
91
-	public function getHTMLName() {
92
-		return $this->config->getAppValue('theming', 'name', $this->name);
93
-	}
94
-
95
-	public function getTitle() {
96
-		return $this->getName();
97
-	}
98
-
99
-	public function getEntity() {
100
-		return $this->getName();
101
-	}
102
-
103
-	public function getBaseUrl() {
104
-		return $this->config->getAppValue('theming', 'url', $this->url);
105
-	}
106
-
107
-	public function getSlogan() {
108
-		return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
109
-	}
110
-
111
-	public function getShortFooter() {
112
-		$slogan = $this->getSlogan();
113
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
114
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
115
-			($slogan !== '' ? ' – ' . $slogan : '');
116
-
117
-		return $footer;
118
-	}
119
-
120
-	/**
121
-	 * Color that is used for the header as well as for mail headers
122
-	 *
123
-	 * @return string
124
-	 */
125
-	public function getColorPrimary() {
126
-		return $this->config->getAppValue('theming', 'color', $this->color);
127
-	}
128
-
129
-	/**
130
-	 * Themed logo url
131
-	 *
132
-	 * @param bool $useSvg Whether to point to the SVG image or a fallback
133
-	 * @return string
134
-	 */
135
-	public function getLogo($useSvg = true) {
136
-		$logo = $this->config->getAppValue('theming', 'logoMime', false);
137
-
138
-		$logoExists = true;
139
-		try {
140
-			$this->appData->getFolder('images')->getFile('logo');
141
-		} catch (\Exception $e) {
142
-			$logoExists = false;
143
-		}
144
-
145
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
146
-
147
-		if(!$logo || !$logoExists) {
148
-			if($useSvg) {
149
-				$logo = $this->urlGenerator->imagePath('core', 'logo.svg');
150
-			} else {
151
-				$logo = $this->urlGenerator->imagePath('core', 'logo.png');
152
-			}
153
-			return $logo . '?v=' . $cacheBusterCounter;
154
-		}
155
-
156
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
157
-	}
158
-
159
-	/**
160
-	 * Themed background image url
161
-	 *
162
-	 * @return string
163
-	 */
164
-	public function getBackground() {
165
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
166
-
167
-		$backgroundExists = true;
168
-		try {
169
-			$this->appData->getFolder('images')->getFile('background');
170
-		} catch (\Exception $e) {
171
-			$backgroundExists = false;
172
-		}
173
-
174
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
175
-
176
-		if(!$backgroundLogo || !$backgroundExists) {
177
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
178
-		}
179
-
180
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
181
-	}
182
-
183
-
184
-	/**
185
-	 * @return array scss variables to overwrite
186
-	 */
187
-	public function getScssVariables() {
188
-		$cache = $this->cacheFactory->create('theming');
189
-		if ($value = $cache->get('getScssVariables')) {
190
-			return $value;
191
-		}
192
-
193
-		$variables = [
194
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
195
-			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
196
-			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
197
-		];
198
-
199
-		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
200
-		$variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
201
-		$variables['image-login-plain'] = 'false';
202
-
203
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
204
-			if ($this->util->invertTextColor($this->getColorPrimary())) {
205
-				$colorPrimaryText = '#000000';
206
-			} else {
207
-				$colorPrimaryText = '#ffffff';
208
-			}
209
-			$variables['color-primary'] = $this->getColorPrimary();
210
-			$variables['color-primary-text'] = $colorPrimaryText;
211
-		}
212
-
213
-		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
214
-			$variables['image-login-plain'] = 'true';
215
-		}
216
-		$cache->set('getScssVariables', $variables);
217
-		return $variables;
218
-	}
219
-
220
-	/**
221
-	 * Check if Imagemagick is enabled and if SVG is supported
222
-	 * otherwise we can't render custom icons
223
-	 *
224
-	 * @return bool
225
-	 */
226
-	public function shouldReplaceIcons() {
227
-		$cache = $this->cacheFactory->create('theming');
228
-		if($value = $cache->get('shouldReplaceIcons')) {
229
-			return (bool)$value;
230
-		}
231
-		$value = false;
232
-		if(extension_loaded('imagick')) {
233
-			$checkImagick = new \Imagick();
234
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
235
-				$value = true;
236
-			}
237
-			$checkImagick->clear();
238
-		}
239
-		$cache->set('shouldReplaceIcons', $value);
240
-		return $value;
241
-	}
242
-
243
-	/**
244
-	 * Increases the cache buster key
245
-	 */
246
-	private function increaseCacheBuster() {
247
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
248
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
249
-		$this->cacheFactory->create('theming')->clear('getScssVariables');
250
-	}
251
-
252
-	/**
253
-	 * Update setting in the database
254
-	 *
255
-	 * @param string $setting
256
-	 * @param string $value
257
-	 */
258
-	public function set($setting, $value) {
259
-		$this->config->setAppValue('theming', $setting, $value);
260
-		$this->increaseCacheBuster();
261
-	}
262
-
263
-	/**
264
-	 * Revert settings to the default value
265
-	 *
266
-	 * @param string $setting setting which should be reverted
267
-	 * @return string default value
268
-	 */
269
-	public function undo($setting) {
270
-		$this->config->deleteAppValue('theming', $setting);
271
-		$this->increaseCacheBuster();
272
-
273
-		switch ($setting) {
274
-			case 'name':
275
-				$returnValue = $this->getEntity();
276
-				break;
277
-			case 'url':
278
-				$returnValue = $this->getBaseUrl();
279
-				break;
280
-			case 'slogan':
281
-				$returnValue = $this->getSlogan();
282
-				break;
283
-			case 'color':
284
-				$returnValue = $this->getColorPrimary();
285
-				break;
286
-			default:
287
-				$returnValue = '';
288
-				break;
289
-		}
290
-
291
-		return $returnValue;
292
-	}
34
+    /** @var IConfig */
35
+    private $config;
36
+    /** @var IL10N */
37
+    private $l;
38
+    /** @var IURLGenerator */
39
+    private $urlGenerator;
40
+    /** @var IAppData */
41
+    private $appData;
42
+    /** @var ICacheFactory */
43
+    private $cacheFactory;
44
+    /** @var string */
45
+    private $name;
46
+    /** @var string */
47
+    private $url;
48
+    /** @var string */
49
+    private $slogan;
50
+    /** @var string */
51
+    private $color;
52
+    /** @var Util */
53
+    private $util;
54
+
55
+    /**
56
+     * ThemingDefaults constructor.
57
+     *
58
+     * @param IConfig $config
59
+     * @param IL10N $l
60
+     * @param IURLGenerator $urlGenerator
61
+     * @param \OC_Defaults $defaults
62
+     * @param IAppData $appData
63
+     * @param ICacheFactory $cacheFactory
64
+     * @param Util $util
65
+     */
66
+    public function __construct(IConfig $config,
67
+                                IL10N $l,
68
+                                IURLGenerator $urlGenerator,
69
+                                IAppData $appData,
70
+                                ICacheFactory $cacheFactory,
71
+                                Util $util
72
+    ) {
73
+        parent::__construct();
74
+        $this->config = $config;
75
+        $this->l = $l;
76
+        $this->urlGenerator = $urlGenerator;
77
+        $this->appData = $appData;
78
+        $this->cacheFactory = $cacheFactory;
79
+        $this->util = $util;
80
+
81
+        $this->name = parent::getName();
82
+        $this->url = parent::getBaseUrl();
83
+        $this->slogan = parent::getSlogan();
84
+        $this->color = parent::getColorPrimary();
85
+    }
86
+
87
+    public function getName() {
88
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
89
+    }
90
+
91
+    public function getHTMLName() {
92
+        return $this->config->getAppValue('theming', 'name', $this->name);
93
+    }
94
+
95
+    public function getTitle() {
96
+        return $this->getName();
97
+    }
98
+
99
+    public function getEntity() {
100
+        return $this->getName();
101
+    }
102
+
103
+    public function getBaseUrl() {
104
+        return $this->config->getAppValue('theming', 'url', $this->url);
105
+    }
106
+
107
+    public function getSlogan() {
108
+        return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
109
+    }
110
+
111
+    public function getShortFooter() {
112
+        $slogan = $this->getSlogan();
113
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
114
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
115
+            ($slogan !== '' ? ' – ' . $slogan : '');
116
+
117
+        return $footer;
118
+    }
119
+
120
+    /**
121
+     * Color that is used for the header as well as for mail headers
122
+     *
123
+     * @return string
124
+     */
125
+    public function getColorPrimary() {
126
+        return $this->config->getAppValue('theming', 'color', $this->color);
127
+    }
128
+
129
+    /**
130
+     * Themed logo url
131
+     *
132
+     * @param bool $useSvg Whether to point to the SVG image or a fallback
133
+     * @return string
134
+     */
135
+    public function getLogo($useSvg = true) {
136
+        $logo = $this->config->getAppValue('theming', 'logoMime', false);
137
+
138
+        $logoExists = true;
139
+        try {
140
+            $this->appData->getFolder('images')->getFile('logo');
141
+        } catch (\Exception $e) {
142
+            $logoExists = false;
143
+        }
144
+
145
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
146
+
147
+        if(!$logo || !$logoExists) {
148
+            if($useSvg) {
149
+                $logo = $this->urlGenerator->imagePath('core', 'logo.svg');
150
+            } else {
151
+                $logo = $this->urlGenerator->imagePath('core', 'logo.png');
152
+            }
153
+            return $logo . '?v=' . $cacheBusterCounter;
154
+        }
155
+
156
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
157
+    }
158
+
159
+    /**
160
+     * Themed background image url
161
+     *
162
+     * @return string
163
+     */
164
+    public function getBackground() {
165
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
166
+
167
+        $backgroundExists = true;
168
+        try {
169
+            $this->appData->getFolder('images')->getFile('background');
170
+        } catch (\Exception $e) {
171
+            $backgroundExists = false;
172
+        }
173
+
174
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
175
+
176
+        if(!$backgroundLogo || !$backgroundExists) {
177
+            return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
178
+        }
179
+
180
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
181
+    }
182
+
183
+
184
+    /**
185
+     * @return array scss variables to overwrite
186
+     */
187
+    public function getScssVariables() {
188
+        $cache = $this->cacheFactory->create('theming');
189
+        if ($value = $cache->get('getScssVariables')) {
190
+            return $value;
191
+        }
192
+
193
+        $variables = [
194
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
195
+            'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
196
+            'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
197
+        ];
198
+
199
+        $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
200
+        $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
201
+        $variables['image-login-plain'] = 'false';
202
+
203
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
204
+            if ($this->util->invertTextColor($this->getColorPrimary())) {
205
+                $colorPrimaryText = '#000000';
206
+            } else {
207
+                $colorPrimaryText = '#ffffff';
208
+            }
209
+            $variables['color-primary'] = $this->getColorPrimary();
210
+            $variables['color-primary-text'] = $colorPrimaryText;
211
+        }
212
+
213
+        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
214
+            $variables['image-login-plain'] = 'true';
215
+        }
216
+        $cache->set('getScssVariables', $variables);
217
+        return $variables;
218
+    }
219
+
220
+    /**
221
+     * Check if Imagemagick is enabled and if SVG is supported
222
+     * otherwise we can't render custom icons
223
+     *
224
+     * @return bool
225
+     */
226
+    public function shouldReplaceIcons() {
227
+        $cache = $this->cacheFactory->create('theming');
228
+        if($value = $cache->get('shouldReplaceIcons')) {
229
+            return (bool)$value;
230
+        }
231
+        $value = false;
232
+        if(extension_loaded('imagick')) {
233
+            $checkImagick = new \Imagick();
234
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
235
+                $value = true;
236
+            }
237
+            $checkImagick->clear();
238
+        }
239
+        $cache->set('shouldReplaceIcons', $value);
240
+        return $value;
241
+    }
242
+
243
+    /**
244
+     * Increases the cache buster key
245
+     */
246
+    private function increaseCacheBuster() {
247
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
248
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
249
+        $this->cacheFactory->create('theming')->clear('getScssVariables');
250
+    }
251
+
252
+    /**
253
+     * Update setting in the database
254
+     *
255
+     * @param string $setting
256
+     * @param string $value
257
+     */
258
+    public function set($setting, $value) {
259
+        $this->config->setAppValue('theming', $setting, $value);
260
+        $this->increaseCacheBuster();
261
+    }
262
+
263
+    /**
264
+     * Revert settings to the default value
265
+     *
266
+     * @param string $setting setting which should be reverted
267
+     * @return string default value
268
+     */
269
+    public function undo($setting) {
270
+        $this->config->deleteAppValue('theming', $setting);
271
+        $this->increaseCacheBuster();
272
+
273
+        switch ($setting) {
274
+            case 'name':
275
+                $returnValue = $this->getEntity();
276
+                break;
277
+            case 'url':
278
+                $returnValue = $this->getBaseUrl();
279
+                break;
280
+            case 'slogan':
281
+                $returnValue = $this->getSlogan();
282
+                break;
283
+            case 'color':
284
+                $returnValue = $this->getColorPrimary();
285
+                break;
286
+            default:
287
+                $returnValue = '';
288
+                break;
289
+        }
290
+
291
+        return $returnValue;
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 
111 111
 	public function getShortFooter() {
112 112
 		$slogan = $this->getSlogan();
113
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
114
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
115
-			($slogan !== '' ? ' – ' . $slogan : '');
113
+		$footer = '<a href="'.$this->getBaseUrl().'" target="_blank"'.
114
+			' rel="noreferrer">'.$this->getEntity().'</a>'.
115
+			($slogan !== '' ? ' – '.$slogan : '');
116 116
 
117 117
 		return $footer;
118 118
 	}
@@ -144,16 +144,16 @@  discard block
 block discarded – undo
144 144
 
145 145
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
146 146
 
147
-		if(!$logo || !$logoExists) {
148
-			if($useSvg) {
147
+		if (!$logo || !$logoExists) {
148
+			if ($useSvg) {
149 149
 				$logo = $this->urlGenerator->imagePath('core', 'logo.svg');
150 150
 			} else {
151 151
 				$logo = $this->urlGenerator->imagePath('core', 'logo.png');
152 152
 			}
153
-			return $logo . '?v=' . $cacheBusterCounter;
153
+			return $logo.'?v='.$cacheBusterCounter;
154 154
 		}
155 155
 
156
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
156
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo').'?v='.$cacheBusterCounter;
157 157
 	}
158 158
 
159 159
 	/**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @return string
163 163
 	 */
164 164
 	public function getBackground() {
165
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
165
+		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
166 166
 
167 167
 		$backgroundExists = true;
168 168
 		try {
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
 
174 174
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
175 175
 
176
-		if(!$backgroundLogo || !$backgroundExists) {
177
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
176
+		if (!$backgroundLogo || !$backgroundExists) {
177
+			return $this->urlGenerator->imagePath('core', 'background.jpg').'?v='.$cacheBusterCounter;
178 178
 		}
179 179
 
180
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
180
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground').'?v='.$cacheBusterCounter;
181 181
 	}
182 182
 
183 183
 
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 		}
192 192
 
193 193
 		$variables = [
194
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
195
-			'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime', '') . "'",
196
-			'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime', '') . "'"
194
+			'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'",
195
+			'theming-logo-mime' => "'".$this->config->getAppValue('theming', 'logoMime', '')."'",
196
+			'theming-background-mime' => "'".$this->config->getAppValue('theming', 'backgroundMime', '')."'"
197 197
 		];
198 198
 
199 199
 		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function shouldReplaceIcons() {
227 227
 		$cache = $this->cacheFactory->create('theming');
228
-		if($value = $cache->get('shouldReplaceIcons')) {
229
-			return (bool)$value;
228
+		if ($value = $cache->get('shouldReplaceIcons')) {
229
+			return (bool) $value;
230 230
 		}
231 231
 		$value = false;
232
-		if(extension_loaded('imagick')) {
232
+		if (extension_loaded('imagick')) {
233 233
 			$checkImagick = new \Imagick();
234 234
 			if (count($checkImagick->queryFormats('SVG')) >= 1) {
235 235
 				$value = true;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	private function increaseCacheBuster() {
247 247
 		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
248
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
248
+		$this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1);
249 249
 		$this->cacheFactory->create('theming')->clear('getScssVariables');
250 250
 	}
251 251
 
Please login to merge, or discard this patch.