index.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $method = strtolower($_REQUEST["op"]);
  46. $handler = new API($_REQUEST);
  47. if ($handler->before($method)) {
  48. if ($method && method_exists($handler, $method)) {
  49. $handler->$method();
  50. } else if (method_exists($handler, 'index')) {
  51. $handler->index($method);
  52. }
  53. $handler->after();
  54. }
  55. header("Api-Content-Length: " . ob_get_length());
  56. ob_end_flush();
  57. ?>