settings.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. /*
  3. Define settings
  4. */
  5. $settings = [
  6. [
  7. "name" => "General",
  8. "settings" => [
  9. [
  10. "description" => "Allow NSFW content",
  11. "parameter" => "nsfw",
  12. "options" => [
  13. [
  14. "value" => "yes",
  15. "text" => "Yes"
  16. ],
  17. [
  18. "value" => "maybe",
  19. "text" => "Maybe"
  20. ],
  21. [
  22. "value" => "no",
  23. "text" => "No"
  24. ]
  25. ]
  26. ],
  27. [
  28. "description" => "Theme",
  29. "parameter" => "theme",
  30. "options" => [
  31. [
  32. "value" => "dark",
  33. "text" => "Gruvbox dark"
  34. ],
  35. [
  36. "value" => "cream",
  37. "text" => "Gruvbox cream"
  38. ]
  39. ]
  40. ],
  41. [
  42. "description" => "Prevent clicking background elements when image viewer is open",
  43. "parameter" => "bg_noclick",
  44. "options" => [
  45. [
  46. "value" => "no",
  47. "text" => "No"
  48. ],
  49. [
  50. "value" => "yes",
  51. "text" => "Yes"
  52. ]
  53. ]
  54. ]
  55. ]
  56. ],
  57. [
  58. "name" => "Scrapers to use",
  59. "settings" => [
  60. [
  61. "description" => "Autocomplete<br><i>Picking <div class=\"code-inline\">Auto</div> changes the source dynamically depending of the page's scraper<br>Picking <div class=\"code-inline\">Disabled</div> disables this feature</i>",
  62. "parameter" => "scraper_ac",
  63. "options" => [
  64. [
  65. "value" => "disabled",
  66. "text" => "Disabled"
  67. ],
  68. [
  69. "value" => "auto",
  70. "text" => "Auto"
  71. ],
  72. [
  73. "value" => "brave",
  74. "text" => "Brave"
  75. ],
  76. [
  77. "value" => "ddg",
  78. "text" => "DuckDuckGo"
  79. ],
  80. [
  81. "value" => "yandex",
  82. "text" => "Yandex"
  83. ],
  84. [
  85. "value" => "google",
  86. "text" => "Google"
  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" => "mojeek",
  132. "text" => "Mojeek"
  133. ],
  134. [
  135. "value" => "marginalia",
  136. "text" => "Marginalia"
  137. ],
  138. [
  139. "value" => "wiby",
  140. "text" => "wiby"
  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" => "mojeek",
  226. "text" => "Mojeek"
  227. ]
  228. ]
  229. ],
  230. [
  231. "description" => "Music",
  232. "parameter" => "scraper_music",
  233. "options" => [
  234. [
  235. "value" => "sc",
  236. "text" => "SoundCloud"
  237. ]
  238. ]
  239. ]
  240. ]
  241. ]
  242. ];
  243. /*
  244. Set cookies
  245. */
  246. if($_POST){
  247. $loop = &$_POST;
  248. }elseif(count($_GET) !== 0){
  249. // redirect user to front page
  250. $loop = &$_GET;
  251. header("Location: /");
  252. }else{
  253. // refresh cookie dates
  254. $loop = &$_COOKIE;
  255. }
  256. foreach($loop as $key => $value){
  257. foreach($settings as $title){
  258. foreach($title["settings"] as $list){
  259. if(
  260. $list["parameter"] == $key &&
  261. $list["options"][0]["value"] == $value
  262. ){
  263. unset($_COOKIE[$key]);
  264. setcookie(
  265. $key,
  266. "",
  267. [
  268. "expires" => -1, // removes cookie
  269. "samesite" => "Strict",
  270. "path" => "/"
  271. ]
  272. );
  273. continue 3;
  274. }
  275. }
  276. }
  277. if(!is_string($value)){
  278. continue;
  279. }
  280. $key = trim($key);
  281. $value = trim($value);
  282. $_COOKIE[$key] = $value;
  283. setcookie(
  284. $key,
  285. $value,
  286. [
  287. "expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
  288. "samesite" => "Strict"
  289. ]
  290. );
  291. }
  292. include "lib/frontend.php";
  293. $frontend = new frontend();
  294. echo
  295. '<!DOCTYPE html>' .
  296. '<html lang="en">' .
  297. '<head>' .
  298. '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">' .
  299. '<title>Settings</title>' .
  300. '<link rel="stylesheet" href="/static/style.css?v4">' .
  301. '<meta name="viewport" content="width=device-width,initial-scale=1">' .
  302. '<meta name="robots" content="index,follow">' .
  303. '<link rel="icon" type="image/x-icon" href="/favicon.ico">' .
  304. '<meta name="description" content="4get.ca: Settings">' .
  305. '<link rel="search" type="application/opensearchdescription+xml" title="4get" href="/opensearch.xml">' .
  306. '</head>' .
  307. '<body' . $frontend->getthemeclass() . '>';
  308. $left =
  309. '<h1>Settings</h1>' .
  310. '<form method="post" autocomplete="off">' .
  311. '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.';
  312. $c = count($_COOKIE);
  313. $code = "";
  314. if($c !== 0){
  315. $left .=
  316. '<br><br>Your current cookie looks like this:' .
  317. '<div class="code">';
  318. $ca = 0;
  319. foreach($_COOKIE as $key => $value){
  320. $code .= $key . "=" . $value;
  321. $ca++;
  322. if($ca !== $c){
  323. $code .= "; ";
  324. }
  325. }
  326. $left .= $frontend->highlightcode($code);
  327. $left .= '</div>';
  328. }else{
  329. $left .=
  330. '<br><br>You currently don\'t have any cookies set.';
  331. }
  332. $left .=
  333. '<div class="settings">';
  334. foreach($settings as $title){
  335. $left .= '<h2>' . $title["name"] . '</h2>';
  336. foreach($title["settings"] as $setting){
  337. $left .=
  338. '<div class="setting">' .
  339. '<div class="title">' . $setting["description"] . '</div>' .
  340. '<select name="' . $setting["parameter"] . '">';
  341. foreach($setting["options"] as $option){
  342. $left .=
  343. '<option value="' . $option["value"] . '"';
  344. if(
  345. isset($_COOKIE[$setting["parameter"]]) &&
  346. $_COOKIE[$setting["parameter"]] == $option["value"]
  347. ){
  348. $left .= ' selected';
  349. }
  350. $left .= '>' . $option["text"] . '</option>';
  351. }
  352. $left .= '</select></div>';
  353. }
  354. }
  355. $left .=
  356. '</div>' .
  357. '<div class="settings-submit">' .
  358. '<input type="submit" value="Update settings!">' .
  359. '<a href="../">&lt; Return to front page</a>' .
  360. '</div>' .
  361. '</form>';
  362. if(count($_GET) === 0){
  363. echo
  364. $frontend->load(
  365. "search.html",
  366. [
  367. "class" => "",
  368. "right-left" =>
  369. '<div class="infobox"><h2>Preference link</h2>Follow this link to auto-apply all cookies. Useful if your browser clears out cookies after a browsing session. Following this link will redirect you to the front page, unless no settings are set.<br><br>' .
  370. '<a href="settings' . rtrim("?" . str_replace("; ", "&", $code), "?") . '">Bookmark me!</a>' .
  371. '</div>',
  372. "right-right" => "",
  373. "left" => $left
  374. ]
  375. );
  376. }