Passed
Push — master ( 39f0aa...ff8cfb )
by Morris
13:54 queued 12s
created

OC_Defaults::getProductName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Daniel Kesselberg <[email protected]>
8
 * @author Jan-Christoph Borchardt <[email protected]>
9
 * @author Jörn Friedrich Dreyer <[email protected]>
10
 * @author Julius Haertl <[email protected]>
11
 * @author Julius Härtl <[email protected]>
12
 * @author Lukas Reschke <[email protected]>
13
 * @author Markus Staab <[email protected]>
14
 * @author Michael Weimann <[email protected]>
15
 * @author Morris Jobke <[email protected]>
16
 * @author Pascal de Bruijn <[email protected]>
17
 * @author Robin Appelman <[email protected]>
18
 * @author Robin McCorkell <[email protected]>
19
 * @author Roeland Jago Douma <[email protected]>
20
 * @author scolebrook <[email protected]>
21
 * @author Thomas Müller <[email protected]>
22
 * @author Volkan Gezer <[email protected]>
23
 *
24
 * @license AGPL-3.0
25
 *
26
 * This code is free software: you can redistribute it and/or modify
27
 * it under the terms of the GNU Affero General Public License, version 3,
28
 * as published by the Free Software Foundation.
29
 *
30
 * This program is distributed in the hope that it will be useful,
31
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
 * GNU Affero General Public License for more details.
34
 *
35
 * You should have received a copy of the GNU Affero General Public License, version 3,
36
 * along with this program. If not, see <http://www.gnu.org/licenses/>
37
 *
38
 */
