Skip to content

Commit

Permalink
feat: add default theme config option (merge pull request #151 from d…
Browse files Browse the repository at this point in the history
…avidovski/default_theme)

Add default theme config option
  • Loading branch information
Ahwxorg authored Jun 9, 2024
2 parents edc288b + 894ff89 commit 7fe31b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"language" => "",
"number_of_results" => 10,

// The default theme css to use
"default_theme" => "dark",

// You can use any Invidious instance here
"invidious_instance_for_video_results" => "https://invidious.snopyta.org",

Expand Down
6 changes: 4 additions & 2 deletions misc/header.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php require_once "locale/localization.php"; ?>
<?php require_once "locale/localization.php";
$GLOBALS["opts"] = require_once "config.php";
?>
<!DOCTYPE html >
<html lang="en">
<head>
Expand All @@ -9,6 +11,6 @@
<link rel="stylesheet" type="text/css" href="static/css/styles.css"/>
<link title="<?php printtext("page_title"); ?>" type="application/opensearchdescription+xml" href="opensearch.xml?method=POST" rel="search"/>
<link rel="stylesheet" type="text/css" href="<?php
$theme = $_REQUEST["theme"] ?? trim(htmlspecialchars($_COOKIE["theme"] ?? "amoled"));
$theme = $_REQUEST["theme"] ?? trim(htmlspecialchars($_COOKIE["theme"] ?? $GLOBALS["opts"]->default_theme ?? "dark"));
echo "static/css/" . $theme . ".css";
?>"/>
7 changes: 5 additions & 2 deletions misc/search_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public static function print_results($results, $opts) {}
}

function load_opts() {
$opts = require_once "config.php";
if (isset($GLOBALS["opts"]))
$opts = $GLOBALS["opts"];
else
$opts = require_once "config.php";

# account for the old, misspelled options
if (isset($opts->disable_bittorent_search))
Expand All @@ -76,7 +79,7 @@ function load_opts() {
$opts->type = (int) ($_REQUEST["t"] ?? 0);
$opts->page = (int) ($_REQUEST["p"] ?? 0);

$opts->theme = $_REQUEST["theme"] ?? trim(htmlspecialchars($_COOKIE["theme"] ?? "amoled"));
$opts->theme = $_REQUEST["theme"] ?? trim(htmlspecialchars($_COOKIE["theme"] ?? $opts->default_theme ?? "dark"));

$opts->safe_search = (int) ($_REQUEST["safe"] ?? 0) == 1 || isset($_COOKIE["safe_search"]);

Expand Down
13 changes: 8 additions & 5 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
die();
}

$opts = load_opts();

require_once "misc/header.php";
$opts = load_opts();
?>

<title>LibreY - <?php printtext("settings_title");?></title>
Expand All @@ -53,7 +53,9 @@
<label for="theme"><?php printtext("settings_theme");?>:</label>
<select name="theme">
<?php
$themes = "<option value=\"amoled\">AMOLED</option>
$default = $opts->default_theme ?? "dark";
$themes = "
<option value=\"dark\">Dark</option>
<option value=\"darker\">Darker</option>
<option value=\"amoled\">AMOLED</option>
<option value=\"light\">Light</option>
Expand All @@ -73,11 +75,12 @@
<option value=\"ubuntu\">Ubuntu</option>
<option value=\"tokyo_night\">Tokyo Night</option>";

if (isset($opts->theme)) {
$theme = $opts->theme;
$themes = str_replace($theme . "\"", $theme . "\" selected", $themes);
if (!isset($opts->theme)) {
$theme = $default;
}

$theme = $opts->theme;
$themes = str_replace($theme . "\"", $theme . "\" selected", $themes);
echo $themes;
?>
</select>
Expand Down

0 comments on commit 7fe31b3

Please sign in to comment.