-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
theming: Separate primary and background colors - fix the header menu colors
#42977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0211feb
fix(theming): Also set default background color ("primary") for custo…
susnux de938bb
feat(theming): Separate background and primary color
susnux 9d2c3c1
fix: Adjust dashboard and header menu to use new background colors
susnux 705335e
feat(theming): Allow to configure primary color separate from backgro…
susnux 482395b
fix(theming): Also reset background color settings when updating glob…
susnux 4d865fd
feat(theming): Allow users to configure their primary color
susnux 282f1b1
fix(theming): Also apply new background colors to guest view
susnux 0ef3147
fix(tests): Adjust theming test for new splitted background and prima…
susnux c826092
fix(core): Adjust styles for header menu icons
susnux 752e3b9
fix(settings): Make background selector be responsive to user changes
susnux bd73bcc
fix(styles): Adjust background stylings
susnux 8028784
fix: cleanup theming app code
susnux 85b64e1
fix: Always populate `--image-background`
susnux 11dbfa6
fix(settings): Return mean color of background image on set
susnux 538a049
fix(tests): Adjust theming test for new splitted background and prima…
susnux f19d586
fix(theming): Add some strict checking for userId
susnux 651afb8
chore: Compile assets
susnux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| * | ||
| * @author Christoph Wurst <[email protected]> | ||
| * @author Daniel Kesselberg <[email protected]> | ||
| * @author Ferdinand Thiessen <[email protected]> | ||
| * @author Gary Kim <[email protected]> | ||
| * @author Jacob Neplokh <[email protected]> | ||
| * @author John Molakvoæ <[email protected]> | ||
|
|
@@ -56,6 +57,7 @@ public function __construct( | |
| private ICacheFactory $cacheFactory, | ||
| private LoggerInterface $logger, | ||
| private ITempManager $tempManager, | ||
| private BackgroundService $backgroundService, | ||
| ) { | ||
| } | ||
|
|
||
|
|
@@ -77,7 +79,11 @@ public function getImageUrl(string $key): string { | |
| case 'favicon': | ||
| return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; | ||
| case 'background': | ||
| return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); | ||
| // Removing the background defines its mime as 'backgroundColor' | ||
| $mimeSetting = $this->config->getAppValue('theming', 'backgroundMime', ''); | ||
| if ($mimeSetting !== 'backgroundColor') { | ||
| return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); | ||
| } | ||
| } | ||
| return ''; | ||
| } | ||
|
|
@@ -227,47 +233,56 @@ public function updateImage(string $key, string $tmpFile): string { | |
| throw new \Exception('Unsupported image type: ' . $detectedMimeType); | ||
| } | ||
|
|
||
| if ($key === 'background' && $this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { | ||
| try { | ||
| // Optimize the image since some people may upload images that will be | ||
| // either to big or are not progressive rendering. | ||
| $newImage = @imagecreatefromstring(file_get_contents($tmpFile)); | ||
| if ($newImage === false) { | ||
| throw new \Exception('Could not read background image, possibly corrupted.'); | ||
| } | ||
| if ($key === 'background') { | ||
| if ($this->shouldOptimizeBackgroundImage($detectedMimeType, filesize($tmpFile))) { | ||
| try { | ||
| // Optimize the image since some people may upload images that will be | ||
| // either to big or are not progressive rendering. | ||
| $newImage = @imagecreatefromstring(file_get_contents($tmpFile)); | ||
| if ($newImage === false) { | ||
| throw new \Exception('Could not read background image, possibly corrupted.'); | ||
| } | ||
|
|
||
| // Preserve transparency | ||
| imagesavealpha($newImage, true); | ||
| imagealphablending($newImage, true); | ||
| // Preserve transparency | ||
| imagesavealpha($newImage, true); | ||
| imagealphablending($newImage, true); | ||
|
|
||
| $newWidth = (imagesx($newImage) < 4096 ? imagesx($newImage) : 4096); | ||
| $newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); | ||
| $outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
| if ($outputImage === false) { | ||
| throw new \Exception('Could not scale uploaded background image.'); | ||
| } | ||
| $imageWidth = imagesx($newImage); | ||
| $imageHeight = imagesy($newImage); | ||
|
|
||
| $newTmpFile = $this->tempManager->getTemporaryFile(); | ||
| imageinterlace($outputImage, true); | ||
| // Keep jpeg images encoded as jpeg | ||
| if (str_contains($detectedMimeType, 'image/jpeg')) { | ||
| if (!imagejpeg($outputImage, $newTmpFile, 90)) { | ||
| throw new \Exception('Could not recompress background image as JPEG'); | ||
| /** @var int */ | ||
| $newWidth = min(4096, $imageWidth); | ||
| $newHeight = intval($imageHeight / ($imageWidth / $newWidth)); | ||
| $outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
|
||
| if ($outputImage === false) { | ||
| throw new \Exception('Could not scale uploaded background image.'); | ||
| } | ||
| } else { | ||
| if (!imagepng($outputImage, $newTmpFile, 8)) { | ||
| throw new \Exception('Could not recompress background image as PNG'); | ||
|
|
||
| $newTmpFile = $this->tempManager->getTemporaryFile(); | ||
| imageinterlace($outputImage, true); | ||
| // Keep jpeg images encoded as jpeg | ||
| if (str_contains($detectedMimeType, 'image/jpeg')) { | ||
| if (!imagejpeg($outputImage, $newTmpFile, 90)) { | ||
| throw new \Exception('Could not recompress background image as JPEG'); | ||
| } | ||
| } else { | ||
| if (!imagepng($outputImage, $newTmpFile, 8)) { | ||
| throw new \Exception('Could not recompress background image as PNG'); | ||
| } | ||
| } | ||
| } | ||
| $tmpFile = $newTmpFile; | ||
| imagedestroy($outputImage); | ||
| } catch (\Exception $e) { | ||
| if (is_resource($outputImage) || $outputImage instanceof \GdImage) { | ||
| $tmpFile = $newTmpFile; | ||
| imagedestroy($outputImage); | ||
| } | ||
| } catch (\Exception $e) { | ||
| if (isset($outputImage) && is_resource($outputImage) || $outputImage instanceof \GdImage) { | ||
Check noticeCode scanning / Psalm PossiblyUndefinedVariable
Possibly undefined variable $outputImage defined in try block
|
||
| imagedestroy($outputImage); | ||
| } | ||
|
|
||
| $this->logger->debug($e->getMessage()); | ||
| $this->logger->debug($e->getMessage()); | ||
| } | ||
| } | ||
|
|
||
| // For background images we need to announce it | ||
| $this->backgroundService->setGlobalBackground($tmpFile); | ||
| } | ||
|
|
||
| $target->putContent(file_get_contents($tmpFile)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Psalm
DeprecatedMethod