index.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. header("Content-Type: text/html; charset=UTF-8");
  3. header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  4. header("Cache-Control: post-check=0, pre-check=0", false);
  5. /*
  6. Welcome to the code of #DashboardFE (or #DashFE if you like it better)
  7. If you are reading this, you are in for a big adventure where all your
  8. patience will be tested.
  9. I will try to add comments to all pieces of code that may seem confusing
  10. or hard to understand how they work.
  11. While the frontend is coded in a procedural style, i think i coded it to
  12. be simple enough to be easy to understand. I suggest you to check first
  13. the code of this file, then the code of the included files ("include/init.php" and
  14. include/functions.php") which will give a better understanding on how the FE
  15. operates.
  16. The frontend also does most of the processing of the posts on the server side. Why?
  17. I wanted this frontend to be available to people that does not like to use javascript
  18. or where javascript is not an option (old phones/computers). This makes the
  19. frontend very fast to navigate on older devices. Javascript is used mostly to make the
  20. FE more dynamic in "normal" situations, but it is not required.
  21. This was mostly coded in a non-serious way and i lack many of the training
  22. that most people may have, you could say that i just put things together
  23. until they work, so if you want to help me to make it better, i will be
  24. so grateful
  25. @daisuke@stereophonic.space
  26. */
  27. ini_set('display_errors', 1);
  28. ini_set("log_errors", 1);
  29. error_reporting(1);
  30. ini_set("error_log", "php-error.log");
  31. include "settings.php"; # the general settings of the FE
  32. include "include/init.php"; # initializes the page load with some variables and cookies
  33. include "include/functions.php"; # the functions that are used on all the FE files.
  34. /* if part of the url query is an ajax action, this file will handle it */
  35. if(isset($_GET['action']) || isset($_POST['action'])){
  36. include "action.php";
  37. }
  38. /* if part of the url query is the return of a login attempt, this file will handle it */
  39. if(isset($_GET['code'])){
  40. include "login/activate.php";
  41. }
  42. /* the header and other layout elements will be included only if the
  43. call is not an AJAX request */
  44. if(!isset($_GET['ajax'])){
  45. if ($logedin){
  46. $info = api_get("accounts/verify_credentials");
  47. if($info['error']){
  48. header('Location: ./logout');
  49. }
  50. }
  51. include "layout/header.php";
  52. }
  53. /* Basically the FE looks at the "page" url variable and then checks if the file exist either in the "pages" folder
  54. or in the "modules" folder. If it does, it includes them
  55. Even if the user does not provide a "page" variable, the init.php file can assume one based on other variables, so you should check that file too.
  56. The url query is sanitized so it only allows alphanumeric characters
  57. */
  58. if(isset($_GET['page']) && file_exists("pages/". preg_replace("/[^a-zA-Z0-9]+/", "", $_GET['page']).".php")){
  59. include ("pages/". preg_replace("/[^a-zA-Z0-9]+/", "", $_GET['page']).".php");
  60. } else {
  61. $page = (isset($_GET['page']) ? preg_replace("/[^a-zA-Z0-9]+/", "", $_GET['page']) : "timeline");
  62. if(file_exists("modules/$page.php")){
  63. include ("modules/$page.php");
  64. } else {
  65. $content .= "The page you were looking for was not found";
  66. }
  67. }
  68. /* same as a bit above */
  69. if(!isset($_GET['ajax'])){
  70. include "layout/footer.php";
  71. }
  72. ?>