Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Cleaned up the file submission section a bit. #242

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# static html and json
/*/*.html
/*/*.json
*.html
*.json
/*/res
/*/src
/*/thumb
Expand All @@ -22,8 +22,11 @@
# .installed
/.installed

# script file
# script files
/main.js
/*/main.js
/*/rules.txt
/stylesheets/board/*.css

# templates cache
/templates/cache
Expand Down
1 change: 1 addition & 0 deletions js/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ $(window).ready(function() {
$(form).find('input[type="submit"]').removeAttr('disabled');
$(form).find('input[name="subject"],input[name="file_url"],\
textarea[name="body"],input[type="file"]').val('').change();
$('input[name^="files"]:not(:first-of-type),input[name^="files"]+br').remove();
},
cache: false,
contentType: false,
Expand Down
13 changes: 2 additions & 11 deletions js/multi-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@

function multi_image() {
$('input[type=file]').after('<a href="#" class="add_image">+</a>');

$(document).on('click', 'a.add_image', function(e) {
e.preventDefault();

var images_len = $('form:not([id="quick-reply"]) [type=file]').length;

if (!(images_len >= max_images)) {
var new_file = '<br class="file_separator"/><input type="file" name="file'+(images_len+1)+'" id="upload_file'+(images_len+1)+'">';

$('[type=file]:last').after(new_file);
if ($("#quick-reply").length) {
$('form:not(#quick-reply) [type=file]:last').after(new_file);
}
if (!($('form:not(#quick-reply) [type=file]').length >= max_images)) {
$('a.add_image').before('<br><input type="file" name="files[]">');
if (typeof setup_form !== 'undefined') setup_form($('form[name="post"]'));
}
})
Expand Down
16 changes: 7 additions & 9 deletions js/upload-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ $(function(){
var enabled_oekaki = typeof window.oekaki != "undefined";

var disable_all = function() {
$("#upload").hide();
$("[id^=upload_file]").hide();
$(".file_separator").hide();
$("#upload_url").hide();
$("#upload_embed").hide();
$(".add_image").hide();
$('#upload').hide();
$('input[name^="files"],input[name^="files"]+br').hide();
$('#upload_url').hide();
$('#upload_embed').hide();
$('.add_image').hide();

$('[id^=upload_file]').each(function(i, v) {
$('[name^="files"]').each(function(i, v) {
$(v).val('');
});

Expand All @@ -40,8 +39,7 @@ $(function(){
enable_file = function() {
disable_all();
$("#upload").show();
$(".file_separator").show();
$("[id^=upload_file]").show();
$('input[name^="files"],input[name^="files"]+br').show();
$(".add_image").show();
};

Expand Down
22 changes: 21 additions & 1 deletion post.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ function strip_array($var) {
error($config['error']['bot']);

$post = array('board' => $_POST['board'], 'files' => array());

// Normalize files list
$_FILES = array_map(function(&$file_post) {
$file_array = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_array[$i][$key] = $file_post[$key][$i];
}
}
return $file_array;
},$_FILES)['files'];

// Check if board exists
if (!openBoard($post['board']))
Expand Down Expand Up @@ -375,7 +388,14 @@ function unlink_tmp_file($file) {
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
$post['body'] = $_POST['body'];
$post['password'] = $_POST['password'];
$post['has_file'] = (!isset($post['embed']) && (($post['op'] && !isset($post['no_longer_require_an_image_for_op']) && $config['force_image_op']) || !empty($_FILES['file']['name'])));
$has_a_file = false;
foreach ($_FILES as $key => $file) {
if ($file['error'] == 0) {
$has_a_file = true;
break;
}
}
$post['has_file'] = (!isset($post['embed']) && (($post['op'] && !isset($post['no_longer_require_an_image_for_op']) && $config['force_image_op']) || $has_a_file));

if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) {
$stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']);
Expand Down
2 changes: 1 addition & 1 deletion templates/post_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
{% trans %}File{% endtrans %}
</th>
<td>
<input type="file" name="file" id="upload_file">
<input type="file" name="files[]">
{% 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>:
Expand Down