settings.php 10 KB

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