settings.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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_api",
  136. "text" => "Google API"
  137. ],
  138. [
  139. "value" => "google_cse",
  140. "text" => "Google CSE"
  141. ],
  142. [
  143. "value" => "yahoo_japan",
  144. "text" => "Yahoo! JAPAN",
  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_api",
  226. "text" => "Google API"
  227. ],
  228. [
  229. "value" => "google_cse",
  230. "text" => "Google CSE"
  231. ],
  232. [
  233. "value" => "yahoo_japan",
  234. "text" => "Yahoo! JAPAN",
  235. ],
  236. [
  237. "value" => "startpage",
  238. "text" => "Startpage"
  239. ],
  240. [
  241. "value" => "qwant",
  242. "text" => "Qwant"
  243. ],
  244. [
  245. "value" => "yep",
  246. "text" => "Yep"
  247. ],
  248. [
  249. "value" => "baidu",
  250. "text" => "Baidu"
  251. ],
  252. [
  253. "value" => "solofield",
  254. "text" => "Solofield"
  255. ],
  256. [
  257. "value" => "pinterest",
  258. "text" => "Pinterest"
  259. ],
  260. [
  261. "value" => "cara",
  262. "text" => "Cara"
  263. ],
  264. [
  265. "value" => "flickr",
  266. "text" => "Flickr"
  267. ],
  268. [
  269. "value" => "pexels",
  270. "text" => "Pexels"
  271. ],
  272. [
  273. "value" => "pixabay",
  274. "text" => "Pixabay"
  275. ],
  276. [
  277. "value" => "unsplash",
  278. "text" => "Unsplash"
  279. ],
  280. [
  281. "value" => "fivehpx",
  282. "text" => "500px"
  283. ],
  284. [
  285. "value" => "vsco",
  286. "text" => "VSCO"
  287. ],
  288. [
  289. "value" => "imgur",
  290. "text" => "Imgur"
  291. ],
  292. [
  293. "value" => "ftm",
  294. "text" => "FindThatMeme"
  295. ]
  296. ]
  297. ],
  298. [
  299. "description" => "Videos",
  300. "parameter" => "scraper_videos",
  301. "options" => [
  302. [
  303. "value" => "yt",
  304. "text" => "YouTube"
  305. ],
  306. [
  307. "value" => "vimeo",
  308. "text" => "Vimeo"
  309. ],
  310. [
  311. "value" => "sepiasearch",
  312. "text" => "Sepia Search"
  313. ],
  314. [
  315. "value" => "ddg",
  316. "text" => "DuckDuckGo"
  317. ],
  318. [
  319. "value" => "brave",
  320. "text" => "Brave"
  321. ],
  322. [
  323. "value" => "yandex",
  324. "text" => "Yandex"
  325. ],
  326. [
  327. "value" => "google",
  328. "text" => "Google"
  329. ],
  330. [
  331. "value" => "yahoo_japan",
  332. "text" => "Yahoo! JAPAN",
  333. ],
  334. [
  335. "value" => "startpage",
  336. "text" => "Startpage"
  337. ],
  338. [
  339. "value" => "qwant",
  340. "text" => "Qwant"
  341. ],
  342. [
  343. "value" => "baidu",
  344. "text" => "Baidu"
  345. ],
  346. [
  347. "value" => "coccoc",
  348. "text" => "Cốc Cốc"
  349. ],
  350. [
  351. "value" => "solofield",
  352. "text" => "Solofield"
  353. ]
  354. ]
  355. ],
  356. [
  357. "description" => "News",
  358. "parameter" => "scraper_news",
  359. "options" => [
  360. [
  361. "value" => "ddg",
  362. "text" => "DuckDuckGo"
  363. ],
  364. [
  365. "value" => "brave",
  366. "text" => "Brave"
  367. ],
  368. [
  369. "value" => "google",
  370. "text" => "Google"
  371. ],
  372. [
  373. "value" => "yahoo_japan",
  374. "text" => "Yahoo! JAPAN",
  375. ],
  376. [
  377. "value" => "startpage",
  378. "text" => "Startpage"
  379. ],
  380. [
  381. "value" => "qwant",
  382. "text" => "Qwant"
  383. ],
  384. [
  385. "value" => "yep",
  386. "text" => "Yep"
  387. ],
  388. [
  389. "value" => "mojeek",
  390. "text" => "Mojeek"
  391. ],
  392. [
  393. "value" => "baidu",
  394. "text" => "Baidu"
  395. ]
  396. ]
  397. ],
  398. [
  399. "description" => "Music",
  400. "parameter" => "scraper_music",
  401. "options" => [
  402. [
  403. "value" => "sc",
  404. "text" => "SoundCloud"
  405. ],
  406. [
  407. "value" => "swisscows",
  408. "text" => "Swisscows"
  409. ]
  410. /*[
  411. "value" => "spotify",
  412. "text" => "Spotify"
  413. ]*/
  414. ]
  415. ]
  416. ]
  417. ]
  418. ];
  419. /*
  420. Set theme collection
  421. */
  422. $themes = glob("static/themes/*");
  423. $settings[0]["settings"][1]["options"][] = [
  424. "value" => "Dark",
  425. "text" => "Dark"
  426. ];
  427. foreach($themes as $theme){
  428. $theme = explode(".", basename($theme))[0];
  429. $settings[0]["settings"][1]["options"][] = [
  430. "value" => $theme,
  431. "text" => $theme
  432. ];
  433. }
  434. /*
  435. Set cookies
  436. */
  437. if($_POST){
  438. $loop = &$_POST;
  439. }elseif(count($_GET) !== 0){
  440. // redirect user to front page
  441. $loop = &$_GET;
  442. header("Location: /");
  443. }else{
  444. // refresh cookie dates
  445. $loop = &$_COOKIE;
  446. }
  447. foreach($loop as $key => $value){
  448. if($key == "theme"){
  449. if($value == config::DEFAULT_THEME){
  450. unset($_COOKIE[$key]);
  451. setcookie(
  452. "theme",
  453. "",
  454. [
  455. "expires" => -1, // removes cookie
  456. "samesite" => "Lax",
  457. "path" => "/"
  458. ]
  459. );
  460. continue;
  461. }
  462. }else{
  463. foreach($settings as $title){
  464. foreach($title["settings"] as $list){
  465. if(
  466. $list["parameter"] == $key &&
  467. $list["options"][0]["value"] == $value
  468. ){
  469. unset($_COOKIE[$key]);
  470. setcookie(
  471. $key,
  472. "",
  473. [
  474. "expires" => -1, // removes cookie
  475. "samesite" => "Lax",
  476. "path" => "/"
  477. ]
  478. );
  479. continue 3;
  480. }
  481. }
  482. }
  483. }
  484. if(!is_string($value)){
  485. continue;
  486. }
  487. $key = trim($key);
  488. $value = trim($value);
  489. $_COOKIE[$key] = $value;
  490. setcookie(
  491. $key,
  492. $value,
  493. [
  494. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  495. "samesite" => "Lax",
  496. "path" => "/"
  497. ]
  498. );
  499. }
  500. include "lib/frontend.php";
  501. $frontend = new frontend();
  502. echo
  503. $frontend->load(
  504. "header_nofilters.html",
  505. [
  506. "title" => "Settings",
  507. "class" => ""
  508. ]
  509. );
  510. $left =
  511. '<h1>Settings</h1>' .
  512. '<form method="post" autocomplete="off">' .
  513. '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.';
  514. $c = count($_COOKIE);
  515. $code = "";
  516. if($c !== 0){
  517. $left .=
  518. '<br><br>Your current cookie looks like this:' .
  519. '<div class="code">';
  520. $ca = 0;
  521. foreach($_COOKIE as $key => $value){
  522. $code .= $key . "=" . $value;
  523. $ca++;
  524. if($ca !== $c){
  525. $code .= "; ";
  526. }
  527. }
  528. $left .= $frontend->highlightcode($code);
  529. $left .= '</div>';
  530. }else{
  531. $left .=
  532. '<br><br>You currently don\'t have any cookies set.';
  533. }
  534. $left .=
  535. '<div class="settings">';
  536. foreach($settings as $title){
  537. $left .= '<h2>' . $title["name"] . '</h2>';
  538. foreach($title["settings"] as $setting){
  539. $left .=
  540. '<div class="setting">' .
  541. '<div class="title">' . $setting["description"] . '</div>' .
  542. '<select name="' . $setting["parameter"] . '">';
  543. if($setting["parameter"] == "theme"){
  544. if(!isset($_COOKIE["theme"])){
  545. $_COOKIE["theme"] = config::DEFAULT_THEME;
  546. }
  547. }
  548. foreach($setting["options"] as $option){
  549. $left .=
  550. '<option value="' . $option["value"] . '"';
  551. if(
  552. isset($_COOKIE[$setting["parameter"]]) &&
  553. $_COOKIE[$setting["parameter"]] == $option["value"]
  554. ){
  555. $left .= ' selected';
  556. }
  557. $left .= '>' . $option["text"] . '</option>';
  558. }
  559. $left .= '</select></div>';
  560. }
  561. }
  562. $left .=
  563. '</div>' .
  564. '<div class="settings-submit">' .
  565. '<input type="submit" value="Update settings!">' .
  566. '<a href="../">&lt; Go back</a>' .
  567. '</div>' .
  568. '</form>';
  569. if(count($_GET) === 0){
  570. $code = [];
  571. foreach($_COOKIE as $key => $value){
  572. $code[] = rawurlencode($key) . "=" . rawurlencode($value);
  573. }
  574. $code = implode("&", $code);
  575. if($code != ""){
  576. $code = "?" . $code;
  577. }
  578. echo
  579. $frontend->load(
  580. "search.html",
  581. [
  582. "timetaken" => null,
  583. "class" => "",
  584. "right-left" =>
  585. '<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>' .
  586. '<a href="settings' . $code . '">Bookmark me!</a>' .
  587. '</div>',
  588. "right-right" => "",
  589. "left" => $left
  590. ]
  591. );
  592. }