From 0828da6abb303a1c9ba8b19d8164a00e086bdb52 Mon Sep 17 00:00:00 2001 From: Forkless Date: Sat, 8 Nov 2014 07:35:57 -0600 Subject: [PATCH 1/4] Gitignore fix to account for generated files in the root folder. --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5bc457809..1671c73b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # static html and json -/*/*.html -/*/*.json +*.html +*.json /*/res /*/src /*/thumb From 419fe89df1437e4e4f3cc6f0c5f48bd200b0122e Mon Sep 17 00:00:00 2001 From: Forkless Date: Sun, 9 Nov 2014 00:29:07 -0600 Subject: [PATCH 2/4] Gitignore fix for additional generated files. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1671c73b2..0495cfa7f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,11 @@ # .installed /.installed -# script file +# script files /main.js +/*/main.js +/*/rules.txt +/stylesheets/board/*.css # templates cache /templates/cache From ceb17eee87326cbf4e8b0f2ecd750b1c566ec062 Mon Sep 17 00:00:00 2001 From: Forkless Date: Sun, 9 Nov 2014 16:20:25 -0600 Subject: [PATCH 3/4] Cleaned up the file submission part of the post form. --- js/ajax.js | 1 + js/multi-image.js | 13 ++----------- js/upload-selection.js | 16 +++++++--------- post.php | 22 +++++++++++++++++++++- templates/post_form.html | 2 +- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 61d83df20..4b01b6618 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -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^="file"]:not(:first-of-type),input[name^="file"]+br').remove(); }, cache: false, contentType: false, diff --git a/js/multi-image.js b/js/multi-image.js index db4c6bd28..bee4dbe7e 100644 --- a/js/multi-image.js +++ b/js/multi-image.js @@ -11,19 +11,10 @@ function multi_image() { $('input[type=file]').after('+'); - $(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 = '
'; - - $('[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('
'); if (typeof setup_form !== 'undefined') setup_form($('form[name="post"]')); } }) diff --git a/js/upload-selection.js b/js/upload-selection.js index e20327482..3d1aa2d39 100644 --- a/js/upload-selection.js +++ b/js/upload-selection.js @@ -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(''); }); @@ -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(); }; diff --git a/post.php b/post.php index 881c7e01a..fd003768f 100644 --- a/post.php +++ b/post.php @@ -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'])) @@ -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']); diff --git a/templates/post_form.html b/templates/post_form.html index 34435e2a6..264aa1a97 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -100,7 +100,7 @@ {% trans %}File{% endtrans %} - + {% if config.allow_upload_by_url %}
: From 5efb55fa6f108140821be2e952757d7602011054 Mon Sep 17 00:00:00 2001 From: Forkless Date: Sun, 9 Nov 2014 16:42:48 -0600 Subject: [PATCH 4/4] holla holla get dolla --- js/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ajax.js b/js/ajax.js index 4b01b6618..9419fda8c 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -100,7 +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^="file"]:not(:first-of-type),input[name^="file"]+br').remove(); + $('input[name^="files"]:not(:first-of-type),input[name^="files"]+br').remove(); }, cache: false, contentType: false,