Yii 1.1: phpbb-integration-kit

Synchronizes Yii users with phpBB3 forum
16 followers

Synchronizes Yii users with phpBB3 forum

Requirements

Yii 1.1 or above

Before usage

Disable a profile activation in your forum.

Add redirects from a forum to the site in forum/ucp.php:

case 'register':
 
    header('location: /site/registration');
    exit();
    break;
 
case 'login':
 
    header('location: /site/login');
    exit();
    break;
 
case 'logout':
 
    header('location: /site/logout');
    exit();
    break;

Rename class user to bbuser in forum sources forum/includes/session.php:

class user extends session
{
    // ...    
    function user()    
    // ...
}

to

class bbuser extends session
{
    // ...    
    function bbuser()    
    // ...
}

Replace in forum/common.php

// Instantiate some basic classes
$user       = new user();

to

// Instantiate some basic classes
$user       = new bbuser();

Remove input fields 'ICQ', 'AVATAR', etc. from forum templates ucp_profile_profile_info.html and ucp_profile_avatar.html.

Note: If you don't want to modify your forum core files, you can move login/logout/register redirects to .htaccess. But if your application contains class User, you must use namespaces or must rename your own class.

Usage sample

Configure protected/config/main.php

return array(
 
    'modules'=>array(
        // ...
        'phpbb',
    }
 
    'components'=>array(
 
        // ...
 
        'db'=>array(
            'connectionString' => '...',
        ),
 
        'forumDb'=>array(
            'class'=>'CDbConnection',
            'connectionString' => '...',
            'tablePrefix' => 'phpbb_',
            'charset' => 'utf8',
        ),
 
        'phpBB'=>array(
            'class'=>'phpbb.extensions.phpBB.phpBB',
            'path'=>'webroot.forum',
        ),        
 
        // Synchronize Login/Logout. See PhpBBWebUser for inheritance details
        'user'=>array(
            'class'=>'phpbb.components.PhpBBWebUser',
            'allowAutoLogin'=>true,
            'loginUrl'=>array('/site/login'),
        ),
 
        'image'=>array(
            'class'=>'ext.image.CImageHandler',
        ),
 
        'file'=>array(
            'class'=>'ext.file.CFile',
        ),
    ),
);

Attach behavior and relation to your User model:

class User extends CActiveRecord
{
    public function behaviors()
    {
        return array(
            'PhpBBUserBehavior'=>array(
                'class'=>'phpbb.components.PhpBBUserBehavior',
                'usernameAttribute'=>'username',
                'newPasswordAttribute'=>'new_password',
                'emailAttribute'=>'email',
                'avatarAttribute'=>'avatar',
                'avatarPath'=>'webroot.upload.images.avatars',
                'forumDbConnection'=>'forumDb',
                'syncAttributes'=>array(
                    'site'=>'user_website',
                    'icq'=>'user_icq',
                    'from'=>'user_from',
                    'occ'=>'user_occ',
                    'interests'=>'user_interests',
                )
            ),
        );
    }
 
    public function relations()
    {    
        Yii::import('phpbb.models.*');
        return array(
            'phpBbUser'=>array(self::HAS_ONE, 'PhpBBUser', array('username'=>'username')),
        );
    }
}

Access to forum userdata:

<?php $model = User::model()->findByPk(Yii::app()->user->id); ?>
 
Private messages: <a href="/forum/ucp.php?i=pm&folder=inbox">New <?php echo $model->phpBbUser->user_unread_privmsg; ?></a>

Access to forum friends:

foreach ($model->phpBbUser->friends as $friend)
{
    echo $friend->user->name . ' ' . $friend->user->lastname . ' ' . $friend->age;
}

Changelog

Version 1.1

* Fixed avatarPath handling

Resources

Total 6 comments

#13839 report it
ElisDN at 2013/07/01 05:10am
Re: Re: Re: How is it supposed to work?

Yes, the extension just creates same entry (with same username and same password) in a forum database on the User onAfterSave event (if isNewRecord is true). You must register all existing site users in a forum manually or recreate synchronized entries with help of the phpBB component of your application:

Yii::app()->phpBB->userAdd($username, $password, $email, 2);
#13837 report it
kokoseq at 2013/07/01 03:56am
Re: Re: How is it supposed to work?

Hi, thanks for quick reply. Yes I did turn captcha etc off. The same user does not exist in forum database, do I have to create it first? If so, what attributes do I have to migrate? Do I have to use the same password hashing as phpbb forum? Cheers

#13834 report it
ElisDN at 2013/06/30 11:22am
Re: How is it supposed to work?

Hi! Did you turn off a forum captcha or an another antispam system? Does same user exist in a forum database table?

#13831 report it
kokoseq at 2013/06/29 01:22pm
How is it supposed to work?

Hi!

Thanks for extension. I tried to use it but I do not actually get how it works exactly. I integrated components to my application, but all I get is that when I click login on forum page, I am redirected to my application login page. When I login as existing user and go back to forum, I am still not logged in forum and can not create new post etc. Where exactly does your code deals with this? Thanks

#11312 report it
ElisDN at 2013/01/05 05:54am
Re: phpBB3 updates

You can move login/logout/register redirects to .htaccess. But if your application contains class User, you must use namespaces or rename your own class. Fixed readme.

#11310 report it
pappfer at 2013/01/05 05:24am
phpBB3 updates

Sounds great! But what is happening if a new phpBB version released? If I use the automatic updater won't it be a problem that I edited some phpBB core files?

Leave a comment

Please to leave your comment.

Create extension