Capabilities.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Theming;
  28. use OCP\Capabilities\IPublicCapability;
  29. use OCP\IConfig;
  30. use OCP\IURLGenerator;
  31. /**
  32. * Class Capabilities
  33. *
  34. * @package OCA\Theming
  35. */
  36. class Capabilities implements IPublicCapability {
  37. /** @var ThemingDefaults */
  38. protected $theming;
  39. /** @var Util */
  40. protected $util;
  41. /** @var IURLGenerator */
  42. protected $url;
  43. /** @var IConfig */
  44. protected $config;
  45. /**
  46. * @param ThemingDefaults $theming
  47. * @param Util $util
  48. * @param IURLGenerator $url
  49. * @param IConfig $config
  50. */
  51. public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) {
  52. $this->theming = $theming;
  53. $this->util = $util;
  54. $this->url = $url;
  55. $this->config = $config;
  56. }
  57. /**
  58. * Return this classes capabilities
  59. *
  60. * @return array
  61. */
  62. public function getCapabilities() {
  63. $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
  64. $color = $this->theming->getColorPrimary();
  65. return [
  66. 'theming' => [
  67. 'name' => $this->theming->getName(),
  68. 'url' => $this->theming->getBaseUrl(),
  69. 'slogan' => $this->theming->getSlogan(),
  70. 'color' => $color,
  71. 'color-text' => $this->theming->getTextColorPrimary(),
  72. 'color-element' => $this->util->elementColor($color),
  73. 'color-element-bright' => $this->util->elementColor($color),
  74. 'color-element-dark' => $this->util->elementColor($color, false),
  75. 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  76. 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
  77. $this->theming->getColorPrimary() :
  78. $this->url->getAbsoluteURL($this->theming->getBackground()),
  79. 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'),
  80. 'background-default' => !$this->util->isBackgroundThemed(),
  81. 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  82. 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
  83. ],
  84. ];
  85. }
  86. }