Completed
Pull Request — master (#4617)
by Julius
12:20
created
apps/theming/lib/ThemingDefaults.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -31,254 +31,254 @@
 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
-		if(!$backgroundLogo || !$backgroundExists) {
169
-			return $this->urlGenerator->imagePath('core','background.jpg');
170
-		}
171
-
172
-		return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
173
-	}
174
-
175
-
176
-	/**
177
-	 * @return array scss variables to overwrite
178
-	 */
179
-	public function getScssVariables() {
180
-		$cache = $this->cacheFactory->create('theming');
181
-		if ($value = $cache->get('getScssVariables')) {
182
-			return $value;
183
-		}
184
-
185
-		$variables = [
186
-			'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
187
-		];
188
-
189
-		$variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
190
-		$variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
191
-		$variables['image-login-plain'] = 'false';
192
-
193
-		if ($this->config->getAppValue('theming', 'color', null) !== null) {
194
-			if ($this->util->invertTextColor($this->getColorPrimary())) {
195
-				$colorPrimaryText = '#000000';
196
-			} else {
197
-				$colorPrimaryText = '#ffffff';
198
-			}
199
-			$variables['color-primary'] = $this->getColorPrimary();
200
-			$variables['color-primary-text'] = $colorPrimaryText;
201
-		}
202
-
203
-		if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
204
-			$variables['image-login-plain'] = 'true';
205
-		}
206
-		$cache->set('getScssVariables', $variables);
207
-		return $variables;
208
-	}
209
-
210
-	/**
211
-	 * Check if Imagemagick is enabled and if SVG is supported
212
-	 * otherwise we can't render custom icons
213
-	 *
214
-	 * @return bool
215
-	 */
216
-	public function shouldReplaceIcons() {
217
-		$cache = $this->cacheFactory->create('theming');
218
-		if($value = $cache->get('shouldReplaceIcons')) {
219
-			return (bool)$value;
220
-		}
221
-		$value = false;
222
-		if(extension_loaded('imagick')) {
223
-			$checkImagick = new \Imagick();
224
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
225
-				$value = true;
226
-			}
227
-			$checkImagick->clear();
228
-		}
229
-		$cache->set('shouldReplaceIcons', $value);
230
-		return $value;
231
-	}
232
-
233
-	/**
234
-	 * Increases the cache buster key
235
-	 */
236
-	private function increaseCacheBuster() {
237
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
238
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
239
-		$this->cacheFactory->create('theming')->clear('getScssVariables');
240
-	}
241
-
242
-	/**
243
-	 * Update setting in the database
244
-	 *
245
-	 * @param string $setting
246
-	 * @param string $value
247
-	 */
248
-	public function set($setting, $value) {
249
-		$this->config->setAppValue('theming', $setting, $value);
250
-		$this->increaseCacheBuster();
251
-	}
252
-
253
-	/**
254
-	 * Revert settings to the default value
255
-	 *
256
-	 * @param string $setting setting which should be reverted
257
-	 * @return string default value
258
-	 */
259
-	public function undo($setting) {
260
-		$this->config->deleteAppValue('theming', $setting);
261
-		$this->increaseCacheBuster();
262
-
263
-		switch ($setting) {
264
-			case 'name':
265
-				$returnValue = $this->getEntity();
266
-				break;
267
-			case 'url':
268
-				$returnValue = $this->getBaseUrl();
269
-				break;
270
-			case 'slogan':
271
-				$returnValue = $this->getSlogan();
272
-				break;
273
-			case 'color':
274
-				$returnValue = $this->getColorPrimary();
275
-				break;
276
-			default:
277
-				$returnValue = '';
278
-				break;
279
-		}
280
-
281
-		return $returnValue;
282
-	}
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
+        if(!$backgroundLogo || !$backgroundExists) {
169
+            return $this->urlGenerator->imagePath('core','background.jpg');
170
+        }
171
+
172
+        return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
173
+    }
174
+
175
+
176
+    /**
177
+     * @return array scss variables to overwrite
178
+     */
179
+    public function getScssVariables() {
180
+        $cache = $this->cacheFactory->create('theming');
181
+        if ($value = $cache->get('getScssVariables')) {
182
+            return $value;
183
+        }
184
+
185
+        $variables = [
186
+            'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'",
187
+        ];
188
+
189
+        $variables['image-logo'] = "'".$this->urlGenerator->getAbsoluteURL($this->getLogo())."'";
190
+        $variables['image-login-background'] = "'".$this->urlGenerator->getAbsoluteURL($this->getBackground())."'";
191
+        $variables['image-login-plain'] = 'false';
192
+
193
+        if ($this->config->getAppValue('theming', 'color', null) !== null) {
194
+            if ($this->util->invertTextColor($this->getColorPrimary())) {
195
+                $colorPrimaryText = '#000000';
196
+            } else {
197
+                $colorPrimaryText = '#ffffff';
198
+            }
199
+            $variables['color-primary'] = $this->getColorPrimary();
200
+            $variables['color-primary-text'] = $colorPrimaryText;
201
+        }
202
+
203
+        if ($this->config->getAppValue('theming', 'backgroundMime', null) === 'backgroundColor') {
204
+            $variables['image-login-plain'] = 'true';
205
+        }
206
+        $cache->set('getScssVariables', $variables);
207
+        return $variables;
208
+    }
209
+
210
+    /**
211
+     * Check if Imagemagick is enabled and if SVG is supported
212
+     * otherwise we can't render custom icons
213
+     *
214
+     * @return bool
215
+     */
216
+    public function shouldReplaceIcons() {
217
+        $cache = $this->cacheFactory->create('theming');
218
+        if($value = $cache->get('shouldReplaceIcons')) {
219
+            return (bool)$value;
220
+        }
221
+        $value = false;
222
+        if(extension_loaded('imagick')) {
223
+            $checkImagick = new \Imagick();
224
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
225
+                $value = true;
226
+            }
227
+            $checkImagick->clear();
228
+        }
229
+        $cache->set('shouldReplaceIcons', $value);
230
+        return $value;
231
+    }
232
+
233
+    /**
234
+     * Increases the cache buster key
235
+     */
236
+    private function increaseCacheBuster() {
237
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
238
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
239
+        $this->cacheFactory->create('theming')->clear('getScssVariables');
240
+    }
241
+
242
+    /**
243
+     * Update setting in the database
244
+     *
245
+     * @param string $setting
246
+     * @param string $value
247
+     */
248
+    public function set($setting, $value) {
249
+        $this->config->setAppValue('theming', $setting, $value);
250
+        $this->increaseCacheBuster();
251
+    }
252
+
253
+    /**
254
+     * Revert settings to the default value
255
+     *
256
+     * @param string $setting setting which should be reverted
257
+     * @return string default value
258
+     */
259
+    public function undo($setting) {
260
+        $this->config->deleteAppValue('theming', $setting);
261
+        $this->increaseCacheBuster();
262
+
263
+        switch ($setting) {
264
+            case 'name':
265
+                $returnValue = $this->getEntity();
266
+                break;
267
+            case 'url':
268
+                $returnValue = $this->getBaseUrl();
269
+                break;
270
+            case 'slogan':
271
+                $returnValue = $this->getSlogan();
272
+                break;
273
+            case 'color':
274
+                $returnValue = $this->getColorPrimary();
275
+                break;
276
+            default:
277
+                $returnValue = '';
278
+                break;
279
+        }
280
+
281
+        return $returnValue;
282
+    }
283 283
 
