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

Andrew Dolgov's avatar
Andrew Dolgov committed
13 14 15
	require_once "db.php";
	require_once "db-prefs.php";
	require_once "functions.php";
Andrew Dolgov's avatar
Andrew Dolgov committed
16

17 18 19
	if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
			function_exists("ob_gzhandler")) {

20 21 22
		ob_start("ob_gzhandler");
	}

23
	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
Andrew Dolgov's avatar
Andrew Dolgov committed
24 25 26 27

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

28 29
	session_name($session_name);

30 31 32 33 34 35
	$input = file_get_contents("php://input");

	// Override $_REQUEST with JSON-encoded data if available
	if ($input) {
		$input = json_decode($input, true);

Andrew Dolgov's avatar
Andrew Dolgov committed
36
		if ($input) $_REQUEST = $input;
37 38
	}

39 40 41 42
	if ($_REQUEST["sid"]) {
		session_id($_REQUEST["sid"]);
	}

Andrew Dolgov's avatar
Andrew Dolgov committed
43 44
	session_start();

Andrew Dolgov's avatar
Andrew Dolgov committed
45
	if (!init_connection($link)) return;
Andrew Dolgov's avatar
Andrew Dolgov committed
46

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

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

Andrew Dolgov's avatar
Andrew Dolgov committed
51 52 53 54 55 56 57
	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
58 59 60
	}

	db_close($link);
61

Andrew Dolgov's avatar
Andrew Dolgov committed
62
?>