1
Fork 1
mirror of https://git.lolcat.ca/lolcat/4get.git synced 2024-10-25 17:26:50 -05:00
4get/settings.php

566 lines
9.7 KiB
PHP
Raw Normal View History

2023-07-22 13:41:14 -05:00
<?php
2023-11-07 08:04:56 -05:00
include "data/config.php";
2023-07-22 13:41:14 -05:00
/*
Define settings
*/
$settings = [
[
"name" => "General",
"settings" => [
[
"description" => "Allow NSFW content",
"parameter" => "nsfw",
"options" => [
[
"value" => "yes",
"text" => "Yes"
],
[
"value" => "maybe",
"text" => "Maybe"
],
[
"value" => "no",
"text" => "No"
]
]
],
[
"description" => "Theme",
"parameter" => "theme",
2023-11-07 08:04:56 -05:00
"options" => []
2023-07-22 13:41:14 -05:00
],
[
"description" => "Prevent clicking background elements when image viewer is open",
"parameter" => "bg_noclick",
"options" => [
[
"value" => "no",
"text" => "No"
],
[
"value" => "yes",
"text" => "Yes"
]
]
]
]
],
[
"name" => "Scrapers to use",
"settings" => [
2023-09-13 08:01:23 -05:00
[
2023-11-07 08:04:56 -05:00
"description" => "Autocomplete<br><i>Picking <span class=\"code-inline\">Auto</span> changes the source dynamically depending of the page's scraper<br><b>Warning:</b> If you edit this field, you will need to re-add the search engine so that the new autocomplete settings are applied!</i>",
2023-09-13 08:01:23 -05:00
"parameter" => "scraper_ac",
"options" => [
[
"value" => "disabled",
"text" => "Disabled"
],
[
"value" => "auto",
"text" => "Auto"
],
[
"value" => "brave",
"text" => "Brave"
],
[
"value" => "ddg",
"text" => "DuckDuckGo"
],
[
"value" => "yandex",
"text" => "Yandex"
],
[
"value" => "google",
"text" => "Google"
],
2024-07-29 09:34:56 -05:00
[
"value" => "startpage",
"text" => "Startpage"
],
2024-08-09 09:06:08 -05:00
[
"value" => "kagi",
"text" => "Kagi"
],
2023-09-13 08:01:23 -05:00
[
"value" => "qwant",
"text" => "Qwant"
],
2024-09-01 09:52:28 -05:00
[
"value" => "ghostery",
"text" => "Ghostery"
],
2023-09-13 08:01:23 -05:00
[
"value" => "yep",
"text" => "Yep"
],
[
"value" => "marginalia",
"text" => "Marginalia"
],
[
"value" => "yt",
"text" => "YouTube"
],
[
"value" => "sc",
"text" => "SoundCloud"
]
]
],
2023-07-22 13:41:14 -05:00
[
"description" => "Web",
"parameter" => "scraper_web",
"options" => [
[
"value" => "ddg",
"text" => "DuckDuckGo"
],
[
"value" => "brave",
"text" => "Brave"
],
[
"value" => "yandex",
"text" => "Yandex"
],
[
2023-08-08 02:09:47 -05:00
"value" => "google",
"text" => "Google"
],
[
"value" => "google_cse",
"text" => "Google CSE"
],
[
"value" => "startpage",
"text" => "Startpage"
],
2024-04-21 18:48:14 -05:00
[
"value" => "qwant",
"text" => "Qwant"
],
2024-09-01 09:52:28 -05:00
[
"value" => "ghostery",
"text" => "Ghostery"
],
2023-12-02 19:11:52 -05:00
[
"value" => "yep",
"text" => "Yep"
],
[
"value" => "greppr",
"text" => "Greppr"
],
2024-03-22 20:31:06 -05:00
[
"value" => "crowdview",
"text" => "Crowdview"
],
2024-02-26 11:31:52 -05:00
[
"value" => "mwmbl",
"text" => "Mwmbl"
],
2023-07-22 13:41:14 -05:00
[
"value" => "mojeek",
"text" => "Mojeek"
],
2024-09-01 19:35:21 -05:00
[
"value" => "solofield",
"text" => "Solofield"
],
2023-07-22 13:41:14 -05:00
[
"value" => "marginalia",
"text" => "Marginalia"
],
[
"value" => "wiby",
"text" => "wiby"
2024-01-06 19:43:54 -05:00
],
[
"value" => "curlie",
"text" => "Curlie"
2023-07-22 13:41:14 -05:00
]
]
],
[
"description" => "Images",
"parameter" => "scraper_images",
"options" => [
[
"value" => "ddg",
"text" => "DuckDuckGo"
],
[
"value" => "yandex",
"text" => "Yandex"
2023-08-08 02:09:47 -05:00
],
[
"value" => "brave",
"text" => "Brave"
],
2023-08-08 02:09:47 -05:00
[
"value" => "google",
"text" => "Google"
],
[
"value" => "google_cse",
"text" => "Google CSE"
],
[
"value" => "startpage",
"text" => "Startpage"
],
2024-04-21 18:48:14 -05:00
[
"value" => "qwant",
"text" => "Qwant"
],
[
"value" => "yep",
"text" => "Yep"
],
2024-09-01 19:35:21 -05:00
[
"value" => "solofield",
"text" => "Solofield"
],
/*[
"value" => "pinterest",
"text" => "Pinterest"
],*/
[
"value" => "imgur",
"text" => "Imgur"
],
[
"value" => "ftm",
"text" => "FindThatMeme"
]
2023-07-22 13:41:14 -05:00
]
],
[
"description" => "Videos",
"parameter" => "scraper_videos",
"options" => [
[
"value" => "yt",
"text" => "YouTube"
],
[
"value" => "ddg",
"text" => "DuckDuckGo"
2023-08-08 02:09:47 -05:00
],
[
"value" => "brave",
"text" => "Brave"
],
[
"value" => "yandex",
"text" => "Yandex"
],
2023-08-08 02:09:47 -05:00
[
"value" => "google",
"text" => "Google"
2024-04-21 18:48:14 -05:00
],
[
"value" => "startpage",
"text" => "Startpage"
],
2024-04-21 18:48:14 -05:00
[
"value" => "qwant",
"text" => "Qwant"
],
2024-09-01 19:35:21 -05:00
[
"value" => "solofield",
"text" => "Solofield"
]
2023-07-22 13:41:14 -05:00
]
],
[
"description" => "News",
"parameter" => "scraper_news",
"options" => [
[
"value" => "ddg",
"text" => "DuckDuckGo"
],
[
"value" => "brave",
"text" => "Brave"
],
[
2023-08-08 02:09:47 -05:00
"value" => "google",
"text" => "Google"
],
[
"value" => "startpage",
"text" => "Startpage"
],
2024-04-21 18:48:14 -05:00
[
"value" => "qwant",
"text" => "Qwant"
],
2023-12-02 19:11:52 -05:00
[
"value" => "yep",
"text" => "Yep"
],
2023-07-22 13:41:14 -05:00
[
"value" => "mojeek",
"text" => "Mojeek"
]
]
2023-09-03 21:41:44 -05:00
],
[
"description" => "Music",
"parameter" => "scraper_music",
"options" => [
[
"value" => "sc",
"text" => "SoundCloud"
2024-01-06 19:46:13 -05:00
]//,
//[
// "value" => "spotify",
// "text" => "Spotify"
//]
2023-09-03 21:41:44 -05:00
]
2023-07-22 13:41:14 -05:00
]
]
]
];
2023-11-07 08:04:56 -05:00
/*
Set theme collection
*/
$themes = glob("static/themes/*");
$settings[0]["settings"][1]["options"][] = [
"value" => "Dark",
"text" => "Dark"
];
foreach($themes as $theme){
$theme = explode(".", basename($theme))[0];
$settings[0]["settings"][1]["options"][] = [
"value" => $theme,
"text" => $theme
];
}
2023-07-22 13:41:14 -05:00
/*
Set cookies
*/
if($_POST){
$loop = &$_POST;
2023-09-13 08:01:23 -05:00
}elseif(count($_GET) !== 0){
// redirect user to front page
$loop = &$_GET;
header("Location: /");
2023-07-22 13:41:14 -05:00
2023-09-13 08:01:23 -05:00
}else{
2023-07-22 13:41:14 -05:00
// refresh cookie dates
$loop = &$_COOKIE;
}
2023-07-22 13:41:14 -05:00
foreach($loop as $key => $value){
2023-11-07 08:04:56 -05:00
if($key == "theme"){
2023-07-22 13:41:14 -05:00
2023-11-07 08:04:56 -05:00
if($value == config::DEFAULT_THEME){
2023-07-22 13:41:14 -05:00
2023-11-07 08:04:56 -05:00
unset($_COOKIE[$key]);
setcookie(
"theme",
"",
[
"expires" => -1, // removes cookie
"samesite" => "Lax",
"path" => "/"
]
);
continue;
}
}else{
foreach($settings as $title){
foreach($title["settings"] as $list){
2023-07-22 13:41:14 -05:00
2023-11-07 08:04:56 -05:00
if(
$list["parameter"] == $key &&
$list["options"][0]["value"] == $value
){
unset($_COOKIE[$key]);
setcookie(
$key,
"",
[
"expires" => -1, // removes cookie
"samesite" => "Lax",
"path" => "/"
]
);
continue 3;
}
2023-07-22 13:41:14 -05:00
}
}
}
if(!is_string($value)){
continue;
}
$key = trim($key);
$value = trim($value);
$_COOKIE[$key] = $value;
setcookie(
$key,
$value,
[
"expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
2023-10-17 16:58:08 -05:00
"samesite" => "Lax",
"path" => "/"
2023-07-22 13:41:14 -05:00
]
);
}
include "lib/frontend.php";
$frontend = new frontend();
echo
2023-11-07 08:04:56 -05:00
$frontend->load(
"header_nofilters.html",
[
"title" => "Settings",
"class" => ""
]
);
2023-07-22 13:41:14 -05:00
$left =
'<h1>Settings</h1>' .
'<form method="post" autocomplete="off">' .
'By clicking <div class="code-inline">Update settings!</div>, a plaintext <div class="code-inline">key=value</div> cookie will be stored on your browser. When selecting a default setting, the parameter is removed from your cookies.';
$c = count($_COOKIE);
2023-09-13 08:01:23 -05:00
$code = "";
2023-07-22 13:41:14 -05:00
if($c !== 0){
$left .=
'<br><br>Your current cookie looks like this:' .
'<div class="code">';
$ca = 0;
foreach($_COOKIE as $key => $value){
$code .= $key . "=" . $value;
$ca++;
if($ca !== $c){
$code .= "; ";
}
}
$left .= $frontend->highlightcode($code);
$left .= '</div>';
}else{
$left .=
'<br><br>You currently don\'t have any cookies set.';
}
$left .=
'<div class="settings">';
foreach($settings as $title){
$left .= '<h2>' . $title["name"] . '</h2>';
foreach($title["settings"] as $setting){
$left .=
'<div class="setting">' .
'<div class="title">' . $setting["description"] . '</div>' .
'<select name="' . $setting["parameter"] . '">';
2023-11-07 08:04:56 -05:00
if($setting["parameter"] == "theme"){
if(!isset($_COOKIE["theme"])){
$_COOKIE["theme"] = config::DEFAULT_THEME;
}
}
2023-07-22 13:41:14 -05:00
foreach($setting["options"] as $option){
$left .=
'<option value="' . $option["value"] . '"';
if(
isset($_COOKIE[$setting["parameter"]]) &&
$_COOKIE[$setting["parameter"]] == $option["value"]
){
$left .= ' selected';
}
$left .= '>' . $option["text"] . '</option>';
}
$left .= '</select></div>';
}
}
$left .=
'</div>' .
'<div class="settings-submit">' .
'<input type="submit" value="Update settings!">' .
'<a href="../">&lt; Go back</a>' .
2023-07-22 13:41:14 -05:00
'</div>' .
'</form>';
2023-09-13 08:01:23 -05:00
if(count($_GET) === 0){
$code = [];
foreach($_COOKIE as $key => $value){
$code[] = rawurlencode($key) . "=" . rawurlencode($value);
}
$code = implode("&", $code);
if($code != ""){
$code = "?" . $code;
}
2023-09-13 08:01:23 -05:00
echo
$frontend->load(
"search.html",
[
2024-02-17 23:22:19 -05:00
"timetaken" => null,
2023-09-13 08:01:23 -05:00
"class" => "",
"right-left" =>
'<div class="infobox"><h2>Preference link</h2>Following this link will re-apply all cookies configured here and will redirect you to the front page. Useful if your browser clears out cookies after a browsing session.<br><br>' .
'<a href="settings' . $code . '">Bookmark me!</a>' .
2023-09-13 08:01:23 -05:00
'</div>',
"right-right" => "",
"left" => $left
]
);
}