2017-05-11, 04:05 AM
2017-05-11, 04:18 AM
can you elaborate your requirement please (may be with an image)
2017-05-11, 04:29 AM
Basically inside of the who's online it shows the total online, along with the current members and guests. I would like to create a new variable that I can use globally to display both of these statistics. I'd basically like it to output for example "9 members, and 20 guests".
2017-05-11, 05:16 AM
Open global.php and search for
add before
You can use this variable {$whosonline_global} in your templates.
// Run hooks for end of global.php
$plugins->run_hooks('global_end');
add before
// global online start
$whosonline_global = '';
if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
{
$lang->load('index');
// Get the online users.
$timesearch = TIME_NOW - (int)$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."'
");
$forum_viewers = $doneusers = array();
$membercount = $guestcount = $anoncount = $botcount = 0;
$onlinemembers = $comma = '';
// 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(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
{
// If the user is logged in anonymously, update the count for that.
if($user['invisible'] == 1)
{
++$anoncount;
}
++$membercount;
if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $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(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
$onlinemembers_global .= "{$comma}{$user['profilelink']}{$invisiblemark}";
$comma = $lang->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_global .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
$comma = $lang->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;
if($onlinecount != 1)
{
$onlinebit = $lang->online_online_plural;
}
else
{
$onlinebit = $lang->online_online_singular;
}
if($membercount != 1)
{
$memberbit = $lang->online_member_plural;
}
else
{
$memberbit = $lang->online_member_singular;
}
if($anoncount != 1)
{
$anonbit = $lang->online_anon_plural;
}
else
{
$anonbit = $lang->online_anon_singular;
}
if($guestcount != 1)
{
$guestbit = $lang->online_guest_plural;
}
else
{
$guestbit = $lang->online_guest_singular;
}
$lang->online_note = "{1} {2} and {4} {5}";
$lang->online_note = $lang->sprintf($lang->online_note, my_number_format($membercount), $memberbit, $anonbit, my_number_format($guestcount), $guestbit);
$whosonline_global = "
<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">
<tr>
<td class=\"thead\" colspan=\"2\"><strong>Who´s online?</strong></td>
</tr>
<tr>
<td class=\"trow1\"><span class=\"smalltext\">{$lang->online_note}<br />{$onlinemembers_global}</span></td>
</tr>
</table><br />";
}
// global online end
You can use this variable {$whosonline_global} in your templates.
2017-05-11, 06:07 AM
(2017-05-11, 05:16 AM)MrBrechreiz Wrote: [ -> ]Open global.php and search for
// Run hooks for end of global.php $plugins->run_hooks('global_end');
add before
// global online start $whosonline_global = ''; if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0) { $lang->load('index'); // Get the online users. $timesearch = TIME_NOW - (int)$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."' "); $forum_viewers = $doneusers = array(); $membercount = $guestcount = $anoncount = $botcount = 0; $onlinemembers = $comma = ''; // 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(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time']) { // If the user is logged in anonymously, update the count for that. if($user['invisible'] == 1) { ++$anoncount; } ++$membercount; if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $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(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']); $user['profilelink'] = build_profile_link($user['username'], $user['uid']); $onlinemembers_global .= "{$comma}{$user['profilelink']}{$invisiblemark}"; $comma = $lang->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_global .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']); $comma = $lang->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; if($onlinecount != 1) { $onlinebit = $lang->online_online_plural; } else { $onlinebit = $lang->online_online_singular; } if($membercount != 1) { $memberbit = $lang->online_member_plural; } else { $memberbit = $lang->online_member_singular; } if($anoncount != 1) { $anonbit = $lang->online_anon_plural; } else { $anonbit = $lang->online_anon_singular; } if($guestcount != 1) { $guestbit = $lang->online_guest_plural; } else { $guestbit = $lang->online_guest_singular; } $lang->online_note = "{1} {2} and {4} {5}"; $lang->online_note = $lang->sprintf($lang->online_note, my_number_format($membercount), $memberbit, $anonbit, my_number_format($guestcount), $guestbit); $whosonline_global = " <table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\"> <tr> <td class=\"thead\" colspan=\"2\"><strong>Who´s online?</strong></td> </tr> <tr> <td class=\"trow1\"><span class=\"smalltext\">{$lang->online_note}<br />{$onlinemembers_global}</span></td> </tr> </table><br />"; } // global online end
You can use this variable {$whosonline_global} in your templates.
Thanks, however that's not what I'm looking for. I've already pulled that online variable block, I'm looking for what I specified in OP.
2017-05-11, 06:12 AM
Change this
to
$whosonline_global = "
<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">
<tr>
<td class=\"thead\" colspan=\"2\"><strong>Who´s online?</strong></td>
</tr>
<tr>
<td class=\"trow1\"><span class=\"smalltext\">{$lang->online_note}<br />{$onlinemembers_global}</span></td>
</tr>
</table><br />";
to
$whosonline_global = "
<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">
<tr>
<td class=\"thead\" colspan=\"2\"><strong>Who´s online?</strong></td>
</tr>
<tr>
<td class=\"trow1\"><span class=\"smalltext\">{$lang->online_note}</span></td>
</tr>
</table><br />";