MyBB Hacks

Full Version: Check if User is mod and if he is online
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, I'm willing to check if there are any moderator online and display the username of these mods.

How can I do it? It will be displayed in portal. What code I need to use?

Thank you.
Anyone can help me please!
Skillz - is this for portal or Pro_portal?
I have ProPortal installed but I'm unable to access my FTP for some reason. So if it can be done using the <if> would be better for me. But if it can't... I would like to see the code for ProPortal.
Do you have an example of a Pro_portal custom block? I don't use pro_portal, but I have it on my test board. I don't know if the block needs a plugin file to activate it. I am interested in helping you (if I can) but as the pro_portal site is now a parked domain, I need some help from you Smile

The whos in Ajax chat block would be a start.
ORIGINAL WHOS_ONLINE block:

PHP Code:
<?php
/***************************************************************
 * ProPortal
 * Copyright © 2010 ProMyBB, All Rights Reserved
 *
 * Website: http://www.promybb.com/
 * License: http://creativecommons.org/licenses/by-nc-sa/3.0/
 ***************************************************************/
 
if (!defined("IN_PORTAL")) {
	die("<div style=\"border:1px solid #CC0000; padding:3px; margin:0; font-family:Tahoma; width:250px; font-size:12px;\"><strong>Error:</strong> This file cannot be viewed directly!</div>");
}

$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
$comma = '';
$guestcount = 0;
$membercount = 0;
$onlinemembers = '';
$query = $db->query("
	SELECT s.sid, s.ip, s.uid, s.time, s.location, 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 u.username ASC, s.time DESC
");
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']));
	
	if($user['uid'] == "0")
	{
		++$guestcount;
	}
	elseif(my_strpos($user['sid'], "bot=") !== false && $session->bots[$botkey])
	{
		// The user is a search bot.
		$onlinemembers .= $comma.format_name($session->bots[$botkey], $session->botgroup);
		$comma = ", ";
		++$botcount;
	}
	else
	{
		if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
		{
			++$membercount;
			
			$doneusers[$user['uid']] = $user['time'];
			
			// If the user is logged in anonymously, update the count for that.
			if($user['invisible'] == 1)
			{
				++$anoncount;
			}
			
			if($user['invisible'] == 1)
			{
				$invisiblemark = "*";
			}
			else
			{
				$invisiblemark = '';
			}
			
			if(($user['invisible'] == 1 && ($mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])) || $user['invisible'] != 1)
			{
				$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
				$user['profilelink'] = get_profile_link($user['uid']);
				$onlinemembers .= "{$comma}<a href=\"{$mybb->settings['bburl']}/{$user['profilelink']}\">{$user['username']}</a>{$invisiblemark}";
				$comma = ", ";
			}
		}
	}
}

$onlinecount = $membercount + $guestcount + $botcount;

// If we can see invisible users add them to the count
if($mybb->usergroup['canviewwolinvis'] == 1)
{
	$onlinecount += $anoncount;
}

// If we can't see invisible users but the user is an invisible user incriment the count by one
if($mybb->usergroup['canviewwolinvis'] != 1 && $mybb->user['invisible'] == 1)
{
	++$onlinecount;
}

// Most users online
$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']);

if($onlinecount == 1)
{
  $lang->online_users = $lang->online_user;
}
else
{
  $lang->online_users = $lang->sprintf($lang->online_users, $onlinecount);
}
$lang->online_counts = $lang->sprintf($lang->online_counts, $membercount, $guestcount);
echo "<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
		<tr>
			<td class=\"thead\"><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/{$expcolimage}\" id=\"block_{$result_blocks['id']}_img\" class=\"expander\" alt=\"{$expaltext}\" title=\"{$expaltext}\" /></div><strong><a href=\"{$mybb->settings['bburl']}/online.php\">{$lang->online}: {$onlinecount}</a></strong></td>
		</tr>
		<tbody style=\"{$expdisplay}\" id=\"block_{$result_blocks['id']}_e\">
		<tr>
			<td class=\"tcat\"><span class=\"smalltext\">{$lang->online_counts}</span></td>
		</tr>
		<tr>
			<td class=\"trow1\">{$onlinemembers}</td>
		</tr>
		</tbody>
	</table>";
