settings.php 9.2 KB

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