From 13ca4b6a77e8c2c5784ace54a1f6557bb5cd4531 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Thu, 12 Mar 2015 10:57:06 +0800 Subject: [PATCH 01/21] Minimize post form width change on options toggle Added linebreaks before the hints in the Options row --- templates/post_form.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/post_form.html b/templates/post_form.html index 29c7f75d..6a28572d 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -154,17 +154,23 @@
+ {% trans %}Do not bump{% endtrans %} +
+ {% trans %}(you can also write sage in the email field){% endtrans %}
{% if config.spoiler_images %}
+ {% trans %}Spoiler images{% endtrans %} +
+ {% trans %}(this replaces the thumbnails of your images with question marks){% endtrans %}
{% endif %} {% if config.allow_no_country and config.country_flags %}
+ {% trans %}Hide country{% endtrans %} +
+ {% trans %}(this board displays your country when you post if this is unchecked){% endtrans %}
{% endif %} {% if mod %} From 2aeb4db98b7c673bb9f4592b451ea179695a3db4 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Thu, 12 Mar 2015 11:02:03 +0800 Subject: [PATCH 02/21] Added missing tag --- templates/post_form.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/post_form.html b/templates/post_form.html index 6a28572d..56632970 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -7,7 +7,7 @@ {% endif %} {% if mod %}{% endif %} - +
{% if not config.field_disable_name or (mod and post.mod|hasPermission(config.mod.bypass_field_disable, board.uri)) %} -
{% trans %}Name{% endtrans %} @@ -111,7 +111,8 @@
Confused? See the FAQ.
+
+ {% if config.user_flag %} @@ -222,7 +223,7 @@