284 284
 }
Please login to merge, or discard this patch.
apps/theming/lib/Controller/ThemingController.php 2 patches
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -56,332 +56,332 @@  discard block
 block discarded – undo
56 56
  * @package OCA\Theming\Controller
57 57
  */
58 58
 class ThemingController extends Controller {
59
-	/** @var ThemingDefaults */
60
-	private $themingDefaults;
61
-	/** @var Util */
62
-	private $util;
63
-	/** @var ITimeFactory */
64
-	private $timeFactory;
65
-	/** @var IL10N */
66
-	private $l10n;
67
-	/** @var IConfig */
68
-	private $config;
69
-	/** @var ITempManager */
70
-	private $tempManager;
71
-	/** @var IAppData */
72
-	private $appData;
73
-	/** @var SCSSCacher */
74
-	private $scssCacher;
59
+    /** @var ThemingDefaults */
60
+    private $themingDefaults;
61
+    /** @var Util */
62
+    private $util;
63
+    /** @var ITimeFactory */
64
+    private $timeFactory;
65
+    /** @var IL10N */
66
+    private $l10n;
67
+    /** @var IConfig */
68
+    private $config;
69
+    /** @var ITempManager */
70
+    private $tempManager;
71
+    /** @var IAppData */
72
+    private $appData;
73
+    /** @var SCSSCacher */
74
+    private $scssCacher;
75 75
 
76
-	/**
77
-	 * ThemingController constructor.
78
-	 *
79
-	 * @param string $appName
80
-	 * @param IRequest $request
81
-	 * @param IConfig $config
82
-	 * @param ThemingDefaults $themingDefaults
83
-	 * @param Util $util
84
-	 * @param ITimeFactory $timeFactory
85
-	 * @param IL10N $l
86
-	 * @param ITempManager $tempManager
87
-	 * @param IAppData $appData
88
-	 * @param SCSSCacher $scssCacher
89
-	 */
90
-	public function __construct(
91
-		$appName,
92
-		IRequest $request,
93
-		IConfig $config,
94
-		ThemingDefaults $themingDefaults,
95
-		Util $util,
96
-		ITimeFactory $timeFactory,
97
-		IL10N $l,
98
-		ITempManager $tempManager,
99
-		IAppData $appData,
100
-		SCSSCacher $scssCacher
101
-	) {
102
-		parent::__construct($appName, $request);
76
+    /**
77
+     * ThemingController constructor.
78
+     *
79
+     * @param string $appName
80
+     * @param IRequest $request
81
+     * @param IConfig $config
82
+     * @param ThemingDefaults $themingDefaults
83
+     * @param Util $util
84
+     * @param ITimeFactory $timeFactory
85
+     * @param IL10N $l
86
+     * @param ITempManager $tempManager
87
+     * @param IAppData $appData
88
+     * @param SCSSCacher $scssCacher
89
+     */
90
+    public function __construct(
91
+        $appName,
92
+        IRequest $request,
93
+        IConfig $config,
94
+        ThemingDefaults $themingDefaults,
95
+        Util $util,
96
+        ITimeFactory $timeFactory,
97
+        IL10N $l,
98
+        ITempManager $tempManager,
99
+        IAppData $appData,
100
+        SCSSCacher $scssCacher
101
+    ) {
102
+        parent::__construct($appName, $request);
103 103
 
104
-		$this->themingDefaults = $themingDefaults;
105
-		$this->util = $util;
106
-		$this->timeFactory = $timeFactory;
107
-		$this->l10n = $l;
108
-		$this->config = $config;
109
-		$this->tempManager = $tempManager;
110
-		$this->appData = $appData;
111
-		$this->scssCacher = $scssCacher;
112
-	}
104
+        $this->themingDefaults = $themingDefaults;
105
+        $this->util = $util;
106
+        $this->timeFactory = $timeFactory;
107
+        $this->l10n = $l;
108
+        $this->config = $config;
109
+        $this->tempManager = $tempManager;
110
+        $this->appData = $appData;
111
+        $this->scssCacher = $scssCacher;
112
+    }
113 113
 
114
-	/**
115
-	 * @param string $setting
116
-	 * @param string $value
117
-	 * @return DataResponse
118
-	 * @internal param string $color
119
-	 */
120
-	public function updateStylesheet($setting, $value) {
121
-		$value = trim($value);
122
-		switch ($setting) {
123
-			case 'name':
124
-				if (strlen($value) > 250) {
125
-					return new DataResponse([
126
-						'data' => [
127
-							'message' => $this->l10n->t('The given name is too long'),
128
-						],
129
-						'status' => 'error'
130
-					]);
131
-				}
132
-				break;
133
-			case 'url':
134
-				if (strlen($value) > 500) {
135
-					return new DataResponse([
136
-						'data' => [
137
-							'message' => $this->l10n->t('The given web address is too long'),
138
-						],
139
-						'status' => 'error'
140
-					]);
141
-				}
142
-				break;
143
-			case 'slogan':
144
-				if (strlen($value) > 500) {
145
-					return new DataResponse([
146
-						'data' => [
147
-							'message' => $this->l10n->t('The given slogan is too long'),
148
-						],
149
-						'status' => 'error'
150
-					]);
151
-				}
152
-				break;
153
-			case 'color':
154
-				if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
155
-					return new DataResponse([
156
-						'data' => [
157
-							'message' => $this->l10n->t('The given color is invalid'),
158
-						],
159
-						'status' => 'error'
160
-					]);
161
-				}
162
-				break;
163
-		}
114
+    /**
115
+     * @param string $setting
116
+     * @param string $value
117
+     * @return DataResponse
118
+     * @internal param string $color
119
+     */
120
+    public function updateStylesheet($setting, $value) {
121
+        $value = trim($value);
122
+        switch ($setting) {
123
+            case 'name':
124
+                if (strlen($value) > 250) {
125
+                    return new DataResponse([
126
+                        'data' => [
127
+                            'message' => $this->l10n->t('The given name is too long'),
128
+                        ],
129
+                        'status' => 'error'
130
+                    ]);
131
+                }
132
+                break;
133
+            case 'url':
134
+                if (strlen($value) > 500) {
135
+                    return new DataResponse([
136
+                        'data' => [
137
+                            'message' => $this->l10n->t('The given web address is too long'),
138
+                        ],
139
+                        'status' => 'error'
140
+                    ]);
141
+                }
142
+                break;
143
+            case 'slogan':
144
+                if (strlen($value) > 500) {
145
+                    return new DataResponse([
146
+                        'data' => [
147
+                            'message' => $this->l10n->t('The given slogan is too long'),
148
+                        ],
149
+                        'status' => 'error'
150
+                    ]);
151
+                }
152
+                break;
153
+            case 'color':
154
+                if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
155
+                    return new DataResponse([
156
+                        'data' => [
157
+                            'message' => $this->l10n->t('The given color is invalid'),
158
+                        ],
159
+                        'status' => 'error'
160
+                    ]);
161
+                }
162
+                break;
163
+        }
164 164
 
165
-		$this->themingDefaults->set($setting, $value);
165
+        $this->themingDefaults->set($setting, $value);
166 166
 
167
-		// reprocess server scss for preview
168
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
167
+        // reprocess server scss for preview
168
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
169 169
 
170
-		return new DataResponse(
171
-			[
172
-				'data' =>
173
-					[
174
-						'message' => $this->l10n->t('Saved')
175
-					],
176
-				'status' => 'success'
177
-			]
178
-		);
179
-	}
170
+        return new DataResponse(
171
+            [
172
+                'data' =>
173
+                    [
174
+                        'message' => $this->l10n->t('Saved')
175
+                    ],
176
+                'status' => 'success'
177
+            ]
178
+        );
179
+    }
180 180
 
