settings.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. include "data/config.php";
  3. /*
  4. Define settings
  5. */
  6. $settings = [
  7. [
  8. "name" => "General",
  9. "settings" => [
  10. [
  11. "description" => "Allow NSFW content",
  12. "parameter" => "nsfw",
  13. "options" => [
  14. [
  15. "value" => "yes",
  16. "text" => "Yes"
  17. ],
  18. [
  19. "value" => "maybe",
  20. "text" => "Maybe"
  21. ],
  22. [
  23. "value" => "no",
  24. "text" => "No"
  25. ]
  26. ]
  27. ],
  28. [
  29. "description" => "Theme",
  30. "parameter" => "theme",
  31. "options" => []
  32. ],
  33. [
  34. "description" => "Prevent clicking background elements when image viewer is open",
  35. "parameter" => "bg_noclick",
  36. "options" => [
  37. [
  38. "value" => "no",
  39. "text" => "No"
  40. ],
  41. [
  42. "value" => "yes",
  43. "text" => "Yes"
  44. ]
  45. ]
  46. ]
  47. ]
  48. ],
  49. [
  50. "name" => "Scrapers to use",
  51. "settings" => [
  52. [
  53. "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>",
  54. "parameter" => "scraper_ac",
  55. "options" => [
  56. [
  57. "value" => "disabled",
  58. "text" => "Disabled"
  59. ],
  60. [
  61. "value" => "auto",
  62. "text" => "Auto"
  63. ],
  64. [
  65. "value" => "brave",
  66. "text" => "Brave"
  67. ],
  68. [
  69. "value" => "ddg",
  70. "text" => "DuckDuckGo"
  71. ],
  72. [
  73. "value" => "yandex",
  74. "text" => "Yandex"
  75. ],
  76. [
  77. "value" => "google",
  78. "text" => "Google"
  79. ],
  80. [
  81. "value" => "startpage",
  82. "text" => "Startpage"
  83. ],
  84. [
  85. "value" => "kagi",
  86. "text" => "Kagi"
  87. ],
  88. [
  89. "value" => "qwant",
  90. "text" => "Qwant"
  91. ],
  92. [
  93. "value" => "ghostery",
  94. "text" => "Ghostery"
  95. ],
  96. [
  97. "value" => "yep",
  98. "text" => "Yep"
  99. ],
  100. [
  101. "value" => "marginalia",
  102. "text" => "Marginalia"
  103. ],
  104. [
  105. "value" => "yt",
  106. "text" => "YouTube"
  107. ],
  108. [
  109. "value" => "sc",
  110. "text" => "SoundCloud"
  111. ]
  112. ]
  113. ],
  114. [
  115. "description" => "Web",
  116. "parameter" => "scraper_web",
  117. "options" => [
  118. [
  119. "value" => "ddg",
  120. "text" => "DuckDuckGo"
  121. ],
  122. [
  123. "value" => "brave",
  124. "text" => "Brave"
  125. ],
  126. [
  127. "value" => "yandex",
  128. "text" => "Yandex"
  129. ],
  130. [
  131. "value" => "google",
  132. "text" => "Google"
  133. ],
  134. [
  135. "value" => "google_cse",
  136. "text" => "Google CSE"
  137. ],
  138. [
  139. "value" => "startpage",
  140. "text" => "Startpage"
  141. ],
  142. [
  143. "value" => "qwant",
  144. "text" => "Qwant"
  145. ],
  146. [
  147. "value" => "ghostery",
  148. "text" => "Ghostery"
  149. ],
  150. [
  151. "value" => "yep",
  152. "text" => "Yep"
  153. ],
  154. [
  155. "value" => "greppr",
  156. "text" => "Greppr"
  157. ],
  158. [
  159. "value" => "crowdview",
  160. "text" => "Crowdview"
  161. ],
  162. [
  163. "value" => "mwmbl",
  164. "text" => "Mwmbl"
  165. ],
  166. [
  167. "value" => "mojeek",
  168. "text" => "Mojeek"
  169. ],
  170. [
  171. "value" => "solofield",
  172. "text" => "Solofield"
  173. ],
  174. [
  175. "value" => "marginalia",
  176. "text" => "Marginalia"
  177. ],
  178. [
  179. "value" => "wiby",
  180. "text" => "wiby"
  181. ],
  182. [
  183. "value" => "curlie",
  184. "text" => "Curlie"
  185. ]
  186. ]
  187. ],
  188. [
  189. "description" => "Images",
  190. "parameter" => "scraper_images",
  191. "options" => [
  192. [
  193. "value" => "ddg",
  194. "text" => "DuckDuckGo"
  195. ],
  196. [
  197. "value" => "yandex",
  198. "text" => "Yandex"
  199. ],
  200. [
  201. "value" => "brave",
  202. "text" => "Brave"
  203. ],
  204. [
  205. "value" => "google",
  206. "text" => "Google"
  207. ],
  208. [
  209. "value" => "google_cse",
  210. "text" => "Google CSE"
  211. ],
  212. [
  213. "value" => "startpage",
  214. "text" => "Startpage"
  215. ],
  216. [
  217. "value" => "qwant",
  218. "text" => "Qwant"
  219. ],
  220. [
  221. "value" => "yep",
  222. "text" => "Yep"
  223. ],
  224. [
  225. "value" => "solofield",
  226. "text" => "Solofield"
  227. ],
  228. [
  229. "value" => "pinterest",
  230. "text" => "Pinterest"
  231. ],
  232. [
  233. "value" => "fivehpx",
  234. "text" => "500px"
  235. ],
  236. [
  237. "value" => "vsco",
  238. "text" => "VSCO"
  239. ],
  240. [
  241. "value" => "imgur",
  242. "text" => "Imgur"
  243. ],
  244. [
  245. "value" => "ftm",
  246. "text" => "FindThatMeme"
  247. ]
  248. ]
  249. ],
  250. [
  251. "description" => "Videos",
  252. "parameter" => "scraper_videos",
  253. "options" => [
  254. [
  255. "value" => "yt",
  256. "text" => "YouTube"
  257. ],
  258. [
  259. "value" => "ddg",
  260. "text" => "DuckDuckGo"
  261. ],
  262. [
  263. "value" => "brave",
  264. "text" => "Brave"
  265. ],
  266. [
  267. "value" => "yandex",
  268. "text" => "Yandex"
  269. ],
  270. [
  271. "value" => "google",
  272. "text" => "Google"
  273. ],
  274. [
  275. "value" => "startpage",
  276. "text" => "Startpage"
  277. ],
  278. [
  279. "value" => "qwant",
  280. "text" => "Qwant"
  281. ],
  282. [
  283. "value" => "solofield",
  284. "text" => "Solofield"
  285. ]
  286. ]
  287. ],
  288. [
  289. "description" => "News",
  290. "parameter" => "scraper_news",
  291. "options" => [
  292. [
  293. "value" => "ddg",
  294. "text" => "DuckDuckGo"
  295. ],
  296. [
  297. "value" => "brave",
  298. "text" => "Brave"
  299. ],
  300. [
  301. "value" => "google",
  302. "text" => "Google"
  303. ],
  304. [
  305. "value" => "startpage",
  306. "text" => "Startpage"
  307. ],
  308. [
  309. "value" => "qwant",
  310. "text" => "Qwant"
  311. ],
  312. [
  313. "value" => "yep",
  314. "text" => "Yep"
  315. ],
  316. [
  317. "value" => "mojeek",
  318. "text" => "Mojeek"
  319. ]
  320. ]
  321. ],
  322. [
  323. "description" => "Music",
  324. "parameter" => "scraper_music",
  325. "options" => [
  326. [
  327. "value" => "sc",
  328. "text" => "SoundCloud"
  329. ]//,
  330. //[
  331. // "value" => "spotify",
  332. // "text" => "Spotify"
  333. //]
  334. ]
  335. ]
  336. ]
  337. ]
  338. ];
  339. /*
  340. Set theme collection
  341. */
  342. $themes = glob("static/themes/*");
  343. $settings[0]["settings"][1]["options"][] = [
  344. "value" => "Dark",
  345. "text" => "Dark"
  346. ];
  347. foreach($themes as $theme){
  348. $theme = explode(".", basename($theme))[0];
  349. $settings[0]["settings"][1]["options"][] = [
  350. "value" => $theme,
  351. "text" => $theme
  352. ];
  353. }
  354. /*
  355. Set cookies
  356. */
  357. if($_POST){
  358. $loop = &$_POST;
  359. }elseif(count($_GET) !== 0){
  360. // redirect user to front page
  361. $loop = &$_GET;
  362. header("Location: /");
  363. }else{
  364. // refresh cookie dates
  365. $loop = &$_COOKIE;
  366. }
  367. foreach($loop as $key => $value){
  368. if($key == "theme"){
  369. if($value == config::DEFAULT_THEME){
  370. unset($_COOKIE[$key]);
  371. setcookie(
  372. "theme",
  373. "",
  374. [
  375. "expires" => -1, // removes cookie
  376. "samesite" => "Lax",
  377. "path" => "/"
  378. ]
  379. );
  380. continue;
  381. }
  382. }else{
  383. foreach($settings as $title){
  384. foreach($title["settings"] as $list){
  385. if(
  386. $list["parameter"] == $key &&
  387. $list["options"][0]["value"] == $value
  388. ){
  389. unset($_COOKIE[$key]);
  390. setcookie(
  391. $key,
  392. "",
  393. [
  394. "expires" => -1, // removes cookie
  395. "samesite" => "Lax",
  396. "path" => "/"
  397. ]
  398. );
  399. continue 3;
  400. }
  401. }
  402. }
  403. }
  404. if(!is_string($value)){
  405. continue;
  406. }
  407. $key = trim($key);
  408. $value = trim($value);
  409. $_COOKIE[$key] = $value;
  410. setcookie(
  411. $key,
  412. $value,
  413. [
  414. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  415. "samesite" => "Lax",
  416. "path" => "/"
  417. ]
  418. );
  419. }
  420. include "lib/frontend.php";
  421. $frontend = new frontend();
  422. echo
  423. $frontend->load(
  424. "header_nofilters.html",
  425. [
  426. "title" => "Settings",
  427. "class" => ""
  428. ]
  429. );
  430. $left =
  431. '<h1>Settings</h1>' .
  432. '<form method="post" autocomplete="off">' .
  433. '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.';
  434. $c = count($_COOKIE);
  435. $code = "";
  436. if($c !== 0){
  437. $left .=
  438. '<br><br>Your current cookie looks like this:' .
  439. '<div class="code">';
  440. $ca = 0;
  441. foreach($_COOKIE as $key => $value){
  442. $code .= $key . "=" . $value;
  443. $ca++;
  444. if($ca !== $c){
  445. $code .= "; ";
  446. }
  447. }
  448. $left .= $frontend->highlightcode($code);
  449. $left .= '</div>';
  450. }else{
  451. $left .=
  452. '<br><br>You currently don\'t have any cookies set.';
  453. }
  454. $left .=
  455. '<div class="settings">';
  456. foreach($settings as $title){
  457. $left .= '<h2>' . $title["name"] . '</h2>';
  458. foreach($title["settings"] as $setting){
  459. $left .=
  460. '<div class="setting">' .
  461. '<div class="title">' . $setting["description"] . '</div>' .
  462. '<select name="' . $setting["parameter"] . '">';
  463. if($setting["parameter"] == "theme"){
  464. if(!isset($_COOKIE["theme"])){
  465. $_COOKIE["theme"] = config::DEFAULT_THEME;
  466. }
  467. }
  468. foreach($setting["options"] as $option){
  469. $left .=
  470. '<option value="' . $option["value"] . '"';
  471. if(
  472. isset($_COOKIE[$setting["parameter"]]) &&
  473. $_COOKIE[$setting["parameter"]] == $option["value"]
  474. ){
  475. $left .= ' selected';
  476. }
  477. $left .= '>' . $option["text"] . '</option>';
  478. }
  479. $left .= '</select></div>';
  480. }
  481. }
  482. $left .=
  483. '</div>' .
  484. '<div class="settings-submit">' .
  485. '<input type="submit" value="Update settings!">' .
  486. '<a href="../">&lt; Go back</a>' .
  487. '</div>' .
  488. '</form>';
  489. if(count($_GET) === 0){
  490. $code = [];
  491. foreach($_COOKIE as $key => $value){
  492. $code[] = rawurlencode($key) . "=" . rawurlencode($value);
  493. }
  494. $code = implode("&", $code);
  495. if($code != ""){
  496. $code = "?" . $code;
  497. }
  498. echo
  499. $frontend->load(
  500. "search.html",
  501. [
  502. "timetaken" => null,
  503. "class" => "",
  504. "right-left" =>
  505. '<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>' .
  506. '<a href="settings' . $code . '">Bookmark me!</a>' .
  507. '</div>',
  508. "right-right" => "",
  509. "left" => $left
  510. ]
  511. );
  512. }