summaryrefslogtreecommitdiff
path: root/classes/rpc.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/rpc.php')
-rwxr-xr-xclasses/rpc.php104
1 files changed, 64 insertions, 40 deletions
diff --git a/classes/rpc.php b/classes/rpc.php
index 23a45d951..dbb54cec5 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -1,13 +1,16 @@
<?php
class RPC extends Handler_Protected {
- /*function csrf_ignore($method) {
+ /*function csrf_ignore(string $method): bool {
$csrf_ignored = array("completelabels");
return array_search($method, $csrf_ignored) !== false;
}*/
- private function _translations_as_array() {
+ /**
+ * @return array<string, string>
+ */
+ private function _translations_as_array(): array {
global $text_domains;
@@ -37,7 +40,7 @@ class RPC extends Handler_Protected {
}
- function togglepref() {
+ function togglepref(): void {
$key = clean($_REQUEST["key"]);
set_pref($key, !get_pref($key));
$value = get_pref($key);
@@ -45,7 +48,7 @@ class RPC extends Handler_Protected {
print json_encode(array("param" =>$key, "value" => $value));
}
- function setpref() {
+ function setpref(): void {
// set_pref escapes input, so no need to double escape it here
$key = clean($_REQUEST['key']);
$value = $_REQUEST['value'];
@@ -55,7 +58,7 @@ class RPC extends Handler_Protected {
print json_encode(array("param" =>$key, "value" => $value));
}
- function mark() {
+ function mark(): void {
$mark = clean($_REQUEST["mark"]);
$id = clean($_REQUEST["id"]);
@@ -68,7 +71,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function delete() {
+ function delete(): void {
$ids = explode(",", clean($_REQUEST["ids"]));
$ids_qmarks = arr_qmarks($ids);
@@ -81,7 +84,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function publ() {
+ function publ(): void {
$pub = clean($_REQUEST["pub"]);
$id = clean($_REQUEST["id"]);
@@ -94,7 +97,7 @@ class RPC extends Handler_Protected {
print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function getRuntimeInfo() {
+ function getRuntimeInfo(): void {
$reply = [
'runtime-info' => $this->_make_runtime_info()
];
@@ -102,11 +105,11 @@ class RPC extends Handler_Protected {
print json_encode($reply);
}
- function getAllCounters() {
+ function getAllCounters(): void {
@$seq = (int) $_REQUEST['seq'];
- $feed_id_count = (int)$_REQUEST["feed_id_count"];
- $label_id_count = (int)$_REQUEST["label_id_count"];
+ $feed_id_count = (int) ($_REQUEST["feed_id_count"] ?? -1);
+ $label_id_count = (int) ($_REQUEST["label_id_count"] ?? -1);
// it seems impossible to distinguish empty array [] from a null - both become unset in $_REQUEST
// so, count is >= 0 means we had an array, -1 means null
@@ -133,7 +136,7 @@ class RPC extends Handler_Protected {
}
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
- function catchupSelected() {
+ function catchupSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -145,7 +148,7 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function markSelected() {
+ function markSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -157,7 +160,7 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function publishSelected() {
+ function publishSelected(): void {
$ids = array_map("intval", clean($_REQUEST["ids"] ?? []));
$cmode = (int)clean($_REQUEST["cmode"]);
@@ -169,8 +172,8 @@ class RPC extends Handler_Protected {
"feeds" => Article::_feeds_of($ids)]);
}
- function sanityCheck() {
- $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true";
+ function sanityCheck(): void {
+ $_SESSION["hasSandbox"] = self::_param_to_bool($_REQUEST["hasSandbox"] ?? false);
$_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]);
$client_location = $_REQUEST["clientLocation"];
@@ -220,14 +223,14 @@ class RPC extends Handler_Protected {
print "</ul>";
}*/
- function catchupFeed() {
+ function catchupFeed(): void {
$feed_id = clean($_REQUEST['feed_id']);
- $is_cat = clean($_REQUEST['is_cat']) == "true";
+ $is_cat = self::_param_to_bool($_REQUEST['is_cat'] ?? false);
$mode = clean($_REQUEST['mode'] ?? '');
$search_query = clean($_REQUEST['search_query']);
$search_lang = clean($_REQUEST['search_lang']);
- Feeds::_catchup($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
+ Feeds::_catchup($feed_id, $is_cat, null, $mode, [$search_query, $search_lang]);
// return counters here synchronously so that frontend can figure out next unread feed properly
print json_encode(['counters' => Counters::get_all()]);
@@ -235,7 +238,7 @@ class RPC extends Handler_Protected {
//print json_encode(array("message" => "UPDATE_COUNTERS"));
}
- function setWidescreen() {
+ function setWidescreen(): void {
$wide = (int) clean($_REQUEST["wide"]);
set_pref(Prefs::WIDESCREEN_MODE, $wide);
@@ -243,7 +246,7 @@ class RPC extends Handler_Protected {
print json_encode(["wide" => $wide]);
}
- static function updaterandomfeed_real() {
+ static function updaterandomfeed_real(): void {
$default_interval = (int) Prefs::get_default(Prefs::DEFAULT_UPDATE_INTERVAL);
@@ -299,7 +302,8 @@ class RPC extends Handler_Protected {
ttrss_feeds f, ttrss_users u LEFT JOIN ttrss_user_prefs2 p ON
(p.owner_uid = u.id AND profile IS NULL AND pref_name = 'DEFAULT_UPDATE_INTERVAL')
WHERE
- f.owner_uid = u.id
+ f.owner_uid = u.id AND
+ u.access_level NOT IN (".sprintf("%d, %d", UserHelper::ACCESS_LEVEL_DISABLED, UserHelper::ACCESS_LEVEL_READONLY).")
$owner_check_qpart
$update_limit_qpart
$updstart_thresh_qpart
@@ -335,19 +339,22 @@ class RPC extends Handler_Protected {
}
- function updaterandomfeed() {
+ function updaterandomfeed(): void {
self::updaterandomfeed_real();
}
- private function markArticlesById($ids, $cmode) {
+ /**
+ * @param array<int, int> $ids
+ */
+ private function markArticlesById(array $ids, int $cmode): void {
$ids_qmarks = arr_qmarks($ids);
- if ($cmode == 0) {
+ if ($cmode == Article::CATCHUP_MODE_MARK_AS_READ) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
marked = false, last_marked = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
- } else if ($cmode == 1) {
+ } else if ($cmode == Article::CATCHUP_MODE_MARK_AS_UNREAD) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
marked = true, last_marked = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
@@ -360,15 +367,18 @@ class RPC extends Handler_Protected {
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
}
- private function publishArticlesById($ids, $cmode) {
+ /**
+ * @param array<int, int> $ids
+ */
+ private function publishArticlesById(array $ids, int $cmode): void {
$ids_qmarks = arr_qmarks($ids);
- if ($cmode == 0) {
+ if ($cmode == Article::CATCHUP_MODE_MARK_AS_READ) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
published = false, last_published = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
- } else if ($cmode == 1) {
+ } else if ($cmode == Article::CATCHUP_MODE_MARK_AS_UNREAD) {
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
published = true, last_published = NOW()
WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
@@ -381,7 +391,7 @@ class RPC extends Handler_Protected {
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
}
- function log() {
+ function log(): void {
$msg = clean($_REQUEST['msg'] ?? "");
$file = basename(clean($_REQUEST['file'] ?? ""));
$line = (int) clean($_REQUEST['line'] ?? 0);
@@ -395,7 +405,7 @@ class RPC extends Handler_Protected {
}
}
- function checkforupdates() {
+ function checkforupdates(): void {
$rv = ["changeset" => [], "plugins" => []];
$version = Config::get_version(false);
@@ -403,7 +413,7 @@ class RPC extends Handler_Protected {
$git_timestamp = $version["timestamp"] ?? false;
$git_commit = $version["commit"] ?? false;
- if (Config::get(Config::CHECK_FOR_UPDATES) && $_SESSION["access_level"] >= 10 && $git_timestamp) {
+ if (Config::get(Config::CHECK_FOR_UPDATES) && $_SESSION["access_level"] >= UserHelper::ACCESS_LEVEL_ADMIN && $git_timestamp) {
$content = @UrlHelper::fetch(["url" => "https://tt-rss.org/version.json"]);
if ($content) {
@@ -424,7 +434,10 @@ class RPC extends Handler_Protected {
print json_encode($rv);
}
- private function _make_init_params() {
+ /**
+ * @return array<string, mixed>
+ */
+ private function _make_init_params(): array {
$params = array();
foreach ([Prefs::ON_CATCHUP_SHOW_NEXT_FEED, Prefs::HIDE_READ_FEEDS,
@@ -480,7 +493,7 @@ class RPC extends Handler_Protected {
return $params;
}
- private function image_to_base64($filename) {
+ private function image_to_base64(string $filename): string {
if (file_exists($filename)) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
@@ -492,7 +505,10 @@ class RPC extends Handler_Protected {
}
}
- static function _make_runtime_info() {
+ /**
+ * @return array<string, mixed>
+ */
+ static function _make_runtime_info(): array {
$data = array();
$pdo = Db::pdo();
@@ -510,7 +526,7 @@ class RPC extends Handler_Protected {
$data['cdm_expanded'] = get_pref(Prefs::CDM_EXPANDED);
$data["labels"] = Labels::get_all($_SESSION["uid"]);
- if (Config::get(Config::LOG_DESTINATION) == 'sql' && $_SESSION['access_level'] >= 10) {
+ if (Config::get(Config::LOG_DESTINATION) == 'sql' && $_SESSION['access_level'] >= UserHelper::ACCESS_LEVEL_ADMIN) {
if (Config::get(Config::DB_TYPE) == 'pgsql') {
$log_interval = "created_at > NOW() - interval '1 hour'";
} else {
@@ -522,6 +538,7 @@ class RPC extends Handler_Protected {
WHERE
errno NOT IN (".E_USER_NOTICE.", ".E_USER_DEPRECATED.") AND
$log_interval AND
+ errstr NOT LIKE '%Returning bool from comparison function is deprecated%' AND
errstr NOT LIKE '%imagecreatefromstring(): Data is not in a recognized format%'");
$sth->execute();
@@ -560,7 +577,10 @@ class RPC extends Handler_Protected {
return $data;
}
- static function get_hotkeys_info() {
+ /**
+ * @return array<string, array<string, string>>
+ */
+ static function get_hotkeys_info(): array {
$hotkeys = array(
__("Navigation") => array(
"next_feed" => __("Open next feed"),
@@ -640,8 +660,12 @@ class RPC extends Handler_Protected {
return $hotkeys;
}
- // {3} - 3 panel mode only
- // {C} - combined mode only
+ /**
+ * {3} - 3 panel mode only
+ * {C} - combined mode only
+ *
+ * @return array{0: array<int, string>, 1: array<string, string>} $prefixes, $hotkeys
+ */
static function get_hotkeys_map() {
$hotkeys = array(
"k" => "next_feed",
@@ -726,7 +750,7 @@ class RPC extends Handler_Protected {
return array($prefixes, $hotkeys);
}
- function hotkeyHelp() {
+ function hotkeyHelp(): void {
$info = self::get_hotkeys_info();
$imap = self::get_hotkeys_map();
$omap = array();