[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/dao/userdata/ -> wbbuserdataprovider.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
   5      
   6      /**

   7       * Model representing the users in our application. Provides the methods such as

   8       * authentication and querying for users.

   9       *

  10       * \ingroup User_Data_Providers

  11       */
  12      class WBBUserDataProvider extends BaseUserDataProvider
  13      {
  14          var $_db;
  15          var $_prefix;
  16        var $_blogtitle_postfix;
  17        var $_adminusergroups;
  18          /**

  19           * Initializes the model

  20           */
  21          function WBBUserDataProvider( $providerConfig )
  22          {
  23              $this->BaseUserDataProvider( $providerConfig );
  24  
  25              // initialize the database connection based on our parameters

  26              $config = $this->getProviderConfiguration();
  27              $user = $config->getValue( "user" );
  28              $pass = $config->getValue( "password" );
  29              $host = $config->getValue( "host" );
  30              $db = $config->getValue( "database" );
  31              $this->_wbbprefix = $config->getValue( "prefix" );
  32              
  33              $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );                     
  34              $this->_blogtitle_postfix = $config->getValue( "blogtitle_postfix" );                   
  35              $this->_adminusergroups = $config->getValue( "admingroup");
  36          }
  37  
  38          /**

  39           * Returns true if the user is in the database and the username

  40           * and password match

  41           *

  42           * @param user Username of the user who we'd like to authenticate

  43           * @param pass Password of the user

  44           * @return true if user and password correct or false otherwise.

  45           */
  46          function authenticateUser( $user, $pass )
  47          {
  48              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
  49                        AND password = '".md5( $pass )."' AND activation > 0";
  50                        
  51              $result = $this->_dbc->Execute( $query );
  52              
  53              if( !$result )
  54                  return false;
  55                  
  56              $ret = ($result->RecordCount() == 1);
  57              $result->Close();
  58  
  59              if($ret)
  60                  return true;
  61              else
  62                  return false;        
  63          }
  64  
  65          /**

  66           * Returns all the information associated to the user given

  67           *

  68           * @param user Username of the user from who we'd like to get the information

  69           * @param pass Password of the user we'd like to get the information

  70           * @return Returns a UserInfo object with the requested information, or false otherwise.

  71           */
  72          function getUserInfo( $user, $pass )
  73          {
  74              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $user )."'
  75                        AND password = '".md5( $pass )."'";
  76                        
  77              $result = $this->_dbc->Execute( $query );
  78              
  79              if( !$result )
  80                  return false;
  81                  
  82              $row = $result->FetchRow();
  83              $result->Close();
  84  
  85              return( $this->_mapUserInfoObject( $row ));            
  86          }
  87  
  88          /**

  89           * Retrieves the user information but given only a username

  90           *

  91           * @param username The username of the user

  92           * @return Returns a UserInfo object with the requested information, or false otherwise.

  93           */
  94          function getUserInfoFromUsername( $username )
  95          {
  96              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE username = '".Db::qstr( $username )."'";                      
  97                        
  98              $result = $this->_dbc->Execute( $query );
  99              
 100              if( !$result )
 101                  return false;
 102                                  
 103              if( $result->RowCount() == 0 ){
 104                  $result->Close();
 105                  return false;
 106              }
 107                  
 108              $row = $result->FetchRow();
 109              $result->Close();
 110              
 111              return( $this->_mapUserInfoObject( $row ));            
 112          }
 113  
 114          /**

 115           * Retrieves the user infromation but given only a userid

 116           *

 117           * @param userId User ID of the user from whom we'd like to get the information

 118           * @return Returns a UserInfo object with the requested information, or false otherwise.

 119           */
 120          function getUserInfoFromId( $userid, $extendedInfo = false )
 121          {
 122              lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
 123              
 124              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid = '".Db::qstr( $userid )."'";
 125  
 126  //print("user__id = $userid");

 127                        
 128              $result = $this->_dbc->Execute( $query );
 129              
 130              if( !$result )
 131                  return false;
 132                  
 133              $row = $result->FetchRow();
 134              $result->Close();
 135              
 136              // fetch the user permissions

 137              //$perms = new UserPermissions();

 138              //$row["site_admin"] = $perms->isSiteAdmin( $userid );

 139              
 140              return( $this->_mapUserInfoObject( $row ));
 141          }
 142          
 143          function WBB2AddBlog( $row )
 144          {
 145              // create a new blog

 146              lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );                
 147              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
 148              lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 149              lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
 150  
 151              $config =& Config::getConfig();
 152              $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
 153              
 154              $blogs = new Blogs();
 155              $blog = new BlogInfo( $row["user"].$this->_blogtitle_postfix,  // name of the new blog
 156                                       $row["id"],  // id of the owner
 157                                       "",  // no about
 158                                    ""); // no properties either

 159              $newBlogId = $blogs->addBlog( $blog );
 160                                
 161              // add a default category and a default post            

 162              $articleCategories = new ArticleCategories();
 163              $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true );
 164              $catId = $articleCategories->addArticleCategory( $articleCategory );
 165              $articleTopic = $locale->tr( "register_default_article_topic" );
 166              $articleText  = $locale->tr( "register_default_article_text" );
 167              $article = new Article( $articleTopic, 
 168                                      $articleText, 
 169                                      Array( $catId ), 
 170                                      $row["userid"], 
 171                                      $newBlogId, 
 172                                      POST_STATUS_PUBLISHED, 
 173                                      0, 
 174                                      Array(), 
 175                                      "welcome" );
 176              $t = new Timestamp();
 177              $article->setDateObject( $t );
 178              $articles = new Articles();
 179              $articles->addArticle( $article );               
 180          }
 181          
 182          function _mapUserInfoObject( $row, $extraInfo = false )
 183          {
 184              lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
 185              
 186              $plogWBB2Data = $this->getpLogWBBUserData( $row["userid"] );
 187  
 188              $row["user"] = $row["username"];
 189              $row["password"] = $row["password"];
 190              $row["email"] = $row["email"];
 191              $row["about"] = $plogWBB2Data["about"];
 192              $row["full_name"] = $plogWBB2Data["full_name"];
 193              $row["resource_picture_id"] = $plogWBB2Data["resource_picture_id"];
 194              if( $row["resource_picture_id"] == "" ) $row["resource_picture_id"] = 0;
 195              $row["properties"] = serialize(Array());
 196              $row["id"] = $row["userid"];   
 197              $row["status"] = ($row["activation"] > 0) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
 198                  if (in_array($row["groupcombinationid"], $this->_adminusergroups)) $row["site_admin"] = '1';
 199            else  $row["site_admin"] = '0';
 200                                
 201                 // does this wbb user have a blog yet? If so, create one if the configuration

 202              // of the user data provider says so

 203              $providerConfig = $this->getProviderConfiguration();
 204              if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
 205                  $userInfo = BaseUserDataProvider::mapRow( $row, true );
 206                  // check if this user is assigned to any blog

 207                  $userBlogs = $userInfo->getBlogs();
 208                  if( empty($userBlogs )) {
 209                      // assign the login_perm permission

 210                      $this->grantLoginPermission( $userInfo );            
 211              
 212                      $this->WBB2AddBlog( $row );
 213                      $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
 214                   }
 215              }
 216              else {
 217                  $userInfo = BaseUserDataProvider::mapRow( $row );
 218              }            
 219              
 220              return( $userInfo );
 221          }
 222  
 223          /**

 224           * Returns an array with all the users available in the database

 225           *

 226           * @param status

 227           * @param includeExtraInfo

 228           * @param page

 229           * @param itemsPerPage

 230           * @return An array containing all the users.

 231           */
 232          function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 233          {            
 234              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE userid >= 0 ORDER BY userid ASC";
 235  
 236              $result = $this->_dbc->Execute( $query, $page, $itemsPerPage );            
 237  
 238              $users = Array();
 239  
 240              while ($info = $result->FetchRow( $result ))
 241                  array_push( $users, $this->_mapUserInfoObject( $info ));
 242              $result->Close();
 243  
 244              return $users;                        
 245          }
 246  
 247          /**

 248           * Updates the information related to a user

 249           *

 250           * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the

 251           * user we would like to update.

 252           * @return Returns true if ok or false otherwise.

 253           */
 254          function updateUser( $userInfo )
 255          {
 256              $query = "UPDATE ".$this->_wbbprefix."users SET
 257                        username = '".Db::qstr($userInfo->getUserName())."',
 258                        email = '".Db::qstr($userInfo->getEmail())."',
 259                        password = '".md5(Db::qstr($userInfo->getPassword()))."',
 260                        sha1_password = '".sha1(Db::qstr($userInfo->getPassword()))."'
 261                        WHERE userid = '".Db::qstr($userInfo->getId())."'";
 262                                    
 263              $result = $this->_dbc->Execute( $query );            
 264              
 265              if( !$result )
 266                  return false;
 267              
 268              BaseUserDataProvider::updateUser( $userInfo );
 269              
 270              // update plog's wbb_user table

 271              $result = $this->updatepLogWBBUserData( $userInfo );
 272  
 273              return( $result );
 274          }
 275          
 276          /**

 277           * @private

 278           * Why the hell couldn't they make the user_id field auto-incrementable???

 279           */
 280          function getLastWBBUserId()
 281          {
 282             $query = "SELECT MAX(userid)+1 AS next_id FROM ".$this->_wbbprefix."users"; 
 283             
 284             $result = $this->_dbc->Execute( $query );
 285             
 286             $row = $result->FetchRow();
 287             $result->Close();
 288             
 289             return( $row["next_id"] );
 290          }
 291  
 292          /**

 293           * Adds a user to the database.

 294           *

 295           * @param user An UserInfo object with the necessary information

 296           * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the

 297           * UserInfo object passed by parameter and set its database id.

 298           */
 299          function addUser( &$user )
 300          {            
 301              // update the wbb table

 302              $password = $user->getPassword();
 303              $id = $this->getLastWBBUserId();
 304                  
 305              $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) ".
 306              "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'])."');";                      
 307  
 308              $result = $this->_dbc->Execute( $query );            
 309  
 310                  $query1 = "INSERT INTO ".$this->_wbbprefix."userfields (userid) VALUES ($id);";
 311                      $result1 = $this->_dbc->Execute( $query1 );   
 312  
 313  
 314              $query2 = "INSERT INTO ".$this->_wbbprefix."user2groups (userid,groupid) VALUES ('".$id."','4');";   
 315                      $result2 = $this->_dbc->Execute( $query2 );   
 316                  
 317                $query3 = "UPDATE ".$this->_wbbprefix."stats SET usercount=usercount+1, lastuserid='".$id."';";
 318            $result3 = $this->_dbc->Execute( $query3 );   
 319  
 320            if( !$result || !$result1 || !$result2 || !$result3)
 321                  return false;          
 322  
 323              $user->setId( $id );
 324              
 325              // update plog's wbb2_user table

 326              $this->updatepLogWBBUserData( $user );
 327  
 328              return( $id );
 329          }
 330          
 331          /**

 332           * @private

 333           * Updates the plog-specific user data that is used when the wbb2 integration is enabled, since

 334           * plog has some extra information that does not fit anywhere in wbb2

 335           *

 336           * @param user A UserInfo object

 337           * @return true if successful or false otherwise

 338           */
 339          function updatepLogWBBUserData( &$user )
 340          {
 341              // is the user already there?

 342              if( $this->getpLogWBBUserData( $user->getId())) {
 343                  // we need to run an UPDATE query...

 344                  $query = "UPDATE ".$this->getPrefix()."phpbb2_users
 345                            SET full_name = '".Db::qstr( $user->getFullName())."', 
 346                                about = '".Db::qstr( $user->getAboutMyself())."',
 347                                properties = '".Db::qstr( serialize($user->getProperties()))."',
 348                                resource_picture_id = '".Db::qstr( $user->getPictureId())."',
 349                                status = '".Db::qstr( $user->getStatus())."'
 350                            WHERE phpbb_id = '".Db::qstr( $user->getId())."'";    
 351              }
 352              else {
 353                  // we need to run an INSERT query...    

 354                  $query = "INSERT INTO ".$this->getPrefix()."phpbb2_users
 355                            (full_name, about, properties, resource_picture_id,phpbb_id,status)
 356                            VALUES ('".Db::qstr( $user->getFullName())."', '".
 357                            Db::qstr($user->getAboutMyself())."','".
 358                            Db::qstr(serialize($user->getProperties()))."','".
 359                            Db::qstr($user->getPictureId())."','".
 360                            Db::qstr($user->getId())."','".
 361                            Db::qstr($user->getStatus())."');";
 362              }
 363              
 364              $result = $this->Execute( $query );
 365              
 366              return( true );
 367          }
 368          
 369          /**

 370           * @private

 371           * Load the plog-specific wbb2 user data

 372           *

 373           * @param userId

 374           * @return A row with the extra user data or false otherwise

 375           */
 376          function getpLogWBBUserData( $userId )
 377          {
 378              $query = "SELECT * FROM ".$this->getPrefix()."phpbb2_users WHERE phpbb_id = '".Db::qstr($userId)."'";
 379              
 380              $result = $this->Execute( $query );
 381              
 382              if( !$result )
 383                  return false;
 384                  
 385              if( $result->RowCount() == 0 ){
 386                  $result->Close();
 387                  return false;
 388              }
 389  
 390              $ret = $result->FetchRow();
 391              $result->Close();
 392  
 393              return $ret;
 394          }
 395          
 396          /**

 397           * Removes users from the database

 398           *

 399           * @param userId The identifier of the user we are trying to remove

 400           */
 401          function deleteUser( $userId )
 402          {
 403          }        
 404  
 405          /**

 406           * returns the total number of users

 407           *

 408           * @return total number of users

 409           */
 410          function getNumUsers( $status = USER_STATUS_ALL )
 411          {
 412              //

 413              // :TODO:

 414              // add the status check here!

 415              //

 416              $query = "SELECT COUNT(id) AS total FROM ".$this->_wbbprefix."users";
 417              
 418              $result = $this->_dbc->Execute( $query );
 419              
 420              // return no users if this doesn't work!

 421              if( !$result )
 422                  return 0;
 423              
 424              $row = $result->FetchRow();
 425              $result->Close();
 426              
 427              if( $row["total"] == "" )
 428                  $row["total"] = 0;
 429                  
 430              return( $row["total"] );
 431          }
 432  
 433          /**

 434           * check if the email account has been registered

 435           * @return true if the email account has been registered

 436           */
 437          function emailExists($email)        
 438          {
 439              $query = "SELECT * FROM ".$this->_wbbprefix."users WHERE email = '".Db::qstr($email)."'";
 440              
 441              $result = $this->_dbc->Execute( $query );
 442              
 443              if( !$result )
 444                  return false;
 445              $ret = ($result->RecordCount() > 0);
 446              $result->Close();
 447              return $ret;
 448          }
 449      }
 450  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics