Hello,
Once i have updated client board i see stats code which was shared in vbulletin.com doesnt work any more. When i try to use it throws me SQL Data base error
Can anyone please fix the code for vBulletin 4.2.5 , Using MariaDB, PHP 5.6
PHP Code:
//CUSTOM FOR DISPLAY OF STATS IN HEADER
require_once('./includes/functions_bigthree.php');
require_once('./includes/functions_forumlist.php');
// ### LOGGED IN USERS #################################################
$activeusers = '';
if (($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 2 OR ($vbulletin->options['displayloggedin'] > 2 AND $vbulletin->userinfo['userid'])) AND !$show['search_engine'])
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$numbervisible = 0;
$numberregistered = 0;
$numberguest = 0;
$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser_query')) ? eval($hook) : false;
//ADDED
$db = new vB_Database($vbulletin);
// make database connection
$db->connect(
$vbulletin->config['Database']['dbname'],
$vbulletin->config['MasterServer']['servername'],
$vbulletin->config['MasterServer']['port'],
$vbulletin->config['MasterServer']['username'],
$vbulletin->config['MasterServer']['password'],
$vbulletin->config['MasterServer']['usepconnect'],
$vbulletin->config['SlaveServer']['servername'],
$vbulletin->config['SlaveServer']['port'],
$vbulletin->config['SlaveServer']['username'],
$vbulletin->config['SlaveServer']['password'],
$vbulletin->config['SlaveServer']['usepconnect'],
$vbulletin->config['Mysqli']['ini_file'],
(isset($vbulletin->config['Mysqli']['charset']) ? $vbulletin->config['Mysqli']['charset'] : '')
);
// define table prefix constant
define('TABLE_PREFIX', trim($vbulletin->config['Database']['tableprefix']));
//EO ADDED
$forumusers = $db->query_read_slave("
SELECT
user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid, user.lastvisit,
session.userid, session.inforum, session.lastactivity, session.badlocation,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
$hook_query_fields
FROM " . TABLE_PREFIX . "session AS session
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)
$hook_query_joins
WHERE session.lastactivity > $datecut
$hook_query_where
" . iif($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 3, "ORDER BY username ASC") . "
");
if ($vbulletin->userinfo['userid'])
{
// fakes the user being online for an initial page view of index.php
$vbulletin->userinfo['joingroupid'] = iif($vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['usergroupid']);
$userinfos = array
(
$vbulletin->userinfo['userid'] => array
(
'userid' =>& $vbulletin->userinfo['userid'],
'username' =>& $vbulletin->userinfo['username'],
'invisible' =>& $vbulletin->userinfo['invisible'],
'inforum' => 0,
'lastactivity' => TIMENOW,
'lastvisit' =>& $vbulletin->userinfo['lastvisit'],
'usergroupid' =>& $vbulletin->userinfo['usergroupid'],
'displaygroupid' =>& $vbulletin->userinfo['displaygroupid'],
'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();
while ($loggedin = $db->fetch_array($forumusers))
{
$userid = $loggedin['userid'];
if (!$userid)
{ // Guest
$numberguest++;
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
if (!$loggedin['badlocation'])
{
$inforum["$loggedin[inforum]"]++;
}
}
else if (empty($userinfos["$userid"]) OR ($userinfos["$userid"]['lastactivity'] < $loggedin['lastactivity']))
{
$userinfos["$userid"] = $loggedin;
}
}
if (!$vbulletin->userinfo['userid'] AND $numberguest == 0)
{
$numberguest++;
}
foreach ($userinfos AS $userid => $loggedin)
{
$numberregistered++;
if ($userid != $vbulletin->userinfo['userid'] AND !$loggedin['badlocation'])
{
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
$inforum["$loggedin[inforum]"]++;
}
fetch_musername($loggedin);
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser')) ? eval($hook) : false;
if (fetch_online_status($loggedin))
{
$numbervisible++;
$show['comma_leader'] = ($activeusers != '');
$templater = vB_Template::create('forumhome_loggedinuser');
$templater->register('loggedin', $loggedin);
$activeusers .= $templater->render();
}
}
// memory saving
unset($userinfos, $loggedin);
$db->free_result($forumusers);
$totalonline = $numberregistered + $numberguest;
$numberinvisible = $numberregistered - $numbervisible;
// ### MAX LOGGEDIN USERS ################################
if (intval($vbulletin->maxloggedin['maxonline']) <= $totalonline)
{
$vbulletin->maxloggedin['maxonline'] = $totalonline;
$vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
}
$recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
$recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], true);
$recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);
$show['loggedinusers'] = true;
}
else
{
$show['loggedinusers'] = false;
}
// ### GET FORUMS & MODERATOR iCACHES ########################
cache_ordered_forums(1, 1);
if ($vbulletin->options['showmoderatorcolumn'])
{
cache_moderators();
}
else if ($vbulletin->userinfo['userid'])
{
cache_moderators($vbulletin->userinfo['userid']);
}
// define max depth for forums display based on $vbulletin->options[forumhomedepth]
define('MAXFORUMDEPTH', $vbulletin->options['forumhomedepth']);
$forumbits = construct_forum_bit($forumid);
$forumhome_markread_script = vB_Template::create('forumhome_markread_script')->render();
// ### BOARD STATISTICS #################################################
// get total threads & posts from the forumcache
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
//print_r($vbulletin->forumcache);
//exit();
foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);
//ADDED
// check if userstats array is populated, else build it (on non-forum pages, e.g. member.php, usercp.php, etc., these stats aren't necessarily available, so need to build them)
if(!count($vbulletin->userstats)){
require_once('./includes/functions_databuild.php');
$vbulletin->userstats = build_user_statistics();
//exit(print_r($vbulletin->userstats));
}
//EO ADDED
// get total members and newest member from template
$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);
$newuserinfo = array(
'userid' => $vbulletin->userstats['newuserid'],
'username' => $vbulletin->userstats['newusername']
);
$activemembers = vb_number_format($vbulletin->userstats['activemembers']);
$show['activemembers'] = ($vbulletin->options['activememberdays'] > 0 AND ($vbulletin->options['activememberoptions'] & 2)) ? true : false;
//EO CUSTOM FOR DISPLAY OF STATS IN HEADER
$templater = vB_Template::create('header');
$templater->register('ad_location', $ad_location);
$templater->register('pmbox', $pmbox);
$templater->register('notifications_menubits', $notifications_menubits);
$templater->register('notifications_total', $notifications_total);
$templater->register('notices', $notices);
//CUSTOM FOR DISPLAY OF STATS IN HEADER
$templater->register('numberguest', $numberguest);
$templater->register('numbermembers', $numbermembers);
$templater->register('numberregistered', $numberregistered);
$templater->register('totalonline', $totalonline);
$templater->register('activemembers', $activemembers);
$templater->register('activeusers', $activeusers);
$templater->register('totalposts', $totalposts);
$templater->register('totalthreads', $totalthreads);
//EO CUSTOM FOR DISPLAY OF STATS IN HEADER
$header = $templater->render();
Thank in advance.
--------------- Added [DATE]1552303048[/DATE] at [TIME]1552303048[/TIME] ---------------
All i need is
{vb:raw totalonline}
and
{vb:raw numbermembers}
to be used in header bar.
Looking forward
Really thanks.