settings.php 8.8 KB

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