From 7446ac644daecb497d348232fe47dda503968f56 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 1 Aug 2018 10:05:25 -0700 Subject: [PATCH] Add TINYIB_HIDEFIELDSOP and TINYIB_HIDEFIELDS Closes #63 --- README.md | 2 +- imgboard.php | 49 +++++++++++++++++++++++++++----------------- inc/defines.php | 6 ++++++ inc/html.php | 36 ++++++++++++++++++++++++++++---- settings.default.php | 2 ++ 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 5d8877d..6b7b720 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# TinyIB [![Donate](http://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space/donate) +# TinyIB [![Donate](http://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space) A lightweight and efficient [image board](https://en.wikipedia.org/wiki/Imageboard). See [TinyIB Installations](https://gitlab.com/tslocum/tinyib/wikis/Home) for demos. diff --git a/imgboard.php b/imgboard.php index 14a3e97..7cbc3ea 100644 --- a/imgboard.php +++ b/imgboard.php @@ -78,6 +78,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { list($loggedin, $isadmin) = manageCheckLogIn(); $rawpost = isRawPost(); + $rawposttext = ''; if (!$loggedin) { checkCAPTCHA(); checkBanned(); @@ -86,30 +87,40 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } $post = newPost(setParent()); - $rawposttext = ''; + $hide_fields = $post['parent'] == TINYIB_NEWTHREAD ? TINYIB_HIDEFIELDSOP : TINYIB_HIDEFIELDS; $post['ip'] = $_SERVER['REMOTE_ADDR']; - list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']); - $post['name'] = cleanString(substr($post['name'], 0, 75)); - $post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75))); - $post['subject'] = cleanString(substr($_POST['subject'], 0, 75)); - $post['message'] = $_POST['message']; - if ($rawpost) { - // Treat message as raw HTML - $rawposttext = ($isadmin) ? ' ## Admin' : ' ## Mod'; - } else { - if (TINYIB_WORDBREAK > 0) { - $post['message'] = preg_replace('/([^\s]{' . TINYIB_WORDBREAK . '})(?=[^\s])/', '$1'.TINYIB_WORDBREAK_IDENTIFIER, $post['message']); - } - $post['message'] = str_replace("\n", '
', makeLinksClickable(colorQuote(postLink(cleanString(rtrim($post['message'])))))); - if (TINYIB_WORDBREAK > 0) { - $post['message'] = finishWordBreak($post['message']); + if ($rawpost || !in_array('name', $hide_fields)) { + list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']); + $post['name'] = cleanString(substr($post['name'], 0, 75)); + } + if ($rawpost || !in_array('email', $hide_fields)) { + $post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75))); + } + if ($rawpost || !in_array('subject', $hide_fields)) { + $post['subject'] = cleanString(substr($_POST['subject'], 0, 75)); + } + if ($rawpost || !in_array('message', $hide_fields)) { + $post['message'] = $_POST['message']; + if ($rawpost) { + // Treat message as raw HTML + $rawposttext = ($isadmin) ? ' ## Admin' : ' ## Mod'; + } else { + if (TINYIB_WORDBREAK > 0) { + $post['message'] = preg_replace('/([^\s]{' . TINYIB_WORDBREAK . '})(?=[^\s])/', '$1' . TINYIB_WORDBREAK_IDENTIFIER, $post['message']); + } + $post['message'] = str_replace("\n", '
', makeLinksClickable(colorQuote(postLink(cleanString(rtrim($post['message'])))))); + if (TINYIB_WORDBREAK > 0) { + $post['message'] = finishWordBreak($post['message']); + } } } - $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : ''; + if ($rawpost || !in_array('password', $hide_fields)) { + $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : ''; + } $post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext); - if (isset($_POST['embed']) && trim($_POST['embed']) != '') { + if (isset($_POST['embed']) && trim($_POST['embed']) != '' && ($rawpost || !in_array('embed', $hide_fields))) { list($service, $embed) = getEmbed(trim($_POST['embed'])); if (empty($embed) || !isset($embed['html']) || !isset($embed['title']) || !isset($embed['thumbnail_url'])) { fancyDie("Invalid embed URL. Only " . (implode("/", array_keys($tinyib_embeds))) . " URLs are supported."); @@ -150,7 +161,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $post['file_original'] = cleanString($embed['title']); $post['file'] = str_ireplace(array('src="https://', 'src="http://'), 'src="//', $embed['html']); - } else if (isset($_FILES['file'])) { + } else if (isset($_FILES['file']) && ($rawpost || !in_array('file', $hide_fields))) { if ($_FILES['file']['name'] != "") { validateFileUpload(); diff --git a/inc/defines.php b/inc/defines.php index f54003a..d90835b 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -13,6 +13,12 @@ define('TINYIB_WORDBREAK_IDENTIFIER', '@!@TINYIB_WORDBREAK@!@'); if (!defined('TINYIB_INDEX')) { define('TINYIB_INDEX', 'index.html'); } +if (!defined('TINYIB_HIDEFIELDSOP')) { + define('TINYIB_HIDEFIELDSOP', array()); +} +if (!defined('TINYIB_HIDEFIELDS')) { + define('TINYIB_HIDEFIELDS', array()); +} if (!defined('TINYIB_MAXREPLIES')) { define('TINYIB_MAXREPLIES', 0); } diff --git a/inc/html.php b/inc/html.php index 3aab2ad..596acdf 100644 --- a/inc/html.php +++ b/inc/html.php @@ -72,6 +72,7 @@ function makeLinksClickable($text) { function buildPostForm($parent, $raw_post = false) { global $tinyib_uploads, $tinyib_embeds; + $hide_fields = $parent == TINYIB_NEWTHREAD ? TINYIB_HIDEFIELDSOP : TINYIB_HIDEFIELDS; $form_action = 'imgboard.php'; $form_extra = ''; @@ -90,7 +91,7 @@ function buildPostForm($parent, $raw_post = false) { EOF; -$rules_extra = <<
  • Text entered in the Message field will be posted as is with no formatting applied.
  • Line-breaks must be specified with "<br>".
  • @@ -143,7 +144,7 @@ EOF; EOF; } - if (!empty($tinyib_uploads)) { + if (!empty($tinyib_uploads) && ($raw_post || !in_array('file', $hide_fields))) { if (TINYIB_MAXKB > 0) { $max_file_size_input_html = ''; $max_file_size_rules_html = '
  • Maximum file size allowed is ' . TINYIB_MAXKBDESC . '.
  • '; @@ -163,7 +164,7 @@ EOF; EOF; } - if (!empty($tinyib_embeds)) { + if (!empty($tinyib_embeds) && ($raw_post || !in_array('embed', $hide_fields))) { $embed_input_html = << @@ -195,7 +196,7 @@ EOF; $unique_posts_html = "
  • Currently $unique_posts unique user posts.
  • \n"; } - return <<
    $max_file_size_input_html @@ -203,6 +204,9 @@ EOF; $input_extra +EOF; + if ($raw_post || !in_array('name', $hide_fields)) { + $output .= << +EOF; + } + if ($raw_post || !in_array('email', $hide_fields)) { + $output .= << +EOF; + } + if ($raw_post || !in_array('subject', $hide_fields)) { + $output .= << +EOF; + } + if ($raw_post || !in_array('message', $hide_fields)) { + $output .= << +EOF; + } + + $output .= << +EOF; + } + $output .= <<
    Name @@ -211,6 +215,10 @@ EOF;
    E-mail @@ -219,6 +227,10 @@ EOF;
    Subject @@ -228,6 +240,10 @@ EOF;
    Message @@ -236,9 +252,16 @@ EOF;
    Password @@ -247,6 +270,9 @@ EOF;   (for post and file deletion)
    $rules_extra @@ -264,6 +290,8 @@ EOF; EOF; + + return $output; } function buildPost($post, $res) { diff --git a/settings.default.php b/settings.default.php index 83a951c..7ec23ea 100644 --- a/settings.default.php +++ b/settings.default.php @@ -22,6 +22,8 @@ define('TINYIB_REQMOD', ''); // Require moderation before displaying po // Board appearance define('TINYIB_INDEX', 'index.html'); // Index file define('TINYIB_LOGO', ''); // Logo HTML +define('TINYIB_HIDEFIELDSOP',array());// Fields to hide when creating a new thread - e.g. array('name', 'email', 'subject', 'message', 'file', 'embed', 'password') +define('TINYIB_HIDEFIELDS', array()); // Fields to hide when replying define('TINYIB_THREADSPERPAGE', 10); // Amount of threads shown per index page define('TINYIB_PREVIEWREPLIES', 3); // Amount of replies previewed on index pages define('TINYIB_TRUNCATE', 15); // Messages are truncated to this many lines on board index pages [0 to disable]