template.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
  4. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Theming;
  27. use OCP\IConfig;
  28. use OCP\IL10N;
  29. use OCP\IURLGenerator;
  30. /**
  31. * Class Template
  32. *
  33. * Handle all the values which can be modified by this app
  34. *
  35. * @package OCA\Theming
  36. */
  37. class Template extends \OC_Defaults {
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IL10N */
  41. private $l;
  42. /** @var IURLGenerator */
  43. private $urlGenerator;
  44. /** @var string */
  45. private $name;
  46. /** @var string */
  47. private $url;
  48. /** @var string */
  49. private $slogan;
  50. /** @var string */
  51. private $color;
  52. /**
  53. * Template constructor.
  54. *
  55. * @param IConfig $config
  56. * @param IL10N $l
  57. * @param IURLGenerator $urlGenerator
  58. * @param \OC_Defaults $defaults
  59. */
  60. public function __construct(IConfig $config,
  61. IL10N $l,
  62. IURLGenerator $urlGenerator,
  63. \OC_Defaults $defaults
  64. ) {
  65. parent::__construct();
  66. $this->config = $config;
  67. $this->l = $l;
  68. $this->urlGenerator = $urlGenerator;
  69. $this->name = $defaults->getName();
  70. $this->url = $defaults->getBaseUrl();
  71. $this->slogan = $defaults->getSlogan();
  72. $this->color = $defaults->getMailHeaderColor();
  73. }
  74. public function getName() {
  75. return $this->config->getAppValue('theming', 'name', $this->name);
  76. }
  77. public function getHTMLName() {
  78. return $this->config->getAppValue('theming', 'name', $this->name);
  79. }
  80. public function getTitle() {
  81. return $this->config->getAppValue('theming', 'name', $this->name);
  82. }
  83. public function getEntity() {
  84. return $this->config->getAppValue('theming', 'name', $this->name);
  85. }
  86. public function getBaseUrl() {
  87. return $this->config->getAppValue('theming', 'url', $this->url);
  88. }
  89. public function getSlogan() {
  90. return $this->config->getAppValue('theming', 'slogan', $this->slogan);
  91. }
  92. public function getShortFooter() {
  93. $slogan = $this->getSlogan();
  94. $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
  95. ' rel="noreferrer">' .$this->getEntity() . '</a>'.
  96. ($slogan !== '' ? ' – ' . $slogan : '');
  97. return $footer;
  98. }
  99. /**
  100. * Color that is used for the header as well as for mail headers
  101. *
  102. * @return string
  103. */
  104. public function getMailHeaderColor() {
  105. return $this->config->getAppValue('theming', 'color', $this->color);
  106. }
  107. /**
  108. * Increases the cache buster key
  109. */
  110. private function increaseCacheBuster() {
  111. $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
  112. $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
  113. }
  114. /**
  115. * Update setting in the database
  116. *
  117. * @param string $setting
  118. * @param string $value
  119. */
  120. public function set($setting, $value) {
  121. $this->config->setAppValue('theming', $setting, $value);
  122. $this->increaseCacheBuster();
  123. }
  124. /**
  125. * Revert settings to the default value
  126. *
  127. * @param string $setting setting which should be reverted
  128. * @return string default value
  129. */
  130. public function undo($setting) {
  131. $this->config->deleteAppValue('theming', $setting);
  132. $this->increaseCacheBuster();
  133. switch ($setting) {
  134. case 'name':
  135. $returnValue = $this->getEntity();
  136. break;
  137. case 'url':
  138. $returnValue = $this->getBaseUrl();
  139. break;
  140. case 'slogan':
  141. $returnValue = $this->getSlogan();
  142. break;
  143. case 'color':
  144. $returnValue = $this->getMailHeaderColor();
  145. break;
  146. default:
  147. $returnValue = '';
  148. break;
  149. }
  150. return $returnValue;
  151. }
  152. }