00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
00005
00012 class WBBUserDataProvider extends BaseUserDataProvider
00013 {
00014 var $_db;
00015 var $_prefix;
00016 var $_blogtitle_postfix;
00017 var $_adminusergroups;
00021 function WBBUserDataProvider( $providerConfig )
00022 {
00023 $this->BaseUserDataProvider( $providerConfig );
00024
00025
00026 $config = $this->getProviderConfiguration();
00027 $user = $config->getValue( "user" );
00028 $pass = $config->getValue( "password" );
00029 $host = $config->getValue( "host" );
00030 $db = $config->getValue( "database" );
00031 $this->_wbbprefix = $config->getValue( "prefix" );
00032
00033 $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );
00034 $this->_blogtitle_postfix = $config->getValue( "blogtitle_postfix" );
00035 $this->_adminusergroups = $config->getValue( "admingroup");
00036 }
00037
00046 function authenticateUser( $user, $pass )
00047 {
00048 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
00049 AND password = '".md5( $pass )."' AND activation > 0";
00050
00051 $result = $this->_dbc->Execute( $query );
00052
00053 if( !$result )
00054 return false;
00055
00056 $ret = ($result->RecordCount() == 1);
00057 $result->Close();
00058
00059 if($ret)
00060 return true;
00061 else
00062 return false;
00063 }
00064
00072 function getUserInfo( $user, $pass )
00073 {
00074 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
00075 AND password = '".md5( $pass )."'";
00076
00077 $result = $this->_dbc->Execute( $query );
00078
00079 if( !$result )
00080 return false;
00081
00082 $row = $result->FetchRow();
00083 $result->Close();
00084
00085 return( $this->_mapUserInfoObject( $row ));
00086 }
00087
00094 function getUserInfoFromUsername( $username )
00095 {
00096 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $username )."'";
00097
00098 $result = $this->_dbc->Execute( $query );
00099
00100 if( !$result )
00101 return false;
00102
00103 if( $result->RowCount() == 0 ){
00104 $result->Close();
00105 return false;
00106 }
00107
00108 $row = $result->FetchRow();
00109 $result->Close();
00110
00111 return( $this->_mapUserInfoObject( $row ));
00112 }
00113
00120 function getUserInfoFromId( $userid, $extendedInfo = false )
00121 {
00122 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00123
00124 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid = '".Db::qstr( $userid )."'";
00125
00126
00127
00128 $result = $this->_dbc->Execute( $query );
00129
00130 if( !$result )
00131 return false;
00132
00133 $row = $result->FetchRow();
00134 $result->Close();
00135
00136
00137
00138
00139
00140 return( $this->_mapUserInfoObject( $row ));
00141 }
00142
00143 function WBB2AddBlog( $row )
00144 {
00145
00146 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
00147 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00148 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00149 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00150
00151 $config =& Config::getConfig();
00152 $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
00153
00154 $blogs = new Blogs();
00155 $blog = new BlogInfo( $row["user"].$this->_blogtitle_postfix,
00156 $row["id"],
00157 "",
00158 "");
00159 $newBlogId = $blogs->addBlog( $blog );
00160
00161
00162 $articleCategories = new ArticleCategories();
00163 $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true );
00164 $catId = $articleCategories->addArticleCategory( $articleCategory );
00165 $articleTopic = $locale->tr( "register_default_article_topic" );
00166 $articleText = $locale->tr( "register_default_article_text" );
00167 $article = new Article( $articleTopic,
00168 $articleText,
00169 Array( $catId ),
00170 $row["userid"],
00171 $newBlogId,
00172 POST_STATUS_PUBLISHED,
00173 0,
00174 Array(),
00175 "welcome" );
00176 $t = new Timestamp();
00177 $article->setDateObject( $t );
00178 $articles = new Articles();
00179 $articles->addArticle( $article );
00180 }
00181
00182 function _mapUserInfoObject( $row, $extraInfo = false )
00183 {
00184 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00185
00186 $plogWBB2Data = $this->getpLogWBBUserData( $row["userid"] );
00187
00188 $row["user"] = $row["username"];
00189 $row["password"] = $row["password"];
00190 $row["email"] = $row["email"];
00191 $row["about"] = $plogWBB2Data["about"];
00192 $row["full_name"] = $plogWBB2Data["full_name"];
00193 $row["resource_picture_id"] = $plogWBB2Data["resource_picture_id"];
00194 if( $row["resource_picture_id"] == "" ) $row["resource_picture_id"] = 0;
00195 $row["properties"] = serialize(Array());
00196 $row["id"] = $row["userid"];
00197 $row["status"] = ($row["activation"] > 0) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
00198 if (in_array($row["groupcombinationid"], $this->_adminusergroups)) $row["site_admin"] = '1';
00199 else $row["site_admin"] = '0';
00200
00201
00202
00203 $providerConfig = $this->getProviderConfiguration();
00204 if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
00205 $userInfo = BaseUserDataProvider::mapRow( $row, true );
00206
00207 $userBlogs = $userInfo->getBlogs();
00208 if( empty($userBlogs )) {
00209
00210 $this->grantLoginPermission( $userInfo );
00211
00212 $this->WBB2AddBlog( $row );
00213 $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
00214 }
00215 }
00216 else {
00217 $userInfo = BaseUserDataProvider::mapRow( $row );
00218 }
00219
00220 return( $userInfo );
00221 }
00222
00232 function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
00233 {
00234 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid >= 0 ORDER BY userid ASC";
00235
00236 $result = $this->_dbc->Execute( $query, $page, $itemsPerPage );
00237
00238 $users = Array();
00239
00240 while ($info = $result->FetchRow( $result ))
00241 array_push( $users, $this->_mapUserInfoObject( $info ));
00242 $result->Close();
00243
00244 return $users;
00245 }
00246
00254 function updateUser( $userInfo )
00255 {
00256 $query = "UPDATE ".$this->_wbbprefix."users SET
00257 username = '".Db::qstr($userInfo->getUserName())."',
00258 email = '".Db::qstr($userInfo->getEmail())."',
00259 password = '".md5(Db::qstr($userInfo->getPassword()))."',
00260 sha1_password = '".sha1(Db::qstr($userInfo->getPassword()))."'
00261 WHERE userid = '".Db::qstr($userInfo->getId())."'";
00262
00263 $result = $this->_dbc->Execute( $query );
00264
00265 if( !$result )
00266 return false;
00267
00268 BaseUserDataProvider::updateUser( $userInfo );
00269
00270
00271 $result = $this->updatepLogWBBUserData( $userInfo );
00272
00273 return( $result );
00274 }
00275
00280 function getLastWBBUserId()
00281 {
00282 $query = "SELECT MAX(userid)+1 AS next_id FROM ".$this->_wbbprefix."users";
00283
00284 $result = $this->_dbc->Execute( $query );
00285
00286 $row = $result->FetchRow();
00287 $result->Close();
00288
00289 return( $row["next_id"] );
00290 }
00291
00299 function addUser( &$user )
00300 {
00301
00302 $password = $user->getPassword();
00303 $id = $this->getLastWBBUserId();
00304
00305 $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) ".
00306 "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($_SERVER['REMOTE_ADDR'])."');";
00307
00308 $result = $this->_dbc->Execute( $query );
00309
00310 $query1 = "INSERT INTO ".$this->_wbbprefix."userfields (userid) VALUES ($id);";
00311 $result1 = $this->_dbc->Execute( $query1 );
00312
00313
00314 $query2 = "INSERT INTO ".$this->_wbbprefix."user2groups (userid,groupid) VALUES ('".$id."','4');";
00315 $result2 = $this->_dbc->Execute( $query2 );
00316
00317 $query3 = "UPDATE ".$this->_wbbprefix."stats SET usercount=usercount+1, lastuserid='".$id."';";
00318 $result3 = $this->_dbc->Execute( $query3 );
00319
00320 if( !$result || !$result1 || !$result2 || !$result3)
00321 return false;
00322
00323 $user->setId( $id );
00324
00325
00326 $this->updatepLogWBBUserData( $user );
00327
00328 return( $id );
00329 }
00330
00339 function updatepLogWBBUserData( &$user )
00340 {
00341
00342 if( $this->getpLogWBBUserData( $user->getId())) {
00343
00344 $query = "UPDATE ".$this->getPrefix()."phpbb2_users
00345 SET full_name = '".Db::qstr( $user->getFullName())."',
00346 about = '".Db::qstr( $user->getAboutMyself())."',
00347 properties = '".Db::qstr( serialize($user->getProperties()))."',
00348 resource_picture_id = '".Db::qstr( $user->getPictureId())."',
00349 status = '".Db::qstr( $user->getStatus())."'
00350 WHERE phpbb_id = '".Db::qstr( $user->getId())."'";
00351 }
00352 else {
00353
00354 $query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
00355 (full_name, about, properties, resource_picture_id,phpbb_id,status)
00356 VALUES ('".Db::qstr( $user->getFullName())."', '".
00357 Db::qstr($user->getAboutMyself())."','".
00358 Db::qstr(serialize($user->getProperties()))."','".
00359 Db::qstr($user->getPictureId())."','".
00360 Db::qstr($user->getId())."','".
00361 Db::qstr($user->getStatus())."');";
00362 }
00363
00364 $result = $this->Execute( $query );
00365
00366 return( true );
00367 }
00368
00376 function getpLogWBBUserData( $userId )
00377 {
00378 $query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
00379
00380 $result = $this->Execute( $query );
00381
00382 if( !$result )
00383 return false;
00384
00385 if( $result->RowCount() == 0 ){
00386 $result->Close();
00387 return false;
00388 }
00389
00390 $ret = $result->FetchRow();
00391 $result->Close();
00392
00393 return $ret;
00394 }
00395
00401 function deleteUser( $userId )
00402 {
00403 }
00404
00410 function getNumUsers( $status = USER_STATUS_ALL )
00411 {
00412
00413
00414
00415
00416 $query = "SELECT COUNT(id) AS total FROM ".$this->_wbbprefix."users";
00417
00418 $result = $this->_dbc->Execute( $query );
00419
00420
00421 if( !$result )
00422 return 0;
00423
00424 $row = $result->FetchRow();
00425 $result->Close();
00426
00427 if( $row["total"] == "" )
00428 $row["total"] = 0;
00429
00430 return( $row["total"] );
00431 }
00432
00437 function emailExists($email)
00438 {
00439 $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE email = '".Db::qstr($email)."'";
00440
00441 $result = $this->_dbc->Execute( $query );
00442
00443 if( !$result )
00444 return false;
00445 $ret = ($result->RecordCount() > 0);
00446 $result->Close();
00447 return $ret;
00448 }
00449 }
00450 ?>