online members on a custom VB page

Discussion in 'vBulletin' started by NewMarK, Mar 18, 2011.

  1. #1
    I want to show my online users different than FORUMHOME..I've checked for vbulletin.org and modified the below templates..

    this is the php file

    <?php
    
    // ####################### SET PHP ENVIRONMENT ###########################
    error_reporting(E_ALL & ~E_NOTICE);
    
    // #################### DEFINE IMPORTANT CONSTANTS #######################
    
    define('THIS_SCRIPT', 'online');
    define('CSRF_PROTECTION', true);  
    // change this depending on your filename
    
    // ################### PRE-CACHE TEMPLATES AND DATA ######################
    // get special phrase groups
    $phrasegroups = array();
    
    // get special data templates from the datastore
    $specialtemplates = array();
    $specialtemplates = array(
        'maxloggedin',
    );  
    
    // pre-cache templates used by all actions
    $globaltemplates = array('custom_online',
    );
    $globaltemplates = array(
        'online',
        'forumhome_loggedinuser',
    ); 
    
    // pre-cache templates used by specific actions
    $actiontemplates = array();
    
    // ######################### REQUIRE BACK-END ############################
    // if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
    // chdir ('/path/to/your/forums');
    require_once('./global.php');
    require_once('./global.php');
    require_once(DIR . '/includes/functions_bigthree.php');
    
    // #######################################################################
    // ######################## START MAIN SCRIPT ############################
    // #######################################################################
    
    $navbits = construct_navbits(array('' => 'online'));
    $navbar = render_navbar_template($navbits);
    
    // ###### YOUR CUSTOM CODE GOES HERE #####
    $pagetitle = 'online';
    // ### 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;
    
        $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++;
        }
    
        $skipgroups = array(3,4);
        foreach ($userinfos AS $userid => $loggedin)
        {
            if (in_array($loggedin['usergroupid'], $skipgroups))
            {
                $numberguest++;
            }
            else
            {
                $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;
    }
    
    // ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
    
    $templater = vB_Template::create('custom_online');
    $templater->register_page_templates();
    $templater->register('navbar', $navbar);
    $templater->register('pagetitle', $pagetitle);
    print_output($templater->render());
    
    ?>
    PHP:
    this is the custom template

    {vb:stylevar htmldoctype}
    <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
      <head>
        <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
        {vb:raw headinclude}
        {vb:raw headinclude_bottom}
      </head>
      <body>
        
        {vb:raw header}
        
        {vb:raw navbar}
        
        <div id="pagetitle">
          <h1>{vb:raw pagetitle}</h1>
        </div>
        
        <h2 class="blockhead">Title</h2>
        <div class="blockbody">
          <div class="blockrow">
    
                <!-- logged-in users -->
                <div id="wgo_onlineusers" class="wgo_subblock section">
                    <h3 class="blocksubhead"><img src="{vb:stylevar imgdir_misc}/users_online.png" alt="{vb:rawphrase currently_active_users}" />{vb:rawphrase currently_active_users}</h3>
                    <div>
                        <p>{vb:rawphrase there_are_x_y_online_link, {vb:raw totalonline}, {vb:raw session.sessionurl}} <span class="shade">{vb:rawphrase x_members_and_y_guests, {vb:raw numberregistered}, {vb:raw numberguest}}</span></p>
                        <p>{vb:rawphrase most_users_ever_online_was_x_y_at_z, {vb:raw recordusers}, {vb:raw recorddate}, {vb:raw recordtime}}</p>
                        <vb:if condition="$activeusers">
                        <ol class="commalist" id="wgo_onlineusers_list">
                            {vb:raw activeusers}
                        </ol>
                        </vb:if>
                    </div>
                </div>
                <!-- end logged-in users -->
    
          </div>
        </div>
        
        {vb:raw footer}
      </body>
    </html>
    PHP:
    but the result is not satisfactory..below is the caps at the end..
     [B]http://img372.yukle.tc/images/15091.JPG[/B]
    Code (markup):
    the online members don't show on the custom page..

    help please..
     
    NewMarK, Mar 18, 2011 IP