Address PHPStan warnings in 'classes/feeds.php'.
Also some minor related tweaks in other classes.
This commit is contained in:
parent
5606e38bff
commit
763515de79
|
@ -409,8 +409,8 @@ class API extends Handler {
|
|||
|
||||
function catchupFeed() {
|
||||
$feed_id = clean($_REQUEST["feed_id"]);
|
||||
$is_cat = clean($_REQUEST["is_cat"]);
|
||||
@$mode = clean($_REQUEST["mode"]);
|
||||
$is_cat = clean($_REQUEST["is_cat"]) == "true";
|
||||
$mode = clean($_REQUEST['mode'] ?? "");
|
||||
|
||||
if (!in_array($mode, ["all", "1day", "1week", "2week"]))
|
||||
$mode = "all";
|
||||
|
|
|
@ -5,6 +5,13 @@ class Debug {
|
|||
const LOG_VERBOSE = 1;
|
||||
const LOG_EXTENDED = 2;
|
||||
|
||||
const ALL_LOG_LEVELS = [
|
||||
Debug::LOG_DISABLED,
|
||||
Debug::LOG_NORMAL,
|
||||
Debug::LOG_VERBOSE,
|
||||
Debug::LOG_EXTENDED,
|
||||
];
|
||||
|
||||
/** @deprecated */
|
||||
public static int $LOG_DISABLED = self::LOG_DISABLED;
|
||||
|
||||
|
@ -43,21 +50,21 @@ class Debug {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Debug::LOG_* $level
|
||||
* @param int $level Debug::LOG_*
|
||||
*/
|
||||
public static function set_loglevel($level): void {
|
||||
public static function set_loglevel(int $level): void {
|
||||
self::$loglevel = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Debug::LOG_*
|
||||
* @return int Debug::LOG_*
|
||||
*/
|
||||
public static function get_loglevel(): int {
|
||||
return self::$loglevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Debug::LOG_* $level
|
||||
* @param int $level Debug::LOG_*
|
||||
*/
|
||||
public static function log(string $message, int $level = Debug::LOG_NORMAL): bool {
|
||||
|
||||
|
|
|
@ -5,8 +5,11 @@ class Feeds extends Handler_Protected {
|
|||
const NEVER_GROUP_FEEDS = [ -6, 0 ];
|
||||
const NEVER_GROUP_BY_DATE = [ -2, -1, -3 ];
|
||||
|
||||
private $viewfeed_timestamp;
|
||||
private $viewfeed_timestamp_last;
|
||||
/** @var int|float int on 64-bit, float on 32-bit */
|
||||
private $viewfeed_timestamp;
|
||||
|
||||
/** @var int|float int on 64-bit, float on 32-bit */
|
||||
private $viewfeed_timestamp_last;
|
||||
|
||||
function csrf_ignore(string $method): bool {
|
||||
$csrf_ignored = array("index");
|
||||
|
@ -14,9 +17,12 @@ class Feeds extends Handler_Protected {
|
|||
return array_search($method, $csrf_ignored) !== false;
|
||||
}
|
||||
|
||||
private function _format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
|
||||
$offset, $override_order = false, $include_children = false, $check_first_id = false,
|
||||
$skip_first_id_check = false, $order_by = false) {
|
||||
/**
|
||||
* @return array{0: array<int, int>, 1: int, 2: int, 3: bool, 4: array<string, mixed>} $topmost_article_ids, $headlines_count, $feed, $disable_cache, $reply
|
||||
*/
|
||||
private function _format_headlines_list(int $feed, string $method, string $view_mode, int $limit, bool $cat_view,
|
||||
int $offset, string $override_order, bool $include_children, bool $check_first_id,
|
||||
bool $skip_first_id_check, string $order_by): array {
|
||||
|
||||
$disable_cache = false;
|
||||
|
||||
|
@ -80,6 +86,8 @@ class Feeds extends Handler_Protected {
|
|||
"include_children" => $include_children,
|
||||
"order_by" => $order_by);
|
||||
|
||||
// Implemented by a plugin, so ignore the undefined 'get_headlines' method.
|
||||
// @phpstan-ignore-next-line
|
||||
$qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
|
||||
$options);
|
||||
}
|
||||
|
@ -433,7 +441,7 @@ class Feeds extends Handler_Protected {
|
|||
return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $reply);
|
||||
}
|
||||
|
||||
function catchupAll() {
|
||||
function catchupAll(): void {
|
||||
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
|
||||
last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?");
|
||||
$sth->execute([$_SESSION['uid']]);
|
||||
|
@ -441,7 +449,7 @@ class Feeds extends Handler_Protected {
|
|||
print json_encode(array("message" => "UPDATE_COUNTERS"));
|
||||
}
|
||||
|
||||
function view() {
|
||||
function view(): void {
|
||||
$reply = array();
|
||||
|
||||
$feed = $_REQUEST["feed"];
|
||||
|
@ -450,7 +458,7 @@ class Feeds extends Handler_Protected {
|
|||
$limit = 30;
|
||||
$cat_view = $_REQUEST["cat"] == "true";
|
||||
$next_unread_feed = $_REQUEST["nuf"] ?? 0;
|
||||
$offset = $_REQUEST["skip"] ?? 0;
|
||||
$offset = (int) ($_REQUEST["skip"] ?? 0);
|
||||
$order_by = $_REQUEST["order_by"] ?? "";
|
||||
$check_first_id = $_REQUEST["fid"] ?? 0;
|
||||
|
||||
|
@ -538,7 +546,10 @@ class Feeds extends Handler_Protected {
|
|||
print json_encode($reply);
|
||||
}
|
||||
|
||||
private function _generate_dashboard_feed() {
|
||||
/**
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
private function _generate_dashboard_feed(): array {
|
||||
$reply = array();
|
||||
|
||||
$reply['headlines']['id'] = -5;
|
||||
|
@ -580,7 +591,10 @@ class Feeds extends Handler_Protected {
|
|||
return $reply;
|
||||
}
|
||||
|
||||
private function _generate_error_feed($error) {
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function _generate_error_feed(string $error): array {
|
||||
$reply = array();
|
||||
|
||||
$reply['headlines']['id'] = -7;
|
||||
|
@ -596,13 +610,13 @@ class Feeds extends Handler_Protected {
|
|||
return $reply;
|
||||
}
|
||||
|
||||
function subscribeToFeed() {
|
||||
function subscribeToFeed(): void {
|
||||
print json_encode([
|
||||
"cat_select" => \Controls\select_feeds_cats("cat")
|
||||
]);
|
||||
}
|
||||
|
||||
function search() {
|
||||
function search(): void {
|
||||
print json_encode([
|
||||
"show_language" => Config::get(Config::DB_TYPE) == "pgsql",
|
||||
"show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0,
|
||||
|
@ -611,7 +625,7 @@ class Feeds extends Handler_Protected {
|
|||
]);
|
||||
}
|
||||
|
||||
function opensite() {
|
||||
function opensite(): void {
|
||||
$feed = ORM::for_table('ttrss_feeds')
|
||||
->find_one((int)$_REQUEST['feed_id']);
|
||||
|
||||
|
@ -628,10 +642,14 @@ class Feeds extends Handler_Protected {
|
|||
print "Feed not found or has an empty site URL.";
|
||||
}
|
||||
|
||||
function updatedebugger() {
|
||||
function updatedebugger(): void {
|
||||
header("Content-type: text/html");
|
||||
|
||||
$xdebug = isset($_REQUEST["xdebug"]) ? (int)$_REQUEST["xdebug"] : 1;
|
||||
$xdebug = isset($_REQUEST["xdebug"]) ? (int)$_REQUEST["xdebug"] : Debug::LOG_VERBOSE;
|
||||
|
||||
if (!in_array($xdebug, Debug::ALL_LOG_LEVELS)) {
|
||||
$xdebug = Debug::LOG_VERBOSE;
|
||||
}
|
||||
|
||||
Debug::set_enabled(true);
|
||||
Debug::set_loglevel($xdebug);
|
||||
|
@ -644,9 +662,9 @@ class Feeds extends Handler_Protected {
|
|||
$sth->execute([$feed_id, $_SESSION['uid']]);
|
||||
|
||||
if (!$sth->fetch()) {
|
||||
print "Access denied.";
|
||||
return;
|
||||
}
|
||||
print "Access denied.";
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -731,7 +749,10 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
}
|
||||
|
||||
static function _catchup($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
|
||||
/**
|
||||
* @param array<int, string> $search
|
||||
*/
|
||||
static function _catchup(string $feed_id_or_tag_name, bool $cat_view, ?int $owner_uid = null, string $mode = 'all', ?array $search = null): void {
|
||||
|
||||
if (!$owner_uid) $owner_uid = $_SESSION['uid'];
|
||||
|
||||
|
@ -785,14 +806,16 @@ class Feeds extends Handler_Protected {
|
|||
$date_qpart = "true";
|
||||
}
|
||||
|
||||
if (is_numeric($feed)) {
|
||||
if (is_numeric($feed_id_or_tag_name)) {
|
||||
$feed_id = (int) $feed_id_or_tag_name;
|
||||
|
||||
if ($cat_view) {
|
||||
|
||||
if ($feed >= 0) {
|
||||
if ($feed_id >= 0) {
|
||||
|
||||
if ($feed > 0) {
|
||||
$children = self::_get_child_cats($feed, $owner_uid);
|
||||
array_push($children, $feed);
|
||||
if ($feed_id > 0) {
|
||||
$children = self::_get_child_cats($feed_id, $owner_uid);
|
||||
array_push($children, $feed_id);
|
||||
$children = array_map("intval", $children);
|
||||
|
||||
$children = join(",", $children);
|
||||
|
@ -810,7 +833,7 @@ class Feeds extends Handler_Protected {
|
|||
(SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
|
||||
$sth->execute([$owner_uid]);
|
||||
|
||||
} else if ($feed == -2) {
|
||||
} else if ($feed_id == -2) {
|
||||
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
|
||||
|
@ -819,18 +842,18 @@ class Feeds extends Handler_Protected {
|
|||
$sth->execute([$owner_uid]);
|
||||
}
|
||||
|
||||
} else if ($feed > 0) {
|
||||
} else if ($feed_id > 0) {
|
||||
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
(SELECT id FROM
|
||||
(SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
|
||||
AND owner_uid = ? AND unread = true AND feed_id = ? AND $date_qpart AND $search_qpart) as tmp)");
|
||||
$sth->execute([$owner_uid, $feed]);
|
||||
$sth->execute([$owner_uid, $feed_id]);
|
||||
|
||||
} else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred
|
||||
} else if ($feed_id < 0 && $feed_id > LABEL_BASE_INDEX) { // special, like starred
|
||||
|
||||
if ($feed == -1) {
|
||||
if ($feed_id == -1) {
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
(SELECT id FROM
|
||||
|
@ -839,7 +862,7 @@ class Feeds extends Handler_Protected {
|
|||
$sth->execute([$owner_uid]);
|
||||
}
|
||||
|
||||
if ($feed == -2) {
|
||||
if ($feed_id == -2) {
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
(SELECT id FROM
|
||||
|
@ -848,7 +871,7 @@ class Feeds extends Handler_Protected {
|
|||
$sth->execute([$owner_uid]);
|
||||
}
|
||||
|
||||
if ($feed == -3) {
|
||||
if ($feed_id == -3) {
|
||||
|
||||
$intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE);
|
||||
|
||||
|
@ -867,7 +890,7 @@ class Feeds extends Handler_Protected {
|
|||
$sth->execute([$owner_uid]);
|
||||
}
|
||||
|
||||
if ($feed == -4) {
|
||||
if ($feed_id == -4) {
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
(SELECT id FROM
|
||||
|
@ -875,10 +898,9 @@ class Feeds extends Handler_Protected {
|
|||
AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
|
||||
$sth->execute([$owner_uid]);
|
||||
}
|
||||
} else if ($feed_id < LABEL_BASE_INDEX) { // label
|
||||
|
||||
} else if ($feed < LABEL_BASE_INDEX) { // label
|
||||
|
||||
$label_id = Labels::feed_to_label_id($feed);
|
||||
$label_id = Labels::feed_to_label_id($feed_id);
|
||||
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
|
@ -887,23 +909,21 @@ class Feeds extends Handler_Protected {
|
|||
AND label_id = ? AND ref_id = article_id
|
||||
AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
|
||||
$sth->execute([$label_id, $owner_uid]);
|
||||
|
||||
}
|
||||
|
||||
} else { // tag
|
||||
$tag_name = $feed_id_or_tag_name;
|
||||
|
||||
$sth = $pdo->prepare("UPDATE ttrss_user_entries
|
||||
SET unread = false, last_read = NOW() WHERE ref_id IN
|
||||
(SELECT id FROM
|
||||
(SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id
|
||||
AND post_int_id = int_id AND tag_name = ?
|
||||
AND ttrss_user_entries.owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
|
||||
$sth->execute([$feed, $owner_uid]);
|
||||
|
||||
$sth->execute([$tag_name, $owner_uid]);
|
||||
}
|
||||
}
|
||||
|
||||
static function _get_counters($feed, $is_cat = false, $unread_only = false,
|
||||
$owner_uid = false) {
|
||||
static function _get_counters(int $feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int {
|
||||
|
||||
$n_feed = (int) $feed;
|
||||
$need_entries = false;
|
||||
|
@ -1002,7 +1022,7 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
function add() {
|
||||
function add(): void {
|
||||
$feed = clean($_REQUEST['feed']);
|
||||
$cat = clean($_REQUEST['cat'] ?? '');
|
||||
$need_auth = isset($_REQUEST['need_auth']);
|
||||
|
@ -1015,7 +1035,7 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array (code => Status code, message => error message if available)
|
||||
* @return array<string, mixed> (code => Status code, message => error message if available)
|
||||
*
|
||||
* 0 - OK, Feed already exists
|
||||
* 1 - OK, Feed added
|
||||
|
@ -1029,8 +1049,7 @@ class Feeds extends Handler_Protected {
|
|||
* 7 - Error while creating feed database entry.
|
||||
* 8 - Permission denied (ACCESS_LEVEL_READONLY).
|
||||
*/
|
||||
static function _subscribe($url, $cat_id = 0,
|
||||
$auth_login = '', $auth_pass = '') : array {
|
||||
static function _subscribe(string $url, int $cat_id = 0, string $auth_login = '', string $auth_pass = ''): array {
|
||||
|
||||
$user = ORM::for_table("ttrss_users")->find_one($_SESSION['uid']);
|
||||
|
||||
|
@ -1109,15 +1128,18 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
static function _get_icon_file($feed_id) {
|
||||
static function _get_icon_file(int $feed_id): string {
|
||||
return Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
|
||||
}
|
||||
|
||||
static function _has_icon($id) {
|
||||
static function _has_icon(int $id): bool {
|
||||
return is_file(Config::get(Config::ICONS_DIR) . "/$id.ico") && filesize(Config::get(Config::ICONS_DIR) . "/$id.ico") > 0;
|
||||
}
|
||||
|
||||
static function _get_icon($id) {
|
||||
/**
|
||||
* @return false|string false if the icon ID was unrecognized, otherwise, the icon identifier string
|
||||
*/
|
||||
static function _get_icon(int $id) {
|
||||
switch ($id) {
|
||||
case 0:
|
||||
return "archive";
|
||||
|
@ -1137,7 +1159,7 @@ class Feeds extends Handler_Protected {
|
|||
} else {
|
||||
$icon = self::_get_icon_file($id);
|
||||
|
||||
if ($icon && file_exists($icon)) {
|
||||
if ($icon && file_exists($icon)) {
|
||||
return Config::get(Config::ICONS_URL) . "/" . basename($icon) . "?" . filemtime($icon);
|
||||
}
|
||||
}
|
||||
|
@ -1147,6 +1169,9 @@ class Feeds extends Handler_Protected {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|int false if the feed couldn't be found by URL+owner, otherwise the feed ID
|
||||
*/
|
||||
static function _find_by_url(string $feed_url, int $owner_uid) {
|
||||
$feed = ORM::for_table('ttrss_feeds')
|
||||
->where('owner_uid', $owner_uid)
|
||||
|
@ -1160,7 +1185,11 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
/** $owner_uid defaults to $_SESSION['uid] */
|
||||
/**
|
||||
* $owner_uid defaults to $_SESSION['uid']
|
||||
*
|
||||
* @return false|int false if the category/feed couldn't be found by title, otherwise its ID
|
||||
*/
|
||||
static function _find_by_title(string $title, bool $cat = false, int $owner_uid = 0) {
|
||||
|
||||
$res = false;
|
||||
|
@ -1184,8 +1213,8 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
static function _get_title($id, bool $cat = false) {
|
||||
$pdo = Db::pdo();
|
||||
static function _get_title(int $id, bool $cat = false): string {
|
||||
$pdo = Db::pdo();
|
||||
|
||||
if ($cat) {
|
||||
return self::_get_cat_title($id);
|
||||
|
@ -1197,7 +1226,7 @@ class Feeds extends Handler_Protected {
|
|||
return __("Fresh articles");
|
||||
} else if ($id == -4) {
|
||||
return __("All articles");
|
||||
} else if ($id === 0 || $id === "0") {
|
||||
} else if ($id === 0) {
|
||||
return __("Archived articles");
|
||||
} else if ($id == -6) {
|
||||
return __("Recently read");
|
||||
|
@ -1226,12 +1255,12 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
|
||||
} else {
|
||||
return $id;
|
||||
return "$id";
|
||||
}
|
||||
}
|
||||
|
||||
// only real cats
|
||||
static function _get_cat_marked(int $cat, int $owner_uid = 0) {
|
||||
static function _get_cat_marked(int $cat, int $owner_uid = 0): int {
|
||||
|
||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||
|
||||
|
@ -1245,16 +1274,17 @@ class Feeds extends Handler_Protected {
|
|||
WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
|
||||
AND owner_uid = :uid)
|
||||
AND owner_uid = :uid");
|
||||
$sth->execute(["cat" => $cat ? $cat : null, "uid" => $owner_uid]);
|
||||
$row = $sth->fetch();
|
||||
|
||||
return $row["marked"];
|
||||
} else {
|
||||
return 0;
|
||||
$sth->execute(["cat" => $cat ? $cat : null, "uid" => $owner_uid]);
|
||||
|
||||
if ($row = $sth->fetch()) {
|
||||
return (int) $row["marked"];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static function _get_cat_unread(int $cat, int $owner_uid = 0) {
|
||||
static function _get_cat_unread(int $cat, int $owner_uid = 0): int {
|
||||
|
||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||
|
||||
|
@ -1265,14 +1295,15 @@ class Feeds extends Handler_Protected {
|
|||
$sth = $pdo->prepare("SELECT SUM(CASE WHEN unread THEN 1 ELSE 0 END) AS unread
|
||||
FROM ttrss_user_entries
|
||||
WHERE feed_id IN (SELECT id FROM ttrss_feeds
|
||||
WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
|
||||
WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
|
||||
AND owner_uid = :uid)
|
||||
AND owner_uid = :uid");
|
||||
|
||||
$sth->execute(["cat" => $cat ? $cat : null, "uid" => $owner_uid]);
|
||||
$row = $sth->fetch();
|
||||
|
||||
return $row["unread"];
|
||||
|
||||
if ($row = $sth->fetch()) {
|
||||
return (int) $row["unread"];
|
||||
}
|
||||
} else if ($cat == -1) {
|
||||
return 0;
|
||||
} else if ($cat == -2) {
|
||||
|
@ -1280,15 +1311,19 @@ class Feeds extends Handler_Protected {
|
|||
$sth = $pdo->prepare("SELECT COUNT(DISTINCT article_id) AS unread
|
||||
FROM ttrss_user_entries ue, ttrss_user_labels2 l
|
||||
WHERE article_id = ref_id AND unread IS true AND ue.owner_uid = :uid");
|
||||
$sth->execute(["uid" => $owner_uid]);
|
||||
$row = $sth->fetch();
|
||||
|
||||
return $row["unread"];
|
||||
$sth->execute(["uid" => $owner_uid]);
|
||||
|
||||
if ($row = $sth->fetch()) {
|
||||
return (int) $row["unread"];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// only accepts real cats (>= 0)
|
||||
static function _get_cat_children_unread(int $cat, int $owner_uid = 0) {
|
||||
static function _get_cat_children_unread(int $cat, int $owner_uid = 0): int {
|
||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
@ -1307,7 +1342,7 @@ class Feeds extends Handler_Protected {
|
|||
return $unread;
|
||||
}
|
||||
|
||||
static function _get_global_unread(int $user_id = 0) {
|
||||
static function _get_global_unread(int $user_id = 0): int {
|
||||
|
||||
if (!$user_id) $user_id = $_SESSION["uid"];
|
||||
|
||||
|
@ -1323,7 +1358,7 @@ class Feeds extends Handler_Protected {
|
|||
return $row["count"];
|
||||
}
|
||||
|
||||
static function _get_cat_title(int $cat_id) {
|
||||
static function _get_cat_title(int $cat_id): string {
|
||||
switch ($cat_id) {
|
||||
case 0:
|
||||
return __("Uncategorized");
|
||||
|
@ -1343,7 +1378,7 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
private static function _get_label_unread($label_id, int $owner_uid = 0) {
|
||||
private static function _get_label_unread(int $label_id, ?int $owner_uid = null): int {
|
||||
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
@ -1360,7 +1395,11 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
static function _get_headlines($params) {
|
||||
/**
|
||||
* @param array<string, mixed> $params
|
||||
* @return array<int, mixed> $result, $feed_title, $feed_site_url, $last_error, $last_updated, $highlight_words, $first_id, $is_vfeed, $query_error_override
|
||||
*/
|
||||
static function _get_headlines($params): array {
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
||||
|
@ -1577,7 +1616,7 @@ class Feeds extends Handler_Protected {
|
|||
} else if ($feed <= LABEL_BASE_INDEX) { // labels
|
||||
$label_id = Labels::feed_to_label_id($feed);
|
||||
|
||||
$query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND
|
||||
$query_strategy_part = "label_id = $label_id AND
|
||||
ttrss_labels2.id = ttrss_user_labels2.label_id AND
|
||||
ttrss_user_labels2.article_id = ref_id";
|
||||
|
||||
|
@ -1857,7 +1896,10 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
}
|
||||
|
||||
static function _get_parent_cats(int $cat, int $owner_uid) {
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
static function _get_parent_cats(int $cat, int $owner_uid): array {
|
||||
$rv = array();
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
@ -1874,7 +1916,10 @@ class Feeds extends Handler_Protected {
|
|||
return $rv;
|
||||
}
|
||||
|
||||
static function _get_child_cats(int $cat, int $owner_uid) {
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
static function _get_child_cats(int $cat, int $owner_uid): array {
|
||||
$rv = array();
|
||||
|
||||
$pdo = Db::pdo();
|
||||
|
@ -1891,7 +1936,11 @@ class Feeds extends Handler_Protected {
|
|||
return $rv;
|
||||
}
|
||||
|
||||
static function _cats_of(array $feeds, int $owner_uid, bool $with_parents = false) {
|
||||
/**
|
||||
* @param array<int, int> $feeds
|
||||
* @return array<int, int>
|
||||
*/
|
||||
static function _cats_of(array $feeds, int $owner_uid, bool $with_parents = false): array {
|
||||
if (count($feeds) == 0)
|
||||
return [];
|
||||
|
||||
|
@ -1930,24 +1979,27 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
private function _color_of($name) {
|
||||
$colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b",
|
||||
"#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416",
|
||||
"#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ];
|
||||
private function _color_of(string $name): string {
|
||||
$colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b",
|
||||
"#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416",
|
||||
"#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ];
|
||||
|
||||
$sum = 0;
|
||||
$sum = 0;
|
||||
|
||||
for ($i = 0; $i < strlen($name); $i++) {
|
||||
$sum += ord($name[$i]);
|
||||
}
|
||||
for ($i = 0; $i < strlen($name); $i++) {
|
||||
$sum += ord($name[$i]);
|
||||
}
|
||||
|
||||
$sum %= count($colormap);
|
||||
$sum %= count($colormap);
|
||||
|
||||
return $colormap[$sum];
|
||||
return $colormap[$sum];
|
||||
}
|
||||
|
||||
private static function _get_feeds_from_html($url, $content) {
|
||||
$url = UrlHelper::validate($url);
|
||||
/**
|
||||
* @return array<string, string> array of feed URL -> feed title
|
||||
*/
|
||||
private static function _get_feeds_from_html(string $url, string $content): array {
|
||||
$url = UrlHelper::validate($url);
|
||||
$baseUrl = substr($url, 0, strrpos($url, '/') + 1);
|
||||
|
||||
$feedUrls = [];
|
||||
|
@ -1964,9 +2016,7 @@ class Feeds extends Handler_Protected {
|
|||
if ($title == '') {
|
||||
$title = $entry->getAttribute('type');
|
||||
}
|
||||
$feedUrl = rewrite_relative_url(
|
||||
$baseUrl, $entry->getAttribute('href')
|
||||
);
|
||||
$feedUrl = UrlHelper::rewrite_relative($baseUrl, $entry->getAttribute('href'));
|
||||
$feedUrls[$feedUrl] = $title;
|
||||
}
|
||||
}
|
||||
|
@ -1974,11 +2024,11 @@ class Feeds extends Handler_Protected {
|
|||
return $feedUrls;
|
||||
}
|
||||
|
||||
static function _is_html($content) {
|
||||
static function _is_html(string $content): bool {
|
||||
return preg_match("/<html|DOCTYPE html/i", substr($content, 0, 8192)) !== 0;
|
||||
}
|
||||
|
||||
static function _remove_cat(int $id, int $owner_uid) {
|
||||
static function _remove_cat(int $id, int $owner_uid): void {
|
||||
$cat = ORM::for_table('ttrss_feed_categories')
|
||||
->where('owner_uid', $owner_uid)
|
||||
->find_one($id);
|
||||
|
@ -1987,7 +2037,7 @@ class Feeds extends Handler_Protected {
|
|||
$cat->delete();
|
||||
}
|
||||
|
||||
static function _add_cat(string $title, int $owner_uid, int $parent_cat = null, int $order_id = 0) {
|
||||
static function _add_cat(string $title, int $owner_uid, int $parent_cat = null, int $order_id = 0): bool {
|
||||
|
||||
$cat = ORM::for_table('ttrss_feed_categories')
|
||||
->where('owner_uid', $owner_uid)
|
||||
|
@ -2011,13 +2061,13 @@ class Feeds extends Handler_Protected {
|
|||
return false;
|
||||
}
|
||||
|
||||
static function _clear_access_keys(int $owner_uid) {
|
||||
static function _clear_access_keys(int $owner_uid): void {
|
||||
$key = ORM::for_table('ttrss_access_keys')
|
||||
->where('owner_uid', $owner_uid)
|
||||
->delete_many();
|
||||
}
|
||||
|
||||
static function _update_access_key(string $feed_id, bool $is_cat, int $owner_uid) {
|
||||
static function _update_access_key(int $feed_id, bool $is_cat, int $owner_uid): ?string {
|
||||
$key = ORM::for_table('ttrss_access_keys')
|
||||
->where('owner_uid', $owner_uid)
|
||||
->where('feed_id', $feed_id)
|
||||
|
@ -2027,7 +2077,7 @@ class Feeds extends Handler_Protected {
|
|||
return self::_get_access_key($feed_id, $is_cat, $owner_uid);
|
||||
}
|
||||
|
||||
static function _get_access_key(string $feed_id, bool $is_cat, int $owner_uid) {
|
||||
static function _get_access_key(int $feed_id, bool $is_cat, int $owner_uid): ?string {
|
||||
$key = ORM::for_table('ttrss_access_keys')
|
||||
->where('owner_uid', $owner_uid)
|
||||
->where('feed_id', $feed_id)
|
||||
|
@ -2036,21 +2086,23 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
if ($key) {
|
||||
return $key->access_key;
|
||||
} else {
|
||||
$key = ORM::for_table('ttrss_access_keys')->create();
|
||||
|
||||
$key->owner_uid = $owner_uid;
|
||||
$key->feed_id = $feed_id;
|
||||
$key->is_cat = $is_cat;
|
||||
$key->access_key = uniqid_short();
|
||||
|
||||
if ($key->save()) {
|
||||
return $key->access_key;
|
||||
}
|
||||
}
|
||||
|
||||
$key = ORM::for_table('ttrss_access_keys')->create();
|
||||
|
||||
$key->owner_uid = $owner_uid;
|
||||
$key->feed_id = $feed_id;
|
||||
$key->is_cat = $is_cat;
|
||||
$key->access_key = uniqid_short();
|
||||
|
||||
if ($key->save()) {
|
||||
return $key->access_key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static function _purge(int $feed_id, int $purge_interval) {
|
||||
static function _purge(int $feed_id, int $purge_interval): ?int {
|
||||
|
||||
if (!$purge_interval) $purge_interval = self::_get_purge_interval($feed_id);
|
||||
|
||||
|
@ -2079,7 +2131,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
if ($purge_interval <= 0) {
|
||||
Debug::log("purge_feed: purging disabled for this feed, nothing to do.", Debug::$LOG_VERBOSE);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$purge_unread)
|
||||
|
@ -2120,7 +2172,7 @@ class Feeds extends Handler_Protected {
|
|||
return $rows_deleted;
|
||||
}
|
||||
|
||||
private static function _get_purge_interval(int $feed_id) {
|
||||
private static function _get_purge_interval(int $feed_id): int {
|
||||
$feed = ORM::for_table('ttrss_feeds')->find_one($feed_id);
|
||||
|
||||
if ($feed) {
|
||||
|
@ -2133,7 +2185,10 @@ class Feeds extends Handler_Protected {
|
|||
}
|
||||
}
|
||||
|
||||
private static function _search_to_sql($search, $search_language, $owner_uid) {
|
||||
/**
|
||||
* @return array{0: string, 1: array<int, string>} [$search_query_part, $search_words]
|
||||
*/
|
||||
private static function _search_to_sql(string $search, string $search_language, int $owner_uid): array {
|
||||
$keywords = str_getcsv(preg_replace('/(-?\w+)\:"(\w+)/', '"${1}:${2}', trim($search)), ' ');
|
||||
$query_keywords = array();
|
||||
$search_words = array();
|
||||
|
@ -2226,7 +2281,7 @@ class Feeds extends Handler_Protected {
|
|||
array_push($query_keywords, "($not
|
||||
(ttrss_entries.id IN (
|
||||
SELECT article_id FROM ttrss_user_labels2 WHERE
|
||||
label_id = ".$pdo->quote($label_id).")))");
|
||||
label_id = $label_id)))");
|
||||
} else {
|
||||
array_push($query_keywords, "(false)");
|
||||
}
|
||||
|
@ -2300,7 +2355,10 @@ class Feeds extends Handler_Protected {
|
|||
return array($search_query_part, $search_words);
|
||||
}
|
||||
|
||||
static function _order_to_override_query($order) {
|
||||
/**
|
||||
* @return array{0: string, 1: bool}
|
||||
*/
|
||||
static function _order_to_override_query(string $order): array {
|
||||
$query = "";
|
||||
$skip_first_id = false;
|
||||
|
||||
|
@ -2310,7 +2368,9 @@ class Feeds extends Handler_Protected {
|
|||
},
|
||||
$order);
|
||||
|
||||
if ($query) return [$query, $skip_first_id];
|
||||
if (is_string($query) && $query !== "") {
|
||||
return [$query, $skip_first_id];
|
||||
}
|
||||
|
||||
switch ($order) {
|
||||
case "title":
|
||||
|
@ -2328,7 +2388,7 @@ class Feeds extends Handler_Protected {
|
|||
return [$query, $skip_first_id];
|
||||
}
|
||||
|
||||
private function _mark_timestamp($label) {
|
||||
private function _mark_timestamp(string $label): void {
|
||||
|
||||
if (empty($_REQUEST['timestamps']))
|
||||
return;
|
||||
|
|
|
@ -227,7 +227,7 @@ class RPC extends Handler_Protected {
|
|||
$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()]);
|
||||
|
|
Loading…
Reference in New Issue