index.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. error_reporting(E_ERROR | E_PARSE);
  3. require_once "../config.php";
  4. set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
  5. dirname(dirname(__FILE__)) . PATH_SEPARATOR .
  6. dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
  7. get_include_path());
  8. chdir("..");
  9. define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
  10. define('NO_SESSION_AUTOSTART', true);
  11. require_once "autoload.php";
  12. require_once "db.php";
  13. require_once "db-prefs.php";
  14. require_once "functions.php";
  15. require_once "sessions.php";
  16. ini_set("session.gc_maxlifetime", 86400);
  17. define('AUTH_DISABLE_OTP', true);
  18. if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
  19. function_exists("ob_gzhandler")) {
  20. ob_start("ob_gzhandler");
  21. } else {
  22. ob_start();
  23. }
  24. $input = file_get_contents("php://input");
  25. if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
  26. // Override $_REQUEST with JSON-encoded data if available
  27. // fallback on HTTP parameters
  28. if ($input) {
  29. $input = json_decode($input, true);
  30. if ($input) $_REQUEST = $input;
  31. }
  32. } else {
  33. // Accept JSON only
  34. $input = json_decode($input, true);
  35. $_REQUEST = $input;
  36. }
  37. if ($_REQUEST["sid"]) {
  38. session_id($_REQUEST["sid"]);
  39. @session_start();
  40. } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
  41. @session_start();
  42. }
  43. startup_gettext();
  44. if (!init_plugins()) return;
  45. if ($_SESSION["uid"]) {
  46. if (!validate_session()) {
  47. header("Content-Type: text/json");
  48. print json_encode(array("seq" => -1,
  49. "status" => 1,
  50. "content" => array("error" => "NOT_LOGGED_IN")));
  51. return;
  52. }
  53. load_user_plugins( $_SESSION["uid"]);
  54. }
  55. $method = strtolower($_REQUEST["op"]);
  56. $handler = new API($_REQUEST);
  57. if ($handler->before($method)) {
  58. if ($method && method_exists($handler, $method)) {
  59. $handler->$method();
  60. } else if (method_exists($handler, 'index')) {
  61. $handler->index($method);
  62. }
  63. $handler->after();
  64. }
  65. header("Api-Content-Length: " . ob_get_length());
  66. ob_end_flush();