settings.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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" => "imgur",
  234. "text" => "Imgur"
  235. ],
  236. [
  237. "value" => "ftm",
  238. "text" => "FindThatMeme"
  239. ]
  240. ]
  241. ],
  242. [
  243. "description" => "Videos",
  244. "parameter" => "scraper_videos",
  245. "options" => [
  246. [
  247. "value" => "yt",
  248. "text" => "YouTube"
  249. ],
  250. [
  251. "value" => "ddg",
  252. "text" => "DuckDuckGo"
  253. ],
  254. [
  255. "value" => "brave",
  256. "text" => "Brave"
  257. ],
  258. [
  259. "value" => "yandex",
  260. "text" => "Yandex"
  261. ],
  262. [
  263. "value" => "google",
  264. "text" => "Google"
  265. ],
  266. [
  267. "value" => "startpage",
  268. "text" => "Startpage"
  269. ],
  270. [
  271. "value" => "qwant",
  272. "text" => "Qwant"
  273. ],
  274. [
  275. "value" => "solofield",
  276. "text" => "Solofield"
  277. ]
  278. ]
  279. ],
  280. [
  281. "description" => "News",
  282. "parameter" => "scraper_news",
  283. "options" => [
  284. [
  285. "value" => "ddg",
  286. "text" => "DuckDuckGo"
  287. ],
  288. [
  289. "value" => "brave",
  290. "text" => "Brave"
  291. ],
  292. [
  293. "value" => "google",
  294. "text" => "Google"
  295. ],
  296. [
  297. "value" => "startpage",
  298. "text" => "Startpage"
  299. ],
  300. [
  301. "value" => "qwant",
  302. "text" => "Qwant"
  303. ],
  304. [
  305. "value" => "yep",
  306. "text" => "Yep"
  307. ],
  308. [
  309. "value" => "mojeek",
  310. "text" => "Mojeek"
  311. ]
  312. ]
  313. ],
  314. [
  315. "description" => "Music",
  316. "parameter" => "scraper_music",
  317. "options" => [
  318. [
  319. "value" => "sc",
  320. "text" => "SoundCloud"
  321. ]//,
  322. //[
  323. // "value" => "spotify",
  324. // "text" => "Spotify"
  325. //]
  326. ]
  327. ]
  328. ]
  329. ]
  330. ];
  331. /*
  332. Set theme collection
  333. */
  334. $themes = glob("static/themes/*");
  335. $settings[0]["settings"][1]["options"][] = [
  336. "value" => "Dark",
  337. "text" => "Dark"
  338. ];
  339. foreach($themes as $theme){
  340. $theme = explode(".", basename($theme))[0];
  341. $settings[0]["settings"][1]["options"][] = [
  342. "value" => $theme,
  343. "text" => $theme
  344. ];
  345. }
  346. /*
  347. Set cookies
  348. */
  349. if($_POST){
  350. $loop = &$_POST;
  351. }elseif(count($_GET) !== 0){
  352. // redirect user to front page
  353. $loop = &$_GET;
  354. header("Location: /");
  355. }else{
  356. // refresh cookie dates
  357. $loop = &$_COOKIE;
  358. }
  359. foreach($loop as $key => $value){
  360. if($key == "theme"){
  361. if($value == config::DEFAULT_THEME){
  362. unset($_COOKIE[$key]);
  363. setcookie(
  364. "theme",
  365. "",
  366. [
  367. "expires" => -1, // removes cookie
  368. "samesite" => "Lax",
  369. "path" => "/"
  370. ]
  371. );
  372. continue;
  373. }
  374. }else{
  375. foreach($settings as $title){
  376. foreach($title["settings"] as $list){
  377. if(
  378. $list["parameter"] == $key &&
  379. $list["options"][0]["value"] == $value
  380. ){
  381. unset($_COOKIE[$key]);
  382. setcookie(
  383. $key,
  384. "",
  385. [
  386. "expires" => -1, // removes cookie
  387. "samesite" => "Lax",
  388. "path" => "/"
  389. ]
  390. );
  391. continue 3;
  392. }
  393. }
  394. }
  395. }
  396. if(!is_string($value)){
  397. continue;
  398. }
  399. $key = trim($key);
  400. $value = trim($value);
  401. $_COOKIE[$key] = $value;
  402. setcookie(
  403. $key,
  404. $value,
  405. [
  406. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  407. "samesite" => "Lax",
  408. "path" => "/"
  409. ]
  410. );
  411. }
  412. include "lib/frontend.php";
  413. $frontend = new frontend();
  414. echo
  415. $frontend->load(
  416. "header_nofilters.html",
  417. [
  418. "title" => "Settings",
  419. "class" => ""
  420. ]
  421. );
  422. $left =
  423. '<h1>Settings</h1>' .
  424. '<form method="post" autocomplete="off">' .
  425. '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.';
  426. $c = count($_COOKIE);
  427. $code = "";
  428. if($c !== 0){
  429. $left .=
  430. '<br><br>Your current cookie looks like this:' .
  431. '<div class="code">';
  432. $ca = 0;
  433. foreach($_COOKIE as $key => $value){
  434. $code .= $key . "=" . $value;
  435. $ca++;
  436. if($ca !== $c){
  437. $code .= "; ";
  438. }
  439. }
  440. $left .= $frontend->highlightcode($code);
  441. $left .= '</div>';
  442. }else{
  443. $left .=
  444. '<br><br>You currently don\'t have any cookies set.';
  445. }
  446. $left .=
  447. '<div class="settings">';
  448. foreach($settings as $title){
  449. $left .= '<h2>' . $title["name"] . '</h2>';
  450. foreach($title["settings"] as $setting){
  451. $left .=
  452. '<div class="setting">' .
  453. '<div class="title">' . $setting["description"] . '</div>' .
  454. '<select name="' . $setting["parameter"] . '">';
  455. if($setting["parameter"] == "theme"){
  456. if(!isset($_COOKIE["theme"])){
  457. $_COOKIE["theme"] = config::DEFAULT_THEME;
  458. }
  459. }
  460. foreach($setting["options"] as $option){
  461. $left .=
  462. '<option value="' . $option["value"] . '"';
  463. if(
  464. isset($_COOKIE[$setting["parameter"]]) &&
  465. $_COOKIE[$setting["parameter"]] == $option["value"]
  466. ){
  467. $left .= ' selected';
  468. }
  469. $left .= '>' . $option["text"] . '</option>';
  470. }
  471. $left .= '</select></div>';
  472. }
  473. }
  474. $left .=
  475. '</div>' .
  476. '<div class="settings-submit">' .
  477. '<input type="submit" value="Update settings!">' .
  478. '<a href="../">&lt; Go back</a>' .
  479. '</div>' .
  480. '</form>';
  481. if(count($_GET) === 0){
  482. $code = [];
  483. foreach($_COOKIE as $key => $value){
  484. $code[] = rawurlencode($key) . "=" . rawurlencode($value);
  485. }
  486. $code = implode("&", $code);
  487. if($code != ""){
  488. $code = "?" . $code;
  489. }
  490. echo
  491. $frontend->load(
  492. "search.html",
  493. [
  494. "timetaken" => null,
  495. "class" => "",
  496. "right-left" =>
  497. '<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>' .
  498. '<a href="settings' . $code . '">Bookmark me!</a>' .
  499. '</div>',
  500. "right-right" => "",
  501. "left" => $left
  502. ]
  503. );
  504. }