Browse Source

Add image_reject_repost_in_thread option

pull/40/head
Macil Tech 12 years ago
parent
commit
91e8547b04
  1. 5
      inc/config.php
  2. 14
      inc/functions.php
  3. 39
      post.php

5
inc/config.php

@ -445,8 +445,10 @@
// Maximum image dimensions // Maximum image dimensions
$config['max_width'] = 10000; $config['max_width'] = 10000;
$config['max_height'] = $config['max_width']; // 1:1 $config['max_height'] = $config['max_width']; // 1:1
// Reject dupliate image uploads // Reject duplicate image uploads
$config['image_reject_repost'] = true; $config['image_reject_repost'] = true;
// Reject duplicate image uploads within the same thread. Doesn't change anything if image_reject_repost is true.
$config['image_reject_repost_in_thread'] = false;
// Display the aspect ratio in a post's file info // Display the aspect ratio in a post's file info
$config['show_ratio'] = false; $config['show_ratio'] = false;
@ -667,6 +669,7 @@
$config['error']['maxsize'] = _('The file was too big.'); $config['error']['maxsize'] = _('The file was too big.');
$config['error']['invalidzip'] = _('Invalid archive!'); $config['error']['invalidzip'] = _('Invalid archive!');
$config['error']['fileexists'] = _('That file <a href="%s">already exists</a>!'); $config['error']['fileexists'] = _('That file <a href="%s">already exists</a>!');
$config['error']['fileexistsinthread'] = _('That file <a href="%s">already exists</a> in this thread!');
$config['error']['delete_too_soon'] = _('You\'ll have to wait another %s before deleting that.'); $config['error']['delete_too_soon'] = _('You\'ll have to wait another %s before deleting that.');
$config['error']['mime_exploit'] = _('MIME type detection XSS exploit (IE) detected; post discarded.'); $config['error']['mime_exploit'] = _('MIME type detection XSS exploit (IE) detected; post discarded.');
$config['error']['invalid_embed'] = _('Couldn\'t make sense of the URL of the video you tried to embed.'); $config['error']['invalid_embed'] = _('Couldn\'t make sense of the URL of the video you tried to embed.');

14
inc/functions.php

@ -1651,6 +1651,20 @@ function getPostByHash($hash) {
return false; return false;
} }
function getPostByHashInThread($hash, $thread) {
global $board;
$query = prepare(sprintf("SELECT `id`,`thread` FROM `posts_%s` WHERE `filehash` = :hash AND ( `thread` = :thread OR `id` = :thread )", $board['uri']));
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
$query->bindValue(':thread', $thread, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
if ($post = $query->fetch()) {
return $post;
}
return false;
}
function undoImage(array $post) { function undoImage(array $post) {
if (!$post['has_file']) if (!$post['has_file'])
return; return;

39
post.php

@ -500,17 +500,34 @@ if (isset($_POST['delete'])) {
} }
} }
if ($post['has_file'] && $config['image_reject_repost'] && $p = getPostByHash($post['filehash'])) { if ($post['has_file']) {
undoImage($post); if ($config['image_reject_repost']) {
error(sprintf($config['error']['fileexists'], if ($p = getPostByHash($post['filehash'])) {
$post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] . undoImage($post);
$board['dir'] . $config['dir']['res'] . error(sprintf($config['error']['fileexists'],
($p['thread'] ? $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] .
$p['thread'] . '.html#' . $p['id'] $board['dir'] . $config['dir']['res'] .
: ($p['thread'] ?
$p['id'] . '.html' $p['thread'] . '.html#' . $p['id']
) :
)); $p['id'] . '.html'
)
));
}
} else if (!$post['op'] && $config['image_reject_repost_in_thread']) {
if ($p = getPostByHashInThread($post['filehash'], $post['thread'])) {
undoImage($post);
error(sprintf($config['error']['fileexistsinthread'],
$post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'] .
$board['dir'] . $config['dir']['res'] .
($p['thread'] ?
$p['thread'] . '.html#' . $p['id']
:
$p['id'] . '.html'
)
));
}
}
} }
if (!hasPermission($config['mod']['postunoriginal'], $board['uri']) && $config['robot_enable'] && checkRobot($post['body_nomarkup'])) { if (!hasPermission($config['mod']['postunoriginal'], $board['uri']) && $config['robot_enable'] && checkRobot($post['body_nomarkup'])) {

Loading…
Cancel
Save