From 77da46c424b6d8d040e4bce3cc98430ba456e510 Mon Sep 17 00:00:00 2001 From: discomrade Date: Tue, 28 Sep 2021 03:09:18 +0000 Subject: [PATCH] Remove newlines and modifiers from thread title Parts sampled from NPFchan --- inc/functions.php | 15 +++++++++++++++ inc/lib/Twig/Extensions/Extension/Tinyboard.php | 2 ++ templates/thread.html | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/inc/functions.php b/inc/functions.php index 5565d951..44712b16 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1914,6 +1914,10 @@ function unicodify($body) { return $body; } +function newline_to_full_stop($body) { + return str_replace("\n", '. ', $body); +} + function extract_modifiers($body) { $modifiers = array(); @@ -1928,6 +1932,17 @@ function extract_modifiers($body) { return $modifiers; } +function remove_markup($body) { + global $config; + + foreach ($config['markup'] as $markup) { + if (is_string($markup[1])) + $body = preg_replace($markup[0], "$1", $body); + } + return $body; +} + + function remove_modifiers($body) { return preg_replace('@(.+?)@usm', '', $body); } diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 3d964c71..97fecb20 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -18,6 +18,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension new Twig_SimpleFilter('sprintf', 'sprintf'), new Twig_SimpleFilter('capcode', 'capcode'), new Twig_SimpleFilter('remove_modifiers', 'remove_modifiers'), + new Twig_SimpleFilter('remove_markup', 'remove_markup'), + new Twig_SimpleFilter('newline_to_full_stop', 'newline_to_full_stop'), new Twig_SimpleFilter('hasPermission', 'twig_hasPermission_filter'), new Twig_SimpleFilter('date', 'twig_date_filter'), new Twig_SimpleFilter('poster_id', 'poster_id'), diff --git a/templates/thread.html b/templates/thread.html index 95a893a8..8ae2a21e 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -13,7 +13,7 @@ {% include 'header.html' %} - {% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup[:256]|remove_modifiers|e }}{% endif %}{% endset %} + {% set meta_subject %}{% if config.thread_subject_in_title and thread.subject %}{{ thread.subject|e }}{% else %}{{ thread.body_nomarkup[:256]|remove_modifiers|newline_to_full_stop|remove_markup|e }}{% endif %}{% endset %}