I modified the script to add more functionality. Actually, I didn't do nothing, it's all ChatGPT

Works with phpBB version 3.3.3 and just updated to latest 3.3.14 and it works again.
Modify posting.php, add code below at around 1110 line (or at line 1137 in the latest phpBB 3.3.14 right after
Code: Select all
if (count($message_parser->warn_msg))
{
$error[] = implode('<br />', $message_parser->warn_msg);
$message_parser->warn_msg = array();
}
Code: Select all
/*** BEGIN CUSTOM CODE
Block posting with banned words being used in both the message and the subject. Also block posting if there is a link into the subject.
To debug, uncomment the error_log line which will output errors into the error_log file. You have to enable this file first however.
https://www.phpbb.com/community/viewtopic.php?t=2135443
***/
// Example spam word list
$aSpam = [
'word1'=> ''
, 'word2'=> ''
, 'word3'=> ''
];
// Regex for detecting URLs (only in the subject)
$urlPattern = '#\bhttps?://[^\s]+#i';
// Combine spam words into a single regex pattern
$wordPattern = '#\b(' . implode('|', array_map('preg_quote', array_keys($aSpam))) . ')\b#i';
// Subject and message to validate
$subject = $request->variable('subject', '', true);
$message = isset($message_parser->message) ? $message_parser->message : '';
// Initialize errors
$error = [];
// Debug: Log subject and message to verify data
// error_log("Subject: " . $subject);
// error_log("Message: " . $message);
// Check for spam words in the subject
if (preg_match($wordPattern, $subject, $matches)) {
$error[] = "Spam detected due to prohibited word: '{$matches[1]}' in subject.";
}
// Check for spam words in the message
if (preg_match($wordPattern, $message, $matches)) {
$error[] = "Spam detected due to prohibited word: '{$matches[1]}' in message.";
}
// Check for URLs in the subject only
if (preg_match($urlPattern, $subject)) {
$error[] = "Spam detected due to URL in subject.";
}
// Debug: Log detected errors
// if (!empty($error)) {
// error_log("Errors detected: " . implode(' | ', $error));
// }
/*** END CUSTOM CODE
***/