1
0

settings.php 8.3 KB

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