1
0

settings.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. /*
  3. Define settings
  4. */
  5. $settings = [
  6. [
  7. "name" => "General",
  8. "settings" => [
  9. [
  10. "description" => "Allow NSFW content",
  11. "parameter" => "nsfw",
  12. "options" => [
  13. [
  14. "value" => "yes",
  15. "text" => "Yes"
  16. ],
  17. [
  18. "value" => "maybe",
  19. "text" => "Maybe"
  20. ],
  21. [
  22. "value" => "no",
  23. "text" => "No"
  24. ]
  25. ]
  26. ],
  27. [
  28. "description" => "Theme",
  29. "parameter" => "theme",
  30. "options" => [
  31. [
  32. "value" => "dark",
  33. "text" => "Gruvbox dark"
  34. ],
  35. [
  36. "value" => "cream",
  37. "text" => "Gruvbox cream"
  38. ]
  39. ]
  40. ],
  41. [
  42. "description" => "Prevent clicking background elements when image viewer is open",
  43. "parameter" => "bg_noclick",
  44. "options" => [
  45. [
  46. "value" => "no",
  47. "text" => "No"
  48. ],
  49. [
  50. "value" => "yes",
  51. "text" => "Yes"
  52. ]
  53. ]
  54. ]
  55. ]
  56. ],
  57. [
  58. "name" => "Scrapers to use",
  59. "settings" => [
  60. [
  61. "description" => "Web",
  62. "parameter" => "scraper_web",
  63. "options" => [
  64. [
  65. "value" => "ddg",
  66. "text" => "DuckDuckGo"
  67. ],
  68. [
  69. "value" => "brave",
  70. "text" => "Brave"
  71. ],
  72. //[
  73. // "value" => "google",
  74. // "text" => "Google"
  75. //],
  76. [
  77. "value" => "mojeek",
  78. "text" => "Mojeek"
  79. ],
  80. [
  81. "value" => "marginalia",
  82. "text" => "Marginalia"
  83. ],
  84. [
  85. "value" => "wiby",
  86. "text" => "wiby"
  87. ]
  88. ]
  89. ],
  90. [
  91. "description" => "Images",
  92. "parameter" => "scraper_images",
  93. "options" => [
  94. [
  95. "value" => "ddg",
  96. "text" => "DuckDuckGo"
  97. ],
  98. [
  99. "value" => "yandex",
  100. "text" => "Yandex"
  101. ]//,
  102. //[
  103. // "value" => "google",
  104. // "text" => "Google"
  105. //]
  106. ]
  107. ],
  108. [
  109. "description" => "Videos",
  110. "parameter" => "scraper_videos",
  111. "options" => [
  112. [
  113. "value" => "yt",
  114. "text" => "YouTube"
  115. ],
  116. [
  117. "value" => "ddg",
  118. "text" => "DuckDuckGo"
  119. ]//,
  120. //[
  121. // "value" => "google",
  122. // "text" => "Google"
  123. //]
  124. ]
  125. ],
  126. [
  127. "description" => "News",
  128. "parameter" => "scraper_news",
  129. "options" => [
  130. [
  131. "value" => "ddg",
  132. "text" => "DuckDuckGo"
  133. ],
  134. [
  135. "value" => "brave",
  136. "text" => "Brave"
  137. ],
  138. //[
  139. // "value" => "google",
  140. // "text" => "Google"
  141. //],
  142. [
  143. "value" => "mojeek",
  144. "text" => "Mojeek"
  145. ]
  146. ]
  147. ]
  148. ]
  149. ]
  150. ];
  151. /*
  152. Set cookies
  153. */
  154. if($_POST){
  155. $loop = &$_POST;
  156. }else{
  157. // refresh cookie dates
  158. $loop = &$_COOKIE;
  159. }
  160. foreach($loop as $key => $value){
  161. foreach($settings as $title){
  162. foreach($title["settings"] as $list){
  163. if(
  164. $list["parameter"] == $key &&
  165. $list["options"][0]["value"] == $value
  166. ){
  167. unset($_COOKIE[$key]);
  168. setcookie(
  169. $key,
  170. "",
  171. [
  172. "expires" => -1, // removes cookie
  173. "samesite" => "Strict"
  174. ]
  175. );
  176. continue 3;
  177. }
  178. }
  179. }
  180. if(!is_string($value)){
  181. continue;
  182. }
  183. $key = trim($key);
  184. $value = trim($value);
  185. $_COOKIE[$key] = $value;
  186. setcookie(
  187. $key,
  188. $value,
  189. [
  190. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  191. "samesite" => "Strict"
  192. ]
  193. );
  194. }
  195. include "lib/frontend.php";
  196. $frontend = new frontend();
  197. echo
  198. '<!DOCTYPE html>' .
  199. '<html lang="en">' .
  200. '<head>' .
  201. '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">' .
  202. '<title>Settings</title>' .
  203. '<link rel="stylesheet" href="/static/style.css?v2">' .
  204. '<meta name="viewport" content="width=device-width,initial-scale=1">' .
  205. '<meta name="robots" content="index,follow">' .
  206. '<link rel="icon" type="image/x-icon" href="/favicon.ico">' .
  207. '<meta name="description" content="4get.ca: Settings">' .
  208. '<link rel="search" type="application/opensearchdescription+xml" title="4get" href="/opensearch.xml">' .
  209. '</head>' .
  210. '<body' . $frontend->getthemeclass() . '>';
  211. $left =
  212. '<h1>Settings</h1>' .
  213. '<form method="post" autocomplete="off">' .
  214. '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.';
  215. $c = count($_COOKIE);
  216. if($c !== 0){
  217. $left .=
  218. '<br><br>Your current cookie looks like this:' .
  219. '<div class="code">';
  220. $code = "";
  221. $ca = 0;
  222. foreach($_COOKIE as $key => $value){
  223. $code .= $key . "=" . $value;
  224. $ca++;
  225. if($ca !== $c){
  226. $code .= "; ";
  227. }
  228. }
  229. $left .= $frontend->highlightcode($code);
  230. $left .= '</div>';
  231. }else{
  232. $left .=
  233. '<br><br>You currently don\'t have any cookies set.';
  234. }
  235. $left .=
  236. '<div class="settings">';
  237. foreach($settings as $title){
  238. $left .= '<h2>' . $title["name"] . '</h2>';
  239. foreach($title["settings"] as $setting){
  240. $left .=
  241. '<div class="setting">' .
  242. '<div class="title">' . $setting["description"] . '</div>' .
  243. '<select name="' . $setting["parameter"] . '">';
  244. foreach($setting["options"] as $option){
  245. $left .=
  246. '<option value="' . $option["value"] . '"';
  247. if(
  248. isset($_COOKIE[$setting["parameter"]]) &&
  249. $_COOKIE[$setting["parameter"]] == $option["value"]
  250. ){
  251. $left .= ' selected';
  252. }
  253. $left .= '>' . $option["text"] . '</option>';
  254. }
  255. $left .= '</select></div>';
  256. }
  257. }
  258. $left .=
  259. '</div>' .
  260. '<div class="settings-submit">' .
  261. '<input type="submit" value="Update settings!">' .
  262. '<a href="../">&lt; Return to main page</a>' .
  263. '</div>' .
  264. '</form>';
  265. echo
  266. $frontend->load(
  267. "search.html",
  268. [
  269. "class" => "",
  270. "right-left" => "",
  271. "right-right" => "",
  272. "left" => $left
  273. ]
  274. );