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

Members Online Everywhere?

Discussion in 'Styling and Customization Questions' started by DRE, May 29, 2012.

  1. DRE

    DRE Well-Known Member

    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.
     
  2. ragtek

    ragtek Guest

    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.
     
  3. DRE

    DRE Well-Known Member

    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.
     
  4. Robbo

    Robbo Well-Known Member

    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.
     
  5. DRE

    DRE Well-Known Member

    I have no idea how to use a listener. I just looked for Floris guide but he deleted his account.
     
  6. ragtek

    ragtek Guest

  7. Chris D

    Chris D XenForo Developer Staff Member

    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 :)
     
    8thos likes this.
  8. DRE

    DRE Well-Known Member

    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...
     
  9. Chris D

    Chris D XenForo Developer Staff Member

    I haven't tested this, but it is indeed an add-on using Robbo's exact code.
     

    Attached Files:

  10. DRE

    DRE Well-Known Member

    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" />

    [​IMG]
     
  11. CRDeveloper

    CRDeveloper Member

    Were you able to make it work?
     
  12. DRE

    DRE Well-Known Member

    No. If anyone is willing to make this an addon that actually works please be my guest. I'd even donate next time I get paid.
     
  13. DRE

    DRE Well-Known Member

  14. ragtek

    ragtek Guest

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

    DRE Well-Known Member

    Doesn't work.
     
  16. ragtek

    ragtek Guest

    i can't find

    <div class="pageBanner">

    in your page
     
  17. DRE

    DRE Well-Known Member

    I removed it after it didn't work.
     
  18. Chris D

    Chris D XenForo Developer Staff Member

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

Share This Page