index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 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();