예제 #1
0
 /**
  * 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->quoteName('userid') . ' as _userid , ' . '	a.' . $db->quoteName('status') . ' as _status , ' . '	a.' . $db->quoteName('points') . '	as _points, ' . '	a.' . $db->quoteName('posted_on') . ' as _posted_on, ' . '	a.' . $db->quoteName('avatar') . '	as _avatar , ' . '	a.' . $db->quoteName('cover') . '	as _cover , ' . '	a.' . $db->quoteName('thumb') . '	as _thumb , ' . '	a.' . $db->quoteName('invite') . '	as _invite, ' . '	a.' . $db->quoteName('params') . '	as _cparams,  ' . '	a.' . $db->quoteName('view') . '	as _view, ' . ' a.' . $db->quoteName('friends') . ' as _friends, ' . ' a.' . $db->quoteName('groups') . ' as _groups, ' . ' a.' . $db->quoteName('events') . ' as _events, ' . ' a.' . $db->quoteName('friendcount') . ' as _friendcount, ' . ' a.' . $db->quoteName('alias') . ' as _alias, ' . ' a.' . $db->quoteName('profile_id') . ' as _profile_id, ' . ' a.' . $db->quoteName('storage') . ' as _storage, ' . ' a.' . $db->quoteName('watermark_hash') . ' as _watermark_hash, ' . ' a.' . $db->quoteName('search_email') . ' as _search_email, ' . ' s.' . $db->quoteName('userid') . ' as _isonline, u.* ' . ' FROM ' . $db->quoteName('#__community_users') . ' as a ' . ' LEFT JOIN ' . $db->quoteName('#__users') . ' u ' . ' ON u.' . $db->quoteName('id') . '=a.' . $db->quoteName('userid') . ' LEFT OUTER JOIN ' . $db->quoteName('#__session') . ' s ' . ' ON s.' . $db->quoteName('userid') . '=a.' . $db->quoteName('userid') . ' AND s.' . $db->quoteName('client_id') . ' !=' . $db->Quote('1') . ' WHERE a.' . $db->quoteName('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->quoteName('#__users') . ' ' . 'WHERE ' . $db->quoteName('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' , 'notificationtypes' );
                     $notificationtypes = new CNotificationTypes();
                     $obj->params .= $notificationtypes->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);
                 /* Temporary fix for Joomla! 3.2 when save user without groups array in object */
                 if (is_array($this->groups) && count($this->groups) == 0 && (JVERSION > 3.1 && JVERSION < 3.3)) {
                     $params = JComponentHelper::getParams('com_users');
                     /**
                      * @todo Should we remove these when Joomla! fixed their issue
                      */
                     if (isset($query)) {
                         unset($query);
                     }
                     if (isset($result)) {
                         unset($result);
                     }
                     $query = $db->getQuery(true);
                     $query = 'SELECT ' . $db->quoteName('group_id') . ' FROM ' . $db->quoteName('#__user_usergroup_map') . ' WHERE ' . $db->quoteName('user_id') . '=' . (int) $this->id;
                     $db->setQuery($query);
                     $result = $db->loadColumn();
                     if (is_null($result)) {
                         // Get the default new user group, Registered if not specified.
                         $result = array($params->get('new_usertype', 2));
                     }
                     $this->groups = $result;
                 }
                 $this->save();
             }
             // Set FB post param to default system value if it is not yet set
             if (is_null($this->_cparams->get('postFacebookStatus', 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;
 }