Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

how to show number of onlines ?

Ads
banner
banner
banner
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#1
Member
Hello
how can I show number of online in mybb ?
just number of theme , e.g , 24

Heart
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#2
Support Team
Hi I am sorry but are you saying that you want to show somewhere in the template the current number of online users?
Looking for ways to make money fast? Read this article and start earning money todya fast, easy or for free.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#3
Member
yes, in index template
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#4
Support Team
Hi, spend quite a bit of time on this so I hope you will appreciate the effort Smile

Here is a plugin save it as: onlineuserscount.php
PHP Code:
<?php

if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("global_start""online_user_count");

function 
onlineuserscount_info()
{
    
    return array(
        
"name"            => "Online users count",
        
"description"    => "Counts and show the value of users, guests and bots currently online.",
        
"website"        => "http://letsforum.com/Thread-how-to-show-number-of-onlines",
        
"author"        => "LetsForum",
        
"authorsite"    => "http://letsforum.com",
        
"version"        => "1.0",
        
"guid"             => "",
        
"compatibility" => "*"
    
);
}


function 
online_user_count()
{
    global 
$mybb$templates$cache$user$spiders$botkey$invisiblemark$db$onlineusercount;
    
        
// Get the online users.
        
$timesearch TIME_NOW $mybb->settings['wolcutoff'];
        
$comma '';
        
$query $db->query("
            SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, u.invisible, u.usergroup, u.displaygroup
            FROM "
.TABLE_PREFIX."sessions s
            LEFT JOIN "
.TABLE_PREFIX."users u ON (s.uid=u.uid)
            WHERE s.time>'
$timesearch'
            ORDER BY u.username ASC, s.time DESC
        "
);
    
        
$forum_viewers = array();
        
$membercount 0;
        
$onlinemembers '';
        
$guestcount 0;
        
$anoncount 0;
        
$doneusers = array();
    
        
// Fetch spiders
        
$spiders $cache->read("spiders");
    
        
// Loop through all users.
        
while($user $db->fetch_array($query))
        {
            
// Create a key to test if this user is a search bot.
            
$botkey my_strtolower(str_replace("bot="''$user['sid']));
    
            
// Decide what type of user we are dealing with.
            
if($user['uid'] > 0)
            {
                
// The user is registered.
                
if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
                {
                    
// If the user is logged in anonymously, update the count for that.
                    
if($user['invisible'] == 1)
                    {
                        ++
$anoncount;
                    }
                    ++
$membercount;
                    if(
$user['invisible'] != || $mybb->usergroup['canviewwolinvis'] == || $user['uid'] == $mybb->user['uid'])
                    {
                        
// If this usergroup can see anonymously logged-in users, mark them.
                        
if($user['invisible'] == 1)
                        {
                            
$invisiblemark "*";
                        }
                        else
                        {
                            
$invisiblemark '';
                        }
    
                        
// Properly format the username and assign the template.
                        
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
                        
$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
                        eval(
"&#092;$onlinemembers .= &#092;"".$templates->get("index_whosonline_memberbit"10)."&#092;";");
                        
$comma ", ";
                    }
                    
// This user has been handled.
                    
$doneusers[$user['uid']] = $user['time'];
                }
            }
            elseif(
my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
            {
                
// The user is a search bot.
                
$onlinemembers .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
                
$comma ", ";
                ++
$botcount;
            }
            else
            {
                
// The user is a guest.
                
++$guestcount;
            }
    
            if(
$user['location1'])
            {
                
$forum_viewers[$user['location1']]++;
            }
        }
    
        
// Build the who's online bit on the index page.
        
$onlinecount $membercount $guestcount $botcount;
        
       
$test $botcount;
eval(
"&#092;$onlineusercount = &#092;"".$templates->get("count_users_online")."&#092;";");
    }
?>

To make it work you have to create a template. So go to global templates and create one.

Name: count_users_online
Content:
Code:
<div>
<div>Users Online: <span>{$onlinemembers}</span></div>
<div>Currently Online: <span>{$onlinecount}</span></div>
<div>Users: <span>{$membercount} </span></div>
<div>Guests: <span>{$guestcount} </span></div>
</div>

Now use {$onlineusercount} anywhere you like. Works in all templates.

Notice! Please customize the template code cause I had no time to do it was focusing on making it work not on making it pretty Wink
Looking for ways to make money fast? Read this article and start earning money todya fast, easy or for free.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#5
Member
Wow Heart
Thanks a lot Dear Victor
That's exactly what I wanted
Heart





User(s) browsing this thread: 1 Guest(s)