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