/** * 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); }
/** * Display/set user profile settings. */ public function actionSettings() { $model = $this->loadModel(Yii::app()->user->getId()); if (isset($_POST['Profile']) || isset($_POST['preferences'])) { if (isset($_POST['Profile'])) { $model->attributes = $_POST['Profile']; if (isset($_POST['preferences']['loginSound'])) { $pieces = explode(',', $_POST['preferences']['loginSound']); $model->loginSound = $pieces[0]; unset($_POST['preferences']['loginSound']); } if (isset($_POST['preferences']['notificationSound'])) { $pieces = explode(',', $_POST['preferences']['notificationSound']); $model->notificationSound = $pieces[0]; unset($_POST['preferences']['notificationSound']); } $model->save(); } if (isset($_POST['preferences']['themeName'])) { ThemeGenerator::clearCache(); Yii::import('application.components.ThemeGenerator.LoginThemeHelper'); LoginThemeHelper::saveProfileTheme($_POST['preferences']['themeName']); $model->theme = array_merge(array_diff_key($model->theme, array_flip(ThemeGenerator::getProfileKeys())), ThemeGenerator::loadDefault($_POST['preferences']['themeName'], false), array_diff_key($_POST['preferences'], array_flip(ThemeGenerator::getProfileKeys()))); $model->save(); } $this->refresh(); } $modules = Modules::model()->findAllByAttributes(array('visible' => 1)); $menuItems = array(); foreach ($modules as $module) { if ($module->name == 'document') { $menuItems[$module->title] = $module->title; } else { $menuItems[$module->name] = Yii::t('app', $module->title); } } $menuItems = array('' => Yii::t('app', 'Activity Feed')) + $menuItems; $languages = $model->getLanguageOptions(); $times = $this->getTimeZones(); $myThemeProvider = new CActiveDataProvider('Media', array('criteria' => array('condition' => "((private = 1 AND uploadedBy = '" . Yii::app()->user->name . "') OR private = 0) AND associationType = 'theme'", 'order' => 'createDate DESC'), 'pagination' => false)); $myBackgroundProvider = new CActiveDataProvider('Media', array('criteria' => array('condition' => "(associationType = 'bg-private' AND associationId = '" . Yii::app()->user->getId() . "') OR associationType = 'bg'", 'order' => 'createDate DESC'), 'pagination' => false)); $myLoginSoundProvider = new CActiveDataProvider('Media', array('criteria' => array('condition' => "(associationType='loginSound' AND (private=0 OR private IS NULL OR uploadedBy='" . Yii::app()->user->getName() . "'))", 'order' => 'createDate DESC'), 'pagination' => false)); $myNotificationSoundProvider = new CActiveDataProvider('Media', array('criteria' => array('condition' => "(associationType='notificationSound' AND (private=0 OR private IS NULL OR uploadedBy='" . Yii::app()->user->getName() . "'))", 'order' => 'createDate DESC'), 'pagination' => false)); $hiddenTags = json_decode(Yii::app()->params->profile->hiddenTags, true); if (empty($hiddenTags)) { $hiddenTags = array(); } if (sizeof($hiddenTags)) { $tagParams = AuxLib::bindArray($hiddenTags); $allTags = Yii::app()->db->createCommand()->select('COUNT(*) AS count, tag')->from('x2_tags')->group('tag')->where('tag IS NOT NULL AND tag IN (' . implode(',', array_keys($tagParams)) . ')', $tagParams)->order('tag ASC')->limit(20)->queryAll(); } else { $allTags = array(); } $admin = Yii::app()->settings; $this->render('settings', array('model' => $model, 'languages' => $languages, 'times' => $times, 'myThemes' => $myThemeProvider, 'myBackgrounds' => $myBackgroundProvider, 'myLoginSounds' => $myLoginSoundProvider, 'myNotificationSounds' => $myNotificationSoundProvider, 'menuItems' => $menuItems, 'allTags' => $allTags)); }
/** * Helper action upon login * expects a post of the theme and sets it to be the current theme ONLY if the current theme is not already set. */ public static function login() { if (!isset($_POST[self::LOGIN_THEME_COOKIE])) { return; } $themeName = $_POST[self::LOGIN_THEME_COOKIE]; $profile = X2Model::model('Profile')->findByPk(Yii::app()->user->id); if ($profile->theme['themeName'] == '' || $profile->theme['themeName'] == ThemeGenerator::$defaultLight) { $profile->theme = ThemeGenerator::loadDefault($themeName, false); $profile->save(); } }