Admin.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 iamfool <praveenraonp@gmail.com>
  8. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  9. * @author Julius Haertl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\Theming\Settings;
  30. use OCA\Theming\ImageManager;
  31. use OCA\Theming\ThemingDefaults;
  32. use OCP\AppFramework\Http\TemplateResponse;
  33. use OCP\IConfig;
  34. use OCP\IL10N;
  35. use OCP\IURLGenerator;
  36. use OCP\Settings\ISettings;
  37. class Admin implements ISettings {
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IL10N */
  41. private $l;
  42. /** @var ThemingDefaults */
  43. private $themingDefaults;
  44. /** @var IURLGenerator */
  45. private $urlGenerator;
  46. /** @var ImageManager */
  47. private $imageManager;
  48. public function __construct(IConfig $config,
  49. IL10N $l,
  50. ThemingDefaults $themingDefaults,
  51. IURLGenerator $urlGenerator,
  52. ImageManager $imageManager) {
  53. $this->config = $config;
  54. $this->l = $l;
  55. $this->themingDefaults = $themingDefaults;
  56. $this->urlGenerator = $urlGenerator;
  57. $this->imageManager = $imageManager;
  58. }
  59. /**
  60. * @return TemplateResponse
  61. */
  62. public function getForm(): TemplateResponse {
  63. $themable = true;
  64. $errorMessage = '';
  65. $theme = $this->config->getSystemValue('theme', '');
  66. if ($theme !== '') {
  67. $themable = false;
  68. $errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
  69. }
  70. $parameters = [
  71. 'themable' => $themable,
  72. 'errorMessage' => $errorMessage,
  73. 'name' => $this->themingDefaults->getEntity(),
  74. 'url' => $this->themingDefaults->getBaseUrl(),
  75. 'slogan' => $this->themingDefaults->getSlogan(),
  76. 'color' => $this->themingDefaults->getColorPrimary(),
  77. 'uploadLogoRoute' => $this->urlGenerator->linkToRoute('theming.Theming.uploadImage'),
  78. 'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
  79. 'iconDocs' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
  80. 'images' => $this->imageManager->getCustomImages(),
  81. 'imprintUrl' => $this->themingDefaults->getImprintUrl(),
  82. 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
  83. ];
  84. return new TemplateResponse('theming', 'settings-admin', $parameters, '');
  85. }
  86. /**
  87. * @return string the section ID, e.g. 'sharing'
  88. */
  89. public function getSection(): string {
  90. return 'theming';
  91. }
  92. /**
  93. * @return int whether the form should be rather on the top or bottom of
  94. * the admin section. The forms are arranged in ascending order of the
  95. * priority values. It is required to return a value between 0 and 100.
  96. *
  97. * E.g.: 70
  98. */
  99. public function getPriority(): int {
  100. return 5;
  101. }
  102. }