defaults.php 8.4 KB

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