181
-	/**
182
-	 * Update the logos and background image
183
-	 *
184
-	 * @return DataResponse
185
-	 */
186
-	public function updateLogo() {
187
-		$backgroundColor = $this->request->getParam('backgroundColor', false);
188
-		if($backgroundColor) {
189
-			$this->themingDefaults->set('backgroundMime', 'backgroundColor');
190
-			return new DataResponse(
191
-				[
192
-					'data' =>
193
-						[
194
-							'name' => 'backgroundColor',
195
-							'message' => $this->l10n->t('Saved')
196
-						],
197
-					'status' => 'success'
198
-				]
199
-			);
200
-		}
201
-		$newLogo = $this->request->getUploadedFile('uploadlogo');
202
-		$newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
203
-		if (empty($newLogo) && empty($newBackgroundLogo)) {
204
-			return new DataResponse(
205
-				[
206
-					'data' => [
207
-						'message' => $this->l10n->t('No file uploaded')
208
-					]
209
-				],
210
-				Http::STATUS_UNPROCESSABLE_ENTITY
211
-			);
212
-		}
181
+    /**
182
+     * Update the logos and background image
183
+     *
184
+     * @return DataResponse
185
+     */
186
+    public function updateLogo() {
187
+        $backgroundColor = $this->request->getParam('backgroundColor', false);
188
+        if($backgroundColor) {
189
+            $this->themingDefaults->set('backgroundMime', 'backgroundColor');
190
+            return new DataResponse(
191
+                [
192
+                    'data' =>
193
+                        [
194
+                            'name' => 'backgroundColor',
195
+                            'message' => $this->l10n->t('Saved')
196
+                        ],
197
+                    'status' => 'success'
198
+                ]
199
+            );
200
+        }
201
+        $newLogo = $this->request->getUploadedFile('uploadlogo');
202
+        $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
203
+        if (empty($newLogo) && empty($newBackgroundLogo)) {
204
+            return new DataResponse(
205
+                [
206
+                    'data' => [
207
+                        'message' => $this->l10n->t('No file uploaded')
208
+                    ]
209
+                ],
210
+                Http::STATUS_UNPROCESSABLE_ENTITY
211
+            );
212
+        }
213 213
 
214
-		$name = '';
215
-		try {
216
-			$folder = $this->appData->getFolder('images');
217
-		} catch (NotFoundException $e) {
218
-			$folder = $this->appData->newFolder('images');
219
-		}
214
+        $name = '';
215
+        try {
216
+            $folder = $this->appData->getFolder('images');
217
+        } catch (NotFoundException $e) {
218
+            $folder = $this->appData->newFolder('images');
219
+        }
220 220
 
221
-		if (!empty($newLogo)) {
222
-			$target = $folder->newFile('logo');
223
-			$target->putContent(file_get_contents($newLogo['tmp_name'], 'r'));
224
-			$this->themingDefaults->set('logoMime', $newLogo['type']);
225
-			$name = $newLogo['name'];
226
-		}
227
-		if (!empty($newBackgroundLogo)) {
228
-			$target = $folder->newFile('background');
229
-			$image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r'));
230
-			if ($image === false) {
231
-				return new DataResponse(
232
-					[
233
-						'data' => [
234
-							'message' => $this->l10n->t('Unsupported image type'),
235
-						],
236
-						'status' => 'failure',
237
-					],
238
-					Http::STATUS_UNPROCESSABLE_ENTITY
239
-				);
240
-			}
221
+        if (!empty($newLogo)) {
222
+            $target = $folder->newFile('logo');
223
+            $target->putContent(file_get_contents($newLogo['tmp_name'], 'r'));
224
+            $this->themingDefaults->set('logoMime', $newLogo['type']);
225
+            $name = $newLogo['name'];
226
+        }
227
+        if (!empty($newBackgroundLogo)) {
228
+            $target = $folder->newFile('background');
229
+            $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r'));
230
+            if ($image === false) {
231
+                return new DataResponse(
232
+                    [
233
+                        'data' => [
234
+                            'message' => $this->l10n->t('Unsupported image type'),
235
+                        ],
236
+                        'status' => 'failure',
237
+                    ],
238
+                    Http::STATUS_UNPROCESSABLE_ENTITY
239
+                );
240
+            }
241 241
 
242
-			// Optimize the image since some people may upload images that will be
243
-			// either to big or are not progressive rendering.
244
-			$tmpFile = $this->tempManager->getTemporaryFile();
245
-			if (function_exists('imagescale')) {
246
-				// FIXME: Once PHP 5.5.0 is a requirement the above check can be removed
247
-				// Workaround for https://bugs.php.net/bug.php?id=65171
248
-				$newHeight = imagesy($image) / (imagesx($image) / 1920);
249
-				$image = imagescale($image, 1920, $newHeight);
250
-			}
251
-			imageinterlace($image, 1);
252
-			imagejpeg($image, $tmpFile, 75);
253
-			imagedestroy($image);
242
+            // Optimize the image since some people may upload images that will be
243
+            // either to big or are not progressive rendering.
244
+            $tmpFile = $this->tempManager->getTemporaryFile();
245
+            if (function_exists('imagescale')) {
246
+                // FIXME: Once PHP 5.5.0 is a requirement the above check can be removed
247
+                // Workaround for https://bugs.php.net/bug.php?id=65171
248
+                $newHeight = imagesy($image) / (imagesx($image) / 1920);
249
+                $image = imagescale($image, 1920, $newHeight);
250
+            }
251
+            imageinterlace($image, 1);
252
+            imagejpeg($image, $tmpFile, 75);
253
+            imagedestroy($image);
254 254
 
255
-			$target->putContent(file_get_contents($tmpFile, 'r'));
256
-			$this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']);
257
-			$name = $newBackgroundLogo['name'];
258
-		}
255
+            $target->putContent(file_get_contents($tmpFile, 'r'));
256
+            $this->themingDefaults->set('backgroundMime', $newBackgroundLogo['type']);
257
+            $name = $newBackgroundLogo['name'];
258
+        }
259 259
 
260
-		return new DataResponse(
261
-			[
262
-				'data' =>
263
-					[
264
-						'name' => $name,
265
-						'message' => $this->l10n->t('Saved')
266
-					],
267
-				'status' => 'success'
268
-			]
269
-		);
270
-	}
260
+        return new DataResponse(
261
+            [
262
+                'data' =>
263
+                    [
264
+                        'name' => $name,
265
+                        'message' => $this->l10n->t('Saved')
266
+                    ],
267
+                'status' => 'success'
268
+            ]
269
+        );
270
+    }
271 271
 
