From ed045259949aed75db2bc640553c9adfbff35661 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Thu, 8 Aug 2013 19:41:21 +0000 Subject: Spoil files moderator action --- inc/config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 8ca769bb..ea0300e0 100644 --- a/inc/config.php +++ b/inc/config.php @@ -954,6 +954,7 @@ $config['mod']['link_ban'] = '[B]'; $config['mod']['link_bandelete'] = '[B&D]'; $config['mod']['link_deletefile'] = '[F]'; + $config['mod']['link_spoilerimage'] = '[S]'; $config['mod']['link_deletebyip'] = '[D+]'; $config['mod']['link_deletebyip_global'] = '[D++]'; $config['mod']['link_sticky'] = '[Sticky]'; -- cgit v1.3 From 2018fd206bfcd69789c2f2ff7c034f7287cc3226 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Sun, 11 Aug 2013 13:54:11 +0000 Subject: Improve spoiler action Conflicts: inc/mod/pages.php --- inc/config.php | 2 ++ inc/mod/pages.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index ea0300e0..7bde3d6a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1093,6 +1093,8 @@ $config['mod']['bandelete'] = MOD; // Remove bans $config['mod']['unban'] = MOD; + // Spoiler file (and keep post) + $config['mod']['deletefile'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; // Delete all posts by IP diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 23b90aba..932b2ed6 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1371,7 +1371,15 @@ function mod_spoiler_image($board, $post) { error($config['error']['noaccess']); // Delete file - $query = prepare(sprintf("UPDATE `posts_%s` SET `thumb` = :thumb, `thumbwidth` = :thumbwidth, `thumbheight` = :thumbheight WHERE `id` = :id", $board)); + $query = prepare(sprintf("SELECT `thumb`, `thread` FROM ``posts_%s`` WHERE id = :id", $board)); + $query->bindValue(':id', $post, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $result = $query->fetch(PDO::FETCH_ASSOC); + + file_unlink($board . '/' . $config['dir']['thumb'] . $result['thumb']); + + // Make thumbnail spoiler + $query = prepare(sprintf("UPDATE ``posts_%s`` SET `thumb` = :thumb, `thumbwidth` = :thumbwidth, `thumbheight` = :thumbheight WHERE `id` = :id", $board)); $query->bindValue(':thumb', "spoiler"); $query->bindValue(':thumbwidth', 128, PDO::PARAM_INT); $query->bindValue(':thumbheight', 128, PDO::PARAM_INT); @@ -1380,7 +1388,10 @@ function mod_spoiler_image($board, $post) { // Record the action modLog("Spoilered file from post #{$post}"); - + + // Rebuild thread + buildThread($result['thread'] ? $result['thread'] : $post); + // Rebuild board buildIndex(); -- cgit v1.3 From d846fe63704e63d93cb65bbecacdd25febf2b9a5 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Sun, 11 Aug 2013 13:55:15 +0000 Subject: forgot to rename config option --- inc/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 7bde3d6a..7c7b6241 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1094,7 +1094,7 @@ // Remove bans $config['mod']['unban'] = MOD; // Spoiler file (and keep post) - $config['mod']['deletefile'] = JANITOR; + $config['mod']['spoilerfile'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; // Delete all posts by IP -- cgit v1.3 From 96122c3fc2a02f0eb957279b3887cd87b862f575 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 11 Aug 2013 17:22:39 -0400 Subject: fix notice for mod spoiler image --- inc/config.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 7c7b6241..2a9dbb78 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1097,6 +1097,8 @@ $config['mod']['spoilerfile'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; + // Spoiler image + $config['mod']['spoilerimage'] = JANITOR; // Delete all posts by IP $config['mod']['deletebyip'] = MOD; // Delete all posts by IP across all boards -- cgit v1.3 From 3a5f25f751173d354f4a4ff4b7371ca62691d11f Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 12 Aug 2013 13:00:06 +1000 Subject: what --- inc/config.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 2a9dbb78..049b59f0 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1093,8 +1093,6 @@ $config['mod']['bandelete'] = MOD; // Remove bans $config['mod']['unban'] = MOD; - // Spoiler file (and keep post) - $config['mod']['spoilerfile'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; // Spoiler image -- cgit v1.3 From 0f5f44bc95ac48aa9466a2c77f1e9e9b059b15f2 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 11 Aug 2013 17:34:43 -0400 Subject: spoilerimage config variable: this got fixed doubly, once wrong, merge both fixes Conflicts: inc/config.php --- inc/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 049b59f0..fd44e9a2 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1093,10 +1093,10 @@ $config['mod']['bandelete'] = MOD; // Remove bans $config['mod']['unban'] = MOD; + // Spoiler file (and keep post) + $config['mod']['spoilerimage'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; - // Spoiler image - $config['mod']['spoilerimage'] = JANITOR; // Delete all posts by IP $config['mod']['deletebyip'] = MOD; // Delete all posts by IP across all boards -- cgit v1.3 From adbb0c1fdfb41d0731de9079028ca79427de61e5 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 12 Aug 2013 13:01:34 +1000 Subject: ... --- inc/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index fd44e9a2..741db545 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1093,7 +1093,7 @@ $config['mod']['bandelete'] = MOD; // Remove bans $config['mod']['unban'] = MOD; - // Spoiler file (and keep post) + // Spoiler image $config['mod']['spoilerimage'] = JANITOR; // Delete file (and keep post) $config['mod']['deletefile'] = JANITOR; -- cgit v1.3 From a7a93ece3d96acb24c589662f49d28675c83c913 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 12 Aug 2013 22:14:26 +1000 Subject: $config['error']['invalidzip'] isn't used anywhere anymore --- inc/config.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 741db545..64fdba92 100644 --- a/inc/config.php +++ b/inc/config.php @@ -267,7 +267,8 @@ 'recaptcha_response_field', 'spoiler', 'quick-reply', - 'page' + 'page', + 'file_url', ); // Enable reCaptcha to make spam even harder. Rarely necessary. @@ -347,7 +348,10 @@ $config['markup_urls'] = true; // Optional URL prefix for links (eg. "http://anonym.to/?"). $config['link_prefix'] = ''; - + + // Allow "uploading" images via URL as well. Users can enter the URL of the image and then Tinyboard will + // download it. Not usually recommended. + $config['allow_upload_by_url'] = false; // A wordfilter (sometimes referred to as just a "filter" or "censor") automatically scans users’ posts // as they are submitted and changes or censors particular words or phrases. @@ -837,7 +841,6 @@ $config['error']['unknownext'] = _('Unknown file extension.'); $config['error']['filesize'] = _('Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes'); $config['error']['maxsize'] = _('The file was too big.'); - $config['error']['invalidzip'] = _('Invalid archive!'); $config['error']['fileexists'] = _('That file already exists!'); $config['error']['fileexistsinthread'] = _('That file already exists in this thread!'); $config['error']['delete_too_soon'] = _('You\'ll have to wait another %s before deleting that.'); -- cgit v1.3 From 0de0bc6ceb2c56256bf87724572055297dae76af Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Mon, 12 Aug 2013 22:51:46 +1000 Subject: Optional: Allow uploading by URL --- inc/config.php | 4 ++-- post.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- templates/main.js | 2 +- templates/post_form.html | 7 +++++++ 4 files changed, 54 insertions(+), 4 deletions(-) (limited to 'inc/config.php') diff --git a/inc/config.php b/inc/config.php index 64fdba92..4858274d 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1314,6 +1314,6 @@ // is the absolute maximum, because MySQL cannot handle table names greater than 64 characters. $config['board_regex'] = '[0-9a-zA-Z$_\x{0080}-\x{FFFF}]{1,58}'; - // Complex regular expression to catch URLs. - $config['url_regex'] = '/' . '(https?|ftp):\/\/' . '(([\w\-]+\.)+[a-zA-Z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' . '(:\d+)?' . '(\/([\w\-~.#\/?=&;:+%!*\[\]@$\'()+,|\^]+)?)?' . '/'; + // Regex for URLs. + $config['url_regex'] = '@^(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))$@'; diff --git a/post.php b/post.php index 074aa0dc..cfec5430 100644 --- a/post.php +++ b/post.php @@ -268,6 +268,46 @@ 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 (!preg_match($config['url_regex'], $post['file_url'])) + error($config['error']['invalidimg']); + + + $post['extension'] = strtolower(mb_substr($post['file_url'], mb_strrpos($post['file_url'], '.') + 1)); + if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files'])) + error($config['error']['unknownext']); + + $post['file_tmp'] = tempnam($config['tmp'], 'url'); + register_shutdown_function('unlink', $post['file_tmp']); + + $fp = fopen($post['file_tmp'], 'w'); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $post['file_url']); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_USERAGENT, 'Tinyboard'); + curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); + curl_setopt($curl, CURLOPT_FILE, $fp); + + if (curl_exec($curl) === false) + error($config['error']['nomove']); + + curl_close($curl); + + fclose($fp); + + $_FILES['file'] = array( + 'name' => basename($post['file_url']), + 'tmp_name' => $post['file_tmp'], + 'error' => 0, + 'size' => filesize($post['file_tmp']) + ); + } + // Check for a file if ($post['op'] && !isset($post['no_longer_require_an_image_for_op'])) { if (!isset($_FILES['file']['tmp_name']) || $_FILES['file']['tmp_name'] == '' && $config['force_image_op']) @@ -545,7 +585,10 @@ if (isset($_POST['delete'])) { } if (!isset($dont_copy_file) || !$dont_copy_file) { - if (!@move_uploaded_file($upload, $post['file'])) + if (isset($post['file_tmp'])) { + if (!@rename($upload, $post['file'])) + error($config['error']['nomove']); + } elseif (!@move_uploaded_file($upload, $post['file'])) error($config['error']['nomove']); } } diff --git a/templates/main.js b/templates/main.js index 71dcd92a..78054a3b 100644 --- a/templates/main.js +++ b/templates/main.js @@ -175,7 +175,7 @@ function dopost(form) { saved[document.location] = form.elements['body'].value; sessionStorage.body = JSON.stringify(saved); - return form.elements['body'].value != "" || form.elements['file'].value != ""; + return form.elements['body'].value != "" || form.elements['file'].value != "" || (form.elements.file_url && form.elements['file_url'].value != ""); } function citeReply(id) { diff --git a/templates/post_form.html b/templates/post_form.html index 4d7a37b7..7c8894c1 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -73,6 +73,13 @@ + {% if config.allow_upload_by_url %} +
+
+ : + +
+ {% endif %} {{ antibot.html() }} -- cgit v1.3