MyBB Community Forums

Full Version: $mybb->user['buddylist'] variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hello,

Trying to show the list of buddy's on a non MyBB page. Managed to work out the variable but instead of displaying the username, it display's their uid number.

How can I change this?

$mybb->user['buddylist'] is currently what I'm using.
If it shows the uid's then you probably need to run a query:
$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');
$query = $db->simple_select('users', '*', "uid IN ({$uids})");
while($buddy = $db->fetch_array($query))
{
	$buddy['username'] = htmlspecialchars_uni($buddy['username']);
	echo $buddy['username']."is my buddy!\n";
}
It says there is an error in the syntax on line 1.
I can't see any typo in line #1 of the code in my last post. Anyways, try the new one (no related to your post but I forget something there).
Quote:ERROR: Unknown Punctuation String @ 15
STR: ->
SQL: $uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');$uids = ($mybb->user['buddylist'] ? $mybb->user['buddylist'] : '0');
Try this:
if($mybb->user['buddylist'])
{
	$query = $db->simple_select('users', '*', "uid IN ({$mybb->user['buddylist']})");
	while($buddy = $db->fetch_array($query))
	{
		$buddy['username'] = htmlspecialchars_uni($buddy['username']);
		echo $buddy['username']."is my buddy!\n";
	}
}
else
{
	echo "I have no buddies.\n";
}
Doesn't seem to work either. Undecided
That's PHP code, not SQL... You'll need to write a plugin or add a core modification with the above code.
I love it, thanks!

Just one more thing, how would I go about displaying the online users in BOLD and also a link to their profile as right now, only shows usernames without a link.
You need to join the sessions table:
	$timesearch = TIME_NOW-intval($mybb->settings['wolcutoffmins'])*60;
	$query = $db->simple_select('users u LEFT JOIN '.TABLE_PREFIX.'sessions s ON (s.uid=u.uid AND s.time>'{$timesearch})', "u.uid, u.username, s.sid", "u.uid IN ({$uids})");
	while($buddy = $db->fetch_array($query))
	{
		$buddy['username'] = htmlspecialchars_uni($buddy['username']);

		if($buddy['sid'])
		{
			echo "<b>{$buddy['username']}</b> is my buddy!\n"; // Buddy is online
		}
		else
		{
			echo "{$buddy['username']} is my buddy!\n";
		}
	}

Unsure if that (example) code will actually work.

Also consider that the user may had set their options to be hidden from the online list, as well as if current user can view hidden users. You could have a better chance reviewing how the online.php file works.
Pages: 1 2 3