PageRenderTime 74ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/api/index.php

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