272
-	/**
273
-	 * Revert setting to default value
274
-	 *
275
-	 * @param string $setting setting which should be reverted
276
-	 * @return DataResponse
277
-	 */
278
-	public function undo($setting) {
279
-		$value = $this->themingDefaults->undo($setting);
280
-		// reprocess server scss for preview
281
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
282
-		return new DataResponse(
283
-			[
284
-				'data' =>
285
-					[
286
-						'value' => $value,
287
-						'message' => $this->l10n->t('Saved')
288
-					],
289
-				'status' => 'success'
290
-			]
291
-		);
292
-	}
272
+    /**
273
+     * Revert setting to default value
274
+     *
275
+     * @param string $setting setting which should be reverted
276
+     * @return DataResponse
277
+     */
278
+    public function undo($setting) {
279
+        $value = $this->themingDefaults->undo($setting);
280
+        // reprocess server scss for preview
281
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core');
282
+        return new DataResponse(
283
+            [
284
+                'data' =>
285
+                    [
286
+                        'value' => $value,
287
+                        'message' => $this->l10n->t('Saved')
288
+                    ],
289
+                'status' => 'success'
290
+            ]
291
+        );
292
+    }
293 293
 
294
-	/**
295
-	 * @PublicPage
296
-	 * @NoCSRFRequired
297
-	 *
298
-	 * @return FileDisplayResponse|NotFoundResponse
299
-	 */
300
-	public function getLogo() {
301
-		try {
302
-			/** @var File $file */
303
-			$file = $this->appData->getFolder('images')->getFile('logo');
304
-		} catch (NotFoundException $e) {
305
-			return new NotFoundResponse();
306
-		}
294
+    /**
295
+     * @PublicPage
296
+     * @NoCSRFRequired
297
+     *
298
+     * @return FileDisplayResponse|NotFoundResponse
299
+     */
300
+    public function getLogo() {
301
+        try {
302
+            /** @var File $file */
303
+            $file = $this->appData->getFolder('images')->getFile('logo');
304
+        } catch (NotFoundException $e) {
305
+            return new NotFoundResponse();
306
+        }
307 307
 
308
-		$response = new FileDisplayResponse($file);
309
-		$response->cacheFor(3600);
310
-		$expires = new \DateTime();
311
-		$expires->setTimestamp($this->timeFactory->getTime());
312
-		$expires->add(new \DateInterval('PT24H'));
313
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
314
-		$response->addHeader('Pragma', 'cache');
315
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
316
-		return $response;
317
-	}
308
+        $response = new FileDisplayResponse($file);
309
+        $response->cacheFor(3600);
310
+        $expires = new \DateTime();
311
+        $expires->setTimestamp($this->timeFactory->getTime());
312
+        $expires->add(new \DateInterval('PT24H'));
313
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
314
+        $response->addHeader('Pragma', 'cache');
315
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
316
+        return $response;
317
+    }
318 318
 
