/** * Registers necessary JS and passes is the proper arguments * Checks for POST */ public function registerJS() { Yii::app()->clientScript->registerCoreScript('cookie', CClientScript::POS_READY); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/LoginThemeHelper.js', CClientScript::POS_END); /* This part will create a part of the theme selector specific to the current theme */ if ($this->currentTheme == ThemeGenerator::$defaultLight) { $theme = ThemeGenerator::loadDefault($this->nextTheme); } else { $theme = ThemeGenerator::loadDefault($this->currentTheme); } if (!isset($theme['background'])) { $theme['background'] = '#000'; } $themeBG = array($theme['background'], X2Color::brightness($theme['background'], -0.1), $theme['background']); $JSON = array('themeColorCookie' => self::LOGIN_BACKGROUND_COOKIE, 'cookieLength' => self::$cookieLength, 'open' => isset($_POST[self::LOGIN_THEME_COOKIE]), 'currentColor' => $this->currentColor, 'currentThemeBG' => $themeBG); $JSON = CJSON::encode($JSON); Yii::app()->clientScript->registerScript('LoginThemeHelperJS', "\n\t\t\tnew x2.LoginThemeHelper({$JSON});\n\t\t", CClientScript::POS_END); }
/** * 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; }