1
0

OC_Defaults.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. use OCP\IConfig;
  8. use OCP\Server;
  9. use OCP\ServerVersion;
  10. class OC_Defaults {
  11. private $theme;
  12. private $defaultEntity;
  13. private $defaultName;
  14. private $defaultTitle;
  15. private $defaultBaseUrl;
  16. private $defaultSyncClientUrl;
  17. private $defaultiOSClientUrl;
  18. private $defaultiTunesAppId;
  19. private $defaultAndroidClientUrl;
  20. private $defaultFDroidClientUrl;
  21. private $defaultDocBaseUrl;
  22. private $defaultDocVersion;
  23. private $defaultSlogan;
  24. private $defaultColorBackground;
  25. private $defaultColorPrimary;
  26. private $defaultTextColorPrimary;
  27. private $defaultProductName;
  28. public function __construct() {
  29. $config = Server::get(IConfig::class);
  30. $serverVersion = Server::get(ServerVersion::class);
  31. $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
  32. $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
  33. $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
  34. $this->defaultBaseUrl = 'https://nextcloud.com';
  35. $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients');
  36. $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
  37. $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102');
  38. $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client');
  39. $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/');
  40. $this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
  41. $this->defaultDocVersion = $serverVersion->getMajorVersion(); // used to generate doc links
  42. $this->defaultColorBackground = '#00679e';
  43. $this->defaultColorPrimary = '#00679e';
  44. $this->defaultTextColorPrimary = '#ffffff';
  45. $this->defaultProductName = 'Nextcloud';
  46. $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
  47. if (file_exists($themePath)) {
  48. // prevent defaults.php from printing output
  49. ob_start();
  50. require_once $themePath;
  51. ob_end_clean();
  52. if (class_exists('OC_Theme')) {
  53. $this->theme = new OC_Theme();
  54. }
  55. }
  56. }
  57. /**
  58. * @param string $method
  59. */
  60. private function themeExist($method) {
  61. if (isset($this->theme) && method_exists($this->theme, $method)) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. /**
  67. * Returns the base URL
  68. * @return string URL
  69. */
  70. public function getBaseUrl() {
  71. if ($this->themeExist('getBaseUrl')) {
  72. return $this->theme->getBaseUrl();
  73. } else {
  74. return $this->defaultBaseUrl;
  75. }
  76. }
  77. /**
  78. * Returns the URL where the sync clients are listed
  79. * @return string URL
  80. */
  81. public function getSyncClientUrl() {
  82. if ($this->themeExist('getSyncClientUrl')) {
  83. return $this->theme->getSyncClientUrl();
  84. } else {
  85. return $this->defaultSyncClientUrl;
  86. }
  87. }
  88. /**
  89. * Returns the URL to the App Store for the iOS Client
  90. * @return string URL
  91. */
  92. public function getiOSClientUrl() {
  93. if ($this->themeExist('getiOSClientUrl')) {
  94. return $this->theme->getiOSClientUrl();
  95. } else {
  96. return $this->defaultiOSClientUrl;
  97. }
  98. }
  99. /**
  100. * Returns the AppId for the App Store for the iOS Client
  101. * @return string AppId
  102. */
  103. public function getiTunesAppId() {
  104. if ($this->themeExist('getiTunesAppId')) {
  105. return $this->theme->getiTunesAppId();
  106. } else {
  107. return $this->defaultiTunesAppId;
  108. }
  109. }
  110. /**
  111. * Returns the URL to Google Play for the Android Client
  112. * @return string URL
  113. */
  114. public function getAndroidClientUrl() {
  115. if ($this->themeExist('getAndroidClientUrl')) {
  116. return $this->theme->getAndroidClientUrl();
  117. } else {
  118. return $this->defaultAndroidClientUrl;
  119. }
  120. }
  121. /**
  122. * Returns the URL to Google Play for the Android Client
  123. * @return string URL
  124. */
  125. public function getFDroidClientUrl() {
  126. if ($this->themeExist('getFDroidClientUrl')) {
  127. return $this->theme->getFDroidClientUrl();
  128. } else {
  129. return $this->defaultFDroidClientUrl;
  130. }
  131. }
  132. /**
  133. * Returns the documentation URL
  134. * @return string URL
  135. */
  136. public function getDocBaseUrl() {
  137. if ($this->themeExist('getDocBaseUrl')) {
  138. return $this->theme->getDocBaseUrl();
  139. } else {
  140. return $this->defaultDocBaseUrl;
  141. }
  142. }
  143. /**
  144. * Returns the title
  145. * @return string title
  146. */
  147. public function getTitle() {
  148. if ($this->themeExist('getTitle')) {
  149. return $this->theme->getTitle();
  150. } else {
  151. return $this->defaultTitle;
  152. }
  153. }
  154. /**
  155. * Returns the short name of the software
  156. * @return string title
  157. */
  158. public function getName() {
  159. if ($this->themeExist('getName')) {
  160. return $this->theme->getName();
  161. } else {
  162. return $this->defaultName;
  163. }
  164. }
  165. /**
  166. * Returns the short name of the software containing HTML strings
  167. * @return string title
  168. */
  169. public function getHTMLName() {
  170. if ($this->themeExist('getHTMLName')) {
  171. return $this->theme->getHTMLName();
  172. } else {
  173. return $this->defaultName;
  174. }
  175. }
  176. /**
  177. * Returns entity (e.g. company name) - used for footer, copyright
  178. * @return string entity name
  179. */
  180. public function getEntity() {
  181. if ($this->themeExist('getEntity')) {
  182. return $this->theme->getEntity();
  183. } else {
  184. return $this->defaultEntity;
  185. }
  186. }
  187. /**
  188. * Returns slogan
  189. * @return string slogan
  190. */
  191. public function getSlogan(?string $lang = null) {
  192. if ($this->themeExist('getSlogan')) {
  193. return $this->theme->getSlogan($lang);
  194. } else {
  195. if ($this->defaultSlogan === null) {
  196. $l10n = \OC::$server->getL10N('lib', $lang);
  197. $this->defaultSlogan = $l10n->t('a safe home for all your data');
  198. }
  199. return $this->defaultSlogan;
  200. }
  201. }
  202. /**
  203. * Returns short version of the footer
  204. * @return string short footer
  205. */
  206. public function getShortFooter() {
  207. if ($this->themeExist('getShortFooter')) {
  208. $footer = $this->theme->getShortFooter();
  209. } else {
  210. $footer = '<a href="' . $this->getBaseUrl() . '" target="_blank"' .
  211. ' rel="noreferrer noopener">' . $this->getEntity() . '</a>' .
  212. ' – ' . $this->getSlogan();
  213. }
  214. return $footer;
  215. }
  216. /**
  217. * Returns long version of the footer
  218. * @return string long footer
  219. */
  220. public function getLongFooter() {
  221. if ($this->themeExist('getLongFooter')) {
  222. $footer = $this->theme->getLongFooter();
  223. } else {
  224. $footer = $this->getShortFooter();
  225. }
  226. return $footer;
  227. }
  228. /**
  229. * @param string $key
  230. * @return string URL to doc with key
  231. */
  232. public function buildDocLinkToKey($key) {
  233. if ($this->themeExist('buildDocLinkToKey')) {
  234. return $this->theme->buildDocLinkToKey($key);
  235. }
  236. return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
  237. }
  238. /**
  239. * Returns primary color
  240. * @return string
  241. */
  242. public function getColorPrimary() {
  243. if ($this->themeExist('getColorPrimary')) {
  244. return $this->theme->getColorPrimary();
  245. }
  246. if ($this->themeExist('getMailHeaderColor')) {
  247. return $this->theme->getMailHeaderColor();
  248. }
  249. return $this->defaultColorPrimary;
  250. }
  251. /**
  252. * Returns primary color
  253. * @return string
  254. */
  255. public function getColorBackground() {
  256. if ($this->themeExist('getColorBackground')) {
  257. return $this->theme->getColorBackground();
  258. }
  259. return $this->defaultColorBackground;
  260. }
  261. /**
  262. * @return array scss variables to overwrite
  263. */
  264. public function getScssVariables() {
  265. if ($this->themeExist('getScssVariables')) {
  266. return $this->theme->getScssVariables();
  267. }
  268. return [];
  269. }
  270. public function shouldReplaceIcons() {
  271. return false;
  272. }
  273. /**
  274. * Themed logo url
  275. *
  276. * @param bool $useSvg Whether to point to the SVG image or a fallback
  277. * @return string
  278. */
  279. public function getLogo($useSvg = true) {
  280. if ($this->themeExist('getLogo')) {
  281. return $this->theme->getLogo($useSvg);
  282. }
  283. if ($useSvg) {
  284. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
  285. } else {
  286. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
  287. }
  288. return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
  289. }
  290. public function getTextColorPrimary() {
  291. if ($this->themeExist('getTextColorPrimary')) {
  292. return $this->theme->getTextColorPrimary();
  293. }
  294. return $this->defaultTextColorPrimary;
  295. }
  296. public function getProductName() {
  297. if ($this->themeExist('getProductName')) {
  298. return $this->theme->getProductName();
  299. }
  300. return $this->defaultProductName;
  301. }
  302. }