]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | error_reporting(E_ERROR | E_PARSE); | |
3 | ||
4 | require_once "../config.php"; | |
5 | ||
6 | set_include_path(dirname(__FILE__) . PATH_SEPARATOR . | |
7 | dirname(dirname(__FILE__)) . PATH_SEPARATOR . | |
8 | dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR . | |
9 | get_include_path()); | |
10 | ||
11 | chdir(".."); | |
12 | ||
13 | define('TTRSS_SESSION_NAME', 'ttrss_api_sid'); | |
14 | define('NO_SESSION_AUTOSTART', true); | |
15 | ||
16 | require_once "autoload.php"; | |
17 | require_once "db.php"; | |
18 | require_once "db-prefs.php"; | |
19 | require_once "functions.php"; | |
20 | require_once "sessions.php"; | |
21 | ||
22 | ini_set('session.use_cookies', 0); | |
23 | ini_set("session.gc_maxlifetime", 86400); | |
24 | ||
25 | define('AUTH_DISABLE_OTP', true); | |
26 | ||
27 | if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT && | |
28 | function_exists("ob_gzhandler")) { | |
29 | ||
30 | ob_start("ob_gzhandler"); | |
31 | } else { | |
32 | ob_start(); | |
33 | } | |
34 | ||
35 | $input = file_get_contents("php://input"); | |
36 | ||
37 | if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) { | |
38 | // Override $_REQUEST with JSON-encoded data if available | |
39 | // fallback on HTTP parameters | |
40 | if ($input) { | |
41 | $input = json_decode($input, true); | |
42 | if ($input) $_REQUEST = $input; | |
43 | } | |
44 | } else { | |
45 | // Accept JSON only | |
46 | $input = json_decode($input, true); | |
47 | $_REQUEST = $input; | |
48 | } | |
49 | ||
50 | if ($_REQUEST["sid"]) { | |
51 | session_id($_REQUEST["sid"]); | |
52 | @session_start(); | |
53 | } else if (defined('_API_DEBUG_HTTP_ENABLED')) { | |
54 | @session_start(); | |
55 | } | |
56 | ||
57 | startup_gettext(); | |
58 | ||
59 | if (!init_plugins()) return; | |
60 | ||
61 | if ($_SESSION["uid"]) { | |
62 | if (!validate_session()) { | |
63 | header("Content-Type: text/json"); | |
64 | ||
65 | print json_encode(array("seq" => -1, | |
66 | "status" => 1, | |
67 | "content" => array("error" => "NOT_LOGGED_IN"))); | |
68 | ||
69 | return; | |
70 | } | |
71 | ||
72 | load_user_plugins( $_SESSION["uid"]); | |
73 | } | |
74 | ||
75 | $method = strtolower($_REQUEST["op"]); | |
76 | ||
77 | $handler = new API($_REQUEST); | |
78 | ||
79 | if ($handler->before($method)) { | |
80 | if ($method && method_exists($handler, $method)) { | |
81 | $handler->$method(); | |
82 | } else if (method_exists($handler, 'index')) { | |
83 | $handler->index($method); | |
84 | } | |
85 | $handler->after(); | |
86 | } | |
87 | ||
88 | header("Api-Content-Length: " . ob_get_length()); | |
89 | ||
90 | ob_end_flush(); | |
91 |