• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to expose online members data to custom template?

Matthew Hawley

Well-known member
#1
Could someone give me a tutorial on how to expose online members and members count data to a custom template? I'm pretty sure it has something to do with viewparams...

Thanks!
 

Aayush

Well-known member
#2
There is a table called xf_session which logs the sessions of users online currently.Use that table to join with users and grabs the data about members you require.
 

Aayush

Well-known member
#3
Also check out the Xenforo Model called Session in the default xf lib. There are a few functions which may help you.
 

truonglv

Formerly Nobita.Kun
#4
Look at on XenForo_ControllerPublic_Forum at line:41
PHP:
'onlineUsers' => $this->_getSessionActivityList(),
And this function:
PHP:
protected function _getSessionActivityList()
    {
        $visitor = XenForo_Visitor::getInstance();

        /** @var $sessionModel XenForo_Model_Session */
        $sessionModel = $this->getModelFromCache('XenForo_Model_Session');

        return $sessionModel->getSessionActivityQuickList(
            $visitor->toArray(),
            array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
            ($visitor['user_id'] ? $visitor->toArray() : null)
        );

    }
I think its useful for you :)