1<?php 2/** 3 * @copyright Copyright (c) 2016, ownCloud, Inc. 4 * 5 * @author Björn Schießle <bjoern@schiessle.org> 6 * @author Christoph Wurst <christoph@winzerhof-wurst.at> 7 * @author Daniel Kesselberg <mail@danielkesselberg.de> 8 * @author Jan-Christoph Borchardt <hey@jancborchardt.net> 9 * @author Jörn Friedrich Dreyer <jfd@butonic.de> 10 * @author Julius Haertl <jus@bitgrid.net> 11 * @author Julius Härtl <jus@bitgrid.net> 12 * @author Lukas Reschke <lukas@statuscode.ch> 13 * @author Markus Staab <markus.staab@redaxo.de> 14 * @author Michael Weimann <mail@michael-weimann.eu> 15 * @author Morris Jobke <hey@morrisjobke.de> 16 * @author Pascal de Bruijn <pmjdebruijn@pcode.nl> 17 * @author Robin Appelman <robin@icewind.nl> 18 * @author Robin McCorkell <robin@mccorkell.me.uk> 19 * @author Roeland Jago Douma <roeland@famdouma.nl> 20 * @author scolebrook <scolebrook@mac.com> 21 * @author Thomas Müller <thomas.mueller@tmit.eu> 22 * @author Volkan Gezer <volkangezer@gmail.com> 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 40class 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 $defaultFDroidClientUrl; 52 private $defaultDocBaseUrl; 53 private $defaultDocVersion; 54 private $defaultSlogan; 55 private $defaultColorPrimary; 56 private $defaultTextColorPrimary; 57 private $defaultProductName; 58 59 public function __construct() { 60 $config = \OC::$server->getConfig(); 61 62 $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ 63 $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ 64 $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ 65 $this->defaultBaseUrl = 'https://nextcloud.com'; 66 $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); 67 $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); 68 $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); 69 $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); 70 $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/'); 71 $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; 72 $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links 73 $this->defaultColorPrimary = '#0082c9'; 74 $this->defaultTextColorPrimary = '#ffffff'; 75 $this->defaultProductName = 'Nextcloud'; 76 77 $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; 78 if (file_exists($themePath)) { 79 // prevent defaults.php from printing output 80 ob_start(); 81 require_once $themePath; 82 ob_end_clean(); 83 if (class_exists('OC_Theme')) { 84 $this->theme = new OC_Theme(); 85 } 86 } 87 } 88 89 /** 90 * @param string $method 91 */ 92 private function themeExist($method) { 93 if (isset($this->theme) && method_exists($this->theme, $method)) { 94 return true; 95 } 96 return false; 97 } 98 99 /** 100 * Returns the base URL 101 * @return string URL 102 */ 103 public function getBaseUrl() { 104 if ($this->themeExist('getBaseUrl')) { 105 return $this->theme->getBaseUrl(); 106 } else { 107 return $this->defaultBaseUrl; 108 } 109 } 110 111 /** 112 * Returns the URL where the sync clients are listed 113 * @return string URL 114 */ 115 public function getSyncClientUrl() { 116 if ($this->themeExist('getSyncClientUrl')) { 117 return $this->theme->getSyncClientUrl(); 118 } else { 119 return $this->defaultSyncClientUrl; 120 } 121 } 122 123 /** 124 * Returns the URL to the App Store for the iOS Client 125 * @return string URL 126 */ 127 public function getiOSClientUrl() { 128 if ($this->themeExist('getiOSClientUrl')) { 129 return $this->theme->getiOSClientUrl(); 130 } else { 131 return $this->defaultiOSClientUrl; 132 } 133 } 134 135 /** 136 * Returns the AppId for the App Store for the iOS Client 137 * @return string AppId 138 */ 139 public function getiTunesAppId() { 140 if ($this->themeExist('getiTunesAppId')) { 141 return $this->theme->getiTunesAppId(); 142 } else { 143 return $this->defaultiTunesAppId; 144 } 145 } 146 147 /** 148 * Returns the URL to Google Play for the Android Client 149 * @return string URL 150 */ 151 public function getAndroidClientUrl() { 152 if ($this->themeExist('getAndroidClientUrl')) { 153 return $this->theme->getAndroidClientUrl(); 154 } else { 155 return $this->defaultAndroidClientUrl; 156 } 157 } 158 159 /** 160 * Returns the URL to Google Play for the Android Client 161 * @return string URL 162 */ 163 public function getFDroidClientUrl() { 164 if ($this->themeExist('getFDroidClientUrl')) { 165 return $this->theme->getFDroidClientUrl(); 166 } else { 167 return $this->defaultFDroidClientUrl; 168 } 169 } 170 171 /** 172 * Returns the documentation URL 173 * @return string URL 174 */ 175 public function getDocBaseUrl() { 176 if ($this->themeExist('getDocBaseUrl')) { 177 return $this->theme->getDocBaseUrl(); 178 } else { 179 return $this->defaultDocBaseUrl; 180 } 181 } 182 183 /** 184 * Returns the title 185 * @return string title 186 */ 187 public function getTitle() { 188 if ($this->themeExist('getTitle')) { 189 return $this->theme->getTitle(); 190 } else { 191 return $this->defaultTitle; 192 } 193 } 194 195 /** 196 * Returns the short name of the software 197 * @return string title 198 */ 199 public function getName() { 200 if ($this->themeExist('getName')) { 201 return $this->theme->getName(); 202 } else { 203 return $this->defaultName; 204 } 205 } 206 207 /** 208 * Returns the short name of the software containing HTML strings 209 * @return string title 210 */ 211 public function getHTMLName() { 212 if ($this->themeExist('getHTMLName')) { 213 return $this->theme->getHTMLName(); 214 } else { 215 return $this->defaultName; 216 } 217 } 218 219 /** 220 * Returns entity (e.g. company name) - used for footer, copyright 221 * @return string entity name 222 */ 223 public function getEntity() { 224 if ($this->themeExist('getEntity')) { 225 return $this->theme->getEntity(); 226 } else { 227 return $this->defaultEntity; 228 } 229 } 230 231 /** 232 * Returns slogan 233 * @return string slogan 234 */ 235 public function getSlogan(?string $lang = null) { 236 if ($this->themeExist('getSlogan')) { 237 return $this->theme->getSlogan($lang); 238 } else { 239 if ($this->defaultSlogan === null) { 240 $l10n = \OC::$server->getL10N('lib', $lang); 241 $this->defaultSlogan = $l10n->t('a safe home for all your data'); 242 } 243 return $this->defaultSlogan; 244 } 245 } 246 247 /** 248 * Returns logo claim 249 * @return string logo claim 250 * @deprecated 13.0.0 251 */ 252 public function getLogoClaim() { 253 return ''; 254 } 255 256 /** 257 * Returns short version of the footer 258 * @return string short footer 259 */ 260 public function getShortFooter() { 261 if ($this->themeExist('getShortFooter')) { 262 $footer = $this->theme->getShortFooter(); 263 } else { 264 $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . 265 ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. 266 ' – ' . $this->getSlogan(); 267 } 268 269 return $footer; 270 } 271 272 /** 273 * Returns long version of the footer 274 * @return string long footer 275 */ 276 public function getLongFooter() { 277 if ($this->themeExist('getLongFooter')) { 278 $footer = $this->theme->getLongFooter(); 279 } else { 280 $footer = $this->getShortFooter(); 281 } 282 283 return $footer; 284 } 285 286 /** 287 * @param string $key 288 * @return string URL to doc with key 289 */ 290 public function buildDocLinkToKey($key) { 291 if ($this->themeExist('buildDocLinkToKey')) { 292 return $this->theme->buildDocLinkToKey($key); 293 } 294 return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; 295 } 296 297 /** 298 * Returns primary color 299 * @return string 300 */ 301 public function getColorPrimary() { 302 if ($this->themeExist('getColorPrimary')) { 303 return $this->theme->getColorPrimary(); 304 } 305 if ($this->themeExist('getMailHeaderColor')) { 306 return $this->theme->getMailHeaderColor(); 307 } 308 return $this->defaultColorPrimary; 309 } 310 311 /** 312 * @return array scss variables to overwrite 313 */ 314 public function getScssVariables() { 315 if ($this->themeExist('getScssVariables')) { 316 return $this->theme->getScssVariables(); 317 } 318 return []; 319 } 320 321 public function shouldReplaceIcons() { 322 return false; 323 } 324 325 /** 326 * Themed logo url 327 * 328 * @param bool $useSvg Whether to point to the SVG image or a fallback 329 * @return string 330 */ 331 public function getLogo($useSvg = true) { 332 if ($this->themeExist('getLogo')) { 333 return $this->theme->getLogo($useSvg); 334 } 335 336 if ($useSvg) { 337 $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); 338 } else { 339 $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); 340 } 341 return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); 342 } 343 344 public function getTextColorPrimary() { 345 if ($this->themeExist('getTextColorPrimary')) { 346 return $this->theme->getTextColorPrimary(); 347 } 348 return $this->defaultTextColorPrimary; 349 } 350 351 public function getProductName() { 352 if ($this->themeExist('getProductName')) { 353 return $this->theme->getProductName(); 354 } 355 return $this->defaultProductName; 356 } 357} 358