From a44e2a0d0c35c63a94abfc482955c23d9d823e4a Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:04:16 +0100 Subject: Add visibility (#4232) * Add visibility * Tab use * Update app/Models/Days.php Co-authored-by: Alexandre Alapetite --- app/Models/Days.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/Models') diff --git a/app/Models/Days.php b/app/Models/Days.php index 2d770c30b..de98c5ec8 100644 --- a/app/Models/Days.php +++ b/app/Models/Days.php @@ -1,7 +1,7 @@ Date: Mon, 14 Nov 2022 15:07:23 +0100 Subject: Typing function checkToken (#4561) * Typing function checkToken * Typing function and rename Co-authored-by: Luc SANCHEZ --- app/Models/CategoryDAO.php | 15 +++++++-------- app/Models/Context.php | 2 +- p/api/greader.php | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'app/Models') diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 20a92d52a..c855f1495 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -265,7 +265,7 @@ SQL; return $categories; } - uasort($categories, function ($a, $b) { + uasort($categories, static function ($a, $b) { $aPosition = $a->attributes('position'); $bPosition = $b->attributes('position'); if ($aPosition === $bPosition) { @@ -310,9 +310,9 @@ SQL; } /** @return array */ - public function listCategoriesOrderUpdate(int $defaultCacheDuration = 86400, int $limit = 0) { + public function listCategoriesOrderUpdate(int $defaultCacheDuration = 86400, int $limit = 0): array { $sql = 'SELECT * FROM `_category` WHERE kind = :kind AND `lastUpdate` < :lu ORDER BY `lastUpdate`' - . ($limit < 1 ? '' : ' LIMIT ' . intval($limit)); + . ($limit < 1 ? '' : ' LIMIT ' . $limit); $stm = $this->pdo->prepare($sql); if ($stm && $stm->bindValue(':kind', FreshRSS_Category::KIND_DYNAMIC_OPML, PDO::PARAM_INT) && @@ -387,7 +387,7 @@ SQL; return $res[0]['count']; } - public function countFeed($id) { + public function countFeed(int $id) { $sql = 'SELECT COUNT(*) AS count FROM `_feed` WHERE category=:id'; $stm = $this->pdo->prepare($sql); $stm->bindParam(':id', $id, PDO::PARAM_INT); @@ -396,7 +396,7 @@ SQL; return $res[0]['count']; } - public function countNotRead($id) { + public function countNotRead(int $id) { $sql = 'SELECT COUNT(*) AS count FROM `_entry` e INNER JOIN `_feed` f ON e.id_feed=f.id WHERE category=:id AND e.is_read=0'; $stm = $this->pdo->prepare($sql); $stm->bindParam(':id', $id, PDO::PARAM_INT); @@ -409,7 +409,7 @@ SQL; * @param array $categories * @param int $feed_id */ - public static function findFeed($categories, $feed_id) { + public static function findFeed(array $categories, int $feed_id) { foreach ($categories as $category) { foreach ($category->feeds() as $feed) { if ($feed->id() === $feed_id) { @@ -422,9 +422,8 @@ SQL; /** * @param array $categories - * @param int $minPriority */ - public static function CountUnreads($categories, $minPriority = 0) { + public static function countUnread(array $categories, int $minPriority = 0): int { $n = 0; foreach ($categories as $category) { foreach ($category->feeds() as $feed) { diff --git a/app/Models/Context.php b/app/Models/Context.php index fed2a6767..152ecc4bf 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -163,7 +163,7 @@ class FreshRSS_Context { // Update number of read / unread variables. $entryDAO = FreshRSS_Factory::createEntryDao(); self::$total_starred = $entryDAO->countUnreadReadFavorites(); - self::$total_unread = FreshRSS_CategoryDAO::CountUnreads( + self::$total_unread = FreshRSS_CategoryDAO::countUnread( self::$categories, 1 ); diff --git a/p/api/greader.php b/p/api/greader.php index b08013850..afca1afaf 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -220,7 +220,7 @@ function token($conf) { exit(); } -function checkToken($conf, $token) { +function checkToken(FreshRSS_UserConfiguration $conf, string $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); if ($user !== '_' && ( //TODO: Check security consequences -- cgit v1.2.3 From 42eeb402ad574236902e40d35d630fa15d29a985 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 15 Nov 2022 15:42:26 +0100 Subject: Fix type hints regressions (#4855) Fix regressions from https://github.com/FreshRSS/FreshRSS/pull/4561 Example: ``` PHP Fatal error: Uncaught TypeError: Argument 1 passed to checkToken() must be an instance of FreshRSS_UserConfiguration, instance of Minz_Configuration given, called in /var/www/FreshRSS/p/api/greader.php on line 1091 and defined in /var/www/FreshRSS/p/api/greader.php:223 Stack trace: #0 /var/www/FreshRSS/p/api/greader.php(1091): checkToken() #1 {main} thrown in /var/www/FreshRSS/p/api/greader.php on line 223 ``` Improvement of https://github.com/FreshRSS/FreshRSS/pull/4110 --- app/Controllers/updateController.php | 2 +- app/Models/Context.php | 14 ++------------ app/Models/SystemConfiguration.php | 6 +++++- app/Models/UserConfiguration.php | 6 +++++- app/install.php | 8 ++------ app/layout/aside_configure.phtml | 6 +++--- app/layout/header.phtml | 2 +- lib/Minz/Configuration.php | 6 +++--- 8 files changed, 22 insertions(+), 28 deletions(-) (limited to 'app/Models') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index f1588c7e1..ae7d613a7 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -217,7 +217,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } public function applyAction() { - if (Minz_Configuration::get('system')->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) { + if (FreshRSS_Context::$system_conf->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) { Minz_Request::forward(array('c' => 'update'), true); } diff --git a/app/Models/Context.php b/app/Models/Context.php index 152ecc4bf..0176e77fa 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -58,12 +58,7 @@ class FreshRSS_Context { public static function initSystem($reload = false) { if ($reload || FreshRSS_Context::$system_conf == null) { //TODO: Keep in session what we need instead of always reloading from disk - Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); - /** - * @var FreshRSS_SystemConfiguration $system_conf - */ - $system_conf = Minz_Configuration::get('system'); - FreshRSS_Context::$system_conf = $system_conf; + FreshRSS_Context::$system_conf = FreshRSS_SystemConfiguration::init(DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); // Register the configuration setter for the system configuration $configurationSetter = new FreshRSS_ConfigurationSetter(); FreshRSS_Context::$system_conf->_configurationSetter($configurationSetter); @@ -88,17 +83,12 @@ class FreshRSS_Context { (!$userMustExist || FreshRSS_user_Controller::userExists($username))) { try { //TODO: Keep in session what we need instead of always reloading from disk - Minz_Configuration::register('user', + FreshRSS_Context::$user_conf = FreshRSS_UserConfiguration::init( USERS_PATH . '/' . $username . '/config.php', FRESHRSS_PATH . '/config-user.default.php', FreshRSS_Context::$system_conf->configurationSetter()); Minz_Session::_param('currentUser', $username); - /** - * @var FreshRSS_UserConfiguration $user_conf - */ - $user_conf = Minz_Configuration::get('user'); - FreshRSS_Context::$user_conf = $user_conf; } catch (Exception $ex) { Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/' . LOG_FILENAME); } diff --git a/app/Models/SystemConfiguration.php b/app/Models/SystemConfiguration.php index ec5960c0e..9fc79969d 100644 --- a/app/Models/SystemConfiguration.php +++ b/app/Models/SystemConfiguration.php @@ -25,6 +25,10 @@ * @property string $unsafe_autologin_enabled * @property-read array $trusted_sources */ -class FreshRSS_SystemConfiguration extends Minz_Configuration { +final class FreshRSS_SystemConfiguration extends Minz_Configuration { + public static function init($config_filename, $default_filename = null): FreshRSS_SystemConfiguration { + parent::register('system', $config_filename, $default_filename); + return parent::get('system'); + } } diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.php index 05c3c08ac..b8b023d79 100644 --- a/app/Models/UserConfiguration.php +++ b/app/Models/UserConfiguration.php @@ -66,6 +66,10 @@ * @property string $view_mode * @property array $volatile */ -class FreshRSS_UserConfiguration extends Minz_Configuration { +final class FreshRSS_UserConfiguration extends Minz_Configuration { + public static function init($config_filename, $default_filename = null, $configuration_setter = null): FreshRSS_UserConfiguration { + parent::register('user', $config_filename, $default_filename, $configuration_setter); + return parent::get('user'); + } } diff --git a/app/install.php b/app/install.php index 9d0d855b8..48f39d25e 100644 --- a/app/install.php +++ b/app/install.php @@ -283,11 +283,7 @@ function freshrss_already_installed() { // A configuration file already exists, we try to load it. $system_conf = null; try { - Minz_Configuration::register('system', $conf_path); - /** - * @var FreshRSS_SystemConfiguration $system_conf - */ - $system_conf = Minz_Configuration::get('system'); + $system_conf = FreshRSS_SystemConfiguration::init($conf_path); } catch (Minz_FileNotExistException $e) { return false; } @@ -295,7 +291,7 @@ function freshrss_already_installed() { // ok, the global conf exists… but what about default user conf? $current_user = $system_conf->default_user; try { - Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php')); + FreshRSS_UserConfiguration::init(USERS_PATH . '/' . $current_user . '/config.php'); } catch (Minz_FileNotExistException $e) { return false; } diff --git a/app/layout/aside_configure.phtml b/app/layout/aside_configure.phtml index 5f1762834..f4a05a47c 100644 --- a/app/layout/aside_configure.phtml +++ b/app/layout/aside_configure.phtml @@ -1,8 +1,8 @@