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); }
/** * @param $file string pathname of a css file * @param $lineNumber int lineNumber of the theme tag * @return array of needed items to construct the array seen in {@link scanCssFile}. */ public function makeRule($file, $lineNumber) { $lines = file($file); $themeLine = $lines[$lineNumber]; // print_r($themeLine);/ $stripped = preg_replace('/.*@theme\\ *(.*)\\*\\//', '\\1', $themeLine); // Remove extra spaces in between $stripped = preg_replace('/\\ \\ */', ' ', $stripped); $stripped = preg_replace('/:/', '', $stripped); $params = explode(' ', $stripped); // Backtrack the last comment while (!preg_match('/line\\ [0-9]+/', $lines[$lineNumber])) { $lineNumber--; if ($lineNumber < 0) { throw new Exception("Backtracked and found no comment in {$file}", 1); } } $comment = $lines[$lineNumber]; $selector = ''; // Move forward lines and append the selector on each line while (!preg_match('/{/', $lines[$lineNumber])) { $lineNumber++; $selector .= $lines[$lineNumber]; } // tab indent to look nice $selector = preg_replace('/\\n[^$]/', "\n ", $selector); $rule = $params[0]; $value = $params[1]; // Throw exception if it is not a valid key if (!in_array($value, ThemeGenerator::getProfileKeys())) { $comment = preg_replace('/\\/\\*(.*)\\*\\//', '\\1', $comment); throw new Exception("\nTheme Key '{$value}' is not a valid key.\nFound at{$comment}"); } return array($selector, $comment, array('rule' => $rule, 'value' => $value)); }
public function behaviors() { // Skip loading theme settins if this request isn't associated with a session, eg API $theme = Yii::app()->params->noSession ? array() : ThemeGenerator::getProfileKeys(); return array('X2LinkableBehavior' => array('class' => 'X2LinkableBehavior', 'baseRoute' => '/profile', 'autoCompleteSource' => null, 'module' => 'profile'), 'ERememberFiltersBehavior' => array('class' => 'application.components.ERememberFiltersBehavior', 'defaults' => array(), 'defaultStickOnClear' => false), 'NormalizedJSONFieldsBehavior' => array('class' => 'application.components.NormalizedJSONFieldsBehavior', 'transformAttributes' => array('theme' => array_merge($theme, array('backgroundColor', 'menuBgColor', 'menuTextColor', 'pageHeaderBgColor', 'pageHeaderTextColor', 'activityFeedWidgetBgColor', 'activityFeedWidgetTextColor', 'backgroundImg', 'backgroundTiling', 'pageOpacity', 'themeName', 'private', 'owner', 'loginSound', 'notificationSound', 'gridViewRowColorOdd', 'gridViewRowColorEven')))), 'JSONFieldsDefaultValuesBehavior' => array('class' => 'application.components.JSONFieldsDefaultValuesBehavior', 'transformAttributes' => array('miscLayoutSettings' => array('themeSectionExpanded' => true, 'unhideTagsSectionExpanded' => true, 'x2flowShowLabels' => true, 'profileInfoIsMinimized' => false, 'perStageWorkflowView' => true, 'columnWidth' => 50, 'recordViewColumnWidth' => 65, 'enableTransactionalView' => true, 'enableJournalView' => true, 'viewModeActionSubmenuOpen' => true)), 'maintainCurrentFieldsOrder' => true), 'X2SmartSearchModelBehavior' => array('class' => 'application.components.X2SmartSearchModelBehavior')); }
public function behaviors() { Yii::import('application.components.X2ActiveRecordBehavior'); Yii::import('application.components.behaviors.FileFieldBehavior'); // Skip loading theme settins if this request isn't associated with a session, eg API $theme = Yii::app()->params->noSession ? array() : ThemeGenerator::getProfileKeys(true, true, false); $that = $this; return array('X2StaticFieldsBehavior' => array('class' => 'application.components.behaviors.X2StaticFieldsBehavior', 'translationCategory' => 'profile', 'fields' => array(array('fieldName' => 'fullName', 'attributeLabel' => 'Full Name', 'type' => 'varchar'), array('fieldName' => 'tagLine', 'attributeLabel' => 'Tag Line', 'type' => 'varchar'), array('fieldName' => 'username', 'attributeLabel' => 'Username', 'type' => 'varchar'), array('fieldName' => 'officePhone', 'attributeLabel' => 'Office Phone', 'type' => 'phone'), array('fieldName' => 'cellPhone', 'attributeLabel' => 'Cell Phone', 'type' => 'phone'), array('fieldName' => 'emailAddress', 'attributeLabel' => 'Email Address', 'type' => 'email'), array('fieldName' => 'language', 'attributeLabel' => 'Language', 'type' => 'dropdown', 'includeEmpty' => false, 'linkType' => function () use($that) { return $that->getLanguageOptions(); }), array('fieldName' => 'googleId', 'attributeLabel' => 'Google ID', 'type' => 'email'))), 'FileFieldBehavior' => array('class' => 'application.components.behaviors.FileFieldBehavior', 'attribute' => 'avatar', 'fileAttribute' => 'photo', 'fileType' => FileFieldBehavior::IMAGE, 'getFilename' => function (CUploadedFile $file) { $time = time(); $rand = chr(rand(65, 90)); $salt = $time . $rand; $name = md5($salt . md5($salt) . $salt); return 'uploads/protected/' . $name . '.' . $file->getExtensionName(); }), 'X2LinkableBehavior' => array('class' => 'X2LinkableBehavior', 'baseRoute' => '/profile', 'autoCompleteSource' => null, 'module' => 'profile'), 'ERememberFiltersBehavior' => array('class' => 'application.components.ERememberFiltersBehavior', 'defaults' => array(), 'defaultStickOnClear' => false), 'NormalizedJSONFieldsBehavior' => array('class' => 'application.components.NormalizedJSONFieldsBehavior', 'transformAttributes' => array('theme' => array_merge($theme, array('backgroundColor', 'menuBgColor', 'menuTextColor', 'pageHeaderBgColor', 'pageHeaderTextColor', 'activityFeedWidgetBgColor', 'activityFeedWidgetTextColor', 'backgroundImg', 'backgroundTiling', 'pageOpacity', 'themeName', 'private', 'owner', 'loginSound', 'notificationSound', 'gridViewRowColorOdd', 'gridViewRowColorEven', 'enableLoginBgImage')))), 'JSONFieldsDefaultValuesBehavior' => array('class' => 'application.components.JSONFieldsDefaultValuesBehavior', 'transformAttributes' => array('miscLayoutSettings' => array('themeSectionExpanded' => true, 'unhideTagsSectionExpanded' => true, 'x2flowShowLabels' => true, 'profileInfoIsMinimized' => false, 'perStageWorkflowView' => true, 'columnWidth' => 50, 'recordViewColumnWidth' => 65, 'enableTransactionalView' => false, 'enableJournalView' => true, 'viewModeActionSubmenuOpen' => true)), 'maintainCurrentFieldsOrder' => true), 'X2SmartSearchModelBehavior' => array('class' => 'application.components.X2SmartSearchModelBehavior')); }
/** * 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)); }
/** * @param $file string pathname of a css file * @param $lineNumber int lineNumber of the theme tag * @return array of needed items to construct the array seen in {@link scanCssFile}. */ public function makeRule($file, $lineNumber) { $lines = file($file); $themeLine = $lines[$lineNumber]; // print_r($themeLine);/ $stripped = preg_replace('/.*@theme\\ *(.*)\\*\\//', '\\1', $themeLine); // Remove extra spaces in between $stripped = preg_replace('/\\ \\ */', ' ', $stripped); $stripped = preg_replace('/:/', '', $stripped); $params = split(' ', $stripped); while (!preg_match('/{/', $lines[$lineNumber])) { $lineNumber--; } $selector = $lines[$lineNumber]; $comment = $lines[$lineNumber - 1]; $rule = $params[0]; $value = $params[1]; // Throw exception if it is not a valid key if (!in_array($value, ThemeGenerator::getProfileKeys())) { $comment = preg_replace('/\\/\\*(.*)\\*\\//', '\\1', $comment); throw new Exception("\nTheme Key '{$value}' is not a valid key.\nFound at{$comment}"); } return array($selector, $comment, array('rule' => $rule, 'value' => $value)); }