PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/api/index.php

https://github.com/krihal/Tiny-Tiny-RSS
PHP | 73 lines | 50 code | 20 blank | 3 comment | 15 complexity | c13640e6b5a0f213b3b4f71a81ae6e18 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-3.0, GPL-2.0
  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. require_once "db.php";
  11. require_once "db-prefs.php";
  12. require_once "functions.php";
  13. require_once "sessions.php";
  14. define('AUTH_DISABLE_OTP', true);
  15. if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
  16. function_exists("ob_gzhandler")) {
  17. ob_start("ob_gzhandler");
  18. } else {
  19. ob_start();
  20. }
  21. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  22. $input = file_get_contents("php://input");
  23. if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
  24. // Override $_REQUEST with JSON-encoded data if available
  25. // fallback on HTTP parameters
  26. if ($input) {
  27. $input = json_decode($input, true);
  28. if ($input) $_REQUEST = $input;
  29. }
  30. } else {
  31. // Accept JSON only
  32. $input = json_decode($input, true);
  33. $_REQUEST = $input;
  34. }
  35. if ($_REQUEST["sid"]) {
  36. session_id($_REQUEST["sid"]);
  37. }
  38. @session_start();
  39. if (!init_connection($link)) return;
  40. $method = strtolower($_REQUEST["op"]);
  41. $handler = new API($link, $_REQUEST);
  42. if ($handler->before($method)) {
  43. if ($method && method_exists($handler, $method)) {
  44. $handler->$method();
  45. } else if (method_exists($handler, 'index')) {
  46. $handler->index($method);
  47. }
  48. $handler->after();
  49. }
  50. db_close($link);
  51. header("Api-Content-Length: " . ob_get_length());
  52. ob_end_flush();
  53. ?>