/** * Constructor * Sets the default basePath to webroot.themes.{{themename}} */ public function init() { Yii::app()->language = Cii::setApplicationLanguage(); parent::init(); if (isset(Yii::app()->theme) && isset(Yii::app()->theme->name)) { $this->basePath = Yii::getPathOfAlias('base.themes.' . Yii::app()->theme->name . '.messages'); } else { if (isset(Yii::app()->controller->module->id)) { $this->basePath = Yii::getPathOfAlias('application.modules.' . Yii::app()->controller->module->id); } else { $this->basePath = Yii::getPathOfAlias('application.modules.install'); } } }
/** * Loads the user information */ public static function loadUserInfo() { if (defined('CIIMS_INSTALL')) { return; } if (isset(Yii::app()->user)) { // Load some specific CiiMS JS here $json = CJSON::encode(array('email' => Cii::get(Yii::app()->user, 'email'), 'token' => Cii::getUserConfig('api_key', false), 'role' => Cii::get(Yii::app()->user, 'role'), 'isAuthenticated' => isset(Yii::app()->user->id), 'debug' => YII_DEBUG, 'time' => time(), 'version' => YII_DEBUG ? Cii::getVersion() : null, 'language' => Cii::setApplicationLanguage(), 'hosted' => defined('CII_CONFIG'), 'api' => Yii::app()->getBaseUrl(true) . '/api')); Yii::app()->clientScript->registerScript('ciims', "\n localStorage.setItem('ciims', '{$json}');\n ", CClientScript::POS_HEAD); } }
/** * BeforeAction method * The events defined here occur before every controller action that extends CiiController occurs. * This method will run the following tasks: * - Set the language for i18n * - Apply the correct theme * @param CAction $action The details of the action we want to run * @return CController::beforeAction($action) */ public function beforeAction($action) { try { if (Yii::app()->params['NewRelicAppName'] !== null) { $name = Yii::app()->params['NewRelicAppName']; } else { $name = Cii::getConfig('name', Yii::app()->name); } @Yii::app()->newRelic->setAppName($name); @Yii::app()->newRelic->setTransactionName($this->id, $action->id); } catch (Exception $e) { } // De-authenticate pre-existing sessions if (!Yii::app()->user->isGuest) { $apiKey = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => Yii::app()->user->id, 'key' => 'api_key'), array('value' => NULL)); if ($apiKey == NULL || !empty($apiKey->value)) { $activeSessionId = Yii::app()->cache->get($apiKey->value); if ($activeSessionId !== session_id()) { Yii::app()->cache->delete(Yii::app()->user->apiKey); Yii::app()->user->logout(); } } } // Sets the application language Cii::setApplicationLanguage(); // Sets the global theme for CiiMS $this->getTheme(); return parent::beforeAction($action); }