summaryrefslogtreecommitdiff
path: root/api/index.php
blob: b8a6d4c4a5807f924879abb4b97c19de54710fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
	error_reporting(E_ERROR | E_PARSE);

	require_once "../config.php";

	set_include_path(get_include_path() . PATH_SEPARATOR .
		dirname(__FILE__) . PATH_SEPARATOR .
		dirname(dirname(__FILE__)) . PATH_SEPARATOR .
		dirname(dirname(__FILE__)) . "/include" );

	function __autoload($class) {
		$file = "classes/".strtolower(basename($class)).".php";
		if (file_exists($file)) {
			require $file;
		}
	}

	require_once "db.php";
	require_once "db-prefs.php";
	require_once "functions.php";

	chdir("..");

	if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT) {
		ob_start("ob_gzhandler");
	}

	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

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

	session_name($session_name);

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

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

		if ($input) $_REQUEST = $input;
	}

	if ($_REQUEST["sid"]) {
		session_id($_REQUEST["sid"]);
	}

	session_start();

	if (!init_connection($link)) return;

	$method = strtolower($_REQUEST["op"]);

	$handler = new API($link, $_REQUEST);

	if ($handler->before($method)) {
		if ($method && method_exists($handler, $method)) {
			$handler->$method();
		} else if (method_exists($handler, 'index')) {
			$handler->index($method);
		}
		$handler->after();
	}

	db_close($link);

?>