You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OC_Defaults.php 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 logo claim
  230. * @return string logo claim
  231. * @deprecated 13.0.0
  232. */
  233. public function getLogoClaim() {
  234. return '';
  235. }
  236. /**
  237. * Returns short version of the footer
  238. * @return string short footer
  239. */
  240. public function getShortFooter() {
  241. if ($this->themeExist('getShortFooter')) {
  242. $footer = $this->theme->getShortFooter();
  243. } else {
  244. $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
  245. ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
  246. ' – ' . $this->getSlogan();
  247. }
  248. return $footer;
  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. return $footer;
  261. }
  262. /**
  263. * @param string $key
  264. * @return string URL to doc with key
  265. */
  266. public function buildDocLinkToKey($key) {
  267. if ($this->themeExist('buildDocLinkToKey')) {
  268. return $this->theme->buildDocLinkToKey($key);
  269. }
  270. return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
  271. }
  272. /**
  273. * Returns primary color
  274. * @return string
  275. */
  276. public function getColorPrimary() {
  277. if ($this->themeExist('getColorPrimary')) {
  278. return $this->theme->getColorPrimary();
  279. }
  280. if ($this->themeExist('getMailHeaderColor')) {
  281. return $this->theme->getMailHeaderColor();
  282. }
  283. return $this->defaultColorPrimary;
  284. }
  285. /**
  286. * @return array scss variables to overwrite
  287. */
  288. public function getScssVariables() {
  289. if ($this->themeExist('getScssVariables')) {
  290. return $this->theme->getScssVariables();
  291. }
  292. return [];
  293. }
  294. public function shouldReplaceIcons() {
  295. return false;
  296. }
  297. /**
  298. * Themed logo url
  299. *
  300. * @param bool $useSvg Whether to point to the SVG image or a fallback
  301. * @return string
  302. */
  303. public function getLogo($useSvg = true) {
  304. if ($this->themeExist('getLogo')) {
  305. return $this->theme->getLogo($useSvg);
  306. }
  307. if ($useSvg) {
  308. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
  309. } else {
  310. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
  311. }
  312. return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
  313. }
  314. public function getTextColorPrimary() {
  315. if ($this->themeExist('getTextColorPrimary')) {
  316. return $this->theme->getTextColorPrimary();
  317. }
  318. return $this->defaultTextColorPrimary;
  319. }
  320. public function getProductName() {
  321. if ($this->themeExist('getProductName')) {
  322. return $this->theme->getProductName();
  323. }
  324. return $this->defaultProductName;
  325. }
  326. }