init.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $user_settings = $cookie[$index];
  16. } else {
  17. $user_settings['index'] = 0;
  18. $user_settings[0]['replies'] = "off";
  19. $user_settings[0]['attach'] = "on";
  20. $user_settings[0]['instance'] = "fedi.absturztau.be";
  21. $user_settings[0]['text'] = "off";
  22. $user_settings[0]['reblog'] = "off";
  23. $user_settings[0]['videoloop'] = "off";
  24. $user_settings[0]['theme'] = "default";
  25. $user_settings[0]['nsfw'] = array();
  26. $user_settings[0]['unrollcw'] = "on";
  27. $user_settings[0]['notif'] = "1111";
  28. if (isset($_COOKIE[0]['token'])) {
  29. $user_settings[0]['explicit'] = "blur";
  30. } else {
  31. $user_settings[0]['explicit'] = "hide";
  32. }
  33. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  34. $user_settings = $user_settings[0];
  35. }
  36. if (isset($_COOKIE['theme'])){
  37. $theme = json_decode(base64_decode($_COOKIE['theme']),true);
  38. } else {
  39. $theme = array();
  40. }
  41. /* fetch the user token from the cookie */
  42. $token = (isset($_COOKIE['token']) ? json_decode(base64_decode($_COOKIE['token']),true)[$index] : false);
  43. /* a lazy way to check if we are logded in, to fix */
  44. $logedin = (isset($token[$index]) ? true : false);
  45. /* by default the timeline to fetch will be the federated one
  46. but we will infer the timeline to load from the presence of
  47. some common url variables.
  48. */
  49. $tl['mode'] = "federated";
  50. if(isset($_GET['mode'])){
  51. $tl['mode'] = $_GET['mode'];
  52. } else {
  53. foreach ($_GET as $key => $value){
  54. if(in_array($key,array("user","thread","local","tag","list","federated","search"))){
  55. $tl['mode'] = $key;
  56. $tl[$key] = $value;
  57. }
  58. }
  59. }
  60. /* same as above but these are mostly used for AJAX requests */
  61. $tl['next'] = (isset($_GET['next']) ? htmlentities($_GET['next']) : false);
  62. $tl['since'] = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
  63. $tl['sincen'] = (isset($_GET['sincen']) ? htmlentities($_GET['sincen']) : false);
  64. $srv = $user_settings['instance'];
  65. /* no longer used */
  66. $nocookies = (isset($_COOKIE['user_settings']) ? false : true);
  67. /* these variables will hold the data of the page that will be generated */
  68. $replies = "";
  69. $notes = "";
  70. ?>