OC_Defaults.php 8.3 KB

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