MyBB Community Forums

Full Version: Make Who's Online List Global
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm currently running version 1.8.4 and I'm trying to get the "{$whosonline}" snippet to work in the header. 

What do I need to move to global.php in order to get this working?
This: https://github.com/mybb/mybb/blob/featur...hp#L40-168 + possibly lang string(s) connected with it from index.lang.php
That doesn't appear to be working. :/

In my header template, I've added: 
<div id="sidebar">
{$whosonline}
</div>


In my global.php file, I've added: 

// Load global language phrases
require_once MYBB_ROOT.'inc/functions_forumlist.php';
$lang->load('index');

// Who's Online
$whosonline = '';
if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
{
	// Get the online users.
	if($mybb->settings['wolorder'] == 'username')
	{
		$order_by = 'u.username ASC';
		$order_by2 = 's.time DESC';
	}
	else
	{
		$order_by = 's.time DESC';
		$order_by2 = 'u.username ASC';
	}

	$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."'
		ORDER BY {$order_by}, {$order_by2}
	");

	$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($user['username'], $user['usergroup'], $user['displaygroup']);
					$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
					eval('$onlinemembers .= "'.$templates->get('index_whosonline_memberbit', 1, 0).'";');
					$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 .= $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 = $lang->sprintf($lang->online_note, my_number_format($onlinecount), $onlinebit, $mybb->settings['wolcutoffmins'], my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
	eval('$whosonline = "'.$templates->get('index_whosonline').'";');
}

eval('$index = "'.$templates->get('index').'";');

below this: 
// set up collapsable items (to automatically show them us expanded)
$collapsed = array('boardstats' => '', 'boardstats_e' => '', 'quickreply' => '', 'quickreply_e' => '');
$collapsedimg = $collapsed;

if($colcookie)
{
	$col = explode("|", $colcookie);
	if(!is_array($col))
	{
		$col[0] = $colcookie; // only one item
	}
	unset($collapsed);
	foreach($col as $key => $val)
	{
		$ex = $val."_e";
		$co = $val."_c";
		$collapsed[$co] = "display: show;";
		$collapsed[$ex] = "display: none;";
		$collapsedimg[$val] = "_collapsed";
		$collapsedthead[$val] = " thead_collapsed";
	}
}

and above this: 
// Run hooks for end of global.php
$plugins->run_hooks('global_end');

$globaltime = $maintimer->getTime();

What am I missing?
We found this mod and it has the who's online in a sidebox, but it's not compatible with 1.8.

http://community.mybb.com/thread-131633.html

Is there a way to do the same thing? I'm looking at the 1.6 files.
-taps chin-

I've tried cross referencing portal.php and browsing online.php. I can't figure out why changes to global.php won't take.

Any ideas?
The code works fine for me. Of course you have to add it above global templates which should contain it, otherwise there is no point in moving it to that file (especially at the bottom of it, no template there). I'd add it after https://github.com/mybb/mybb/blob/featur...l.php#L437

EDIT: and I never mentioned copying the 1st require_once line (redundant), neither the last index template line (may cause problems).
-victory dance-

You are amazing! I was just inserting the code into the wrong spot. Thank you for catching that!