ttrss/api/index.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2009-12-16 10:50:32 +01:00
<?php
error_reporting(E_ERROR | E_PARSE);
2021-02-22 15:38:46 +01:00
set_include_path(__DIR__ . PATH_SEPARATOR .
dirname(__DIR__) . PATH_SEPARATOR .
dirname(__DIR__) . "/include" . PATH_SEPARATOR .
get_include_path());
2011-12-11 21:13:14 +01:00
2012-08-16 16:33:08 +02:00
chdir("..");
2011-12-13 12:40:42 +01:00
define('NO_SESSION_AUTOSTART', true);
2012-09-19 10:45:01 +02:00
2013-04-17 13:36:34 +02:00
require_once "autoload.php";
2011-12-11 21:13:14 +01:00
require_once "functions.php";
2012-09-19 10:45:01 +02:00
require_once "sessions.php";
2009-12-16 10:50:32 +01:00
2021-02-22 12:41:09 +01:00
ini_set('session.use_cookies', "0");
ini_set("session.gc_maxlifetime", "86400");
ob_start();
2021-02-23 07:01:27 +01:00
$_REQUEST = json_decode((string)file_get_contents("php://input"), true);
2021-02-09 06:47:41 +01:00
if (!empty($_REQUEST["sid"])) {
2009-12-16 14:40:15 +01:00
session_id($_REQUEST["sid"]);
session_start();
2009-12-16 14:40:15 +01:00
}
startup_gettext();
2013-04-17 16:58:30 +02:00
if (!init_plugins()) return;
2009-12-16 10:50:32 +01:00
2021-02-09 06:47:41 +01:00
if (!empty($_SESSION["uid"])) {
if (!\Sessions\validate_session()) {
2016-07-20 12:55:51 +02:00
header("Content-Type: text/json");
print json_encode([
"seq" => -1,
"status" => API::STATUS_ERR,
"content" => [ "error" => API::E_NOT_LOGGED_IN ]
]);
2016-07-20 12:55:51 +02:00
return;
}
2021-02-09 06:47:41 +01:00
UserHelper::load_user_plugins($_SESSION["uid"]);
2016-07-20 12:52:22 +02:00
}
$method = strtolower($_REQUEST["op"] ?? "");
2009-12-16 10:50:32 +01:00
2013-05-07 09:35:10 +02:00
$handler = new API($_REQUEST);
2009-12-17 11:31:12 +01:00
2011-12-13 12:40:42 +01:00
if ($handler->before($method)) {
if ($method && method_exists($handler, $method)) {
$handler->$method();
2021-02-09 06:47:41 +01:00
} else /* if (method_exists($handler, 'index')) */ {
2011-12-13 12:40:42 +01:00
$handler->index($method);
}
$handler->after();
2009-12-16 10:50:32 +01:00
}
header("Api-Content-Length: " . ob_get_length());
ob_end_flush();
2017-04-26 19:24:18 +02:00