reply limit and mutes

This commit is contained in:
Savetheinternet 2011-01-20 19:24:41 +11:00
parent a62cd3893f
commit e1e5dc713e
2 changed files with 51 additions and 27 deletions

View File

@ -81,6 +81,7 @@
define('ERROR_FLOOD', 'Flood detected; Post discared.', true);
define('ERROR_UNORIGINAL', 'Unoriginal content!', true);
define('ERROR_MUTED', 'Unoriginal content! You have been muted for %d seconds.', true);
define('ERROR_YOUAREMUTED', 'You are muted! Expires in %d seconds.', true);
define('ERROR_TOR', 'Hmm… That looks like a Tor exit node.', true);
define('ERROR_TOOMANYLINKS', 'Too many links; flood detected.', true);
define('ERR_INVALIDIMG','Invalid image.', true);
@ -101,9 +102,12 @@
define('ERROR_INVALIDPOST', 'That post doesn\'t exist…', true);
define('ERROR_404', 'Page not found.', true);
// Reply limit (deletes thread when this is reached)
define('REPLY_LIMIT', 250, true);
// For resizing, max values
define('THUMB_WIDTH', 200, true);
define('THUMB_HEIGHT', 200, true);
define('THUMB_WIDTH', 250, true);
define('THUMB_HEIGHT', 250, true);
// Store image hash in the database for r9k-like boards implementation soon
// Function name for hashing
@ -112,7 +116,7 @@
define('BLOCK_TOR', true, true);
// Typically spambots try to post a lot of links. Refuse a post with X standalone links?
define('MAX_LINKS', 7, true);
define('MAX_LINKS', 15, true);
// Maximum image upload size in bytes
define('MAX_FILESIZE', 10*1024*1024, true); // 10MB
@ -181,8 +185,8 @@
define('ROBOT_STRIP_REPEATING', true, true);
// Enable mutes
define('ROBOT_MUTE', true, true);
define('ROBOT_MUTE_MIN', 60, true);
define('ROBOT_MUTE_MAX', 120, true);
define('ROBOT_MUTE_HOUR', 50, true); // How many mutes X hours ago to include in the algorithm
define('ROBOT_MUTE_MULTIPLIER', 2, true);
define('ROBOT_MUTE_DESCRIPTION', 'You have been muted for unoriginal content.', true);
/*

View File

@ -1,4 +1,7 @@
<?php
file_put_contents('test.log', "\n\nNEW POST\n", FILE_APPEND);
file_put_contents('test.log', print_r($_FILES, true), FILE_APPEND);
require 'inc/functions.php';
require 'inc/display.php';
if (file_exists('inc/instance-config.php')) {
@ -69,6 +72,10 @@
if(!openBoard($post['board']))
error(ERROR_NOBOARD);
if(ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && ROBOT_MUTE) {
checkMute();
}
//Check if thread exists
if(!$OP && !threadExists($post['thread']))
error(ERROR_NONEXISTANT);
@ -159,24 +166,7 @@
if($post['mod_tag'])
$post['trip'] .= ' <a class="nametag">## ' . $post['mod_tag'] . '</a>';
if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body'])) {
if(ROBOT_MUTE) {
$mutetime = ROBOT_MUTE_MIN+rand()%(ROBOT_MUTE_MAX-ROBOT_MUTE_MIN);
$query = prepare("INSERT INTO `bans` VALUES (:ip, :mod, :set, :expires, :reason)");
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
$query->bindValue(':mod', -1, PDO::PARAM_INT);
$query->bindValue(':set', time(), PDO::PARAM_INT);
$query->bindValue(':expires', time()+$mutetime, PDO::PARAM_INT);
$query->bindValue(':reason', ROBOT_MUTE_DESCRIPTION);
$query->execute() or error(db_error($query));
error(sprintf(ERROR_MUTED, $mutetime));
} else {
error(ERROR_UNORIGINAL);
}
}
$post['body_nomarkup'] = $post['body'];
markup($post['body']);
// Check for a flood
@ -185,11 +175,14 @@
}
if($post['has_file']) {
file_put_contents('test.log', "There is a file, I'm about to move it!\n", FILE_APPEND);
// Just trim the filename if it's too long
if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…';
// Move the uploaded file
if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error(ERROR_NOMOVE);
file_put_contents('test.log', "Moved it successfully (to {$post['file']}), I think!\n", FILE_APPEND);
if($post['zip']) {
// Validate ZIP file
if(is_resource($zip = zip_open($post['zip'])))
@ -202,10 +195,14 @@
$post['extension'] = strtolower(substr($post['file'], strrpos($post['file'], '.') + 1));
}
file_put_contents('test.log', "Getting image size of {$post['file']}\n", FILE_APPEND);
$size = @getimagesize($post['file']);
$post['width'] = $size[0];
$post['height'] = $size[1];
file_put_contents('test.log', "GOT IT! {$post['width']}x{$post['height']}\n", FILE_APPEND);
// Check if the image is valid
if($post['width'] < 1 || $post['height'] < 1) {
unlink($post['file']);
@ -217,12 +214,18 @@
error(ERR_MAXSIZE);
}
file_put_contents('test.log', "Making a hash\n", FILE_APPEND);
$hash_function = FILE_HASH;
$post['filehash'] = $hash_function($post['file']);
$post['filesize'] = filesize($post['file']);
file_put_contents('test.log', "Got a hash ({$post['filehash']})! Loading image...\n", FILE_APPEND);
$image = createimage($post['extension'], $post['file']);
file_put_contents('test.log', "Image loaded!\n", FILE_APPEND);
if(REDRAW_IMAGE && !$post['zip']) {
switch($post['extension']) {
case 'jpg':
@ -245,19 +248,32 @@
}
}
file_put_contents('test.log', "Resizing...\n", FILE_APPEND);
// Create a thumbnail
$thumb = resize($image, $post['width'], $post['height'], $post['thumb'], THUMB_WIDTH, THUMB_HEIGHT);
file_put_contents('test.log', "Resized!\n", FILE_APPEND);
$post['thumbwidth'] = $thumb['width'];
$post['thumbheight'] = $thumb['height'];
}
if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) {
if(ROBOT_MUTE) {
error(sprintf(ERROR_MUTED, mute()));
} else {
error(ERROR_UNORIGINAL);
}
}
// Remove DIR_* before inserting them into the database.
if($post['has_file']) {
$post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . DIR_IMG));
$post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . DIR_THUMB));
}
file_put_contents('test.log', "Posting...!\n", FILE_APPEND);
// Todo: Validate some more, remove messy code, allow more specific configuration
$id = post($post, $OP);
@ -357,11 +373,15 @@
unlink($post['zip']);
}
if(numPosts($OP?$id:$post['thread']) > REPLY_LIMIT) {
deletePost($OP?$id:$post['thread']);
} else {
buildThread(($OP?$id:$post['thread']));
if(!$OP && $post['email'] != 'sage') {
bumpThread($post['thread']);
}
}
if($OP)
clean();