init.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. $cookie = json_decode(base64_decode($_COOKIE['user_settings']),true);
  3. if(isset($_GET['switchaccount']) && is_numeric($_GET['switchaccount'])){
  4. if(isset($cookie[$_GET['switchaccount']])){
  5. $cookie['index'] = $_GET['switchaccount'];
  6. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  7. header('Location: ./?mode=home');
  8. die();
  9. }
  10. }
  11. /* this file initializes some stuff when the user loads a page */
  12. $index = isset($cookie['index']) ? $cookie['index'] : 0;
  13. /* fetch the FE user setings from the cookie or set them if the cookie does not exists */
  14. if (isset($_COOKIE['user_settings'])){
  15. if (isset($cookie[$index])){
  16. $user_settings = $cookie[$index];
  17. } else {
  18. $user_settings = $cookie[0];
  19. $index = 0;
  20. $cookie['index'] = 0;
  21. setrawcookie("user_settings", base64_encode(json_encode($cookie)) , time() + 60 * 60 * 24 * 30, '/');
  22. header('Location: ./?mode=home');
  23. }
  24. } else {
  25. $user_settings['index'] = 0;
  26. $user_settings[0]['replies'] = "off";
  27. $user_settings[0]['attach'] = "on";
  28. $user_settings[0]['instance'] = "fedi.absturztau.be";
  29. $user_settings[0]['text'] = "off";
  30. $user_settings[0]['reblog'] = "off";
  31. $user_settings[0]['videoloop'] = "off";
  32. $user_settings[0]['theme'] = "default";
  33. $user_settings[0]['nsfw'] = array();
  34. $user_settings[0]['softmute'] = array();
  35. $user_settings[0]['unrollcw'] = "on";
  36. $user_settings[0]['mute'] = "off";
  37. $user_settings[0]['invidious'] = "";
  38. $user_settings[0]['teddit'] = "";
  39. $user_settings[0]['nitter'] = "";
  40. $user_settings[0]['embyt'] = "off";
  41. $user_settings[0]['linkpv'] = "off";
  42. $user_settings[0]['notif'] = "1111";
  43. if (isset($_COOKIE[0]['token'])) {
  44. $user_settings[0]['explicit'] = "blur";
  45. } else {
  46. $user_settings[0]['explicit'] = "hide";
  47. }
  48. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  49. $user_settings = $user_settings[0];
  50. }
  51. if (isset($_COOKIE['theme'])){
  52. $theme = json_decode(base64_decode($_COOKIE['theme']),true);
  53. } else {
  54. $theme = array();
  55. }
  56. /* fetch the user token from the cookie */
  57. $token = (isset($_COOKIE['token']) ? json_decode(base64_decode($_COOKIE['token']),true)[$index] : false);
  58. /* a lazy way to check if we are logded in, to fix */
  59. $logedin = (isset($token[$index]) ? true : false);
  60. /* by default the timeline to fetch will be the federated one
  61. but we will infer the timeline to load from the presence of
  62. some common url variables.
  63. */
  64. $tl['mode'] = "federated";
  65. if(isset($_GET['mode'])){
  66. $tl['mode'] = $_GET['mode'];
  67. } else {
  68. foreach ($_GET as $key => $value){
  69. if(in_array($key,array("user","thread","local","tag","list","federated","search"))){
  70. $tl['mode'] = $key;
  71. $tl[$key] = $value;
  72. }
  73. }
  74. }
  75. /* same as above but these are mostly used for AJAX requests */
  76. $tl['next'] = (isset($_GET['next']) ? htmlentities($_GET['next']) : false);
  77. $tl['since'] = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
  78. $tl['sincen'] = (isset($_GET['sincen']) ? htmlentities($_GET['sincen']) : false);
  79. $srv = $user_settings['instance'];
  80. /* no longer used */
  81. $nocookies = (isset($_COOKIE['user_settings']) ? false : true);
  82. /* these variables will hold the data of the page that will be generated */
  83. $replies = "";
  84. $notes = "";
  85. ?>