]> git.wh0rd.org - tt-rss.git/blame - api/index.php
pngcrush.sh
[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
88e8fb3a 6 set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
4a0500fb 7 dirname(dirname(__FILE__)) . PATH_SEPARATOR .
88e8fb3a
AD
8 dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
9 get_include_path());
4a0500fb 10
f1d65e50 11 chdir("..");
de8260cb 12
964f1533 13 define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
9ce7a554 14 define('NO_SESSION_AUTOSTART', true);
964f1533 15
404e2e36 16 require_once "autoload.php";
4a0500fb
AD
17 require_once "db.php";
18 require_once "db-prefs.php";
19 require_once "functions.php";
964f1533 20 require_once "sessions.php";
378a548c 21
8064ca3f 22 ini_set('session.use_cookies', 0);
3f009418
AD
23 ini_set("session.gc_maxlifetime", 86400);
24
02cd6de1
AD
25 define('AUTH_DISABLE_OTP', true);
26
6a79e8af
AD
27 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
28 function_exists("ob_gzhandler")) {
29
70543b6a 30 ob_start("ob_gzhandler");
839b0658
AD
31 } else {
32 ob_start();
70543b6a
AD
33 }
34
90e71380
AD
35 $input = file_get_contents("php://input");
36
6eaf3193
AD
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
90e71380 46 $input = json_decode($input, true);
6eaf3193 47 $_REQUEST = $input;
90e71380
AD
48 }
49
3bb7e191
AD
50 if ($_REQUEST["sid"]) {
51 session_id($_REQUEST["sid"]);
5160620c 52 @session_start();
0bb5833b
AD
53 } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
54 @session_start();
3bb7e191
AD
55 }
56
cd839c98
RR
57 startup_gettext();
58
4a70edea 59 if (!init_plugins()) return;
378a548c 60
5d97019d 61 if ($_SESSION["uid"]) {
4afcf635
AD
62 if (!validate_session()) {
63 header("Content-Type: text/json");
64
65 print json_encode(array("seq" => -1,
66 "status" => 1,
67 "content" => array("error" => "NOT_LOGGED_IN")));
68
69 return;
70 }
71
5d97019d
AD
72 load_user_plugins( $_SESSION["uid"]);
73 }
74
de8260cb 75 $method = strtolower($_REQUEST["op"]);
378a548c 76
6f7798b6 77 $handler = new API($_REQUEST);
b792cd70 78
de8260cb
AD
79 if ($handler->before($method)) {
80 if ($method && method_exists($handler, $method)) {
81 $handler->$method();
82 } else if (method_exists($handler, 'index')) {
83 $handler->index($method);
84 }
85 $handler->after();
378a548c
AD
86 }
87
839b0658
AD
88 header("Api-Content-Length: " . ob_get_length());
89
90 ob_end_flush();
ea79a0e0 91