Completed
Pull Request — master (#3868)
by Joas
341:41 queued 329:19
created
apps/theming/lib/ThemingDefaults.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -32,196 +32,196 @@
 block discarded – undo
32 32
 
33 33
 class ThemingDefaults extends \OC_Defaults {
34 34
 
35
-	/** @var IConfig */
36
-	private $config;
37
-	/** @var IL10N */
38
-	private $l;
39
-	/** @var IURLGenerator */
40
-	private $urlGenerator;
41
-	/** @var IRootFolder */
42
-	private $rootFolder;
43
-	/** @var ICacheFactory */
44
-	private $cacheFactory;
45
-	/** @var string */
46
-	private $name;
47
-	/** @var string */
48
-	private $url;
49
-	/** @var string */
50
-	private $slogan;
51
-	/** @var string */
52
-	private $color;
53
-
54
-	/**
55
-	 * ThemingDefaults constructor.
56
-	 *
57
-	 * @param IConfig $config
58
-	 * @param IL10N $l
59
-	 * @param IURLGenerator $urlGenerator
60
-	 * @param \OC_Defaults $defaults
61
-	 * @param IRootFolder $rootFolder
62
-	 * @param ICacheFactory $cacheFactory
63
-	 */
64
-	public function __construct(IConfig $config,
65
-								IL10N $l,
66
-								IURLGenerator $urlGenerator,
67
-								\OC_Defaults $defaults,
68
-								IRootFolder $rootFolder,
69
-								ICacheFactory $cacheFactory
70
-	) {
71
-		parent::__construct();
72
-		$this->config = $config;
73
-		$this->l = $l;
74
-		$this->urlGenerator = $urlGenerator;
75
-		$this->rootFolder = $rootFolder;
76
-		$this->cacheFactory = $cacheFactory;
77
-
78
-		$this->name = $defaults->getName();
79
-		$this->url = $defaults->getBaseUrl();
80
-		$this->slogan = $defaults->getSlogan();
81
-		$this->color = $defaults->getMailHeaderColor();
82
-	}
83
-
84
-	public function getName() {
85
-		return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
-	}
87
-
88
-	public function getHTMLName() {
89
-		return $this->config->getAppValue('theming', 'name', $this->name);
90
-	}
91
-
92
-	public function getTitle() {
93
-		return $this->getName();
94
-	}
95
-
96
-	public function getEntity() {
97
-		return $this->getName();
98
-	}
99
-
100
-	public function getBaseUrl() {
101
-		return $this->config->getAppValue('theming', 'url', $this->url);
102
-	}
103
-
104
-	public function getSlogan() {
105
-		return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
-	}
107
-
108
-	public function getShortFooter() {
109
-		$slogan = $this->getSlogan();
110
-		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
-			' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
-			($slogan !== '' ? ' – ' . $slogan : '');
113
-
114
-		return $footer;
115
-	}
116
-
117
-	/**
118
-	 * Color that is used for the header as well as for mail headers
119
-	 *
120
-	 * @return string
121
-	 */
122
-	public function getMailHeaderColor() {
123
-		return $this->config->getAppValue('theming', 'color', $this->color);
124
-	}
125
-
126
-	/**
127
-	 * Themed logo url
128
-	 *
129
-	 * @return string
130
-	 */
131
-	public function getLogo() {
132
-		$logo = $this->config->getAppValue('theming', 'logoMime');
133
-		if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) {
134
-			return $this->urlGenerator->imagePath('core','logo.svg');
135
-		} else {
136
-			return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
137
-		}
138
-	}
139
-
140
-	/**
141
-	 * Themed background image url
142
-	 *
143
-	 * @return string
144
-	 */
145
-	public function getBackground() {
146
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
147
-		if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) {
148
-			return $this->urlGenerator->imagePath('core','background.jpg');
149
-		} else {
150
-			return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Check if Imagemagick is enabled and if SVG is supported
156
-	 * otherwise we can't render custom icons
157
-	 *
158
-	 * @return bool
159
-	 */
160
-	public function shouldReplaceIcons() {
161
-		$cache = $this->cacheFactory->create('theming');
162
-		if($value = $cache->get('shouldReplaceIcons')) {
163
-			return (bool)$value;
164
-		}
165
-		$value = false;
166
-		if(extension_loaded('imagick')) {
167
-			$checkImagick = new \Imagick();
168
-			if (count($checkImagick->queryFormats('SVG')) >= 1) {
169
-				$value = true;
170
-			}
171
-			$checkImagick->clear();
172
-		}
173
-		$cache->set('shouldReplaceIcons', $value);
174
-		return $value;
175
-	}
176
-
177
-	/**
178
-	 * Increases the cache buster key
179
-	 */
180
-	private function increaseCacheBuster() {
181
-		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
182
-		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
183
-	}
184
-
185
-	/**
186
-	 * Update setting in the database
187
-	 *
188
-	 * @param string $setting
189
-	 * @param string $value
190
-	 */
191
-	public function set($setting, $value) {
192
-		$this->config->setAppValue('theming', $setting, $value);
193
-		$this->increaseCacheBuster();
194
-	}
195
-
196
-	/**
197
-	 * Revert settings to the default value
198
-	 *
199
-	 * @param string $setting setting which should be reverted
200
-	 * @return string default value
201
-	 */
202
-	public function undo($setting) {
203
-		$this->config->deleteAppValue('theming', $setting);
204
-		$this->increaseCacheBuster();
205
-
206
-		switch ($setting) {
207
-			case 'name':
208
-				$returnValue = $this->getEntity();
209
-				break;
210
-			case 'url':
211
-				$returnValue = $this->getBaseUrl();
212
-				break;
213
-			case 'slogan':
214
-				$returnValue = $this->getSlogan();
215
-				break;
216
-			case 'color':
217
-				$returnValue = $this->getMailHeaderColor();
218
-				break;
219
-			default:
220
-				$returnValue = '';
221
-				break;
222
-		}
223
-
224
-		return $returnValue;
225
-	}
35
+    /** @var IConfig */
36
+    private $config;
37
+    /** @var IL10N */
38
+    private $l;
39
+    /** @var IURLGenerator */
40
+    private $urlGenerator;
41
+    /** @var IRootFolder */
42
+    private $rootFolder;
43
+    /** @var ICacheFactory */
44
+    private $cacheFactory;
45
+    /** @var string */
46
+    private $name;
47
+    /** @var string */
48
+    private $url;
49
+    /** @var string */
50
+    private $slogan;
51
+    /** @var string */
52
+    private $color;
53
+
54
+    /**
55
+     * ThemingDefaults constructor.
56
+     *
57
+     * @param IConfig $config
58
+     * @param IL10N $l
59
+     * @param IURLGenerator $urlGenerator
60
+     * @param \OC_Defaults $defaults
61
+     * @param IRootFolder $rootFolder
62
+     * @param ICacheFactory $cacheFactory
63
+     */
64
+    public function __construct(IConfig $config,
65
+                                IL10N $l,
66
+                                IURLGenerator $urlGenerator,
67
+                                \OC_Defaults $defaults,
68
+                                IRootFolder $rootFolder,
69
+                                ICacheFactory $cacheFactory
70
+    ) {
71
+        parent::__construct();
72
+        $this->config = $config;
73
+        $this->l = $l;
74
+        $this->urlGenerator = $urlGenerator;
75
+        $this->rootFolder = $rootFolder;
76
+        $this->cacheFactory = $cacheFactory;
77
+
78
+        $this->name = $defaults->getName();
79
+        $this->url = $defaults->getBaseUrl();
80
+        $this->slogan = $defaults->getSlogan();
81
+        $this->color = $defaults->getMailHeaderColor();
82
+    }
83
+
84
+    public function getName() {
85
+        return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
86
+    }
87
+
88
+    public function getHTMLName() {
89
+        return $this->config->getAppValue('theming', 'name', $this->name);
90
+    }
91
+
92
+    public function getTitle() {
93
+        return $this->getName();
94
+    }
95
+
96
+    public function getEntity() {
97
+        return $this->getName();
98
+    }
99
+
100
+    public function getBaseUrl() {
101
+        return $this->config->getAppValue('theming', 'url', $this->url);
102
+    }
103
+
104
+    public function getSlogan() {
105
+        return Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan));
106
+    }
107
+
108
+    public function getShortFooter() {
109
+        $slogan = $this->getSlogan();
110
+        $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
111
+            ' rel="noreferrer">' .$this->getEntity() . '</a>'.
112
+            ($slogan !== '' ? ' – ' . $slogan : '');
113
+
114
+        return $footer;
115
+    }
116
+
117
+    /**
118
+     * Color that is used for the header as well as for mail headers
119
+     *
120
+     * @return string
121
+     */
122
+    public function getMailHeaderColor() {
123
+        return $this->config->getAppValue('theming', 'color', $this->color);
124
+    }
125
+
126
+    /**
127
+     * Themed logo url
128
+     *
129
+     * @return string
130
+     */
131
+    public function getLogo() {
132
+        $logo = $this->config->getAppValue('theming', 'logoMime');
133
+        if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) {
134
+            return $this->urlGenerator->imagePath('core','logo.svg');
135
+        } else {
136
+            return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
137
+        }
138
+    }
139
+
140
+    /**
141
+     * Themed background image url
142
+     *
143
+     * @return string
144
+     */
145
+    public function getBackground() {
146
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
147
+        if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) {
148
+            return $this->urlGenerator->imagePath('core','background.jpg');
149
+        } else {
150
+            return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Check if Imagemagick is enabled and if SVG is supported
156
+     * otherwise we can't render custom icons
157
+     *
158
+     * @return bool
159
+     */
160
+    public function shouldReplaceIcons() {
161
+        $cache = $this->cacheFactory->create('theming');
162
+        if($value = $cache->get('shouldReplaceIcons')) {
163
+            return (bool)$value;
164
+        }
165
+        $value = false;
166
+        if(extension_loaded('imagick')) {
167
+            $checkImagick = new \Imagick();
168
+            if (count($checkImagick->queryFormats('SVG')) >= 1) {
169
+                $value = true;
170
+            }
171
+            $checkImagick->clear();
172
+        }
173
+        $cache->set('shouldReplaceIcons', $value);
174
+        return $value;
175
+    }
176
+
177
+    /**
178
+     * Increases the cache buster key
179
+     */
180
+    private function increaseCacheBuster() {
181
+        $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
182
+        $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
183
+    }
184
+
185
+    /**
186
+     * Update setting in the database
187
+     *
188
+     * @param string $setting
189
+     * @param string $value
190
+     */
191
+    public function set($setting, $value) {
192
+        $this->config->setAppValue('theming', $setting, $value);
193
+        $this->increaseCacheBuster();
194
+    }
195
+
196
+    /**
197
+     * Revert settings to the default value
198
+     *
199
+     * @param string $setting setting which should be reverted
200
+     * @return string default value
201
+     */
202
+    public function undo($setting) {
203
+        $this->config->deleteAppValue('theming', $setting);
204
+        $this->increaseCacheBuster();
205
+
206
+        switch ($setting) {
207
+            case 'name':
208
+                $returnValue = $this->getEntity();
209
+                break;
210
+            case 'url':
211
+                $returnValue = $this->getBaseUrl();
212
+                break;
213
+            case 'slogan':
214
+                $returnValue = $this->getSlogan();
215
+                break;
216
+            case 'color':
217
+                $returnValue = $this->getMailHeaderColor();
218
+                break;
219
+            default:
220
+                $returnValue = '';
221
+                break;
222
+        }
223
+
224
+        return $returnValue;
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.