📄 wbbuserdataprovider.class.php
字号:
<?php
include_once( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
/**
* Model representing the users in our application. Provides the methods such as
* authentication and querying for users.
*
* \ingroup User_Data_Providers
*/
class WBBUserDataProvider extends BaseUserDataProvider
{
var $_db;
var $_prefix;
var $_blogtitle_postfix;
var $_adminusergroups;
/**
* Initializes the model
*/
function WBBUserDataProvider( $providerConfig )
{
$this->BaseUserDataProvider( $providerConfig );
// initialize the database connection based on our parameters
$config = $this->getProviderConfiguration();
$user = $config->getValue( "user" );
$pass = $config->getValue( "password" );
$host = $config->getValue( "host" );
$db = $config->getValue( "database" );
$this->_wbbprefix = $config->getValue( "prefix" );
$this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );
$this->_blogtitle_postfix = $config->getValue( "blogtitle_postfix" );
$this->_adminusergroups = $config->getValue( "admingroup");
}
/**
* Returns true if the user is in the database and the username
* and password match
*
* @param user Username of the user who we'd like to authenticate
* @param pass Password of the user
* @return true if user and password correct or false otherwise.
*/
function authenticateUser( $user, $pass )
{
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
AND password = '".md5( $pass )."' AND activation > 0";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$ret = ($result->RecordCount() == 1);
$result->Close();
if($ret)
return true;
else
return false;
}
/**
* Returns all the information associated to the user given
*
* @param user Username of the user from who we'd like to get the information
* @param pass Password of the user we'd like to get the information
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfo( $user, $pass )
{
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
AND password = '".md5( $pass )."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$row = $result->FetchRow();
$result->Close();
return( $this->_mapUserInfoObject( $row ));
}
/**
* Retrieves the user information but given only a username
*
* @param username The username of the user
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfoFromUsername( $username )
{
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $username )."'";
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
if( $result->RowCount() == 0 ){
$result->Close();
return false;
}
$row = $result->FetchRow();
$result->Close();
return( $this->_mapUserInfoObject( $row ));
}
/**
* Retrieves the user infromation but given only a userid
*
* @param userId User ID of the user from whom we'd like to get the information
* @return Returns a UserInfo object with the requested information, or false otherwise.
*/
function getUserInfoFromId( $userid, $extendedInfo = false )
{
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
$query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid = '".Db::qstr( $userid )."'";
//print("user__id = $userid");
$result = $this->_dbc->Execute( $query );
if( !$result )
return false;
$row = $result->FetchRow();
$result->Close();
// fetch the user permissions
//$perms = new UserPermissions();
//$row["site_admin"] = $perms->isSiteAdmin( $userid );
return( $this->_mapUserInfoObject( $row ));
}
function WBB2AddBlog( $row )
{
// create a new blog
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
$config =& Config::getConfig();
$locale =& Locales::getLocale( $config->getValue( "default_locale" ));
$blogs = new Blogs();
$blog = new BlogInfo( $row["user"].$this->_blogtitle_postfix, // name of the new blog
$row["id"], // id of the owner
"", // no about
""); // no properties either
$newBlogId = $blogs->addBlog( $blog );
// add a default category and a default post
$articleCategories = new ArticleCategories();
$articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true );
$catId = $articleCategories->addArticleCategory( $articleCategory );
$articleTopic = $locale->tr( "register_default_article_topic" );
$articleText = $locale->tr( "register_default_article_text" );
$article = new Article( $articleTopic,
$articleText,
Array( $catId ),
$row["userid"],
$newBlogId,
POST_STATUS_PUBLISHED,
0,
Array(),
"welcome" );
$t = new Timestamp();
$article->setDateObject( $t );
$articles = new Articles();
$articles->addArticle( $article );
}
function _mapUserInfoObject( $row, $extraInfo = false )
{
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
$plogWBB2Data = $this->getpLogWBBUserData( $row["userid"] );
$row["user"] = $row["username"];
$row["password"] = $row["password"];
$row["email"] = $row["email"];
$row["about"] = $plogWBB2Data["about"];
$row["full_name"] = $plogWBB2Data["full_name"];
$row["resource_picture_id"] = $plogWBB2Data["resource_picture_id"];
if( $row["resource_picture_id"] == "" ) $row["resource_picture_id"] = 0;
$row["properties"] = serialize(Array());
$row["id"] = $row["userid"];
$row["status"] = ($row["activation"] > 0) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
if (in_array($row["groupcombinationid"], $this->_adminusergroups)) $row["site_admin"] = '1';
else $row["site_admin"] = '0';
// does this wbb user have a blog yet? If so, create one if the configuration
// of the user data provider says so
$providerConfig = $this->getProviderConfiguration();
if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
$userInfo = BaseUserDataProvider::mapRow( $row, true );
// check if this user is assigned to any blog
$userBlogs = $userInfo->getBlogs();
if( empty($userBlogs )) {
$this->WBB2AddBlog( $row );
$userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
}
}
else {
$userInfo = BaseUserDataProvider::mapRow( $row );
}
return( $userInfo );
}
/**
* Returns an array with all the users available in the database
*
* @param status
* @param includeExtraInfo
* @param page
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -