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

📄 joomlauserdataprovider.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	        //Data fetched from auxiliary table
	        //If no data fetched, these fields will be empty
	        if(!$plogJoomlaData){
		        $row["about"] = "";
		        $row["resource_picture_id"] = 0;
		        $row["properties"] = serialize(Array());
	        } else {
		        $row["about"] = $plogJoomlaData["about"];
		        $row["resource_picture_id"] = $plogJoomlaData["resource_picture_id"];
				if( $row["resource_picture_id"] == "" ) $plogJoomlaData["resource_picture_id"] = 0;
		        $row["properties"] = serialize($plogJoomlaData["properties"]);
	        }
		        
	        // If this is the first time user data is loaded on LT, Joomla Super administrator
	        // will be an LT site admin as well.
	        // Otherwise, get site admin status from auxiliary table	        
	        if(!$plogJoomlaData){
				$row["site_admin"] = ($row["usertype"]==JOOMLA_SITE_ADMIN);
	        }   else {
	        	$row["site_admin"] = $plogJoomlaData["blog_site_admin"];
	        }    
	        	        
	       	// does this Joomla 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->JoomlaAddBlog( $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
         * @param itemsPerPage
         * @return An array containing all the users.
         */
        function getAllUsers( $status = USER_STATUS_ALL, $searchTerms = "", $orderBy = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
        {	        
            $query = "SELECT * FROM ".$this->_joomladbprefix."users ORDER BY id ASC";

            $result = $this->_dbc->Execute( $query, $page, $itemsPerPage );            

            $users = Array();

            while ($info = $result->FetchRow( $result )){
                array_push( $users, $this->_mapUserInfoObject( $info ));
            }
            $result->Close();

            return $users;	        	        
        }

        /**
         * Updates the information related to a user
         *
         * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the
         * user we would like to update.
         * @return Returns true if ok or false otherwise.
         */
        function updateUser( $userInfo )
        {
	        /* These should be accessible only from Joomla! */
	        /*
	        $query = "UPDATE ".$this->_joomladbprefix."users ".
		        "SET username = '".Db::qstr($userInfo->getUserName()).
		        "', password = '".Db::qstr(md5($userInfo->getPassword())).
		        "', email = '".Db::qstr($userInfo->getEmail()).
		        "', block = '".Db::qstr(($userInfo->getStatus()>USER_STATUS_ACTIVE)? JOOMLA_USER_IS_BLOCKED : JOOMLA_USER_IS_ACTIVE) .
		        "'  WHERE id = ".Db::qstr($userInfo->getId());
	                              
            $result = $this->_dbc->Execute( $query );            
            
            if( !$result ){
	            $this->log->debug("Error while updating joomla table. Query:\n".$query."\n" );
            	return false;
        	}
            
            BaseUserDataProvider::updateUser( $userInfo );
            */
            
			// update plog's joomla_user table
			$result = $this->updatepLogJoomlaUserData( $userInfo );

			return( $result );
        }
        
        /**
         * Adds a user to the database.
         *
         * @param user An UserInfo object with the necessary information
         * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the
		 * UserInfo object passed by parameter and set its database id.
         */
        function addUser( &$user )
        {	        
	        /* 	User registration should be done via Joomla!/Mambo.*/
        }
        
        /**
         * @private
         * Updates the plog-specific user data that is used when the joomla integration is enabled, since
         * plog has some extra information that does not fit anywhere in joomla
         *
         * @param user A UserInfo object
         * @return true if successful or false otherwise
         */
        function updatepLogJoomlaUserData( &$user )
        {
	    	// is the user already there?
	    	if( $this->getpLogJoomlaUserData( $user->getId())) {
		    	// we need to run an UPDATE query...
		    	$query = "UPDATE ".$this->getPrefix().$this->_joomlaauxtable.
		    	         " SET about = '".Db::qstr( $user->getAboutMyself()).
		    	         "', properties = '".Db::qstr( serialize($user->getProperties())).
		    	         "', resource_picture_id = '".Db::qstr( $user->getPictureId()).
		    	         "', blog_site_admin = ".(Db::qstr( $user->isSiteAdmin() ? "1" : "0")).
		    	         "  WHERE joomla_id = ".Db::qstr( $user->getId());    
	    	}
	    	else {
		    	// we need to run an INSERT query...	
		    	$query = "INSERT INTO ".$this->getPrefix().$this->_joomlaauxtable."(joomla_id, about, properties, blog_site_admin, resource_picture_id) ".
		    			  " VALUES (".
		    			  Db::qstr($user->getId()).",'".
		    			  Db::qstr($user->getAboutMyself())."','".
		    	          Db::qstr(serialize($user->getProperties()))."',".
		    	          Db::qstr( $user->isSiteAdmin() ? "1" : "0").",'".
		    	          Db::qstr($user->getPictureId())."')";
	    	}
	    	
	    	$result = $this->Execute( $query );
	    	
			return( true );
        }
        
        /**
         * @private
         * Load the plog-specific joomla user data
         *
         * @param userId
         * @return A row with the extra user data or false otherwise
         */
        function getpLogJoomlaUserData( $userId )
        {
            
	        $query = "SELECT * FROM ".$this->getPrefix().$this->_joomlaauxtable." WHERE joomla_id = '".Db::qstr($userId)."'";
	        $result = $this->Execute( $query );
	        
	        if( !$result )
	        	return false;
	        	
	        if( $result->RowCount() == 0 ){
                $result->Close();
                return false;
            }

            $ret = $result->FetchRow();
            $result->Close();

	        return $ret;
        }
        
        /**
         * Removes users from the database
         *
         * @param userId The identifier of the user we are trying to remove
         */
        function deleteUser( $userId )
        {
        }        

        /**
         * returns the total number of users
         *
         * @return total number of users
         */
        function getNumUsers( $status = USER_STATUS_ALL )
        {
	        //
	        // :TODO:
	        // add the status check here!
	        //
	        $query = "SELECT COUNT(id) AS total FROM ".$this->_joomladbprefix."users";
	        
	        $result = $this->_dbc->Execute( $query );
	        
	        // return no users if this doesn't work!
	        if( !$result )
	        	return 0;
	        
	        $row = $result->FetchRow();
            $result->Close();
	        
	        if( $row["total"] == "" )
	        	$row["total"] = 0;
	        	
	        return( $row["total"] );
        }

        /**
         * check if the email account has been registered
         * @return true if the email account has been registered
         */
        function emailExists($email)        
        {
	        $query = "SELECT * FROM ".$this->_joomladbprefix."users WHERE email = '".Db::qstr($email)."'";
	        
	        $result = $this->_dbc->Execute( $query );
	        
	        if( !$result )
	        	return false;
            $ret = ($result->RecordCount() > 0);
            $result->Close();
	        return $ret;
        }
    }
?>

⌨️ 快捷键说明

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