319
-	/**
320
-	 * @PublicPage
321
-	 * @NoCSRFRequired
322
-	 *
323
-	 * @return FileDisplayResponse|NotFoundResponse
324
-	 */
325
-	public function getLoginBackground() {
326
-		try {
327
-			/** @var File $file */
328
-			$file = $this->appData->getFolder('images')->getFile('background');
329
-		} catch (NotFoundException $e) {
330
-			return new NotFoundResponse();
331
-		}
319
+    /**
320
+     * @PublicPage
321
+     * @NoCSRFRequired
322
+     *
323
+     * @return FileDisplayResponse|NotFoundResponse
324
+     */
325
+    public function getLoginBackground() {
326
+        try {
327
+            /** @var File $file */
328
+            $file = $this->appData->getFolder('images')->getFile('background');
329
+        } catch (NotFoundException $e) {
330
+            return new NotFoundResponse();
331
+        }
332 332
 
333
-		$response = new FileDisplayResponse($file);
334
-		$response->cacheFor(3600);
335
-		$expires = new \DateTime();
336
-		$expires->setTimestamp($this->timeFactory->getTime());
337
-		$expires->add(new \DateInterval('PT24H'));
338
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
339
-		$response->addHeader('Pragma', 'cache');
340
-		$response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
341
-		return $response;
342
-	}
333
+        $response = new FileDisplayResponse($file);
334
+        $response->cacheFor(3600);
335
+        $expires = new \DateTime();
336
+        $expires->setTimestamp($this->timeFactory->getTime());
337
+        $expires->add(new \DateInterval('PT24H'));
338
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
339
+        $response->addHeader('Pragma', 'cache');
340
+        $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
341
+        return $response;
342
+    }
343 343
 
