Fix bug in search relating to group names with special characters.

This commit is contained in:
Retro_Guy 2023-12-28 17:39:02 -07:00
parent 98cacd2682
commit 3b5f153113
1 changed files with 20 additions and 13 deletions

View File

@ -11,6 +11,13 @@ include "newsportal.php";
$snippet_size = 100; $snippet_size = 100;
if (isset($_GET['group'])) {
$search_group = urldecode($_GET['group']);
}
if (isset($_POST['group'])) {
$search_group = urldecode($_POST['group']);
}
if (isset($_REQUEST['data']) && $_REQUEST['data'] == '') { if (isset($_REQUEST['data']) && $_REQUEST['data'] == '') {
unset($_REQUEST['data']); unset($_REQUEST['data']);
} }
@ -28,8 +35,8 @@ if ((! isset($_POST['key']) || ! password_verify($CONFIG['thissitekey'], $_POST[
echo '<a href="' . $file_index . '" target=' . $frame['menu'] . '>' . basename(getcwd()) . '</a> / '; echo '<a href="' . $file_index . '" target=' . $frame['menu'] . '>' . basename(getcwd()) . '</a> / ';
echo 'search</h1>'; echo 'search</h1>';
echo '<table cellpadding="0" cellspacing="0" class="np_buttonbar"><tr>'; echo '<table cellpadding="0" cellspacing="0" class="np_buttonbar"><tr>';
if (isset($_GET['group'])) { if (isset($search_group)) {
$searching = $_GET['group']; $searching = $search_group;
} else { } else {
$searching = $config_name; $searching = $config_name;
} }
@ -74,8 +81,8 @@ if ((! isset($_POST['key']) || ! password_verify($CONFIG['thissitekey'], $_POST[
echo '</td></tr>'; echo '</td></tr>';
echo '<tr>'; echo '<tr>';
echo '<td><input name="command" type="hidden" id="command" value="Search" readonly="readonly"></td>'; echo '<td><input name="command" type="hidden" id="command" value="Search" readonly="readonly"></td>';
if (isset($_GET['group'])) { if (isset($search_group)) {
echo '<input type="hidden" name="group" value="' . $_GET['group'] . '">'; echo '<input type="hidden" name="group" value="' . $search_group . '">';
} }
echo '<input type="hidden" name="key" value="' . password_hash($CONFIG['thissitekey'], PASSWORD_DEFAULT) . '">'; echo '<input type="hidden" name="key" value="' . password_hash($CONFIG['thissitekey'], PASSWORD_DEFAULT) . '">';
if (isset($_GET['data'])) { if (isset($_GET['data'])) {
@ -154,16 +161,16 @@ if (isset($_COOKIE['tzo'])) {
$offset = $CONFIG['timezone']; $offset = $CONFIG['timezone'];
} }
$overview = array(); $overview = array();
if (! isset($group)) { if (trim($search_group = '')) {
$group = null; $search_group = null;
} }
if ($_POST['searchpoint'] == 'body') { if ($_POST['searchpoint'] == 'body') {
$overview = get_body_search($group, $_POST['terms']); $overview = get_body_search($search_group, $_POST['terms']);
} else { } else {
if (isset($_REQUEST['data'])) { if (isset($_REQUEST['data'])) {
$overview = get_header_search($group, base64_decode(urldecode($_REQUEST['data']))); $overview = get_header_search($search_group, base64_decode(urldecode($_REQUEST['data'])));
} else { } else {
$overview = get_header_search($group, $_POST['terms']); $overview = get_header_search($search_group, $_POST['terms']);
} }
} }
foreach ($overview as $overviewline) { foreach ($overview as $overviewline) {
@ -282,8 +289,8 @@ function get_body_search($group, $terms)
$terms = preg_replace('/"NOT"/', 'NOT', $terms); $terms = preg_replace('/"NOT"/', 'NOT', $terms);
$terms = '"' . $terms . '"'; $terms = '"' . $terms . '"';
} }
if (isset($_POST['group'])) { if ($group != '') {
$grouplist[0] = $_POST['group']; $grouplist[0] = $group;
} else { } else {
$local_groupfile = $spooldir . "/" . $config_name . "/local_groups.txt"; $local_groupfile = $spooldir . "/" . $config_name . "/local_groups.txt";
$grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
@ -318,8 +325,8 @@ function get_header_search($group, $terms)
GLOBAL $CONFIG, $config_name, $spooldir, $snippet_size; GLOBAL $CONFIG, $config_name, $spooldir, $snippet_size;
$terms = preg_replace('/\%/', '\%', $terms); $terms = preg_replace('/\%/', '\%', $terms);
$searchterms = "%" . $terms . "%"; $searchterms = "%" . $terms . "%";
if (isset($_POST['group']) && $_POST['searchpoint'] != 'msgid') { if (isset($search_group) && $_POST['searchpoint'] != 'msgid') {
$grouplist[0] = $_POST['group']; $grouplist[0] = $search_group;
} elseif ($_POST['searchpoint'] != 'msgid') { } elseif ($_POST['searchpoint'] != 'msgid') {
$local_groupfile = $spooldir . "/" . $config_name . "/local_groups.txt"; $local_groupfile = $spooldir . "/" . $config_name . "/local_groups.txt";
$grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $grouplist = file($local_groupfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);