PDA

View Full Version : vbshout ban command


DJ29Joesph
12-14-2009, 06:41 PM
trying to add a ban and unban command to vbshout. I'm hoping I can use the database for this. I created a column in vbuser called Shoutban. The two commands will be /ban and /unban.

This is what I have so far. These are just snips of the code I changed.


function isBanned($user)
{
global $vbulletin;
$banneduserid = $vbulletin->db->query('SELECT userid FROM '.TABLE_PREFIX.'user WHERE ShoutBan > 0')
return (isBanned_Check($user['userid'], $banneduserid) || isBanned_Check($user['usergroupid'], 'shout_banned_usergroups'));
}

function isBanned_Check($bash, $against)
{
global $vbulletin;
return in_array($bash, iif($vbulletin->options[$against], explode(',', $vbulletin->options[$against]), array()));
}

function execCommand($Command)
{
global $meShout;

if (preg_match_all("#^/pruneshout(.*)$#", $Command, $Matches, PREG_SET_ORDER) && canCommand())
{
return execCommand_pruneshout($Matches);
}
else if (preg_match_all("#^/prune(.*)$#", $Command, $Matches, PREG_SET_ORDER) && canCommand())
{
return execCommand_prune($Matches);
}
else if (preg_match_all("#^/ban(.*)$#", $Command, $Matches, PREG_SET_ORDER) && canCommand())
{
return execCommand_ban($Matches);
}
else if (preg_match_all("#^/unban(.*)$#", $Command, $Matches, PREG_SET_ORDER) && canCommand())
{
return execCommand_unban($Matches);
}
else if (preg_match_all("#^/me(.*)$#", $Command, $Matches, PREG_SET_ORDER))
{
$meShout = 1;
return trim($Matches[0][1]);
}

return $Command;
}

function execCommand_ban($Data)
{
global $vbulletin;

$Data = trim($Data[0][1]);

if (!empty($Data))
{
$u = $vbulletin->db->query_first('select userid from '.TABLE_PREFIX.'user where username = \''.addslashes(htmlspecialchars_uni($Data)).'\''))
{
$vbulletin->db->query('UPDATE '.TABLE_PREFIX.'user SET ShoutBan=1 WHERE userid = \''.intval($u['userid']).'\'');
}
}

return true;
}

function execCommand_unban($Data)
{
global $vbulletin;

$Data = trim($Data[0][1]);

if (!empty($Data))
{
$u = $vbulletin->db->query_first('select userid from '.TABLE_PREFIX.'user where username = \''.addslashes(htmlspecialchars_uni($Data)).'\''))
{
$vbulletin->db->query('UPDATE '.TABLE_PREFIX.'user SET ShoutBan=0 WHERE userid = \''.intval($u['userid']).'\'');
}

}

return true;
}


Im not all that great with php but thought I give it a try. Thanks

kh99
12-14-2009, 06:56 PM
I'm not sure I follow all your logic, but a couple things I noticed: In the isBanned function , I think you want "query_first" for the query. Also, it looks to me like isBanned_Check will always fail if you're not passing something for $against because you're calling in_array with an empty array. I think that will mean that isBanned is really only checking the banned groups. (Or I've missed something...)

DJ29Joesph
12-17-2009, 06:48 AM
ah yes, you are correct, thanks