344
-	/**
345
-	 * @NoCSRFRequired
346
-	 * @PublicPage
347
-	 *
348
-	 * @return FileDisplayResponse|NotFoundResponse
349
-	 */
350
-	public function getStylesheet() {
351
-		$appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1);
352
-		/* SCSSCacher is required here
344
+    /**
345
+     * @NoCSRFRequired
346
+     * @PublicPage
347
+     *
348
+     * @return FileDisplayResponse|NotFoundResponse
349
+     */
350
+    public function getStylesheet() {
351
+        $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1);
352
+        /* SCSSCacher is required here
353 353
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
354 354
 		 * since we need to add the cacheBuster value to the url
355 355
 		 */
356
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
357
-		if(!$cssCached) {
358
-			return new NotFoundResponse();
359
-		}
356
+        $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
357
+        if(!$cssCached) {
358
+            return new NotFoundResponse();
359
+        }
360 360
 
361
-		try {
362
-			$cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
363
-			$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
364
-			$response->cacheFor(86400);
365
-			$expires = new \DateTime();
366
-			$expires->setTimestamp($this->timeFactory->getTime());
367
-			$expires->add(new \DateInterval('PT24H'));
368
-			$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
369
-			$response->addHeader('Pragma', 'cache');
370
-			return $response;
371
-		} catch (NotFoundException $e) {
372
-			return new NotFoundResponse();
373
-		}
374
-	}
361
+        try {
362
+            $cssFile = $this->scssCacher->getCachedCSS('theming', 'theming.css');
363
+            $response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
364
+            $response->cacheFor(86400);
365
+            $expires = new \DateTime();
366
+            $expires->setTimestamp($this->timeFactory->getTime());
367
+            $expires->add(new \DateInterval('PT24H'));
368
+            $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
369
+            $response->addHeader('Pragma', 'cache');
370
+            return $response;
371
+        } catch (NotFoundException $e) {
372
+            return new NotFoundResponse();
373
+        }
374
+    }
375 375
 
