Completed
Pull Request — master (#4707)
by Morris
21:56 queued 10:23
created
apps/theming/lib/ThemingDefaults.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -31,251 +31,251 @@
 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
-	 * @return string
133
-	 */
134
-	public function getLogo() {
135
-		$logo = $this->config->getAppValue('theming', 'logoMime', false);
136
-
137
-		$logoExists = true;
138
-		try {
139
-			$this->appData->getFolder('images')->getFile('logo');
140
-		} catch (\Exception $e) {
141
-			$logoExists = false;
142
-		}
143
-
144
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
145
-
146
-		if(!$logo || !$logoExists) {
147
-			return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
148
-		}
149
-
150
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
151
-	}
152
-
153
-	/**
154
-	 * Themed background image url
155
-	 *
156
-	 * @return string
157
-	 */
158
-	public function getBackground() {
159
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
160
-
161
-		$backgroundExists = true;
162
-		try {
163
-			$this->appData->getFolder('images')->getFile('background');
164
-		} catch (\Exception $e) {
165
-			$backgroundExists = false;
166
-		}
167
-
168
-		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
169
-
170
-		if(!$backgroundLogo || !$backgroundExists) {
171
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
172
-		}
173
-
174
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
175
-	}
176
-
177
-
178
-	/**
179
-	 * @return array scss variables to overwrite
180
-	 */
181
-	public function getScssVariables() {
182
-		$cache = $this->cacheFactory->create('theming');
183
-		if ($value = $cache->get('getScssVariables')) {
184
-			return $value;
185
-		}
186
-
187
-		$variables = [
188
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
189
-		];
190
-
191
-		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
192
-		$variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
193
-
194
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
195
-			if ($this->util->invertTextColor($this->getColorPrimary())) {
196
-				$colorPrimaryText = '#000000';
197
-			} else {
198
-				$colorPrimaryText = '#ffffff';
199
-			}
200
-			$variables['color-primary'] = $this->getColorPrimary();
201
-			$variables['color-primary-text'] = $colorPrimaryText;
202
-		}
203
-		$cache->set('getScssVariables', $variables);
204
-		return $variables;
205
-	}
206
-
207
-	/**
208
-	 * Check if Imagemagick is enabled and if SVG is supported
209
-	 * otherwise we can't render custom icons
210
-	 *
211
-	 * @return bool
212
-	 */
213
-	public function shouldReplaceIcons() {
214
-		$cache = $this->cacheFactory->create('theming');
215
-		if($value = $cache->get('shouldReplaceIcons')) {
216
-			return (bool)$value;
217
-		}
218
-		$value = false;
219
-		if(extension_loaded('imagick')) {
220
-			$checkImagick = new \Imagick();
221
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
222
-				$value = true;
223
-			}
224
-			$checkImagick->clear();
225
-		}
226
-		$cache->set('shouldReplaceIcons', $value);
227
-		return $value;
228
-	}
229
-
230
-	/**
231
-	 * Increases the cache buster key
232
-	 */
233
-	private function increaseCacheBuster() {
234
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
235
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
236
-		$this->cacheFactory->create('theming')->clear('getScssVariables');
237
-	}
238
-
239
-	/**
240
-	 * Update setting in the database
241
-	 *
242
-	 * @param string $setting
243
-	 * @param string $value
244
-	 */
245
-	public function set($setting, $value) {
246
-		$this->config->setAppValue('theming', $setting, $value);
247
-		$this->increaseCacheBuster();
248
-	}
249
-
250
-	/**
251
-	 * Revert settings to the default value
252
-	 *
253
-	 * @param string $setting setting which should be reverted
254
-	 * @return string default value
255
-	 */
256
-	public function undo($setting) {
257
-		$this->config->deleteAppValue('theming', $setting);
258
-		$this->increaseCacheBuster();
259
-
260
-		switch ($setting) {
261
-			case 'name':
262
-				$returnValue = $this->getEntity();
263
-				break;
264
-			case 'url':
265
-				$returnValue = $this->getBaseUrl();
266
-				break;
267
-			case 'slogan':
268
-				$returnValue = $this->getSlogan();
269
-				break;
270
-			case 'color':
271
-				$returnValue = $this->getColorPrimary();
272
-				break;
273
-			default:
274
-				$returnValue = '';
275
-				break;
276
-		}
277
-
278
-		return $returnValue;
279
-	}
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
+     * @return string
133
+     */
134
+    public function getLogo() {
135
+        $logo = $this->config->getAppValue('theming', 'logoMime', false);
136
+
137
+        $logoExists = true;
138
+        try {
139
+            $this->appData->getFolder('images')->getFile('logo');
140
+        } catch (\Exception $e) {
141
+            $logoExists = false;
142
+        }
143
+
144
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
145
+
146
+        if(!$logo || !$logoExists) {
147
+            return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
148
+        }
149
+
150
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
151
+    }
152
+
153
+    /**
154
+     * Themed background image url
155
+     *
156
+     * @return string
157
+     */
158
+    public function getBackground() {
159
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
160
+
161
+        $backgroundExists = true;
162
+        try {
163
+            $this->appData->getFolder('images')->getFile('background');
164
+        } catch (\Exception $e) {
165
+            $backgroundExists = false;
166
+        }
167
+
168
+        $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
169
+
170
+        if(!$backgroundLogo || !$backgroundExists) {
171
+            return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
172
+        }
173
+
174
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
175
+    }
176
+
177
+
178
+    /**
179
+     * @return array scss variables to overwrite
180
+     */
181
+    public function getScssVariables() {
182
+        $cache = $this->cacheFactory->create('theming');
183
+        if ($value = $cache->get('getScssVariables')) {
184
+            return $value;
185
+        }
186
+
187
+        $variables = [
188
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
189
+        ];
190
+
191
+        $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
192
+        $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
193
+
194
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
195
+            if ($this->util->invertTextColor($this->getColorPrimary())) {
196
+                $colorPrimaryText = '#000000';
197
+            } else {
198
+                $colorPrimaryText = '#ffffff';
199
+            }
200
+            $variables['color-primary'] = $this->getColorPrimary();
201
+            $variables['color-primary-text'] = $colorPrimaryText;
202
+        }
203
+        $cache->set('getScssVariables', $variables);
204
+        return $variables;
205
+    }
206
+
207
+    /**
208
+     * Check if Imagemagick is enabled and if SVG is supported
209
+     * otherwise we can't render custom icons
210
+     *
211
+     * @return bool
212
+     */
213
+    public function shouldReplaceIcons() {
214
+        $cache = $this->cacheFactory->create('theming');
215
+        if($value = $cache->get('shouldReplaceIcons')) {
216
+            return (bool)$value;
217
+        }
218
+        $value = false;
219
+        if(extension_loaded('imagick')) {
220
+            $checkImagick = new \Imagick();
221
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
222
+                $value = true;
223
+            }
224
+            $checkImagick->clear();
225
+        }
226
+        $cache->set('shouldReplaceIcons', $value);
227
+        return $value;
228
+    }
229
+
230
+    /**
231
+     * Increases the cache buster key
232
+     */
233
+    private function increaseCacheBuster() {
234
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
235
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
236
+        $this->cacheFactory->create('theming')->clear('getScssVariables');
237
+    }
238
+
239
+    /**
240
+     * Update setting in the database
241
+     *
242
+     * @param string $setting
243
+     * @param string $value
244
+     */
245
+    public function set($setting, $value) {
246
+        $this->config->setAppValue('theming', $setting, $value);
247
+        $this->increaseCacheBuster();
248
+    }
249
+
250
+    /**
251
+     * Revert settings to the default value
252
+     *
253
+     * @param string $setting setting which should be reverted
254
+     * @return string default value
255
+     */
256
+    public function undo($setting) {
257
+        $this->config->deleteAppValue('theming', $setting);
258
+        $this->increaseCacheBuster();
259
+
260
+        switch ($setting) {
261
+            case 'name':
262
+                $returnValue = $this->getEntity();
263
+                break;
264
+            case 'url':
265
+                $returnValue = $this->getBaseUrl();
266
+                break;
267
+            case 'slogan':
268
+                $returnValue = $this->getSlogan();
269
+                break;
270
+            case 'color':
271
+                $returnValue = $this->getColorPrimary();
272
+                break;
273
+            default:
274
+                $returnValue = '';
275
+                break;
276
+        }
277
+
278
+        return $returnValue;
279
+    }
280 280
 