?>


MODIFIED BLOCK: (I think something is messed up.. But I can't test it because I can't access my FTP account for some reason :/. The query is wrong too it needed to b changed to fit our needs.)

PHP Code:
<?php
/***************************************************************
 * ProPortal
 * Copyright © 2010 ProMyBB, All Rights Reserved
 *
 * Website: http://www.promybb.com/
 * License: http://creativecommons.org/licenses/by-nc-sa/3.0/
 ***************************************************************/
 
if (!defined("IN_PORTAL")) {
	die("<div style=\"border:1px solid #CC0000; padding:3px; margin:0; font-family:Tahoma; width:250px; font-size:12px;\"><strong>Error:</strong> This file cannot be viewed directly!</div>");
}

$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
//$space = '';
$staffcount = 0;
$onlinestaff = '';
$query = $db->query("
	SELECT s.sid, s.ip, s.uid, s.time, s.location, u.username, 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 u.username ASC, s.time DESC
");
while($user = $db->fetch_array($query))
{
		if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
		{
			++$staffcount;
			
			$doneusers[$user['uid']] = $user['time'];
			
			if($mybb->usergroup['canmodcp'] == 1 || $user['uid'] == $mybb->user['uid'])
			{
				$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
				$user['profilelink'] = get_profile_link($user['uid']);
				$onlinestaff .= "<a href=\"{$mybb->settings['bburl']}/{$user['profilelink']}\">{$user['username']}</a>";
				//$space = "<br />";
			}
		}
	}
}

$onlinestaff = $staffcount;

echo "<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
		<tr>
			<td class=\"thead\" colspan=\"2\"><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/{$expcolimage}\" id=\"block_{$result_blocks['id']}_img\" class=\"expander\" alt=\"{$expaltext}\" title=\"{$expaltext}\" /></div>
			<strong>Online Staff: {$staffcount}</td>
		</tr>
		<tbody style=\"{$expdisplay}\" id=\"block_{$result_blocks['id']}_e\">
		<tr>
			<td class=\"trow1\" align=\"center\" valign=\"middle\" width=\"35%\"><img src=\"".$mybb->user['avatar']."\" alt=\"".$mybb->user['avatar']."'s Avatar\" width=\"50px\" height=\"50px\" border=\"0\" /></td>
			<td class=\"trow2\" valign=\"middle\">{$onlinestaff}</td>
		</tr>
		</tbody>
	</table>";

//<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
//		<tr>
//			<td class=\"thead\"><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/{$expcolimage}\" id=\"block_{$result_blocks['id']}_img\" class=\"expander\" alt=\"{$expaltext}\" title=\"{$expaltext}\" /></div><strong><a href=\"{$mybb->settings['bburl']}/online.php\">{$lang->online}: {$onlinestaff}</a></strong></td>
//		</tr>
//		<tbody style=\"{$expdisplay}\" id=\"block_{$result_blocks['id']}_e\">
//		<tr>
//			<td class=\"tcat\"><span class=\"smalltext\">Online Staff</span></td>
//		</tr>
//		<tr>
//			<td class=\"trow1\">{$onlinestaff}</td>
//		</tr>
//		</tbody>
//	</table>";
?>

I have a working sample on my testboard:

http://www.leefish.nl/testfish/portal.php
(01-10-2011 02:46 PM)leefish Wrote: [ -> ]I have a working sample on my testboard:

http://www.leefish.nl/testfish/portal.php

Did you added another query for searching [moderators] online ?
Yes, I remade the query and the whole block_file from scratch.

I now have a shoutbox on the pro_portal - its NOT a block, and its a non-awesome shoutbox (no sound support) - but it IS there

Block now on leefish Custom Block

As usual, no need to register to download. A thanks comment would be nice though Tongue
Reference URL's