settings.php 11 KB

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