Adding support for multiple file upload using URLs, previously only one URL was supported. Also removes duplicate slack reporting merge.
This commit is contained in:
parent
08114c44e9
commit
ef41b1622d
57
post.php
57
post.php
@ -530,8 +530,14 @@ if (isset($_POST['delete'])) {
|
||||
$_POST['subject'] = '';
|
||||
}
|
||||
|
||||
if ($config['allow_upload_by_url'] && isset($_POST['file_url']) && !empty($_POST['file_url'])) {
|
||||
$post['file_url'] = $_POST['file_url'];
|
||||
if ($config['allow_upload_by_url'] && isset($_POST['file_url1']) && !empty($_POST['file_url1'])) {
|
||||
function unlink_tmp_file($file) {
|
||||
@unlink($file);
|
||||
fatal_error_handler();
|
||||
}
|
||||
|
||||
function upload_by_url($config,$post,$url) {
|
||||
$post['file_url'] = $url;
|
||||
if (!preg_match('@^https?://@', $post['file_url']))
|
||||
error($config['error']['invalidimg']);
|
||||
|
||||
@ -550,10 +556,6 @@ if (isset($_POST['delete'])) {
|
||||
error($config['error']['unknownext']);
|
||||
|
||||
$post['file_tmp'] = tempnam($config['tmp'], 'url');
|
||||
function unlink_tmp_file($file) {
|
||||
@unlink($file);
|
||||
fatal_error_handler();
|
||||
}
|
||||
register_shutdown_function('unlink_tmp_file', $post['file_tmp']);
|
||||
|
||||
$fp = fopen($post['file_tmp'], 'w');
|
||||
@ -576,13 +578,20 @@ if (isset($_POST['delete'])) {
|
||||
|
||||
fclose($fp);
|
||||
|
||||
$_FILES['file'] = array(
|
||||
$_FILES[$post['file_tmp']] = array(
|
||||
'name' => basename($url_without_params),
|
||||
'tmp_name' => $post['file_tmp'],
|
||||
'file_tmp' => true,
|
||||
'error' => 0,
|
||||
'size' => filesize($post['file_tmp'])
|
||||
);
|
||||
}
|
||||
|
||||
for( $counter = 1; $counter <= $config['max_images']; $counter++ ) {
|
||||
$varname = "file_url". $counter;
|
||||
upload_by_url($config,$post,$_POST[$varname]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
|
||||
@ -1001,8 +1010,7 @@ if (isset($_POST['delete'])) {
|
||||
escapeshellarg($file['thumb']));
|
||||
|
||||
if ($error){
|
||||
$path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['ext
|
||||
ension']] : $config['file_icons']['default']);
|
||||
$path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']);
|
||||
}
|
||||
|
||||
$file['thumb'] = basename($file['thumb']);
|
||||
@ -1181,37 +1189,6 @@ if (isset($_POST['delete'])) {
|
||||
$query->bindValue(':thread', $post['thread']);
|
||||
$query->bindValue(':limit', $config['cycle_limit'], PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
if ($config['slack'])
|
||||
{
|
||||
function slack($message, $room = "reports", $icon = ":no_entry_sign:")
|
||||
{
|
||||
$room = ($room) ? $room : "reports";
|
||||
$data = "payload=" . json_encode(array(
|
||||
"channel" => "#{$room}",
|
||||
"text" => urlencode($message),
|
||||
"icon_emoji" => $icon
|
||||
));
|
||||
|
||||
// You can get your webhook endpoint from your Slack settings
|
||||
// For some reason using the configuration key doesn't work
|
||||
$ch = curl_init($config['slack_incoming_webhook_endpoint']);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_';
|
||||
$slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n';
|
||||
|
||||
$slackresult = slack($slackmessage, $config['slack_channel']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (isset($post['antispam_hash'])) {
|
||||
|
@ -121,7 +121,10 @@
|
||||
{% if config.allow_upload_by_url %}
|
||||
<div style="float:none;text-align:left" id="upload_url">
|
||||
<label for="file_url">{% trans %}Or URL{% endtrans %}</label>:
|
||||
<input style="display:inline" type="text" id="file_url" name="file_url" size="35">
|
||||
{% for counter in 1..config.max_images %}
|
||||
<input style="display:inline" type="text" id="file_url{{ counter }}" name="file_url{{ counter }}" size="35">
|
||||
</br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{{ antibot.html() }}
|
||||
|
Loading…
Reference in New Issue
Block a user