MyBB Community Forums

Full Version: Users Browsing Custom Pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In creating custom pages, I wanted to keep the {$usersbrowsing}

So, I simply copied the code from showthread.php (lines 1441-1520) and inserted it into the custom PHP page. While it mostly works, it seems to not be contacting the languages files correctly; the custom pages are outside the /forum/ directory where MyBB is installed, but I tried the same configuration in the /forum/ directory with no resolve. 

https://www.dota2reborn.net/scripts/Rand...or-PHP.php

This is the only custom page I put the code on, so I could test the code and correct bugs (like this) prior to adding the code to my other pages. 

{$lang->users_browsing_thread}

In the template for showthread_usersbrowsing, there is this language bit that is used to say "Users browsing this thread". I'm also having trouble showing what the user is doing. If you hover over the name of a user, it should say what they're doing on the page and at what time. The only thing I get is the time. Also, it adds an extra comma to the end of users shown on the page for some reason.
In regards to what the user is doing, this may help you: https://github.com/dragonexpert/tutorial....html#L167
I think he rather wants to display users viewing that page there. The request isn't quite clear. Which code are you using currently?
I had the file and line numbers in the original post, but here they are.

if($mybb->settings['browsingthisthread'] != 0) {
	$timecut = TIME_NOW - $mybb->settings['wolcutoff'];

	$comma = '';
	$guestcount = 0;
	$membercount = 0;
	$inviscount = 0;
	$onlinemembers = '';
	$doneusers = array();

	$query = $db->query("
		SELECT s.ip, s.uid, s.time, 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 > '$timecut' AND location2='$tid' AND nopermission != 1
		ORDER BY u.username ASC, s.time DESC
	");

	while($user = $db->fetch_array($query))
	{
		if($user['uid'] == 0)
		{
			++$guestcount;
		}
		else if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
		{
			++$membercount;
			$doneusers[$user['uid']] = $user['time'];

			$invisiblemark = '';
			if($user['invisible'] == 1)
			{
				$invisiblemark = "*";
				++$inviscount;
			}

			if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
			{
				$user['profilelink'] = get_profile_link($user['uid']);
				$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
				$user['reading'] = my_date($mybb->settings['timeformat'], $user['time']);

				eval("\$onlinemembers .= \"".$templates->get("showthread_usersbrowsing_user", 1, 0)."\";");
				$comma = $lang->comma;
			}
		}
	}

	$guestsonline = '';
	if($guestcount)
	{
		$guestsonline = $lang->sprintf($lang->users_browsing_thread_guests, $guestcount);
	}

	$invisonline = '';
	if($mybb->user['invisible'] == 1)
	{
		// the user was counted as invisible user --> correct the inviscount
		$inviscount -= 1;
	}
	if($inviscount && $mybb->usergroup['canviewwolinvis'] != 1)
	{
		$invisonline = $lang->sprintf($lang->users_browsing_forum_invis, $inviscount);
	}

	$onlinesep = '';
	if($invisonline != '' && $onlinemembers)
	{
		$onlinesep = $lang->comma;
	}
	
	$onlinesep2 = '';
	if($invisonline != '' && $guestcount || $onlinemembers && $guestcount)
	{
		$onlinesep2 = $lang->comma;
	}

	eval("\$usersbrowsing = \"".$templates->get("showthread_usersbrowsing")."\";");
	$usersbrowsing = str_replace("member.php", "https://www.dota2reborn.net/forum/member.php", $usersbrowsing);
}

$plugins->run_hooks("showthread_end");

After looking at it more carefully, I think one of the problems is that it tries to pull
location2='$tid'
in the SQL query, but because they are custom pages, they have no location2 information (in the sessions table).

dragonexpert did bring up a point to show what the users are doing, if they're visiting a custom page. However, in showing the custom page that a user is viewing, if I try to link to the scripts (which are in /scripts/ while MyBB is in /forum/), then I get an error. MyBB prefixes the forum URL to whatever URL I specify.

Here's the code added to function_online.php under the function build_friendly_wol_location($user_activity)
case "password_gen_PHP":
            $location_name = 'Viewing <a href=\"https://www.dota2reborn.net/scripts/Random-Password-Generator-JS.php\">PHP JavaScript Generator Script</a>';
            break;

The last thing is that the template is not achieving access to the language files for some reason (look in the original post for the content).
(2015-08-04, 01:21 AM)Tyler E. Wrote: [ -> ]The last thing is that the template is not achieving access to the language files for some reason (look in the original post for the content).

You don't load any lang file in the code you posted. This code loads all showthread phrases: https://github.com/mybb/mybb/blob/featur...ad.php#L31

As for the other issue, the query is just wrong because you can't copy and paste exactly the same code as for threads.. $tid is undefined, for example. You need to select users based on the location column in the sessions table: https://github.com/mybb/mybb/blob/featur...n.php#L469 Look for records which start with Random-Password-Generator-PHP.php. The tutorial dragonexpert posted is for something else and won't help you here, as I said. It's for custom page description on the who's online page.
Ah, I thought the language was already loaded which was my bad.

I fixed the query problem by checking against the URL they're on and only updating the users if they're on that URL.

I just mentioned that dragonexpert brought to my attention something that I forgot to do, which was updated the who's online list so that it'll show the custom pages instead of an unknown location. I just need to figure out why it's prefixing the URL I specify with the forum's URL.

For example, if I create an activity for a custom page and the $location_name in the functions_online.php file is:
$location_name = 'Viewing <a href=\"https://www.domain.net/scripts/Random-Winner-Generator.php\">Random Winner Generator Script</a>';

Then I get this as the link on the user's profile when they visit that page
https://www.domain.net/%22https://www.domain.net/scripts/Random-Password-Generator-PHP.php/%22
Have you tried without escaping the double quotes? They shouldn't be escaped since they are inside single quotes.
I didn't really give any thought to that, but that appeared to be the problem. Thanks for the help!