phpbb-integration-kit Synchronizes Yii users with phpBB3 forum

  1. Requirements
  2. Before usage
  3. Usage sample
  4. Changelog
  5. Resources

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

3 0
14 followers
710 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Auth
Tags: Auth, forum, phpbb
Developed by: ElisDN
Created on: Jan 5, 2013
Last updated: 4 years ago

Downloads

show all

Related Extensions