Fix checkboxes not unchecking when saving

This commit is contained in:
davidovski 2023-08-06 13:27:40 +01:00
parent ff1db195d1
commit b0f449671d
2 changed files with 11 additions and 7 deletions

View File

@ -8,7 +8,7 @@
$results = array();
$domain = $config->google_domain;
$disable_automatic_redirection = isset($_COOKIE["disable_automatic_redirection"]);
$automatic_redirection = isset($_COOKIE["automatic_redirection"]);
$site_language = isset($_COOKIE["google_language_site"]) ? trim(htmlspecialchars($_COOKIE["google_language_site"])) : $config->google_language_site;
$results_language = isset($_COOKIE["google_language_results"]) ? trim(htmlspecialchars($_COOKIE["google_language_results"])) : $config->google_language_results;
$number_of_results = isset($_COOKIE["google_number_of_results"]) ? trim(htmlspecialchars($_COOKIE["google_number_of_results"])) : $config->google_number_of_results;
@ -72,13 +72,16 @@
curl_multi_exec($mh, $running);
} while ($running);
if (!$disabled_automatic_redirection
&& $config->automatic_redirection
&& curl_getinfo($google_ch)['http_code'] == '302') {
if (curl_getinfo($google_ch)['http_code'] != '200') {
if ($automatic_redirection
&& $config->automatic_redirection) {
$instances_json = json_decode(file_get_contents("instances.json"), true);
$instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));
header("Location: " . $instances[array_rand($instances)] . "search.php?q=$query");
die();
} else {
return $results;
}
}

View File

@ -1,7 +1,8 @@
<?php
$config = require "config.php";
if (isset($_REQUEST["reset"]))
// Reset all cookies when resetting, or before saving new cookies
if (isset($_REQUEST["reset"]) || isset($_REQUEST["save"]))
{
if (isset($_SERVER["HTTP_COOKIE"]))
{
@ -105,8 +106,8 @@
<div class="settings-textbox-container">
<?php if ($config->automatic_redirection) : ?>
<div>
<label>disable automatic redirection</label>
<input type="checkbox" name="disable_automatic_redirection" <?php echo isset($_COOKIE["disable_automatic_redirection"]) ? "checked" : ""; ?> >
<label>Redirect to other instances if this one doesn't work</label>
<input type="checkbox" name="automatic_redirection" <?php echo isset($_COOKIE["automatic_redirection"]) ? "checked" : ""; ?> >
</div>
<?php endif; ?>