376
-	/**
377
-	 * @NoCSRFRequired
378
-	 * @PublicPage
379
-	 *
380
-	 * @return DataDownloadResponse
381
-	 */
382
-	public function getJavascript() {
383
-		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
384
-		$responseJS = '(function() {
376
+    /**
377
+     * @NoCSRFRequired
378
+     * @PublicPage
379
+     *
380
+     * @return DataDownloadResponse
381
+     */
382
+    public function getJavascript() {
383
+        $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
384
+        $responseJS = '(function() {
385 385
 	OCA.Theming = {
386 386
 		name: ' . json_encode($this->themingDefaults->getName()) . ',
387 387
 		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
@@ -391,10 +391,10 @@  discard block
 block discarded – undo
391 391
 		cacheBuster: ' . json_encode($cacheBusterValue) . '
392 392
 	};
393 393
 })();';
394
-		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
395
-		$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
396
-		$response->addHeader('Pragma', 'cache');
397
-		$response->cacheFor(3600);
398
-		return $response;
399
-	}
394
+        $response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
395
+        $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
396
+        $response->addHeader('Pragma', 'cache');
397
+        $response->cacheFor(3600);
398
+        return $response;
399
+    }
400 400
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 */
186 186
 	public function updateLogo() {
187 187
 		$backgroundColor = $this->request->getParam('backgroundColor', false);
188
-		if($backgroundColor) {
188
+		if ($backgroundColor) {
189 189
 			$this->themingDefaults->set('backgroundMime', 'backgroundColor');
190 190
 			return new DataResponse(
191 191
 				[
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 		 * We cannot rely on automatic caching done by \OC_Util::addStyle,
354 354
 		 * since we need to add the cacheBuster value to the url
355 355
 		 */
356
-		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming');
357
-		if(!$cssCached) {
356
+		$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath.'/css/theming.scss', 'theming');
357
+		if (!$cssCached) {
358 358
 			return new NotFoundResponse();
359 359
 		}
360 360
 
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
 		$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
384 384
 		$responseJS = '(function() {
385 385
 	OCA.Theming = {
386
-		name: ' . json_encode($this->themingDefaults->getName()) . ',
387
-		url: ' . json_encode($this->themingDefaults->getBaseUrl()) . ',
388
-		slogan: ' . json_encode($this->themingDefaults->getSlogan()) . ',
389
-		color: ' . json_encode($this->themingDefaults->getColorPrimary()) . ',
390
-		inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())) . ',
391
-		cacheBuster: ' . json_encode($cacheBusterValue) . '
386
+		name: ' . json_encode($this->themingDefaults->getName()).',
387
+		url: ' . json_encode($this->themingDefaults->getBaseUrl()).',
388
+		slogan: ' . json_encode($this->themingDefaults->getSlogan()).',
389
+		color: ' . json_encode($this->themingDefaults->getColorPrimary()).',
390
+		inverted: ' . json_encode($this->util->invertTextColor($this->themingDefaults->getColorPrimary())).',
391
+		cacheBuster: ' . json_encode($cacheBusterValue).'
392 392
 	};
393 393
 })();';
394 394
 		$response = new DataDownloadResponse($responseJS, 'javascript', 'text/javascript');
Please login to merge, or discard this patch.