Admin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\Service\BackgroundService;
  33. use OCA\Theming\ThemingDefaults;
  34. use OCP\AppFramework\Http\TemplateResponse;
  35. use OCP\AppFramework\Services\IInitialState;
  36. use OCP\IConfig;
  37. use OCP\IL10N;
  38. use OCP\IURLGenerator;
  39. use OCP\Settings\IDelegatedSettings;
  40. use OCP\Util;
  41. class Admin implements IDelegatedSettings {
  42. public function __construct(
  43. private string $appName,
  44. private IConfig $config,
  45. private IL10N $l,
  46. private ThemingDefaults $themingDefaults,
  47. private IInitialState $initialState,
  48. private IURLGenerator $urlGenerator,
  49. private ImageManager $imageManager,
  50. ) {
  51. }
  52. /**
  53. * @return TemplateResponse
  54. */
  55. public function getForm(): TemplateResponse {
  56. $themable = true;
  57. $errorMessage = '';
  58. $theme = $this->config->getSystemValue('theme', '');
  59. if ($theme !== '') {
  60. $themable = false;
  61. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  62. }
  63. $allowedMimeTypes = array_reduce(ThemingController::VALID_UPLOAD_KEYS, function ($carry, $key) {
  64. $carry[$key] = $this->imageManager->getSupportedUploadImageFormats($key);
  65. return $carry;
  66. }, []);
  67. $this->initialState->provideInitialState('adminThemingParameters', [
  68. 'isThemable' => $themable,
  69. 'notThemableErrorMessage' => $errorMessage,
  70. 'name' => $this->themingDefaults->getEntity(),
  71. 'url' => $this->themingDefaults->getBaseUrl(),
  72. 'slogan' => $this->themingDefaults->getSlogan(),
  73. 'primaryColor' => $this->themingDefaults->getDefaultColorPrimary(),
  74. 'backgroundColor' => $this->themingDefaults->getDefaultColorBackground(),
  75. 'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
  76. 'allowedMimeTypes' => $allowedMimeTypes,
  77. 'backgroundURL' => $this->imageManager->getImageUrl('background'),
  78. 'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
  79. 'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
  80. 'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
  81. 'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
  82. 'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
  83. 'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
  84. 'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
  85. 'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
  86. 'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  87. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  88. 'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
  89. 'defaultApps' => array_filter(explode(',', $this->config->getSystemValueString('defaultapp', ''))),
  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. }