1
0

settings.php 8.7 KB

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