I use vBulletin forum software (the old 3.x version) its just my preferred forum software. Although vBulletin 3 has been updated to support at least PHP 7.1, a lot of products that were developed for it are horribly outdated.
I am trying to learn how to upgrade theses products, I have a little PHP knowledge but not as much as I wish. Some things I have done in my learning progress for example; I download an older version of vBulletin 3, and a newer version then compare the files to see what types of changes they've made. This isn't really helpful in learning though. (why are these changes being made, what do these changes mean?) I have kept notes on things I've noticed changed in newer files, and this is an example of things I have been changing.
Find:
datamanager(
function vB_DataManager
function delete()
=&
split(
$groupis = $_GET['groupis'];
split
parent::
ereg
Replace:
datamanager_init(
function __construct
function delete($doquery = true)
=
preg_split(
$groupis = intval($_GET['groupis']);
explode
parent::__construct
preg_match
I keep my find list and replace list so the lines match what needs to be replaced with what.
The latest product I am trying to update contains multiple files, one thing I know to replace that is not on my list is '&$'(but not always...? from what I've read, so when is right to replace them?) This is Just one file of about 5 that I am working on, it currently functions (with errors here and there), but I don't know where to begin with actually updating this to be a more efficient code. (removed some functions for char limit)
class vbma
{
var $vbulletin;
var $fields = array(//Array of commonly used filed names, Also alows intergration
'custnum' => 'custnum',//Key (short name) => Value (database table name)
'mpassword' => 'ma_password',
'info' => 'ma_info'
);
var $currency_sym;
var $vbphrase;
var $addons = array();
function vbma($vbulletin, $vbphrase)
{
$this->vbulletin = $vbulletin;
$this->vbphrase = $vbphrase;
foreach (glob("includes/class_vbma*.php") as $addon)
{
if ($addon == 'includes/class_vbma.php')
{
continue;
}
require_once (DIR . '/' . $addon);
$addon = basename(substr($addon, 19, strlen($addon)), '.php');
$name = 'vbma_' . $addon;
$this->$addon = new $name($this);
$this->addons["$addon"] = $addon;
}
}
function init($permissions)
{
$vbphrase = $this->vbphrase;
$this->canViewMemArea($permissions);
if ($this->vbulletin->options['memarea_enabled'] == 0 and !($this->vbulletin->
userinfo['permissions']['adminpermissions'] & $this->vbulletin->
bf_ugp_adminpermissions['cancontrolpanel']))
{
eval(standard_error($this->vbulletin->options['memarea_offmessage']));
} elseif ($this->vbulletin->options['memarea_enabled'] == 0 and $this->vbulletin->
userinfo['permissions']['adminpermissions'] & $this->vbulletin->
bf_ugp_adminpermissions['cancontrolpanel'])
{
$oringle = $vbphrase['alert_board_off'];
$vbphrase['alert_board_off'] = $this->vbphrase['memarea_off'];
eval('$GLOBALS[navbar] .= "' . fetch_template('board_inactive_warning') . '";');
}
foreach ($this->addons as $addon)
{
if (method_exists($this->$addon, 'init'))
{
$this->$addon->init();
}
}
$maxlength = TIMENOW - (60 * 60 * 24 * 3);
$GLOBALS['ma_session'] = $this->vbulletin->db->query_first("SELECT * FROM " .
TABLE_PREFIX . "ma_session WHERE userid = '" . $this->vbulletin->userinfo['userid'] .
"' AND dateline > '" . $maxlength . "'");
$GLOBALS['curr'] = $this->getCurrency();
$this->currency_sym = $GLOBALS['currency_sym'] = $this->vbulletin->options['memarea_curr_code'];
}
function checkCustomerInfo($customernum, $password)
{
$fcust = $this->fields['custnum'];
$fpass = $this->fields['mpassword'];
if ($this->vbulletin->userinfo["$fcust"] == $customernum and $this->vbulletin->
userinfo["$fpass"] == $password)
{
return true;
}
return false;
}
function startSession($userid)
{
$this->vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX .
"ma_session (`userid`, `dateline`) VALUES (
'" . $this->vbulletin->db->escape_string($this->vbulletin->userinfo['userid']) .
"', '" . TIMENOW . "'
)");
}
function getCurrency()
{
$curr_a = array('$' => 'USD', $this->vbphrase['memarea_currency_eur'] => 'EUR',
$this->vbphrase['memarea_currency_pound'] => 'GBP', $this->vbphrase['memarea_currency_nis'] =>
'NIS');
return $curr_a[$this->vbulletin->options['memarea_curr_code']];
}
function getPaypalAddress($license)
{
$paypal = $license['paypal'];
if (empty($paypal) or $paypal == '0')
{
$paypal = $this->vbulletin->options['memarea_paypal_email'];
}
return $paypal;
}
function getLicense($licenseid, $checkpermission = true, $getproduct = true, $productfields =
'products.id as proid, products.title as protitle', $throwerror = true, $getExpireDate = true,
$showExpiredErrors = false, $showSusErrors = false)
{
if ($getproduct)
{
$license = $this->vbulletin->db->query_first("SELECT licenses.*, $productfields FROM " .
TABLE_PREFIX . "ma_licenses as licenses
LEFT JOIN " . TABLE_PREFIX .
"ma_products as products ON (products.id = licenses.productid)
WHERE licenses.id = '" . $licenseid . "'");
}
else
{
$license = $this->vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX .
"ma_licenses WHERE id = '" . $licenseid . "'");
}
if ($throwerror and empty($license))
{
eval(standard_error(fetch_error('license_not_found')));
}
if ($checkpermission and $this->vbulletin->userinfo['userid'] !== $license['userid'])
{
print_no_permission();
}
if ($getExpireDate)
{
$license['expiredate'] = $this->getLicenseExpireDate($license);
}
if ($showExpiredErrors and $this->isExpired($license))
{
eval(standard_error(fetch_error('memarea_license_expired')));
}
if ($showSusErrors and $this->isSuspended($license))
{
eval(standard_error(fetch_error('memarea_suspended_license')));
}
return $license;
}
function isExpired($license)
{
if (intval($license['status']) == 0 or ($license['expire'] !== '0' and (($license['dateline'] +
$license['expire']) <= TIMENOW)))
{
return true;
}
else
{
return false;
}
}
function isSuspended($license)
{
if (intval($license['status']) == 1)
{
return true;
}
else
{
return false;
}
}
function getLicenseExpireDate($license)
{
if ($license['expire'] == '0')
{
return $this->vbphrase['memarea_lifetime'];
}
else
{
return vbdate($this->vbulletin->options['dateformat'], ($license['dateline'] + $license['expire']));
}
}
function sendCustomerInfo($userid, $username, $email, $num, $pass)
{
if ($this->vbulletin->options['memarea_notification_type'] == 0 or $this->
vbulletin->options['memarea_notification_type'] == 2)
{
vbmail($email, $this->vbphrase['memarea_email_subject'], construct_phrase($this->
vbphrase['memarea_email_message'], $num, $pass));
}
if ($this->vbulletin->options['memarea_notification_type'] == 1 or $this->
vbulletin->options['memarea_notification_type'] == 2)
{
$pmdm = datamanager_init('PM', $this->vbulletin, ERRTYPE_ARRAY);
$pmdm->set('fromuserid', $this->vbulletin->options['memarea_botuser']);
$fuserinfo = $this->vbulletin->db->query_first("SELECT username FROM " .
TABLE_PREFIX . "user WHERE userid = '" . $this->vbulletin->options['memarea_botuser'] .
"'");
$pmdm->set('fromusername', $fuserinfo['username']);
$pmdm->set('title', $this->vbphrase['memarea_email_subject']);
$pmdm->set('message', construct_phrase($this->vbphrase['memarea_email_message'],
$num, $pass));
$botpermissions = array();
$botpermissions['adminpermissions'] = 2;
$pmdm->set_recipients($username, $botpermissions);
$pmdm->set('dateline', TIMENOW);
$pmdm->pre_save();
if (count($pmdm->errors) == 0)
{
$pmdm->save();
}
else
{
var_dump($pmdm->errors);
}
}
}
function setCustomerNumber($ma_info, $usergroup = '', $usevb = true, $userinfo = '')
{
if ($usevb == false)
{
$this->vbulletin->userinfo = $userinfo;
}
$fcust = $this->fields['custnum'];
$fpass = $this->fields['mpassword'];
$finfo = $this->fields['info'];
$userdm = datamanager_init('User', $this->vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($this->vbulletin->userinfo['userid']);
$userdm->set_existing($userinfo);
if (!$this->vbulletin->userinfo["$fcust"] and !$this->vbulletin->userinfo["$fpass"])
{
$rand = rand($this->vbulletin->options['memarea_numstart'], $this->vbulletin->
options['memarea_numend']);
$num = $this->vbulletin->options['custnum_prefix'] . substr(md5($rand), 0, $this->
vbulletin->options['memarea_custnumleng'] - strlen($this->vbulletin->options['custnum_prefix']));
$userdm->set($fcust, $num);
$pass = substr(md5(time() . $num . $rand . rand(0, 2000)), 0, $this->vbulletin->
options['memarea_custnumleng']);
$userdm->set($fpass, $pass);
$this->sendCustomerInfo($this->vbulletin->userinfo['userid'], $this->vbulletin->
userinfo['username'], $this->vbulletin->userinfo['email'], $num, $pass);
}
if ($usergroup or $usergroup !== '' or $usergroup !== '0')
{
if ($usergroup != $this->vbulletin->userinfo['usergroupid'])
{
$ma_info['oldgroup'] = $this->vbulletin->userinfo['usergroupid'];
$userdm->set('usergroupid', $usergroup);
}
}
if ($ma_info)
{
$ma_info = serialize($ma_info);
$userdm->set($finfo, $ma_info);
}
$userdm->pre_save();
if (count($userdm->errors) == 0)
{
$userdm->save();
return true;
}
else
{
var_dump($userdm->errors);
return false;
}
}
function checkProductPermissions($product)
{
$perm = unserialize($product['permissions']);
return in_array($this->vbulletin->userinfo['usergroupid'], $perm);
}
function buildInfoValues()
{
$values = array();
if (is_array($this->vbulletin->userinfo['ma_info']))
{
foreach ($this->vbulletin->userinfo['ma_info'] as $key => $value)
{
if (!$this->vbulletin->GPC["$key"])
{
$values["$key"] = $value;
}
}
}
return $values;
}
function canViewMemArea($permissions)
{
if (!($permissions['memarea_permissions'] & $this->vbulletin->bf_ugp['memarea_permissions']['memarea_active']))
{
print_no_permission();
}
}
function buildInfoArray()
{
return array('fullname' => $this->vbulletin->GPC['fullname'], 'address_1' => $this->
vbulletin->GPC['address_1'], 'address_2' => $this->vbulletin->GPC['address_2'],
'address_city' => $this->vbulletin->GPC['address_city'], 'address_state' => $this->
vbulletin->GPC['address_state'], 'address_zip' => $this->vbulletin->GPC['address_zip'],
'country' => $this->vbulletin->GPC['country'], 'phone' => $this->vbulletin->GPC['phone'],
'company' => $this->vbulletin->GPC['company']);
}
function insertPurchaseInfo($ids, $information, $userid = 'usevb')
{
if ($userid == 'usevb')
{
$userid = $this->vbulletin->userinfo['userid'];
}
$this->vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX .
"ma_purchases (`userid`, `dateline`, `order`, `info`) VALUES (
'" . $userid . "',
'" . TIMENOW . "',
'" . $this->vbulletin->db->escape_string(serialize($ids)) . "',
'" . $this->vbulletin->db->escape_string(serialize($information)) . "'
)");
return $this->vbulletin->db->insert_id();
}
function buildCartRow($page, $action, $title, $price, $id = 0, $multi = false)
{
$currency_sym = $this->currency_sym;
$product = array('title' => $title, 'price' => $price);
if ($page == 'billing')
{
$delname = 'del_item[' . $id . ']';
eval('$return = "' . fetch_template('memarea_billingdetailsbit') . '";');
}
else
{
$_REQUEST['do'] = 'paymentdetails';
eval('$return = "' . fetch_template('memarea_billingdetailsbit') . '";');
$_REQUEST['do'] = $action;
}
return $return;
}
function sendOutNewSaleEmail()
{
if (!empty($this->vbulletin->options['memarea_email_new_sale']))
{
foreach (explode(",", $this->vbulletin->options['memarea_email_new_sale']) as $userid)
{
$userinfo = fetch_userinfo($userid);
vbmail($userinfo['email'], construct_phrase($this->vbphrase['memarea_new_sale'],
$this->vbulletin->options['bbtitle']), construct_phrase($this->vbphrase['memarea_new_sale_body'],
$userinfo['username'], $this->vbulletin->options['bbtitle']));
unset($userinfo);
}
}
}
function checkDetailsFields($requested, $errormessage)
{
if (empty($this->vbulletin->GPC['fullname']) or empty($this->vbulletin->GPC['address_1']) or
empty($this->vbulletin->GPC['address_city']) or empty($this->vbulletin->GPC['address_zip']) or
empty($this->vbulletin->GPC['country']) or empty($this->vbulletin->GPC['phone']))
{
//$GLOBALS['error'] = $errormessage;
eval(standard_error($errormessage));
//$this->handleRequest($requested);
return false;
}
return true;
}
function handleRequest($do)
{
$method = 'handleRequest' . $do;
if (method_exists($this, $method))
{
$this->{$method}();
}
foreach ($this->addons as $addon)
{
if (method_exists($this->{$addon}, $method))
{
$this->{$addon}->{$method}();
}
}
}
function handleRequestgivelicense()
{
$vbphrase = $this->vbphrase;
$GLOBALS['id'] = $this->vbulletin->input->clean_gpc('r', 'id', TYPE_UINT);
$GLOBALS['license'] = $this->getLicense($GLOBALS['id'], true, false, '', true, false);
$GLOBALS['templatename'] = 'memarea_givelicense';
}
function handleRequestdogivelicense()
{
$vbphrase = $this->vbphrase;
$id = $this->vbulletin->input->clean_gpc('r', 'licenseid', TYPE_UINT);
$username = $this->vbulletin->input->clean_gpc('r', 'usernames', TYPE_STR);
$userinfo = $this->vbulletin->db->query_first("SELECT userid FROM " .
TABLE_PREFIX . "user WHERE username = '" . $username . "'");
if (empty($userinfo))
{
$GLOBALS['message'] = $vbphrase['memarea_givelicense_not_found'];
$this->handleRequestgivelicense();
}
else
{ //User exists
$license = $this->getLicense($id, true, false, '', true, false);
$licensedm = datamanager_init('License', $this->vbulletin, ERRTYPE_ARRAY);
$licensedm->set_existing($license);
$licensedm->setr('userid', $userinfo['userid']);
$licensedm->save();
eval(standard_error($vbphrase['memarea_gave_license']));
}
}
function handleRequestmembersarea()
{
$vbphrase = $this->vbphrase;
$licensesq = $this->vbulletin->db->query_read("SELECT licenses.*, licenses.title as sitetitle, products.title as title, products.licenseleng as expire FROM " .
TABLE_PREFIX . "ma_licenses as licenses
LEFT JOIN " . TABLE_PREFIX .
"ma_products as products ON (products.id = licenses.productid)
WHERE licenses.userid = '" . $this->vbulletin->userinfo['userid'] . "'");
$licenses = '';
while ($license = $this->vbulletin->db->fetch_array($licensesq))
{
if (empty($license['sitetitle']))
{
$license['sitetitle'] = substr($license['url'], 7);
}
$license['expiredate'] = $this->getLicenseExpireDate($license);
eval('$licenses .= "' . fetch_template('memarea_clientsbit') . '";');
}
if ($this->addons['helpdesk'])
{
$GLOBALS['tickets'] = $this->helpdesk->getTicketsBitMem();
}
$GLOBALS['licenses'] = $licenses;
$GLOBALS['templatename'] = 'memarea_clients';
}
function handleRequestlogout()
{
$this->vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX .
"ma_session WHERE userid = '" . $this->vbulletin->userinfo['userid'] . "'");
eval(standard_error($this->vbphrase['memarea_loggedout']));
}
function handleRequestlogin()
{
$this->vbulletin->input->clean_array_gpc('p', array('customernumber' => TYPE_STR,
'password' => TYPE_STR));
if ($this->checkCustomerInfo($this->vbulletin->GPC['customernumber'], $this->
vbulletin->GPC['password']))
{
$this->startSession($this->vbulletin->userinfo['userid']);
$this->handleRequest('membersarea');
$GLOBALS['bypass'] = true;
}
else
{
$this->handleRequest('membersarea');
$GLOBALS['errormessage'] = $this->vbphrase['memarea_bad_login'];
}
}
function handleRequestresend_details()
{
$num = $this->vbulletin->userinfo['custnum'];
$pass = $this->vbulletin->userinfo['ma_password'];
$this->sendCustomerInfo($this->vbulletin->userinfo['userid'], $this->vbulletin->
userinfo['username'], $this->vbulletin->userinfo['email'], $num, $pass);
eval(standard_error($this->vbphrase['memarea_details_sent']));
}
function handleRequestlicence()
{
$GLOBALS['templatename'] = 'memarea_licence';
}
function handleRequestdetails()
{
$GLOBALS['values'] = $this->buildInfoValues();
$GLOBALS['templatename'] = 'memarea_details';
}
function handleRequestsave_details()
{
$this->vbulletin->input->clean_array_gpc('p', array('fullname' => TYPE_STR,
'address_1' => TYPE_STR, 'address_2' => TYPE_STR, 'address_city' => TYPE_STR,
'address_state' => TYPE_STR, 'address_zip' => TYPE_STR, 'country' => TYPE_STR,
'phone' => TYPE_STR, 'company' => TYPE_STR));
if ($this->checkDetailsFields('details', $this->vbphrase['memarea_required_fields']))
{
$information = $this->buildInfoArray();
$this->vbulletin->userinfo['ma_info'] = $information;
$this->vbulletin->userinfo['usergroupid'] = $usergrpid;
if ($this->setCustomerNumber($information, $usergrpid))
{
$this->vbulletin->url = 'members.php?do=details';
eval(print_standard_redirect($this->vbphrase['memarea_saved_details'], false, true));
}
}
}
function handleRequestproducts()
{
global $stylevar;
$vbphrase = $this->vbphrase;
$products = $this->vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX .
"ma_products");
$pros = '';
$haspro = ($this->addons['pro'] == 'pro');
$currency_sym = $this->currency_sym;
while ($product = $this->vbulletin->db->fetch_array($products))
{
if ($this->checkProductPermissions($product))
{
$file = DIR . '/images/productthumbs/' . basename('thumbnail_product_' . $product['id'] .
$product['thumbnail_ext']);
$show['prodthumb'] = false;
if (file_exists($file))
{
$filename = 'images/productthumbs/' . basename('thumbnail_product_' . $product['id'] .
$product['thumbnail_ext']);
$show['prodthumb'] = true;
}
$product['description'] = fetch_trimmed_title($product['description'], $this->
vbulletin->options['memarea_description_length']);
eval('$pros .= "' . fetch_template('memarea_productsbit') . '";');
}
}
$GLOBALS['pros'] = $pros;
$GLOBALS['templatename'] = 'memarea_products';
}
}
I am asking for help in anything you see that would need to be updated, why it would need to be updated, why does this need to be changed to that. Any resources I can use in updating the older products that I need to update, and just any other tips in this matter. Thank you for your time.