index.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.use_cookies', 0);
  17. ini_set("session.gc_maxlifetime", 86400);
  18. define('AUTH_DISABLE_OTP', true);
  19. if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
  20. function_exists("ob_gzhandler")) {
  21. ob_start("ob_gzhandler");
  22. } else {
  23. ob_start();
  24. }
  25. $input = file_get_contents("php://input");
  26. if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
  27. // Override $_REQUEST with JSON-encoded data if available
  28. // fallback on HTTP parameters
  29. if ($input) {
  30. $input = json_decode($input, true);
  31. if ($input) $_REQUEST = $input;
  32. }
  33. } else {
  34. // Accept JSON only
  35. $input = json_decode($input, true);
  36. $_REQUEST = $input;
  37. }
  38. if ($_REQUEST["sid"]) {
  39. session_id($_REQUEST["sid"]);
  40. @session_start();
  41. } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
  42. @session_start();
  43. }
  44. startup_gettext();
  45. if (!init_plugins()) return;
  46. if ($_SESSION["uid"]) {
  47. if (!validate_session()) {
  48. header("Content-Type: text/json");
  49. print json_encode(array("seq" => -1,
  50. "status" => 1,
  51. "content" => array("error" => "NOT_LOGGED_IN")));
  52. return;
  53. }
  54. load_user_plugins( $_SESSION["uid"]);
  55. }
  56. $method = strtolower($_REQUEST["op"]);
  57. $handler = new API($_REQUEST);
  58. if ($handler->before($method)) {
  59. if ($method && method_exists($handler, $method)) {
  60. $handler->$method();
  61. } else if (method_exists($handler, 'index')) {
  62. $handler->index($method);
  63. }
  64. $handler->after();
  65. }
  66. header("Api-Content-Length: " . ob_get_length());
  67. ob_end_flush();