vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   vBulletin Forum Sideblocks - Who's Online Sidebar Block (https://vborg.vbsupport.ru/showthread.php?t=266778)

grey_goose 07-13-2011 10:00 PM

Who's Online Sidebar Block
 
1 Attachment(s)
This is tested and working with Everywhere Sidebar 4 VB4

Step One: Create a Template
ACP > Style Manager > Add New Template
Title: block_online
Code:

<div class="blocksubhead">{vb:rawphrase x_members_and_y_guests, {vb:raw numberregistered}, {vb:raw numberguest}}</div>
<div class="blockrow">
  <vb:if condition="$activeusers">
    <vb:each from="activeusers" value="loggedin">
      <a class="username" href="{vb:link member, {vb:raw loggedin}}">{vb:raw loggedin.musername}</a>{vb:raw loggedin.invisiblemark}{vb:raw loggedin.buddymark},
    </vb:each>
  <vb:else />
    {vb:rawphrase no_x_online, {vb:rawphrase members}}
  </vb:if>
</div>
<div class="blockrow">{vb:rawphrase most_users_ever_online_was_x_y_at_z, {vb:raw recordusers}, {vb:raw recorddate}, {vb:raw recordtime}}</div>

Step Two: Create the Block
ACP > Forums & Moderators > Forum Blocks Manager > Add Block
Select Block Type: Custom HTML/PHP
Title: Online Users
Cache Time (in minutes): 5
Active: Yes
Content Type: PHP
Code:

global $vbulletin;
global $db;

// space separated list of group ids to filter out
$filter_groupids = "";

// members logged into forums
$loggedinusers = array();
$activeusers = array();
$invisiblecount = 0;

// Logged in user
if ($vbulletin->userinfo['userid'])
  {
    $loggedinusers[$vbulletin->userinfo['userid']] = array(
      'userid' => $vbulletin->userinfo['userid'],
      'username' => $vbulletin->userinfo['username'],
      'invisiblemark' => ($vbulletin->userinfo['invisible']) ? '*' : '',
      'displaygroupid' => $vbulletin->userinfo['displaygroupid'],
      'musername' => fetch_musername($vbulletin->userinfo)
    );
  }

$getonline = $db->query_read("
                        SELECT session.userid, username, usergroupid, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, membergroupids
                        FROM " . TABLE_PREFIX . "session AS session
                        LEFT JOIN " . TABLE_PREFIX . "user AS user USING (userid)
                        WHERE session.lastactivity > " . (TIMENOW - $vbulletin->options['cookietimeout']) . "
                        ORDER BY username ASC
                ");

$filter_groupids = explode(" ", $filter_groupids);
while ($onlineusers = $db->fetch_array($getonline))
  {
    if (!$onlineusers['userid'])
      {
        $numberguest++;
      }
    else
      {
        if ($onlineusers['invisible'])
          {
            if (($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehidden']) OR $onlineusers['userid'] == $vbulletin->userinfo['userid'])
              {
                $onlineusers['invisiblemark'] = '*';
              }
            else
              {
                $invisiblecount++;
                continue;
              }
          }

        $groupids = array();
        array_push($groupids, $onlineusers['usergroupid'], $onlineusers['displaygroupid']);
        $groupids = array_merge
          (
          $groupids,
          explode(" ", $onlineusers['membergroupids'])
          );
        foreach($groupids as $value)
          if(in_array($value, $filter_groupids))
            continue;
        $loggedinusers[$onlineusers['userid']] = $onlineusers;
      }
  }

$db->free_result($getonline);
unset($onlineusers);

// ##### Process Online Users Module
$numberregistered = sizeof($loggedinusers);
$show['comma_leader'] = false;
$show['divrow'] = false;

if (!empty($loggedinusers))
  {
    foreach ($loggedinusers AS $loggedinuserid => $loggedin)
      {
        $loggedin['musername'] = fetch_musername($loggedin);

        ($hook = vBulletinHook::fetch_hook('vba_cmps_module_onlineuserbits')) ? eval($hook) : false;

        $activeusers[$loggedinuserid] = $loggedin;
      }
  }

// Process the total first, before number_format is applied
$totalonline = $numberregistered + $numberguest + $invisiblecount;

if ($vbulletin->maxloggedin['maxonline'] <= $totalonline)
  {
    $vbulletin->maxloggedin['maxonline'] = $totalonline;
    $vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
    build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
  }

$totalonline = vb_number_format($totalonline);
$numberregistered = vb_number_format($numberregistered + $invisiblecount);
$numberguest = vb_number_format($numberguest);

$recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
$recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], 1);
$recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);

