Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2009, 06:41 PM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vbshout ban command

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.

PHP Code:
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
Reply With Quote
  #2  
Old 12-14-2009, 06:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...)
Reply With Quote
  #3  
Old 12-17-2009, 06:48 AM
DJ29Joesph DJ29Joesph is offline
 
Join Date: Jan 2009
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ah yes, you are correct, thanks
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:13 AM.


Powered by vBulletin® Version 3.9.0
Copyright ©2000 - 2017, vBulletin Solutions Inc.