From c8d4d2c4c18980cbbe9a50913605bb4cb541afae Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Tue, 24 Jul 2018 16:46:58 -0700 Subject: [PATCH] Add TINYIB_WORDBREAK - resolves #60 --- imgboard.php | 16 +++++++++++----- inc/defines.php | 4 ++++ inc/functions.php | 16 ++++++++++++---- inc/html.php | 2 +- settings.default.php | 1 + 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/imgboard.php b/imgboard.php index d4b0c3a..14a3e97 100644 --- a/imgboard.php +++ b/imgboard.php @@ -86,19 +86,25 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } $post = newPost(setParent()); + $rawposttext = ''; + $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'; - $post['message'] = $_POST['message']; // Treat message as raw HTML } else { - $rawposttext = ''; - $post['message'] = str_replace("\n", '
', makeLinksClickable(colorQuote(postLink(cleanString(rtrim($_POST['message'])))))); + 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'])) : ''; $post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext); diff --git a/inc/defines.php b/inc/defines.php index 4b7f24b..f54003a 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -6,6 +6,7 @@ if (!defined('TINYIB_BOARD')) { define('TINYIB_NEWTHREAD', '0'); define('TINYIB_INDEXPAGE', false); define('TINYIB_RESPAGE', true); +define('TINYIB_WORDBREAK_IDENTIFIER', '@!@TINYIB_WORDBREAK@!@'); // The following are provided for backward compatibility and should not be relied upon // Copy new settings from settings.default.php to settings.php @@ -36,6 +37,9 @@ if (!defined('TINYIB_REQMOD')) { if (!defined('TINYIB_ALWAYSNOKO')) { define('TINYIB_ALWAYSNOKO', false); } +if (!defined('TINYIB_WORDBREAK')) { + define('TINYIB_WORDBREAK', 0); +} if (!defined('TINYIB_TIMEZONE')) { define('TINYIB_TIMEZONE', ''); } diff --git a/inc/functions.php b/inc/functions.php index c593835..5798295 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -35,7 +35,7 @@ if (TINYIB_DBMODE == 'pdo' && TINYIB_DBDRIVER == 'pgsql') { CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("bumped"); CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("stickied"); CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("moderated");'; - + $bans_sql = 'CREATE TABLE "' . TINYIB_DBBANS . '" ( "id" bigserial NOT NULL, "ip" varchar(39) NOT NULL, @@ -77,7 +77,7 @@ if (TINYIB_DBMODE == 'pdo' && TINYIB_DBDRIVER == 'pgsql') { KEY `stickied` (`stickied`), KEY `moderated` (`moderated`) )"; - + $bans_sql = "CREATE TABLE `" . TINYIB_DBBANS . "` ( `id` mediumint(7) unsigned NOT NULL auto_increment, `ip` varchar(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, @@ -90,8 +90,8 @@ if (TINYIB_DBMODE == 'pdo' && TINYIB_DBDRIVER == 'pgsql') { } function cleanString($string) { - $search = array("<", ">"); - $replace = array("<", ">"); + $search = array("&", "<", ">"); + $replace = array("&", "<", ">"); return str_replace($search, $replace, $string); } @@ -249,6 +249,14 @@ function postLink($message) { return preg_replace_callback('/>>([0-9]+)/', '_postLink', $message); } +function _finishWordBreak($matches) { + return '' . str_replace(TINYIB_WORDBREAK_IDENTIFIER, '
', $matches[4]) . ''; +} + +function finishWordBreak($message) { + return str_replace(TINYIB_WORDBREAK_IDENTIFIER, '
', preg_replace_callback('/(.*?)<\/a>/', '_finishWordBreak', $message)); +} + function colorQuote($message) { if (substr($message, -1, 1) != "\n") { $message .= "\n"; diff --git a/inc/html.php b/inc/html.php index 2a58281..3aab2ad 100644 --- a/inc/html.php +++ b/inc/html.php @@ -74,7 +74,7 @@ function buildPostForm($parent, $raw_post = false) { global $tinyib_uploads, $tinyib_embeds; $form_action = 'imgboard.php'; - $form_extra = ''; + $form_extra = ''; $input_extra = ''; $rules_extra = ''; if ($raw_post) { diff --git a/settings.default.php b/settings.default.php index 3a7836e..83a951c 100644 --- a/settings.default.php +++ b/settings.default.php @@ -25,6 +25,7 @@ define('TINYIB_LOGO', ''); // Logo HTML 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] +define('TINYIB_WORDBREAK', 80); // Words longer than this many characters will be broken apart [0 to disable] define('TINYIB_TIMEZONE', 'UTC'); // See https://secure.php.net/manual/en/timezones.php - e.g. America/Los_Angeles // Post control