@@ -38,232 +38,232 @@ |
||
| 38 | 38 | |
| 39 | 39 | class Util { |
| 40 | 40 | |
| 41 | - private IConfig $config; |
|
| 42 | - private IAppManager $appManager; |
|
| 43 | - private IAppData $appData; |
|
| 41 | + private IConfig $config; |
|
| 42 | + private IAppManager $appManager; |
|
| 43 | + private IAppData $appData; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Util constructor. |
|
| 47 | - * |
|
| 48 | - * @param IConfig $config |
|
| 49 | - * @param IAppManager $appManager |
|
| 50 | - * @param IAppData $appData |
|
| 51 | - */ |
|
| 52 | - public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
| 53 | - $this->config = $config; |
|
| 54 | - $this->appManager = $appManager; |
|
| 55 | - $this->appData = $appData; |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * Util constructor. |
|
| 47 | + * |
|
| 48 | + * @param IConfig $config |
|
| 49 | + * @param IAppManager $appManager |
|
| 50 | + * @param IAppData $appData |
|
| 51 | + */ |
|
| 52 | + public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) { |
|
| 53 | + $this->config = $config; |
|
| 54 | + $this->appManager = $appManager; |
|
| 55 | + $this->appData = $appData; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param string $color rgb color value |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - public function invertTextColor($color) { |
|
| 63 | - $l = $this->calculateLuma($color); |
|
| 64 | - if ($l > 0.6) { |
|
| 65 | - return true; |
|
| 66 | - } else { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * @param string $color rgb color value |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + public function invertTextColor($color) { |
|
| 63 | + $l = $this->calculateLuma($color); |
|
| 64 | + if ($l > 0.6) { |
|
| 65 | + return true; |
|
| 66 | + } else { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * get color for on-page elements: |
|
| 73 | - * theme color by default, grey if theme color is to bright |
|
| 74 | - * @param string $color |
|
| 75 | - * @param bool $brightBackground |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function elementColor($color, bool $brightBackground = true) { |
|
| 79 | - $luminance = $this->calculateLuminance($color); |
|
| 71 | + /** |
|
| 72 | + * get color for on-page elements: |
|
| 73 | + * theme color by default, grey if theme color is to bright |
|
| 74 | + * @param string $color |
|
| 75 | + * @param bool $brightBackground |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function elementColor($color, bool $brightBackground = true) { |
|
| 79 | + $luminance = $this->calculateLuminance($color); |
|
| 80 | 80 | |
| 81 | - if ($brightBackground && $luminance > 0.8) { |
|
| 82 | - // If the color is too bright in bright mode, we fall back to a darker gray |
|
| 83 | - return '#aaaaaa'; |
|
| 84 | - } |
|
| 81 | + if ($brightBackground && $luminance > 0.8) { |
|
| 82 | + // If the color is too bright in bright mode, we fall back to a darker gray |
|
| 83 | + return '#aaaaaa'; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if (!$brightBackground && $luminance < 0.2) { |
|
| 87 | - // If the color is too dark in dark mode, we fall back to a brighter gray |
|
| 88 | - return '#555555'; |
|
| 89 | - } |
|
| 86 | + if (!$brightBackground && $luminance < 0.2) { |
|
| 87 | + // If the color is too dark in dark mode, we fall back to a brighter gray |
|
| 88 | + return '#555555'; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $color; |
|
| 92 | - } |
|
| 91 | + return $color; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function mix(string $color1, string $color2, int $factor): string { |
|
| 95 | - $color = new Color($color1); |
|
| 96 | - return '#' . $color->mix($color2, $factor); |
|
| 97 | - } |
|
| 94 | + public function mix(string $color1, string $color2, int $factor): string { |
|
| 95 | + $color = new Color($color1); |
|
| 96 | + return '#' . $color->mix($color2, $factor); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function lighten(string $color, int $factor): string { |
|
| 100 | - $color = new Color($color); |
|
| 101 | - return '#' . $color->lighten($factor); |
|
| 102 | - } |
|
| 99 | + public function lighten(string $color, int $factor): string { |
|
| 100 | + $color = new Color($color); |
|
| 101 | + return '#' . $color->lighten($factor); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - public function darken(string $color, int $factor): string { |
|
| 105 | - $color = new Color($color); |
|
| 106 | - return '#' . $color->darken($factor); |
|
| 107 | - } |
|
| 104 | + public function darken(string $color, int $factor): string { |
|
| 105 | + $color = new Color($color); |
|
| 106 | + return '#' . $color->darken($factor); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Convert RGB to HSL |
|
| 111 | - * |
|
| 112 | - * Copied from cssphp, copyright Leaf Corcoran, licensed under MIT |
|
| 113 | - * |
|
| 114 | - * @param int $red |
|
| 115 | - * @param int $green |
|
| 116 | - * @param int $blue |
|
| 117 | - * |
|
| 118 | - * @return float[] |
|
| 119 | - */ |
|
| 120 | - public function toHSL(int $red, int $green, int $blue): array { |
|
| 121 | - $color = new Color(Color::rgbToHex(['R' => $red, 'G' => $green, 'B' => $blue])); |
|
| 122 | - return array_values($color->getHsl()); |
|
| 123 | - } |
|
| 109 | + /** |
|
| 110 | + * Convert RGB to HSL |
|
| 111 | + * |
|
| 112 | + * Copied from cssphp, copyright Leaf Corcoran, licensed under MIT |
|
| 113 | + * |
|
| 114 | + * @param int $red |
|
| 115 | + * @param int $green |
|
| 116 | + * @param int $blue |
|
| 117 | + * |
|
| 118 | + * @return float[] |
|
| 119 | + */ |
|
| 120 | + public function toHSL(int $red, int $green, int $blue): array { |
|
| 121 | + $color = new Color(Color::rgbToHex(['R' => $red, 'G' => $green, 'B' => $blue])); |
|
| 122 | + return array_values($color->getHsl()); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @param string $color rgb color value |
|
| 127 | - * @return float |
|
| 128 | - */ |
|
| 129 | - public function calculateLuminance(string $color): float { |
|
| 130 | - [$red, $green, $blue] = $this->hexToRGB($color); |
|
| 131 | - $hsl = $this->toHSL($red, $green, $blue); |
|
| 132 | - return $hsl[2]; |
|
| 133 | - } |
|
| 125 | + /** |
|
| 126 | + * @param string $color rgb color value |
|
| 127 | + * @return float |
|
| 128 | + */ |
|
| 129 | + public function calculateLuminance(string $color): float { |
|
| 130 | + [$red, $green, $blue] = $this->hexToRGB($color); |
|
| 131 | + $hsl = $this->toHSL($red, $green, $blue); |
|
| 132 | + return $hsl[2]; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param string $color rgb color value |
|
| 137 | - * @return float |
|
| 138 | - */ |
|
| 139 | - public function calculateLuma(string $color): float { |
|
| 140 | - [$red, $green, $blue] = $this->hexToRGB($color); |
|
| 141 | - return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
| 142 | - } |
|
| 135 | + /** |
|
| 136 | + * @param string $color rgb color value |
|
| 137 | + * @return float |
|
| 138 | + */ |
|
| 139 | + public function calculateLuma(string $color): float { |
|
| 140 | + [$red, $green, $blue] = $this->hexToRGB($color); |
|
| 141 | + return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @param string $color rgb color value |
|
| 146 | - * @return int[] |
|
| 147 | - * @psalm-return array{0: int, 1: int, 2: int} |
|
| 148 | - */ |
|
| 149 | - public function hexToRGB(string $color): array { |
|
| 150 | - $color = new Color($color); |
|
| 151 | - return array_values($color->getRgb()); |
|
| 152 | - } |
|
| 144 | + /** |
|
| 145 | + * @param string $color rgb color value |
|
| 146 | + * @return int[] |
|
| 147 | + * @psalm-return array{0: int, 1: int, 2: int} |
|
| 148 | + */ |
|
| 149 | + public function hexToRGB(string $color): array { |
|
| 150 | + $color = new Color($color); |
|
| 151 | + return array_values($color->getRgb()); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * @param $color |
|
| 156 | - * @return string base64 encoded radio button svg |
|
| 157 | - */ |
|
| 158 | - public function generateRadioButton($color) { |
|
| 159 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
| 160 | - '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
| 161 | - return base64_encode($radioButtonIcon); |
|
| 162 | - } |
|
| 154 | + /** |
|
| 155 | + * @param $color |
|
| 156 | + * @return string base64 encoded radio button svg |
|
| 157 | + */ |
|
| 158 | + public function generateRadioButton($color) { |
|
| 159 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
| 160 | + '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
|
| 161 | + return base64_encode($radioButtonIcon); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * @param $app string app name |
|
| 167 | - * @return string|ISimpleFile path to app icon / file of logo |
|
| 168 | - */ |
|
| 169 | - public function getAppIcon($app) { |
|
| 170 | - $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
|
| 171 | - try { |
|
| 172 | - $appPath = $this->appManager->getAppPath($app); |
|
| 173 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
| 174 | - if (file_exists($icon)) { |
|
| 175 | - return $icon; |
|
| 176 | - } |
|
| 177 | - $icon = $appPath . '/img/app.svg'; |
|
| 178 | - if (file_exists($icon)) { |
|
| 179 | - return $icon; |
|
| 180 | - } |
|
| 181 | - } catch (AppPathNotFoundException $e) { |
|
| 182 | - } |
|
| 165 | + /** |
|
| 166 | + * @param $app string app name |
|
| 167 | + * @return string|ISimpleFile path to app icon / file of logo |
|
| 168 | + */ |
|
| 169 | + public function getAppIcon($app) { |
|
| 170 | + $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
|
| 171 | + try { |
|
| 172 | + $appPath = $this->appManager->getAppPath($app); |
|
| 173 | + $icon = $appPath . '/img/' . $app . '.svg'; |
|
| 174 | + if (file_exists($icon)) { |
|
| 175 | + return $icon; |
|
| 176 | + } |
|
| 177 | + $icon = $appPath . '/img/app.svg'; |
|
| 178 | + if (file_exists($icon)) { |
|
| 179 | + return $icon; |
|
| 180 | + } |
|
| 181 | + } catch (AppPathNotFoundException $e) { |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
| 185 | - $logoFile = null; |
|
| 186 | - try { |
|
| 187 | - $folder = $this->appData->getFolder('images'); |
|
| 188 | - return $folder->getFile('logo'); |
|
| 189 | - } catch (NotFoundException $e) { |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
| 193 | - } |
|
| 184 | + if ($this->config->getAppValue('theming', 'logoMime', '') !== '') { |
|
| 185 | + $logoFile = null; |
|
| 186 | + try { |
|
| 187 | + $folder = $this->appData->getFolder('images'); |
|
| 188 | + return $folder->getFile('logo'); |
|
| 189 | + } catch (NotFoundException $e) { |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * @param $app string app name |
|
| 197 | - * @param $image string relative path to image in app folder |
|
| 198 | - * @return string|false absolute path to image |
|
| 199 | - */ |
|
| 200 | - public function getAppImage($app, $image) { |
|
| 201 | - $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
|
| 202 | - $image = str_replace(['\0', '\\', '..'], '', $image); |
|
| 203 | - if ($app === "core") { |
|
| 204 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
| 205 | - if (file_exists($icon)) { |
|
| 206 | - return $icon; |
|
| 207 | - } |
|
| 208 | - } |
|
| 195 | + /** |
|
| 196 | + * @param $app string app name |
|
| 197 | + * @param $image string relative path to image in app folder |
|
| 198 | + * @return string|false absolute path to image |
|
| 199 | + */ |
|
| 200 | + public function getAppImage($app, $image) { |
|
| 201 | + $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
|
| 202 | + $image = str_replace(['\0', '\\', '..'], '', $image); |
|
| 203 | + if ($app === "core") { |
|
| 204 | + $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
| 205 | + if (file_exists($icon)) { |
|
| 206 | + return $icon; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - try { |
|
| 211 | - $appPath = $this->appManager->getAppPath($app); |
|
| 212 | - } catch (AppPathNotFoundException $e) { |
|
| 213 | - return false; |
|
| 214 | - } |
|
| 210 | + try { |
|
| 211 | + $appPath = $this->appManager->getAppPath($app); |
|
| 212 | + } catch (AppPathNotFoundException $e) { |
|
| 213 | + return false; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - $icon = $appPath . '/img/' . $image; |
|
| 217 | - if (file_exists($icon)) { |
|
| 218 | - return $icon; |
|
| 219 | - } |
|
| 220 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
| 221 | - if (file_exists($icon)) { |
|
| 222 | - return $icon; |
|
| 223 | - } |
|
| 224 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
| 225 | - if (file_exists($icon)) { |
|
| 226 | - return $icon; |
|
| 227 | - } |
|
| 228 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
| 229 | - if (file_exists($icon)) { |
|
| 230 | - return $icon; |
|
| 231 | - } |
|
| 232 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
| 233 | - if (file_exists($icon)) { |
|
| 234 | - return $icon; |
|
| 235 | - } |
|
| 216 | + $icon = $appPath . '/img/' . $image; |
|
| 217 | + if (file_exists($icon)) { |
|
| 218 | + return $icon; |
|
| 219 | + } |
|
| 220 | + $icon = $appPath . '/img/' . $image . '.svg'; |
|
| 221 | + if (file_exists($icon)) { |
|
| 222 | + return $icon; |
|
| 223 | + } |
|
| 224 | + $icon = $appPath . '/img/' . $image . '.png'; |
|
| 225 | + if (file_exists($icon)) { |
|
| 226 | + return $icon; |
|
| 227 | + } |
|
| 228 | + $icon = $appPath . '/img/' . $image . '.gif'; |
|
| 229 | + if (file_exists($icon)) { |
|
| 230 | + return $icon; |
|
| 231 | + } |
|
| 232 | + $icon = $appPath . '/img/' . $image . '.jpg'; |
|
| 233 | + if (file_exists($icon)) { |
|
| 234 | + return $icon; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - return false; |
|
| 238 | - } |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * replace default color with a custom one |
|
| 242 | - * |
|
| 243 | - * @param $svg string content of a svg file |
|
| 244 | - * @param $color string color to match |
|
| 245 | - * @return string |
|
| 246 | - */ |
|
| 247 | - public function colorizeSvg($svg, $color) { |
|
| 248 | - $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
| 249 | - return $svg; |
|
| 250 | - } |
|
| 240 | + /** |
|
| 241 | + * replace default color with a custom one |
|
| 242 | + * |
|
| 243 | + * @param $svg string content of a svg file |
|
| 244 | + * @param $color string color to match |
|
| 245 | + * @return string |
|
| 246 | + */ |
|
| 247 | + public function colorizeSvg($svg, $color) { |
|
| 248 | + $svg = preg_replace('/#0082c9/i', $color, $svg); |
|
| 249 | + return $svg; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Check if a custom theme is set in the server configuration |
|
| 254 | - * |
|
| 255 | - * @return bool |
|
| 256 | - */ |
|
| 257 | - public function isAlreadyThemed() { |
|
| 258 | - $theme = $this->config->getSystemValue('theme', ''); |
|
| 259 | - if ($theme !== '') { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 252 | + /** |
|
| 253 | + * Check if a custom theme is set in the server configuration |
|
| 254 | + * |
|
| 255 | + * @return bool |
|
| 256 | + */ |
|
| 257 | + public function isAlreadyThemed() { |
|
| 258 | + $theme = $this->config->getSystemValue('theme', ''); |
|
| 259 | + if ($theme !== '') { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - public function isBackgroundThemed() { |
|
| 266 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); |
|
| 267 | - return $backgroundLogo !== '' && $backgroundLogo !== 'backgroundColor'; |
|
| 268 | - } |
|
| 265 | + public function isBackgroundThemed() { |
|
| 266 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); |
|
| 267 | + return $backgroundLogo !== '' && $backgroundLogo !== 'backgroundColor'; |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -93,17 +93,17 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | public function mix(string $color1, string $color2, int $factor): string { |
| 95 | 95 | $color = new Color($color1); |
| 96 | - return '#' . $color->mix($color2, $factor); |
|
| 96 | + return '#'.$color->mix($color2, $factor); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function lighten(string $color, int $factor): string { |
| 100 | 100 | $color = new Color($color); |
| 101 | - return '#' . $color->lighten($factor); |
|
| 101 | + return '#'.$color->lighten($factor); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | public function darken(string $color, int $factor): string { |
| 105 | 105 | $color = new Color($color); |
| 106 | - return '#' . $color->darken($factor); |
|
| 106 | + return '#'.$color->darken($factor); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @return string base64 encoded radio button svg |
| 157 | 157 | */ |
| 158 | 158 | public function generateRadioButton($color) { |
| 159 | - $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' . |
|
| 159 | + $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">'. |
|
| 160 | 160 | '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>'; |
| 161 | 161 | return base64_encode($radioButtonIcon); |
| 162 | 162 | } |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
| 171 | 171 | try { |
| 172 | 172 | $appPath = $this->appManager->getAppPath($app); |
| 173 | - $icon = $appPath . '/img/' . $app . '.svg'; |
|
| 173 | + $icon = $appPath.'/img/'.$app.'.svg'; |
|
| 174 | 174 | if (file_exists($icon)) { |
| 175 | 175 | return $icon; |
| 176 | 176 | } |
| 177 | - $icon = $appPath . '/img/app.svg'; |
|
| 177 | + $icon = $appPath.'/img/app.svg'; |
|
| 178 | 178 | if (file_exists($icon)) { |
| 179 | 179 | return $icon; |
| 180 | 180 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } catch (NotFoundException $e) { |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | - return \OC::$SERVERROOT . '/core/img/logo/logo.svg'; |
|
| 192 | + return \OC::$SERVERROOT.'/core/img/logo/logo.svg'; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $app = str_replace(['\0', '/', '\\', '..'], '', $app); |
| 202 | 202 | $image = str_replace(['\0', '\\', '..'], '', $image); |
| 203 | 203 | if ($app === "core") { |
| 204 | - $icon = \OC::$SERVERROOT . '/core/img/' . $image; |
|
| 204 | + $icon = \OC::$SERVERROOT.'/core/img/'.$image; |
|
| 205 | 205 | if (file_exists($icon)) { |
| 206 | 206 | return $icon; |
| 207 | 207 | } |
@@ -213,23 +213,23 @@ discard block |
||
| 213 | 213 | return false; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $icon = $appPath . '/img/' . $image; |
|
| 216 | + $icon = $appPath.'/img/'.$image; |
|
| 217 | 217 | if (file_exists($icon)) { |
| 218 | 218 | return $icon; |
| 219 | 219 | } |
| 220 | - $icon = $appPath . '/img/' . $image . '.svg'; |
|
| 220 | + $icon = $appPath.'/img/'.$image.'.svg'; |
|
| 221 | 221 | if (file_exists($icon)) { |
| 222 | 222 | return $icon; |
| 223 | 223 | } |
| 224 | - $icon = $appPath . '/img/' . $image . '.png'; |
|
| 224 | + $icon = $appPath.'/img/'.$image.'.png'; |
|
| 225 | 225 | if (file_exists($icon)) { |
| 226 | 226 | return $icon; |
| 227 | 227 | } |
| 228 | - $icon = $appPath . '/img/' . $image . '.gif'; |
|
| 228 | + $icon = $appPath.'/img/'.$image.'.gif'; |
|
| 229 | 229 | if (file_exists($icon)) { |
| 230 | 230 | return $icon; |
| 231 | 231 | } |
| 232 | - $icon = $appPath . '/img/' . $image . '.jpg'; |
|
| 232 | + $icon = $appPath.'/img/'.$image.'.jpg'; |
|
| 233 | 233 | if (file_exists($icon)) { |
| 234 | 234 | return $icon; |
| 235 | 235 | } |
@@ -33,171 +33,171 @@ |
||
| 33 | 33 | use OCP\IURLGenerator; |
| 34 | 34 | |
| 35 | 35 | class DefaultTheme implements ITheme { |
| 36 | - public Util $util; |
|
| 37 | - public ThemingDefaults $themingDefaults; |
|
| 38 | - public IURLGenerator $urlGenerator; |
|
| 39 | - public ImageManager $imageManager; |
|
| 40 | - public IConfig $config; |
|
| 41 | - public IL10N $l; |
|
| 42 | - |
|
| 43 | - public string $primaryColor; |
|
| 44 | - |
|
| 45 | - public function __construct(Util $util, |
|
| 46 | - ThemingDefaults $themingDefaults, |
|
| 47 | - IURLGenerator $urlGenerator, |
|
| 48 | - ImageManager $imageManager, |
|
| 49 | - IConfig $config, |
|
| 50 | - IL10N $l) { |
|
| 51 | - $this->util = $util; |
|
| 52 | - $this->themingDefaults = $themingDefaults; |
|
| 53 | - $this->urlGenerator = $urlGenerator; |
|
| 54 | - $this->imageManager = $imageManager; |
|
| 55 | - $this->config = $config; |
|
| 56 | - $this->l = $l; |
|
| 57 | - |
|
| 58 | - $this->primaryColor = $this->themingDefaults->getColorPrimary(); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function getId(): string { |
|
| 62 | - return 'default'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getType(): int { |
|
| 66 | - return ITheme::TYPE_THEME; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getTitle(): string { |
|
| 70 | - return $this->l->t('Light theme'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function getEnableLabel(): string { |
|
| 74 | - return $this->l->t('Enable the default light theme'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function getDescription(): string { |
|
| 78 | - return $this->l->t('The default light appearance.'); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function getMediaQuery(): string { |
|
| 82 | - return ''; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getCSSVariables(): array { |
|
| 86 | - $colorMainText = '#222222'; |
|
| 87 | - $colorMainBackground = '#ffffff'; |
|
| 88 | - $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground)); |
|
| 89 | - $colorBoxShadow = $this->util->darken($colorMainBackground, 70); |
|
| 90 | - $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); |
|
| 91 | - |
|
| 92 | - $variables = [ |
|
| 93 | - '--color-main-background' => $colorMainBackground, |
|
| 94 | - '--color-main-background-rgb' => $colorMainBackgroundRGB, |
|
| 95 | - '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)', |
|
| 96 | - |
|
| 97 | - // to use like this: background-image: linear-gradient(0, var('--gradient-main-background)); |
|
| 98 | - '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%', |
|
| 99 | - |
|
| 100 | - // used for different active/hover/focus/disabled states |
|
| 101 | - '--color-background-hover' => $this->util->darken($colorMainBackground, 4), |
|
| 102 | - '--color-background-dark' => $this->util->darken($colorMainBackground, 7), |
|
| 103 | - '--color-background-darker' => $this->util->darken($colorMainBackground, 14), |
|
| 104 | - |
|
| 105 | - '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10), |
|
| 106 | - '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20), |
|
| 107 | - |
|
| 108 | - // primary related colours |
|
| 109 | - '--color-primary' => $this->primaryColor, |
|
| 110 | - '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', |
|
| 111 | - '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 80), |
|
| 112 | - '--color-primary-light' => $this->util->mix($this->primaryColor, $colorMainBackground, 10), |
|
| 113 | - '--color-primary-light-text' => $this->primaryColor, |
|
| 114 | - '--color-primary-light-hover' => $this->util->mix($this->primaryColor, $colorMainText, 10), |
|
| 115 | - '--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7), |
|
| 116 | - // used for buttons, inputs... |
|
| 117 | - '--color-primary-element' => $this->util->elementColor($this->primaryColor), |
|
| 118 | - '--color-primary-element-hover' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 80), |
|
| 119 | - '--color-primary-element-light' => $this->util->lighten($this->util->elementColor($this->primaryColor), 15), |
|
| 120 | - '--color-primary-element-lighter' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 15), |
|
| 121 | - |
|
| 122 | - // max contrast for WCAG compliance |
|
| 123 | - '--color-main-text' => $colorMainText, |
|
| 124 | - '--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33), |
|
| 125 | - '--color-text-light' => $colorMainText, |
|
| 126 | - '--color-text-lighter' => $this->util->lighten($colorMainText, 33), |
|
| 127 | - |
|
| 128 | - // info/warning/success feedback colours |
|
| 129 | - '--color-error' => '#e9322d', |
|
| 130 | - '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 80), |
|
| 131 | - '--color-warning' => '#eca700', |
|
| 132 | - '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 80), |
|
| 133 | - '--color-success' => '#46ba61', |
|
| 134 | - '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 80), |
|
| 135 | - |
|
| 136 | - // used for the icon loading animation |
|
| 137 | - '--color-loading-light' => '#cccccc', |
|
| 138 | - '--color-loading-dark' => '#444444', |
|
| 139 | - |
|
| 140 | - '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
|
| 141 | - '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)", |
|
| 142 | - |
|
| 143 | - '--color-border' => $this->util->darken($colorMainBackground, 7), |
|
| 144 | - '--color-border-dark' => $this->util->darken($colorMainBackground, 14), |
|
| 145 | - |
|
| 146 | - '--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", |
|
| 147 | - '--default-font-size' => '15px', |
|
| 148 | - |
|
| 149 | - // TODO: support "(prefers-reduced-motion)" |
|
| 150 | - '--animation-quick' => '100ms', |
|
| 151 | - '--animation-slow' => '300ms', |
|
| 152 | - |
|
| 153 | - // Default variables -------------------------------------------- |
|
| 154 | - '--border-radius' => '3px', |
|
| 155 | - '--border-radius-large' => '10px', |
|
| 156 | - // pill-style button, value is large so big buttons also have correct roundness |
|
| 157 | - '--border-radius-pill' => '100px', |
|
| 158 | - |
|
| 159 | - '--default-line-height' => '24px', |
|
| 160 | - |
|
| 161 | - // various structure data |
|
| 162 | - '--header-height' => '50px', |
|
| 163 | - '--navigation-width' => '300px', |
|
| 164 | - '--sidebar-min-width' => '300px', |
|
| 165 | - '--sidebar-max-width' => '500px', |
|
| 166 | - '--list-min-width' => '200px', |
|
| 167 | - '--list-max-width' => '300px', |
|
| 168 | - '--header-menu-item-height' => '44px', |
|
| 169 | - '--header-menu-profile-item-height' => '66px', |
|
| 170 | - |
|
| 171 | - // mobile. Keep in sync with core/js/js.js |
|
| 172 | - '--breakpoint-mobile' => '1024px', |
|
| 173 | - |
|
| 174 | - // invert filter if primary is too bright |
|
| 175 | - // to be used for legacy reasons only. Use inline |
|
| 176 | - // svg with proper css variable instead or material |
|
| 177 | - // design icons. |
|
| 178 | - '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'unset', |
|
| 179 | - '--background-invert-if-dark' => 'unset', |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - // Register image variables only if custom-defined |
|
| 183 | - $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor'; |
|
| 184 | - foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) { |
|
| 185 | - if ($this->imageManager->hasImage($image)) { |
|
| 186 | - // If primary as background has been request, let's not define the background image |
|
| 187 | - if ($image === 'background' && $backgroundDeleted) { |
|
| 188 | - $variables["--image-background-plain"] = true; |
|
| 189 | - continue; |
|
| 190 | - } else if ($image === 'background') { |
|
| 191 | - $variables['--image-background-size'] = 'cover'; |
|
| 192 | - } |
|
| 193 | - $variables["--image-$image"] = "url('".$this->imageManager->getImageUrl($image)."')"; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $variables; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - public function getCustomCss(): string { |
|
| 201 | - return ''; |
|
| 202 | - } |
|
| 36 | + public Util $util; |
|
| 37 | + public ThemingDefaults $themingDefaults; |
|
| 38 | + public IURLGenerator $urlGenerator; |
|
| 39 | + public ImageManager $imageManager; |
|
| 40 | + public IConfig $config; |
|
| 41 | + public IL10N $l; |
|
| 42 | + |
|
| 43 | + public string $primaryColor; |
|
| 44 | + |
|
| 45 | + public function __construct(Util $util, |
|
| 46 | + ThemingDefaults $themingDefaults, |
|
| 47 | + IURLGenerator $urlGenerator, |
|
| 48 | + ImageManager $imageManager, |
|
| 49 | + IConfig $config, |
|
| 50 | + IL10N $l) { |
|
| 51 | + $this->util = $util; |
|
| 52 | + $this->themingDefaults = $themingDefaults; |
|
| 53 | + $this->urlGenerator = $urlGenerator; |
|
| 54 | + $this->imageManager = $imageManager; |
|
| 55 | + $this->config = $config; |
|
| 56 | + $this->l = $l; |
|
| 57 | + |
|
| 58 | + $this->primaryColor = $this->themingDefaults->getColorPrimary(); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function getId(): string { |
|
| 62 | + return 'default'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getType(): int { |
|
| 66 | + return ITheme::TYPE_THEME; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getTitle(): string { |
|
| 70 | + return $this->l->t('Light theme'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function getEnableLabel(): string { |
|
| 74 | + return $this->l->t('Enable the default light theme'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function getDescription(): string { |
|
| 78 | + return $this->l->t('The default light appearance.'); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function getMediaQuery(): string { |
|
| 82 | + return ''; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getCSSVariables(): array { |
|
| 86 | + $colorMainText = '#222222'; |
|
| 87 | + $colorMainBackground = '#ffffff'; |
|
| 88 | + $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground)); |
|
| 89 | + $colorBoxShadow = $this->util->darken($colorMainBackground, 70); |
|
| 90 | + $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); |
|
| 91 | + |
|
| 92 | + $variables = [ |
|
| 93 | + '--color-main-background' => $colorMainBackground, |
|
| 94 | + '--color-main-background-rgb' => $colorMainBackgroundRGB, |
|
| 95 | + '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)', |
|
| 96 | + |
|
| 97 | + // to use like this: background-image: linear-gradient(0, var('--gradient-main-background)); |
|
| 98 | + '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%', |
|
| 99 | + |
|
| 100 | + // used for different active/hover/focus/disabled states |
|
| 101 | + '--color-background-hover' => $this->util->darken($colorMainBackground, 4), |
|
| 102 | + '--color-background-dark' => $this->util->darken($colorMainBackground, 7), |
|
| 103 | + '--color-background-darker' => $this->util->darken($colorMainBackground, 14), |
|
| 104 | + |
|
| 105 | + '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10), |
|
| 106 | + '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20), |
|
| 107 | + |
|
| 108 | + // primary related colours |
|
| 109 | + '--color-primary' => $this->primaryColor, |
|
| 110 | + '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', |
|
| 111 | + '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 80), |
|
| 112 | + '--color-primary-light' => $this->util->mix($this->primaryColor, $colorMainBackground, 10), |
|
| 113 | + '--color-primary-light-text' => $this->primaryColor, |
|
| 114 | + '--color-primary-light-hover' => $this->util->mix($this->primaryColor, $colorMainText, 10), |
|
| 115 | + '--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7), |
|
| 116 | + // used for buttons, inputs... |
|
| 117 | + '--color-primary-element' => $this->util->elementColor($this->primaryColor), |
|
| 118 | + '--color-primary-element-hover' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 80), |
|
| 119 | + '--color-primary-element-light' => $this->util->lighten($this->util->elementColor($this->primaryColor), 15), |
|
| 120 | + '--color-primary-element-lighter' => $this->util->mix($this->util->elementColor($this->primaryColor), $colorMainBackground, 15), |
|
| 121 | + |
|
| 122 | + // max contrast for WCAG compliance |
|
| 123 | + '--color-main-text' => $colorMainText, |
|
| 124 | + '--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33), |
|
| 125 | + '--color-text-light' => $colorMainText, |
|
| 126 | + '--color-text-lighter' => $this->util->lighten($colorMainText, 33), |
|
| 127 | + |
|
| 128 | + // info/warning/success feedback colours |
|
| 129 | + '--color-error' => '#e9322d', |
|
| 130 | + '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 80), |
|
| 131 | + '--color-warning' => '#eca700', |
|
| 132 | + '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 80), |
|
| 133 | + '--color-success' => '#46ba61', |
|
| 134 | + '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 80), |
|
| 135 | + |
|
| 136 | + // used for the icon loading animation |
|
| 137 | + '--color-loading-light' => '#cccccc', |
|
| 138 | + '--color-loading-dark' => '#444444', |
|
| 139 | + |
|
| 140 | + '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
|
| 141 | + '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)", |
|
| 142 | + |
|
| 143 | + '--color-border' => $this->util->darken($colorMainBackground, 7), |
|
| 144 | + '--color-border-dark' => $this->util->darken($colorMainBackground, 14), |
|
| 145 | + |
|
| 146 | + '--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'", |
|
| 147 | + '--default-font-size' => '15px', |
|
| 148 | + |
|
| 149 | + // TODO: support "(prefers-reduced-motion)" |
|
| 150 | + '--animation-quick' => '100ms', |
|
| 151 | + '--animation-slow' => '300ms', |
|
| 152 | + |
|
| 153 | + // Default variables -------------------------------------------- |
|
| 154 | + '--border-radius' => '3px', |
|
| 155 | + '--border-radius-large' => '10px', |
|
| 156 | + // pill-style button, value is large so big buttons also have correct roundness |
|
| 157 | + '--border-radius-pill' => '100px', |
|
| 158 | + |
|
| 159 | + '--default-line-height' => '24px', |
|
| 160 | + |
|
| 161 | + // various structure data |
|
| 162 | + '--header-height' => '50px', |
|
| 163 | + '--navigation-width' => '300px', |
|
| 164 | + '--sidebar-min-width' => '300px', |
|
| 165 | + '--sidebar-max-width' => '500px', |
|
| 166 | + '--list-min-width' => '200px', |
|
| 167 | + '--list-max-width' => '300px', |
|
| 168 | + '--header-menu-item-height' => '44px', |
|
| 169 | + '--header-menu-profile-item-height' => '66px', |
|
| 170 | + |
|
| 171 | + // mobile. Keep in sync with core/js/js.js |
|
| 172 | + '--breakpoint-mobile' => '1024px', |
|
| 173 | + |
|
| 174 | + // invert filter if primary is too bright |
|
| 175 | + // to be used for legacy reasons only. Use inline |
|
| 176 | + // svg with proper css variable instead or material |
|
| 177 | + // design icons. |
|
| 178 | + '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'unset', |
|
| 179 | + '--background-invert-if-dark' => 'unset', |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + // Register image variables only if custom-defined |
|
| 183 | + $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor'; |
|
| 184 | + foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) { |
|
| 185 | + if ($this->imageManager->hasImage($image)) { |
|
| 186 | + // If primary as background has been request, let's not define the background image |
|
| 187 | + if ($image === 'background' && $backgroundDeleted) { |
|
| 188 | + $variables["--image-background-plain"] = true; |
|
| 189 | + continue; |
|
| 190 | + } else if ($image === 'background') { |
|
| 191 | + $variables['--image-background-size'] = 'cover'; |
|
| 192 | + } |
|
| 193 | + $variables["--image-$image"] = "url('".$this->imageManager->getImageUrl($image)."')"; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $variables; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + public function getCustomCss(): string { |
|
| 201 | + return ''; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -181,7 +181,7 @@ |
||
| 181 | 181 | |
| 182 | 182 | // Register image variables only if custom-defined |
| 183 | 183 | $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor'; |
| 184 | - foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) { |
|
| 184 | + foreach (['logo', 'logoheader', 'favicon', 'background'] as $image) { |
|
| 185 | 185 | if ($this->imageManager->hasImage($image)) { |
| 186 | 186 | // If primary as background has been request, let's not define the background image |
| 187 | 187 | if ($image === 'background' && $backgroundDeleted) { |
@@ -28,39 +28,39 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class DyslexiaFont extends DefaultTheme implements ITheme { |
| 30 | 30 | |
| 31 | - public function getId(): string { |
|
| 32 | - return 'opendyslexic'; |
|
| 33 | - } |
|
| 31 | + public function getId(): string { |
|
| 32 | + return 'opendyslexic'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function getType(): int { |
|
| 36 | - return ITheme::TYPE_FONT; |
|
| 37 | - } |
|
| 35 | + public function getType(): int { |
|
| 36 | + return ITheme::TYPE_FONT; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getTitle(): string { |
|
| 40 | - return $this->l->t('Dyslexia font'); |
|
| 41 | - } |
|
| 39 | + public function getTitle(): string { |
|
| 40 | + return $this->l->t('Dyslexia font'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getEnableLabel(): string { |
|
| 44 | - return $this->l->t('Enable dyslexia font'); |
|
| 45 | - } |
|
| 43 | + public function getEnableLabel(): string { |
|
| 44 | + return $this->l->t('Enable dyslexia font'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getDescription(): string { |
|
| 48 | - return $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.'); |
|
| 49 | - } |
|
| 47 | + public function getDescription(): string { |
|
| 48 | + return $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia.'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getCSSVariables(): array { |
|
| 52 | - $variables = parent::getCSSVariables(); |
|
| 53 | - $originalFontFace = $variables['--font-face']; |
|
| 51 | + public function getCSSVariables(): array { |
|
| 52 | + $variables = parent::getCSSVariables(); |
|
| 53 | + $originalFontFace = $variables['--font-face']; |
|
| 54 | 54 | |
| 55 | - $variables = [ |
|
| 56 | - '--font-face' => 'OpenDyslexic, ' . $originalFontFace |
|
| 57 | - ]; |
|
| 55 | + $variables = [ |
|
| 56 | + '--font-face' => 'OpenDyslexic, ' . $originalFontFace |
|
| 57 | + ]; |
|
| 58 | 58 | |
| 59 | - return $variables; |
|
| 60 | - } |
|
| 59 | + return $variables; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getCustomCss(): string { |
|
| 63 | - return " |
|
| 62 | + public function getCustomCss(): string { |
|
| 63 | + return " |
|
| 64 | 64 | @font-face { |
| 65 | 65 | font-family: 'OpenDyslexic'; |
| 66 | 66 | font-style: normal; |
@@ -79,6 +79,6 @@ discard block |
||
| 79 | 79 | url('../fonts/OpenDyslexic-Bold.ttf') format('truetype'); |
| 80 | 80 | } |
| 81 | 81 | "; |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | $originalFontFace = $variables['--font-face']; |
| 54 | 54 | |
| 55 | 55 | $variables = [ |
| 56 | - '--font-face' => 'OpenDyslexic, ' . $originalFontFace |
|
| 56 | + '--font-face' => 'OpenDyslexic, '.$originalFontFace |
|
| 57 | 57 | ]; |
| 58 | 58 | |
| 59 | 59 | return $variables; |
@@ -28,65 +28,65 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class DarkHighContrastTheme extends DarkTheme implements ITheme { |
| 30 | 30 | |
| 31 | - public function getId(): string { |
|
| 32 | - return 'dark-highcontrast'; |
|
| 33 | - } |
|
| 31 | + public function getId(): string { |
|
| 32 | + return 'dark-highcontrast'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function getMediaQuery(): string { |
|
| 36 | - return '(prefers-color-scheme: dark) and (prefers-contrast: more)'; |
|
| 37 | - } |
|
| 35 | + public function getMediaQuery(): string { |
|
| 36 | + return '(prefers-color-scheme: dark) and (prefers-contrast: more)'; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getTitle(): string { |
|
| 40 | - return $this->l->t('Dark theme with high contrast mode'); |
|
| 41 | - } |
|
| 39 | + public function getTitle(): string { |
|
| 40 | + return $this->l->t('Dark theme with high contrast mode'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getEnableLabel(): string { |
|
| 44 | - return $this->l->t('Enable dark high contrast mode'); |
|
| 45 | - } |
|
| 43 | + public function getEnableLabel(): string { |
|
| 44 | + return $this->l->t('Enable dark high contrast mode'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getDescription(): string { |
|
| 48 | - return $this->l->t('Similar to the high contrast mode, but with dark colours.'); |
|
| 49 | - } |
|
| 47 | + public function getDescription(): string { |
|
| 48 | + return $this->l->t('Similar to the high contrast mode, but with dark colours.'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Try to keep this consistent with HighContrastTheme |
|
| 53 | - */ |
|
| 54 | - public function getCSSVariables(): array { |
|
| 55 | - $variables = parent::getCSSVariables(); |
|
| 56 | - $colorMainText = '#ffffff'; |
|
| 57 | - $colorMainBackground = '#000000'; |
|
| 58 | - $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorMainText)); |
|
| 51 | + /** |
|
| 52 | + * Try to keep this consistent with HighContrastTheme |
|
| 53 | + */ |
|
| 54 | + public function getCSSVariables(): array { |
|
| 55 | + $variables = parent::getCSSVariables(); |
|
| 56 | + $colorMainText = '#ffffff'; |
|
| 57 | + $colorMainBackground = '#000000'; |
|
| 58 | + $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorMainText)); |
|
| 59 | 59 | |
| 60 | - $variables['--color-main-background'] = $colorMainBackground; |
|
| 61 | - $variables['--color-main-text'] = $colorMainText; |
|
| 60 | + $variables['--color-main-background'] = $colorMainBackground; |
|
| 61 | + $variables['--color-main-text'] = $colorMainText; |
|
| 62 | 62 | |
| 63 | - $variables['--color-background-dark'] = $this->util->lighten($colorMainBackground, 30); |
|
| 64 | - $variables['--color-background-darker'] = $this->util->lighten($colorMainBackground, 30); |
|
| 63 | + $variables['--color-background-dark'] = $this->util->lighten($colorMainBackground, 30); |
|
| 64 | + $variables['--color-background-darker'] = $this->util->lighten($colorMainBackground, 30); |
|
| 65 | 65 | |
| 66 | - $variables['--color-placeholder-light'] = $this->util->lighten($colorMainBackground, 30); |
|
| 67 | - $variables['--color-placeholder-dark'] = $this->util->lighten($colorMainBackground, 45); |
|
| 66 | + $variables['--color-placeholder-light'] = $this->util->lighten($colorMainBackground, 30); |
|
| 67 | + $variables['--color-placeholder-dark'] = $this->util->lighten($colorMainBackground, 45); |
|
| 68 | 68 | |
| 69 | - $variables['--color-text-maxcontrast'] = $colorMainText; |
|
| 70 | - $variables['--color-text-light'] = $colorMainText; |
|
| 71 | - $variables['--color-text-lighter'] = $colorMainText; |
|
| 69 | + $variables['--color-text-maxcontrast'] = $colorMainText; |
|
| 70 | + $variables['--color-text-light'] = $colorMainText; |
|
| 71 | + $variables['--color-text-lighter'] = $colorMainText; |
|
| 72 | 72 | |
| 73 | - // used for the icon loading animation |
|
| 74 | - $variables['--color-loading-light'] = '#000000'; |
|
| 75 | - $variables['--color-loading-dark'] = '#dddddd'; |
|
| 73 | + // used for the icon loading animation |
|
| 74 | + $variables['--color-loading-light'] = '#000000'; |
|
| 75 | + $variables['--color-loading-dark'] = '#dddddd'; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - $variables['--color-box-shadow-rgb'] = $colorBoxShadowRGB; |
|
| 79 | - $variables['--color-box-shadow'] = $colorBoxShadowRGB; |
|
| 78 | + $variables['--color-box-shadow-rgb'] = $colorBoxShadowRGB; |
|
| 79 | + $variables['--color-box-shadow'] = $colorBoxShadowRGB; |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - $variables['--color-border'] = $this->util->lighten($colorMainBackground, 50); |
|
| 83 | - $variables['--color-border-dark'] = $this->util->lighten($colorMainBackground, 50); |
|
| 82 | + $variables['--color-border'] = $this->util->lighten($colorMainBackground, 50); |
|
| 83 | + $variables['--color-border-dark'] = $this->util->lighten($colorMainBackground, 50); |
|
| 84 | 84 | |
| 85 | - return $variables; |
|
| 86 | - } |
|
| 85 | + return $variables; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function getCustomCss(): string { |
|
| 89 | - return " |
|
| 88 | + public function getCustomCss(): string { |
|
| 89 | + return " |
|
| 90 | 90 | [class^='icon-'], [class*=' icon-'], |
| 91 | 91 | .action, |
| 92 | 92 | #appmenu li a, |
@@ -94,5 +94,5 @@ discard block |
||
| 94 | 94 | opacity: 1 !important; |
| 95 | 95 | } |
| 96 | 96 | "; |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -28,58 +28,58 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class HighContrastTheme extends DefaultTheme implements ITheme { |
| 30 | 30 | |
| 31 | - public function getId(): string { |
|
| 32 | - return 'highcontrast'; |
|
| 33 | - } |
|
| 31 | + public function getId(): string { |
|
| 32 | + return 'highcontrast'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function getMediaQuery(): string { |
|
| 36 | - return '(prefers-contrast: more)'; |
|
| 37 | - } |
|
| 35 | + public function getMediaQuery(): string { |
|
| 36 | + return '(prefers-contrast: more)'; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getTitle(): string { |
|
| 40 | - return $this->l->t('High contrast mode'); |
|
| 41 | - } |
|
| 39 | + public function getTitle(): string { |
|
| 40 | + return $this->l->t('High contrast mode'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getEnableLabel(): string { |
|
| 44 | - return $this->l->t('Enable high contrast mode'); |
|
| 45 | - } |
|
| 43 | + public function getEnableLabel(): string { |
|
| 44 | + return $this->l->t('Enable high contrast mode'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getDescription(): string { |
|
| 48 | - return $this->l->t('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.'); |
|
| 49 | - } |
|
| 47 | + public function getDescription(): string { |
|
| 48 | + return $this->l->t('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getCSSVariables(): array { |
|
| 52 | - $variables = parent::getCSSVariables(); |
|
| 53 | - $colorMainText = '#000000'; |
|
| 54 | - $colorMainBackground = '#ffffff'; |
|
| 51 | + public function getCSSVariables(): array { |
|
| 52 | + $variables = parent::getCSSVariables(); |
|
| 53 | + $colorMainText = '#000000'; |
|
| 54 | + $colorMainBackground = '#ffffff'; |
|
| 55 | 55 | |
| 56 | - $variables['--color-main-background'] = $colorMainBackground; |
|
| 57 | - $variables['--color-main-text'] = $colorMainText; |
|
| 56 | + $variables['--color-main-background'] = $colorMainBackground; |
|
| 57 | + $variables['--color-main-text'] = $colorMainText; |
|
| 58 | 58 | |
| 59 | - $variables['--color-background-dark'] = $this->util->darken($colorMainBackground, 30); |
|
| 60 | - $variables['--color-background-darker'] = $this->util->darken($colorMainBackground, 30); |
|
| 59 | + $variables['--color-background-dark'] = $this->util->darken($colorMainBackground, 30); |
|
| 60 | + $variables['--color-background-darker'] = $this->util->darken($colorMainBackground, 30); |
|
| 61 | 61 | |
| 62 | - $variables['--color-placeholder-light'] = $this->util->darken($colorMainBackground, 30); |
|
| 63 | - $variables['--color-placeholder-dark'] = $this->util->darken($colorMainBackground, 45); |
|
| 62 | + $variables['--color-placeholder-light'] = $this->util->darken($colorMainBackground, 30); |
|
| 63 | + $variables['--color-placeholder-dark'] = $this->util->darken($colorMainBackground, 45); |
|
| 64 | 64 | |
| 65 | - $variables['--color-text-maxcontrast'] = 'var(--color-main-text)'; |
|
| 66 | - $variables['--color-text-light'] = 'var(--color-main-text)'; |
|
| 67 | - $variables['--color-text-lighter'] = 'var(--color-main-text)'; |
|
| 65 | + $variables['--color-text-maxcontrast'] = 'var(--color-main-text)'; |
|
| 66 | + $variables['--color-text-light'] = 'var(--color-main-text)'; |
|
| 67 | + $variables['--color-text-lighter'] = 'var(--color-main-text)'; |
|
| 68 | 68 | |
| 69 | - // used for the icon loading animation |
|
| 70 | - $variables['--color-loading-light'] = '#dddddd'; |
|
| 71 | - $variables['--color-loading-dark'] = '#000000'; |
|
| 69 | + // used for the icon loading animation |
|
| 70 | + $variables['--color-loading-light'] = '#dddddd'; |
|
| 71 | + $variables['--color-loading-dark'] = '#000000'; |
|
| 72 | 72 | |
| 73 | - $variables['--color-box-shadow'] = 'var(--color-main-text)'; |
|
| 73 | + $variables['--color-box-shadow'] = 'var(--color-main-text)'; |
|
| 74 | 74 | |
| 75 | - $variables['--color-border'] = $this->util->darken($colorMainBackground, 50); |
|
| 76 | - $variables['--color-border-dark'] = $this->util->darken($colorMainBackground, 50); |
|
| 75 | + $variables['--color-border'] = $this->util->darken($colorMainBackground, 50); |
|
| 76 | + $variables['--color-border-dark'] = $this->util->darken($colorMainBackground, 50); |
|
| 77 | 77 | |
| 78 | - return $variables; |
|
| 79 | - } |
|
| 78 | + return $variables; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function getCustomCss(): string { |
|
| 82 | - return " |
|
| 81 | + public function getCustomCss(): string { |
|
| 82 | + return " |
|
| 83 | 83 | [class^='icon-'], [class*=' icon-'], |
| 84 | 84 | .action, |
| 85 | 85 | #appmenu li a, |
@@ -87,5 +87,5 @@ discard block |
||
| 87 | 87 | opacity: 1 !important; |
| 88 | 88 | } |
| 89 | 89 | "; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -28,60 +28,60 @@ |
||
| 28 | 28 | |
| 29 | 29 | class DarkTheme extends DefaultTheme implements ITheme { |
| 30 | 30 | |
| 31 | - public function getId(): string { |
|
| 32 | - return 'dark'; |
|
| 33 | - } |
|
| 31 | + public function getId(): string { |
|
| 32 | + return 'dark'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function getMediaQuery(): string { |
|
| 36 | - return '(prefers-color-scheme: dark)'; |
|
| 37 | - } |
|
| 35 | + public function getMediaQuery(): string { |
|
| 36 | + return '(prefers-color-scheme: dark)'; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getTitle(): string { |
|
| 40 | - return $this->l->t('Dark theme'); |
|
| 41 | - } |
|
| 39 | + public function getTitle(): string { |
|
| 40 | + return $this->l->t('Dark theme'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getEnableLabel(): string { |
|
| 44 | - return $this->l->t('Enable dark theme'); |
|
| 45 | - } |
|
| 43 | + public function getEnableLabel(): string { |
|
| 44 | + return $this->l->t('Enable dark theme'); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getDescription(): string { |
|
| 48 | - return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness. It is still under development, so please report any issues you may find.'); |
|
| 49 | - } |
|
| 47 | + public function getDescription(): string { |
|
| 48 | + return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness. It is still under development, so please report any issues you may find.'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getCSSVariables(): array { |
|
| 52 | - $defaultVariables = parent::getCSSVariables(); |
|
| 51 | + public function getCSSVariables(): array { |
|
| 52 | + $defaultVariables = parent::getCSSVariables(); |
|
| 53 | 53 | |
| 54 | - $colorMainText = '#D8D8D8'; |
|
| 55 | - $colorMainBackground = '#171717'; |
|
| 56 | - $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground)); |
|
| 57 | - $colorBoxShadow = $this->util->darken($colorMainBackground, 70); |
|
| 58 | - $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); |
|
| 54 | + $colorMainText = '#D8D8D8'; |
|
| 55 | + $colorMainBackground = '#171717'; |
|
| 56 | + $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground)); |
|
| 57 | + $colorBoxShadow = $this->util->darken($colorMainBackground, 70); |
|
| 58 | + $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); |
|
| 59 | 59 | |
| 60 | - return array_merge($defaultVariables, [ |
|
| 61 | - '--color-main-text' => $colorMainText, |
|
| 62 | - '--color-main-background' => $colorMainBackground, |
|
| 63 | - '--color-main-background-rgb' => $colorMainBackgroundRGB, |
|
| 60 | + return array_merge($defaultVariables, [ |
|
| 61 | + '--color-main-text' => $colorMainText, |
|
| 62 | + '--color-main-background' => $colorMainBackground, |
|
| 63 | + '--color-main-background-rgb' => $colorMainBackgroundRGB, |
|
| 64 | 64 | |
| 65 | - '--color-background-hover' => $this->util->lighten($colorMainBackground, 4), |
|
| 66 | - '--color-background-dark' => $this->util->lighten($colorMainBackground, 7), |
|
| 67 | - '--color-background-darker' => $this->util->lighten($colorMainBackground, 14), |
|
| 65 | + '--color-background-hover' => $this->util->lighten($colorMainBackground, 4), |
|
| 66 | + '--color-background-dark' => $this->util->lighten($colorMainBackground, 7), |
|
| 67 | + '--color-background-darker' => $this->util->lighten($colorMainBackground, 14), |
|
| 68 | 68 | |
| 69 | - '--color-placeholder-light' => $this->util->lighten($colorMainBackground, 10), |
|
| 70 | - '--color-placeholder-dark' => $this->util->lighten($colorMainBackground, 20), |
|
| 69 | + '--color-placeholder-light' => $this->util->lighten($colorMainBackground, 10), |
|
| 70 | + '--color-placeholder-dark' => $this->util->lighten($colorMainBackground, 20), |
|
| 71 | 71 | |
| 72 | - '--color-text-maxcontrast' => $this->util->darken($colorMainText, 30), |
|
| 73 | - '--color-text-light' => $this->util->darken($colorMainText, 10), |
|
| 74 | - '--color-text-lighter' => $this->util->darken($colorMainText, 20), |
|
| 72 | + '--color-text-maxcontrast' => $this->util->darken($colorMainText, 30), |
|
| 73 | + '--color-text-light' => $this->util->darken($colorMainText, 10), |
|
| 74 | + '--color-text-lighter' => $this->util->darken($colorMainText, 20), |
|
| 75 | 75 | |
| 76 | - '--color-loading-light' => '#777', |
|
| 77 | - '--color-loading-dark' => '#CCC', |
|
| 76 | + '--color-loading-light' => '#777', |
|
| 77 | + '--color-loading-dark' => '#CCC', |
|
| 78 | 78 | |
| 79 | - '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
|
| 79 | + '--color-box-shadow-rgb' => $colorBoxShadowRGB, |
|
| 80 | 80 | |
| 81 | - '--color-border' => $this->util->lighten($colorMainBackground, 7), |
|
| 82 | - '--color-border-dark' => $this->util->lighten($colorMainBackground, 14), |
|
| 81 | + '--color-border' => $this->util->lighten($colorMainBackground, 7), |
|
| 82 | + '--color-border-dark' => $this->util->lighten($colorMainBackground, 14), |
|
| 83 | 83 | |
| 84 | - '--background-invert-if-dark' => 'invert(100%)', |
|
| 85 | - ]); |
|
| 86 | - } |
|
| 84 | + '--background-invert-if-dark' => 'invert(100%)', |
|
| 85 | + ]); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -34,139 +34,139 @@ |
||
| 34 | 34 | use OCP\IUserSession; |
| 35 | 35 | |
| 36 | 36 | class ThemesService { |
| 37 | - private IUserSession $userSession; |
|
| 38 | - private IConfig $config; |
|
| 39 | - |
|
| 40 | - /** @var ITheme[] */ |
|
| 41 | - private array $themesProviders; |
|
| 42 | - |
|
| 43 | - public function __construct(IUserSession $userSession, |
|
| 44 | - IConfig $config, |
|
| 45 | - DefaultTheme $defaultTheme, |
|
| 46 | - DarkTheme $darkTheme, |
|
| 47 | - HighContrastTheme $highContrastTheme, |
|
| 48 | - DarkHighContrastTheme $darkHighContrastTheme, |
|
| 49 | - DyslexiaFont $dyslexiaFont) { |
|
| 50 | - $this->userSession = $userSession; |
|
| 51 | - $this->config = $config; |
|
| 52 | - |
|
| 53 | - // Register themes |
|
| 54 | - $this->themesProviders = [ |
|
| 55 | - $defaultTheme->getId() => $defaultTheme, |
|
| 56 | - $darkTheme->getId() => $darkTheme, |
|
| 57 | - $highContrastTheme->getId() => $highContrastTheme, |
|
| 58 | - $darkHighContrastTheme->getId() => $darkHighContrastTheme, |
|
| 59 | - $dyslexiaFont->getId() => $dyslexiaFont, |
|
| 60 | - ]; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get the list of all registered themes |
|
| 65 | - * |
|
| 66 | - * @return ITheme[] |
|
| 67 | - */ |
|
| 68 | - public function getThemes(): array { |
|
| 69 | - return $this->themesProviders; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Enable a theme for the logged-in user |
|
| 74 | - * |
|
| 75 | - * @param ITheme $theme the theme to enable |
|
| 76 | - * @return string[] the enabled themes |
|
| 77 | - */ |
|
| 78 | - public function enableTheme(ITheme $theme): array { |
|
| 79 | - $themesIds = $this->getEnabledThemes(); |
|
| 80 | - |
|
| 81 | - // If already enabled, ignore |
|
| 82 | - if (in_array($theme->getId(), $themesIds)) { |
|
| 83 | - return $themesIds; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** @var ITheme[] */ |
|
| 87 | - $themes = array_map(function($themeId) { |
|
| 88 | - return $this->getThemes()[$themeId]; |
|
| 89 | - }, $themesIds); |
|
| 90 | - |
|
| 91 | - // Filtering all themes with the same type |
|
| 92 | - $filteredThemes = array_filter($themes, function(ITheme $t) use ($theme) { |
|
| 93 | - return $theme->getType() === $t->getType(); |
|
| 94 | - }); |
|
| 95 | - |
|
| 96 | - // Retrieve IDs only |
|
| 97 | - /** @var string[] */ |
|
| 98 | - $filteredThemesIds = array_map(function(ITheme $t) { |
|
| 99 | - return $t->getId(); |
|
| 100 | - }, array_values($filteredThemes)); |
|
| 101 | - |
|
| 102 | - $enabledThemes = array_merge(array_diff($themesIds, $filteredThemesIds), [$theme->getId()]); |
|
| 103 | - $this->setEnabledThemes($enabledThemes); |
|
| 104 | - |
|
| 105 | - return $enabledThemes; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Disable a theme for the logged-in user |
|
| 110 | - * |
|
| 111 | - * @param ITheme $theme the theme to disable |
|
| 112 | - * @return string[] the enabled themes |
|
| 113 | - */ |
|
| 114 | - public function disableTheme(ITheme $theme): array { |
|
| 115 | - $themesIds = $this->getEnabledThemes(); |
|
| 116 | - |
|
| 117 | - // If enabled, removing it |
|
| 118 | - if (in_array($theme->getId(), $themesIds)) { |
|
| 119 | - $enabledThemes = array_diff($themesIds, [$theme->getId()]); |
|
| 120 | - $this->setEnabledThemes($enabledThemes); |
|
| 121 | - return $enabledThemes; |
|
| 122 | - } |
|
| 37 | + private IUserSession $userSession; |
|
| 38 | + private IConfig $config; |
|
| 39 | + |
|
| 40 | + /** @var ITheme[] */ |
|
| 41 | + private array $themesProviders; |
|
| 42 | + |
|
| 43 | + public function __construct(IUserSession $userSession, |
|
| 44 | + IConfig $config, |
|
| 45 | + DefaultTheme $defaultTheme, |
|
| 46 | + DarkTheme $darkTheme, |
|
| 47 | + HighContrastTheme $highContrastTheme, |
|
| 48 | + DarkHighContrastTheme $darkHighContrastTheme, |
|
| 49 | + DyslexiaFont $dyslexiaFont) { |
|
| 50 | + $this->userSession = $userSession; |
|
| 51 | + $this->config = $config; |
|
| 52 | + |
|
| 53 | + // Register themes |
|
| 54 | + $this->themesProviders = [ |
|
| 55 | + $defaultTheme->getId() => $defaultTheme, |
|
| 56 | + $darkTheme->getId() => $darkTheme, |
|
| 57 | + $highContrastTheme->getId() => $highContrastTheme, |
|
| 58 | + $darkHighContrastTheme->getId() => $darkHighContrastTheme, |
|
| 59 | + $dyslexiaFont->getId() => $dyslexiaFont, |
|
| 60 | + ]; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get the list of all registered themes |
|
| 65 | + * |
|
| 66 | + * @return ITheme[] |
|
| 67 | + */ |
|
| 68 | + public function getThemes(): array { |
|
| 69 | + return $this->themesProviders; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Enable a theme for the logged-in user |
|
| 74 | + * |
|
| 75 | + * @param ITheme $theme the theme to enable |
|
| 76 | + * @return string[] the enabled themes |
|
| 77 | + */ |
|
| 78 | + public function enableTheme(ITheme $theme): array { |
|
| 79 | + $themesIds = $this->getEnabledThemes(); |
|
| 80 | + |
|
| 81 | + // If already enabled, ignore |
|
| 82 | + if (in_array($theme->getId(), $themesIds)) { |
|
| 83 | + return $themesIds; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** @var ITheme[] */ |
|
| 87 | + $themes = array_map(function($themeId) { |
|
| 88 | + return $this->getThemes()[$themeId]; |
|
| 89 | + }, $themesIds); |
|
| 90 | + |
|
| 91 | + // Filtering all themes with the same type |
|
| 92 | + $filteredThemes = array_filter($themes, function(ITheme $t) use ($theme) { |
|
| 93 | + return $theme->getType() === $t->getType(); |
|
| 94 | + }); |
|
| 95 | + |
|
| 96 | + // Retrieve IDs only |
|
| 97 | + /** @var string[] */ |
|
| 98 | + $filteredThemesIds = array_map(function(ITheme $t) { |
|
| 99 | + return $t->getId(); |
|
| 100 | + }, array_values($filteredThemes)); |
|
| 101 | + |
|
| 102 | + $enabledThemes = array_merge(array_diff($themesIds, $filteredThemesIds), [$theme->getId()]); |
|
| 103 | + $this->setEnabledThemes($enabledThemes); |
|
| 104 | + |
|
| 105 | + return $enabledThemes; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Disable a theme for the logged-in user |
|
| 110 | + * |
|
| 111 | + * @param ITheme $theme the theme to disable |
|
| 112 | + * @return string[] the enabled themes |
|
| 113 | + */ |
|
| 114 | + public function disableTheme(ITheme $theme): array { |
|
| 115 | + $themesIds = $this->getEnabledThemes(); |
|
| 116 | + |
|
| 117 | + // If enabled, removing it |
|
| 118 | + if (in_array($theme->getId(), $themesIds)) { |
|
| 119 | + $enabledThemes = array_diff($themesIds, [$theme->getId()]); |
|
| 120 | + $this->setEnabledThemes($enabledThemes); |
|
| 121 | + return $enabledThemes; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - return $themesIds; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Check whether a theme is enabled or not |
|
| 129 | - * for the logged-in user |
|
| 130 | - * |
|
| 131 | - * @return bool |
|
| 132 | - */ |
|
| 133 | - public function isEnabled(ITheme $theme): bool { |
|
| 134 | - $user = $this->userSession->getUser(); |
|
| 135 | - if ($user instanceof IUser) { |
|
| 136 | - // Using keys as it's faster |
|
| 137 | - $themes = $this->getEnabledThemes(); |
|
| 138 | - return in_array($theme->getId(), $themes); |
|
| 139 | - } |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Get the list of all enabled themes IDs |
|
| 145 | - * for the logged-in user |
|
| 146 | - * |
|
| 147 | - * @return string[] |
|
| 148 | - */ |
|
| 149 | - public function getEnabledThemes(): array { |
|
| 150 | - $user = $this->userSession->getUser(); |
|
| 151 | - if ($user === null) { |
|
| 152 | - return []; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - try { |
|
| 156 | - return json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '[]')); |
|
| 157 | - } catch (\Exception $e) { |
|
| 158 | - return []; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Set the list of enabled themes |
|
| 164 | - * for the logged-in user |
|
| 165 | - * |
|
| 166 | - * @param string[] $themes the list of enabled themes IDs |
|
| 167 | - */ |
|
| 168 | - private function setEnabledThemes(array $themes): void { |
|
| 169 | - $user = $this->userSession->getUser(); |
|
| 170 | - $this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', json_encode(array_unique(array_values($themes)))); |
|
| 171 | - } |
|
| 124 | + return $themesIds; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Check whether a theme is enabled or not |
|
| 129 | + * for the logged-in user |
|
| 130 | + * |
|
| 131 | + * @return bool |
|
| 132 | + */ |
|
| 133 | + public function isEnabled(ITheme $theme): bool { |
|
| 134 | + $user = $this->userSession->getUser(); |
|
| 135 | + if ($user instanceof IUser) { |
|
| 136 | + // Using keys as it's faster |
|
| 137 | + $themes = $this->getEnabledThemes(); |
|
| 138 | + return in_array($theme->getId(), $themes); |
|
| 139 | + } |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Get the list of all enabled themes IDs |
|
| 145 | + * for the logged-in user |
|
| 146 | + * |
|
| 147 | + * @return string[] |
|
| 148 | + */ |
|
| 149 | + public function getEnabledThemes(): array { |
|
| 150 | + $user = $this->userSession->getUser(); |
|
| 151 | + if ($user === null) { |
|
| 152 | + return []; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + try { |
|
| 156 | + return json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '[]')); |
|
| 157 | + } catch (\Exception $e) { |
|
| 158 | + return []; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Set the list of enabled themes |
|
| 164 | + * for the logged-in user |
|
| 165 | + * |
|
| 166 | + * @param string[] $themes the list of enabled themes IDs |
|
| 167 | + */ |
|
| 168 | + private function setEnabledThemes(array $themes): void { |
|
| 169 | + $user = $this->userSession->getUser(); |
|
| 170 | + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', json_encode(array_unique(array_values($themes)))); |
|
| 171 | + } |
|
| 172 | 172 | } |
@@ -32,34 +32,34 @@ |
||
| 32 | 32 | use OCP\IConfig; |
| 33 | 33 | |
| 34 | 34 | class JSDataService implements \JsonSerializable { |
| 35 | - private ThemingDefaults $themingDefaults; |
|
| 36 | - private Util $util; |
|
| 37 | - private IConfig $appConfig; |
|
| 38 | - private ThemesService $themesService; |
|
| 35 | + private ThemingDefaults $themingDefaults; |
|
| 36 | + private Util $util; |
|
| 37 | + private IConfig $appConfig; |
|
| 38 | + private ThemesService $themesService; |
|
| 39 | 39 | |
| 40 | - public function __construct( |
|
| 41 | - ThemingDefaults $themingDefaults, |
|
| 42 | - Util $util, |
|
| 43 | - IConfig $appConfig, |
|
| 44 | - ThemesService $themesService |
|
| 45 | - ) { |
|
| 46 | - $this->themingDefaults = $themingDefaults; |
|
| 47 | - $this->util = $util; |
|
| 48 | - $this->appConfig = $appConfig; |
|
| 49 | - $this->themesService = $themesService; |
|
| 50 | - } |
|
| 40 | + public function __construct( |
|
| 41 | + ThemingDefaults $themingDefaults, |
|
| 42 | + Util $util, |
|
| 43 | + IConfig $appConfig, |
|
| 44 | + ThemesService $themesService |
|
| 45 | + ) { |
|
| 46 | + $this->themingDefaults = $themingDefaults; |
|
| 47 | + $this->util = $util; |
|
| 48 | + $this->appConfig = $appConfig; |
|
| 49 | + $this->themesService = $themesService; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function jsonSerialize(): array { |
|
| 53 | - return [ |
|
| 54 | - 'name' => $this->themingDefaults->getName(), |
|
| 55 | - 'url' => $this->themingDefaults->getBaseUrl(), |
|
| 56 | - 'slogan' => $this->themingDefaults->getSlogan(), |
|
| 57 | - 'color' => $this->themingDefaults->getColorPrimary(), |
|
| 58 | - 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
| 59 | - 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), |
|
| 60 | - 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), |
|
| 61 | - 'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'), |
|
| 62 | - 'enabledThemes' => $this->themesService->getEnabledThemes(), |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 52 | + public function jsonSerialize(): array { |
|
| 53 | + return [ |
|
| 54 | + 'name' => $this->themingDefaults->getName(), |
|
| 55 | + 'url' => $this->themingDefaults->getBaseUrl(), |
|
| 56 | + 'slogan' => $this->themingDefaults->getSlogan(), |
|
| 57 | + 'color' => $this->themingDefaults->getColorPrimary(), |
|
| 58 | + 'imprintUrl' => $this->themingDefaults->getImprintUrl(), |
|
| 59 | + 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), |
|
| 60 | + 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), |
|
| 61 | + 'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'), |
|
| 62 | + 'enabledThemes' => $this->themesService->getEnabledThemes(), |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -28,61 +28,61 @@ |
||
| 28 | 28 | |
| 29 | 29 | class ThemeInjectionService { |
| 30 | 30 | |
| 31 | - private IURLGenerator $urlGenerator; |
|
| 32 | - private ThemesService $themesService; |
|
| 33 | - private DefaultTheme $defaultTheme; |
|
| 31 | + private IURLGenerator $urlGenerator; |
|
| 32 | + private ThemesService $themesService; |
|
| 33 | + private DefaultTheme $defaultTheme; |
|
| 34 | 34 | |
| 35 | - public function __construct(IURLGenerator $urlGenerator, |
|
| 36 | - ThemesService $themesService, |
|
| 37 | - DefaultTheme $defaultTheme) { |
|
| 38 | - $this->urlGenerator = $urlGenerator; |
|
| 39 | - $this->themesService = $themesService; |
|
| 40 | - $this->defaultTheme = $defaultTheme; |
|
| 41 | - } |
|
| 35 | + public function __construct(IURLGenerator $urlGenerator, |
|
| 36 | + ThemesService $themesService, |
|
| 37 | + DefaultTheme $defaultTheme) { |
|
| 38 | + $this->urlGenerator = $urlGenerator; |
|
| 39 | + $this->themesService = $themesService; |
|
| 40 | + $this->defaultTheme = $defaultTheme; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function injectHeaders() { |
|
| 44 | - $themes = $this->themesService->getThemes(); |
|
| 45 | - $defaultTheme = $themes[$this->defaultTheme->getId()]; |
|
| 46 | - $mediaThemes = array_filter($themes, function($theme) { |
|
| 47 | - // Check if the theme provides a media query |
|
| 48 | - return (bool)$theme->getMediaQuery(); |
|
| 49 | - }); |
|
| 43 | + public function injectHeaders() { |
|
| 44 | + $themes = $this->themesService->getThemes(); |
|
| 45 | + $defaultTheme = $themes[$this->defaultTheme->getId()]; |
|
| 46 | + $mediaThemes = array_filter($themes, function($theme) { |
|
| 47 | + // Check if the theme provides a media query |
|
| 48 | + return (bool)$theme->getMediaQuery(); |
|
| 49 | + }); |
|
| 50 | 50 | |
| 51 | - // Default theme fallback |
|
| 52 | - $this->addThemeHeader($defaultTheme->getId()); |
|
| 51 | + // Default theme fallback |
|
| 52 | + $this->addThemeHeader($defaultTheme->getId()); |
|
| 53 | 53 | |
| 54 | - // Themes applied by media queries |
|
| 55 | - foreach($mediaThemes as $theme) { |
|
| 56 | - $this->addThemeHeader($theme->getId(), true, $theme->getMediaQuery()); |
|
| 57 | - } |
|
| 54 | + // Themes applied by media queries |
|
| 55 | + foreach($mediaThemes as $theme) { |
|
| 56 | + $this->addThemeHeader($theme->getId(), true, $theme->getMediaQuery()); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - // Themes |
|
| 60 | - foreach($this->themesService->getThemes() as $theme) { |
|
| 61 | - // Ignore default theme as already processed first |
|
| 62 | - if ($theme->getId() === $this->defaultTheme->getId()) { |
|
| 63 | - continue; |
|
| 64 | - } |
|
| 65 | - $this->addThemeHeader($theme->getId(), false); |
|
| 66 | - } |
|
| 67 | - } |
|
| 59 | + // Themes |
|
| 60 | + foreach($this->themesService->getThemes() as $theme) { |
|
| 61 | + // Ignore default theme as already processed first |
|
| 62 | + if ($theme->getId() === $this->defaultTheme->getId()) { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + $this->addThemeHeader($theme->getId(), false); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Inject theme header into rendered page |
|
| 71 | - * |
|
| 72 | - * @param string $themeId the theme ID |
|
| 73 | - * @param bool $plain request the :root syntax |
|
| 74 | - * @param string $media media query to use in the <link> element |
|
| 75 | - */ |
|
| 76 | - private function addThemeHeader(string $themeId, bool $plain = true, string $media = null) { |
|
| 77 | - $linkToCSS = $this->urlGenerator->linkToRoute('theming.Theming.getThemeStylesheet', [ |
|
| 78 | - 'themeId' => $themeId, |
|
| 79 | - 'plain' => $plain, |
|
| 80 | - ]); |
|
| 81 | - Util::addHeader('link', [ |
|
| 82 | - 'rel' => 'stylesheet', |
|
| 83 | - 'media' => $media, |
|
| 84 | - 'href' => $linkToCSS, |
|
| 85 | - 'class' => 'theme' |
|
| 86 | - ]); |
|
| 87 | - } |
|
| 69 | + /** |
|
| 70 | + * Inject theme header into rendered page |
|
| 71 | + * |
|
| 72 | + * @param string $themeId the theme ID |
|
| 73 | + * @param bool $plain request the :root syntax |
|
| 74 | + * @param string $media media query to use in the <link> element |
|
| 75 | + */ |
|
| 76 | + private function addThemeHeader(string $themeId, bool $plain = true, string $media = null) { |
|
| 77 | + $linkToCSS = $this->urlGenerator->linkToRoute('theming.Theming.getThemeStylesheet', [ |
|
| 78 | + 'themeId' => $themeId, |
|
| 79 | + 'plain' => $plain, |
|
| 80 | + ]); |
|
| 81 | + Util::addHeader('link', [ |
|
| 82 | + 'rel' => 'stylesheet', |
|
| 83 | + 'media' => $media, |
|
| 84 | + 'href' => $linkToCSS, |
|
| 85 | + 'class' => 'theme' |
|
| 86 | + ]); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -45,19 +45,19 @@ |
||
| 45 | 45 | $defaultTheme = $themes[$this->defaultTheme->getId()]; |
| 46 | 46 | $mediaThemes = array_filter($themes, function($theme) { |
| 47 | 47 | // Check if the theme provides a media query |
| 48 | - return (bool)$theme->getMediaQuery(); |
|
| 48 | + return (bool) $theme->getMediaQuery(); |
|
| 49 | 49 | }); |
| 50 | 50 | |
| 51 | 51 | // Default theme fallback |
| 52 | 52 | $this->addThemeHeader($defaultTheme->getId()); |
| 53 | 53 | |
| 54 | 54 | // Themes applied by media queries |
| 55 | - foreach($mediaThemes as $theme) { |
|
| 55 | + foreach ($mediaThemes as $theme) { |
|
| 56 | 56 | $this->addThemeHeader($theme->getId(), true, $theme->getMediaQuery()); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // Themes |
| 60 | - foreach($this->themesService->getThemes() as $theme) { |
|
| 60 | + foreach ($this->themesService->getThemes() as $theme) { |
|
| 61 | 61 | // Ignore default theme as already processed first |
| 62 | 62 | if ($theme->getId() === $this->defaultTheme->getId()) { |
| 63 | 63 | continue; |