diff options
| author | 2024-06-05 22:04:06 +0200 | |
|---|---|---|
| committer | 2024-06-05 22:04:06 +0200 | |
| commit | f99c8d5f54c67e0abc3f3189b4f5e3e4571e114c (patch) | |
| tree | d7d74a628cd9614dd4093220139b6c073f3a5c54 /p/api | |
| parent | 8fc8ac3aefca73a4cd509313a2f1ad73ef7f2e1a (diff) | |
Modernize code to php7.4 (#6043)
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Modernize code to php7.4
* Consistency
---------
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'p/api')
| -rw-r--r-- | p/api/fever.php | 72 | ||||
| -rw-r--r-- | p/api/index.php | 8 | ||||
| -rw-r--r-- | p/api/pshb.php | 12 |
3 files changed, 46 insertions, 46 deletions
diff --git a/p/api/fever.php b/p/api/fever.php index 8cf3dfc21..9f4766c9e 100644 --- a/p/api/fever.php +++ b/p/api/fever.php @@ -31,13 +31,13 @@ Minz_Session::init('FreshRSS', true); // ================================================================================================ // <Debug> -$ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576) ?: '';; +$ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1_048_576) ?: '';; function debugInfo(): string { if (function_exists('getallheaders')) { $ALL_HEADERS = getallheaders(); } else { //nginx http://php.net/getallheaders#84262 - $ALL_HEADERS = array(); + $ALL_HEADERS = []; foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) === 'HTTP_') { $ALL_HEADERS[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; @@ -82,7 +82,7 @@ final class FeverDAO extends Minz_ModelPdo * @return FreshRSS_Entry[] */ public function findEntries(array $feed_ids, array $entry_ids, string $max_id, string $since_id): array { - $values = array(); + $values = []; $order = ''; $entryDAO = FreshRSS_Factory::createEntryDao(); @@ -118,7 +118,7 @@ final class FeverDAO extends Minz_ModelPdo if ($stm !== false && $stm->execute($values)) { $result = $stm->fetchAll(PDO::FETCH_ASSOC); - $entries = array(); + $entries = []; foreach ($result as $dao) { $entries[] = FreshRSS_Entry::fromArray($dao); } @@ -134,9 +134,9 @@ final class FeverDAO extends Minz_ModelPdo */ final class FeverAPI { - const API_LEVEL = 3; - const STATUS_OK = 1; - const STATUS_ERR = 0; + public const API_LEVEL = 3; + public const STATUS_OK = 1; + public const STATUS_ERR = 0; private FreshRSS_EntryDAO $entryDAO; @@ -186,7 +186,7 @@ final class FeverAPI * @throws Exception */ public function process(): array { - $response_arr = array(); + $response_arr = []; if (!$this->isAuthenticatedApiUser()) { throw new Exception('No user given or user is not allowed to access API'); @@ -280,8 +280,8 @@ final class FeverAPI * Returns the complete JSON, with 'api_version' and status as 'auth'. * @param array<string,mixed> $reply */ - public function wrap(int $status, array $reply = array()): string { - $arr = array('api_version' => self::API_LEVEL, 'auth' => $status); + public function wrap(int $status, array $reply = []): string { + $arr = ['api_version' => self::API_LEVEL, 'auth' => $status]; if ($status === self::STATUS_OK) { $arr['last_refreshed_on_time'] = $this->lastRefreshedOnTime(); @@ -309,20 +309,21 @@ final class FeverAPI /** @return array<array<string,string|int>> */ private function getFeeds(): array { - $feeds = array(); + $feeds = []; $myFeeds = $this->feedDAO->listFeeds(); /** @var FreshRSS_Feed $feed */ foreach ($myFeeds as $feed) { - $feeds[] = array( + $feeds[] = [ 'id' => $feed->id(), 'favicon_id' => $feed->id(), 'title' => escapeToUnicodeAlternative($feed->name(), true), 'url' => htmlspecialchars_decode($feed->url(), ENT_QUOTES), 'site_url' => htmlspecialchars_decode($feed->website(), ENT_QUOTES), - 'is_spark' => 0, // unsupported + 'is_spark' => 0, + // unsupported 'last_updated_on_time' => $feed->lastUpdate(), - ); + ]; } return $feeds; @@ -330,16 +331,16 @@ final class FeverAPI /** @return array<array<string,int|string>> */ private function getGroups(): array { - $groups = array(); + $groups = []; $categoryDAO = FreshRSS_Factory::createCategoryDao(); $categories = $categoryDAO->listCategories(false, false) ?: []; foreach ($categories as $category) { - $groups[] = array( + $groups[] = [ 'id' => $category->id(), - 'title' => escapeToUnicodeAlternative($category->name(), true), - ); + 'title' => escapeToUnicodeAlternative($category->name(), true) + ]; } return $groups; @@ -350,7 +351,7 @@ final class FeverAPI if (!FreshRSS_Context::hasSystemConf()) { return []; } - $favicons = array(); + $favicons = []; $salt = FreshRSS_Context::systemConf()->salt; $myFeeds = $this->feedDAO->listFeeds(); @@ -362,10 +363,10 @@ final class FeverAPI continue; } - $favicons[] = array( + $favicons[] = [ 'id' => $feed->id(), 'data' => image_type_to_mime_type(exif_imagetype($filename) ?: 0) . ';base64,' . base64_encode(file_get_contents($filename) ?: '') - ); + ]; } return $favicons; @@ -379,8 +380,8 @@ final class FeverAPI * @return array<array<string,int|string>> */ private function getFeedsGroup(): array { - $groups = array(); - $ids = array(); + $groups = []; + $ids = []; $myFeeds = $this->feedDAO->listFeeds(); foreach ($myFeeds as $feed) { @@ -388,10 +389,10 @@ final class FeverAPI } foreach ($ids as $category => $feedIds) { - $groups[] = array( + $groups[] = [ 'group_id' => $category, 'feed_ids' => implode(',', $feedIds) - ); + ]; } return $groups; @@ -402,13 +403,13 @@ final class FeverAPI * @return array<string> */ private function getLinks(): array { - return array(); + return []; } /** * @param array<string> $ids */ - private function entriesToIdList(array $ids = array()): string { + private function entriesToIdList(array $ids = []): string { return implode(',', array_values($ids)); } @@ -452,8 +453,8 @@ final class FeverAPI /** @return array<array<string,string|int>> */ private function getItems(): array { - $feed_ids = array(); - $entry_ids = array(); + $feed_ids = []; + $entry_ids = []; $max_id = ''; $since_id = ''; @@ -495,7 +496,7 @@ final class FeverAPI } } - $items = array(); + $items = []; $feverDAO = new FeverDAO(); $entries = $feverDAO->findEntries($feed_ids, $entry_ids, $max_id, $since_id); @@ -509,17 +510,16 @@ final class FeverAPI if ($entry == null) { continue; } - $items[] = array( - 'id' => '' . $entry->id(), + $items[] = [ + 'id' => $entry->id(), 'feed_id' => $entry->feedId(), 'title' => escapeToUnicodeAlternative($entry->title(), false), 'author' => escapeToUnicodeAlternative(trim($entry->authors(true), '; '), false), - 'html' => $entry->content(), - 'url' => htmlspecialchars_decode($entry->link(), ENT_QUOTES), + 'html' => $entry->content(), 'url' => htmlspecialchars_decode($entry->link(), ENT_QUOTES), 'is_saved' => $entry->isFavorite() ? 1 : 0, 'is_read' => $entry->isRead() ? 1 : 0, 'created_on_time' => $entry->date(true), - ); + ]; } return $items; @@ -570,7 +570,7 @@ $handler = new FeverAPI(); header('Content-Type: application/json; charset=UTF-8'); if (!$handler->isAuthenticatedApiUser()) { - echo $handler->wrap(FeverAPI::STATUS_ERR, array()); + echo $handler->wrap(FeverAPI::STATUS_ERR, []); } else { echo $handler->wrap(FeverAPI::STATUS_OK, $handler->process()); } diff --git a/p/api/index.php b/p/api/index.php index 686e74240..66c9e465c 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -14,10 +14,10 @@ require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader FreshRSS_Context::initSystem(); -echo json_encode(array( - 'greader' => Minz_Url::display('/api/greader.php', 'php', true), - 'fever' => Minz_Url::display('/api/fever.php', 'php', true), - )); +echo json_encode([ + 'greader' => Minz_Url::display('/api/greader.php', 'php', true), + 'fever' => Minz_Url::display('/api/fever.php', 'php', true), +]); ?> </script> </head> diff --git a/p/api/pshb.php b/p/api/pshb.php index b4d553430..18aa0ebbf 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -const MAX_PAYLOAD = 3145728; +const MAX_PAYLOAD = 3_145_728; header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); @@ -30,7 +30,7 @@ if ($canonical === false) { if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { Minz_Log::warning('Warning: Accept unknown unsubscribe', PSHB_LOG); header('Connection: close'); - exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); + exit($_REQUEST['hub_challenge'] ?? ''); } // https://github.com/w3c/websub/issues/106 , https://w3c.github.io/websub/#content-distribution header('HTTP/1.1 410 Gone'); @@ -67,7 +67,7 @@ if (empty($users)) { } if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'subscribe') { - $leaseSeconds = empty($_REQUEST['hub_lease_seconds']) ? 0 : intval($_REQUEST['hub_lease_seconds']); + $leaseSeconds = empty($_REQUEST['hub_lease_seconds']) ? 0 : (int) $_REQUEST['hub_lease_seconds']; if ($leaseSeconds > 60) { $hubJson['lease_end'] = time() + $leaseSeconds; } else { @@ -79,13 +79,13 @@ if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'subscribe') { } file_put_contents('./!hub.json', json_encode($hubJson)); header('Connection: close'); - exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); + exit($_REQUEST['hub_challenge'] ?? ''); } if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { if (empty($hubJson['lease_end']) || $hubJson['lease_end'] < time()) { header('Connection: close'); - exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); + exit($_REQUEST['hub_challenge'] ?? ''); } else { header('HTTP/1.1 422 Unprocessable Entity'); die('We did not ask to unsubscribe!'); @@ -103,7 +103,7 @@ $simplePie->init(); unset($ORIGINAL_INPUT); $links = $simplePie->get_links('self'); -$self = isset($links[0]) ? $links[0] : null; +$self = $links[0] ?? null; if ($self !== $canonical) { //header('HTTP/1.1 422 Unprocessable Entity'); |
