required.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * This file contains global settings and things that should be loaded at the
  4. * top of each file.
  5. */
  6. ob_start();
  7. session_start();
  8. header("Access-Control-Allow-Origin: *");
  9. if (isset($_GET['format']) && strtolower($_GET['format']) == 'plain') {
  10. define("JSON", false);
  11. header('Content-Type: text/plain; charset=utf-8');
  12. } else {
  13. define("JSON", true);
  14. header('Content-Type: application/json; charset=utf-8');
  15. }
  16. // Composer
  17. require 'vendor/autoload.php';
  18. // API response formatters
  19. require 'response.php';
  20. // Settings file
  21. require 'settings.php';
  22. // Database settings
  23. // Also inits database and stuff
  24. $database;
  25. try {
  26. $database = new medoo([
  27. 'database_type' => DB_TYPE,
  28. 'database_name' => DB_NAME,
  29. 'server' => DB_SERVER,
  30. 'username' => DB_USER,
  31. 'password' => DB_PASS,
  32. 'charset' => DB_CHARSET
  33. ]);
  34. } catch (Exception $ex) {
  35. header('HTTP/1.1 500 Internal Server Error');
  36. sendError('Database error. Try again later.', true);
  37. }
  38. if (!DEBUG) {
  39. error_reporting(0);
  40. } else {
  41. error_reporting(E_ALL);
  42. ini_set('display_errors', 'On');
  43. }
  44. $VARS;
  45. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  46. $VARS = $_POST;
  47. define("GET", false);
  48. } else {
  49. $VARS = $_GET;
  50. define("GET", true);
  51. }
  52. /**
  53. * Checks if a string or whatever is empty.
  54. * @param $str The thingy to check
  55. * @return boolean True if it's empty or whatever.
  56. */
  57. function is_empty($str) {
  58. return (is_null($str) || !isset($str) || $str == '');
  59. }
  60. if (is_empty($VARS['lang'])) {
  61. require_once "lang/en_us.php";
  62. } else {
  63. switch ($VARS['lang']) {
  64. case "test":
  65. require_once "lang/test.php";
  66. break;
  67. case "en-US":
  68. require_once "lang/en_us.php";
  69. break;
  70. default:
  71. require_once "lang/en_us.php";
  72. }
  73. }