Admin.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\Controller\ThemingController;
  31. use OCA\Theming\ImageManager;
  32. use OCA\Theming\ThemingDefaults;
  33. use OCP\AppFramework\Http\TemplateResponse;
  34. use OCP\AppFramework\Services\IInitialState;
  35. use OCP\IConfig;
  36. use OCP\IL10N;
  37. use OCP\IURLGenerator;
  38. use OCP\Settings\IDelegatedSettings;
  39. use OCP\Util;
  40. class Admin implements IDelegatedSettings {
  41. private string $appName;
  42. private IConfig $config;
  43. private IL10N $l;
  44. private ThemingDefaults $themingDefaults;
  45. private IInitialState $initialState;
  46. private IURLGenerator $urlGenerator;
  47. private ImageManager $imageManager;
  48. public function __construct(string $appName,
  49. IConfig $config,
  50. IL10N $l,
  51. ThemingDefaults $themingDefaults,
  52. IInitialState $initialState,
  53. IURLGenerator $urlGenerator,
  54. ImageManager $imageManager) {
  55. $this->appName = $appName;
  56. $this->config = $config;
  57. $this->l = $l;
  58. $this->themingDefaults = $themingDefaults;
  59. $this->initialState = $initialState;
  60. $this->urlGenerator = $urlGenerator;
  61. $this->imageManager = $imageManager;
  62. }
  63. /**
  64. * @return TemplateResponse
  65. */
  66. public function getForm(): TemplateResponse {
  67. $themable = true;
  68. $errorMessage = '';
  69. $theme = $this->config->getSystemValue('theme', '');
  70. if ($theme !== '') {
  71. $themable = false;
  72. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  73. }
  74. $allowedMimeTypes = array_reduce(ThemingController::VALID_UPLOAD_KEYS, function($carry, $key) {
  75. $carry[$key] = $this->imageManager->getSupportedUploadImageFormats($key);
  76. return $carry;
  77. }, []);
  78. $this->initialState->provideInitialState('adminThemingParameters', [
  79. 'isThemable' => $themable,
  80. 'notThemableErrorMessage' => $errorMessage,
  81. 'name' => $this->themingDefaults->getEntity(),
  82. 'url' => $this->themingDefaults->getBaseUrl(),
  83. 'slogan' => $this->themingDefaults->getSlogan(),
  84. 'color' => $this->themingDefaults->getDefaultColorPrimary(),
  85. 'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
  86. 'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
  87. 'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
  88. 'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
  89. 'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
  90. 'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
  91. 'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
  92. 'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  93. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  94. 'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
  95. 'allowedMimeTypes' => $allowedMimeTypes,
  96. ]);
  97. Util::addScript($this->appName, 'admin-theming');
  98. return new TemplateResponse($this->appName, 'settings-admin');
  99. }
  100. /**
  101. * @return string the section ID, e.g. 'sharing'
  102. */
  103. public function getSection(): string {
  104. return $this->appName;
  105. }
  106. /**
  107. * @return int whether the form should be rather on the top or bottom of
  108. * the admin section. The forms are arranged in ascending order of the
  109. * priority values. It is required to return a value between 0 and 100.
  110. *
  111. * E.g.: 70
  112. */
  113. public function getPriority(): int {
  114. return 5;
  115. }
  116. public function getName(): ?string {
  117. return null; // Only one setting in this section
  118. }
  119. public function getAuthorizedAppConfig(): array {
  120. return [
  121. $this->appName => '/.*/',
  122. ];
  123. }
  124. }