settings.php 11 KB

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