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.

333 lines
8.8 KiB

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