]> git.wh0rd.org - tt-rss.git/blob - api/index.php
api: use tt-rss session storage
[tt-rss.git] / api / index.php
1 <?php
2 error_reporting(E_ERROR | E_PARSE);
3
4 require_once "../config.php";
5
6 set_include_path(get_include_path() . PATH_SEPARATOR .
7 dirname(__FILE__) . PATH_SEPARATOR .
8 dirname(dirname(__FILE__)) . PATH_SEPARATOR .
9 dirname(dirname(__FILE__)) . "/include" );
10
11 chdir("..");
12
13 define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
14
15 require_once "db.php";
16 require_once "db-prefs.php";
17 require_once "functions.php";
18 require_once "sessions.php";
19
20 define('AUTH_DISABLE_OTP', true);
21
22 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
23 function_exists("ob_gzhandler")) {
24
25 ob_start("ob_gzhandler");
26 }
27
28 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
29
30 $session_expire = SESSION_EXPIRE_TIME; //seconds
31 $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";
32
33 session_name($session_name);
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 }
53
54 session_start();
55
56 if (!init_connection($link)) return;
57
58 $method = strtolower($_REQUEST["op"]);
59
60 $handler = new API($link, $_REQUEST);
61
62 if ($handler->before($method)) {
63 if ($method && method_exists($handler, $method)) {
64 $handler->$method();
65 } else if (method_exists($handler, 'index')) {
66 $handler->index($method);
67 }
68 $handler->after();
69 }
70
71 db_close($link);
72
73 ?>