From 45f549482a0158008534f0862287962b51fd4cab Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 30 Apr 2021 23:12:19 -0700 Subject: [PATCH] Support regular expression keywords --- imgboard.php | 17 ++++++++++++++--- inc/functions.php | 8 ++++++++ inc/html.php | 8 +++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/imgboard.php b/imgboard.php index 409318f..7875889 100644 --- a/imgboard.php +++ b/imgboard.php @@ -860,13 +860,19 @@ EOF; $keyword['text'] = $_POST['text']; $keyword['action'] = $_POST['action']; + $kw = $keyword['text']; + + if (isset($_POST['regexp']) && $_POST['regexp'] == '1') { + $keyword['text'] = 'regexp:' . $keyword['text']; + } + insertKeyword($keyword); if ($_GET['keywords'] > 0) { - manageLogAction(sprintf(__('Updated keyword %s'), htmlentities($keyword['text']))); + manageLogAction(sprintf(__('Updated keyword %s'), htmlentities($kw))); $text .= manageInfo(__('Keyword updated.')); $_GET['keywords'] = 0; } else { - manageLogAction(sprintf(__('Updated keyword %s'), htmlentities($keyword['text']))); + manageLogAction(sprintf(__('Updated keyword %s'), htmlentities($kw))); $text .= manageInfo(__('Keyword added.')); } } elseif (isset($_GET['deletekeyword'])) { @@ -875,8 +881,13 @@ EOF; fancyDie(__('That keyword does not exist.')); } + $kw = $keyword['text']; + if (substr($keyword['text'], 0, 7) == 'regexp:') { + $kw = substr($keyword['text'], 7); + } + deleteKeyword($_GET['deletekeyword']); - manageLogAction(sprintf(__('Deleted keyword %s'), htmlentities($keyword['text']))); + manageLogAction(sprintf(__('Deleted keyword %s'), htmlentities($kw))); $text .= manageInfo(__('Keyword deleted.')); } diff --git a/inc/functions.php b/inc/functions.php index cd6c7a2..f97de87 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -311,6 +311,14 @@ function checkBanned() { function checkKeywords($text) { $keywords = allKeywords(); foreach ($keywords as $keyword) { + if (substr($keyword['text'], 0, 7) == 'regexp:') { + if (preg_match(substr($keyword['text'],7), $text)) { + $keyword['text'] = substr($keyword['text'],7); + return $keyword; + } + continue; + } + if (stripos($text, $keyword['text']) !== false) { return $keyword; } diff --git a/inc/html.php b/inc/html.php index 841cfb4..01dafe3 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1374,6 +1374,7 @@ function manageEditKeyword($id) { $v_text = ''; $v_action = ''; + $v_regexp_checked = ''; if ($id > 0) { $keyword = keywordByID($id); if (empty($keyword)) { @@ -1381,6 +1382,11 @@ function manageEditKeyword($id) { } $v_text = htmlentities($keyword['text'], ENT_QUOTES); $v_action = $keyword['action']; + + if (substr($v_text, 0, 7) == 'REGEXP:') { + $v_regexp_checked = 'selected'; + $v_text = substr($v_text, 7); + } } $txt_keyword = __('Keyword'); @@ -1392,7 +1398,7 @@ function manageEditKeyword($id) {
$txt_keywords -

+