]> git.wh0rd.org - tt-rss.git/blob - api/index.php
2d555678fec25ffb9d523294bbab5b4809ccf17b
[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 require_once "db.php";
14 require_once "db-prefs.php";
15 require_once "functions.php";
16
17 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
18 function_exists("ob_gzhandler")) {
19
20 ob_start("ob_gzhandler");
21 }
22
23 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
24
25 $session_expire = SESSION_EXPIRE_TIME; //seconds
26 $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";
27
28 session_name($session_name);
29
30 $input = file_get_contents("php://input");
31
32 if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
33 // Override $_REQUEST with JSON-encoded data if available
34 // fallback on HTTP parameters
35 if ($input) {
36 $input = json_decode($input, true);
37 if ($input) $_REQUEST = $input;
38 }
39 } else {
40 // Accept JSON only
41 $input = json_decode($input, true);
42 $_REQUEST = $input;
43 }
44
45 if ($_REQUEST["sid"]) {
46 session_id($_REQUEST["sid"]);
47 }
48
49 session_start();
50
51 if (!init_connection($link)) return;
52
53 $method = strtolower($_REQUEST["op"]);
54
55 $handler = new API($link, $_REQUEST);
56
57 if ($handler->before($method)) {
58 if ($method && method_exists($handler, $method)) {
59 $handler->$method();
60 } else if (method_exists($handler, 'index')) {
61 $handler->index($method);
62 }
63 $handler->after();
64 }
65
66 db_close($link);
67
68 ?>