// print everything
$templater = vB_Template::create('block_online');
$templater->register('activeusers', $activeusers);
$templater->register('altbgclass', $altbgclass);
$templater->register('bgclass', $bgclass);
$templater->register('numberguest', $numberguest);
$templater->register('numberregistered', $numberregistered);
$templater->register('recorddate', $recorddate);
$templater->register('recordtime', $recordtime);
$templater->register('recordusers', $recordusers);
$content = $templater->render();
unset($loggedinusers, $activeusers);
return $content;

Line 5 of the block can be edited to exclude usergroups from displaying at:
$filter_groupids = "(insert numbers here)";

Enjoy.

CaneInsider 07-14-2011 01:02 AM

Installed. Anyway to turn off showing who is online? I have over 750 members logged in so it makes my sidebar go down a long way....

Khriz 07-14-2011 02:43 AM

<a href="https://vborg.vbsupport.ru/showthread.php?t=233965" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=233965</a> ?

grey_goose 07-14-2011 10:47 AM

CI: Time permitting, I'll give it a go

Khriz: We never could get that to work with ESB, this one does *shrug*

Khriz 07-14-2011 02:03 PM

I will test it :)
I will try to block lateral statistics
I want to have a sidebar similar to xenforo ^ ^

grey_goose 07-14-2011 03:38 PM

Prove what? There's a screenshot and installs, it works.

Done trolling now ?

voglermc 07-14-2011 04:13 PM

A cms block would be cool too! Thanks and nominated/rated!

grey_goose 07-14-2011 08:29 PM

Thanks voglermc!

Unfortunately a cms block won't be forthcoming from me... we just have the forums (not the suite) and use mediawiki for our content management.

Macgiber 07-14-2011 08:40 PM

Installed

grey_goose 07-16-2011 02:56 PM

Quote:

Originally Posted by CaneInsider (Post 2220272)
Installed. Anyway to turn off showing who is online? I have over 750 members logged in so it makes my sidebar go down a long way....

Here you go.

Replace your block content entirely with this, then add your usergroup numbers to:

// space separated list of group ids to filter out
$filter_groupids = "";


Code:

global $vbulletin;
global $db;

// space separated list of group ids to filter out
$filter_groupids = "";

// members logged into forums
$loggedinusers = array();
$activeusers = array();
$invisiblecount = 0;

// Logged in user
if ($vbulletin->userinfo['userid'])
  {
    $loggedinusers[$vbulletin->userinfo['userid']] = array(
      'userid' => $vbulletin->userinfo['userid'],
      'username' => $vbulletin->userinfo['username'],
      'invisiblemark' => ($vbulletin->userinfo['invisible']) ? '*' : '',
      'displaygroupid' => $vbulletin->userinfo['displaygroupid'],
      'musername' => fetch_musername($vbulletin->userinfo)
    );
  }

