/**
  * Renders the change language form and handles its submission
  * @param CFilterChain $filterChain
  * @return boolean whether to continue execution
  */
 protected function preFilter($filterChain)
 {
     if (isset($_POST['ChangeLanguageForm'])) {
         $model = new ChangeLanguageForm();
         $model->attributes = $_POST['ChangeLanguageForm'];
         if ($model->validate()) {
             // Get the display name of the new language
             $languages = LanguageManager::getAvailableLanguages();
             $newLanguage = $languages[$model->language];
             // Update user's default language
             if ($model->setDefault) {
                 $user = User::model()->findByPk(Yii::app()->user->id);
                 $user->language = $model->language;
                 // Don't rehash the password, it hasn't been changed
                 $user->inhibitPasswordHash();
                 $user->save();
             }
             // Update and inform
             Yii::app()->languageManager->setCurrent($model->language);
             Yii::app()->user->setFlash('success', Yii::t('Language', 'Language changed to {newLanguage}', array('{newLanguage}' => $newLanguage)));
         }
     }
     return true;
 }
/* @var $this Controller */
/* @var $model ChangeLanguageForm */
/* @var $form TbActiveForm */
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('layout' => TbHtml::FORM_LAYOUT_HORIZONTAL));
// Cache the contents of the form
$cacheDependency = new CFileCacheDependency(Yii::app()->basePath . '/messages');
$cacheDuration = 60 * 60 * 24 * 365;
if ($this->beginCache('ChangeLanguageModal', array('dependency' => $cacheDependency, 'duration' => $cacheDuration, 'varyByExpression' => function () {
    return implode('_', array(Yii::app()->user->role, Yii::app()->language));
}))) {
    // Notify administrators that changing the language here only affects them
    if (Yii::app()->user->getRole() === User::ROLE_ADMIN) {
        $settingsLink = CHtml::link(Yii::t('Settings', 'Settings'), $this->createUrl('setting/admin'));
        echo FormHelper::helpBlock(Yii::t('Language', 'To change the application language for all users go to {settingsUrl} instead', array('{settingsUrl}' => $settingsLink)));
    }
    echo $form->dropdownListControlGroup($model, 'language', LanguageManager::getAvailableLanguages());
    echo $form->checkboxControlGroup($model, 'setDefault');
    ?>
	<div class="form-actions">
		<?php 
    echo TbHtml::submitButton(Yii::t('ChangeLanguageForm', 'Change language'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY));
    ?>

		<?php 
    echo TbHtml::button(Yii::t('ChangeLanguageForm', 'Close'), array('class' => 'btn-padded', 'color' => TbHtml::BUTTON_COLOR_INFO, 'data-toggle' => 'modal', 'data-target' => '#change-language-modal'));
    ?>
	</div>

	<?php 
    $this->endCache();
}
Beispiel #3
0
    /**
     * Returns the settings definitions
     * @return array
     */
    public function getDefinitions()
    {
        return array('language' => array('label' => Yii::t('Settings', 'Application language'), 'separator' => array('icon' => 'fa fa-pencil-square-o', 'label' => Yii::t('Settings', 'Look and feel')), 'type' => self::TYPE_DROPDOWN, 'default' => 'en', 'description' => Yii::t('Settings', 'Changing this will reset the default language for all users'), 'listData' => LanguageManager::getAvailableLanguages(), 'order' => 50), 'applicationName' => array('label' => Yii::t('Settings', 'Application name'), 'type' => self::TYPE_TEXT, 'default' => 'XBMC Video Server', 'order' => 100), 'applicationSubtitle' => array('label' => Yii::t('Settings', 'Application subtitle'), 'type' => self::TYPE_TEXT, 'default' => Yii::t('Misc', 'Free your library'), 'order' => 125), 'playlistFormat' => array('label' => Yii::t('Settings', 'Playlist format'), 'type' => self::TYPE_DROPDOWN, 'default' => 'm3u', 'listData' => PlaylistFactory::getTypes(), 'order' => 150), 'singleFilePlaylist' => array('label' => Yii::t('Settings', "Don't use playlists when item consists of a single file"), 'type' => self::TYPE_CHECKBOX, 'default' => '0', 'description' => Yii::t('Settings', 'You may have to right-click and copy the address in order to stream (not download) the file'), 'order' => 200), 'showHelpBlocks' => array('label' => Yii::t('Settings', 'Show help blocks throughout the site'), 'type' => self::TYPE_CHECKBOX, 'default' => '1', 'order' => 300), 'pagesize' => array('label' => Yii::t('Settings', 'Amount of results to show per page'), 'type' => self::TYPE_TEXT, 'default' => '60', 'description' => Yii::t('Settings', 'Leave empty to disable pagination altogether'), 'htmlOptions' => array('span' => 1), 'order' => 500), 'ignoreArticle' => array('label' => Yii::t('Settings', 'Ignore article ("the") in results'), 'type' => self::TYPE_CHECKBOX, 'default' => '', 'order' => 550), 'requestTimeout' => array('label' => Yii::t('Settings', 'Request timeout'), 'separator' => array('icon' => 'fa fa-lock', 'label' => Yii::t('Settings', 'Security and performance')), 'type' => self::TYPE_TEXT, 'default' => '30', 'description' => Yii::t('Settings', 'Determines how long the application should wait for a response from XBMC. Increase this if you get timeout errors.'), 'htmlOptions' => array('span' => 1), 'order' => 625), 'cacheApiCalls' => array('label' => Yii::t('Settings', 'Cache all API results'), 'type' => self::TYPE_CHECKBOX, 'default' => '0', 'description' => Yii::t('Settings', 'Useful on slow hardware. A refresh button will appear in the menu which flushes the cache'), 'order' => 650), 'useHttpsForVfsUrls' => array('label' => Yii::t('Settings', 'Use HTTPS when streaming'), 'type' => self::TYPE_CHECKBOX, 'default' => '0', 'description' => Yii::t('Settings', 'When checked, streaming will be done over HTTPS if 
					the application is accessed over HTTPS. This will usually only 
					work if the server uses a real signed certificate, thus it is 
					not enabled by default.'), 'order' => 700), 'allowUserPowerOff' => array('label' => Yii::t('Settings', 'Allow users to power off backends'), 'type' => self::TYPE_CHECKBOX_LIST, 'default' => '', 'listData' => array(Setting::POWER_OPTION_SHUTDOWN => Yii::t('Settings', 'Shutdown'), Setting::POWER_OPTION_SUSPEND => Yii::t('Settings', 'Suspend'), Setting::POWER_OPTION_HIBERNATE => Yii::t('Settings', 'Hibernate'), Setting::POWER_OPTION_REBOOT => Yii::t('Settings', 'Reboot')), 'description' => Yii::t('Settings', 'Administrators are not affected by this setting and can always power off backends.'), 'order' => 750), 'whitelist' => array('label' => Yii::t('Settings', 'Access whitelist'), 'type' => self::TYPE_TEXT_WIDE, 'default' => '', 'description' => Yii::t('Settings', "If specified, access is restricted to the defined \n\t\t\t\t\twhitelist. Valid values are IP addresses, IP subnets and \n\t\t\t\t\tdomain names (including wildcards). Example: 192.168.1.0/24,1.2.3.4,example.com,*.user.com"), 'order' => 800));
    }
 /**
  * @return array the validation rules for this controller
  */
 public function rules()
 {
     return array(array('language, setDefault', 'required'), array('language', 'in', 'range' => array_keys(LanguageManager::getAvailableLanguages())));
 }