1
0

Capabilities.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Guillaume COMPAGNON <gcompagnon@outlook.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Julien Veyssier <eneiluj@posteo.net>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Kate Döen <kate.doeen@nextcloud.com>
  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;
  29. use OCP\Capabilities\IPublicCapability;
  30. use OCP\IConfig;
  31. use OCP\IURLGenerator;
  32. /**
  33. * Class Capabilities
  34. *
  35. * @package OCA\Theming
  36. */
  37. class Capabilities implements IPublicCapability {
  38. /** @var ThemingDefaults */
  39. protected $theming;
  40. /** @var Util */
  41. protected $util;
  42. /** @var IURLGenerator */
  43. protected $url;
  44. /** @var IConfig */
  45. protected $config;
  46. /**
  47. * @param ThemingDefaults $theming
  48. * @param Util $util
  49. * @param IURLGenerator $url
  50. * @param IConfig $config
  51. */
  52. public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) {
  53. $this->theming = $theming;
  54. $this->util = $util;
  55. $this->url = $url;
  56. $this->config = $config;
  57. }
  58. /**
  59. * Return this classes capabilities
  60. *
  61. * @return array{
  62. * theming: array{
  63. * name: string,
  64. * url: string,
  65. * slogan: string,
  66. * color: string,
  67. * color-text: string,
  68. * color-element: string,
  69. * color-element-bright: string,
  70. * color-element-dark: string,
  71. * logo: string,
  72. * background: string,
  73. * background-plain: bool,
  74. * background-default: bool,
  75. * logoheader: string,
  76. * favicon: string,
  77. * },
  78. * }
  79. */
  80. public function getCapabilities() {
  81. $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
  82. $color = $this->theming->getColorPrimary();
  83. return [
  84. 'theming' => [
  85. 'name' => $this->theming->getName(),
  86. 'url' => $this->theming->getBaseUrl(),
  87. 'slogan' => $this->theming->getSlogan(),
  88. 'color' => $color,
  89. 'color-text' => $this->theming->getTextColorPrimary(),
  90. 'color-element' => $this->util->elementColor($color),
  91. 'color-element-bright' => $this->util->elementColor($color),
  92. 'color-element-dark' => $this->util->elementColor($color, false),
  93. 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  94. 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
  95. $this->theming->getColorPrimary() :
  96. $this->url->getAbsoluteURL($this->theming->getBackground()),
  97. 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'),
  98. 'background-default' => !$this->util->isBackgroundThemed(),
  99. 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  100. 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  101. ],
  102. ];
  103. }
  104. }