$getonline = $db->query_read("
                        SELECT session.userid, username, usergroupid, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, membergroupids
                        FROM " . TABLE_PREFIX . "session AS session
                        LEFT JOIN " . TABLE_PREFIX . "user AS user USING (userid)
                        WHERE session.lastactivity > " . (TIMENOW - $vbulletin->options['cookietimeout']) . "
                        ORDER BY username ASC
                ");

$filter_groupids = explode(" ", $filter_groupids);
while ($onlineusers = $db->fetch_array($getonline))
  {
    if (!$onlineusers['userid'])
      {
        $numberguest++;
      }
    else
      {
        if ($onlineusers['invisible'])
          {
            if (($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehidden']) OR $onlineusers['userid'] == $vbulletin->userinfo['userid'])
              {
                $onlineusers['invisiblemark'] = '*';
              }
            else
              {
                $invisiblecount++;
                continue;
              }
          }

        $groupids = array();
        array_push($groupids, $onlineusers['usergroupid'], $onlineusers['displaygroupid']);
        $groupids = array_merge
          (
          $groupids,
          explode(" ", $onlineusers['membergroupids'])
          );
        foreach($groupids as $value)
          if(in_array($value, $filter_groupids))
            continue;
        $loggedinusers[$onlineusers['userid']] = $onlineusers;
      }
  }

$db->free_result($getonline);
unset($onlineusers);

// ##### Process Online Users Module
$numberregistered = sizeof($loggedinusers);
$show['comma_leader'] = false;
$show['divrow'] = false;

if (!empty($loggedinusers))
  {
    foreach ($loggedinusers AS $loggedinuserid => $loggedin)
      {
        $loggedin['musername'] = fetch_musername($loggedin);

        ($hook = vBulletinHook::fetch_hook('vba_cmps_module_onlineuserbits')) ? eval($hook) : false;

        $activeusers[$loggedinuserid] = $loggedin;
      }
  }

// Process the total first, before number_format is applied
$totalonline = $numberregistered + $numberguest + $invisiblecount;

if ($vbulletin->maxloggedin['maxonline'] <= $totalonline)
  {
    $vbulletin->maxloggedin['maxonline'] = $totalonline;
    $vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
    build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
  }

$totalonline = vb_number_format($totalonline);
$numberregistered = vb_number_format($numberregistered + $invisiblecount);
$numberguest = vb_number_format($numberguest);

$recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
$recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], 1);
$recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);

// print everything
$templater = vB_Template::create('block_online');
$templater->register('activeusers', $activeusers);
$templater->register('altbgclass', $altbgclass);
$templater->register('bgclass', $bgclass);
$templater->register('numberguest', $numberguest);
$templater->register('numberregistered', $numberregistered);
$templater->register('recorddate', $recorddate);
$templater->register('recordtime', $recordtime);
$templater->register('recordusers', $recordusers);
$content = $templater->render();
unset($loggedinusers, $activeusers);
return $content;


apn3a 07-23-2011 09:22 PM

Hey :)

Can we have something like that for the Today birthday users?

Thank you

ErnieTheMilk 07-24-2011 07:00 AM

Are there any permissions issues related to this, when I try this I get a message telling me I don't have Permission to access the document...

Steve_GB 09-07-2011 06:28 PM

Neat.

Some feedback:

The buddymark doesn't actually display when I try this. Should be a + next to friends etc but none seen when I run this. I can see it is meant to be there from the code etc.

After each name is a comma but in VB those seem to often be at the end of runs of things when viewed with ie8 and that is what I see with this too, a comma between members fine, like john, fred.. but also one after fred, which looks wrong of course.

One workaround for that is simply to delete the comma from the template, then you just get a space between member names and no commas at all, which looks a little better perhaps. Your example graphic actually shows the unwanted comma at the end of the list of members so you are seeing this too.

Hope the feedback is helpful and thanks for sharing this here.

Steve

Malcolm-X 12-03-2011 11:51 PM

in my sidebar it just says "Most users ever online was , at ." but nothing alse is shown... please help.. I use ESB 1.4.4.4 and vb4.1.7

thanks

dsantana 05-24-2012 10:57 PM

I added this as a widget as well for my CMS page...
Just used the php code in a PHP Direct Execution setup...

Thanks a bunch!!!

Dave-ahfb 06-08-2012 12:33 AM

Installed on 4.2

Most ever online now only shows the actual users online, The most ever stat was even wiped out on the default VB WOL block

3saltoot 11-05-2015 07:36 AM

nice ,, thank you ..

Hellendor 02-27-2017 06:24 PM

Hello friends, I have version vB 4.2.3 and I do not know how to create the first part of the block :confused: which is to create the template. You can help me step by step, please. Thank you very much.

IggyP 01-22-2018 12:53 PM

wondering the way to take an idea like this and just move the whole WGO block to sidebar...

oldfan 04-07-2023 11:50 PM

works on 4.2.5.php 7.2


All times are GMT. The time now is 09:44 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01363 seconds
  • Memory Usage 1,815KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (20)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete