A bunch of stuff.
This commit is contained in:
parent
d284b0d50d
commit
62bd2ee348
@ -76,6 +76,7 @@
|
||||
define('ERROR_LOCKED', 'Thread locked. You may not reply at this time.', true);
|
||||
define('ERROR_NOPOST', 'You didn\'t make a post.', true);
|
||||
define('ERROR_FLOOD', 'Flood detected; Post discared.', true);
|
||||
define('ERROR_UNORIGINAL', 'Unoriginal content!', true);
|
||||
define('ERR_INVALIDIMG','Invalid image.', true);
|
||||
define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes<br>Your file\'s size: %filesz% bytes', true);
|
||||
define('ERR_MAXSIZE', 'The file was too big.', true);
|
||||
@ -163,6 +164,12 @@
|
||||
// "302" is recommended.
|
||||
define('REDIRECT_HTTP', 302, true);
|
||||
|
||||
// Robot stuff
|
||||
// Strip repeating characters when making hashes
|
||||
define('ROBOT_ENABLE', true, true);
|
||||
define('ROBOT_STRIP_REPEATING', true, true);
|
||||
|
||||
|
||||
/*
|
||||
Mod stuff
|
||||
*/
|
||||
@ -206,6 +213,8 @@
|
||||
define('MOD_LOCK', MOD_MOD, true);
|
||||
// Post in a locked thread
|
||||
define('MOD_POSTINLOCKED', MOD_MOD, true);
|
||||
// Post bypass unoriginal content check
|
||||
define('MOD_POSTUNORIGINAL', MOD_MOD, true);
|
||||
|
||||
/* Administration */
|
||||
// Display the contents of instant-config.php
|
||||
|
@ -262,6 +262,61 @@
|
||||
$query->execute() or error(db_error($query));
|
||||
}
|
||||
|
||||
// Delete a post (reply or thread)
|
||||
function deletePost($id) {
|
||||
global $board;
|
||||
|
||||
// Select post and replies (if thread) in one query
|
||||
$query = prepare(sprintf("SELECT `id`,`thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if($query->rowCount() < 1) {
|
||||
error(ERROR_INVALIDPOST);
|
||||
}
|
||||
|
||||
// Delete posts and maybe replies
|
||||
while($post = $query->fetch()) {
|
||||
if(!$post['thread']) {
|
||||
// Delete thread HTML page
|
||||
@unlink($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $post['id']));
|
||||
} elseif($query->rowCount() == 1) {
|
||||
// Rebuild thread
|
||||
$rebuild = $post['thread'];
|
||||
}
|
||||
if($post['thumb']) {
|
||||
// Delete thumbnail
|
||||
@unlink($board['dir'] . DIR_THUMB . $post['thumb']);
|
||||
}
|
||||
if($post['file']) {
|
||||
// Delete file
|
||||
@unlink($board['dir'] . DIR_IMG . $post['file']);
|
||||
}
|
||||
}
|
||||
|
||||
$query = prepare(sprintf("DELETE FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if(isset($rebuild)) {
|
||||
buildThread($rebuild);
|
||||
}
|
||||
}
|
||||
|
||||
function clean() {
|
||||
global $board;
|
||||
$offset = round(MAX_PAGES*THREADS_PER_PAGE);
|
||||
|
||||
// I too wish there was an easier way of doing this...
|
||||
$query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri']));
|
||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
|
||||
$query->execute() or error(db_error($query));
|
||||
while($post = $query->fetch()) {
|
||||
deletePost($post['id']);
|
||||
}
|
||||
}
|
||||
|
||||
function index($page, $mod=false) {
|
||||
global $board;
|
||||
|
||||
@ -324,6 +379,40 @@
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function makerobot($body) {
|
||||
$body = strtolower($body);
|
||||
|
||||
// Leave only letters
|
||||
$body = preg_replace('/[^a-z]/i', '', $body);
|
||||
// Remove repeating characters
|
||||
if(ROBOT_STRIP_REPEATING)
|
||||
$body = preg_replace('/(.)\\1+/', '$1', $body);
|
||||
|
||||
return sha1($body);
|
||||
}
|
||||
|
||||
function checkRobot($body) {
|
||||
/* CREATE TABLE `robot` (
|
||||
`hash` VARCHAR( 40 ) NOT NULL COMMENT 'SHA1'
|
||||
) ENGINE = INNODB; */
|
||||
|
||||
$body = makerobot($body);
|
||||
$query = prepare("SELECT 1 FROM `robot` WHERE `hash` = :hash LIMIT 1");
|
||||
$query->bindValue(':hash', $body);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if($query->fetch()) {
|
||||
return true;
|
||||
} else {
|
||||
// Insert new hash
|
||||
|
||||
$query = prepare("INSERT INTO `robot` VALUES (:hash)");
|
||||
$query->bindValue(':hash', $body);
|
||||
$query->execute() or error(db_error($query));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function buildIndex() {
|
||||
global $board;
|
||||
sql_open();
|
||||
@ -417,6 +506,7 @@
|
||||
$body = preg_replace("/(^|\n)==(.+?)==\n?/m", "<h2>$2</h2>", $body);
|
||||
$body = preg_replace("/'''(.+?)'''/m", "<strong>$1</strong>", $body);
|
||||
$body = preg_replace("/''(.+?)''/m", "<em>$1</em>", $body);
|
||||
$body = preg_replace("/\*\*(.+?)\*\*/m", "<span class=\"spoiler\">$1</span>", $body);
|
||||
}
|
||||
$body = preg_replace("/\n/", '<br/>', $body);
|
||||
}
|
||||
|
41
inc/mod.php
41
inc/mod.php
@ -209,45 +209,4 @@
|
||||
|
||||
buildThread($post['thread']);
|
||||
}
|
||||
|
||||
// Delete a post (reply or thread)
|
||||
function deletePost($id) {
|
||||
global $board;
|
||||
|
||||
// Select post and replies (if thread) in one query
|
||||
$query = prepare(sprintf("SELECT `id`,`thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if($query->rowCount() < 1) {
|
||||
error(ERROR_INVALIDPOST);
|
||||
}
|
||||
|
||||
// Delete posts and maybe replies
|
||||
while($post = $query->fetch()) {
|
||||
if(!$post['thread']) {
|
||||
// Delete thread HTML page
|
||||
@unlink($board['dir'] . DIR_RES . sprintf(FILE_PAGE, $post['id']));
|
||||
} elseif($query->rowCount() == 1) {
|
||||
// Rebuild thread
|
||||
$rebuild = $post['thread'];
|
||||
}
|
||||
if($post['thumb']) {
|
||||
// Delete thumbnail
|
||||
@unlink($board['dir'] . DIR_THUMB . $post['thumb']);
|
||||
}
|
||||
if($post['file']) {
|
||||
// Delete file
|
||||
@unlink($board['dir'] . DIR_IMG . $post['file']);
|
||||
}
|
||||
}
|
||||
|
||||
$query = prepare(sprintf("DELETE FROM `posts_%s` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if(isset($rebuild)) {
|
||||
buildThread($rebuild);
|
||||
}
|
||||
}
|
||||
?>
|
9
post.php
9
post.php
@ -147,6 +147,9 @@
|
||||
if(checkFlood($post))
|
||||
error(ERROR_FLOOD);
|
||||
|
||||
if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && checkRobot($post['body']))
|
||||
error(ERROR_UNORIGINAL);
|
||||
|
||||
if($post['has_file']) {
|
||||
// Just trim the filename if it's too long
|
||||
if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…';
|
||||
@ -221,7 +224,6 @@
|
||||
}
|
||||
|
||||
// Todo: Validate some more, remove messy code, allow more specific configuration
|
||||
|
||||
$id = post($post, $OP);
|
||||
|
||||
if($post['has_file'] && $post['zip']) {
|
||||
@ -322,10 +324,13 @@
|
||||
|
||||
buildThread(($OP?$id:$post['thread']));
|
||||
|
||||
if(!$OP) {
|
||||
if(!$OP && $post['email'] != 'sage') {
|
||||
bumpThread($post['thread']);
|
||||
}
|
||||
|
||||
if($OP)
|
||||
clean();
|
||||
|
||||
buildIndex();
|
||||
sql_close();
|
||||
|
||||
|
10
style.css
10
style.css
@ -199,6 +199,10 @@ span.controls.op {
|
||||
span.controls a {
|
||||
margin: 0;
|
||||
}
|
||||
div#wrap {
|
||||
width: 900px;
|
||||
margin:0 auto;
|
||||
}
|
||||
div.ban {
|
||||
background: white;
|
||||
border: 1px solid #98E;
|
||||
@ -220,3 +224,9 @@ div.ban p {
|
||||
div.ban p.reason {
|
||||
font-weight: bold;
|
||||
}
|
||||
span.spoiler {
|
||||
background: black;
|
||||
}
|
||||
span.spoiler:hover {
|
||||
color: white;
|
||||
}
|
Loading…
Reference in New Issue
Block a user