Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-11-2019, 10:10 AM
ramesh_umk3 ramesh_umk3 is offline
 
Join Date: Jul 2010
Location: Earth
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Stats Display Code Doesnt Work on 4.2.5

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'] == OR $vbulletin->options['displayloggedin'] == OR ($vbulletin->options['displayloggedin'] > 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'] == 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(11);
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'] > 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.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:57 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07213 seconds
  • Memory Usage 2,568KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete