defaults.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Pascal de Bruijn <pmjdebruijn@pcode.nl>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Robin McCorkell <robin@mccorkell.me.uk>
  13. * @author scolebrook <scolebrook@mac.com>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. * @author Volkan Gezer <volkangezer@gmail.com>
  16. *
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. class OC_Defaults {
  33. private $theme;
  34. private $l;
  35. private $defaultEntity;
  36. private $defaultName;
  37. private $defaultTitle;
  38. private $defaultBaseUrl;
  39. private $defaultSyncClientUrl;
  40. private $defaultiOSClientUrl;
  41. private $defaultiTunesAppId;
  42. private $defaultAndroidClientUrl;
  43. private $defaultDocBaseUrl;
  44. private $defaultDocVersion;
  45. private $defaultSlogan;
  46. private $defaultLogoClaim;
  47. private $defaultColorPrimary;
  48. private $defaultTextColorPrimary;
  49. public function __construct() {
  50. $this->l = \OC::$server->getL10N('lib');
  51. $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
  52. $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
  53. $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
  54. $this->defaultBaseUrl = 'https://nextcloud.com';
  55. $this->defaultSyncClientUrl = 'https://nextcloud.com/install/#install-clients';
  56. $this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8';
  57. $this->defaultiTunesAppId = '1125420102';
  58. $this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.nextcloud.client';
  59. $this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
  60. $this->defaultDocVersion = '12'; // used to generate doc links
  61. $this->defaultSlogan = $this->l->t('a safe home for all your data');
  62. $this->defaultLogoClaim = '';
  63. $this->defaultColorPrimary = '#0082c9';
  64. $this->defaultTextColorPrimary = '#ffffff';
  65. $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
  66. if (file_exists($themePath)) {
  67. // prevent defaults.php from printing output
  68. ob_start();
  69. require_once $themePath;
  70. ob_end_clean();
  71. if (class_exists('OC_Theme')) {
  72. $this->theme = new OC_Theme();
  73. }
  74. }
  75. }
  76. /**
  77. * @param string $method
  78. */
  79. private function themeExist($method) {
  80. if (isset($this->theme) && method_exists($this->theme, $method)) {
  81. return true;
  82. }
  83. return false;
  84. }
  85. /**
  86. * Returns the base URL
  87. * @return string URL
  88. */
  89. public function getBaseUrl() {
  90. if ($this->themeExist('getBaseUrl')) {
  91. return $this->theme->getBaseUrl();
  92. } else {
  93. return $this->defaultBaseUrl;
  94. }
  95. }
  96. /**
  97. * Returns the URL where the sync clients are listed
  98. * @return string URL
  99. */
  100. public function getSyncClientUrl() {
  101. if ($this->themeExist('getSyncClientUrl')) {
  102. return $this->theme->getSyncClientUrl();
  103. } else {
  104. return $this->defaultSyncClientUrl;
  105. }
  106. }
  107. /**
  108. * Returns the URL to the App Store for the iOS Client
  109. * @return string URL
  110. */
  111. public function getiOSClientUrl() {
  112. if ($this->themeExist('getiOSClientUrl')) {
  113. return $this->theme->getiOSClientUrl();
  114. } else {
  115. return $this->defaultiOSClientUrl;
  116. }
  117. }
  118. /**
  119. * Returns the AppId for the App Store for the iOS Client
  120. * @return string AppId
  121. */
  122. public function getiTunesAppId() {
  123. if ($this->themeExist('getiTunesAppId')) {
  124. return $this->theme->getiTunesAppId();
  125. } else {
  126. return $this->defaultiTunesAppId;
  127. }
  128. }
  129. /**
  130. * Returns the URL to Google Play for the Android Client
  131. * @return string URL
  132. */
  133. public function getAndroidClientUrl() {
  134. if ($this->themeExist('getAndroidClientUrl')) {
  135. return $this->theme->getAndroidClientUrl();
  136. } else {
  137. return $this->defaultAndroidClientUrl;
  138. }
  139. }
  140. /**
  141. * Returns the documentation URL
  142. * @return string URL
  143. */
  144. public function getDocBaseUrl() {
  145. if ($this->themeExist('getDocBaseUrl')) {
  146. return $this->theme->getDocBaseUrl();
  147. } else {
  148. return $this->defaultDocBaseUrl;
  149. }
  150. }
  151. /**
  152. * Returns the title
  153. * @return string title
  154. */
  155. public function getTitle() {
  156. if ($this->themeExist('getTitle')) {
  157. return $this->theme->getTitle();
  158. } else {
  159. return $this->defaultTitle;
  160. }
  161. }
  162. /**
  163. * Returns the short name of the software
  164. * @return string title
  165. */
  166. public function getName() {
  167. if ($this->themeExist('getName')) {
  168. return $this->theme->getName();
  169. } else {
  170. return $this->defaultName;
  171. }
  172. }
  173. /**
  174. * Returns the short name of the software containing HTML strings
  175. * @return string title
  176. */
  177. public function getHTMLName() {
  178. if ($this->themeExist('getHTMLName')) {
  179. return $this->theme->getHTMLName();
  180. } else {
  181. return $this->defaultName;
  182. }
  183. }
  184. /**
  185. * Returns entity (e.g. company name) - used for footer, copyright
  186. * @return string entity name
  187. */
  188. public function getEntity() {
  189. if ($this->themeExist('getEntity')) {
  190. return $this->theme->getEntity();
  191. } else {
  192. return $this->defaultEntity;
  193. }
  194. }
  195. /**
  196. * Returns slogan
  197. * @return string slogan
  198. */
  199. public function getSlogan() {
  200. if ($this->themeExist('getSlogan')) {
  201. return $this->theme->getSlogan();
  202. } else {
  203. return $this->defaultSlogan;
  204. }
  205. }
  206. /**
  207. * Returns logo claim
  208. * @return string logo claim
  209. */
  210. public function getLogoClaim() {
  211. if ($this->themeExist('getLogoClaim')) {
  212. return $this->theme->getLogoClaim();
  213. } else {
  214. return $this->defaultLogoClaim;
  215. }
  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">' .$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.svg');
  290. } else {
  291. $logo = \OC::$server->getURLGenerator()->imagePath('core', '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. }