Browse Source

Increased `filehash` length and made the reject-post-if-image-already-exists-in-active-content thing

pull/40/head
Savetheinternet 13 years ago
parent
commit
efa06c270e
  1. 15
      inc/functions.php
  2. 2
      install.sql
  3. 17
      post.php
  4. 2
      templates/posts.sql

15
inc/functions.php

@ -1121,7 +1121,20 @@
return $res; return $res;
} }
function getPostByHash($hash) {
global $board;
$query = prepare(sprintf("SELECT `id`,`thread` FROM `posts_%s` WHERE `filehash` = :hash", $board['uri']));
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
$query->execute() or error(db_error($query));
if($post = $query->fetch()) {
return $post;
}
return false;
}
function undoImage($post) { function undoImage($post) {
unlink($post['file']); unlink($post['file']);
unlink($post['thumb']); unlink($post['thumb']);

2
install.sql

@ -135,7 +135,7 @@ CREATE TABLE IF NOT EXISTS `posts_b` (
`fileheight` int(11) DEFAULT NULL, `fileheight` int(11) DEFAULT NULL,
`filesize` int(11) DEFAULT NULL, `filesize` int(11) DEFAULT NULL,
`filename` varchar(30) DEFAULT NULL, `filename` varchar(30) DEFAULT NULL,
`filehash` varchar(32) DEFAULT NULL, `filehash` varchar(40) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL, `password` varchar(20) DEFAULT NULL,
`ip` varchar(45) NOT NULL, `ip` varchar(45) NOT NULL,
`sticky` int(1) NOT NULL, `sticky` int(1) NOT NULL,

17
post.php

@ -155,7 +155,7 @@
$post['mod'] = isset($_POST['mod']) && $_POST['mod']; $post['mod'] = isset($_POST['mod']) && $_POST['mod'];
if(empty($post['body']) && $config['force_body']) if(empty($post['body']) && $config['force_body'])
error($config['error']['tooshortbody']); error($config['error']['tooshort_body']);
if($post['mod']) { if($post['mod']) {
require 'inc/mod.php'; require 'inc/mod.php';
@ -277,6 +277,21 @@
} }
} }
if($config['image_reject_repost'] && $p = getPostByHash($post['filehash'])) {
undoImage($post);
error(sprintf($config['error']['fileexists'],
$post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] .
$board['dir'] . $config['dir']['res'] .
($p->thread ?
$p->thread . '.html#' . $p->id
:
$p->id . '.html'
)
));
}
exit;
// Remove DIR_* before inserting them into the database. // Remove DIR_* before inserting them into the database.
if($post['has_file']) { if($post['has_file']) {
$post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . $config['dir']['img'])); $post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . $config['dir']['img']));

2
templates/posts.sql

@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` (
`fileheight` int(11) DEFAULT NULL, `fileheight` int(11) DEFAULT NULL,
`filesize` int(11) DEFAULT NULL, `filesize` int(11) DEFAULT NULL,
`filename` varchar(30) DEFAULT NULL, `filename` varchar(30) DEFAULT NULL,
`filehash` varchar(32) DEFAULT NULL, `filehash` varchar(40) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL, `password` varchar(20) DEFAULT NULL,
`ip` varchar(15) NOT NULL, `ip` varchar(15) NOT NULL,
`sticky` int(1) NOT NULL, `sticky` int(1) NOT NULL,

Loading…
Cancel
Save