Visualizzazione Stampabile
-
creazione plugin
Salve vorrei sapere se c'è qualche esperto di vbulletin in grado di creare un plugin che possa interfacciarsi con un progetto esistente. Sostanzialmente con vbulletin vorrei gestire la registrazione degli utenti che poi dovranno inviare al nostro sito alcuni documenti e sarebbe utile realizzare qualcosa che unisse queste due realtà.
Mi farebbe piacere ricevere qualche proposta... ciao
-
Il contrario è abbastanza facile, cioè agganciare un prodotto esistente a vBulletin. Io ho fatto una cosa del genere con www.keybuster.com, che inserisce i nuovi utenti anche nel database del forum, che usiamo come ticket system.
Se vuoi provarlo, iscriviti con un account finto e puoi vedere come funziona. Dopo la conferma email sei anche iscritto al forum con la stessa password, ad un gruppo utenti specifico.
-
Script aggiunta utente
Chiamata:
Codice PHP:
// Register to the vBulletin database
require_once('vbadduser.php'); // Open vBulletin database
vbdb_open();
// Add user to vBulletin forum
$success = vbadd_user($username, $password, $email); // Output result
if(!$success)
{
$message = 'Unable to save user to the vBulletin forum database.';
}
else
{
$message = 'User saved successfully to the vBulletin forum database.';
}
Script vbadduser.php
Codice PHP:
<?php
/*******************************************************************************
* www.y2ksw.com *
* (C) Copyright Y2K Software s.a.s. 2005-2006 *
* All Rights Reserved *
********************************************************************************
* Adds a single user to the forum database *
*******************************************************************************/
// Change these parameters to meet your needs ----------------------------------
// database
define('DBHOST', 'localhost');
define('DBPORT', 3306);
define('DBNAME', 'forum_database_name');
define('DBUSERNAME', 'forum_database_username');
define('DBPASSWORD', 'forum_database_password');
// table prefix, e.g. 'vb3_'
define('PREFIX', 'vb3_');
/*
vBulletin standard user groups
1. Unregistered / Not Logged In
2. Registered Users
3. Users Awaiting Email Confirmation
4. (COPPA) Users Awaiting Moderation
5. Super Moderators
6. Administrators
7. Moderators
*/
define('USERGROUPID', 2);
define('USERTITLE', 'Your custom user title');
// Please make sure you have a reputation level <= this value:
define('REPUTATIONDEFAULT', 10);
// Calendar
// sunday = 0; ... saturday = 6;
define('STARTOFWEEK', 1);
// User options - please refer to the vBulletin manual; good place to mess it all up :-)
define('OPTIONS', 7255);
// Functions -------------------------------------------------------------------
// Open the database (fails on error and exits)
function vbdb_open()
{
$host = DBHOST;
if(DBPORT && DBPORT != 3306)
{
$host = DBHOST . ':' . DBPORT;
}
mysql_connect($host, DBUSERNAME, DBPASSWORD)
or die('Unable to connect to the vBulletin database');
mysql_select_db(DBNAME)
or die('Unable to select the vBulletin database');
}
// Generates a totally random string of 3 chars
function vbsalt()
{
$vbsalt = '';
for ($i = 0; $i < 3; $i++)
{
$vbsalt .= chr(rand(32, 126));
}
return $vbsalt;
}
// Save user count & newest user into template
function vbbuild_user_statistics()
{
// get total members
$SQL = "SELECT COUNT(*), MAX(userid) "
. "FROM " . PREFIX . "user"
;
if($rsm = vbrs_open($SQL))
{
// get newest member
$SQL = "SELECT userid, username "
. "FROM " . PREFIX . "user "
. "WHERE userid=$rsm[1] "
. "LIMIT 1"
;
if($rsu = vbrs_open($SQL))
{
// make a little array with the data
$values = array(
'numbermembers' => $rsm[0],
'newusername' => $rsu[1],
'newuserid' => $rsu[0]
);
// update the special template
vbbuild_datastore('userstats', serialize($values));
}
}
}
// Build datastore
function vbbuild_datastore($title = '', $data = '')
{
$title = trim($title);
if($title == '')
{
return;
}
$data = trim($data);
$SQL = "REPLACE INTO " . PREFIX . "datastore ("
. "title, "
. "data"
. ") VALUES ("
. "'" . addslashes($title) . "', "
. "'" . addslashes($data) . "'"
. ")"
;
mysql_query($SQL);
}
// Adds a user to a vBulletin forum
function vbadd_user($username, $password, $email)
{
// Get current date and time
$TIMENOW = time();
// Check if user already exists
$SQL = "SELECT userid "
. "FROM " . PREFIX . "user "
. "WHERE username='" . addslashes($username) . "' "
. "LIMIT 1"
;
if($rs = vbrs_open($SQL))
{
// Returns TRUE since the nickname is already present
// This avoids overwriting an account which has been created before by
// the user
return TRUE;
}
// Add user to forum
$vbsalt = vbsalt();
if(strlen($password) == 32)
{
// if the password has 32 characters we assume it is already in md5 format
$hashedpassword = md5($password . $vbsalt);
}
else
{
// the password is plain text or in an unrecognized format
$hashedpassword = md5(md5($password) . $vbsalt);
}
$SQL = "SELECT reputationlevelid "
. "FROM " . PREFIX . "reputationlevel "
. "WHERE minimumreputation<=" . REPUTATIONDEFAULT . " "
. "ORDER BY minimumreputation DESC "
. "LIMIT 1"
;
$rs = vbrs_open($SQL);
$reputationlevelid = $rs[0];
$SQL = "INSERT INTO " . PREFIX . "user ("
. "username, "
. "salt, "
. "password, "
. "passworddate, "
. "email, "
. "showvbcode, "
. "usertitle, "
. "joindate, "
. "lastvisit, "
. "lastactivity, "
. "usergroupid, "
. "options, "
. "maxposts, "
. "startofweek, "
. "reputationlevelid, "
. "reputation, "
. "autosubscribe"
. ") VALUES ("
. "'" . addslashes($username) . "', "
. "'" . addslashes($vbsalt) . "', "
. "'$hashedpassword', "
. "NOW(), "
. "'" . addslashes($email) . "', "
. "2, "
. "'" . addslashes(USERTITLE) . "', "
. "$TIMENOW, "
. "$TIMENOW, "
. "$TIMENOW, "
. USERGROUPID . ", "
. OPTIONS . ", "
. "-1, "
. STARTOFWEEK . ", "
. "$reputationlevelid, "
. REPUTATIONDEFAULT . ", "
. "-1"
. ")"
;
if(!mysql_query($SQL))
{
return;
}
// Get last inserted user ID
$userid = mysql_insert_id();
// Insert user text fields
$SQL = "INSERT INTO " . PREFIX . "usertextfield ("
. "userid"
. ") VALUES ("
. "$userid"
. ")"
;
if(!mysql_query($SQL))
{
return;
}
// insert custom user fields
$SQL = "INSERT INTO " . PREFIX . "userfield ("
. "userid"
. ") VALUES ("
. "$userid"
. ")"
;
if(!mysql_query($SQL))
{
return;
}
// insert record into password history
$SQL = "INSERT INTO " . PREFIX . "passwordhistory ("
. "userid, "
. "password, "
. "passworddate"
. ") VALUES ("
. "$userid, "
. "'$hashedpassword', "
. "NOW()"
. ")"
;
if(!mysql_query($SQL))
{
return;
}
vbbuild_user_statistics();
return TRUE;
}
function vbrs_open($SQL)
{
$rs = mysql_query($SQL)
or die('Unable to open the vBulletin table');
return mysql_fetch_row($rs);
}
?>