CodeIgniter integration with phpbb

Help for PHP & MY SQL

CodeIgniter integration with phpbb

Postby king on November 19th, 2009, 1:19 pm

CodeIgniter integration with phpbb
Any idea’s on how to solve that?
Edit: I’ve just made a library to do the work

Bb library:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author Rick Ellis
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeignitor.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/

// ------------------------------------------------------------------------

/**
* CodeIgniter phpBB3 Library
*
* @author Sarre
* @link http://codeigniter.com/forums/viewthread/45737/
*
*
* IMPORTANT: url_helper: redirect function had to be renamed to CI_redirect,
* because of a conflict with phpBB's redirect function.
*/

// ------------------------------------------------------------------------

Class Bb {
var $user;

/**
* Use the session management of phpBB3
*/
function Bb()
{

$this->object =& get_instance();
$this->object->load->database();

global $db, $cache, $phpEx, $method, $config, $phpbb_root_path;
$phpEx = "php";
$phpbb_root_path = "../phpBB3/";
define('IN_PHPBB', true);
include('../phpBB3/common.php');
$user->session_begin();
$auth->acl($user->data);
$this->user = $user;
}

/**
* Return username
*/
function getMe()
{
return $this->user;
}

/**
* Return user information
*/
function get($what)
{
return $this->user->data[$what];
}

/**
* Collect session_id
*/
function getId()
{
$sql = "SELECT user_id FROM phpbb3_users WHERE username='" . $this->user->data['username'] . "' LIMIT 1";
$query = $this->object->db->query($sql);
$row = $query->row();
return $row->user_id;
}

/**
* Collect user information through an id
*/
function getUserById($user_id)
{
$sql = "SELECT * FROM phpbb3_users WHERE user_id = '$user_id' LIMIT 1";
$query = $this->object->db->query($sql);
return $query->row();
}

/**
* Collect user information through a name
*/
function getUserByName($user_name)
{
$sql = "SELECT * FROM phpbb3_users WHERE username = '$user_name' LIMIT 1";
$query = $this->object->db->query($sql);
return $query->row();
}

/**
* Permissions functions
*/
function get_User_Memberships()
{
$user_id = $this->getId();
$sql = "SELECT g.group_name FROM phpbb3_groups g , phpbb3_user_group u WHERE u.user_id ='$user_id' AND u.group_id = g.group_id";
$result = $this->object->db->query($sql);
$usergroups = $result->result_array();

for($i=0; $i<count($usergroups); $i++) {
$groups[$i] = $usergroups[$i]['group_name'];
}
return $groups;
}

function isMember($needed_group)
{
$groups = $this->get_User_Memberships();
$status= false;
$needed_group = strtoupper($needed_group);
if (in_array($needed_group,$groups))
{
$status = true;
}
return $status;
}

function isAdmin()
{
if($this->isMember("Administrators"))
{
return true;
} else {
return false;
}
}

function isRegistered()
{
if($this->isMember("Registered"))
{
return true;
} else {
return false;
}
}

}
?>

Then in your controller, you can do stuff like this:
$this->load->library('Bb');

/* Checking out some functions */

echo "<b>username:</b> " . $this->bb->getMe()->data['username'];
echo "<br /><b>username:</b> " . $this->bb->get("username");
echo "<br /><b>user_type:</b> " . $this->bb->get("user_type");
echo "<br /><b>user_type:</b> " . $this->bb->getUserById($this->bb->getId())->user_type;

echo "<br /><b>id:</b> " . $this->bb->getId();
echo "<br /><b>getUserById(1):</b> ";
print_r($this->bb->getUserById(1));
echo "<br />";
echo "<b>get username of no_name:</b> " . $this->bb->getUserById(1)->username . "<br />";
echo "<b>get user_type of no_name:</b> " . $this->bb->getUserById(1)->user_type . "<br />";
echo "<b>get username of some_user:</b> " . $this->bb->getUserById(2)->username . "<br />";
echo "<b>get user by name:</b> ";
$no_name = $this->bb->getUserByName("Anonymous");
echo $no_name->username;
echo "<br />";

echo "<br />Permissions functions:<br />";
echo "<br />";
if($this->bb->isRegistered()) echo "<b>You're registered!</b>";
else echo "<b>You're NOT registered!</b>";
echo "<br />";
if($this->bb->isAdmin()) echo "<b>You're an admin!</b>";
else echo "<b>You're NOT an admin!</b>";
echo "<br />";
if($this->bb->isMember("Administrators")) echo "You are member of the Administrators group!";
else echo "You are NOT part of the Administrators group!";

The advantage of using a library is that you can now autoload it!
Don’t forget to make the changes to phpBB as I described in a previous post…

//Unfortunately, it still conflicts with the url_helper…
Edit: change the url_helper function: rename redirect() tot CI_redirect() -> no more conflict
Edit2: changed it into a library, so you can autoload it (thought that you could autoload models, but you can’t)

Sarre

http://codeigniter.com/forums/viewthread/45737/
king
Site Admin
 
Posts: 288
Joined: April 24th, 2008, 5:36 pm

Manipulate accounts of PHPBB 3 users

Postby king on November 19th, 2009, 3:11 pm

Detailed description
This class can be used to manipulate accounts of PHPBB 3 users.

It can access the MySQL database of a PHPBB 3 installation to perform several types of operations on PHPBB 3 user accounts. Currently it can:

- Begin and end an user login session
- Check if an user is logged in
- Add a new user account
- Delete an user account
- Change user options and password

There is also an auxiliary script to keep the phpBB session alive is it is used as a slave application (this script should be included in a hidden frame if conflicts appear)

http://www.phpclasses.org/browse/package/4826.html
king
Site Admin
 
Posts: 288
Joined: April 24th, 2008, 5:36 pm

Re: CodeIgniter integration with phpbb

Postby king on January 5th, 2010, 6:37 pm

king
Site Admin
 
Posts: 288
Joined: April 24th, 2008, 5:36 pm


Return to PHP & MY SQL

Who is online

Users browsing this forum: No registered users and 1 guest

cron