]> git.wh0rd.org - tt-rss.git/blobdiff - api/index.php
support disabling of e-mail digests entirely
[tt-rss.git] / api / index.php
index b8a6d4c4a5807f924879abb4b97c19de54710fd2..3fbf6bf575e914e271080b3a850be667790d9d3f 100644 (file)
@@ -3,55 +3,78 @@
 
        require_once "../config.php";
 
-       set_include_path(get_include_path() . PATH_SEPARATOR .
-               dirname(__FILE__) . PATH_SEPARATOR .
+       set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
                dirname(dirname(__FILE__)) . PATH_SEPARATOR .
-               dirname(dirname(__FILE__)) . "/include" );
+               dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
+               get_include_path());
 
-       function __autoload($class) {
-               $file = "classes/".strtolower(basename($class)).".php";
-               if (file_exists($file)) {
-                       require $file;
-               }
-       }
+       chdir("..");
 
+       define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
+       define('NO_SESSION_AUTOSTART', true);
+
+       require_once "autoload.php";
        require_once "db.php";
        require_once "db-prefs.php";
        require_once "functions.php";
+       require_once "sessions.php";
 
-       chdir("..");
-
-       if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT) {
-               ob_start("ob_gzhandler");
-       }
+       ini_set('session.use_cookies', 0);
+       ini_set("session.gc_maxlifetime", 86400);
 
-       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+       define('AUTH_DISABLE_OTP', true);
 
-       $session_expire = SESSION_EXPIRE_TIME; //seconds
-       $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid_api" : TTRSS_SESSION_NAME . "_api";
+       if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
+                       function_exists("ob_gzhandler")) {
 
-       session_name($session_name);
+               ob_start("ob_gzhandler");
+       } else {
+               ob_start();
+       }
 
        $input = file_get_contents("php://input");
 
-       // Override $_REQUEST with JSON-encoded data if available
-       if ($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);
-
-               if ($input) $_REQUEST = $input;
+               $_REQUEST = $input;
        }
 
        if ($_REQUEST["sid"]) {
                session_id($_REQUEST["sid"]);
+               @session_start();
+       } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
+               @session_start();
        }
 
-       session_start();
+       startup_gettext();
+
+       if (!init_plugins()) return;
 
-       if (!init_connection($link)) return;
+       if ($_SESSION["uid"]) {
+               if (!validate_session()) {
+                       header("Content-Type: text/json");
+
+                       print json_encode(array("seq" => -1,
+                               "status" => 1,
+                               "content" => array("error" => "NOT_LOGGED_IN")));
+
+                       return;
+               }
+
+               load_user_plugins( $_SESSION["uid"]);
+       }
 
        $method = strtolower($_REQUEST["op"]);
 
-       $handler = new API($link, $_REQUEST);
+       $handler = new API($_REQUEST);
 
        if ($handler->before($method)) {
                if ($method && method_exists($handler, $method)) {
@@ -62,6 +85,7 @@
                $handler->after();
        }
 
-       db_close($link);
+       header("Api-Content-Length: " . ob_get_length());
+
+       ob_end_flush();
 
-?>