⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joomlauserdataprovider.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

    include_once( PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
    include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
    
    define( "JOOMLA_USER_IS_BLOCKED", 1);
    define( "JOOMLA_USER_IS_ACTIVE", 0);
    define( "JOOMLA_SITE_ADMIN", "Super Administrator");
    
    
    /**
     * Model representing the users in our application. Provides the methods such as
     * authentication and querying for users.
	 *
	 * \ingroup User_Data_Providers
     */
     
    class JoomlaUserDataProvider extends BaseUserDataProvider
    //Based on phpbb2userdataprovider.class.php
    {
	    var $_db;
	    var $_joomladbprefix;
	    var $_joomlaauxtable;
	    var $_blogtitle_postfix;

        /**
         * Initializes the model
         */
        function JoomlaUserDataProvider( $providerConfig )
        {
            $this->BaseUserDataProvider( $providerConfig );
			
            //*** Temporarily disabled for causing a fatal error ***/
            // disable all caching for userdata
            //CacheManager::disableCache( CACHE_USERINFO );
            
            // 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->_joomladbprefix = $config->getValue( "prefix" );
            $this->_blogtitle_postfix = $config->getValue( "blogtitle_postfix" );
            //phpbb2_users table is created upon installation, we can use it for joomla too
            //but better parameterize its name
            $this->_joomlaauxtable="joomla_users";

            $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );                     
            
            //Oddly, there have been problems in reading Joomla! db in utf-8
            //Setting explicitly connection charset has fixed them
			$dbcharset = $config->getValue( "dbcharset" );
        	$query = "SET NAMES '".$dbcharset."';";
            $result = $this->_dbc->Execute( $query );
                   
            
        }

        /**
         * 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->_joomladbprefix."users".
	        			" WHERE username = '".$user."'".
	        			" AND password = '".md5($pass)."'".
	        			" AND block=".JOOMLA_USER_IS_ACTIVE;
	        			
	        $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 Joomla db
	        $query = "SELECT * FROM ".$this->_joomladbprefix."users".
	        			" WHERE username = '".$user."'".
	        			" AND password = '".md5($pass)."';".
	                  
	        $result = $this->_dbc->Execute( $query );
	        
	        if( !$result )
	        	return false;
	        	
	        $row = $result->FetchRow();
            $result->Close();
            
            $userid=$row["id"];
                      	
            $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 Joomla table
	        $query = "SELECT * FROM ".$this->_joomladbprefix."users WHERE username = '".Db::qstr( $username )."'";	       	       
	                  
	        $result = $this->_dbc->Execute( $query );
	        
	        if( !$result ){
	        	return false;
        	}
	        		        	
	        if( $result->RowCount() != 1 ){
                $result->Close();
	        	return false;
            }
	        	
	        $row = $result->FetchRow();
            $result->Close();
            
            $userid=$row["id"];
	        
	        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->_joomladbprefix."users WHERE id = '".Db::qstr( $userid )."'";

			//print("user__id = $userid");
	                  
	        $result = $this->_dbc->Execute( $query );
	        
	        if( !$result )
	        	return false;
	        	
	        $row = $result->FetchRow();
            $result->Close();
	        
	        return( $this->_mapUserInfoObject( $row ));
        }
        
        function JoomlaAddBlog( $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" );
		    
		    $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( "General", "", $newBlogId, true );
            $catId = $articleCategories->addArticleCategory( $articleCategory );
            $config =& Config::getConfig();
            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
            $articleTopic = $locale->tr( "register_default_article_topic" );
            $articleText  = $locale->tr( "register_default_article_text" );
            $article = new Article( $articleTopic, 
                                    $articleText, 
                                    Array( $catId ), 
                                    $row["id"], 
                                    $newBlogId, 
                                    POST_STATUS_PUBLISHED, 
                                    0, 
                                    Array(), 
                                    "welcome" );
            $t = new Timestamp();
            $article->setDateObject( $t );
            $articles = new Articles();
            $articles->addArticle( $article );	           
        }
        
        /* Gets rows from Joomla user data table and auxiliary LT table and merges
         * them into a single userInfo object
         * 
         * @param row Joomla user data table row, as fetched
         * @param extraInfo Lifetype auxiliary table extra user data, as fetched
         * @return userInfo object, as neede by LT 
         */
        function _mapUserInfoObject( $row, $extraInfo=false)
        {
	        include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
	        
	        $plogJoomlaData = $this->getpLogJoomlaUserData( $row["id"] );

			//Data fetched from Joomla db
	        //$row["id"] = $row["id"];   //no need to map
	        $row["user"] = $row["username"];
	        $row["password"] = $row["password"];
	        $row["email"] = $row["email"];
	        $row["full_name"] = $row["name"];
	        $row["status"] = ($row["block"] != 1) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
	        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -