Admin.php 4.3 KB

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