index.php 1.94 KB
Newer Older
Andrew Dolgov's avatar
Andrew Dolgov committed
1 2 3 4
<?php
	error_reporting(E_ERROR | E_PARSE);

	require_once "../config.php";
5

6
	set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
Andrew Dolgov's avatar
Andrew Dolgov committed
7
		dirname(dirname(__FILE__)) . PATH_SEPARATOR .
8 9
		dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
  		get_include_path());
Andrew Dolgov's avatar
Andrew Dolgov committed
10

11
	chdir("..");
Andrew Dolgov's avatar
Andrew Dolgov committed
12

13
	define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
14
	define('NO_SESSION_AUTOSTART', true);
15

16
	require_once "autoload.php";
Andrew Dolgov's avatar
Andrew Dolgov committed
17 18 19
	require_once "db.php";
	require_once "db-prefs.php";
	require_once "functions.php";
20
	require_once "sessions.php";
Andrew Dolgov's avatar
Andrew Dolgov committed
21

22 23
	ini_set("session.gc_maxlifetime", 86400);

24 25
	define('AUTH_DISABLE_OTP', true);

26 27 28
	if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
			function_exists("ob_gzhandler")) {

29
		ob_start("ob_gzhandler");
30 31
	} else {
		ob_start();
32 33
	}

34 35
	$input = file_get_contents("php://input");

36 37 38 39 40 41 42 43 44
	if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
		// Override $_REQUEST with JSON-encoded data if available
		// fallback on HTTP parameters
		if ($input) {
			$input = json_decode($input, true);
			if ($input) $_REQUEST = $input;
		}
	} else {
		// Accept JSON only
45
		$input = json_decode($input, true);
46
		$_REQUEST = $input;
47 48
	}

49 50
	if ($_REQUEST["sid"]) {
		session_id($_REQUEST["sid"]);
51
		@session_start();
Andrew Dolgov's avatar
Andrew Dolgov committed
52 53
	} else if (defined('_API_DEBUG_HTTP_ENABLED')) {
		@session_start();
54 55
	}

56 57
	startup_gettext();

Andrew Dolgov's avatar
Andrew Dolgov committed
58
	if (!init_plugins()) return;
Andrew Dolgov's avatar
Andrew Dolgov committed
59

60
	if ($_SESSION["uid"]) {
61 62 63 64 65 66 67 68 69 70
		if (!validate_session()) {
			header("Content-Type: text/json");

			print json_encode(array("seq" => -1,
				"status" => 1,
				"content" => array("error" => "NOT_LOGGED_IN")));

			return;
		}

71 72 73
		load_user_plugins( $_SESSION["uid"]);
	}

Andrew Dolgov's avatar
Andrew Dolgov committed
74
	$method = strtolower($_REQUEST["op"]);
Andrew Dolgov's avatar
Andrew Dolgov committed
75

76
	$handler = new API($_REQUEST);
77

Andrew Dolgov's avatar
Andrew Dolgov committed
78 79 80 81 82 83 84
	if ($handler->before($method)) {
		if ($method && method_exists($handler, $method)) {
			$handler->$method();
		} else if (method_exists($handler, 'index')) {
			$handler->index($method);
		}
		$handler->after();
Andrew Dolgov's avatar
Andrew Dolgov committed
85 86
	}

87 88 89
	header("Api-Content-Length: " . ob_get_length());

	ob_end_flush();
Andrew Dolgov's avatar
Andrew Dolgov committed
90
?>