<?php
/**
* phpnuke Jamroom Bridge Plugin
* @package Talldude_Library
* @subpackage Jamroom_Bridges
* @copyright 2006 by Brian Johnson / Talldude Networks LLC
* @author Brian Johnson -
bigguy@talldude.net & Stephen Bishop
www.projectoverseer.biz
* @filesource
* $Id: phpnuke.php,v 3.11 2006-09-06 03:02:52 Revolution Exp $
*/
defined('IN_JAMROOM') or exit();
//------------------------------------------------------------
// configuration
//------------------------------------------------------------
$GLOBALS['nuke']['server'] = 'localhost'; // machine nuke is running on
$GLOBALS['nuke']['dbname'] = ''; // nuke Database name
$GLOBALS['nuke']['dbuser'] = ''; // database user name
$GLOBALS['nuke']['dbpass'] = ''; // database user password
$GLOBALS['nuke']['prefix'] = 'nuke'; // default phpnuke table prefix
$GLOBALS['nuke']['language'] = 'english'; // default phpnuke user language
$GLOBALS['nuke']['grp_desc'] = 'Personal User'; // Group Description
//------------------------------------------------------------
// You should not need to edit below here
//------------------------------------------------------------
/**
* The jrBridge_check function is used before the "create" function
* as a way to "precheck" the phpnuke forum and see if a user account
* name already exists - this allows an error to be returned in
* Jamroom so name duplication does not occur.
*
* @param array Incoming array of User Info
*
* @return bool Returns true/false on success/fail
*/
function jrBridge_check($_data)
{
// Verify we recieved our input array
if (!is_array($_data)) {
return('ERROR: jrBridge_create() Input _data array is empty!');
}
// Now connect up to the phpnuke database and do our work
$con = jrBridge_phpnuke_connect();
if (!is_resource($con)) {
return("ERROR: unable to open the phpnuke database - MySQL error: {$con}");
}
$user = dbEscapeString($_data['user_nickname']);
// check to see if the user account already exists
$req = "SELECT username
FROM {$GLOBALS['nuke']['prefix']}_users
WHERE username = '{$user}'";
$res = mysql_query($req,$con);
if (mysql_num_rows($res) > 0) {
return("ERROR: username {$user} already exists in phpnuke user table!");
}
return(true);
}
/**
* The jrBridge_create function is used for "creating" a new
* entry in the phpnuke forum.
*
* @param array Incoming array of User Info
*
* @return mixed Returns error string on failure, bool true on success
*/
function jrBridge_create($_data)
{
// Verify we recieved our input array
if (!is_array($_data)) {
return('ERROR: jrBridge_create() Input _data array is empty!');
}
// our user password comes in unencrypted - lets MD5 it
$pass = md5($_data['user_password']);
$user = dbEscapeString($_data['user_nickname']);
$mail = dbEscapeString($_data['user_emailadr']);
// Now connect up to the phpnuke database and do our work
$con = jrBridge_phpnuke_connect();
if (!is_resource($con)) {
return("ERROR: unable to open the phpnuke database - MySQL error: {$con}");
}
// get what our next user_id is going to be
$req = "SELECT MAX(user_id + 1) AS new_id FROM {$GLOBALS['nuke']['prefix']}_users";
$res = mysql_query($req,$con);
if (mysql_num_rows($res) > 0) {
$_row = mysql_fetch_assoc($res);
$new_id = $_row['new_id'];
}
mysql_free_result($res);
if (!is_numeric($new_id) || $new_id <= 1) {
mysql_close($con);
return("ERROR: unable to determine the incremental user_id value from phpnuke - verify database connectivity");
}
// Insert our User account
$GLOBALS['nuke']['language'] = dbEscapeString($GLOBALS['nuke']['language']);
$req = "INSERT INTO {$GLOBALS['nuke']['prefix']}_users (user_id,user_active,username,user_password,user_regdate,user_lang,user_email)
VALUES ({$new_id},1,'{$user}','{$pass}',". time() .",'{$GLOBALS['nuke']['language']}','{$mail}')";
mysql_query($req,$con) or $err = mysql_errno() ."-". mysql_error();
if (isset($err)) {
mysql_close($con);
return("ERROR: failed to insert new user into the phpnuke user table - MySQL error: {$err}");
}
// Insert group account
$req = "INSERT INTO {$GLOBALS['nuke']['prefix']}_bbuser_group (group_id,user_id,user_pending)
VALUES ({$new_id},{$new_id},0)";
mysql_query($req,$con) or $err = mysql_errno() ."-". mysql_error();
if (isset($err)) {
mysql_close($con);
return("ERROR: failed to insert new user into the phpnuke user_group table<br>MySQL error: {$err}");
}
$GLOBALS['nuke']['grp_desc'] = dbEscapeString($GLOBALS['nuke']['grp_desc']);
$req = "INSERT INTO {$GLOBALS['nuke']['prefix']}_bbgroups (group_id,group_type,group_description,group_moderator,group_single_user)
VALUES ({$new_id},1,'{$GLOBALS['nuke']['grp_desc']}',0,1)";
mysql_query($req,$con) or $err = mysql_errno() ."-". mysql_error();
if (isset($err)) {
mysql_close($con);
return("ERROR: failed to insert new user into the phpnuke groups table<br>MySQL error: {$err}");
}
mysql_close($con);
return(true);
}
/**
* The jrBridge_create function is used for "creating" a new
* entry in the phpnuke forum.
*
* @param array Incoming array of User Info
*
* @return mixed Returns error string on failure, bool true on success
*/
function jrBridge_update($_data)
{
// Verify we recieved our input array
if (!is_array($_data)) {
return('ERROR: jrBridge_create() Input _data array is empty!');
}
// Now connect up to the phpnuke database and do our work
$con = jrBridge_phpnuke_connect();
if (!is_resource($con)) {
return("ERROR: unable to open the phpnuke database - MySQL error: {$con}");
}
// Update User account
$req = "UPDATE {$GLOBALS['nuke']['prefix']}_users SET ";
if (strlen($_data['user_password']) > 0) {
$req .= "user_password = '". md5($_data['user_password']) ."',
user_email = '". dbEscapeString($_data['user_emailadr']) ."' ";
}
else {
$req .= "user_email = '". dbEscapeString($_data['user_emailadr']) ."' ";
}
$req .= "WHERE username = '". dbEscapeString($_data['user_nickname']) ."'
LIMIT 1";
$res = mysql_query($req,$con) or $err = mysql_errno() ."-". mysql_error();
if (mysql_affected_rows($con) == 0) {
mysql_close($con);
return("ERROR: failed to update user {$_data['user_nickname']} in phpnuke user table - MySQL error: {$err}");
}
mysql_close($con);
return(true);
}
/**
* The jrBridge_delete function is used for "deleting" an entry
* in the phpnuke forum.
*
* @param string Username to remove from forum
*
* @return mixed Returns error string on failure, bool true on success
*/
function jrBridge_delete($_data)
{
// Verify we recieved our input array
if (!is_array($_data)) {
return('ERROR: jrBridge_delete() Input _data array is empty!');
}
// Now connect up to the phpnuke database and do our work
$con = jrBridge_phpnuke_connect();
if (!is_resource($con)) {
return("ERROR: unable to open the phpnuke database - MySQL error: {$con}");
}
// Delete User account
$req = "DELETE FROM {$GLOBALS['nuke']['prefix']}_users
WHERE username = '". dbEscapeString($_data['user_nickname']) ."'
AND user_level != 1
LIMIT 1";
$res = mysql_query($req,$con) or $err = mysql_errno() ."-". mysql_error();
if (mysql_affected_rows($con) == 0) {
mysql_close($con);
return("ERROR: failed to delete user {$_data['user_nickname']} from phpnuke user table - MySQL error: {$err}");
}
mysql_close($con);
return(true);
}
/**
* The jrBridge_test function is used for "testing" the Bridge Plugin.
* Any "checks" can be added to this function
*
* @return mixed Returns error string on failure, bool true on success
*/
function jrBridge_test()
{
// Test Database connection
$con = jrBridge_phpnuke_connect();
if (!is_resource($con)) {
return("ERROR: unable to open the phpnuke database - MySQL error: {$con}");
}
// Test incremental USER ID select
$req = "SELECT MAX(user_id + 1) AS new_id FROM {$GLOBALS['nuke']['prefix']}_users";
$res = mysql_query($req,$con);
if (mysql_num_rows($res) > 0) {
$_row = mysql_fetch_assoc($res);
$test_id = $_row['new_id'];
}
mysql_free_result($res);
if (!is_numeric($test_id) || $test_id <= 1) {
mysql_close($con);
return("ERROR: unable to determine the incremental user_id value from phpnuke - verify database connectivity");
}
mysql_close($con);
return(true);
}
/**
* The jrBridge_create function is used for "creating" a new
* entry in the phpnuke forum.
*
* @param array Incoming array of User Info
*
* @return mixed Returns error string on failure, bool true on success
*/
function jrBridge_phpnuke_connect()
{
// Now connect up to the phpnuke database and do our work
$con = mysql_connect($GLOBALS['nuke']['server'],$GLOBALS['nuke']['dbuser'],$GLOBALS['nuke']['dbpass']) or $err = mysql_errno() .' - '. mysql_error();
if (isset($err)) {
return('Invalid MySQL Server Name, Username or Password');
}
mysql_select_db($GLOBALS['nuke']['dbname'],$con) or $err = mysql_errno() .' - '. mysql_error();
if (isset($err)) {
return('Invalid MySQL Database');
}
return($con);
}
?>