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