index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. error_reporting(E_ERROR | E_PARSE);
  3. require_once "../config.php";
  4. set_include_path(get_include_path() . PATH_SEPARATOR .
  5. dirname(__FILE__) . PATH_SEPARATOR .
  6. dirname(dirname(__FILE__)) . PATH_SEPARATOR .
  7. dirname(dirname(__FILE__)) . "/include" );
  8. function __autoload($class) {
  9. $file = "classes/".strtolower(basename($class)).".php";
  10. if (file_exists($file)) {
  11. require $file;
  12. }
  13. }
  14. require_once "db.php";
  15. require_once "db-prefs.php";
  16. require_once "functions.php";
  17. chdir("..");
  18. if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
  19. function_exists("ob_gzhandler")) {
  20. ob_start("ob_gzhandler");
  21. }
  22. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  23. $session_expire = SESSION_EXPIRE_TIME; //seconds
  24. $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";
  25. session_name($session_name);
  26. $input = file_get_contents("php://input");
  27. // Override $_REQUEST with JSON-encoded data if available
  28. if ($input) {
  29. $input = json_decode($input, true);
  30. if ($input) $_REQUEST = $input;
  31. }
  32. if ($_REQUEST["sid"]) {
  33. session_id($_REQUEST["sid"]);
  34. }
  35. session_start();
  36. if (!init_connection($link)) return;
  37. $method = strtolower($_REQUEST["op"]);
  38. $handler = new API($link, $_REQUEST);
  39. if ($handler->before($method)) {
  40. if ($method && method_exists($handler, $method)) {
  41. $handler->$method();
  42. } else if (method_exists($handler, 'index')) {
  43. $handler->index($method);
  44. }
  45. $handler->after();
  46. }
  47. db_close($link);
  48. ?>