@@ -43,218 +43,218 @@ |
||
| 43 | 43 | use OCP\PreConditionNotMetException; |
| 44 | 44 | |
| 45 | 45 | class BackgroundService { |
| 46 | - // true when the background is bright and need dark icons |
|
| 47 | - public const THEMING_MODE_DARK = 'dark'; |
|
| 48 | - public const DEFAULT_COLOR = '#0082c9'; |
|
| 49 | - public const DEFAULT_ACCESSIBLE_COLOR = '#006aa3'; |
|
| 46 | + // true when the background is bright and need dark icons |
|
| 47 | + public const THEMING_MODE_DARK = 'dark'; |
|
| 48 | + public const DEFAULT_COLOR = '#0082c9'; |
|
| 49 | + public const DEFAULT_ACCESSIBLE_COLOR = '#006aa3'; |
|
| 50 | 50 | |
| 51 | - public const BACKGROUND_SHIPPED = 'shipped'; |
|
| 52 | - public const BACKGROUND_CUSTOM = 'custom'; |
|
| 53 | - public const BACKGROUND_DEFAULT = 'default'; |
|
| 54 | - public const BACKGROUND_DISABLED = 'disabled'; |
|
| 51 | + public const BACKGROUND_SHIPPED = 'shipped'; |
|
| 52 | + public const BACKGROUND_CUSTOM = 'custom'; |
|
| 53 | + public const BACKGROUND_DEFAULT = 'default'; |
|
| 54 | + public const BACKGROUND_DISABLED = 'disabled'; |
|
| 55 | 55 | |
| 56 | - public const DEFAULT_BACKGROUND_IMAGE = 'kamil-porembinski-clouds.jpg'; |
|
| 57 | - public const SHIPPED_BACKGROUNDS = [ |
|
| 58 | - 'hannah-maclean-soft-floral.jpg' => [ |
|
| 59 | - 'attribution' => 'Soft floral (Hannah MacLean, CC0)', |
|
| 60 | - 'attribution_url' => 'https://stocksnap.io/photo/soft-floral-XOYWCCW5PA', |
|
| 61 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 62 | - 'primary_color' => '#9f652f', |
|
| 63 | - ], |
|
| 64 | - 'ted-moravec-morning-fog.jpg' => [ |
|
| 65 | - 'attribution' => 'Morning fog (Ted Moravec, Public Domain)', |
|
| 66 | - 'attribution_url' => 'https://flickr.com/photos/tmoravec/52392410261', |
|
| 67 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 68 | - 'primary_color' => '#114c3b', |
|
| 69 | - ], |
|
| 70 | - 'stefanus-martanto-setyo-husodo-underwater-ocean.jpg' => [ |
|
| 71 | - 'attribution' => 'Underwater ocean (Stefanus Martanto Setyo Husodo, CC0)', |
|
| 72 | - 'attribution_url' => 'https://stocksnap.io/photo/underwater-ocean-TJA9LBH4WS', |
|
| 73 | - 'primary_color' => '#04577e', |
|
| 74 | - ], |
|
| 75 | - 'zoltan-voros-rhythm-and-blues.jpg' => [ |
|
| 76 | - 'attribution' => 'Rhythm and blues (Zoltán Vörös, CC BY)', |
|
| 77 | - 'attribution_url' => 'https://flickr.com/photos/v923z/51634409289/', |
|
| 78 | - 'primary_color' => '#1c243c', |
|
| 79 | - ], |
|
| 80 | - 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ |
|
| 81 | - 'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)', |
|
| 82 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg', |
|
| 83 | - 'primary_color' => '#a53c17', |
|
| 84 | - ], |
|
| 85 | - 'bernie-cetonia-aurata-take-off-composition.jpg' => [ |
|
| 86 | - 'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)', |
|
| 87 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', |
|
| 88 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 89 | - 'primary_color' => '#56633d', |
|
| 90 | - ], |
|
| 91 | - 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ |
|
| 92 | - 'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)', |
|
| 93 | - 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', |
|
| 94 | - 'primary_color' => '#9c4236', |
|
| 95 | - ], |
|
| 96 | - 'eduardo-neves-pedra-azul.jpg' => [ |
|
| 97 | - 'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)', |
|
| 98 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', |
|
| 99 | - 'primary_color' => '#4f6071', |
|
| 100 | - ], |
|
| 101 | - 'european-space-agency-barents-bloom.jpg' => [ |
|
| 102 | - 'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)', |
|
| 103 | - 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', |
|
| 104 | - 'primary_color' => '#396475', |
|
| 105 | - ], |
|
| 106 | - 'hannes-fritz-flippity-floppity.jpg' => [ |
|
| 107 | - 'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)', |
|
| 108 | - 'attribution_url' => 'http://hannes.photos/flippity-floppity', |
|
| 109 | - 'primary_color' => '#98415a', |
|
| 110 | - ], |
|
| 111 | - 'hannes-fritz-roulette.jpg' => [ |
|
| 112 | - 'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)', |
|
| 113 | - 'attribution_url' => 'http://hannes.photos/roulette', |
|
| 114 | - 'primary_color' => '#845334', |
|
| 115 | - ], |
|
| 116 | - 'hannes-fritz-sea-spray.jpg' => [ |
|
| 117 | - 'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)', |
|
| 118 | - 'attribution_url' => 'http://hannes.photos/sea-spray', |
|
| 119 | - 'primary_color' => '#4f6071', |
|
| 120 | - ], |
|
| 121 | - 'kamil-porembinski-clouds.jpg' => [ |
|
| 122 | - 'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)', |
|
| 123 | - 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', |
|
| 124 | - 'primary_color' => self::DEFAULT_COLOR, |
|
| 125 | - ], |
|
| 126 | - 'bernard-spragg-new-zealand-fern.jpg' => [ |
|
| 127 | - 'attribution' => 'New zealand fern (Bernard Spragg, CC0)', |
|
| 128 | - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', |
|
| 129 | - 'primary_color' => '#316b26', |
|
| 130 | - ], |
|
| 131 | - 'rawpixel-pink-tapioca-bubbles.jpg' => [ |
|
| 132 | - 'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)', |
|
| 133 | - 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', |
|
| 134 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 135 | - 'primary_color' => '#7b4e7e', |
|
| 136 | - ], |
|
| 137 | - 'nasa-waxing-crescent-moon.jpg' => [ |
|
| 138 | - 'attribution' => 'Waxing crescent moon (NASA, Public Domain)', |
|
| 139 | - 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', |
|
| 140 | - 'primary_color' => '#005ac1', |
|
| 141 | - ], |
|
| 142 | - 'tommy-chau-already.jpg' => [ |
|
| 143 | - 'attribution' => 'Cityscape (Tommy Chau, CC BY)', |
|
| 144 | - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', |
|
| 145 | - 'primary_color' => '#6a2af4', |
|
| 146 | - ], |
|
| 147 | - 'tommy-chau-lion-rock-hill.jpg' => [ |
|
| 148 | - 'attribution' => 'Lion rock hill (Tommy Chau, CC BY)', |
|
| 149 | - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', |
|
| 150 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 151 | - 'primary_color' => '#7f4f70', |
|
| 152 | - ], |
|
| 153 | - 'lali-masriera-yellow-bricks.jpg' => [ |
|
| 154 | - 'attribution' => 'Yellow bricks (Lali Masriera, CC BY)', |
|
| 155 | - 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', |
|
| 156 | - 'theming' => self::THEMING_MODE_DARK, |
|
| 157 | - 'primary_color' => '#7f5700', |
|
| 158 | - ], |
|
| 159 | - ]; |
|
| 56 | + public const DEFAULT_BACKGROUND_IMAGE = 'kamil-porembinski-clouds.jpg'; |
|
| 57 | + public const SHIPPED_BACKGROUNDS = [ |
|
| 58 | + 'hannah-maclean-soft-floral.jpg' => [ |
|
| 59 | + 'attribution' => 'Soft floral (Hannah MacLean, CC0)', |
|
| 60 | + 'attribution_url' => 'https://stocksnap.io/photo/soft-floral-XOYWCCW5PA', |
|
| 61 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 62 | + 'primary_color' => '#9f652f', |
|
| 63 | + ], |
|
| 64 | + 'ted-moravec-morning-fog.jpg' => [ |
|
| 65 | + 'attribution' => 'Morning fog (Ted Moravec, Public Domain)', |
|
| 66 | + 'attribution_url' => 'https://flickr.com/photos/tmoravec/52392410261', |
|
| 67 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 68 | + 'primary_color' => '#114c3b', |
|
| 69 | + ], |
|
| 70 | + 'stefanus-martanto-setyo-husodo-underwater-ocean.jpg' => [ |
|
| 71 | + 'attribution' => 'Underwater ocean (Stefanus Martanto Setyo Husodo, CC0)', |
|
| 72 | + 'attribution_url' => 'https://stocksnap.io/photo/underwater-ocean-TJA9LBH4WS', |
|
| 73 | + 'primary_color' => '#04577e', |
|
| 74 | + ], |
|
| 75 | + 'zoltan-voros-rhythm-and-blues.jpg' => [ |
|
| 76 | + 'attribution' => 'Rhythm and blues (Zoltán Vörös, CC BY)', |
|
| 77 | + 'attribution_url' => 'https://flickr.com/photos/v923z/51634409289/', |
|
| 78 | + 'primary_color' => '#1c243c', |
|
| 79 | + ], |
|
| 80 | + 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ |
|
| 81 | + 'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)', |
|
| 82 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg', |
|
| 83 | + 'primary_color' => '#a53c17', |
|
| 84 | + ], |
|
| 85 | + 'bernie-cetonia-aurata-take-off-composition.jpg' => [ |
|
| 86 | + 'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)', |
|
| 87 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', |
|
| 88 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 89 | + 'primary_color' => '#56633d', |
|
| 90 | + ], |
|
| 91 | + 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ |
|
| 92 | + 'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)', |
|
| 93 | + 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', |
|
| 94 | + 'primary_color' => '#9c4236', |
|
| 95 | + ], |
|
| 96 | + 'eduardo-neves-pedra-azul.jpg' => [ |
|
| 97 | + 'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)', |
|
| 98 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', |
|
| 99 | + 'primary_color' => '#4f6071', |
|
| 100 | + ], |
|
| 101 | + 'european-space-agency-barents-bloom.jpg' => [ |
|
| 102 | + 'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)', |
|
| 103 | + 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', |
|
| 104 | + 'primary_color' => '#396475', |
|
| 105 | + ], |
|
| 106 | + 'hannes-fritz-flippity-floppity.jpg' => [ |
|
| 107 | + 'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)', |
|
| 108 | + 'attribution_url' => 'http://hannes.photos/flippity-floppity', |
|
| 109 | + 'primary_color' => '#98415a', |
|
| 110 | + ], |
|
| 111 | + 'hannes-fritz-roulette.jpg' => [ |
|
| 112 | + 'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)', |
|
| 113 | + 'attribution_url' => 'http://hannes.photos/roulette', |
|
| 114 | + 'primary_color' => '#845334', |
|
| 115 | + ], |
|
| 116 | + 'hannes-fritz-sea-spray.jpg' => [ |
|
| 117 | + 'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)', |
|
| 118 | + 'attribution_url' => 'http://hannes.photos/sea-spray', |
|
| 119 | + 'primary_color' => '#4f6071', |
|
| 120 | + ], |
|
| 121 | + 'kamil-porembinski-clouds.jpg' => [ |
|
| 122 | + 'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)', |
|
| 123 | + 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', |
|
| 124 | + 'primary_color' => self::DEFAULT_COLOR, |
|
| 125 | + ], |
|
| 126 | + 'bernard-spragg-new-zealand-fern.jpg' => [ |
|
| 127 | + 'attribution' => 'New zealand fern (Bernard Spragg, CC0)', |
|
| 128 | + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', |
|
| 129 | + 'primary_color' => '#316b26', |
|
| 130 | + ], |
|
| 131 | + 'rawpixel-pink-tapioca-bubbles.jpg' => [ |
|
| 132 | + 'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)', |
|
| 133 | + 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', |
|
| 134 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 135 | + 'primary_color' => '#7b4e7e', |
|
| 136 | + ], |
|
| 137 | + 'nasa-waxing-crescent-moon.jpg' => [ |
|
| 138 | + 'attribution' => 'Waxing crescent moon (NASA, Public Domain)', |
|
| 139 | + 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', |
|
| 140 | + 'primary_color' => '#005ac1', |
|
| 141 | + ], |
|
| 142 | + 'tommy-chau-already.jpg' => [ |
|
| 143 | + 'attribution' => 'Cityscape (Tommy Chau, CC BY)', |
|
| 144 | + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', |
|
| 145 | + 'primary_color' => '#6a2af4', |
|
| 146 | + ], |
|
| 147 | + 'tommy-chau-lion-rock-hill.jpg' => [ |
|
| 148 | + 'attribution' => 'Lion rock hill (Tommy Chau, CC BY)', |
|
| 149 | + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', |
|
| 150 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 151 | + 'primary_color' => '#7f4f70', |
|
| 152 | + ], |
|
| 153 | + 'lali-masriera-yellow-bricks.jpg' => [ |
|
| 154 | + 'attribution' => 'Yellow bricks (Lali Masriera, CC BY)', |
|
| 155 | + 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', |
|
| 156 | + 'theming' => self::THEMING_MODE_DARK, |
|
| 157 | + 'primary_color' => '#7f5700', |
|
| 158 | + ], |
|
| 159 | + ]; |
|
| 160 | 160 | |
| 161 | - private IRootFolder $rootFolder; |
|
| 162 | - private IAppData $appData; |
|
| 163 | - private IConfig $config; |
|
| 164 | - private string $userId; |
|
| 165 | - private ThemingDefaults $themingDefaults; |
|
| 161 | + private IRootFolder $rootFolder; |
|
| 162 | + private IAppData $appData; |
|
| 163 | + private IConfig $config; |
|
| 164 | + private string $userId; |
|
| 165 | + private ThemingDefaults $themingDefaults; |
|
| 166 | 166 | |
| 167 | - public function __construct(IRootFolder $rootFolder, |
|
| 168 | - IAppData $appData, |
|
| 169 | - IConfig $config, |
|
| 170 | - ?string $userId, |
|
| 171 | - ThemingDefaults $themingDefaults) { |
|
| 172 | - if ($userId === null) { |
|
| 173 | - return; |
|
| 174 | - } |
|
| 167 | + public function __construct(IRootFolder $rootFolder, |
|
| 168 | + IAppData $appData, |
|
| 169 | + IConfig $config, |
|
| 170 | + ?string $userId, |
|
| 171 | + ThemingDefaults $themingDefaults) { |
|
| 172 | + if ($userId === null) { |
|
| 173 | + return; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - $this->rootFolder = $rootFolder; |
|
| 177 | - $this->config = $config; |
|
| 178 | - $this->userId = $userId; |
|
| 179 | - $this->appData = $appData; |
|
| 180 | - $this->themingDefaults = $themingDefaults; |
|
| 181 | - } |
|
| 176 | + $this->rootFolder = $rootFolder; |
|
| 177 | + $this->config = $config; |
|
| 178 | + $this->userId = $userId; |
|
| 179 | + $this->appData = $appData; |
|
| 180 | + $this->themingDefaults = $themingDefaults; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - public function setDefaultBackground(): void { |
|
| 184 | - $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_image'); |
|
| 185 | - $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_color'); |
|
| 186 | - } |
|
| 183 | + public function setDefaultBackground(): void { |
|
| 184 | + $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_image'); |
|
| 185 | + $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_color'); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * @param $path |
|
| 190 | - * @throws NotFoundException |
|
| 191 | - * @throws NotPermittedException |
|
| 192 | - * @throws LockedException |
|
| 193 | - * @throws PreConditionNotMetException |
|
| 194 | - * @throws NoUserException |
|
| 195 | - */ |
|
| 196 | - public function setFileBackground($path): void { |
|
| 197 | - $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_CUSTOM); |
|
| 198 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 188 | + /** |
|
| 189 | + * @param $path |
|
| 190 | + * @throws NotFoundException |
|
| 191 | + * @throws NotPermittedException |
|
| 192 | + * @throws LockedException |
|
| 193 | + * @throws PreConditionNotMetException |
|
| 194 | + * @throws NoUserException |
|
| 195 | + */ |
|
| 196 | + public function setFileBackground($path): void { |
|
| 197 | + $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_CUSTOM); |
|
| 198 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 199 | 199 | |
| 200 | - /** @var File $file */ |
|
| 201 | - $file = $userFolder->get($path); |
|
| 202 | - $image = new \OCP\Image(); |
|
| 200 | + /** @var File $file */ |
|
| 201 | + $file = $userFolder->get($path); |
|
| 202 | + $image = new \OCP\Image(); |
|
| 203 | 203 | |
| 204 | - if ($image->loadFromFileHandle($file->fopen('r')) === false) { |
|
| 205 | - throw new InvalidArgumentException('Invalid image file'); |
|
| 206 | - } |
|
| 204 | + if ($image->loadFromFileHandle($file->fopen('r')) === false) { |
|
| 205 | + throw new InvalidArgumentException('Invalid image file'); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); |
|
| 209 | - } |
|
| 208 | + $this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r')); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - public function setShippedBackground($fileName): void { |
|
| 212 | - if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { |
|
| 213 | - throw new InvalidArgumentException('The given file name is invalid'); |
|
| 214 | - } |
|
| 215 | - $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', $fileName); |
|
| 216 | - $this->setColorBackground(self::SHIPPED_BACKGROUNDS[$fileName]['primary_color']); |
|
| 217 | - } |
|
| 211 | + public function setShippedBackground($fileName): void { |
|
| 212 | + if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { |
|
| 213 | + throw new InvalidArgumentException('The given file name is invalid'); |
|
| 214 | + } |
|
| 215 | + $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', $fileName); |
|
| 216 | + $this->setColorBackground(self::SHIPPED_BACKGROUNDS[$fileName]['primary_color']); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - public function setColorBackground(string $color): void { |
|
| 220 | - if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
| 221 | - throw new InvalidArgumentException('The given color is invalid'); |
|
| 222 | - } |
|
| 223 | - $this->config->setUserValue($this->userId, Application::APP_ID, 'background_color', $color); |
|
| 224 | - } |
|
| 219 | + public function setColorBackground(string $color): void { |
|
| 220 | + if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { |
|
| 221 | + throw new InvalidArgumentException('The given color is invalid'); |
|
| 222 | + } |
|
| 223 | + $this->config->setUserValue($this->userId, Application::APP_ID, 'background_color', $color); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - public function deleteBackgroundImage(): void { |
|
| 227 | - $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_DISABLED); |
|
| 228 | - } |
|
| 226 | + public function deleteBackgroundImage(): void { |
|
| 227 | + $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_DISABLED); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - public function getBackground(): ?ISimpleFile { |
|
| 231 | - $background = $this->config->getUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_DEFAULT); |
|
| 232 | - if ($background === self::BACKGROUND_CUSTOM) { |
|
| 233 | - try { |
|
| 234 | - return $this->getAppDataFolder()->getFile('background.jpg'); |
|
| 235 | - } catch (NotFoundException | NotPermittedException $e) { |
|
| 236 | - return null; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - return null; |
|
| 240 | - } |
|
| 230 | + public function getBackground(): ?ISimpleFile { |
|
| 231 | + $background = $this->config->getUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_DEFAULT); |
|
| 232 | + if ($background === self::BACKGROUND_CUSTOM) { |
|
| 233 | + try { |
|
| 234 | + return $this->getAppDataFolder()->getFile('background.jpg'); |
|
| 235 | + } catch (NotFoundException | NotPermittedException $e) { |
|
| 236 | + return null; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + return null; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Storing the data in appdata/theming/users/USERID |
|
| 244 | - * |
|
| 245 | - * @return ISimpleFolder |
|
| 246 | - * @throws NotPermittedException |
|
| 247 | - */ |
|
| 248 | - private function getAppDataFolder(): ISimpleFolder { |
|
| 249 | - try { |
|
| 250 | - $rootFolder = $this->appData->getFolder('users'); |
|
| 251 | - } catch (NotFoundException $e) { |
|
| 252 | - $rootFolder = $this->appData->newFolder('users'); |
|
| 253 | - } |
|
| 254 | - try { |
|
| 255 | - return $rootFolder->getFolder($this->userId); |
|
| 256 | - } catch (NotFoundException $e) { |
|
| 257 | - return $rootFolder->newFolder($this->userId); |
|
| 258 | - } |
|
| 259 | - } |
|
| 242 | + /** |
|
| 243 | + * Storing the data in appdata/theming/users/USERID |
|
| 244 | + * |
|
| 245 | + * @return ISimpleFolder |
|
| 246 | + * @throws NotPermittedException |
|
| 247 | + */ |
|
| 248 | + private function getAppDataFolder(): ISimpleFolder { |
|
| 249 | + try { |
|
| 250 | + $rootFolder = $this->appData->getFolder('users'); |
|
| 251 | + } catch (NotFoundException $e) { |
|
| 252 | + $rootFolder = $this->appData->newFolder('users'); |
|
| 253 | + } |
|
| 254 | + try { |
|
| 255 | + return $rootFolder->getFolder($this->userId); |
|
| 256 | + } catch (NotFoundException $e) { |
|
| 257 | + return $rootFolder->newFolder($this->userId); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | } |