settings.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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" => "mullvad_brave",
  128. "text" => "Mullvad (Brave)"
  129. ],
  130. [
  131. "value" => "yandex",
  132. "text" => "Yandex"
  133. ],
  134. [
  135. "value" => "google",
  136. "text" => "Google"
  137. ],
  138. [
  139. "value" => "google_cse",
  140. "text" => "Google CSE"
  141. ],
  142. [
  143. "value" => "mullvad_google",
  144. "text" => "Mullvad (Google)"
  145. ],
  146. [
  147. "value" => "startpage",
  148. "text" => "Startpage"
  149. ],
  150. [
  151. "value" => "qwant",
  152. "text" => "Qwant"
  153. ],
  154. [
  155. "value" => "ghostery",
  156. "text" => "Ghostery"
  157. ],
  158. [
  159. "value" => "yep",
  160. "text" => "Yep"
  161. ],
  162. [
  163. "value" => "greppr",
  164. "text" => "Greppr"
  165. ],
  166. [
  167. "value" => "crowdview",
  168. "text" => "Crowdview"
  169. ],
  170. [
  171. "value" => "mwmbl",
  172. "text" => "Mwmbl"
  173. ],
  174. [
  175. "value" => "mojeek",
  176. "text" => "Mojeek"
  177. ],
  178. [
  179. "value" => "baidu",
  180. "text" => "Baidu"
  181. ],
  182. [
  183. "value" => "coccoc",
  184. "text" => "Cốc Cốc"
  185. ],
  186. [
  187. "value" => "solofield",
  188. "text" => "Solofield"
  189. ],
  190. [
  191. "value" => "marginalia",
  192. "text" => "Marginalia"
  193. ],
  194. [
  195. "value" => "wiby",
  196. "text" => "wiby"
  197. ],
  198. [
  199. "value" => "curlie",
  200. "text" => "Curlie"
  201. ]
  202. ]
  203. ],
  204. [
  205. "description" => "Images",
  206. "parameter" => "scraper_images",
  207. "options" => [
  208. [
  209. "value" => "ddg",
  210. "text" => "DuckDuckGo"
  211. ],
  212. [
  213. "value" => "yandex",
  214. "text" => "Yandex"
  215. ],
  216. [
  217. "value" => "brave",
  218. "text" => "Brave"
  219. ],
  220. [
  221. "value" => "google",
  222. "text" => "Google"
  223. ],
  224. [
  225. "value" => "google_cse",
  226. "text" => "Google CSE"
  227. ],
  228. [
  229. "value" => "startpage",
  230. "text" => "Startpage"
  231. ],
  232. [
  233. "value" => "qwant",
  234. "text" => "Qwant"
  235. ],
  236. [
  237. "value" => "yep",
  238. "text" => "Yep"
  239. ],
  240. [
  241. "value" => "baidu",
  242. "text" => "Baidu"
  243. ],
  244. [
  245. "value" => "solofield",
  246. "text" => "Solofield"
  247. ],
  248. [
  249. "value" => "pinterest",
  250. "text" => "Pinterest"
  251. ],
  252. [
  253. "value" => "cara",
  254. "text" => "Cara"
  255. ],
  256. [
  257. "value" => "flickr",
  258. "text" => "Flickr"
  259. ],
  260. [
  261. "value" => "fivehpx",
  262. "text" => "500px"
  263. ],
  264. [
  265. "value" => "vsco",
  266. "text" => "VSCO"
  267. ],
  268. [
  269. "value" => "imgur",
  270. "text" => "Imgur"
  271. ],
  272. [
  273. "value" => "ftm",
  274. "text" => "FindThatMeme"
  275. ]
  276. ]
  277. ],
  278. [
  279. "description" => "Videos",
  280. "parameter" => "scraper_videos",
  281. "options" => [
  282. [
  283. "value" => "yt",
  284. "text" => "YouTube"
  285. ],
  286. [
  287. "value" => "vimeo",
  288. "text" => "Vimeo"
  289. ],
  290. [
  291. "value" => "sepiasearch",
  292. "text" => "Sepia Search"
  293. ],
  294. [
  295. "value" => "ddg",
  296. "text" => "DuckDuckGo"
  297. ],
  298. [
  299. "value" => "brave",
  300. "text" => "Brave"
  301. ],
  302. [
  303. "value" => "yandex",
  304. "text" => "Yandex"
  305. ],
  306. [
  307. "value" => "google",
  308. "text" => "Google"
  309. ],
  310. [
  311. "value" => "startpage",
  312. "text" => "Startpage"
  313. ],
  314. [
  315. "value" => "qwant",
  316. "text" => "Qwant"
  317. ],
  318. [
  319. "value" => "baidu",
  320. "text" => "Baidu"
  321. ],
  322. [
  323. "value" => "coccoc",
  324. "text" => "Cốc Cốc"
  325. ],
  326. [
  327. "value" => "solofield",
  328. "text" => "Solofield"
  329. ]
  330. ]
  331. ],
  332. [
  333. "description" => "News",
  334. "parameter" => "scraper_news",
  335. "options" => [
  336. [
  337. "value" => "ddg",
  338. "text" => "DuckDuckGo"
  339. ],
  340. [
  341. "value" => "brave",
  342. "text" => "Brave"
  343. ],
  344. [
  345. "value" => "google",
  346. "text" => "Google"
  347. ],
  348. [
  349. "value" => "startpage",
  350. "text" => "Startpage"
  351. ],
  352. [
  353. "value" => "qwant",
  354. "text" => "Qwant"
  355. ],
  356. [
  357. "value" => "yep",
  358. "text" => "Yep"
  359. ],
  360. [
  361. "value" => "mojeek",
  362. "text" => "Mojeek"
  363. ],
  364. [
  365. "value" => "baidu",
  366. "text" => "Baidu"
  367. ]
  368. ]
  369. ],
  370. [
  371. "description" => "Music",
  372. "parameter" => "scraper_music",
  373. "options" => [
  374. [
  375. "value" => "sc",
  376. "text" => "SoundCloud"
  377. ]//,
  378. //[
  379. // "value" => "spotify",
  380. // "text" => "Spotify"
  381. //]
  382. ]
  383. ]
  384. ]
  385. ]
  386. ];
  387. /*
  388. Set theme collection
  389. */
  390. $themes = glob("static/themes/*");
  391. $settings[0]["settings"][1]["options"][] = [
  392. "value" => "Dark",
  393. "text" => "Dark"
  394. ];
  395. foreach($themes as $theme){
  396. $theme = explode(".", basename($theme))[0];
  397. $settings[0]["settings"][1]["options"][] = [
  398. "value" => $theme,
  399. "text" => $theme
  400. ];
  401. }
  402. /*
  403. Set cookies
  404. */
  405. if($_POST){
  406. $loop = &$_POST;
  407. }elseif(count($_GET) !== 0){
  408. // redirect user to front page
  409. $loop = &$_GET;
  410. header("Location: /");
  411. }else{
  412. // refresh cookie dates
  413. $loop = &$_COOKIE;
  414. }
  415. foreach($loop as $key => $value){
  416. if($key == "theme"){
  417. if($value == config::DEFAULT_THEME){
  418. unset($_COOKIE[$key]);
  419. setcookie(
  420. "theme",
  421. "",
  422. [
  423. "expires" => -1, // removes cookie
  424. "samesite" => "Lax",
  425. "path" => "/"
  426. ]
  427. );
  428. continue;
  429. }
  430. }else{
  431. foreach($settings as $title){
  432. foreach($title["settings"] as $list){
  433. if(
  434. $list["parameter"] == $key &&
  435. $list["options"][0]["value"] == $value
  436. ){
  437. unset($_COOKIE[$key]);
  438. setcookie(
  439. $key,
  440. "",
  441. [
  442. "expires" => -1, // removes cookie
  443. "samesite" => "Lax",
  444. "path" => "/"
  445. ]
  446. );
  447. continue 3;
  448. }
  449. }
  450. }
  451. }
  452. if(!is_string($value)){
  453. continue;
  454. }
  455. $key = trim($key);
  456. $value = trim($value);
  457. $_COOKIE[$key] = $value;
  458. setcookie(
  459. $key,
  460. $value,
  461. [
  462. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  463. "samesite" => "Lax",
  464. "path" => "/"
  465. ]
  466. );
  467. }
  468. include "lib/frontend.php";
  469. $frontend = new frontend();
  470. echo
  471. $frontend->load(
  472. "header_nofilters.html",
  473. [
  474. "title" => "Settings",
  475. "class" => ""
  476. ]
  477. );
  478. $left =
  479. '<h1>Settings</h1>' .
  480. '<form method="post" autocomplete="off">' .
  481. '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.';
  482. $c = count($_COOKIE);
  483. $code = "";
  484. if($c !== 0){
  485. $left .=
  486. '<br><br>Your current cookie looks like this:' .
  487. '<div class="code">';
  488. $ca = 0;
  489. foreach($_COOKIE as $key => $value){
  490. $code .= $key . "=" . $value;
  491. $ca++;
  492. if($ca !== $c){
  493. $code .= "; ";
  494. }
  495. }
  496. $left .= $frontend->highlightcode($code);
  497. $left .= '</div>';
  498. }else{
  499. $left .=
  500. '<br><br>You currently don\'t have any cookies set.';
  501. }
  502. $left .=
  503. '<div class="settings">';
  504. foreach($settings as $title){
  505. $left .= '<h2>' . $title["name"] . '</h2>';
  506. foreach($title["settings"] as $setting){
  507. $left .=
  508. '<div class="setting">' .
  509. '<div class="title">' . $setting["description"] . '</div>' .
  510. '<select name="' . $setting["parameter"] . '">';
  511. if($setting["parameter"] == "theme"){
  512. if(!isset($_COOKIE["theme"])){
  513. $_COOKIE["theme"] = config::DEFAULT_THEME;
  514. }
  515. }
  516. foreach($setting["options"] as $option){
  517. $left .=
  518. '<option value="' . $option["value"] . '"';
  519. if(
  520. isset($_COOKIE[$setting["parameter"]]) &&
  521. $_COOKIE[$setting["parameter"]] == $option["value"]
  522. ){
  523. $left .= ' selected';
  524. }
  525. $left .= '>' . $option["text"] . '</option>';
  526. }
  527. $left .= '</select></div>';
  528. }
  529. }
  530. $left .=
  531. '</div>' .
  532. '<div class="settings-submit">' .
  533. '<input type="submit" value="Update settings!">' .
  534. '<a href="../">&lt; Go back</a>' .
  535. '</div>' .
  536. '</form>';
  537. if(count($_GET) === 0){
  538. $code = [];
  539. foreach($_COOKIE as $key => $value){
  540. $code[] = rawurlencode($key) . "=" . rawurlencode($value);
  541. }
  542. $code = implode("&", $code);
  543. if($code != ""){
  544. $code = "?" . $code;
  545. }
  546. echo
  547. $frontend->load(
  548. "search.html",
  549. [
  550. "timetaken" => null,
  551. "class" => "",
  552. "right-left" =>
  553. '<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>' .
  554. '<a href="settings' . $code . '">Bookmark me!</a>' .
  555. '</div>',
  556. "right-right" => "",
  557. "left" => $left
  558. ]
  559. );
  560. }