Ejemplo n.º 1
0
 public function testGeneratePalette2()
 {
     $profileDefaultThemeLegacy = $this->profiles('adminProfile');
     $profileNoTheme = $this->profiles('testProfile');
     $profileSelectedThemeLegacy = $this->profiles('testProfile2');
     // ensure that keys get normalized
     $this->assertTrue(array_keys(ThemeGenerator::generatePalette($profileDefaultThemeLegacy->theme, true)) === array_keys(ThemeGenerator::generatePalette($profileNoTheme->theme, true)) && array_keys(ThemeGenerator::generatePalette($profileNoTheme->theme, true)) === array_keys(ThemeGenerator::generatePalette($profileSelectedThemeLegacy->theme, true)));
 }
Ejemplo n.º 2
0
 public function testGeneratePalette($colors = null)
 {
     // Test for malformed array input
     if (!$colors) {
         $colors = $this->normalColors;
     }
     $generated = ThemeGenerator::generatePalette($colors);
     VERBOSE_MODE && print_r($generated);
     $keys = ThemeGenerator::getProfileKeys();
     $this->assertTrue(in_array('themeName', $keys));
     VERBOSE_MODE && print_r($keys);
     foreach ($keys as $key) {
         if ($key == 'themeName') {
             continue;
         }
         $this->assertArrayHasKey($key, $generated);
     }
     $this->assertCount(count($keys) - 1, $generated);
 }
Ejemplo n.º 3
0
 /**
  * Loads a theme for the login page
  * @param string $themeName string of the theme to render
  * @param bool $computed whether or not to include computed theme color values
  */
 public static function loadDefault($themeName, $computed = true)
 {
     //In case default light was deleted
     if ($themeName == self::$defaultLight) {
         return array('themeName' => self::$defaultLight);
     }
     $media = X2Model::model('Media')->findByAttributes(array('associationType' => 'theme', 'fileName' => $themeName, 'private' => 0));
     if (!$media) {
         $media = X2Model::model('Media')->findByAttributes(array('associationType' => 'theme', 'fileName' => self::$defaultDark));
         if (!$media) {
             return self::loadDefault(self::$defaultLight);
         }
     }
     $theme = CJSON::decode($media->description);
     if ($computed) {
         $colors = ThemeGenerator::generatePalette($theme, true);
     } else {
         $colors = $theme;
     }
     return $colors;
 }
Ejemplo n.º 4
0
 /**
  * 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 ($model->save()) {
                 //$this->redirect(array('view','id'=>$model->id));
             }
         }
         if (isset($_POST['preferences'])) {
             $model->theme = ThemeGenerator::generatePalette($_POST['preferences']);
             if ($model->save()) {
                 Yii::import('application.components.ThemeGenerator.LoginThemeHelper');
                 LoginThemeHelper::saveProfileTheme($_POST['preferences']['themeName']);
             }
         }
         $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;
     $languageDirs = scandir('./protected/messages');
     // scan for installed language folders
     $languages = array('en' => 'English');
     foreach ($languageDirs as $code) {
         // look for langauges name
         $name = $this->getLanguageName($code, $languageDirs);
         // in each item in $languageDirs
         if ($name !== false) {
             $languages[$code] = $name;
         }
         // add to $languages if name is found
     }
     $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));
 }