📄 wbbuserdataprovider.class.php
字号:
* @param itemsPerPage
* @return An array containing all the users.
*/
function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid >= 0 ORDER BY userid ASC";
$result = $this->_dbc->Execute( $query, $page, $itemsPerPage );
$users = Array();
while ($info = $result->FetchRow( $result ))
array_push( $users, $this->_mapUserInfoObject( $info ));
$result->Close();
return $users;
}
/**
* Updates the information related to a user
*
* @param userInfo An UserInfo object containing the <b>already udpated</b> information of the
* user we would like to update.
* @return Returns true if ok or false otherwise.
*/
function updateUser( $userInfo )
{
$query = "UPDATE ".$this->_wbbprefix."users SET
username = '".Db::qstr($userInfo->getUserName())."',
email = '".Db::qstr($userInfo->getEmail())."',
password = '".md5(Db::qstr($userInfo->getPassword()))."',
sha1_password = '".sha1(Db::qstr($userInfo->getPassword()))."'
WHERE userid = '".Db::qstr($userInfo->getId())."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
BaseUserDataProvider::updateUser( $userInfo );
// update plog's wbb_user table
$result = $this->updatepLogWBBUserData( $userInfo );
return( $result );
}
/**
* @private
* Why the hell couldn't they make the user_id field auto-incrementable???
*/
function getLastWBBUserId()
{
$query = "SELECT MAX(userid)+1 AS next_id FROM ".$this->_wbbprefix."users";
$result = $this->_dbc->Execute( $query );
$row = $result->FetchRow();
$result->Close();
return( $row["next_id"] );
}
/**
* Adds a user to the database.
*
* @param user An UserInfo object with the necessary information
* @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the
* UserInfo object passed by parameter and set its database id.
*/
function addUser( &$user )
{
// update the wbb table
$password = $user->getPassword();
$id = $this->getLastWBBUserId();
$query = "INSERT INTO ".$this->_wbbprefix."users (userid,username,password,sha1_password,email,groupcombinationid,rankid,regdate,lastvisit,lastactivity,usertext,signature,icq,aim,yim,msn,homepage,birthday,gender,showemail,admincanemail,usercanemail,invisible,usecookies,styleid,activation,daysprune,timezoneoffset,startweek,dateformat,timeformat,emailnotify,notificationperpm,receivepm,emailonpm,pmpopup,umaxposts,showsignatures,showavatars,showimages,threadview,langid,rankgroupid,useronlinegroupid,allowsigsmilies,allowsightml,allowsigbbcode,allowsigimages,usewysiwyg,reg_ipaddress) ".
"VALUES ($id,'".Db::qstr($user->getUserName())."','".md5($user->getPassword())."', '".sha1($user->getPassword())."', '".Db::qstr($user->getEmail())."','4','4','".time()."','".time()."','".time()."','','','','','','','','0000-00-00','0','1','1','1','0','1','0','1','0','1','0','','','0','1','1','0','1','0','1','1','1','0','0','4','4','1','0','1','1','0', '".addslashes($REMOTE_ADDR)."');";
$result = $this->_dbc->Execute( $query );
$query1 = "INSERT INTO ".$this->_wbbprefix."userfields (userid) VALUES ($id);";
$result1 = $this->_dbc->Execute( $query1 );
$query2 = "INSERT INTO ".$this->_wbbprefix."user2groups (userid,groupid) VALUES ('".$id."','4');";
$result2 = $this->_dbc->Execute( $query2 );
$query3 = "UPDATE ".$this->_wbbprefix."stats SET usercount=usercount+1, lastuserid='".$id."';";
$result3 = $this->_dbc->Execute( $query3 );
if( !$result || !$result1 || !$result2 || !$result3)
return false;
$user->setId( $id );
// update plog's wbb2_user table
$this->updatepLogWBBUserData( $user );
return( $id );
}
/**
* @private
* Updates the plog-specific user data that is used when the wbb2 integration is enabled, since
* plog has some extra information that does not fit anywhere in wbb2
*
* @param user A UserInfo object
* @return true if successful or false otherwise
*/
function updatepLogWBBUserData( &$user )
{
// is the user already there?
if( $this->getpLogWBBUserData( $user->getId())) {
// we need to run an UPDATE query...
$query = "UPDATE ".$this->getPrefix()."phpbb2_users
SET full_name = '".Db::qstr( $user->getFullName())."',
about = '".Db::qstr( $user->getAboutMyself())."',
properties = '".Db::qstr( serialize($user->getProperties()))."',
resource_picture_id = '".Db::qstr( $user->getPictureId())."',
status = '".Db::qstr( $user->getStatus())."'
WHERE phpbb_id = '".Db::qstr( $user->getId())."'";
}
else {
// we need to run an INSERT query...
$query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
(full_name, about, properties, resource_picture_id,phpbb_id,status)
VALUES ('".Db::qstr( $user->getFullName())."', '".
Db::qstr($user->getAboutMyself())."','".
Db::qstr(serialize($user->getProperties()))."','".
Db::qstr($user->getPictureId())."','".
Db::qstr($user->getId())."','".
Db::qstr($user->getStatus())."');";
}
$result = $this->Execute( $query );
return( true );
}
/**
* @private
* Load the plog-specific wbb2 user data
*
* @param userId
* @return A row with the extra user data or false otherwise
*/
function getpLogWBBUserData( $userId )
{
$query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
$result = $this->Execute( $query );
if( !$result )
return false;
if( $result->RowCount() == 0 ){
$result->Close();
return false;
}
$ret = $result->FetchRow();
$result->Close();
return $ret;
}
/**
* Removes users from the database
*
* @param userId The identifier of the user we are trying to remove
*/
function deleteUser( $userId )
{
}
/**
* returns the total number of users
*
* @return total number of users
*/
function getNumUsers( $status = USER_STATUS_ALL )
{
//
// :TODO:
// add the status check here!
//
$query = "SELECT COUNT(id) AS total FROM ".$this->_wbbprefix."users";
$result = $this->_dbc->Execute( $query );
// return no users if this doesn't work!
if( !$result )
return 0;
$row = $result->FetchRow();
$result->Close();
if( $row["total"] == "" )
$row["total"] = 0;
return( $row["total"] );
}
/**
* check if the email account has been registered
* @return true if the email account has been registered
*/
function emailExists($email)
{
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE email = '".Db::qstr($email)."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$ret = ($result->RecordCount() > 0);
$result->Close();
return $ret;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -