00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 lt_include( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
00023 lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
00024
00031 class vbb3UserDataProvider extends BaseUserDataProvider
00032 {
00033 var $_dbc;
00034 var $_vbb3prefix;
00035
00036
00037 var $_usepasswordsalt;
00038 var $_allowedusergroups;
00039 var $_disallowedusergroups;
00040
00041 var $_adminusergroups;
00042 var $_adminusers;
00043
00047 function vbb3UserDataProvider( $providerConfig )
00048 {
00049 $this->BaseUserDataProvider( $providerConfig );
00050
00051
00052 $config = $this->getProviderConfiguration();
00053 $user = $config->getValue( "user" );
00054 $pass = $config->getValue( "password" );
00055 $host = $config->getValue( "host" );
00056 $db = $config->getValue( "database" );
00057
00058 $this->_vbb3prefix = $config->getValue( "prefix" );
00059 $this->_usepasswordsalt = $config->getValue( "usesalt" );
00060 $this->_allowedusergroups = $config->getValue( "allowgroup" );
00061 $this->_disallowedusergroups = $config->getValue( "denygroup" );
00062 $this->_adminusergroups = $config->getValue( "admingroup");
00063 $this->_adminusers = $config->getValue( "adminuser");
00064
00065
00066 $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );
00067 }
00068
00069 function vbbAllowed( $row )
00070 {
00071
00072 if (!in_array($row['usergroupid'], $this->_disallowedusergroups))
00073 if (in_array($row['usergroupid'], $this->_allowedusergroups))
00074 return true;
00075
00076
00077
00078 return false;
00079 }
00080
00081 function vbbAdmin( $row )
00082 {
00083
00084 if (in_array($row['usergroupid'], $this->_adminusergroups))
00085 return true;
00086
00087 if (in_array($row['userid'], $this->_adminusers))
00088 return true;
00089
00090
00091
00092 return false;
00093 }
00094
00095 function vbbCheckPassword( $pass , $row )
00096 {
00097
00098 if ($this->_usepasswordsalt)
00099 {
00100 if(md5(md5($pass) . $row['salt']) == $row['password']) return true;
00101 }
00102 else
00103 {
00104 if(md5($pass) == $row['password']) return true;
00105 }
00106
00107
00108 return false;
00109 }
00110
00119 function authenticateUser( $user, $pass )
00120 {
00121 $query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $user )."'";
00122
00123 $result = $this->_dbc->Execute( $query );
00124
00125
00126 if( !$result )
00127 return false;
00128
00129 $ret = ($result->RecordCount() == 1);
00130
00131 if ($ret) $row = $result->FetchRow();
00132
00133 $result->Close();
00134
00135
00136 if($ret && $this->vbbCheckPassword($pass,$row) && $this->vbbAllowed($row))
00137 return true;
00138 else
00139 return false;
00140 }
00141
00149 function getUserInfo( $user, $pass )
00150 {
00151 $query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $user )."'";
00152
00153
00154 $result = $this->_dbc->Execute( $query );
00155
00156 if( !$result )
00157 return false;
00158
00159 $row = $result->FetchRow();
00160 $result->Close();
00161
00162 if (!$this->vbbCheckPassword($pass,$row))
00163 return false;
00164
00165 return( $this->_mapUserInfoObject( $row ));
00166 }
00167
00174 function getUserInfoFromUsername( $username )
00175 {
00176 $query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE username = '".Db::qstr( $username )."'";
00177
00178 $result = $this->_dbc->Execute( $query );
00179
00180 if( !$result )
00181 return false;
00182
00183 if( $result->RowCount() == 0 ){
00184 $result->Close();
00185 return false;
00186 }
00187
00188 $row = $result->FetchRow();
00189 $result->Close();
00190
00191 return( $this->_mapUserInfoObject( $row ));
00192 }
00193
00200 function getUserInfoFromId( $userid, $extendedInfo = false )
00201 {
00202 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00203
00204
00205 $query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE userid = '".Db::qstr( $userid )."'";
00206
00207
00208
00209 $result = $this->_dbc->Execute( $query );
00210
00211 if( !$result )
00212 return false;
00213
00214 $row = $result->FetchRow();
00215 $result->Close();
00216
00217
00218
00219
00220
00221 return( $this->_mapUserInfoObject( $row ));
00222 }
00223
00224 function vbb3AddBlog( $row )
00225 {
00226
00227 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
00228 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00229 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00230 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00231
00232 $blogs = new Blogs();
00233 $blog = new BlogInfo( $row["user"],
00234 $row["id"],
00235 "",
00236 "");
00237 $newBlogId = $blogs->addBlog( $blog );
00238
00239
00240 $articleCategories = new ArticleCategories();
00241 $articleCategory = new ArticleCategory( "General", "", $newBlogId, true );
00242 $catId = $articleCategories->addArticleCategory( $articleCategory );
00243 $config =& Config::getConfig();
00244 $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
00245 $articleTopic = $locale->tr( "register_default_article_topic" );
00246 $articleText = $locale->tr( "register_default_article_text" );
00247 $article = new Article( $articleTopic,
00248 $articleText,
00249 Array( $catId ),
00250 $row["user_id"],
00251 $newBlogId,
00252 POST_STATUS_PUBLISHED,
00253 0,
00254 Array(),
00255 "welcome" );
00256 $t = new Timestamp();
00257 $article->setDateObject( $t );
00258 $articles = new Articles();
00259 $articles->addArticle( $article );
00260 }
00261
00262 function _mapUserInfoObject( $row, $extraInfo = false )
00263 {
00264 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00265
00266 $plogPhpBB2Data = $this->getpLogPHPBBUserData( $row["userid"] );
00267
00268 $row["user"] = $row["username"];
00269
00270 $row["email"] = $row["email"];
00271 $row["about"] = $plogPhpBB2Data["about"];
00272 $row["full_name"] = $plogPhpBB2Data["full_name"];
00273 $row["resource_picture_id"] = $plogPhpBB2Data["resource_picture_id"];
00274 if( $row["resource_picture_id"] == "" )
00275 $row["resource_picture_id"] = 0;
00276 $row["properties"] = serialize(Array());
00277 $row["id"] = $row["userid"];
00278 $row["status"] = $this->vbbAllowed($row) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
00279 $row["site_admin"] = $this->vbbAdmin($row)?1:0;
00280
00281
00282
00283 $providerConfig = $this->getProviderConfiguration();
00284 if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
00285 $userInfo = BaseUserDataProvider::mapRow( $row, true );
00286
00287 $userBlogs = $userInfo->getBlogs();
00288 if( empty($userBlogs )) {
00289
00290 $this->grantLoginPermission( $userInfo );
00291
00292 $this->vbb3AddBlog( $row );
00293 $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
00294 }
00295 }
00296 else {
00297 $userInfo = BaseUserDataProvider::mapRow( $row );
00298 }
00299
00300 return( $userInfo );
00301 }
00302
00312 function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
00313 {
00314 $where = "";
00315 switch ($status)
00316 {
00317 case user_status_all:
00318 $where = "";
00319 break;
00320 case user_status_active:
00321 $where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
00322 break;
00323 case user_status_unconfirmed:
00324 case user_status_disabled:
00325 $where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
00326 break;
00327 }
00328
00329 if ($searchTerms != "")
00330 {
00331 if ($where != "")
00332 $where = $where." AND ".($this->getSearchConditions($searchTerms));
00333 else
00334 $where = $this->getSearchConditions($searchTerms);
00335 }
00336
00337
00338 if ($where != "")
00339 $where = " where ".$where;
00340
00341 $query = "SELECT * FROM ".$this->_vbb3prefix."user".$where." ORDER BY userid ASC";
00342
00343 $result = $this->_dbc->Execute( $query, $page, $itemsPerPage );
00344
00345 $users = Array();
00346
00347 while ($info = $result->FetchRow( $result ))
00348 array_push( $users, $this->_mapUserInfoObject( $info ));
00349 $result->Close();
00350
00351 return $users;
00352 }
00353
00361 function updateUser( $userInfo )
00362 {
00363 BaseUserDataProvider::updateUser( $userInfo );
00364 return $this->updatepLogPHPBB2UserData( $userInfo );
00365
00366 $query = "UPDATE ".$this->_vbb3prefix."user SET
00367 username = '".Db::qstr($userInfo->getUserName())."',
00368 email = '".Db::qstr($userInfo->getEmail())."',
00369 //user_active = '".Db::qstr($userInfo->getPassword())."'
00370 WHERE userid = '".Db::qstr($userInfo->getId())."'";
00371
00372 $result = $this->_dbc->Execute( $query );
00373
00374 if( !$result )
00375 return false;
00376
00377 BaseUserDataProvider::updateUser( $userInfo );
00378
00379
00380 $result = $this->updatepLogPHPBB2UserData( $userInfo );
00381
00382 return( $result );
00383 }
00384
00389 function getLastPhpBBUserId()
00390 {
00391 $query = "SELECT MAX(userid)+1 AS next_id FROM ".$this->_vbb3prefix."user";
00392
00393 $result = $this->_dbc->Execute( $query );
00394
00395 $row = $result->FetchRow();
00396 $result->Close();
00397
00398 return( $row["next_id"] );
00399 }
00400
00408 function addUser( &$user )
00409 {
00410
00411 $password = $user->getPassword();
00412 $id = $this->getLastPhpBBUserId();
00413
00414 $query = "INSERT INTO ".$this->_vbb3prefix."user (userid,username,password,useremail)
00415 VALUES ($id, '".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','".
00416 Db::qstr($user->getEmail())."');";
00417
00418 $result = $this->_dbc->Execute( $query );
00419
00420 if( !$result )
00421 return false;
00422
00423 $user->setId( $id );
00424
00425
00426 $this->updatepLogPHPBB2UserData( $user );
00427
00428 return( $id );
00429 }
00430
00439 function updatepLogPHPBB2UserData( &$user )
00440 {
00441
00442 if( $this->getpLogPHPBBUserData( $user->getId())) {
00443
00444 $query = "UPDATE ".$this->getPrefix()."phpbb2_users
00445 SET full_name = '".Db::qstr( $user->getFullName())."',
00446 about = '".Db::qstr( $user->getAboutMyself())."',
00447 properties = '".Db::qstr( serialize($user->getProperties()))."',
00448 resource_picture_id = '".Db::qstr( $user->getPictureId())."',
00449 status = '".Db::qstr( $user->getStatus())."'
00450 WHERE phpbb_id = '".Db::qstr( $user->getId())."'";
00451 }
00452 else {
00453
00454 $query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
00455 (full_name, about, properties, resource_picture_id,phpbb_id,status)
00456 VALUES ('".Db::qstr( $user->getFullName())."', '".
00457 Db::qstr($user->getAboutMyself())."','".
00458 Db::qstr(serialize($user->getProperties()))."','".
00459 Db::qstr($user->getPictureId())."','".
00460 Db::qstr($user->getId())."','".
00461 Db::qstr($user->getStatus())."');";
00462 }
00463
00464 $result = $this->Execute( $query );
00465
00466 return( true );
00467 }
00468
00476 function getpLogPHPBBUserData( $userId )
00477 {
00478 $query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
00479
00480 $result = $this->Execute( $query );
00481
00482 if( !$result )
00483 return false;
00484
00485 if( $result->RowCount() == 0 ){
00486 $result->Close();
00487 return false;
00488 }
00489
00490 $ret = $result->FetchRow();
00491 $result->Close();
00492
00493 return $ret;
00494 }
00495
00501 function deleteUser( $userId )
00502 {
00503 }
00504
00510 function getNumUsers( $status = USER_STATUS_ALL , $searchTerms = "" )
00511 {
00512 $where = "";
00513 switch ($status)
00514 {
00515 case user_status_all:
00516 $where = "";
00517 break;
00518 case user_status_active:
00519 $where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
00520 break;
00521 case user_status_unconfirmed:
00522 case user_status_disabled:
00523 $where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
00524 break;
00525 }
00526
00527 if ($searchTerms != "")
00528 {
00529 if ($where != "")
00530 $where = $where." AND ".$this->getSearchConditions($searchTerms);
00531 else
00532 $where = $this->getSearchConditions($searchTerms);
00533 }
00534
00535
00536 if ($where != "")
00537 $where = " where ".$where;
00538
00539 $query = "SELECT COUNT(userid) AS total FROM ".$this->_vbb3prefix."user".$where;
00540
00541
00542 $result = $this->_dbc->Execute( $query );
00543
00544
00545 if( !$result )
00546 return 0;
00547
00548 $row = $result->FetchRow();
00549 $result->Close();
00550
00551 if( $row["total"] == "" )
00552 $row["total"] = 0;
00553
00554 return( $row["total"] );
00555 }
00556
00561 function emailExists($email)
00562 {
00563 $query = "SELECT * FROM ".$this->_vbb3prefix."user WHERE email = '".Db::qstr($email)."'";
00564
00565 $result = $this->_dbc->Execute( $query );
00566
00567 if( !$result )
00568 return false;
00569 $ret = ($result->RecordCount() > 0);
00570 $result->Close();
00571 return $ret;
00572 }
00573
00574
00578 function getSearchConditions( $searchTerms )
00579 {
00580 lt_include( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
00581
00582 $searchTerms = SearchEngine::adaptSearchString( $searchTerms );
00583
00584 return( "(username LIKE '%".$searchTerms."%')");
00585 }
00586
00598 function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" )
00599 {
00600 $userids = Array();
00601 $users = Array();
00602 $prefix = $this->getPrefix();
00603
00604
00605
00606 if( $includeOwner ) {
00607 $query = "SELECT {$prefix}blogs.owner_id as userid FROM {$prefix}blogs
00608 WHERE {$prefix}blogs.id = '".Db::qstr($blogId)."';";
00609 $result = $this->Execute( $query );
00610
00611 if( !$result )
00612 return $users;
00613
00614 $row = $result->FetchRow();
00615 $result->Close();
00616
00617 array_push($userids,$row['userid']);
00618 }
00619
00620
00621 $query2 = "SELECT {$prefix}users_permissions.user_id as userid FROM {$prefix}users_permissions
00622 WHERE {$prefix}users_permissions.blog_id = '".Db::qstr($blogId)."';";
00623 $result2 = $this->Execute( $query2 );
00624
00625 if( $result2 )
00626 {
00627 while( $row = $result2->FetchRow()) {
00628 array_push($userids,$row['userid']);
00629 }
00630 $result2->Close();
00631 }
00632
00633
00634 if (!is_array($userids))
00635 {
00636 return $users;
00637 }
00638
00639
00640 $where = "";
00641 switch ($status)
00642 {
00643 case user_status_all:
00644 $where = "";
00645 break;
00646 case user_status_active:
00647 $where = "usergroupid in (".implode(",", $this->_allowedusergroups).")";
00648 break;
00649 case user_status_unconfirmed:
00650 case user_status_disabled:
00651 $where = "not(usergroupid in (".implode(",", $this->_allowedusergroups)."))";
00652 break;
00653 }
00654
00655 if ($searchTerms != "")
00656 {
00657 if ($where != "")
00658 $where = $where." AND ".($this->getSearchConditions($searchTerms));
00659 else
00660 $where = $this->getSearchConditions($searchTerms);
00661 }
00662
00663 if ($where != "")
00664 $where = $where." AND ";
00665
00666 $where = $where." (userid in (".implode(",", $userids)."))";
00667
00668
00669
00670 if ($where != "")
00671 $where = " where ".$where;
00672
00673 $query3 = "SELECT * FROM ".$this->_vbb3prefix."user".$where." ORDER BY userid ASC";
00674
00675
00676 $result3 = $this->_dbc->Execute( $query3);
00677
00678
00679
00680 while ($info = $result3->FetchRow( $result3 ))
00681 array_push( $users, $this->_mapUserInfoObject( $info ));
00682 $result3->Close();
00683
00684 return $users;
00685 }
00686 }
00687 ?>