init.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /* this file initializes some stuff when the user loads a page */
  3. /* fetch the user token from the cookie */
  4. $token = (isset($_COOKIE['token']) ? $_COOKIE['token'] : false);
  5. /* fetch the FE user setings from the cookie or set them if the cookie does not exists */
  6. if (isset($_COOKIE['user_settings'])){
  7. $user_settings = json_decode(base64_decode($_COOKIE['user_settings']),true);
  8. } else {
  9. $user_settings['replies'] = "off";
  10. $user_settings['attach'] = "on";
  11. $user_settings['instance'] = "mastodon.social";
  12. $user_settings['text'] = "off";
  13. $user_settings['reblog'] = "off";
  14. $user_settings['videoloop'] = "off";
  15. $user_settings['theme'] = "default";
  16. $user_settings['nsfw'] = array();
  17. if (isset($_COOKIE['token'])) {
  18. $user_settings['explicit'] = "blur";
  19. } else {
  20. $user_settings['explicit'] = "hide";
  21. }
  22. setrawcookie("user_settings",base64_encode(json_encode($user_settings)),time()+60*60*24*30,'/');
  23. }
  24. if (isset($_COOKIE['theme'])){
  25. $theme = json_decode(base64_decode($_COOKIE['theme']),true);
  26. } else {
  27. $theme = array();
  28. }
  29. /* a lazy way to check if we are logded in, to fix */
  30. $logedin = (isset($_COOKIE['token']) ? true : false);
  31. /* by default the timeline to fetch will be the federated one
  32. but we will infer the timeline to load from the presence of
  33. some common url variables.
  34. */
  35. $tl['mode'] = "federated";
  36. if(isset($_GET['mode'])){
  37. $tl['mode'] = $_GET['mode'];
  38. } else {
  39. foreach ($_GET as $key => $value){
  40. if(in_array($key,array("user","thread","local","tag","list","federated","search"))){
  41. $tl['mode'] = $key;
  42. $tl[$key] = $value;
  43. }
  44. }
  45. }
  46. /* same as above but these are mostly used for AJAX requests */
  47. $tl['next'] = (isset($_GET['next']) ? htmlentities($_GET['next']) : false);
  48. $tl['since'] = (isset($_GET['since']) ? htmlentities($_GET['since']) : false);
  49. $tl['sincen'] = (isset($_GET['sincen']) ? htmlentities($_GET['sincen']) : false);
  50. $srv = $user_settings['instance'];
  51. /* no longer used */
  52. $nocookies = (isset($_COOKIE['user_settings']) ? false : true);
  53. /* these variables will hold the data of the page that will be generated */
  54. $replies = "";
  55. $notes = "";
  56. ?>