defaults.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Felix A. Epp <work@felixepp.de>
  7. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  8. * @author Julius Haertl <jus@bitgrid.net>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Pascal de Bruijn <pmjdebruijn@pcode.nl>
  14. * @author Robin Appelman <robin@icewind.nl>
  15. * @author Robin McCorkell <robin@mccorkell.me.uk>
  16. * @author Roeland Jago Douma <roeland@famdouma.nl>
  17. * @author scolebrook <scolebrook@mac.com>
  18. * @author Thomas Müller <thomas.mueller@tmit.eu>
  19. * @author Volkan Gezer <volkangezer@gmail.com>
  20. *
  21. * @license AGPL-3.0
  22. *
  23. * This code is free software: you can redistribute it and/or modify
  24. * it under the terms of the GNU Affero General Public License, version 3,
  25. * as published by the Free Software Foundation.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU Affero General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Affero General Public License, version 3,
  33. * along with this program. If not, see <http://www.gnu.org/licenses/>
  34. *
  35. */
  36. class OC_Defaults {
  37. private $theme;
  38. private $l;
  39. private $defaultEntity;
  40. private $defaultName;
  41. private $defaultTitle;
  42. private $defaultBaseUrl;
  43. private $defaultSyncClientUrl;
  44. private $defaultiOSClientUrl;
  45. private $defaultiTunesAppId;
  46. private $defaultAndroidClientUrl;
  47. private $defaultDocBaseUrl;
  48. private $defaultDocVersion;
  49. private $defaultSlogan;
  50. private $defaultColorPrimary;
  51. private $defaultTextColorPrimary;
  52. public function __construct() {
  53. $this->l = \OC::$server->getL10N('lib');
  54. $config = \OC::$server->getConfig();
  55. $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
  56. $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
  57. $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
  58. $this->defaultBaseUrl = 'https://nextcloud.com';
  59. $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients');
  60. $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
  61. $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102');
  62. $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client');
  63. $this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
  64. $this->defaultDocVersion = '14'; // used to generate doc links
  65. $this->defaultSlogan = $this->l->t('a safe home for all your data');
  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() {
  203. if ($this->themeExist('getSlogan')) {
  204. return $this->theme->getSlogan();
  205. } else {
  206. return $this->defaultSlogan;
  207. }
  208. }
  209. /**
  210. * Returns logo claim
  211. * @return string logo claim
  212. * @deprecated 13.0.0
  213. */
  214. public function getLogoClaim() {
  215. return '';
  216. }
  217. /**
  218. * Returns short version of the footer
  219. * @return string short footer
  220. */
  221. public function getShortFooter() {
  222. if ($this->themeExist('getShortFooter')) {
  223. $footer = $this->theme->getShortFooter();
  224. } else {
  225. $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
  226. ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'.
  227. ' – ' . $this->getSlogan();
  228. }
  229. return $footer;
  230. }
  231. /**
  232. * Returns long version of the footer
  233. * @return string long footer
  234. */
  235. public function getLongFooter() {
  236. if ($this->themeExist('getLongFooter')) {
  237. $footer = $this->theme->getLongFooter();
  238. } else {
  239. $footer = $this->getShortFooter();
  240. }
  241. return $footer;
  242. }
  243. /**
  244. * @param string $key
  245. * @return string URL to doc with key
  246. */
  247. public function buildDocLinkToKey($key) {
  248. if ($this->themeExist('buildDocLinkToKey')) {
  249. return $this->theme->buildDocLinkToKey($key);
  250. }
  251. return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
  252. }
  253. /**
  254. * Returns primary color
  255. * @return string
  256. */
  257. public function getColorPrimary() {
  258. if ($this->themeExist('getColorPrimary')) {
  259. return $this->theme->getColorPrimary();
  260. }
  261. if ($this->themeExist('getMailHeaderColor')) {
  262. return $this->theme->getMailHeaderColor();
  263. }
  264. return $this->defaultColorPrimary;
  265. }
  266. /**
  267. * @return array scss variables to overwrite
  268. */
  269. public function getScssVariables() {
  270. if($this->themeExist('getScssVariables')) {
  271. return $this->theme->getScssVariables();
  272. }
  273. return [];
  274. }
  275. public function shouldReplaceIcons() {
  276. return false;
  277. }
  278. /**
  279. * Themed logo url
  280. *
  281. * @param bool $useSvg Whether to point to the SVG image or a fallback
  282. * @return string
  283. */
  284. public function getLogo($useSvg = true) {
  285. if ($this->themeExist('getLogo')) {
  286. return $this->theme->getLogo($useSvg);
  287. }
  288. if($useSvg) {
  289. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg');
  290. } else {
  291. $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png');
  292. }
  293. return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
  294. }
  295. public function getTextColorPrimary() {
  296. if ($this->themeExist('getTextColorPrimary')) {
  297. return $this->theme->getTextColorPrimary();
  298. }
  299. return $this->defaultTextColorPrimary;
  300. }
  301. }