Admin.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\Theming\Settings;
  29. use OCA\Theming\AppInfo\Application;
  30. use OCA\Theming\ImageManager;
  31. use OCA\Theming\ThemingDefaults;
  32. use OCP\AppFramework\Http\TemplateResponse;
  33. use OCP\AppFramework\Services\IInitialState;
  34. use OCP\IConfig;
  35. use OCP\IL10N;
  36. use OCP\IURLGenerator;
  37. use OCP\Settings\IDelegatedSettings;
  38. use OCP\Util;
  39. class Admin implements IDelegatedSettings {
  40. private string $appName;
  41. private IConfig $config;
  42. private IL10N $l;
  43. private ThemingDefaults $themingDefaults;
  44. private IInitialState $initialState;
  45. private IURLGenerator $urlGenerator;
  46. private ImageManager $imageManager;
  47. public function __construct(string $appName,
  48. IConfig $config,
  49. IL10N $l,
  50. ThemingDefaults $themingDefaults,
  51. IInitialState $initialState,
  52. IURLGenerator $urlGenerator,
  53. ImageManager $imageManager) {
  54. $this->appName = $appName;
  55. $this->config = $config;
  56. $this->l = $l;
  57. $this->themingDefaults = $themingDefaults;
  58. $this->initialState = $initialState;
  59. $this->urlGenerator = $urlGenerator;
  60. $this->imageManager = $imageManager;
  61. }
  62. /**
  63. * @return TemplateResponse
  64. */
  65. public function getForm(): TemplateResponse {
  66. $themable = true;
  67. $errorMessage = '';
  68. $theme = $this->config->getSystemValue('theme', '');
  69. if ($theme !== '') {
  70. $themable = false;
  71. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  72. }
  73. $this->initialState->provideInitialState('adminThemingParameters', [
  74. 'isThemable' => $themable,
  75. 'notThemableErrorMessage' => $errorMessage,
  76. 'name' => $this->themingDefaults->getEntity(),
  77. 'url' => $this->themingDefaults->getBaseUrl(),
  78. 'slogan' => $this->themingDefaults->getSlogan(),
  79. 'color' => $this->themingDefaults->getDefaultColorPrimary(),
  80. 'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
  81. 'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
  82. 'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
  83. 'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
  84. 'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
  85. 'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
  86. 'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
  87. 'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  88. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  89. 'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
  90. ]);
  91. Util::addScript($this->appName, 'admin-theming');
  92. return new TemplateResponse($this->appName, 'settings-admin');
  93. }
  94. /**
  95. * @return string the section ID, e.g. 'sharing'
  96. */
  97. public function getSection(): string {
  98. return $this->appName;
  99. }
  100. /**
  101. * @return int whether the form should be rather on the top or bottom of
  102. * the admin section. The forms are arranged in ascending order of the
  103. * priority values. It is required to return a value between 0 and 100.
  104. *
  105. * E.g.: 70
  106. */
  107. public function getPriority(): int {
  108. return 5;
  109. }
  110. public function getName(): ?string {
  111. return null; // Only one setting in this section
  112. }
  113. public function getAuthorizedAppConfig(): array {
  114. return [
  115. $this->appName => '/.*/',
  116. ];
  117. }
  118. }