39
40
class OC_Defaults {
41
	private $theme;
42
43
	private $defaultEntity;
44
	private $defaultName;
45
	private $defaultTitle;
46
	private $defaultBaseUrl;
47
	private $defaultSyncClientUrl;
48
	private $defaultiOSClientUrl;
49
	private $defaultiTunesAppId;
50
	private $defaultAndroidClientUrl;
51
	private $defaultDocBaseUrl;
52
	private $defaultDocVersion;
53
	private $defaultSlogan;
54
	private $defaultColorPrimary;
55
	private $defaultTextColorPrimary;
56
	private $defaultProductName;
57
58
	public function __construct() {
59
		$config = \OC::$server->getConfig();
60
61
		$this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
62
		$this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
63
		$this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
64
		$this->defaultBaseUrl = 'https://nextcloud.com';
65
		$this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients');
66
		$this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
67
		$this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102');
68
		$this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client');
69
		$this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
70
		$this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links
71
		$this->defaultColorPrimary = '#0082c9';
72
		$this->defaultTextColorPrimary = '#ffffff';
73
		$this->defaultProductName = 'Nextcloud';
74
75
		$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
76
		if (file_exists($themePath)) {
77
			// prevent defaults.php from printing output
78
			ob_start();
79
			require_once $themePath;
80
			ob_end_clean();
81
			if (class_exists('OC_Theme')) {
82
				$this->theme = new OC_Theme();
83
			}
84
		}
85
	}
86
87
	/**
88
	 * @param string $method
89
	 */
90
	private function themeExist($method) {
91
		if (isset($this->theme) && method_exists($this->theme, $method)) {
92
			return true;
93
		}
94
		return false;
95
	}
96
97
	/**
98
	 * Returns the base URL
99
	 * @return string URL
100
	 */
101
	public function getBaseUrl() {
102
		if ($this->themeExist('getBaseUrl')) {
103
			return $this->theme->getBaseUrl();
104
		} else {
105
			return $this->defaultBaseUrl;
106
		}
107
	}
108
109
	/**
110
	 * Returns the URL where the sync clients are listed
111
	 * @return string URL
112
	 */
113
	public function getSyncClientUrl() {
114
		if ($this->themeExist('getSyncClientUrl')) {
115
			return $this->theme->getSyncClientUrl();
116
		} else {
117
			return $this->defaultSyncClientUrl;
118
		}
119
	}
120
121
	/**
122
	 * Returns the URL to the App Store for the iOS Client
123
	 * @return string URL
124
	 */
125
	public function getiOSClientUrl() {
126
		if ($this->themeExist('getiOSClientUrl')) {
127
			return $this->theme->getiOSClientUrl();
128
		} else {
129
			return $this->defaultiOSClientUrl;
130
		}
131
	}
132
133
	/**
134
	 * Returns the AppId for the App Store for the iOS Client
135
	 * @return string AppId
136
	 */
137
	public function getiTunesAppId() {
138
		if ($this->themeExist('getiTunesAppId')) {
139
			return $this->theme->getiTunesAppId();
140
		} else {
141
			return $this->defaultiTunesAppId;
142
		}
143
	}
144
145
	/**
146
	 * Returns the URL to Google Play for the Android Client
147
	 * @return string URL
148
	 */
149
	public function getAndroidClientUrl() {
150
		if ($this->themeExist('getAndroidClientUrl')) {
151
			return $this->theme->getAndroidClientUrl();
152
		} else {
153
			return $this->defaultAndroidClientUrl;
154
		}
155
	}
156
157
	/**
158
	 * Returns the documentation URL
159
	 * @return string URL
160
	 */
161
	public function getDocBaseUrl() {
162
		if ($this->themeExist('getDocBaseUrl')) {
163
			return $this->theme->getDocBaseUrl();
164
		} else {
165
			return $this->defaultDocBaseUrl;
166
		}
167
	}
168
169
	/**
170
	 * Returns the title
171
	 * @return string title
172
	 */
173
	public function getTitle() {
174
		if ($this->themeExist('getTitle')) {
175
			return $this->theme->getTitle();
176
		} else {
177
			return $this->defaultTitle;
178
		}
179
	}
180
181
	/**
182
	 * Returns the short name of the software
183
	 * @return string title
184
	 */
185
	public function getName() {
186
		if ($this->themeExist('getName')) {
187
			return $this->theme->getName();
188
		} else {
189
			return $this->defaultName;
190
		}
191
	}
192
193
	/**
194
	 * Returns the short name of the software containing HTML strings
195
	 * @return string title
196
	 */
197
	public function getHTMLName() {
198
		if ($this->themeExist('getHTMLName')) {
199
			return $this->theme->getHTMLName();
200
		} else {
201
			return $this->defaultName;
202
		}
203
	}
204
205
	/**
206
	 * Returns entity (e.g. company name) - used for footer, copyright
207
	 * @return string entity name
208
	 */
209
	public function getEntity() {
210
		if ($this->themeExist('getEntity')) {
211
			return $this->theme->getEntity();
212
		} else {
213
			return $this->defaultEntity;
214
		}
215
	}
216
217
	/**
218
	 * Returns slogan
219
	 * @return string slogan
220
	 */
221
	public function getSlogan(?string $lang = null) {
222
		if ($this->themeExist('getSlogan')) {
223
			return $this->theme->getSlogan($lang);
224
		} else {
225
			if ($this->defaultSlogan === null) {
226
				$l10n = \OC::$server->getL10N('lib', $lang);
227
				$this->defaultSlogan = $l10n->t('a safe home for all your data');
228
			}
229
			return $this->defaultSlogan;
230
		}
231
	}
232
233
	/**
234
	 * Returns logo claim
235
	 * @return string logo claim
236
	 * @deprecated 13.0.0
237
	 */
238
	public function getLogoClaim() {
239
		return '';
240
	}
241
242
	/**
243
	 * Returns short version of the footer
244
	 * @return string short footer
245
	 */
246
	public function getShortFooter() {
247
		if ($this->themeExist('getShortFooter')) {
248
			$footer = $this->theme->getShortFooter();
249
		} else {
250
			$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
251
				' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
252
				' – ' . $this->getSlogan();
253
		}
254
255
		return $footer;
256
	}
257
258
	/**
259
	 * Returns long version of the footer
260
	 * @return string long footer
261
	 */
262
	public function getLongFooter() {
263
		if ($this->themeExist('getLongFooter')) {
264
			$footer = $this->theme->getLongFooter();
265
		} else {
266
			$footer = $this->getShortFooter();
267
		}
268
269
		return $footer;
270
	}
271
272
	/**
273
	 * @param string $key
274
	 * @return string URL to doc with key
275
	 */
276
	public function buildDocLinkToKey($key) {
277
		if ($this->themeExist('buildDocLinkToKey')) {
278
			return $this->theme->buildDocLinkToKey($key);
279
		}
280
		return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
281
	}
282
283
	/**
284
	 * Returns primary color
285
	 * @return string
286
	 */
287
	public function getColorPrimary() {
288
		if ($this->themeExist('getColorPrimary')) {
289
			return $this->theme->getColorPrimary();
290
		}
291
		if ($this->themeExist('getMailHeaderColor')) {
292
			return $this->theme->getMailHeaderColor();
293
		}
294
		return $this->defaultColorPrimary;
295
	}
296
297
	/**
298
	 * @return array scss variables to overwrite
299
	 */
300
	public function getScssVariables() {
301
		if ($this->themeExist('getScssVariables')) {
302
			return $this->theme->getScssVariables();
303
		}
304
		return [];
305
	}
306
307
	public function shouldReplaceIcons() {
308
		return false;
309
	}
310
311
	/**
312
	 * Themed logo url
313
	 *
314
	 * @param bool $useSvg Whether to point to the SVG image or a fallback
315
	 * @return string
316
	 */
317
	public function getLogo($useSvg = true) {
318
		if ($this->themeExist('getLogo')) {
319
			return $this->theme->getLogo($useSvg);
320
		}
321
322
		if ($useSvg) {
323
			$logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
324
		} else {
325
			$logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
326
		}
327
		return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
328
	}
329
330
	public function getTextColorPrimary() {
331
		if ($this->themeExist('getTextColorPrimary')) {
332
			return $this->theme->getTextColorPrimary();
333
		}
334
		return $this->defaultTextColorPrimary;
335
	}
336
337
	public function getProductName() {
338
		if ($this->themeExist('getProductName')) {
339
			return $this->theme->getProductName();
340
		}
341
		return $this->defaultProductName;
342
	}
343
}
344