コード例 #1
0
ファイル: user.php プロジェクト: Simarpreet05/joomla
 /**
  * Inititalize the user JUser object
  * return true if the user is a new
  */
 public function init($initObj = null)
 {
     $isNewUser = false;
     if (!$this->_init) {
         $config = CFactory::getConfig();
         $db =& JFactory::getDBO();
         $obj = $initObj;
         if ($initObj == null) {
             $query = 'SELECT  ' . '	a.' . $db->nameQuote('userid') . ' as _userid , ' . '	a.' . $db->nameQuote('status') . ' as _status , ' . '	a.' . $db->nameQuote('points') . '	as _points, ' . '	a.' . $db->nameQuote('posted_on') . ' as _posted_on, ' . '	a.' . $db->nameQuote('avatar') . '	as _avatar , ' . '	a.' . $db->nameQuote('thumb') . '	as _thumb , ' . '	a.' . $db->nameQuote('invite') . '	as _invite, ' . '	a.' . $db->nameQuote('params') . '	as _cparams,  ' . '	a.' . $db->nameQuote('view') . '	as _view, ' . ' a.' . $db->nameQuote('friends') . ' as _friends, ' . ' a.' . $db->nameQuote('groups') . ' as _groups, ' . ' a.' . $db->nameQuote('events') . ' as _events, ' . ' a.' . $db->nameQuote('friendcount') . ' as _friendcount, ' . ' a.' . $db->nameQuote('alias') . ' as _alias, ' . ' a.' . $db->nameQuote('profile_id') . ' as _profile_id, ' . ' a.' . $db->nameQuote('storage') . ' as _storage, ' . ' a.' . $db->nameQuote('watermark_hash') . ' as _watermark_hash, ' . ' a.' . $db->nameQuote('search_email') . ' as _search_email, ' . ' s.' . $db->nameQuote('userid') . ' as _isonline, u.* ' . ' FROM ' . $db->nameQuote('#__community_users') . ' as a ' . ' LEFT JOIN ' . $db->nameQuote('#__users') . ' u ' . ' ON u.' . $db->nameQuote('id') . '=a.' . $db->nameQuote('userid') . ' LEFT OUTER JOIN ' . $db->nameQuote('#__session') . ' s ' . ' ON s.' . $db->nameQuote('userid') . '=a.' . $db->nameQuote('userid') . ' AND s.' . $db->nameQuote('client_id') . ' !=' . $db->Quote('1') . ' WHERE a.' . $db->nameQuote('userid') . '=' . $db->Quote($this->id);
             $db->setQuery($query);
             $obj = $db->loadObject();
             if ($db->getErrorNum()) {
                 JError::raiseError(500, $db->stderr());
             }
         }
         // Initialise new user
         if (empty($obj)) {
             if (!$obj && $this->id != 0) {
                 // @rule: ensure that the id given is correct and exists in #__users
                 $existQuery = 'SELECT COUNT(1) FROM ' . $db->nameQuote('#__users') . ' ' . 'WHERE ' . $db->nameQuote('id') . '=' . $db->Quote($this->id);
                 $db->setQuery($existQuery);
                 $isValid = $db->loadResult() > 0 ? true : false;
                 if ($isValid) {
                     // We need to create a new record for this specific user first.
                     $obj = new stdClass();
                     $obj->userid = $this->id;
                     $obj->points = $this->_points;
                     $obj->thumb = '';
                     $obj->avatar = '';
                     // Load default params
                     $obj->params = "notifyEmailSystem=" . $config->get('privacyemail') . "\n" . "privacyProfileView=" . $config->get('privacyprofile') . "\n" . "privacyPhotoView=" . $config->get('privacyphotos') . "\n" . "privacyFriendsView=" . $config->get('privacyfriends') . "\n" . "privacyGroupsView=" . $config->get('privacy_groups_list') . "\n" . "privacyVideoView=" . $config->get('privacyvideos') . "\n" . "notifyEmailMessage=" . $config->get('privacyemailpm') . "\n" . "notifyEmailApps=" . $config->get('privacyapps') . "\n" . "notifyWallComment=" . $config->get('privacywallcomment') . "\n";
                     //load default email privacy settings
                     CFactory::load('libraries', 'emailtypes');
                     $emailtypes = new CEmailTypes();
                     $obj->params .= $emailtypes->convertToParamsString();
                     $db->insertObject('#__community_users', $obj);
                     if ($db->getErrorNum()) {
                         JError::raiseError(500, $db->stderr());
                     }
                     // Reload the object
                     $db->setQuery($query);
                     $obj = $db->loadObject();
                     $isNewUser = true;
                 }
             }
         }
         if ($obj) {
             $thisVars = get_object_vars($this);
             // load cparams
             $this->_cparams = new CParameter($obj->_cparams);
             // fix a bug where privacyVideoView = 1
             if ($this->_cparams->get('privacyVideoView') == 1) {
                 $this->_cparams->set('privacyVideoView', 0);
             }
             unset($obj->_cparams);
             // load user params
             $this->_params = new CParameter($obj->params);
             unset($obj->params);
             foreach ($thisVars as $key => $val) {
                 if (isset($obj->{$key})) {
                     $this->{$key} = $obj->{$key};
                 }
             }
             #correct the friendcount here because blocked user are still counted in "friendcount"
             //$model	= CFactory::getModel( 'friends' );
             //$realfriendcount = $model->getFriendsCount($this->id);
             //$this->_friendcount = $realfriendcount;
             // Update group list if we haven't get
             if ($this->_params->get('update_cache_list', 0) == 0) {
                 //dont load updateGroupList in the backend
                 if (strpos(JURI::current(), 'administrator') == false) {
                     $this->updateGroupList();
                     $this->updateEventList();
                 }
                 $this->_params->set('update_cache_list', 1);
                 $this->save();
             }
             // Set FB post param to default system value if it is not yet set
             if ($this->_cparams->get('postFacebookStatus', null) == null) {
                 $this->_cparams->set('postFacebookStatus', $config->get('fbconnectpoststatus'));
             }
         } else {
             // this is a visitor, we still have to create params object for them
             $this->_cparams = new CParameter('');
             $this->_params = new CParameter('');
         }
         $this->_init = true;
     }
     return $isNewUser;
 }