@@ -31,196 +31,196 @@ |
||
| 31 | 31 | |
| 32 | 32 | class ThemingDefaults extends \OC_Defaults { |
| 33 | 33 | |
| 34 | - /** @var IConfig */ |
|
| 35 | - private $config; |
|
| 36 | - /** @var IL10N */ |
|
| 37 | - private $l; |
|
| 38 | - /** @var IURLGenerator */ |
|
| 39 | - private $urlGenerator; |
|
| 40 | - /** @var IRootFolder */ |
|
| 41 | - private $rootFolder; |
|
| 42 | - /** @var ICacheFactory */ |
|
| 43 | - private $cacheFactory; |
|
| 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 | - /** |
|
| 54 | - * ThemingDefaults constructor. |
|
| 55 | - * |
|
| 56 | - * @param IConfig $config |
|
| 57 | - * @param IL10N $l |
|
| 58 | - * @param IURLGenerator $urlGenerator |
|
| 59 | - * @param \OC_Defaults $defaults |
|
| 60 | - * @param IRootFolder $rootFolder |
|
| 61 | - * @param ICacheFactory $cacheFactory |
|
| 62 | - */ |
|
| 63 | - public function __construct(IConfig $config, |
|
| 64 | - IL10N $l, |
|
| 65 | - IURLGenerator $urlGenerator, |
|
| 66 | - \OC_Defaults $defaults, |
|
| 67 | - IRootFolder $rootFolder, |
|
| 68 | - ICacheFactory $cacheFactory |
|
| 69 | - ) { |
|
| 70 | - parent::__construct(); |
|
| 71 | - $this->config = $config; |
|
| 72 | - $this->l = $l; |
|
| 73 | - $this->urlGenerator = $urlGenerator; |
|
| 74 | - $this->rootFolder = $rootFolder; |
|
| 75 | - $this->cacheFactory = $cacheFactory; |
|
| 76 | - |
|
| 77 | - $this->name = $defaults->getName(); |
|
| 78 | - $this->url = $defaults->getBaseUrl(); |
|
| 79 | - $this->slogan = $defaults->getSlogan(); |
|
| 80 | - $this->color = $defaults->getMailHeaderColor(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getName() { |
|
| 84 | - return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function getHTMLName() { |
|
| 88 | - return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function getTitle() { |
|
| 92 | - return $this->getName(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function getEntity() { |
|
| 96 | - return $this->getName(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function getBaseUrl() { |
|
| 100 | - return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function getSlogan() { |
|
| 104 | - return \OC_Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function getShortFooter() { |
|
| 108 | - $slogan = $this->getSlogan(); |
|
| 109 | - $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 110 | - ' rel="noreferrer">' .$this->getEntity() . '</a>'. |
|
| 111 | - ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 112 | - |
|
| 113 | - return $footer; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Color that is used for the header as well as for mail headers |
|
| 118 | - * |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public function getMailHeaderColor() { |
|
| 122 | - return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Themed logo url |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function getLogo() { |
|
| 131 | - $logo = $this->config->getAppValue('theming', 'logoMime'); |
|
| 132 | - if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) { |
|
| 133 | - return $this->urlGenerator->imagePath('core','logo.svg'); |
|
| 134 | - } else { |
|
| 135 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Themed background image url |
|
| 141 | - * |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function getBackground() { |
|
| 145 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); |
|
| 146 | - if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) { |
|
| 147 | - return $this->urlGenerator->imagePath('core','background.jpg'); |
|
| 148 | - } else { |
|
| 149 | - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Check if Imagemagick is enabled and if SVG is supported |
|
| 155 | - * otherwise we can't render custom icons |
|
| 156 | - * |
|
| 157 | - * @return bool |
|
| 158 | - */ |
|
| 159 | - public function shouldReplaceIcons() { |
|
| 160 | - $cache = $this->cacheFactory->create('theming'); |
|
| 161 | - if($value = $cache->get('shouldReplaceIcons')) { |
|
| 162 | - return (bool)$value; |
|
| 163 | - } |
|
| 164 | - $value = false; |
|
| 165 | - if(extension_loaded('imagick')) { |
|
| 166 | - $checkImagick = new \Imagick(); |
|
| 167 | - if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
| 168 | - $value = true; |
|
| 169 | - } |
|
| 170 | - $checkImagick->clear(); |
|
| 171 | - } |
|
| 172 | - $cache->set('shouldReplaceIcons', $value); |
|
| 173 | - return $value; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Increases the cache buster key |
|
| 178 | - */ |
|
| 179 | - private function increaseCacheBuster() { |
|
| 180 | - $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 181 | - $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Update setting in the database |
|
| 186 | - * |
|
| 187 | - * @param string $setting |
|
| 188 | - * @param string $value |
|
| 189 | - */ |
|
| 190 | - public function set($setting, $value) { |
|
| 191 | - $this->config->setAppValue('theming', $setting, $value); |
|
| 192 | - $this->increaseCacheBuster(); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Revert settings to the default value |
|
| 197 | - * |
|
| 198 | - * @param string $setting setting which should be reverted |
|
| 199 | - * @return string default value |
|
| 200 | - */ |
|
| 201 | - public function undo($setting) { |
|
| 202 | - $this->config->deleteAppValue('theming', $setting); |
|
| 203 | - $this->increaseCacheBuster(); |
|
| 204 | - |
|
| 205 | - switch ($setting) { |
|
| 206 | - case 'name': |
|
| 207 | - $returnValue = $this->getEntity(); |
|
| 208 | - break; |
|
| 209 | - case 'url': |
|
| 210 | - $returnValue = $this->getBaseUrl(); |
|
| 211 | - break; |
|
| 212 | - case 'slogan': |
|
| 213 | - $returnValue = $this->getSlogan(); |
|
| 214 | - break; |
|
| 215 | - case 'color': |
|
| 216 | - $returnValue = $this->getMailHeaderColor(); |
|
| 217 | - break; |
|
| 218 | - default: |
|
| 219 | - $returnValue = ''; |
|
| 220 | - break; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $returnValue; |
|
| 224 | - } |
|
| 34 | + /** @var IConfig */ |
|
| 35 | + private $config; |
|
| 36 | + /** @var IL10N */ |
|
| 37 | + private $l; |
|
| 38 | + /** @var IURLGenerator */ |
|
| 39 | + private $urlGenerator; |
|
| 40 | + /** @var IRootFolder */ |
|
| 41 | + private $rootFolder; |
|
| 42 | + /** @var ICacheFactory */ |
|
| 43 | + private $cacheFactory; |
|
| 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 | + /** |
|
| 54 | + * ThemingDefaults constructor. |
|
| 55 | + * |
|
| 56 | + * @param IConfig $config |
|
| 57 | + * @param IL10N $l |
|
| 58 | + * @param IURLGenerator $urlGenerator |
|
| 59 | + * @param \OC_Defaults $defaults |
|
| 60 | + * @param IRootFolder $rootFolder |
|
| 61 | + * @param ICacheFactory $cacheFactory |
|
| 62 | + */ |
|
| 63 | + public function __construct(IConfig $config, |
|
| 64 | + IL10N $l, |
|
| 65 | + IURLGenerator $urlGenerator, |
|
| 66 | + \OC_Defaults $defaults, |
|
| 67 | + IRootFolder $rootFolder, |
|
| 68 | + ICacheFactory $cacheFactory |
|
| 69 | + ) { |
|
| 70 | + parent::__construct(); |
|
| 71 | + $this->config = $config; |
|
| 72 | + $this->l = $l; |
|
| 73 | + $this->urlGenerator = $urlGenerator; |
|
| 74 | + $this->rootFolder = $rootFolder; |
|
| 75 | + $this->cacheFactory = $cacheFactory; |
|
| 76 | + |
|
| 77 | + $this->name = $defaults->getName(); |
|
| 78 | + $this->url = $defaults->getBaseUrl(); |
|
| 79 | + $this->slogan = $defaults->getSlogan(); |
|
| 80 | + $this->color = $defaults->getMailHeaderColor(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getName() { |
|
| 84 | + return strip_tags($this->config->getAppValue('theming', 'name', $this->name)); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function getHTMLName() { |
|
| 88 | + return $this->config->getAppValue('theming', 'name', $this->name); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function getTitle() { |
|
| 92 | + return $this->getName(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function getEntity() { |
|
| 96 | + return $this->getName(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function getBaseUrl() { |
|
| 100 | + return $this->config->getAppValue('theming', 'url', $this->url); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function getSlogan() { |
|
| 104 | + return \OC_Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', $this->slogan)); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function getShortFooter() { |
|
| 108 | + $slogan = $this->getSlogan(); |
|
| 109 | + $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
|
| 110 | + ' rel="noreferrer">' .$this->getEntity() . '</a>'. |
|
| 111 | + ($slogan !== '' ? ' – ' . $slogan : ''); |
|
| 112 | + |
|
| 113 | + return $footer; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Color that is used for the header as well as for mail headers |
|
| 118 | + * |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public function getMailHeaderColor() { |
|
| 122 | + return $this->config->getAppValue('theming', 'color', $this->color); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Themed logo url |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function getLogo() { |
|
| 131 | + $logo = $this->config->getAppValue('theming', 'logoMime'); |
|
| 132 | + if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) { |
|
| 133 | + return $this->urlGenerator->imagePath('core','logo.svg'); |
|
| 134 | + } else { |
|
| 135 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Themed background image url |
|
| 141 | + * |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function getBackground() { |
|
| 145 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); |
|
| 146 | + if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) { |
|
| 147 | + return $this->urlGenerator->imagePath('core','background.jpg'); |
|
| 148 | + } else { |
|
| 149 | + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Check if Imagemagick is enabled and if SVG is supported |
|
| 155 | + * otherwise we can't render custom icons |
|
| 156 | + * |
|
| 157 | + * @return bool |
|
| 158 | + */ |
|
| 159 | + public function shouldReplaceIcons() { |
|
| 160 | + $cache = $this->cacheFactory->create('theming'); |
|
| 161 | + if($value = $cache->get('shouldReplaceIcons')) { |
|
| 162 | + return (bool)$value; |
|
| 163 | + } |
|
| 164 | + $value = false; |
|
| 165 | + if(extension_loaded('imagick')) { |
|
| 166 | + $checkImagick = new \Imagick(); |
|
| 167 | + if (count($checkImagick->queryFormats('SVG')) >= 1) { |
|
| 168 | + $value = true; |
|
| 169 | + } |
|
| 170 | + $checkImagick->clear(); |
|
| 171 | + } |
|
| 172 | + $cache->set('shouldReplaceIcons', $value); |
|
| 173 | + return $value; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Increases the cache buster key |
|
| 178 | + */ |
|
| 179 | + private function increaseCacheBuster() { |
|
| 180 | + $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 181 | + $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Update setting in the database |
|
| 186 | + * |
|
| 187 | + * @param string $setting |
|
| 188 | + * @param string $value |
|
| 189 | + */ |
|
| 190 | + public function set($setting, $value) { |
|
| 191 | + $this->config->setAppValue('theming', $setting, $value); |
|
| 192 | + $this->increaseCacheBuster(); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Revert settings to the default value |
|
| 197 | + * |
|
| 198 | + * @param string $setting setting which should be reverted |
|
| 199 | + * @return string default value |
|
| 200 | + */ |
|
| 201 | + public function undo($setting) { |
|
| 202 | + $this->config->deleteAppValue('theming', $setting); |
|
| 203 | + $this->increaseCacheBuster(); |
|
| 204 | + |
|
| 205 | + switch ($setting) { |
|
| 206 | + case 'name': |
|
| 207 | + $returnValue = $this->getEntity(); |
|
| 208 | + break; |
|
| 209 | + case 'url': |
|
| 210 | + $returnValue = $this->getBaseUrl(); |
|
| 211 | + break; |
|
| 212 | + case 'slogan': |
|
| 213 | + $returnValue = $this->getSlogan(); |
|
| 214 | + break; |
|
| 215 | + case 'color': |
|
| 216 | + $returnValue = $this->getMailHeaderColor(); |
|
| 217 | + break; |
|
| 218 | + default: |
|
| 219 | + $returnValue = ''; |
|
| 220 | + break; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $returnValue; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | } |