settings.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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" => "Autocomplete<br><i>Picking <div class=\"code-inline\">Auto</div> changes the source dynamically depending of the page's scraper<br>Picking <div class=\"code-inline\">Disabled</div> disables this feature</i>",
  62. "parameter" => "scraper_ac",
  63. "options" => [
  64. [
  65. "value" => "disabled",
  66. "text" => "Disabled"
  67. ],
  68. [
  69. "value" => "auto",
  70. "text" => "Auto"
  71. ],
  72. [
  73. "value" => "brave",
  74. "text" => "Brave"
  75. ],
  76. [
  77. "value" => "ddg",
  78. "text" => "DuckDuckGo"
  79. ],
  80. [
  81. "value" => "yandex",
  82. "text" => "Yandex"
  83. ],
  84. [
  85. "value" => "google",
  86. "text" => "Google"
  87. ],
  88. [
  89. "value" => "qwant",
  90. "text" => "Qwant"
  91. ],
  92. [
  93. "value" => "yep",
  94. "text" => "Yep"
  95. ],
  96. [
  97. "value" => "marginalia",
  98. "text" => "Marginalia"
  99. ],
  100. [
  101. "value" => "yt",
  102. "text" => "YouTube"
  103. ],
  104. [
  105. "value" => "sc",
  106. "text" => "SoundCloud"
  107. ]
  108. ]
  109. ],
  110. [
  111. "description" => "Web",
  112. "parameter" => "scraper_web",
  113. "options" => [
  114. [
  115. "value" => "ddg",
  116. "text" => "DuckDuckGo"
  117. ],
  118. [
  119. "value" => "brave",
  120. "text" => "Brave"
  121. ],
  122. [
  123. "value" => "yandex",
  124. "text" => "Yandex"
  125. ],
  126. /*[
  127. "value" => "google",
  128. "text" => "Google"
  129. ],*/
  130. [
  131. "value" => "mojeek",
  132. "text" => "Mojeek"
  133. ],
  134. [
  135. "value" => "marginalia",
  136. "text" => "Marginalia"
  137. ],
  138. [
  139. "value" => "wiby",
  140. "text" => "wiby"
  141. ]
  142. ]
  143. ],
  144. [
  145. "description" => "Images",
  146. "parameter" => "scraper_images",
  147. "options" => [
  148. [
  149. "value" => "ddg",
  150. "text" => "DuckDuckGo"
  151. ],
  152. [
  153. "value" => "yandex",
  154. "text" => "Yandex"
  155. ],
  156. [
  157. "value" => "brave",
  158. "text" => "Brave"
  159. ],
  160. [
  161. "value" => "google",
  162. "text" => "Google"
  163. ]
  164. ]
  165. ],
  166. [
  167. "description" => "Videos",
  168. "parameter" => "scraper_videos",
  169. "options" => [
  170. [
  171. "value" => "yt",
  172. "text" => "YouTube"
  173. ],
  174. [
  175. "value" => "ddg",
  176. "text" => "DuckDuckGo"
  177. ],
  178. [
  179. "value" => "brave",
  180. "text" => "Brave"
  181. ],
  182. [
  183. "value" => "yandex",
  184. "text" => "Yandex"
  185. ]/*,
  186. [
  187. "value" => "google",
  188. "text" => "Google"
  189. ]*/
  190. ]
  191. ],
  192. [
  193. "description" => "News",
  194. "parameter" => "scraper_news",
  195. "options" => [
  196. [
  197. "value" => "ddg",
  198. "text" => "DuckDuckGo"
  199. ],
  200. [
  201. "value" => "brave",
  202. "text" => "Brave"
  203. ],
  204. /*[
  205. "value" => "google",
  206. "text" => "Google"
  207. ],*/
  208. [
  209. "value" => "mojeek",
  210. "text" => "Mojeek"
  211. ]
  212. ]
  213. ],
  214. [
  215. "description" => "Music",
  216. "parameter" => "scraper_music",
  217. "options" => [
  218. [
  219. "value" => "sc",
  220. "text" => "SoundCloud"
  221. ]
  222. ]
  223. ]
  224. ]
  225. ]
  226. ];
  227. /*
  228. Set cookies
  229. */
  230. if($_POST){
  231. $loop = &$_POST;
  232. }elseif(count($_GET) !== 0){
  233. // redirect user to front page
  234. $loop = &$_GET;
  235. header("Location: /");
  236. }else{
  237. // refresh cookie dates
  238. $loop = &$_COOKIE;
  239. }
  240. foreach($loop as $key => $value){
  241. foreach($settings as $title){
  242. foreach($title["settings"] as $list){
  243. if(
  244. $list["parameter"] == $key &&
  245. $list["options"][0]["value"] == $value
  246. ){
  247. unset($_COOKIE[$key]);
  248. setcookie(
  249. $key,
  250. "",
  251. [
  252. "expires" => -1, // removes cookie
  253. "samesite" => "Strict"
  254. ]
  255. );
  256. continue 3;
  257. }
  258. }
  259. }
  260. if(!is_string($value)){
  261. continue;
  262. }
  263. $key = trim($key);
  264. $value = trim($value);
  265. $_COOKIE[$key] = $value;
  266. setcookie(
  267. $key,
  268. $value,
  269. [
  270. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  271. "samesite" => "Strict"
  272. ]
  273. );
  274. }
  275. include "lib/frontend.php";
  276. $frontend = new frontend();
  277. echo
  278. '<!DOCTYPE html>' .
  279. '<html lang="en">' .
  280. '<head>' .
  281. '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">' .
  282. '<title>Settings</title>' .
  283. '<link rel="stylesheet" href="/static/style.css?v4">' .
  284. '<meta name="viewport" content="width=device-width,initial-scale=1">' .
  285. '<meta name="robots" content="index,follow">' .
  286. '<link rel="icon" type="image/x-icon" href="/favicon.ico">' .
  287. '<meta name="description" content="4get.ca: Settings">' .
  288. '<link rel="search" type="application/opensearchdescription+xml" title="4get" href="/opensearch.xml">' .
  289. '</head>' .
  290. '<body' . $frontend->getthemeclass() . '>';
  291. $left =
  292. '<h1>Settings</h1>' .
  293. '<form method="post" autocomplete="off">' .
  294. '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.';
  295. $c = count($_COOKIE);
  296. $code = "";
  297. if($c !== 0){
  298. $left .=
  299. '<br><br>Your current cookie looks like this:' .
  300. '<div class="code">';
  301. $ca = 0;
  302. foreach($_COOKIE as $key => $value){
  303. $code .= $key . "=" . $value;
  304. $ca++;
  305. if($ca !== $c){
  306. $code .= "; ";
  307. }
  308. }
  309. $left .= $frontend->highlightcode($code);
  310. $left .= '</div>';
  311. }else{
  312. $left .=
  313. '<br><br>You currently don\'t have any cookies set.';
  314. }
  315. $left .=
  316. '<div class="settings">';
  317. foreach($settings as $title){
  318. $left .= '<h2>' . $title["name"] . '</h2>';
  319. foreach($title["settings"] as $setting){
  320. $left .=
  321. '<div class="setting">' .
  322. '<div class="title">' . $setting["description"] . '</div>' .
  323. '<select name="' . $setting["parameter"] . '">';
  324. foreach($setting["options"] as $option){
  325. $left .=
  326. '<option value="' . $option["value"] . '"';
  327. if(
  328. isset($_COOKIE[$setting["parameter"]]) &&
  329. $_COOKIE[$setting["parameter"]] == $option["value"]
  330. ){
  331. $left .= ' selected';
  332. }
  333. $left .= '>' . $option["text"] . '</option>';
  334. }
  335. $left .= '</select></div>';
  336. }
  337. }
  338. $left .=
  339. '</div>' .
  340. '<div class="settings-submit">' .
  341. '<input type="submit" value="Update settings!">' .
  342. '<a href="../">&lt; Return to front page</a>' .
  343. '</div>' .
  344. '</form>';
  345. if(count($_GET) === 0){
  346. echo
  347. $frontend->load(
  348. "search.html",
  349. [
  350. "class" => "",
  351. "right-left" =>
  352. '<div class="infobox"><h2>Preference link</h2>Follow this link to auto-apply all cookies. Useful if your browser clears out cookies after a browsing session. Following this link will redirect you to the front page, unless no settings are set.<br><br>' .
  353. '<a href="settings' . rtrim("?" . str_replace("; ", "&", $code), "?") . '">Bookmark me!</a>' .
  354. '</div>',
  355. "right-right" => "",
  356. "left" => $left
  357. ]
  358. );
  359. }