To get around this - I made a method for the User model that returns a boolean for "profile_background_image_display".
def profile_background_image_display
return is_theme? || has_custom_background?
end
def is_theme?
colors = %w(9AE4E8 C6E2EE EDECE9 0099B9 352726 709397 EBEBEB 8B542B 1A1B1F 642D8B FF6699 BADFCD)
images = (1..12).map{|i| "theme#{i}/bg.gif"}
for i in 0..11
if self.profile_background_image_url =~ Regexp.new(images.at(i)) && self.profile_background_color.downcase == colors.at(i).downcase
return true
end
end
if self.profile_background_image_url =~ /images\/bg.gif/ && self.profile_background_color == colors.at(0) # This is the default, not theme 1
return true
end
return false
end
def has_custom_background?
return !(self.profile_background_image_url =~ /theme\d+\/bg.gif/)
end
Note - this isn't perfect. This is where it breaks down:
- It will show a background image if the user sets a custom background image and hides it.
- It will show the background image if the user picks a theme and hides the background.
- It will hide the background image if the user uses a theme background on a custom color.
That's the trade off.
Hope this is useful to someone - I'd love to know if you have a better solution.
No comments:
Post a Comment