Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: EL34 - elokuu 02, 2014, 08:29:53 AP

Otsikko: Need some help with a bit of PHP - convert SMF 1 to SMF 2 code
Kirjoitti: EL34 - elokuu 02, 2014, 08:29:53 AP
I use mod httpbl by snoopy virtual
He is not supporting this mod and has moved on, so I need to convert a bit of code he gave me for SMF 1 into SMF 2 code

Snoopy gave me a bit of custom code he wrote that deletes guest only from the http bl log file - log_httpBL
That will leave forum members only in the log file and delete all guest
This worked great in SMF 1 , but I have since upgraded to SMF 2 and want this feature back

The button code he gave me works fine. It adds a button when you are viewing the http bl log

The code that runs when the button is pressed would be different for SMF 2 but I am not familiar with how to alter that
I know where to insert the code in the httpbl_config.php file
I just need some PHP translation help

Here's is the code he gave me for SMF 1


// 'Remove Guests' (EL34) button was pressed.
else if (!empty($_POST['removeGuests']))
db_query("
DELETE FROM {$db_prefix}log_httpBL
WHERE username = 'Guest'", __FILE__, __LINE__);






SMF 2 delete code looks a bit different to me
Here's a SMF 2 code sample that deletes everything in the httpbl log




// 'Clear this log' button was pressed.
else if (!empty($_POST['clearThisLog']))
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_httpBL
WHERE ' . $query_where,
array(
)
);


How would the SMF 1 code shown above be written for SMF2?
All it has to do is delete all username of guest
thanks
Otsikko: Re: Need some help with a bit of PHP - convert SMF 1 to SMF 2 code
Kirjoitti: Arantor - elokuu 02, 2014, 08:32:09 AP
// 'Remove Guests' (EL34) button was pressed.
else if (!empty($_POST['removeGuests']))
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_httpBL
WHERE username = {string:guest}',
array(
'guest' => 'Guest',
)
);


should do the trick for the first block.
Otsikko: Re: Need some help with a bit of PHP - convert SMF 1 to SMF 2 code
Kirjoitti: EL34 - elokuu 02, 2014, 08:34:59 AP
Thank you for the code and the super fast reply

I'll go insert it and report back
Otsikko: Re: Need some help with a bit of PHP - convert SMF 1 to SMF 2 code
Kirjoitti: EL34 - elokuu 02, 2014, 10:10:40 AP
Thank you, the code worked but I had to change something to get it to work

Apparently the username was set to guest in the log-httpbl table in SMF 1

In SMF 2 the username is just blank if they are guest
So I changed the guest string comparison to blank and now it works

Thanks for your help

else if (!empty($_POST['removeGuests']))
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_httpBL
WHERE username = {string:guest}',
array(
'guest' => '',
)
);
Otsikko: Re: Need some help with a bit of PHP - convert SMF 1 to SMF 2 code
Kirjoitti: Arantor - elokuu 02, 2014, 10:12:02 AP
Looks good :)