Completed
Push — master ( 3d9077...efdef8 )
by Robin
13:01 queued 04:55
created

OC_Defaults::themeExist()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Jan-Christoph Borchardt <[email protected]>
7
 * @author Jörn Friedrich Dreyer <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Pascal de Bruijn <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Robin McCorkell <[email protected]>
13
 * @author scolebrook <[email protected]>
14
 * @author Thomas Müller <[email protected]>
15
 * @author Volkan Gezer <[email protected]>
16
 *
17
 * @license AGPL-3.0
18
 *
19
 * This code is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License, version 3,
21
 * as published by the Free Software Foundation.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
 * GNU Affero General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU Affero General Public License, version 3,
29
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
30
 *
31
 */
32
class OC_Defaults {
33
34
	private $theme;
35
	private $l;
36
37
	private $defaultEntity;
38
	private $defaultName;
39
	private $defaultTitle;
40
	private $defaultBaseUrl;
41
	private $defaultSyncClientUrl;
42
	private $defaultiOSClientUrl;
43
	private $defaultiTunesAppId;
44
	private $defaultAndroidClientUrl;
45
	private $defaultDocBaseUrl;
46
	private $defaultDocVersion;
47
	private $defaultSlogan;
48
	private $defaultLogoClaim;
49
	private $defaultMailHeaderColor;
50
51
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
52
		$this->l = \OC::$server->getL10N('lib');
53
54
		$this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
55
		$this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
56
		$this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
57
		$this->defaultBaseUrl = 'https://nextcloud.com';
58
		$this->defaultSyncClientUrl = 'https://nextcloud.com/install';
59
		$this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8';
60
		$this->defaultiTunesAppId = '1125420102';
61
		$this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.nextcloud.client';
62
		$this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
63
		$this->defaultDocVersion = '10'; // used to generate doc links
64
		$this->defaultSlogan = $this->l->t('a safe home for all your data');
65
		$this->defaultLogoClaim = '';
66
		$this->defaultMailHeaderColor = '#0082c9'; /* header color of mail notifications */
67
68
		$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
69
		if (file_exists($themePath)) {
70
			// prevent defaults.php from printing output
71
			ob_start();
72
			require_once $themePath;
73
			ob_end_clean();
74
			if (class_exists('OC_Theme')) {
75
				$this->theme = new OC_Theme();
76
			}
77
		}
78
	}
79
80
	/**
81
	 * @param string $method
82
	 */
83
	private function themeExist($method) {
84
		if (isset($this->theme) && method_exists($this->theme, $method)) {
85
			return true;
86
		}
87
		return false;
88
	}
89
90
	/**
91
	 * Returns the base URL
92
	 * @return string URL
93
	 */
94
	public function getBaseUrl() {
95
		if ($this->themeExist('getBaseUrl')) {
96
			return $this->theme->getBaseUrl();
97
		} else {
98
			return $this->defaultBaseUrl;
99
		}
100
	}
101
102
	/**
103
	 * Returns the URL where the sync clients are listed
104
	 * @return string URL
105
	 */
106
	public function getSyncClientUrl() {
107
		if ($this->themeExist('getSyncClientUrl')) {
108
			return $this->theme->getSyncClientUrl();
109
		} else {
110
			return $this->defaultSyncClientUrl;
111
		}
112
	}
113
114
	/**
115
	 * Returns the URL to the App Store for the iOS Client
116
	 * @return string URL
117
	 */
118
	public function getiOSClientUrl() {
119
		if ($this->themeExist('getiOSClientUrl')) {
120
			return $this->theme->getiOSClientUrl();
121
		} else {
122
			return $this->defaultiOSClientUrl;
123
		}
124
	}
125
126
	/**
127
	 * Returns the AppId for the App Store for the iOS Client
128
	 * @return string AppId
129
	 */
130
	public function getiTunesAppId() {
131
		if ($this->themeExist('getiTunesAppId')) {
132
			return $this->theme->getiTunesAppId();
133
		} else {
134
			return $this->defaultiTunesAppId;
135
		}
136
	}
137
138
	/**
139
	 * Returns the URL to Google Play for the Android Client
140
	 * @return string URL
141
	 */
