📄 vbb3userdataprovider.class.php
字号:
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 )
{
BaseUserDataProvider::updateUser( $userInfo );
return $this->updatepLogPHPBB2UserData( $userInfo ); //nerver change data in vbb table , just return the updatepLogPHPBB2UserData' return value
$query = "UPDATE ".$this->_vbb3prefix."user SET
username = '".Db::qstr($userInfo->getUserName())."',
email = '".Db::qstr($userInfo->getEmail())."',
//user_active = '".Db::qstr($userInfo->getPassword())."'
WHERE userid = '".Db::qstr($userInfo->getId())."'";//todo
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
BaseUserDataProvider::updateUser( $userInfo );
// update plog's phpbb2_user table
$result = $this->updatepLogPHPBB2UserData( $userInfo );
return( $result );
}
/**
* @private
* Why the hell couldn't they make the user_id field auto-incrementable???
*/
function getLastPhpBBUserId()
{
$query = "SELECT MAX(userid)+1 AS next_id FROM ".$this->_vbb3prefix."user";
$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 )
{
return false; //nerver change data in vbb table , just tell pblog can not do that
$password = $user->getPassword();
$id = $this->getLastPhpBBUserId();
$query = "INSERT INTO ".$this->_vbb3prefix."user (userid,username,password,useremail)
VALUES ($id, '".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','".
Db::qstr($user->getEmail())."');";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$user->setId( $id );
// update plog's phpbb2_user table
$this->updatepLogPHPBB2UserData( $user );
return( $id );
}
/**
* @private
* Updates the plog-specific user data that is used when the vbb3 integration is enabled, since
* plog has some extra information that does not fit anywhere in vbb3
*
* @param user A UserInfo object
* @return true if successful or false otherwise
*/
function updatepLogPHPBB2UserData( &$user )
{
// is the user already there?
if( $this->getpLogPHPBBUserData( $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 vbb3 user data
*
* @param userId
* @return A row with the extra user data or false otherwise
*/
function getpLogPHPBBUserData( $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 , $searchTerms = "" )
{
$where = "";
switch ($status)
{
case user_status_all:
$where = "";
break;
case user_status_active:
$where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
break;
case user_status_unconfirmed:
case user_status_disabled:
$where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
break;
}
if ($searchTerms != "")
{
if ($where != "")
$where = $where." AND ".$this->getSearchConditions($searchTerms);
else
$where = $this->getSearchConditions($searchTerms);
}
if ($where != "")
$where = " where ".$where;
$query = "SELECT COUNT(userid) AS total FROM ".$this->_vbb3prefix."user".$where;
$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->_vbb3prefix."user WHERE email = '".Db::qstr($email)."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$ret = ($result->RecordCount() > 0);
$result->Close();
return $ret;
}
/**
* @see Model::getSearchConditions
*/
function getSearchConditions( $searchTerms )
{
include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
// prepare the query string
$searchTerms = SearchEngine::adaptSearchString( $searchTerms );
return( "(username LIKE '%".$searchTerms."%')");
}
/**
* Returns an array with all the users that belong to the given
* blog.
*
* @param blogId The blog identifier.
* @param includeOwner Wether to include the owner of the blog or not.
* @param status
* @param searchTerms
* @return An array with the information about the users who belong in
* one way or another to that blog.
*/
function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" )
{
$userids = Array();
$users = Array();
$prefix = $this->getPrefix();
// get the information about the owner, if requested so
if( $includeOwner ) {
$query = "SELECT {$prefix}blogs.owner_id as userid FROM {$prefix}blogs
WHERE {$prefix}blogs.id = '".Db::qstr($blogId)."';";
$result = $this->Execute( $query );
if( !$result )
return $users;
$row = $result->FetchRow();
$result->Close();
array_push($userids,$row['userid']);
}
// now get the other users who have permission for that blog.
$query2 = "SELECT {$prefix}users_permissions.user_id as userid FROM {$prefix}users_permissions
WHERE {$prefix}users_permissions.blog_id = '".Db::qstr($blogId)."';";
$result2 = $this->Execute( $query2 );
if( $result2 )
{
while( $row = $result2->FetchRow()) {
array_push($userids,$row['userid']);
}
$result2->Close();
}
if (!is_array($userids)) //return empty value
{
return $users;
}
$where = "";
switch ($status)
{
case user_status_all:
$where = "";
break;
case user_status_active:
$where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
break;
case user_status_unconfirmed:
case user_status_disabled:
$where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
break;
}
if ($searchTerms != "")
{
if ($where != "")
$where = $where." AND ".($this->getSearchConditions($searchTerms));
else
$where = $this->getSearchConditions($searchTerms);
}
if ($where != "")
$where = $where." AND ";
$where = $where." (userid in (".implode(",", $userids)."))";
if ($where != "")
$where = " where ".$where;
$query3 = "SELECT * FROM ".$this->_vbb3prefix."user".$where." ORDER BY userid ASC";
$result3 = $this->_dbc->Execute( $query3);
while ($info = $result3->FetchRow( $result3 ))
array_push( $users, $this->_mapUserInfoObject( $info ));
$result3->Close();
return $users;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -