1
Shine
Lifetype Blog: A setting method of xoops
  • 2007/1/7 9:24

  • Shine

  • Just can't stay away

  • Posts: 822

  • Since: 2002/7/22


Lifetype is a multiblog stand alone script. Although the documentation is far from complete (it is a lot of fuzzling by yourself) the first impression is that this blogscript looks very promising.
Somebody is trying to make a bridge into xoops. Thought this news would be interesting for others and coders who feel like adding their knowledge to get this bridge realised.

See:http://forums.lifetype.net/viewtopic.php?t=4357

Grtz., Shine

2
tchang
Re: Lifetype Blog: A setting method of xoops
  • 2007/1/20 14:56

  • tchang

  • Just popping in

  • Posts: 3

  • Since: 2005/2/2 1


Hi,

I've worked a little on lifetype integration with xoops. The latest version use a data provider which can be "easily" overriden.
The following code will allow you to use the XOOPS database for lifetype authentication (single registration).
If anyone is interested I'd be pleased to find someone to work with.

lifetype_header.php
<?php
    
    
    $xoopsOption
['nocommon'] = true;
    
    include_once 
dirname(__FILE__)."/../../mainfile.php";

?>


xoopsuserdataprovider.class.php
<?php

        
// XOOPS include
        
include_once(dirname(__FILE__)."/../../../../lifetype_header.php");

    include_once( 
PLOG_CLASS_PATH."class/dao/userdata/baseuserdataprovider.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/database/db.class.php" );
    include_once( 
PLOG_CLASS_PATH."class/dao/blogs.class.php" );
    
    
/**
     * Model representing the users in our application. Provides the methods such as
     * authentication and querying for users.
         * 
     */
    
class XoopsUserDataProvider  extends BaseUserDataProvider
    
{
        var 
$_db;
        var 
$_prefix;

        
/**
         * Initializes the model
         */
        
function XoopsUserDataProvider $providerConfig )
        { 
// echo "XoopsUserDataProvider<br>";
                
                    
$this->BaseUserDataProvider$providerConfig );

                    
// 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->_prefix $config->getValue"prefix" );
                    
                    
$this->_db =& Db::getNewDb$host$user$pass$db ); 
        }

        
/**
         * 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 )
        { 
// echo "authenticateUser<br>";
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE uname = '".Db::qstr$user )."'
                      AND pass = '"
.md5$pass )."' AND level > 0";
                      
            
$result $this->_db->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 )
        {
// echo "getUserInfo<br>";
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE uname = '".Db::qstr$user )."'
                      AND pass = '"
.md5$pass )."'";
                      
            
$result $this->_db->Execute$query );
            
            if( !
$result )
                return 
false;
                
            
$row $result->FetchRow();
            
$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 )
        {
// echo "getUserInfoFromUsername<br>";
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE uname = '".Db::qstr$username )."'";                      
                      
            
$result $this->_db->Execute$query );
            
            if( !
$result )
                return 
false;
                                
            if( 
$result->RowCount() == ){
                
$result->Close();
                return 
false;
            }
                
            
$row $result->FetchRow();
            
$result->Close();
            
            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 )
        { 
// echo "getUserInfoFromId<br>";
            
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
            
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE uid = '".Db::qstr$userid )."'";

                  
$result $this->_db->Execute$query );
            
            if( !
$result )
                return 
false;
                
            
$row $result->FetchRow();
            
$result->Close();
            
            
// fetch the user permissions
            //$perms = new UserPermissions();
            //$row["site_admin"] = $perms->isSiteAdmin( $userid );
            
            
return( $this->_mapUserInfoObject$row ));
        }
        
                
/**
         * 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 xoopsAddBlog$row )
        { 
// echo "addBlog<br>";
                    // create a new blog
                    
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
                    include_once( 
PLOG_CLASS_PATH."class/dao/bloginfo.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"],  // 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"""$newBlogIdtrue );
                    
$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 );               
        }
        
                
/**
                 * Map the XOOPS user class with the lifetype user
                 * @private
                 * @param xoopsUsr the XOOPS user object to be mapped
                 * @return The method returns a UserInfo object build from the XOOPS information
                 */
        
function _mapUserInfoObject$row$extraInfo false )
        { 
// echo "map<br>";
            
include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
           
            
$row["user"] = $row["uname"];
                    
$row["password"] = $row["pass"];
                    
$row["email"] = $row["email"];
                    
$row["about"] = $row["bio"];
                    
$row["full_name"] = $row["firstname"]. " " $row["name"];
                    
$row["resource_picture_id"] = 0;
                    
$row["properties"] = serialize(Array());
                    
$row["id"] = $row["uid"];   
                    
$row["status"] = ($row["level"] > 0) ? USER_STATUS_ACTIVE USER_STATUS_DISABLED;
                    
$row["site_admin"] = ($row["level"] == 5) ? 1:;           
                        
               
// does this phpbb 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$rowtrue );
                
// check if this user is assigned to any blog
                
$userBlogs $userInfo->getBlogs();
                
$this->log->debug("phpbb: checking if user ".$row["user"]." has at least one blog..." );
                if( empty(
$userBlogs )) {
                    
$this->log->debug"phpbb: creating new blog for user!" );
                    
$this->xoopsAddBlog$row );
                    
$userInfo->setBlogs$this->getUsersBlogs$userInfo->getId()));
                     }
                        else {
                            
$this->log->debug("he already has one!!!");
                        }
            }
            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 ""$page = -1$itemsPerPage DEFAULT_ITEMS_PER_PAGE )
        {            
// echo "getAllUsers<br>";
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE uid >= 0 ORDER BY uid ASC";

            
$result $this->_db->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 )
        {                    return 
false;
            
$query "UPDATE ".XOOPS_DB_PREFIX."_users SET ".
                     
//"uname = '".Db::qstr($userInfo->getUserName())."', ".
                     //"email = '".Db::qstr($userInfo->getEmail())."', ".
                     
"pass = '".Db::qstr($userInfo->getPassword())."' ".
                     
"WHERE uid = '".Db::qstr($userInfo->getId())."'";
                                  
                    
$result $this->_db->Execute$query );            
                    
                    if( !
$result )
                        return 
false;
                    
                    
BaseUserDataProvider::updateUser$userInfo );
                    
                    return( 
$result );
                    
                    return 
false;
        }
        
        
/**
         * 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 )
        {            
                    
/*
            // update the phpbb table
            $password = $user->getPassword();
           
            $query = "INSERT INTO ".XOOPS_DB_PREFIX."_users (uname,pass,email)
                      VALUES ($id, '".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','".
                      Db::qstr($user->getEmail())."','1');";                      
                      
            $result = $this->_db->Execute( $query );            

            if( !$result )
                return false;
            
                    $user->setId( $id );
                    
                    // update plog's phpbb2_user table
                    $this->updatepLogPHPBB2UserData( $user );

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

        
/**
         * returns the total number of users
         *
         * @return total number of users
         */
        
function getNumUsers$status USER_STATUS_ALL )
        { 
// echo "getNumUsers<br>";
            //
            // :TODO:
            // add the status check here!
            //
            
$query "SELECT COUNT(uid) AS total FROM ".XOOPS_DB_PREFIX."_users";
            
            
$result $this->_db->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)        
        { 
// echo "emailExists<br>";
            
$query "SELECT * FROM ".XOOPS_DB_PREFIX."_users WHERE email = '".Db::qstr($email)."'";
            
            
$result $this->_db->Execute$query );
            
            if( !
$result )
                return 
false;
            
$ret = ($result->RecordCount() > 0);
            
$result->Close();
            return 
$ret;
        }
                
                
/**
         * Returns an array with all the users that belong to the given
         * blog.
         *
         * @param blogId The blog identifier.
         * @param includeOwner Wether to include the owner of the blog or not.
         * @return An array with the information about the users who belong in
         * one way or another to that blog.
         */
        
function getBlogUsers$blogId$includeOwner true$status USER_STATUS_ALL )
        { 
// echo "getBlogUsers<br>";
                    
$users = Array();
                    
                    
// get the information about the owner, if requested so
                    
if( $includeOwner ) {
                            
$query "SELECT ".XOOPS_DB_PREFIX."_users.* FROM ".XOOPS_DB_PREFIX."_users, ".$this->_prefix."blogs 
                                                WHERE "
.XOOPS_DB_PREFIX."_users.uid = ".$this->_prefix."blogs.owner_id AND ".$this->_prefix."blogs.id = '".Db::qstr($blogId)."';"
                            
$result $this->Execute$query );
                    
                            if( !
$result )
                                    return 
false;
                    
                            
$row $result->FetchRow();
                            
$result->Close();
                            
array_push$users$this->_mapUserInfoObject$row ));
                    }
                    
                    
// now get the other users who have permission for that blog.
                    
$query2 "SELECT ".XOOPS_DB_PREFIX."_users.* FROM ".XOOPS_DB_PREFIX."_users, ".$this->_prefix."users_permissions 
                                         WHERE "
.XOOPS_DB_PREFIX."_users.uid = ".$this->_prefix."users_permissions.user_id 
                                         AND "
.$this->_prefix."users_permissions.blog_id = '".Db::qstr($blogId)."';"
                    
$result2 $this->Execute$query2 );
                    if( !
$result2 // if error, return what we have so far...
                            
return $users;
                    
                    while( 
$row $result2->FetchRow()) {
                            
array_push$users$this->_mapUserInfoObject($row));
                    }
                    
$result2->Close();
                    
                    return 
$users;
        }
                
                
/**
         * Returns an array of BlogInfo objects with the information of all the blogs to which
         * a user belongs
         *
         * @param userId Identifier of the user
         * @return An array of BlogInfo objects to whom the user belongs.
         */
        
function getUsersBlogs$userid$status BLOG_STATUS_ALL )
        { 
// echo "getUsersBlogs<br>";
                    
return parent::getUsersBlogs($userid,$status);
                }
                
                
/**
          * Returns all the blogs defined for the site in an array, sorted by its
          * blog identifier.
          *
          * @param status
          * @param searchTerms
          * @param page
          * @param itemsPerPage
          *
          * @return Returns an array with all the blogs defined for this site. The array
          * is sorted by the blog identifier, so that $blogs[$blogId] will give us the information
          * of the blog with $blogId as its identifier.
          */
                
function getAllBlogs$status BLOG_STATUS_ALL$blogCategoryId ALL_BLOG_CATEGORIES$searchTerms ""$page = -1$itemsPerPage DEFAULT_ITEMS_PER_PAGE ) {
                                    
                    
$blogs = new Blogs();
                    return 
$blogs->getAllBlogs($status,$blogCategoryId,$searchTerms,$page,$itemsPerPage);
                }
    }
?>

Login

Who's Online

202 user(s) are online (133 user(s) are browsing Support Forums)


Members: 0


Guests: 202


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits