2008-11-04, 11:54 PM
I'm working on a plugin which replaces occurrences of a word or expression with the same word, but with extra MyCode around it.
The main problems I'm having are:
- Nothing seems to happen when a thread is replied to using the Quick Reply
- Only one word/expression is changed when it does work (using Full Edit or non-quick Reply)
I'm not a fantastic PHP scripter, so there might be a few rookie mistakes.
The code is below, and attached.
As you can see by the code, it's eventually going to be automatically banning/warning users for saying certain words, saving moderators a bit of time
The main problems I'm having are:
- Nothing seems to happen when a thread is replied to using the Quick Reply
- Only one word/expression is changed when it does work (using Full Edit or non-quick Reply)
I'm not a fantastic PHP scripter, so there might be a few rookie mistakes.
The code is below, and attached.
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialisation of this file is not allowed.");
}
$plugins->add_hook("datahandler_post_update", "autoban_run");
$plugins->add_hook("datahandler_post_insert_post", "autoban_run");
$plugins->add_hook("datahandler_post_insert_thread_post", "autoban_run");
$plugins->add_hook("datahandler_post_update_thread_post", "autoban_run");
$plugins->add_hook("datahandler_post_update", "autoban_run");
function autoban_info()
{
return array(
"name" => "Uber's Autoban",
"description" => "Automatically bans members for posting certain words.",
"website" => "google.com",
"author" => "UberMensch",
"authorsite" => "google.com",
"version" => "0.1",
"compatibility" => "1*",
);
}
function autoban_activate()
{
}
function autoban_deactivate()
{
}
function autoban_run($post)
{
$banwords = "test,test2,line of test";
$callback = 0;
if( isset( $post->post_update_data['message']) )
{
$callback = 1;
}
$words = split(",", $banwords);
$message;
for( $i = 0; $i <= count($words)-1; $i++)
{
if($callback == 1)
{
$message = str_replace( $words[$i], "[highlight][u]" . $words[$i] . "[/u][/highlight]", $post->post_update_data['message']);
} else {
$message = str_replace( $words[$i], "[highlight][u]" . $words[$i] . "[/u][/highlight]", $post->post_insert_data['message']);
}
}
if( $callback = 1 )
{
$post->post_update_data['message'] = $message . "\r\n\r\n\r\n[highlight]USER WAS AUTOBANNED FOR THIS POST[/highlight]";
} else {
$post->post_insert_data['message'] = $message . "\r\n\r\n\r\n[highlight]USER WAS AUTOBANNED FOR THIS POST[/highlight]";
}
}
?>
As you can see by the code, it's eventually going to be automatically banning/warning users for saying certain words, saving moderators a bit of time