settings.php 8.8 KB

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