I want to create a custom logout button for my vB 5.3.3.
I'm using the following code from the core/vb/user.php file but it is not working. Can someone help me troubleshoot this code, please?
Thank you
PHP Code:
//init the vBulletin system
require_once( JPATH_SITE . '/forum/core/vb/vb.php' );
vB::init();
function processLogout() {
global $vbulletin;
$assertor = vB::getDbAssertor();
$session = vB::getCurrentSession();
$userinfo = $session->fetch_userinfo();
$timeNow = vB::getRequest()->getTimeNow();
$options = vB::getDatastore()->getValue( 'options' );
if ( $userinfo[ 'userid' ]AND $userinfo[ 'userid' ] != -1 ) {
// init user data manager
$userdata = new vB_Datamanager_User( vB_DataManager_Constants::ERRTYPE_SILENT );
$userdata->set_existing( $userinfo );
$userdata->set( 'lastactivity', $timeNow - $options[ 'cookietimeout' ] );
$userdata->set( 'lastvisit', $timeNow );
$userdata->save();
if ( !defined( 'VB_API' ) ) {
$assertor->delete( 'session', array( 'userid' => $userinfo[ 'userid' ], 'apiaccesstoken' => null ) );
$assertor->delete( 'cpsession', array( 'userid' => $userinfo[ 'userid' ] ) );
}
}
$assertor->delete( 'session', array( 'sessionhash' => $session->get( 'dbsessionhash' ) ) );
// Remove accesstoken from apiclient table so that a new one will be generated
if ( defined( 'VB_API' )AND VB_API === true AND $vbulletin->apiclient[ 'apiclientid' ] ) {
$assertor->update(
'apiclient',
array( 'apiaccesstoken' => '', 'userid' => 0 ),
array( 'apiclientid' => intval( $vbulletin->apiclient[ 'apiclientid' ] ) )
);
$vbulletin->apiclient[ 'apiaccesstoken' ] = '';
}
if ( $vbulletin->session->created == true AND( !defined( 'VB_API' )OR!VB_API ) ) {
// if we just created a session on this page, there's no reason not to use it
$newsession = $vbulletin->session;
} else {
// API should always create a new session here to generate a new accesstoken
$newsession = vB_Session::getNewSession( vB::getDbAssertor(), vB::getDatastore(), vB::getConfig(), '', 0, '', vB::getCurrentSession()->get( 'styleid' ) );
}
$newsession->set( 'userid', 0 );
$newsession->set( 'loggedin', 0 );
$vbulletin->session = & $newsession;
$result = array();
$result[ 'sessionhash' ] = $newsession->get( 'dbsessionhash' );
$result[ 'apiaccesstoken' ] = $newsession->get( 'apiaccesstoken' );
if ( defined( 'VB_API' )AND VB_API === true ) {
if ( $_REQUEST[ 'api_c' ] ) {
$assertor->update( 'apiclient',
array(
'apiaccesstoken' => $result[ 'apiaccesstoken' ],
'userid' => 0,
),
array(
'apiclientid' => intval( $_REQUEST[ 'api_c' ] )
)
);
}
}
vB::getHooks()->invoke( 'hookProcessLogout', array(
'result' => & $result,
'userinfo' => $userinfo,
) );
return $result;
}