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

Members Online Everywhere?

DRE

Well-known member
#1
How can I put members online on every page?

For example, I would like to put members online right above the footer.

Simply putting <xen:include template="sidebar_online_users" /> in a template does not work.
 
R

ragtek

Guest
#2
It doesn't work because the variable (with the online members) isn't available.
You would need an add-on to fetch & output it where ever you want.
 

DRE

Well-known member
#3
It doesn't work because the variable (with the online members) isn't available.
You would need an add-on to fetch & output it where ever you want.
Oh okay! Only addons I know that do something like that is Jaxel'x XenPorta, xFrock's Widget Framework, EasyTarget's Poor Man's Portal and Wordpress bridge addons and Mythocal's Portal addon.
 

Robbo

Well-known member
#4
Here is a listener which will give you those variables everywhere.

Code:
<?php

class OnlineUsers_Listener
{
	public static function frontControllerPreView(XenForo_FrontController $fc, XenForo_ControllerResponse_Abstract &$controllerResponse, XenForo_ViewRenderer_Abstract &$viewRenderer, array &$containerParams)
	{
		// First 2 checks are for forum sections that already has the totals so we don't get them twice
		if ($controllerResponse instanceof XenForo_ControllerResponse_View && isset($controllerResponse->params['onlineUsers']['total']))
		{
			$containerParams['totalUsers'] = $controllerResponse->params['onlineUsers']['total'];
		}
		elseif ($controllerResponse instanceof XenForo_ControllerResponse_View && isset($controllerResponse->params['onlineTotals']['total']))
		{
			$containerParams['totalUsers'] = $controllerResponse->params['onlineTotals']['total'];
		}
		else
		{
			$visitor = XenForo_Visitor::getInstance()->toArray();
			$sessionModel = XenForo_Model::create('XenForo_Model_Session');
			$onlineUsers = $sessionModel->getSessionActivityQuickList(
				$visitor,
				array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
				($visitor['user_id'] ? $visitor : null)
			);
			$containerParams['totalUsers'] = $onlineUsers['total'];
		}
	}

	public static function templatePostRender($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template)
	{
		if ($templateName == 'PAGE_CONTAINER')
		{
			$pos = strpos($content, '<div class="pageBanner"></div>');
			if ($pos === false)
				return;

			$content = substr($content, 0, $pos) . $template->create('online_users', $template->getParams()) . substr($content, $pos);
		}
	}
}
That second method there is to put it on every page in a custom way. The first method is what you need.
 

Chris D

XenForo developer
Staff member
#7
8thos - if you're interested in learning I highly recommend giving it a go.

If, like "Jessica Rabbit" you "can't be assed" then let me know, and I'll make it into an add on for you with that code kindly provided by Robbo :)
 

DRE

Well-known member
#8
8thos - if you're interested in learning I highly recommend giving it a go.

If, like "Jessica Rabbit" you "can't be assed" then let me know, and I'll make it into an add on for you with that code kindly provided by Robbo :)
Please make it an addon sir!!! It's not that I can't be assed, I'm just really busy. I failed an open-book test the other day cause I was spending too much time trying to fix my site. I have never failed an open-book test in my life...
 

DRE

Well-known member
#10
Thanks but doesn't work

Template: PAGE_CONTAINER

Search:
Code:
<xen:include template="footer" />
Replace:
Code:
<div align="center"><xen:include template="sidebar_online_users" /></div>
    <xen:include template="footer" />

 
R

ragtek

Guest
#14
the above posted addon is searching for
Code:
<div class="pageBanner"></div>
so add this to your footer and then it should work;)
 

Chris D

XenForo developer
Staff member
#18
Yeah to be fair, when this was originally written a while ago, I tried adding that and it still didn't work.