LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

commit e99670628d3bc2214a01d7aa0f9f8801f3425ba7
parent 6a1dea2581a17102971aae7b833138b49efe816c
Author: davidovski <david@davidovski.xyz>
Date: Sat, 9 Sep 2023 14:28:04 +0100

Use languages list to generate dropdown in settings

Diffstat:
Msettings.php | 21+++++++++++++++++----

1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/settings.php b/settings.php
@@ -1,6 +1,5 @@
 <?php
         require "misc/search_engine.php";
-        $opts = load_opts();
 
         // Reset all cookies when resetting, or before saving new cookies
         if (isset($_REQUEST["reset"]) || isset($_REQUEST["save"])) {
@@ -29,6 +28,8 @@
             die();
         }
 
+        $opts = load_opts();
+
         require "misc/header.php";
 ?>
 
@@ -59,7 +60,7 @@
                     <option value=\"ubuntu\">Ubuntu</option>
                     <option value=\"tokyo_night\">Tokyo night</option>";
 
-                    if (isset($_COOKIE["theme"])) {
+                    if (isset($opts->theme)) {
                         $theme = $opts->theme;
                         $themes = str_replace($theme . "\"", $theme . "\" selected", $themes);
                     }
@@ -97,10 +98,22 @@
                 <div class="settings-textbox-container">
                     <div>
                         <span>Language</span>
+                        <select name="language">
                         <?php
-                            // TODO make this a dropdown
-                            echo "<input type=\"text\" name=\"language\" placeholder=\"any\" value=\"" . htmlspecialchars($opts->language ?? "") . "\">";
+
+                           $languages = json_decode(file_get_contents("static/misc/languages.json"), true);
+                           $options = "";
+
+                           $options .= "<option value=\"\" " . (!isset($opts->language) ? "selected" : "") . ">Any</option>";
+
+                           foreach ($languages as $lang_code => $language) {
+                               $name = $language["name"];
+                               $selected = $opts->language == $lang_code ? "selected" : "";
+                               $options .= "<option value=\"$lang_code\" $selected>$name</option>";
+                           }
+                           echo $options;
                         ?>
+                        </select>
                     </div>
                     <div>
                         <label>Number of results per page</label>