Admin.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Settings;
  7. use OCA\Theming\AppInfo\Application;
  8. use OCA\Theming\Controller\ThemingController;
  9. use OCA\Theming\ImageManager;
  10. use OCA\Theming\Service\BackgroundService;
  11. use OCA\Theming\ThemingDefaults;
  12. use OCP\AppFramework\Http\TemplateResponse;
  13. use OCP\AppFramework\Services\IInitialState;
  14. use OCP\IConfig;
  15. use OCP\IL10N;
  16. use OCP\IURLGenerator;
  17. use OCP\Settings\IDelegatedSettings;
  18. use OCP\Util;
  19. class Admin implements IDelegatedSettings {
  20. public function __construct(
  21. private string $appName,
  22. private IConfig $config,
  23. private IL10N $l,
  24. private ThemingDefaults $themingDefaults,
  25. private IInitialState $initialState,
  26. private IURLGenerator $urlGenerator,
  27. private ImageManager $imageManager,
  28. ) {
  29. }
  30. /**
  31. * @return TemplateResponse
  32. */
  33. public function getForm(): TemplateResponse {
  34. $themable = true;
  35. $errorMessage = '';
  36. $theme = $this->config->getSystemValue('theme', '');
  37. if ($theme !== '') {
  38. $themable = false;
  39. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  40. }
  41. $allowedMimeTypes = array_reduce(ThemingController::VALID_UPLOAD_KEYS, function ($carry, $key) {
  42. $carry[$key] = $this->imageManager->getSupportedUploadImageFormats($key);
  43. return $carry;
  44. }, []);
  45. $this->initialState->provideInitialState('adminThemingParameters', [
  46. 'isThemable' => $themable,
  47. 'notThemableErrorMessage' => $errorMessage,
  48. 'name' => $this->themingDefaults->getEntity(),
  49. 'url' => $this->themingDefaults->getBaseUrl(),
  50. 'slogan' => $this->themingDefaults->getSlogan(),
  51. 'primaryColor' => $this->themingDefaults->getDefaultColorPrimary(),
  52. 'backgroundColor' => $this->themingDefaults->getDefaultColorBackground(),
  53. 'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
  54. 'allowedMimeTypes' => $allowedMimeTypes,
  55. 'backgroundURL' => $this->imageManager->getImageUrl('background'),
  56. 'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
  57. 'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
  58. 'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
  59. 'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
  60. 'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
  61. 'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
  62. 'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
  63. 'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
  64. 'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  65. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  66. 'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
  67. 'defaultApps' => array_filter(explode(',', $this->config->getSystemValueString('defaultapp', ''))),
  68. ]);
  69. Util::addScript($this->appName, 'admin-theming');
  70. return new TemplateResponse($this->appName, 'settings-admin');
  71. }
  72. /**
  73. * @return string the section ID, e.g. 'sharing'
  74. */
  75. public function getSection(): string {
  76. return $this->appName;
  77. }
  78. /**
  79. * @return int whether the form should be rather on the top or bottom of
  80. * the admin section. The forms are arranged in ascending order of the
  81. * priority values. It is required to return a value between 0 and 100.
  82. *
  83. * E.g.: 70
  84. */
  85. public function getPriority(): int {
  86. return 5;
  87. }
  88. public function getName(): ?string {
  89. return null; // Only one setting in this section
  90. }
  91. public function getAuthorizedAppConfig(): array {
  92. return [
  93. $this->appName => '/.*/',
  94. ];
  95. }
  96. }