Steal make_comment_hex() from plainib

This commit is contained in:
Michael Foster 2013-09-07 12:50:32 +10:00
parent e9ccc5d72d
commit 55dc5cedc3
2 changed files with 24 additions and 4 deletions

View File

@ -39,7 +39,7 @@ class Filter {
continue 3; continue 3;
break; break;
case 'body': case 'body':
if ($flood_post['posthash'] != md5($post['body_nomarkup'])) if ($flood_post['posthash'] != make_comment_hex($post['body_nomarkup']))
continue 3; continue 3;
break; break;
case 'file': case 'file':
@ -216,12 +216,12 @@ function do_filters(array $post) {
if ($post['has_file']) { if ($post['has_file']) {
$query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash OR `filehash` = :filehash"); $query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash OR `filehash` = :filehash");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':posthash', md5($post['body_nomarkup'])); $query->bindValue(':posthash', make_comment_hex($post['body_nomarkup']));
$query->bindValue(':filehash', $post['filehash']); $query->bindValue(':filehash', $post['filehash']);
} else { } else {
$query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash"); $query = prepare("SELECT * FROM ``flood`` WHERE `ip` = :ip OR `posthash` = :posthash");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':posthash', md5($post['body_nomarkup'])); $query->bindValue(':posthash', make_comment_hex($post['body_nomarkup']));
} }
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$flood_check = $query->fetchAll(PDO::FETCH_ASSOC); $flood_check = $query->fetchAll(PDO::FETCH_ASSOC);

View File

@ -763,7 +763,7 @@ function insertFloodPost(array $post) {
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':board', $board['uri']); $query->bindValue(':board', $board['uri']);
$query->bindValue(':time', time()); $query->bindValue(':time', time());
$query->bindValue(':posthash', md5($post['body_nomarkup'])); $query->bindValue(':posthash', make_comment_hex($post['body_nomarkup']));
if ($post['has_file']) if ($post['has_file'])
$query->bindValue(':filehash', $post['filehash']); $query->bindValue(':filehash', $post['filehash']);
else else
@ -1191,6 +1191,26 @@ function getPages($mod=false) {
return $pages; return $pages;
} }
// Stolen with permission from PlainIB (by Frank Usrs)
function make_comment_hex($str) {
// remove cross-board citations
// the numbers don't matter
$str = preg_replace('!>>>/[A-Za-z0-9]+/!', '', $str);
if (function_exists('iconv')) {
// remove diacritics and other noise
// FIXME: this removes cyrillic entirely
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
}
$str = strtolower($str);
// strip all non-alphabet characters
$str = preg_replace('/[^a-z]/', '', $str);
return md5($str);
}
function makerobot($body) { function makerobot($body) {
global $config; global $config;
$body = strtolower($body); $body = strtolower($body);