Admin.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\ImageManager;
  30. use OCA\Theming\ThemingDefaults;
  31. use OCP\AppFramework\Http\TemplateResponse;
  32. use OCP\IConfig;
  33. use OCP\IL10N;
  34. use OCP\IURLGenerator;
  35. use OCP\Settings\IDelegatedSettings;
  36. class Admin implements IDelegatedSettings {
  37. private string $appName;
  38. private IConfig $config;
  39. private IL10N $l;
  40. private ThemingDefaults $themingDefaults;
  41. private IURLGenerator $urlGenerator;
  42. private ImageManager $imageManager;
  43. public function __construct(string $appName,
  44. IConfig $config,
  45. IL10N $l,
  46. ThemingDefaults $themingDefaults,
  47. IURLGenerator $urlGenerator,
  48. ImageManager $imageManager) {
  49. $this->appName = $appName;
  50. $this->config = $config;
  51. $this->l = $l;
  52. $this->themingDefaults = $themingDefaults;
  53. $this->urlGenerator = $urlGenerator;
  54. $this->imageManager = $imageManager;
  55. }
  56. /**
  57. * @return TemplateResponse
  58. */
  59. public function getForm(): TemplateResponse {
  60. $themable = true;
  61. $errorMessage = '';
  62. $theme = $this->config->getSystemValue('theme', '');
  63. if ($theme !== '') {
  64. $themable = false;
  65. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  66. }
  67. $parameters = [
  68. 'themable' => $themable,
  69. 'errorMessage' => $errorMessage,
  70. 'name' => $this->themingDefaults->getEntity(),
  71. 'url' => $this->themingDefaults->getBaseUrl(),
  72. 'slogan' => $this->themingDefaults->getSlogan(),
  73. 'color' => $this->themingDefaults->getDefaultColorPrimary(),
  74. 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
  75. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  76. 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  77. 'images' => $this->imageManager->getCustomImages(),
  78. 'imprintUrl' => $this->themingDefaults->getImprintUrl(),
  79. 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
  80. 'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
  81. ];
  82. return new TemplateResponse($this->appName, 'settings-admin', $parameters, '');
  83. }
  84. /**
  85. * @return string the section ID, e.g. 'sharing'
  86. */
  87. public function getSection(): string {
  88. return $this->appName;
  89. }
  90. /**
  91. * @return int whether the form should be rather on the top or bottom of
  92. * the admin section. The forms are arranged in ascending order of the
  93. * priority values. It is required to return a value between 0 and 100.
  94. *
  95. * E.g.: 70
  96. */
  97. public function getPriority(): int {
  98. return 5;
  99. }
  100. public function getName(): ?string {
  101. return null; // Only one setting in this section
  102. }
  103. public function getAuthorizedAppConfig(): array {
  104. return [
  105. $this->appName => '/.*/',
  106. ];
  107. }
  108. }