Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for search warnings, errors and addressing issue 114 #116

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/classes/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public function show() {
case "autocomplete":
$afterJS .= $this->autocompleteJS($componentInfo['options']['list'], $componentInfo['options']['real_id'], $componentInfo['options']['fake_id']);
$fakeComponentName = "fake".$componentName;
$displayForm .= "<input type='text' name='".$fakeComponentName."' value='".filterText($_POST[$fakeComponentName])."' ".$dispAttributes." id='".$componentInfo['options']['fake_id']."'><input type='hidden' name='".$componentName."' value='".($componentInfo['value'] ?? '')."' id='".$componentInfo['options']['real_id']."'>";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional to delete the hidden <input> here?

$fakeComponentValue = $_POST[$fakeComponentName] ?? '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$_POST[$fakeComponentName] is only used once, so I don't think we need the extra variable $fakeComponentValue. Instead we can just do $_POST[$fakeComponentName] ?? ''

$displayForm .= "<input type='text' name='".$fakeComponentName."' value='".filterText($fakeComponentValue)."' ".$dispAttributes." id='".$componentInfo['options']['fake_id']."'>";
break;
case "textarea":
$displayForm .= "<textarea name='".$componentName."' ".$dispAttributes.">".$componentInfo['value']."</textarea>";
Expand Down
12 changes: 7 additions & 5 deletions src/forum/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
$breadcrumbObj->addCrumb("Search Forum");

if (count($_GET) > 0) {
$_POST['fakesearchuser'] = $_GET['searchuser'];
$_POST['fakesearchuser'] = $_GET['searchuser'] ?? '';
$_POST['checkCSRF'] = $_SESSION['csrfKey'];
$_POST['submit'] = true;
$_POST['filtertopics_replies'] = 0;
Expand All @@ -63,7 +63,7 @@
$_POST['sortresults'] = 0;
$_POST['sortresults_ascdesc'] = 0;

if (count($_GET['filterboards']) == 0) {
if (count($_GET['filterboards'] ?? []) == 0) {
$_POST['filterboards'][] = 0;
}

Expand Down Expand Up @@ -122,9 +122,11 @@ function check_filter_boards() {
global $boardObj, $formObj;

$countErrors = 0;
foreach ($_POST['filterboards'] as $value) {
if (!$boardObj->select($value) && $value != 0) {
$countErrors++;
if (isset($_POST['filterboards']) && is_array($_POST['filterboards'])) {
foreach ($_POST['filterboards'] as $value) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of line 125 and for line 126 do foreach ($_POST['filterboards'] ?? [] as $value) {. Should accomplish the same thing with less code :)

if (!$boardObj->select($value) && $value != 0) {
$countErrors++;
}
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/forum/search_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
if (trim($_POST['keyword']) != "") {
$_POST['keyword'] = str_replace("%", "\%", $_POST['keyword']);

if ($_POST['filterkeyword'] == 0) {
if (($_POST['filterkeyword'] ?? 0) == 0) {
$filterKeyword = array("message" => $_POST['keyword'], "title" => $_POST['keyword']);

$filterResults[] = " (".$postTable.".message LIKE '%".$mysqli->real_escape_string($_POST['keyword'])."%' OR ".$postTable.".title LIKE '%".$mysqli->real_escape_string($_POST['keyword'])."%') ";
Expand All @@ -88,18 +88,18 @@
// Filter By Username
$filterByUsername = "";
$memberIDList = array();
if (trim($_POST['fakesearchuser']) != "") {
$_POST['fakesearchuser'] = str_replace("*", "%", $_POST['fakesearchuser']);
if (trim($_POST['fakesearchuser'] ?? '') != "") {
$_POST['fakesearchuser'] = str_replace("*", "%", $_POST['fakesearchuser']);

$memberList = $member->get_entries(array("username" => $_POST['fakesearchuser']), "username", true, array("username" => "Like"));
$memberIDList = array();
$memberList = $member->get_entries(array("username" => $_POST['fakesearchuser']), "username", true, array("username" => "Like"));
$memberIDList = array();

foreach ($memberList as $searchMemberInfo) {
$memberIDList[] = $searchMemberInfo['member_id'];
}

$memberListSQL = "('".implode("','", $memberIDList)."')";
$filterResults[] = " ".$postTable.".member_id IN ".$memberListSQL;
$memberListSQL = "('".implode("','", $memberIDList)."')";
$filterResults[] = " ".$postTable.".member_id IN ".$memberListSQL;

if ($_POST['filterusername'] == 1) {
$topicList = array();
Expand Down Expand Up @@ -146,16 +146,18 @@

// Filter Board
$arrFilterBoards = array();
if (!in_array(0, $_POST['filterboards'])) {
$arrFilterBoards = $_POST['filterboards'];
$filterBoards = $_POST['filterboards'] ?? []; // Use null coalescing operator to provide a default empty array

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment needed here. Since it is just saying the same thing as the code.


if (!in_array(0, $filterBoards)) {
$arrFilterBoards = $filterBoards;

if ($_POST['include_subforums'] == 1) {
foreach ($_POST['filterboards'] as $value) {
foreach ($filterBoards as $value) {
$boardObj->select($value);
$arrFilterBoards = array_merge($arrFilterBoards, $boardObj->getAllSubForums());
}

$arrFilterBoards = array_unique($arrFilterBoards);
$arrFilterBoards = array_unique($arrFilterBoards);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should delete 1 tab to fix indenting

}
}

Expand Down
33 changes: 19 additions & 14 deletions src/forum/templates/searchform.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,30 @@
}

echo "

<div class='formDiv' style='border: 0px; background: none; overflow: auto'>

<div class='formDiv' style='border: 0px; background: none; overflow: auto'>
<form id='forumSearchForm' action='".$MAIN_ROOT."forum/search.php' method='get'>
<div class='largeFont' style='float: right'>
<b>".$searchLabel.":</b> <input type='text' class='textBox' id='searchTerm'> <input type='button' class='submitButton' id='btnSearchForum' ".$setFilterTopic.$setFilterBoard." style='padding: 3px 8px' value='GO'>
<b>".$searchLabel.":</b>
<input type='text' class='textBox' name='keyword' id='searchTerm'>
<input type='submit' class='submitButton' style='padding: 3px 8px' value='GO'>
<br><span class='tinyFont'><a href='".$MAIN_ROOT."forum/search.php'>Advanced Search</a></span>
</div>
</div>

<script type='text/javascript'>

$(document).ready(function() {
".$addToURL."
</form>
</div>

<script type='text/javascript'>

$(document).ready(function() {

$('#btnSearchForum').click(function() {

window.location = '".$MAIN_ROOT."forum/search.php?keyword='+$('#searchTerm').val()+'".$addToURL."';

});

window.location = '".$MAIN_ROOT."forum/search.php?keyword='+$('#searchTerm').val()+'".$addToURL."';

});

</script>

});

</script>
";
Loading