Entries from April 2008

Wednesday, April 30th, 2008

Using Phpbb3 Avatars In Custom Pages

Recently I’ve been working on a custom web app that integrates with phpbb3. In this app, I’d like to have a custom user profile page. I have my own ‘users’ table and the link between the two is the “user_id” field which I set when the user first enters the app. Throughout, however, there are “Submitted By:” sections with links to the user’s profile page.

On said profile page, I’d like to show the user’s avatar straight from phpbb. This took some hackery, but I finally got it working. Behold.

First off, if you’re not already doing phpbb session management, here’s that code. This requires your phpbb user to be logged in:

define(’IN_PHPBB’, true);

//replace $phpbb_root_path with path to your forum<
$phpbb_root_path = ‘../forum/’;
$phpEx = substr(strrchr(__FILE__, ‘.’), 1);
include($phpbb_root_path . ‘common.’ . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

Next, we need to include the phpbb functions file so we can run the function “get_user_avatar”:

include($phpbb_root_path . ‘includes/functions_display.’ . $phpEx);

Now, for the business:

//close the current DB connection, where $OPEN_CONNECTION is your MySQL connection
//mysql_close($OPEN_CONNECTION);
//then go to the forum DB and get this user’s avatar info
//include your forum’s ‘config.php’ file — this is custom
//to wherever that file is!!

include (’../forum/config.php’);

//connect to the forum’s database
$db2 = mysql_connect($dbhost, $dbuser, $dbpasswd)
or die(”Unable to connect to MySQL”);
$selected = mysql_select_db($dbname,$db2)
or die(”Could not select the database”);

//here’s the SQL query. REPLACE “$USER_ID”
//with the user id you’d like to query.
$sql = ‘SELECT `user_avatar`, `user_avatar_type`, `user_avatar_width`,
`user_avatar_height` FROM `phpbb_users`
WHERE `user_id` = ‘ . $USER_ID . ”;
$result2 = mysql_query($sql); $row = mysql_fetch_array($result2);

//finally, this will return the avatar
echo get_user_avatar($row['user_avatar'],
$row['user_avatar_type'], $row['user_avatar_width'],
$row['user_avatar_height']);

That’s it! Enjoy.

Tags: > > > >

Friday, April 18th, 2008

Caught in the Act

Poor Kid. I knew you could get stuck in those things, but I figured only an arm…not your whole…person.

Tags: > > > >

Wednesday, April 16th, 2008

Microsoft - what the…?

Tags: > > >