Browse Source

Support regular expression keywords

shortcut
Trevor Slocum 1 year ago
parent
commit
45f549482a
  1. 17
      imgboard.php
  2. 8
      inc/functions.php
  3. 8
      inc/html.php

17
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.'));
}

8
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;
}

8
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) {
<form id="tinyib" name="tinyib" method="post" action="?manage&keywords=$id">
<fieldset>
<legend>$txt_keywords</legend>
<div valign="top"><label for="keyword">$txt_keyword</label> <input type="text" name="text" id="text" value="$v_text"><br>
<div valign="top"><label for="keyword">$txt_keyword</label> <input type="text" name="text" id="text" value="$v_text"> <label for="regexp">&nbsp; <input type="checkbox" name="regexp" value="1" $v_regexp_checked> Regular expression</label><br>
<label for="action">$txt_action</label>
<select name="action">
EOF;

Loading…
Cancel
Save