281 281
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 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
 	}
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
 
144 144
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
145 145
 
146
-		if(!$logo || !$logoExists) {
147
-			return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
146
+		if (!$logo || !$logoExists) {
147
+			return $this->urlGenerator->imagePath('core', 'logo.svg').'?v='.$cacheBusterCounter;
148 148
 		}
149 149
 
150
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
150
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLogo').'?v='.$cacheBusterCounter;
151 151
 	}
152 152
 
153 153
 	/**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @return string
157 157
 	 */
158 158
 	public function getBackground() {
159
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false);
159
+		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
160 160
 
161 161
 		$backgroundExists = true;
162 162
 		try {
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 
168 168
 		$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
169 169
 
170
-		if(!$backgroundLogo || !$backgroundExists) {
171
-			return $this->urlGenerator->imagePath('core','background.jpg') . '?v=' . $cacheBusterCounter;
170
+		if (!$backgroundLogo || !$backgroundExists) {
171
+			return $this->urlGenerator->imagePath('core', 'background.jpg').'?v='.$cacheBusterCounter;
172 172
 		}
173 173
 
174
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter;
174
+		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground').'?v='.$cacheBusterCounter;
175 175
 	}
176 176
 
177 177
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 
187 187
 		$variables = [
188
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
188
+			'theming-cachebuster' => "'".$this->config->getAppValue('theming', 'cachebuster', '0')."'",
189 189
 		];
190 190
 
191 191
 		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function shouldReplaceIcons() {
214 214
 		$cache = $this->cacheFactory->create('theming');
215
-		if($value = $cache->get('shouldReplaceIcons')) {
216
-			return (bool)$value;
215
+		if ($value = $cache->get('shouldReplaceIcons')) {
216
+			return (bool) $value;
217 217
 		}
218 218
 		$value = false;
219
-		if(extension_loaded('imagick')) {
219
+		if (extension_loaded('imagick')) {
220 220
 			$checkImagick = new \Imagick();
221 221
 			if (count($checkImagick->queryFormats('SVG')) >= 1) {
222 222
 				$value = true;
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	private function increaseCacheBuster() {
234 234
 		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
235
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
235
+		$this->config->setAppValue('theming', 'cachebuster', (int) $cacheBusterKey + 1);
236 236
 		$this->cacheFactory->create('theming')->clear('getScssVariables');
237 237
 	}
238 238
 
Please login to merge, or discard this patch.