OC_Defaults.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. class OC_Defaults {
  40. private $theme;
  41. private $defaultEntity;
  42. private $defaultName;
  43. private $defaultTitle;
  44. private $defaultBaseUrl;
  45. private $defaultSyncClientUrl;
  46. private $defaultiOSClientUrl;
  47. private $defaultiTunesAppId;
  48. private $defaultAndroidClientUrl;
  49. private $defaultFDroidClientUrl;
  50. private $defaultDocBaseUrl;
  51. private $defaultDocVersion;
  52. private $defaultSlogan;
  53. private $defaultColorPrimary;
  54. private $defaultTextColorPrimary;
  55. private $defaultProductName;
  56. public function __construct() {
  57. $config = \OC::$server->getConfig();
  58. $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
  59. $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
  60. $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
  61. $this->defaultBaseUrl = 'https://nextcloud.com';
  62. $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients');
  63. $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
  64. $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102');
  65. $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client');
  66. $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/');
  67. $this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
  68. $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links
  69. $this->defaultColorPrimary = '#0082c9';
  70. $this->defaultTextColorPrimary = '#ffffff';
  71. $this->defaultProductName = 'Nextcloud';
  72. $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
  73. if (file_exists($themePath)) {
  74. // prevent defaults.php from printing output
  75. ob_start();
  76. require_once $themePath;
  77. ob_end_clean();
  78. if (class_exists('OC_Theme')) {
  79. $this->theme = new OC_Theme();
  80. }
  81. }
  82. }
  83. /**
  84. * @param string $method
  85. */
  86. private function themeExist($method) {
  87. if (isset($this->theme) && method_exists($this->theme, $method)) {
  88. return true;
  89. }
  90. return false;
  91. }
  92. /**
  93. * Returns the base URL
  94. * @return string URL
  95. */
  96. public function getBaseUrl() {
  97. if ($this->themeExist('getBaseUrl')) {
  98. return $this->theme->getBaseUrl();
  99. } else {
  100. return $this->defaultBaseUrl;
  101. }
  102. }
  103. /**
  104. * Returns the URL where the sync clients are listed
  105. * @return string URL
  106. */
  107. public function getSyncClientUrl() {
  108. if ($this->themeExist('getSyncClientUrl')) {
  109. return $this->theme->getSyncClientUrl();
  110. } else {
  111. return $this->defaultSyncClientUrl;
  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. * Returns the AppId for the App Store for the iOS Client
  127. * @return string AppId
  128. */
  129. public function getiTunesAppId() {
  130. if ($this->themeExist('getiTunesAppId')) {
  131. return $this->theme->getiTunesAppId();
  132. } else {
  133. return $this->defaultiTunesAppId;
  134. }
  135. }
  136. /**
  137. * Returns the URL to Google Play for the Android Client
  138. * @return string URL
  139. */
  140. public function getAndroidClientUrl() {
  141. if ($this->themeExist('getAndroidClientUrl')) {
  142. return $this->theme->getAndroidClientUrl();
  143. } else {
  144. return $this->defaultAndroidClientUrl;
  145. }
  146. }
  147. /**
  148. * Returns the URL to Google Play for the Android Client
  149. * @return string URL
  150. */
  151. public function getFDroidClientUrl() {
  152. if ($this->themeExist('getFDroidClientUrl')) {
  153. return $this->theme->getFDroidClientUrl();
  154. } else {
  155. return $this->defaultFDroidClientUrl;
  156. }
  157. }
  158. /**
  159. * Returns the documentation URL
  160. * @return string URL
  161. */
  162. public function getDocBaseUrl() {
  163. if ($this->themeExist('getDocBaseUrl')) {
  164. return $this->theme->getDocBaseUrl();
  165. } else {
  166. return $this->defaultDocBaseUrl;
  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. * Returns the short name of the software
  182. * @return string title
  183. */
  184. public function getName() {
  185. if ($this->themeExist('getName')) {
  186. return $this->theme->getName();
  187. } else {
  188. return $this->defaultName;
  189. }
  190. }
  191. /**
  192. * Returns the short name of the software containing HTML strings
  193. * @return string title
  194. */
  195. public function getHTMLName() {
  196. if ($this->themeExist('getHTMLName')) {
  197. return $this->theme->getHTMLName();
  198. } else {
  199. return $this->defaultName;
  200. }
  201. }
  202. /**
  203. * Returns entity (e.g. company name) - used for footer, copyright
  204. * @return string entity name
  205. */
  206. public function getEntity() {
  207. if ($this->themeExist('getEntity')) {
  208. return $this->theme->getEntity();
  209. } else {
  210. return $this->defaultEntity;
  211. }
  212. }
  213. /**
  214. * Returns slogan
  215. * @return string slogan
  216. */
  217. public function getSlogan(?string $lang = null) {
  218. if ($this->themeExist('getSlogan')) {
  219. return $this->theme->getSlogan($lang);
  220. } else {
  221. if ($this->defaultSlogan === null) {
  222. $l10n = \OC::$server->getL10N('lib', $lang);
  223. $this->defaultSlogan = $l10n->t('a safe home for all your data');
  224. }
  225. return $this->defaultSlogan;
  226. }
  227. }
  228. /**
  229. * Returns short version of the footer
  230. * @return string short footer
  231. */
  232. public function getShortFooter() {
  233. if ($this->themeExist('getShortFooter')) {
  234. $footer = $this->theme->getShortFooter();
  235. } else {
  236. $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
  237. ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
  238. ' – ' . $this->getSlogan();
  239. }
  240. return $footer;
  241. }
  242. /**
  243. * Returns long version of the footer
  244. * @return string long footer
  245. */
  246. public function getLongFooter() {
  247. if ($this->themeExist('getLongFooter')) {
  248. $footer = $this->theme->getLongFooter();
  249. } else {
  250. $footer = $this->getShortFooter();
  251. }
  252. return $footer;
  253. }
  254. /**
  255. * @param string $key
  256. * @return string URL to doc with key
  257. */
  258. public function buildDocLinkToKey($key) {
  259. if ($this->themeExist('buildDocLinkToKey')) {
  260. return $this->theme->buildDocLinkToKey($key);
  261. }
  262. return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
  263. }
  264. /**
  265. * Returns primary color
  266. * @return string
  267. */
  268. public function getColorPrimary() {
  269. if ($this->themeExist('getColorPrimary')) {
  270. return $this->theme->getColorPrimary();
  271. }
  272. if ($this->themeExist('getMailHeaderColor')) {
  273. return $this->theme->getMailHeaderColor();
  274. }
  275. return $this->defaultColorPrimary;
  276. }
  277. /**
  278. * @return array scss variables to overwrite
  279. */
  280. public function getScssVariables() {
  281. if ($this->themeExist('getScssVariables')) {
  282. return $this->theme->getScssVariables();
  283. }
  284. return [];
  285. }
  286. public function shouldReplaceIcons() {
  287. return false;
  288. }
  289. /**
  290. * Themed logo url
  291. *
  292. * @param bool $useSvg Whether to point to the SVG image or a fallback
  293. * @return string
  294. */
  295. public function getLogo($useSvg = true) {
  296. if ($this->themeExist('getLogo')) {
  297. return $this->theme->getLogo($useSvg);
  298. }
  299. if ($useSvg) {
  300. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
  301. } else {
  302. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
  303. }
  304. return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
  305. }
  306. public function getTextColorPrimary() {
  307. if ($this->themeExist('getTextColorPrimary')) {
  308. return $this->theme->getTextColorPrimary();
  309. }
  310. return $this->defaultTextColorPrimary;
  311. }
  312. public function getProductName() {
  313. if ($this->themeExist('getProductName')) {
  314. return $this->theme->getProductName();
  315. }
  316. return $this->defaultProductName;
  317. }
  318. }