]> git.wh0rd.org - tt-rss.git/blob - api/index.php
move API to classes/
[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 function __autoload($class) {
12 $file = "classes/".strtolower(basename($class)).".php";
13 if (file_exists($file)) {
14 require $file;
15 }
16 }
17
18 require_once "db.php";
19 require_once "db-prefs.php";
20 require_once "functions.php";
21
22 chdir("..");
23
24 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT) {
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 // Override $_REQUEST with JSON-encoded data if available
38 if ($input) {
39 $input = json_decode($input, true);
40
41 if ($input) $_REQUEST = $input;
42 }
43
44 if ($_REQUEST["sid"]) {
45 session_id($_REQUEST["sid"]);
46 }
47
48 session_start();
49
50 if (!init_connection($link)) return;
51
52 $method = strtolower($_REQUEST["op"]);
53
54 $handler = new API($link, $_REQUEST);
55
56 if ($handler->before($method)) {
57 if ($method && method_exists($handler, $method)) {
58 $handler->$method();
59 } else if (method_exists($handler, 'index')) {
60 $handler->index($method);
61 }
62 $handler->after();
63 }
64
65 db_close($link);
66
67 ?>