<?php class PanelModule extends CWebModule { /** * @var string * @desc hash method (md5,sha1 or algo hash function http://www.php.net/manual/en/function.hash.php) */ public $hash='md5'; /** * @var array * @desc Profile model relation from other models */ public $profileRelations = array(); public $fieldsMessage = ''; /** * @var int * @desc Remember Me Time (seconds), defalt = 2592000 (30 days) */ public $rememberMeTime = 2592000; // 30 days public $returnUrl = array("dashboard/index"); public $returnUrl2 = array("../CyT/default/index"); public function init() { // this method is called when the module is being created // you may place code here to customize the module or the application // import the module-level models and components $this->setImport(array( 'panel.models.*', 'panel.components.*', )); } public function beforeControllerAction($controller, $action) { if(parent::beforeControllerAction($controller, $action)) { // this method is called before any module controller action is performed // you may place customized code here return true; } else return false; } /** * @return hash string. */ public static function encrypting($string="", $salt="") { $hash = Yii::app()->getModule('panel')->hash; if ($hash=="md5") return md5($string); if ($hash=="sha1") return sha1($string); if ($hash=='blowfish' && $salt=='') return crypt($string, Randomness::blowfishSalt()); if ($hash=='blowfish' && !empty($salt)) return crypt($string, $salt); else return hash($hash,$string); } /** * Return safe user data. * @param user id not required * @return user object or false */ static private $_users=array(); public static function user($id=0,$clearCache=false) { if (!$id&&!Yii::app()->user->isGuest) $id = Yii::app()->user->id; if ($id) { if (!isset(self::$_users[$id])||$clearCache) self::$_users[$id] = User::model()->with(array('profile'))->findbyPk($id); return self::$_users[$id]; } else return false; } /** * @var array * @desc Behaviors for models */ public $componentBehaviors=array(); public function getBehaviorsFor($componentName){ if (isset($this->componentBehaviors[$componentName])) { return $this->componentBehaviors[$componentName]; } else { return array(); } } }