]> git.wh0rd.org - tt-rss.git/blame - api/index.php
rework class system to use subdirectories
[tt-rss.git] / api / index.php
CommitLineData
378a548c 1<?php
378a548c
AD
2 error_reporting(E_ERROR | E_PARSE);
3
4 require_once "../config.php";
dbaa4e4a 5
4a0500fb
AD
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
f1d65e50 11 chdir("..");
de8260cb 12
4a0500fb
AD
13 require_once "db.php";
14 require_once "db-prefs.php";
15 require_once "functions.php";
378a548c 16
6a79e8af
AD
17 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
18 function_exists("ob_gzhandler")) {
19
70543b6a
AD
20 ob_start("ob_gzhandler");
21 }
22
dbaa4e4a 23 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
378a548c
AD
24
25 $session_expire = SESSION_EXPIRE_TIME; //seconds
26 $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";
27
3bb7e191
AD
28 session_name($session_name);
29
90e71380
AD
30 $input = file_get_contents("php://input");
31
32 // Override $_REQUEST with JSON-encoded data if available
33 if ($input) {
34 $input = json_decode($input, true);
35
de8260cb 36 if ($input) $_REQUEST = $input;
90e71380
AD
37 }
38
3bb7e191
AD
39 if ($_REQUEST["sid"]) {
40 session_id($_REQUEST["sid"]);
41 }
42
378a548c
AD
43 session_start();
44
de8260cb 45 if (!init_connection($link)) return;
378a548c 46
de8260cb 47 $method = strtolower($_REQUEST["op"]);
378a548c 48
de8260cb 49 $handler = new API($link, $_REQUEST);
b792cd70 50
de8260cb
AD
51 if ($handler->before($method)) {
52 if ($method && method_exists($handler, $method)) {
53 $handler->$method();
54 } else if (method_exists($handler, 'index')) {
55 $handler->index($method);
56 }
57 $handler->after();
378a548c
AD
58 }
59
60 db_close($link);
dbaa4e4a 61
378a548c 62?>