index.php 1.65 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

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

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

13 14
	define('TTRSS_SESSION_NAME', 'ttrss_api_sid');

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

20 21
	define('AUTH_DISABLE_OTP', true);

22 23 24
	if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
			function_exists("ob_gzhandler")) {

25 26 27
		ob_start("ob_gzhandler");
	}

28
	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
Andrew Dolgov's avatar
Andrew Dolgov committed
29 30 31 32

	$session_expire = SESSION_EXPIRE_TIME; //seconds
	$session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";

33 34
	session_name($session_name);

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

37 38 39 40 41 42 43 44 45
	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
46
		$input = json_decode($input, true);
47
		$_REQUEST = $input;
48 49
	}

50 51 52 53
	if ($_REQUEST["sid"]) {
		session_id($_REQUEST["sid"]);
	}

Andrew Dolgov's avatar
Andrew Dolgov committed
54 55
	session_start();

Andrew Dolgov's avatar
Andrew Dolgov committed
56
	if (!init_connection($link)) return;
Andrew Dolgov's avatar
Andrew Dolgov committed
57

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

Andrew Dolgov's avatar
Andrew Dolgov committed
60
	$handler = new API($link, $_REQUEST);
61

Andrew Dolgov's avatar
Andrew Dolgov committed
62 63 64 65 66 67 68
	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
69 70 71
	}

	db_close($link);
72

Andrew Dolgov's avatar
Andrew Dolgov committed
73
?>