/** * Populates the array with different color option * @return array array filled with formatted css color strings */ public static function generatePalette($preferences, $refresh = false) { $computedTheme = Yii::app()->cache->get(self::getCacheKey()); if (!Yii::app()->user->isGuest && $computedTheme && !$refresh) { return $computedTheme; } $colors = $preferences; //Keys for smart text $colors['smart_text'] = ''; $colors['smart_text2'] = ''; if (isset($colors['backgroundImg']) && $colors['backgroundImg']) { $colors['background'] = ''; } $settings = self::getSettingsList(); foreach ($settings as $key) { if (!isset($colors[$key])) { $colors[$key] = ''; } $value = $colors[$key]; if (!preg_match("/#/", $value) && $value) { $colors[$key] = '#' . $value; } if (!preg_match('/_override$/', $key)) { $colors['darker_' . $key] = X2Color::brightness($value, -0.1, false); $colors['dark_' . $key] = X2Color::brightness($value, -0.05, false); $colors['brighter_' . $key] = X2Color::brightness($value, 0.1, false); $colors['bright_' . $key] = X2Color::brightness($value, 0.05, false); $colors['opaque_' . $key] = X2Color::opaque($value, 0.2); } $colors['light_' . $key] = X2Color::brightness($value, 0.05, true); $colors['lighter_' . $key] = X2Color::brightness($value, 0.1, true); } // generate smart text for module overrides foreach (array_filter($settings, function ($key) { return preg_match('/^background_.*_override$/', $key); }) as $key) { if (isset($colors[$key]) && $colors[$key]) { $colors[preg_replace('/^background_/', 'smart_text_', $key)] = X2Color::smartText($colors[$key], $colors['text'] ? '' : '#000000'); } else { $colors[preg_replace('/^background_/', 'smart_text_', $key)] = ''; } } # settings for most borders in the app $colors['border'] = $colors['lighter_content']; # Smart text for highlight 1 (Buttons and Windows) if (isset($colors['highlight1'], $colors['text']) && !empty($colors['highlight1']) && !empty($colors['text'])) { $colors['smart_text'] = X2Color::smartText($colors['highlight1'], $colors['text']); } # Smart text for highlight 2 (highlighted buttons) if (isset($colors['highlight2'], $colors['text']) && !empty($colors['highlight2']) && !empty($colors['text'])) { $colors['smart_text2'] = X2Color::smartText($colors['highlight2'], $colors['text']); } Yii::app()->cache->set(self::getCacheKey(), $colors, 0); return $colors; }
/** * Populates the array with different color option * @return array array filled with formatted css color strings */ public static function generatePalette($preferences) { $colors = $preferences; // Flag to indicate this array is generated $colors['generated'] = true; //Keys for smart text $colors['smart_text'] = ''; $colors['smart_text2'] = ''; if (isset($colors['backgroundImg']) && $colors['backgroundImg']) { $colors['background'] = ''; } foreach (self::$settingsList as $key) { $value = isset($colors[$key]) ? $colors[$key] : ''; if (!preg_match("/#/", $value) && $value) { $colors[$key] = '#' . $value; } $colors['darker_' . $key] = X2Color::brightness($value, -0.1, false); $colors['dark_' . $key] = X2Color::brightness($value, -0.05, false); $colors['brighter_' . $key] = X2Color::brightness($value, 0.1, false); $colors['bright_' . $key] = X2Color::brightness($value, 0.05, false); $colors['lighter_' . $key] = X2Color::brightness($value, 0.1, true); $colors['light_' . $key] = X2Color::brightness($value, 0.05, true); $colors['opaque_' . $key] = X2Color::opaque($value, 0.2); } # settings for most borders in the app $colors['border'] = $colors['lighter_content']; # Smart text for highlight 1 (Buttons and Windows) if (isset($colors['highlight1'], $colors['text']) && !empty($colors['highlight1']) && !empty($colors['text'])) { $colors['smart_text'] = X2Color::smartText($colors['highlight1'], $colors['text']); } # Smart text for highlight 2 (highlighted buttons) if (isset($colors['highlight2'], $colors['text']) && !empty($colors['highlight2']) && !empty($colors['text'])) { $colors['smart_text2'] = X2Color::smartText($colors['highlight2'], $colors['text']); } return $colors; }