142
	public function getAndroidClientUrl() {
143
		if ($this->themeExist('getAndroidClientUrl')) {
144
			return $this->theme->getAndroidClientUrl();
145
		} else {
146
			return $this->defaultAndroidClientUrl;
147
		}
148
	}
149
150
	/**
151
	 * Returns the documentation URL
152
	 * @return string URL
153
	 */
154
	public function getDocBaseUrl() {
155
		if ($this->themeExist('getDocBaseUrl')) {
156
			return $this->theme->getDocBaseUrl();
157
		} else {
158
			return $this->defaultDocBaseUrl;
159
		}
160
	}
161
162
	/**
163
	 * Returns the title
164
	 * @return string title
165
	 */
166
	public function getTitle() {
167
		if ($this->themeExist('getTitle')) {
168
			return $this->theme->getTitle();
169
		} else {
170
			return $this->defaultTitle;
171
		}
172
	}
173
174
	/**
175
	 * Returns the short name of the software
176
	 * @return string title
177
	 */
178
	public function getName() {
179
		if ($this->themeExist('getName')) {
180
			return $this->theme->getName();
181
		} else {
182
			return $this->defaultName;
183
		}
184
	}
185
186
	/**
187
	 * Returns the short name of the software containing HTML strings
188
	 * @return string title
189
	 */
190
	public function getHTMLName() {
191
		if ($this->themeExist('getHTMLName')) {
192
			return $this->theme->getHTMLName();
193
		} else {
194
			return $this->defaultName;
195
		}
196
	}
197
198
	/**
199
	 * Returns entity (e.g. company name) - used for footer, copyright
200
	 * @return string entity name
201
	 */
202
	public function getEntity() {
203
		if ($this->themeExist('getEntity')) {
204
			return $this->theme->getEntity();
205
		} else {
206
			return $this->defaultEntity;
207
		}
208
	}
209
210
	/**
211
	 * Returns slogan
212
	 * @return string slogan
213
	 */
214
	public function getSlogan() {
215
		if ($this->themeExist('getSlogan')) {
216
			return $this->theme->getSlogan();
217
		} else {
218
			return $this->defaultSlogan;
219
		}
220
	}
221
222
	/**
223
	 * Returns logo claim
224
	 * @return string logo claim
225
	 */
226
	public function getLogoClaim() {
227
		if ($this->themeExist('getLogoClaim')) {
228
			return $this->theme->getLogoClaim();
229
		} else {
230
			return $this->defaultLogoClaim;
231
		}
232
	}
233
234
	/**
235
	 * Returns short version of the footer
236
	 * @return string short footer
237
	 */
238
	public function getShortFooter() {
239
		if ($this->themeExist('getShortFooter')) {
240
			$footer = $this->theme->getShortFooter();
241
		} else {
242
			$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
243
				' rel="noreferrer">' .$this->getEntity() . '</a>'.
244
				' – ' . $this->getSlogan();
245
		}
246
247
		return $footer;
248
	}
249
250
	/**
251
	 * Returns long version of the footer
252
	 * @return string long footer
253
	 */
254
	public function getLongFooter() {
255
		if ($this->themeExist('getLongFooter')) {
256
			$footer = $this->theme->getLongFooter();
257
		} else {
258
			$footer = $this->getShortFooter();
259
		}
260
261
		return $footer;
262
	}
263
264
	/**
265
	 * @param string $key
266
	 */
267
	public function buildDocLinkToKey($key) {
268
		if ($this->themeExist('buildDocLinkToKey')) {
269
			return $this->theme->buildDocLinkToKey($key);
270
		}
271
		return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
272
	}
273
274
	/**
275
	 * Returns mail header color
276
	 * @return string
277
	 */
278
	public function getMailHeaderColor() {
279
		if ($this->themeExist('getMailHeaderColor')) {
280
			return $this->theme->getMailHeaderColor();
281
		} else {
282
			return $this->defaultMailHeaderColor;
283
		}
284
	}
285
286
	public function shouldReplaceIcons() {
287
		return false;
288
	}
289
}
290