2424 */
2525namespace OCA \Theming \Themes ;
2626
27- use OCA \Theming \AppInfo \Application ;
2827use OCA \Theming \ImageManager ;
2928use OCA \Theming \ITheme ;
3029use OCA \Theming \Service \BackgroundService ;
3534use OCP \IL10N ;
3635use OCP \IURLGenerator ;
3736use OCP \IUserSession ;
38- use OCP \Server ;
3937
4038class DefaultTheme implements ITheme {
4139 use CommonThemeTrait;
@@ -47,6 +45,7 @@ class DefaultTheme implements ITheme {
4745 public ImageManager $ imageManager ;
4846 public IConfig $ config ;
4947 public IL10N $ l ;
48+ public IAppManager $ appManager ;
5049
5150 public string $ defaultPrimaryColor ;
5251 public string $ primaryColor ;
@@ -57,14 +56,16 @@ public function __construct(Util $util,
5756 IURLGenerator $ urlGenerator ,
5857 ImageManager $ imageManager ,
5958 IConfig $ config ,
60- IL10N $ l ) {
59+ IL10N $ l ,
60+ IAppManager $ appManager ) {
6161 $ this ->util = $ util ;
6262 $ this ->themingDefaults = $ themingDefaults ;
6363 $ this ->userSession = $ userSession ;
6464 $ this ->urlGenerator = $ urlGenerator ;
6565 $ this ->imageManager = $ imageManager ;
6666 $ this ->config = $ config ;
6767 $ this ->l = $ l ;
68+ $ this ->appManager = $ appManager ;
6869
6970 $ this ->defaultPrimaryColor = $ this ->themingDefaults ->getDefaultColorPrimary ();
7071 $ this ->primaryColor = $ this ->themingDefaults ->getColorPrimary ();
@@ -108,8 +109,6 @@ public function getCSSVariables(): array {
108109 $ colorBoxShadow = $ this ->util ->darken ($ colorMainBackground , 70 );
109110 $ colorBoxShadowRGB = join (', ' , $ this ->util ->hexToRGB ($ colorBoxShadow ));
110111
111- $ hasCustomLogoHeader = $ this ->imageManager ->hasImage ('logo ' ) || $ this ->imageManager ->hasImage ('logoheader ' );
112-
113112 $ variables = [
114113 '--color-main-background ' => $ colorMainBackground ,
115114 '--color-main-background-rgb ' => $ colorMainBackgroundRGB ,
@@ -188,71 +187,18 @@ public function getCSSVariables(): array {
188187
189188 // mobile. Keep in sync with core/js/js.js
190189 '--breakpoint-mobile ' => '1024px ' ,
191-
192- // invert filter if primary is too bright
193- // to be used for legacy reasons only. Use inline
194- // svg with proper css variable instead or material
195- // design icons.
196- // ⚠️ Using 'no' as a value to make sure we specify an
197- // invalid one with no fallback. 'unset' could here fallback to some
198- // other theme with media queries
199- '--primary-invert-if-bright ' => $ this ->util ->invertTextColor ($ this ->primaryColor ) ? 'invert(100%) ' : 'no ' ,
200190 '--background-invert-if-dark ' => 'no ' ,
201191 '--background-invert-if-bright ' => 'invert(100%) ' ,
202192
203193 // Default last fallback values
204- '--image-main- background ' => "url(' " . $ this ->urlGenerator ->imagePath ('core ' , 'app-background.jpg ' ) . "') " ,
205- '--color-main- background-plain ' => $ this ->defaultPrimaryColor ,
194+ '--image-background ' => "url(' " . $ this ->urlGenerator ->imagePath ('core ' , 'app-background.jpg ' ) . "') " ,
195+ '--color-background-plain ' => $ this ->defaultPrimaryColor ,
206196 ];
207197
208198 // Primary variables
209199 $ variables = array_merge ($ variables , $ this ->generatePrimaryVariables ($ colorMainBackground , $ colorMainText ));
210-
211- $ backgroundDeleted = $ this ->config ->getAppValue (Application::APP_ID , 'backgroundMime ' , '' ) === 'backgroundColor ' ;
212- // If primary as background has been request or if we have a custom primary colour
213- // let's not define the background image
214- if ($ backgroundDeleted && $ this ->themingDefaults ->isUserThemingDisabled ()) {
215- $ variables ['--image-background-plain ' ] = 'true ' ;
216- $ variables ['--color-main-background-plain ' ] = $ this ->themingDefaults ->getColorPrimary ();
217- }
218-
219- // Register image variables only if custom-defined
220- foreach (['logo ' , 'logoheader ' , 'favicon ' , 'background ' ] as $ image ) {
221- if ($ this ->imageManager ->hasImage ($ image )) {
222- $ imageUrl = $ this ->imageManager ->getImageUrl ($ image );
223- if ($ image === 'background ' ) {
224- // If background deleted is set, ignoring variable
225- if ($ backgroundDeleted ) {
226- continue ;
227- }
228- $ variables ['--image-background-size ' ] = 'cover ' ;
229- $ variables ['--image-main-background ' ] = "url(' " . $ imageUrl . "') " ;
230- }
231- $ variables ["--image- $ image " ] = "url(' " . $ imageUrl . "') " ;
232- }
233- }
234-
235- if ($ hasCustomLogoHeader ) {
236- $ variables ["--image-logoheader-custom " ] = 'true ' ;
237- }
238-
239- $ appManager = Server::get (IAppManager::class);
240- $ user = $ this ->userSession ->getUser ();
241- if (!$ this ->themingDefaults ->isUserThemingDisabled () && $ appManager ->isEnabledForUser (Application::APP_ID ) && $ user !== null ) {
242- $ themingBackground = $ this ->config ->getUserValue ($ user ->getUID (), Application::APP_ID , 'background ' , 'default ' );
243- $ currentVersion = (int )$ this ->config ->getUserValue ($ user ->getUID (), Application::APP_ID , 'userCacheBuster ' , '0 ' );
244-
245-
246- if ($ themingBackground === 'custom ' ) {
247- $ cacheBuster = substr (sha1 ($ user ->getUID () . '_ ' . $ currentVersion ), 0 , 8 );
248- $ variables ['--image-main-background ' ] = "url(' " . $ this ->urlGenerator ->linkToRouteAbsolute ('theming.userTheme.getBackground ' ) . "?v= $ cacheBuster') " ;
249- } elseif (isset (BackgroundService::SHIPPED_BACKGROUNDS [$ themingBackground ])) {
250- $ variables ['--image-main-background ' ] = "url(' " . $ this ->urlGenerator ->linkTo (Application::APP_ID , "/img/background/ $ themingBackground " ) . "') " ;
251- } elseif (substr ($ themingBackground , 0 , 1 ) === '# ' ) {
252- unset($ variables ['--image-main-background ' ]);
253- $ variables ['--color-main-background-plain ' ] = $ this ->themingDefaults ->getColorPrimary ();
254- }
255- }
200+ $ variables = array_merge ($ variables , $ this ->generateGlobalBackgroundVariables ());
201+ $ variables = array_merge ($ variables , $ this ->generateUserBackgroundVariables ());
256202
257203 return $ variables ;
258204 }
0 commit comments