1
0

Admin.php 3.8 KB

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