api: fix some php8 warnings (3)

This commit is contained in:
Andrew Dolgov 2021-02-09 08:47:41 +03:00
parent f6f0f21664
commit aba028a375
2 changed files with 18 additions and 18 deletions

View File

@ -41,11 +41,11 @@
} }
} else { } else {
// Accept JSON only // Accept JSON only
$input = json_decode($input, true); $input = json_decode((string)$input, true);
$_REQUEST = $input; $_REQUEST = $input;
} }
if ($_REQUEST["sid"]) { if (!empty($_REQUEST["sid"])) {
session_id($_REQUEST["sid"]); session_id($_REQUEST["sid"]);
@session_start(); @session_start();
} else if (defined('_API_DEBUG_HTTP_ENABLED')) { } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
@ -56,7 +56,7 @@
if (!init_plugins()) return; if (!init_plugins()) return;
if ($_SESSION["uid"]) { if (!empty($_SESSION["uid"])) {
if (!validate_session()) { if (!validate_session()) {
header("Content-Type: text/json"); header("Content-Type: text/json");
@ -77,7 +77,7 @@
if ($handler->before($method)) { if ($handler->before($method)) {
if ($method && method_exists($handler, $method)) { if ($method && method_exists($handler, $method)) {
$handler->$method(); $handler->$method();
} else if (method_exists($handler, 'index')) { } else /* if (method_exists($handler, 'index')) */ {
$handler->index($method); $handler->index($method);
} }
$handler->after(); $handler->after();

View File

@ -16,12 +16,12 @@ class API extends Handler {
if (parent::before($method)) { if (parent::before($method)) {
header("Content-Type: text/json"); header("Content-Type: text/json");
if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") { if (empty($_SESSION["uid"]) && $method != "login" && $method != "isloggedin") {
$this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN')); $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN'));
return false; return false;
} }
if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) { if (!empty($_SESSION["uid"]) && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) {
$this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED')); $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED'));
return false; return false;
} }
@ -120,7 +120,7 @@ class API extends Handler {
$unread_only = self::param_to_bool(clean($_REQUEST["unread_only"] ?? 0)); $unread_only = self::param_to_bool(clean($_REQUEST["unread_only"] ?? 0));
$limit = (int) clean($_REQUEST["limit"] ?? 0); $limit = (int) clean($_REQUEST["limit"] ?? 0);
$offset = (int) clean($_REQUEST["offset"] ?? 0); $offset = (int) clean($_REQUEST["offset"] ?? 0);
$include_nested = self::param_to_bool(clean($_REQUEST["include_nested"])); $include_nested = self::param_to_bool(clean($_REQUEST["include_nested"] ?? false));
$feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested); $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested);
@ -128,9 +128,9 @@ class API extends Handler {
} }
function getCategories() { function getCategories() {
$unread_only = self::param_to_bool(clean($_REQUEST["unread_only"])); $unread_only = self::param_to_bool(clean($_REQUEST["unread_only"] ?? false));
$enable_nested = self::param_to_bool(clean($_REQUEST["enable_nested"])); $enable_nested = self::param_to_bool(clean($_REQUEST["enable_nested"] ?? false));
$include_empty = self::param_to_bool(clean($_REQUEST['include_empty'])); $include_empty = self::param_to_bool(clean($_REQUEST['include_empty'] ?? false));
// TODO do not return empty categories, return Uncategorized and standard virtual cats // TODO do not return empty categories, return Uncategorized and standard virtual cats
@ -195,7 +195,7 @@ class API extends Handler {
if (!$limit || $limit >= 200) $limit = 200; if (!$limit || $limit >= 200) $limit = 200;
$offset = (int)clean($_REQUEST["skip"]); $offset = (int)clean($_REQUEST["skip"]);
$filter = clean($_REQUEST["filter"]); $filter = clean($_REQUEST["filter"] ?? "");
$is_cat = self::param_to_bool(clean($_REQUEST["is_cat"])); $is_cat = self::param_to_bool(clean($_REQUEST["is_cat"]));
$show_excerpt = self::param_to_bool(clean($_REQUEST["show_excerpt"])); $show_excerpt = self::param_to_bool(clean($_REQUEST["show_excerpt"]));
$show_content = self::param_to_bool(clean($_REQUEST["show_content"])); $show_content = self::param_to_bool(clean($_REQUEST["show_content"]));
@ -206,11 +206,11 @@ class API extends Handler {
$include_nested = self::param_to_bool(clean($_REQUEST["include_nested"])); $include_nested = self::param_to_bool(clean($_REQUEST["include_nested"]));
$sanitize_content = !isset($_REQUEST["sanitize"]) || $sanitize_content = !isset($_REQUEST["sanitize"]) ||
self::param_to_bool($_REQUEST["sanitize"]); self::param_to_bool($_REQUEST["sanitize"]);
$force_update = self::param_to_bool(clean($_REQUEST["force_update"])); $force_update = self::param_to_bool(clean($_REQUEST["force_update"] ?? false));
$has_sandbox = self::param_to_bool(clean($_REQUEST["has_sandbox"])); $has_sandbox = self::param_to_bool(clean($_REQUEST["has_sandbox"] ?? false));
$excerpt_length = (int)clean($_REQUEST["excerpt_length"]); $excerpt_length = (int)clean($_REQUEST["excerpt_length"] ?? 0);
$check_first_id = (int)clean($_REQUEST["check_first_id"]); $check_first_id = (int)clean($_REQUEST["check_first_id"] ?? 0);
$include_header = self::param_to_bool(clean($_REQUEST["include_header"])); $include_header = self::param_to_bool(clean($_REQUEST["include_header"] ?? false));
$_SESSION['hasSandbox'] = $has_sandbox; $_SESSION['hasSandbox'] = $has_sandbox;
@ -218,7 +218,7 @@ class API extends Handler {
/* do not rely on params below */ /* do not rely on params below */
$search = clean($_REQUEST["search"]); $search = clean($_REQUEST["search"] ?? "");
list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset, list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset,
$filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order,