ttrss/api/index.php

90 lines
1.9 KiB
PHP
Raw Normal View History

2009-12-16 09:50:32 +00:00
<?php
error_reporting(E_ERROR | E_PARSE);
require_once "../config.php";
set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
2011-12-11 20:13:14 +00:00
dirname(dirname(__FILE__)) . PATH_SEPARATOR .
dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
get_include_path());
2011-12-11 20:13:14 +00:00
2012-08-16 14:33:08 +00:00
chdir("..");
2011-12-13 11:40:42 +00:00
2012-09-19 08:45:01 +00:00
define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
define('NO_SESSION_AUTOSTART', true);
2012-09-19 08:45:01 +00:00
2013-04-17 11:36:34 +00:00
require_once "autoload.php";
2011-12-11 20:13:14 +00:00
require_once "db.php";
require_once "db-prefs.php";
require_once "functions.php";
2012-09-19 08:45:01 +00:00
require_once "sessions.php";
2009-12-16 09:50:32 +00:00
2018-10-15 04:37:07 +00:00
ini_set('session.use_cookies', 0);
ini_set("session.gc_maxlifetime", 86400);
2012-03-20 10:45:43 +00:00
if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
function_exists("ob_gzhandler")) {
ob_start("ob_gzhandler");
} else {
ob_start();
}
$input = file_get_contents("php://input");
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
$input = json_decode($input, true);
$_REQUEST = $input;
}
2009-12-16 13:40:15 +00:00
if ($_REQUEST["sid"]) {
session_id($_REQUEST["sid"]);
@session_start();
2013-03-28 07:04:15 +00:00
} else if (defined('_API_DEBUG_HTTP_ENABLED')) {
@session_start();
2009-12-16 13:40:15 +00:00
}
startup_gettext();
2013-04-17 14:58:30 +00:00
if (!init_plugins()) return;
2009-12-16 09:50:32 +00:00
2016-07-20 10:52:22 +00:00
if ($_SESSION["uid"]) {
2016-07-20 10:55:51 +00:00
if (!validate_session()) {
header("Content-Type: text/json");
print json_encode(array("seq" => -1,
"status" => 1,
"content" => array("error" => "NOT_LOGGED_IN")));
return;
}
2016-07-20 10:52:22 +00:00
load_user_plugins( $_SESSION["uid"]);
}
2011-12-13 11:40:42 +00:00
$method = strtolower($_REQUEST["op"]);
2009-12-16 09:50:32 +00:00
2013-05-07 07:35:10 +00:00
$handler = new API($_REQUEST);
2009-12-17 10:31:12 +00:00
2011-12-13 11:40:42 +00:00
if ($handler->before($method)) {
if ($method && method_exists($handler, $method)) {
$handler->$method();
} else if (method_exists($handler, 'index')) {
$handler->index($method);
}
$handler->after();
2009-12-16 09:50:32 +00:00
}
header("Api-Content-Length: " . ob_get_length());
ob_end_flush();
2017-04-26 17:24:18 +00:00