Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 1 Year, 5 Months, 4 Weeks ago Use {$onlinemembers} and {$index_stats} In Footer
#1
Solved: 1 Year, 5 Months, 4 Weeks ago
How do I use {$onlinemembers} and {$index_stats} in the footer template and I need it to work on all pages.

I need this for a custom theme maybe creating a plugin to do this but unsure how also I am fine with editing core files.
Reply
#2
Solved: 1 Year, 5 Months, 4 Weeks ago
You need to add the below code in global.php so that it will work. Add it anywhere you want Smile
$statspage = '';
if($mybb->settings['statsenabled'] != 0)
{
	eval('$statspage = "'.$templates->get('index_statspage').'";');
}
$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(htmlspecialchars_uni($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').'";');
}

// Build the forum statistics to show on the index page.
$forumstats = '';
if($mybb->settings['showindexstats'] != 0)
{
	// First, load the stats cache.
	$stats = $cache->read('stats');
	// Check who's the newest member.
	if(!$stats['lastusername'])
	{
		$newestmember = $lang->nobody;;
	}
	else
	{
		$newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']);
	}
	// Format the stats language.
	$lang->stats_posts_threads = $lang->sprintf($lang->stats_posts_threads, my_number_format($stats['numposts']), my_number_format($stats['numthreads']));
	$lang->stats_numusers = $lang->sprintf($lang->stats_numusers, my_number_format($stats['numusers']));
	$lang->stats_newestuser = $lang->sprintf($lang->stats_newestuser, $newestmember);
	// Find out what the highest users online count is.
	$mostonline = $cache->read('mostonline');
	if($onlinecount > $mostonline['numusers'])
	{
		$time = TIME_NOW;
		$mostonline['numusers'] = $onlinecount;
		$mostonline['time'] = $time;
		$cache->update('mostonline', $mostonline);
	}
	$recordcount = $mostonline['numusers'];
	$recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']);
	$recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']);
	// Then format that language string.
	$lang->stats_mostonline = $lang->sprintf($lang->stats_mostonline, my_number_format($recordcount), $recorddate, $recordtime);
	eval('$forumstats = "'.$templates->get('index_stats').'";');
}

// Show the board statistics table only if one or more index statistics are enabled.
$boardstats = '';
if(($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0) || $mybb->settings['showindexstats'] != 0 || ($mybb->settings['showbirthdays'] != 0 && $bdaycount > 0))
{
	if(!isset($stats) || isset($stats) && !is_array($stats))
	{
		// Load the stats cache.
		$stats = $cache->read('stats');
	}
	eval('$boardstats = "'.$templates->get('index_boardstats').'";');
}

This is from index.php, there might be some variable that you need to define as they might not be present in global.php.

Regards
WallBB
Reply
#3
Solved: 1 Year, 5 Months, 4 Weeks ago
Just adding the code itself does not work at all.
Reply
#4
Solved: 1 Year, 5 Months, 4 Weeks ago
^ of course, variables should be added to footer template.
however it would be better to make a plugin for your requirement.

here is a basic plugin which can fulfill some of your requirements.
its code can be taken as a base for developing required plugin
Reply
#5
Solved: 1 Year, 5 Months, 4 Weeks ago
(04-14-2018, 06:03 AM).m. Wrote: ^ of course, variables should be added to footer template.
however it would be better to make a plugin for your requirement.

here is a basic plugin which can fulfill some of your requirements.
its code can be taken as a base for developing required plugin

Ok installed but this might seem like a dumb question but how do I add it in the footer like {$numthreads} or what?
Reply
#6
Solved: 1 Year, 5 Months, 4 Weeks ago
^ if you are referring to above suggested plugin then
you can add mystats in the required templates and
that will be replaced by stats values from the plugin

please note that it is a basic plugin to give an idea ..

(edited)
Reply
#7
Solved: 1 Year, 5 Months, 4 Weeks ago
Ya that plugin also I am just testing it plus placing {$mystats} in the footer does nothing.
Reply
#8
Solved: 1 Year, 5 Months, 4 Weeks ago
^ oh! you can just add mystats (NOT {$mystats})
Reply
#9
Solved: 1 Year, 5 Months, 4 Weeks ago
(04-14-2018, 07:18 AM).m. Wrote: ^ oh! you can just add mystats (NOT {$mystats})

Thanks its working.

Wait. Ok so I have what I need set up but 1 thing I can't get to work is the online members I would want to display the usernames of those members in the footer too anyway this can be done?
Reply
#10
Solved: 1 Year, 5 Months, 4 Weeks ago
(04-14-2018, 05:39 AM)Brian. Wrote: Just adding the code itself does not work at all.
As I said in my post, you need to take care of variables in the code above. .m. also highlighted this.

(04-14-2018, 06:03 AM).m. Wrote: ^ of course, variables should be added to footer template.
however it would be better to make a plugin for your requirement.

here is a basic plugin which can fulfill some of your requirements.
its code can be taken as a base for developing required plugin



I usually prefer adding code myself Smile
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)