-
+ From 26ce0158d86401546cc0c8035a42b9a97b0afcbc Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 15 Mar 2015 22:18:27 +0800 Subject: [PATCH 03/21] initial commit templates --- templates/post_form.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/post_form.html b/templates/post_form.html index 2f6f02d2..b5ef767d 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -91,6 +91,12 @@ +
+
+
Select/drop/paste files here
+
+
+
{% if config.allow_upload_by_url %}
: From 72898dbecf04185ecf21acd5693bac6b7418e435 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 15 Mar 2015 22:18:47 +0800 Subject: [PATCH 04/21] initial commit stylesheet --- stylesheets/style.css | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/stylesheets/style.css b/stylesheets/style.css index 52d02473..9941a1a3 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -1181,3 +1181,84 @@ div.mix { #youtube-size input { width: 50px; } + +input#upload_file { + display: none; +} +/* File selector */ +.dropzone { + color: #000; + cursor: default; + margin: auto; + padding: 0px 4px; + text-align: center; + min-height: 50px; + max-height: 140px; + transition: 0.2s; + background-color: rgba(200, 200, 200, 0.5); + overflow-y: auto; +} +.dropzone-wrap { + width: 100%; +} +.dropzone .file-hint { + color: rgba(0, 0, 0, 0.5); + cursor: pointer; + position: relative; + margin-bottom: 5px; + padding: 10px 0px; + top: 5px; + transition: 0.2s; + border: 2px dashed rgba(125, 125, 125, 0.4); +} +.file-hint:hover, .dropzone.dragover .file-hint { + color: rgba(0, 0, 0, 1); + border-color: rgba(125, 125, 125, 0.8); +} +.dropzone.dragover { + background-color: rgba(200, 200, 200, 1); +} +.dropzone .file-thumbs { + text-align: left; + width: 100%; +} +.dropzone .tmb-container { + padding: 3px; + overflow-x: hidden; + white-space: nowrap; +} +.dropzone .file-tmb { + height: 40px; + width: 70px; + cursor: pointer; + display: inline-block; + text-align: center; + background-color: rgba(187, 187, 187, 0.5); + background-size: cover; + background-position: center; +} +.dropzone .file-tmb span { + font-weight: 600; + position: relative; + top: 13px; +} +.dropzone .tmb-filename { + display: inline-block; + vertical-align: bottom; + bottom: 12px; + position: relative; + margin-left: 5px; +} +.dropzone .remove-btn { + cursor: pointer; + color: rgba(125, 125, 125, 0.5); + display: inline-block; + vertical-align: bottom; + bottom: 10px; + position: relative; + margin-right: 5px; + font-size: 20px +} +.dropzone .remove-btn:hover { + color: rgba(125, 125, 125, 1); +} From 6e054239e7545087929b9d78a76351c614627feb Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 15 Mar 2015 22:18:58 +0800 Subject: [PATCH 05/21] initial commit file-selector.js --- js/file-selector.js | 187 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 js/file-selector.js diff --git a/js/file-selector.js b/js/file-selector.js new file mode 100644 index 00000000..437e1d4a --- /dev/null +++ b/js/file-selector.js @@ -0,0 +1,187 @@ +/* + * file-selector.js - Add support for drag and drop file selection, and paste from clipbboard on supported browsers. + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/file-selector.js'; + */ + +onready(function () { + +// add options panel item +$(document).ready(function () { + if (window.Options && Options.get_tab('general')) { + Options.extend_tab('general', ''); + + $('#file-drag-drop>input').on('click', function() { + if ($('#file-drag-drop>input').is(':checked')) { + localStorage.file_dragdrop = 'true'; + } else { + localStorage.file_dragdrop = 'false'; + } + }); + + if (localStorage.file_dragdrop === 'undefined') localStorage.file_dragdrop = 'true'; + if (localStorage.file_dragdrop === 'true') $('#file-drag-drop>input').prop('checked', true); + } +}); + +// disabled by user, or incompatible browser. +// fallback to old +if (localStorage.file_dragdrop == 'false' || !(window.FileReader || window.File)) { + $('.dropzone-wrap').remove(); + $('#upload_file').show(); + + return; +} + +// multipost not enabled +if (typeof max_images == 'undefined') { + var max_images = 1; +} + +var files = []; + +function addFile(file) { + if (files.length == max_images) + return; + + files.push(file); + addThumb(file); +} + +function removeFile(file) { + files.splice(files.indexOf(file), 1); +} + +function getThumbElement(file) { + return $('.tmb-container').filter(function(){return($(this).data('file-ref')==file);}); +} + +function addThumb(file) { + + var fileName = (file.name.length < 24) ? file.name : file.name.substr(0, 22) + '…'; + var fileType = file.type.split('/')[0]; + var fileExt = file.type.split('/')[1]; + var $fileThumb; + + $('.file-thumbs').append($('
') + .addClass('tmb-container') + .data('file-ref', file) + .append( + $('
').addClass('remove-btn').html('✖'), + $('
').addClass('file-tmb'), + $('
').addClass('tmb-filename').html(fileName) + ) + ); + + if (fileType == 'image') { + // if image file, generate thumbnail + var reader = new FileReader(); + + reader.onloadend = function () { + var dataURL = reader.result; + var $fileThumb = getThumbElement(file).find('.file-tmb'); + $fileThumb.css('background-image', 'url('+ dataURL +')'); + }; + + reader.readAsDataURL(file); + } else { + $fileThumb = getThumbElement(file).find('.file-tmb'); + $fileThumb.html('' + fileExt.toUpperCase() + ''); + } +} + +$(document).on('ajax_before_post', function (e, formData) { + var i; + + for (i=0; i 0) key += i + 1; + formData.append(key, files[i]); + } + + // clear file queue and UI + files = []; + $('.file-thumbs').empty(); +}); + +var dragCounter = 0; +var dropHandlers = { + dragenter: function (e) { + e.stopPropagation(); + e.preventDefault(); + + if (dragCounter === 0) $(this).addClass('dragover'); + dragCounter++; + }, + dragover: function (e) { + // needed for webkit to work + e.stopPropagation(); + e.preventDefault(); + }, + dragleave: function (e) { + e.stopPropagation(); + e.preventDefault(); + + dragCounter--; + if (dragCounter === 0) $(this).removeClass('dragover'); + }, + drop: function (e) { + e.stopPropagation(); + e.preventDefault(); + + $(this).removeClass('dragover'); + dragCounter = 0; + + var fileList = e.originalEvent.dataTransfer.files; + for (var i=0; i'); + + $fileSelector.on('change', function (e) { + if (this.files.length > 0) { + for (var i=0; i Date: Sun, 15 Mar 2015 23:32:53 +0800 Subject: [PATCH 06/21] Run on index and thread Clear file queue after upload success corrected fallback detection --- js/file-selector.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/js/file-selector.js b/js/file-selector.js index 437e1d4a..c820db48 100644 --- a/js/file-selector.js +++ b/js/file-selector.js @@ -6,29 +6,28 @@ * $config['additional_javascript'][] = 'js/file-selector.js'; */ -onready(function () { +if (active_page == 'index' || active_page == 'thread') { +$(document).ready(function () { // add options panel item -$(document).ready(function () { - if (window.Options && Options.get_tab('general')) { - Options.extend_tab('general', ''); +if (window.Options && Options.get_tab('general')) { + Options.extend_tab('general', ''); - $('#file-drag-drop>input').on('click', function() { - if ($('#file-drag-drop>input').is(':checked')) { - localStorage.file_dragdrop = 'true'; - } else { - localStorage.file_dragdrop = 'false'; - } - }); + $('#file-drag-drop>input').on('click', function() { + if ($('#file-drag-drop>input').is(':checked')) { + localStorage.file_dragdrop = 'true'; + } else { + localStorage.file_dragdrop = 'false'; + } + }); - if (localStorage.file_dragdrop === 'undefined') localStorage.file_dragdrop = 'true'; - if (localStorage.file_dragdrop === 'true') $('#file-drag-drop>input').prop('checked', true); - } -}); + if (localStorage.file_dragdrop === 'undefined') localStorage.file_dragdrop = 'true'; + if (localStorage.file_dragdrop === 'true') $('#file-drag-drop>input').prop('checked', true); +} // disabled by user, or incompatible browser. // fallback to old -if (localStorage.file_dragdrop == 'false' || !(window.FileReader || window.File)) { +if (localStorage.file_dragdrop == 'false' || !(window.FileReader && window.File)) { $('.dropzone-wrap').remove(); $('#upload_file').show(); @@ -93,15 +92,15 @@ function addThumb(file) { } $(document).on('ajax_before_post', function (e, formData) { - var i; - - for (i=0; i 0) key += i + 1; formData.append(key, files[i]); } +}); - // clear file queue and UI +// clear file queue and UI on success +$(document).on('ajax_after_post', function () { files = []; $('.file-thumbs').empty(); }); @@ -185,3 +184,4 @@ $(document).on('paste', function (e) { }); }); +} From b073dc74a8fbea44e23bc9c2fa63ce20dc2a08b3 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Mon, 16 Mar 2015 22:36:26 +0800 Subject: [PATCH 07/21] post-filter.js: prevent extra space characters prevent extra spaces in comment caused by joining strings with leading or trailing space. --- js/post-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/post-filter.js b/js/post-filter.js index 518e38bb..8eb3ab7d 100644 --- a/js/post-filter.js +++ b/js/post-filter.js @@ -425,7 +425,7 @@ if (active_page === 'thread' || active_page === 'index' || active_page === 'cata array = $post.find('.body').contents().filter(function () {if ($(this).text() !== '') return true;}).toArray(); array = $.map(array, function (ele) { - return $(ele).text(); + return $(ele).text().trim(); }); comment = array.join(' '); From 6e35f12e3a7c99a18f2a09aed0e8fc679dc29b37 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Wed, 18 Mar 2015 18:44:47 +0800 Subject: [PATCH 08/21] Fallback for browsers that disables javascript --- js/file-selector.js | 3 ++- stylesheets/style.css | 3 --- templates/post_form.html | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/js/file-selector.js b/js/file-selector.js index c820db48..ddae2d09 100644 --- a/js/file-selector.js +++ b/js/file-selector.js @@ -140,7 +140,8 @@ var dropHandlers = { } }; -$('.dropzone').css('user-select', 'none') // let jquery add browser specific prefix +$('#upload input[type=file]').hide(); // hide the original file selector +$('.dropzone-wrap').css('user-select', 'none').show(); // let jquery add browser specific prefix // attach handlers $(document).on(dropHandlers, '.dropzone'); diff --git a/stylesheets/style.css b/stylesheets/style.css index 9941a1a3..8978780e 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -1182,9 +1182,6 @@ div.mix { width: 50px; } -input#upload_file { - display: none; -} /* File selector */ .dropzone { color: #000; diff --git a/templates/post_form.html b/templates/post_form.html index b5ef767d..f118f5aa 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -91,7 +91,7 @@ -
+ + {% if config.allow_upload_by_url %}
: From aa90f3b43b1eb33e403a133c98e81b0ad8ae7472 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 18 Mar 2015 19:27:47 -0700 Subject: [PATCH 10/21] Remove ReCAPTCHA from remaining pages --- create.php | 53 +++++++++---------------------------- dnsbls_bypass.php | 35 +++++++++++------------- templates/8chan/create.html | 5 ++-- templates/8chan/dnsbls.html | 1 + templates/mod/settings.html | 2 +- 5 files changed, 32 insertions(+), 64 deletions(-) diff --git a/create.php b/create.php index 59134bd8..309ac9eb 100644 --- a/create.php +++ b/create.php @@ -1,35 +1,17 @@ '._('Game').'' . $ayah->getPublisherHTML() . ''; -} - -if (!$cbRecaptcha){ - $recapcha_html = ''; -} else { - $recapcha_html = 'reCaptcha' . recaptcha_get_html($config['recaptcha_public'], NULL, TRUE) . ''; -} - +include '8chan-captcha/functions.php'; $password = base64_encode(openssl_random_pseudo_bytes(9)); -$body = Element("8chan/create.html", array("config" => $config, "password" => $password, "game_html" => $game_html, "recapcha_html" => $recapcha_html)); +$captcha = generate_captcha($config['captcha']['extra']); + +$body = Element("8chan/create.html", array("config" => $config, "password" => $password, "captcha" => $captcha)); echo Element("page.html", array("config" => $config, "body" => $body, "title" => _("Create your board"), "subtitle" => _("before someone else does"))); } @@ -41,26 +23,13 @@ $subtitle = $_POST['subtitle']; $username = $_POST['username']; $password = $_POST['password']; - $resp = ($cbRecaptcha) ? recaptcha_check_answer ($config['recaptcha_private'], - $_SERVER["REMOTE_ADDR"], - $_POST["recaptcha_challenge_field"], - $_POST["recaptcha_response_field"]):false; +$resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([ + 'mode' => 'check', + 'text' => $_POST['captcha_text'], + 'extra' => $config['captcha']['extra'], + 'cookie' => $_POST['captcha_cookie'] +])); -if ($resp != false){ -$passedCaptcha = $resp->is_valid; -} else { -$passedCaptcha = true; -} - -if (!$ayah){ -$score = true; -} else { -$score = $ayah->scoreResult(); -} -if (!$score) - error(_('You failed the game')); -if (!$passedCaptcha) - error(_('You failed to enter the reCaptcha correctly')); if (!preg_match('/^[a-z0-9]{1,30}$/', $uri)) error(_('Invalid URI')); if (!(strlen($title) < 40)) @@ -69,6 +38,8 @@ if (!(strlen($subtitle) < 200)) error(_('Invalid subtitle')); if (!preg_match('/^[a-zA-Z0-9._]{1,30}$/', $username)) error(_('Invalid username')); +if ($resp !== '1') + error($config['error']['captcha']); foreach (listBoards() as $i => $board) { if ($board['uri'] == $uri) diff --git a/dnsbls_bypass.php b/dnsbls_bypass.php index a37f1ca0..cf289b67 100644 --- a/dnsbls_bypass.php +++ b/dnsbls_bypass.php @@ -1,31 +1,26 @@ array('8.8.8.8'))); -$result = $dns->query(RECAPTCHA_VERIFY_SERVER, "A"); -if ($result and $result->answer[0]) { - $RECAPTCHA_VERIFY_SERVER_IP = $result->answer[0]->address; -} else { - $RECAPTCHA_VERIFY_SERVER_IP = RECAPTCHA_VERIFY_SERVER; -} +include '8chan-captcha/functions.php'; if ($_SERVER['REQUEST_METHOD'] === 'GET') { - $ayah_html = recaptcha_get_html($config['recaptcha_public'], NULL, TRUE); - $body = Element("8chan/dnsbls.html", array("config" => $config, "ayah_html" => $ayah_html)); + $captcha = generate_captcha($config['captcha']['extra']); + + $html = "{$captcha['html']}
+ +
"; + + $body = Element("8chan/dnsbls.html", array("config" => $config, "ayah_html" => $html)); echo Element("page.html", array("config" => $config, "body" => $body, "title" => _("Bypass DNSBL"), "subtitle" => _("Post even if blocked"))); } else { - $score = recaptcha_check_answer($config['recaptcha_private'], - $_SERVER["REMOTE_ADDR"], - $_POST["recaptcha_challenge_field"], - $_POST["recaptcha_response_field"], - array(), - $RECAPTCHA_VERIFY_SERVER_IP); + $resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([ + 'mode' => 'check', + 'text' => $_POST['captcha_text'], + 'extra' => $config['captcha']['extra'], + 'cookie' => $_POST['captcha_cookie'] + ])); - if ($score->is_valid) { + if ($resp === '1') { $tor = checkDNSBL($_SERVER['REMOTE_ADDR']); if (!$tor) { $query = prepare('INSERT INTO ``dnsbl_bypass`` VALUES(:ip, NOW()) ON DUPLICATE KEY UPDATE `created`=NOW()'); diff --git a/templates/8chan/create.html b/templates/8chan/create.html index b6470709..be0cf4b7 100644 --- a/templates/8chan/create.html +++ b/templates/8chan/create.html @@ -7,8 +7,9 @@ Subtitle {% trans %}(must be < 200 chars){% endtrans %} {% trans %}Username{% endtrans %} {% trans %}(must contain only alphanumeric, periods and underscores){% endtrans %} {% trans %}Password{% endtrans %} {% trans %}(write this down){% endtrans %} -{{ game_html }} -{{ recapcha_html }} +{% trans %}CAPTCHA{% endtrans %}{{ captcha['html'] }}
+ +
diff --git a/templates/8chan/dnsbls.html b/templates/8chan/dnsbls.html index 49c54efc..0e346a00 100644 --- a/templates/8chan/dnsbls.html +++ b/templates/8chan/dnsbls.html @@ -1,5 +1,6 @@

{% trans %}Your IP is listed in our DNSBL. To stop attackers, we require users who use certain IP ranges to pass a test which proves they are human every 24 hours.{% endtrans %}

+

{% trans %}Tor users need to fill out the CAPTCHA every 3 hours or 5 posts.{% endtrans %}

{% trans %}It is also possible that the site is currently under attack and we are requiring everyone to pass the test right now. Sorry for the inconvenience.{% endtrans %}

diff --git a/templates/mod/settings.html b/templates/mod/settings.html index 4c4a5cfa..c0f43ced 100644 --- a/templates/mod/settings.html +++ b/templates/mod/settings.html @@ -53,7 +53,7 @@ {% trans %}Public action log{% endtrans %}
{% trans %}Displays all actions to the public{% endtrans %}{% for i in range(2, 25) %}{% endfor %} {% trans %}Bump limit{% endtrans %} - {% trans %}Language{% endtrans %}
{% trans %}To contribute translations, register at Transifex{% endtrans %} + {% trans %}Language{% endtrans %}
{% trans %}Read this page for more information about contributing translations:
Translation tutorial or use Transifex{% endtrans %}
'); $fileSelector.on('change', function (e) { diff --git a/templates/post_form.html b/templates/post_form.html index 6db2ae13..5c642211 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -92,7 +92,7 @@ - + {% if config.allow_upload_by_url %}
: From 5c57bd44e1571988e976c177d82101ac51924fe2 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 19 Mar 2015 20:23:34 -0700 Subject: [PATCH 19/21] Suppress TypeError if no password form --- templates/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/main.js b/templates/main.js index f4be2c8c..77f5b9f4 100644 --- a/templates/main.js +++ b/templates/main.js @@ -336,7 +336,7 @@ function init() { {% endraw %} {% if config.allow_delete %} - if (document.forms.postcontrols) { + if (document.forms.postcontrols && document.forms.postcontrols.password) { document.forms.postcontrols.password.value = localStorage.password; } {% endif %} From e26cfbb889185d69275ab466070856f98f7cf219 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 19 Mar 2015 20:23:54 -0700 Subject: [PATCH 20/21] Make scroll event faster in auto-reload.js --- js/auto-reload.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/auto-reload.js b/js/auto-reload.js index a976a019..7340bf25 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -287,8 +287,6 @@ $(document).ready(function(){ }; $(window).scroll(function() { - recheck_activated(); - // if the newest post is not visible if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) { From e357e8b72c060ab795e0bae84249f94433662471 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 19 Mar 2015 20:34:54 -0700 Subject: [PATCH 21/21] ayylmao @marktaiwan --- js/file-selector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/file-selector.js b/js/file-selector.js index 687920d0..6a7e6773 100644 --- a/js/file-selector.js +++ b/js/file-selector.js @@ -147,7 +147,7 @@ $(document).on('keypress click', '.dropzone, .dropzone .file-hint', function (e) e.stopPropagation(); // accept mosue click or Enter - if (e.which != 1 || e.which != 13) + if (e.which != 1 && e.which != 13) return; var $fileSelector = $('');