$value) {
if (! PageExists($value)) unset($BlocklistPages[$key]);
}
}
//print_r($BlocklistPages);
//print_r($_POST['text']);
# This script only applies to editing (or the commentbox cookbook script), so
# if we're not editing or commenting, just return. Partly borrowed from cmsb-blocklist.php.
# Not sure why he added "diff" to the actions that this runs on.
if (! ($action == 'edit' || $action == 'comment')
|| (count($BlocklistPages) < 1)
|| in_array ($page_name, $BlocklistPages) ) { return; }
//Now that we know we're supposed to be here, set remaining variables
SDV($BlocklistMessageFmt, "
$[This post has been blocked by the administrator]
");
SDV($BlockIPMessageFmt, "Remote server matches blocked server IP: ");
SDV($BlockTextMessageFmt, "Content matches blocklist content: ");
SDV($EnableWhyBlocked, "0"); // default is to not let them know
SDV($EnableBlocklistRegex, "0"); // enables Perl-compatible regular expression search
// Set the block counter
$Blocklisted = 0;
// check each blocklist page
foreach((array)$BlocklistPages as $oneblockpage) {
$pn = FmtPageName($oneblockpage,$pagename);
$page = ReadPage($pn);
// Prep for IP checking
list($ipa,$ipb,$ipc,$ipd) = explode('.', $_SERVER['REMOTE_ADDR']);
// Check ip address against page text
if (preg_match("/(\\D$ipa\\.$ipb\\.(\\D|$ipc)\\.($ipd)?\\D)/", $page['text'], $matchedip)) {
$Blocklisted++; // increment counter
$WhyBlockedFmt .= $BlockIPMessageFmt . $matchedip[1] . "\n"; // add a reason why the page is blocked
}
// When not tallying reasons, only run through the terms if the IP is not blocked
if (!(($EnableWhyBlocked == 0) && ($Blocklisted > 0))) {
//catch and fix multiple block:'s on a single line and leading whitespace
//(allows legacy format)
$blocktext = preg_replace('/\\s*block:/', "\nblock:", $page['text']);
// Make an array of text that follows "block:" incl spaces & punct
preg_match_all('/block:\s*(.+)/', $blocktext, $blockterms);
//compares entries in the blocklist to the post content
// Check posted page content against blocklist
// Note: matches only on first, not repeated, offenses-per-criteria
// If score/reasons are not being tallied, break out.
foreach ($blockterms[1] as $blockitem){
if (stristr(@$_POST['text'], $blockitem)) {
$Blocklisted++;
if ($EnableWhyBlocked == 0) break;
$WhyBlockedFmt .= $BlockTextMessageFmt . $blockitem . "\n";
}
}
}
// Check Regex only if necessary
if (($EnableBlocklistRegex == 1) && !(($EnableWhyBlocked == 0) && ($Blocklisted > 0))) {
//catch and fix multiple block:'s on a single line and leading whitespace
//(allows legacy format)
$blocktext = preg_replace('/\\s*regex:/', "\nregex:", $blocktext);
// Make an array of text that follows "regex:" incl spaces & punct
preg_match_all('/regex:(.+)/', $blocktext, $regexterms);
//compares entries in the regex list to the post content
// Note: matches only on first, not repeated, offenses-per-criteria
// If score/reasons are not being tallied, break out.
foreach ($regexterms[1] as $oneregex){
if (preg_match($oneregex, @$_POST['text'], $regexmatch)) {
$Blocklisted++;
if ($EnableWhyBlocked == 0) break;
$WhyBlockedFmt .= $BlockTextMessageFmt . $regexmatch[0] . "\n";
}
}
}
} //foreach ((array)$BlocklistPages)
// if the posting is blocked, then disallow the post
if ($Blocklisted) {
$EnablePost = 0;
unset($_POST['post']);
unset($_POST['postattr']);
unset($_POST['postedit']);
// let the poster know they've been blocked
$MessagesFmt[] .= $BlocklistMessageFmt;
// if required, provide reasons
if ($EnableWhyBlocked == 1) $MessagesFmt[] = '' . $WhyBlockedFmt . "
";
}
?>