diff options
| author | 2023-03-22 09:57:31 +0100 | |
|---|---|---|
| committer | 2023-03-22 09:57:31 +0100 | |
| commit | e750448f5b32982170f81ca045f9f7e8dc8eed6f (patch) | |
| tree | 4053a9bfdcc5764cdc8ed93e9be73f54da7bd9d4 /p/api | |
| parent | 1a0616562db5c096dc7ca187f0210b3d57bffebf (diff) | |
Consistent entry ID type (32-bit compatibility) (#5213)
* Remove FreshRSS_Searchable for better types
The interface was not used, and it was preventing more precise types for the different `searchById()` methods, as they each have different input and output types.
* Consistent entry ID
Entry IDs (which are 64-bit integers) must be processed as string to be compatible with 32-bit platforms
* Fix type
* A few more related types
* PHPStan level 6
* Some more casts needed
* String cast for htmlspecialchars
Diffstat (limited to 'p/api')
| -rw-r--r-- | p/api/fever.php | 20 | ||||
| -rw-r--r-- | p/api/greader.php | 15 |
2 files changed, 17 insertions, 18 deletions
diff --git a/p/api/fever.php b/p/api/fever.php index 1bc7068ab..7afe843e9 100644 --- a/p/api/fever.php +++ b/p/api/fever.php @@ -227,8 +227,8 @@ final class FeverAPI } if (isset($_REQUEST['mark'], $_REQUEST['as'], $_REQUEST['id']) && ctype_digit($_REQUEST['id'])) { - $id = intval($_REQUEST['id']); - $before = intval($_REQUEST['before'] ?? '0'); + $id = (string)$_REQUEST['id']; + $before = (int)($_REQUEST['before'] ?? '0'); switch (strtolower($_REQUEST['mark'])) { case 'item': switch ($_REQUEST['as']) { @@ -249,14 +249,14 @@ final class FeverAPI case 'feed': switch ($_REQUEST['as']) { case 'read': - $this->setFeedAsRead($id, $before); + $this->setFeedAsRead((int)$id, $before); break; } break; case 'group': switch ($_REQUEST['as']) { case 'read': - $this->setGroupAsRead($id, $before); + $this->setGroupAsRead((int)$id, $before); break; } break; @@ -420,40 +420,40 @@ final class FeverAPI } private function getUnreadItemIds(): string { - $entries = $this->entryDAO->listIdsWhere('a', '', FreshRSS_Entry::STATE_NOT_READ, 'ASC', 0) ?: []; + $entries = $this->entryDAO->listIdsWhere('a', 0, FreshRSS_Entry::STATE_NOT_READ, 'ASC', 0) ?: []; return $this->entriesToIdList($entries); } private function getSavedItemIds(): string { - $entries = $this->entryDAO->listIdsWhere('a', '', FreshRSS_Entry::STATE_FAVORITE, 'ASC', 0) ?: []; + $entries = $this->entryDAO->listIdsWhere('a', 0, FreshRSS_Entry::STATE_FAVORITE, 'ASC', 0) ?: []; return $this->entriesToIdList($entries); } /** * @return integer|false */ - private function setItemAsRead(int $id) { + private function setItemAsRead(string $id) { return $this->entryDAO->markRead($id, true); } /** * @return integer|false */ - private function setItemAsUnread(int $id) { + private function setItemAsUnread(string $id) { return $this->entryDAO->markRead($id, false); } /** * @return integer|false */ - private function setItemAsSaved(int $id) { + private function setItemAsSaved(string $id) { return $this->entryDAO->markFavorite($id, true); } /** * @return integer|false */ - private function setItemAsUnsaved(int $id) { + private function setItemAsUnsaved(string $id) { return $this->entryDAO->markFavorite($id, false); } diff --git a/p/api/greader.php b/p/api/greader.php index 069f37b65..a4b542c23 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -385,10 +385,6 @@ final class GReaderAPI { self::badRequest(); } $addCatId = 0; - $categoryDAO = null; - if ($add != '' || $remove != '') { - $categoryDAO = FreshRSS_Factory::createCategoryDao(); - } $c_name = ''; if ($add != '' && strpos($add, 'user/') === 0) { //user/-/label/Example ; user/username/label/Example if (strpos($add, 'user/-/label/') === 0) { @@ -403,6 +399,7 @@ final class GReaderAPI { } } $c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8'); + $categoryDAO = FreshRSS_Factory::createCategoryDao(); $cat = $categoryDAO->searchByName($c_name); $addCatId = $cat == null ? 0 : $cat->id(); } elseif ($remove != '' && strpos($remove, 'user/-/label/') === 0) { @@ -586,13 +583,14 @@ final class GReaderAPI { } /** - * @return array<string|int|FreshRSS_BooleanSearch> + * @param string|int $streamId + * @return array{string,int,int,FreshRSS_BooleanSearch} */ - private static function streamContentsFilters(string $type, string $streamId, + private static function streamContentsFilters(string $type, $streamId, string $filter_target, string $exclude_target, int $start_time, int $stop_time): array { switch ($type) { case 'f': //feed - if ($streamId != '' && !ctype_digit($streamId)) { + if ($streamId != '' && is_string($streamId) && !ctype_digit($streamId)) { $feedDAO = FreshRSS_Factory::createFeedDao(); $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8'); $feed = $feedDAO->searchByUrl($streamId); @@ -601,7 +599,7 @@ final class GReaderAPI { break; case 'c': //category or label $categoryDAO = FreshRSS_Factory::createCategoryDao(); - $streamId = htmlspecialchars($streamId, ENT_COMPAT, 'UTF-8'); + $streamId = htmlspecialchars((string)$streamId, ENT_COMPAT, 'UTF-8'); $cat = $categoryDAO->searchByName($streamId); if ($cat != null) { $type = 'c'; @@ -619,6 +617,7 @@ final class GReaderAPI { } break; } + $streamId = (int)$streamId; switch ($filter_target) { case 'user/-/state/com.google/read': |
