Welcome to Elgg's documentation
This is the place to find documentation on all aspects of Elgg. If you would like to contribute your own documentation please do; we want this to be a real community effort!
VBulletin
From Elgg Documentation
Contents |
[edit] VBulletin Integration
VBulletin is a popular forum system like Vanilla or phpBB.
At difference that their competitors this product not is a Open Source product so some kind integration with this product couldn't be distributed to the public easily.
This page will try to explain what are the necessary steps to integrate this product with elgg.
[edit] Create a plugin skeleton
- Create the vbulletin directory inside your mod directory
- Create the lib.php file
- Create a config.php file
[edit] Copy the vbulletin code inside the plugin
Copy the vbulleting code inside the vbulletin directory that you create before.
I suggest to change the directory name for something like bulletin or board to make the URLs clever (In the form: http://yoursite.com/mod/vbulletin/bulletin instead of http://yoursite.com/mod/vbulletin/vbulletin )
At this point your vbulletin mod must look like:
vbulletin
|--bulletin (directory with the vbulletin code)
|--lib.php
|--config.php
[edit] Code the basic Elgg <=> Vbulletin sync code
- Copy the next code inside your lib.php file.
This is the code that mode the elgg => vbulleting synchronization possible.
If you are interested in change the way elgg profile fields are mapped in vbulletin fields you can modify the vbulletin_sync_user($user) function.
<?
require_once (dirname(__FILE__) . "/bulletin/includes/config.php");
require_once (dirname(__FILE__) . "/config.php");
function vbulletin_pagesetup() {
global $PAGE, $CFG, $messages;
if (isloggedin()) {
if (defined("context") && context == "vbulletin") {
$PAGE->menu[] = array (
'name' => 'forum',
'html' => "<li><a href=\"" . VBULLETIN_URL . " class=\"selected\" >" . __gettext("Forums"
) . '</a></li>');
} else {
$PAGE->menu[] = array (
'name' => 'forum',
'html' => "<li><a href=\"" . VBULLETIN_URL . "\" >" . __gettext("Forums"
) . '</a></li>');
}
}
}
function vbulletin_init() {
global $CFG, $function, $db, $METATABLES, $config;
if (!get_config('vbulletin')) {
if (in_array($config['Database']['tableprefix'] . "user", $METATABLES)) {
// Syncronize the current elgg users
$users = get_records("users", "user_type", "person");
if (is_array($users)) {
foreach ($users as $user) {
vbulletin_sync_user($user);
}
}
set_config('vbulletin', time());
}
}
listen_for_event('user', 'publish', 'vbulletin_sync');
listen_for_event('user', 'delete', 'vbulletin_sync');
listen_for_event('profile_data', 'publish', 'vbulletin_sync');
}
/**
* Event hook to be called to sync elgg users with vbulletin
*
* @param string $object_type Object type (user)
* @param string $event Event type (publish | republish | delete)
* @param mixed $object Event object (user)
*/
function vbulletin_sync($object_type, $event, $object) {
global $config, $messages;
$ident = ($object_type == "user") ? $object->ident : $object->owner;
$user = ($object_type=="user")?$object:get_record("users","ident",$ident);
if ($event == "publish") {
vbulletin_sync_user($user);
} else
if ($event == "delete") {
$query = "DELETE FROM " . $config['Database']['tableprefix'] . "user where userid=" . $ident;
if (!execute_sql($query, false)) {
$messages[] = __gettext("Error deleting the user: " . $ident);
}
}
return $object;
}
/**
* Syncronize a elgg user with vbulletin
* @param object $user Elgg user
*/
function vbulletin_sync_user($user) {
global $config, $CFG, $db, $messages;
$user_data = array (
"ident" => "userid",
"username" => "username",
"password" => "password",
"email" => "email"
);
$profile_data = array (
"aim" => "aim",
"icq" => "icq",
"msn" => "msn",
"personalweb" => "homepage",
"skype" => "skype"
);
$profile_data_sql = "SELECT name,value FROM " . $CFG->prefix . "profile_data";
$profile_data_sql .= " WHERE owner=" . $user->ident;
$profile_data_sql .= " AND access='PUBLIC'";
$profile_data_sql .= " AND name IN (" . implode(',', array_map(array (
$db,
'qstr'
), array_keys($profile_data))) . ")";
$profile = get_records_sql($profile_data_sql);
$profile = (is_array($profile)) ? $profile : array ();
$profile_keys = array ();
$profile_insert = array ();
$profile_update = array ();
$salt .= chr(rand(33, 126));
if (is_array($profile)) {
if (isset ($profile['personalweb'])) {
$profile['personalweb']->value = $CFG->wwwroot . $user->username . "/";
} else {
$profile['personalweb'] = new StdClass;
$profile['personalweb']->name = 'personalweb';
$profile['personalweb']->value = $CFG->wwwroot . $user->username . "/";
}
foreach ($profile as $value) {
$profile_keys[] = $profile_data[$value->name];
$profile_insert[] = $db->qstr($value->value);
$profile_update[] = $profile_data[$value->name] . "=" . $db->qstr($value->value);
}
}
foreach (array_keys($user_data) as $value) {
if($user_data[$value]=="password"){
$user_insert[] = $db->qstr(md5($user-> $value.$salt));
$user_update[] = $user_data[$value] . "=" . $db->qstr(md5($user-> $value.$salt));
}
else{
$user_insert[] = $db->qstr($user-> $value);
$user_update[] = $user_data[$value] . "=" . $db->qstr($user-> $value);
}
}
$insert_values = array_merge(array_values($user_data), array (
"usergroupid,passworddate,salt,options"
));
$insert_values = array_merge($insert_values, $profile_keys);
$user_insert[] = $db->qstr('6');
$user_insert[] = "current_date";
$user_insert[] = $db->qstr($salt);
$user_insert[] = $db->qstr('7');
$query_insert = "INSERT INTO " . $config['Database']['tableprefix'] . "user (" . implode(',', $insert_values) . ")";
$query_insert .= " VALUES (" . implode(',', array_merge($user_insert, $profile_insert)) . ")";
$user_update[] = "passworddate=current_date";
$user_update[] = "salt=".$db->qstr($salt);
$user_update[] = "options=".$db->qstr('7');
$query_update = "UPDATE " . $config['Database']['tableprefix'] . "user SET ";
$query_update .= implode(',', array_merge($user_update, $profile_update));
$query_update .= " WHERE userid=" . $user->ident;
$query = "SELECT userid FROM " . $config['Database']['tableprefix'] . "user WHERE userid=" . $user->ident;
if (record_exists_sql($query)) {
execute_sql($query_update, false);
} else {
if (!execute_sql($query_insert, false)) {
$messages[] = __gettext("Syncronization error");
}
}
}
?>
- In the config.php file paste the following code:
<?php
global $CFG;
define("VBULLETIN_URL",$CFG->wwwroot."mod/vbulletin/bulletin/");
define("VBULLETIN_HOME",dirname(__FILE__)."/bulletin/");
define("VBULLETIN_FORUM","Special interest");
?>
- You must to add the following code on :elgg/units/user/userdetails_actions.php for Elgg v0.8 or in elgg/mod/users/lib/userdetails_actions.php for Elgg v0.9 at end of the "userdetails:update" switch case.
plugin_hook("user","publish",get_record('users','ident',$page_owner));
[edit] Modify vbulletin
- Keep a backup of the following files:
- bulletin/includes/config.php
- bulletin/install/vbulletin-style.xml
- In bulletin/includes/config.php made the following modifications.
At line 22:
// Require of the Elgg Config @require_once dirname(__FILE__)."/../../../../config.php";
At line 29, replace the $config['Database']['dbtype'] property by:
$config['Database']['dbtype'] = $CFG->dbtype;
At line 34, replace the $config['Database']['dbname'] property by:
$config['Database']['dbname'] = $CFG->dbname;
At line 40 add the following lines:
define("ELGG_TABLE_PREFIX",$CFG->prefix);
define("VBULLETIN_ELGG_HOME",$CFG->wwwroot);
At line 59, replace the $config['MasterServer']['servername'] property by:
$config['MasterServer']['servername'] = $CFG->dbhost;
At line 65, replace the $config['MasterServer']['username'] property by:
$config['MasterServer']['username'] = $CFG->dbuser;
At line 66, replace the $config['MasterServer']['password'] property by:
$config['MasterServer']['password'] = $CFG->dbpass;
- Copy the file bulletin/includes/class_core.php to bulletin/includes/class_core_elgg.php and then made the following code modifications.
Note: If your vbulletin version is different that mine probably you will have a different code base. Check the differences with the base file bulletin/includes/class_core.php if needed.
Between lines 2545 and 2551 add the following code:
$elgg_cookie = false;
// TODO ELGG: Obtaining elggperm cookie
if($_COOKIE["elggperm"]){
$sessionhash = md5($_COOKIE["elggperm"]);
$elgg_cookie = true;
}
Between lines 2637 and 2644 add the following code:
// TODO ELGG: Obtaining elggperm cookie
if($elgg_cookie AND $user = $db->query_first_slave("
SELECT *
FROM " . ELGG_TABLE_PREFIX. "users
WHERE code = '".$this->registry->db->escape_string($sessionhash)."'")){
$this->vars['userid'] = $user['ident'];
}
Between lines 2785 and 2788 add the following code:
if($_COOKIE["elggperm"]){
//TODO ELGG: Retornando la cookie de elgg
return md5($_COOKIE["elggperm"]);
}
Between lines 2820 and 2821 add the following code:
//vbsetcookie('sessionhash', $sessionhash, false, false, true);
After that replace the line 46 of file bulletin/includes/init.php with this one:
require_once(CWD . '/includes/class_core_elgg.php');
The following modifications are for vbulletin to Elgg user sync however personally I prefer to disable the vbulletin registration for 'force' the users to register on your Elgg install.
I don't think so this will be necessary (I do this integration some time ago so I didn't remember all the details) however this is the behaviour that I have tested so you can use it without problem.
- Keep a backup of the following files:
- bulletin/register.php
- bulletin/profile.php
- For synchronize vbulletin => Elgg users modify the bulletin/register.php file at the line 388 just after:
$userdata_rank =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdata_rank->set_existing(fetch_userinfo($userid));
$userdata_rank->set('posts', 0);
$userdata_rank->save();
Paste the following code:
// ELGG: Do user syncronization with elgg
$elgg_query = "INSERT INTO ".ELGG_TABLE_PREFIX."users (ident,username,password,email) VALUES(";
$elgg_query.= $userid.",'".$vbulletin->GPC['username']."','".$vbulletin->GPC['password_md5']."','".$vbulletin->GPC['email']."')";
$db->query_write($elgg_query);
- In bulletin/profile.php add the following code at the between the lines 348 and 363:
//TODO ELGG: Update email and password
$elgg_query = "UPDATE ".ELGG_TABLE_PREFIX."users set ";
$_email = false;
if(!empty($vbulletin->GPC['email'])){
$elgg_query .= "email='".$vbulletin->GPC['email']."'";
$_email=true;
}
if(!empty($vbulletin->GPC['newpassword_md5'])){
$elgg_query.= ($_email)?",":"";
$elgg_query.="'password=".$vbulletin->GPC['newpassword_md5']."'";
}
$elgg_query.=" WHERE ident=".$vbulletin->userinfo['userid'];
$db->query_write($elgg_query);
And the following between the lines 871 and 909
//TODO ELGG: sync profile data
$elgg_data = array();
if(!empty($vbulletin->GPC['icq'])){
$elgg_data['icq']=$vbulletin->GPC['icq'];
}
if(!empty($vbulletin->GPC['msn'])){
$elgg_data['msn']=$vbulletin->GPC['msn'];
}
if(!empty($vbulletin->GPC['aim'])){
$elgg_data['aim']=$vbulletin->GPC['aim'];
}
if(!empty($vbulletin->GPC['yahoo'])){
$elgg_data['yahoo']=$vbulletin->GPC['yahoo'];
}
if(!empty($vbulletin->GPC['skype'])){
$elgg_data['skype'] =$vbulletin->GPC['skype'];
}
if(!empty($vbulletin->GPC['homepage'])){
$elgg_data['personalweb']= $vbulletin->GPC['homepage'];
}
foreach($elgg_data as $key => $value){
$profile_data_sql = "SELECT * FROM ".ELGG_TABLE_PREFIX."profile_data ";
$profile_data_sql.="WHERE name='$key' ";
$profile_data_sql.="AND owner=".$vbulletin->userinfo['userid'];
if($profile= $db->query_first_slave($profile_data_sql)){
$elgg_query = "UPDATE ".ELGG_TABLE_PREFIX."profile_data SET ";
$elgg_query.= "name='".$key."' ";
$elgg_query.= ", value='".$value."' ";
$elgg_query.= "WHERE ident=".$profile['ident'];
}
else{
$elgg_query = "INSERT INTO ".ELGG_TABLE_PREFIX."profile_data (name,value,owner) VALUES (";
$elgg_query.= "'$key','$value',".$vbulletin->userinfo['userid'].")";
}
$db->query_write($elgg_query);
}
[edit] Install vbulletin
Install vbulletin using their default installer(http://www.yoursite/mod/vbulletin/bulletin). Be sure that the vbulletin tables are created in THE SAME database that your Elgg install.
[edit] Modify vbulletin template system
Made the proper modifications in your bulletin/install/vbulletin-style.xml file.
Note: I suggest that for make links to your Elgg install you need to put in this file the complete URLs to your Elgg resources. Relative URLs could be problematic.
[edit] Try your plugin
Enter to http://www.yoursite.com/ and test it!
--dramirez 03:12, 7 January 2008 (UTC)

