diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index 3fc7036fa..b53747921 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -36,7 +36,6 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { $anon_refresh !== FreshRSS_Context::systemConf()->allow_anonymous_refresh || $unsafe_autologin !== FreshRSS_Context::systemConf()->unsafe_autologin_enabled || $api_enabled !== FreshRSS_Context::systemConf()->api_enabled) { - if (in_array($auth_type, ['form', 'http_auth', 'none'], true)) { FreshRSS_Context::systemConf()->auth_type = $auth_type; } else { @@ -89,6 +88,7 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { case 'none': // It should not happen! Minz_Error::error(404); + break; default: // TODO load plugin instead Minz_Error::error(404); diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index 410147b4e..4d5c77596 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -28,7 +28,7 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { * Request parameter is: * - new-category */ - public function createAction() :void { + public function createAction(): void { $catDAO = FreshRSS_Factory::createCategoryDao(); $tagDAO = FreshRSS_Factory::createTagDao(); diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 8cea74752..e604ca6b2 100644 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -79,31 +79,31 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController { } else { $type_get = $get[0]; $get = (int)substr($get, 2); - switch($type_get) { - case 'c': - $entryDAO->markReadCat($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 'f': - $entryDAO->markReadFeed($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 's': - $entryDAO->markReadEntries($id_max, true, null, FreshRSS_Feed::PRIORITY_IMPORTANT, - FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 'a': - $entryDAO->markReadEntries($id_max, false, FreshRSS_Feed::PRIORITY_MAIN_STREAM, FreshRSS_Feed::PRIORITY_IMPORTANT, - FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 'i': - $entryDAO->markReadEntries($id_max, false, FreshRSS_Feed::PRIORITY_IMPORTANT, null, - FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 't': - $entryDAO->markReadTag($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; - case 'T': - $entryDAO->markReadTag(0, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); - break; + switch ($type_get) { + case 'c': + $entryDAO->markReadCat($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 'f': + $entryDAO->markReadFeed($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 's': + $entryDAO->markReadEntries($id_max, true, null, FreshRSS_Feed::PRIORITY_IMPORTANT, + FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 'a': + $entryDAO->markReadEntries($id_max, false, FreshRSS_Feed::PRIORITY_MAIN_STREAM, FreshRSS_Feed::PRIORITY_IMPORTANT, + FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 'i': + $entryDAO->markReadEntries($id_max, false, FreshRSS_Feed::PRIORITY_IMPORTANT, null, + FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 't': + $entryDAO->markReadTag($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; + case 'T': + $entryDAO->markReadTag(0, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state, $is_read); + break; } if ($next_get !== 'a') { diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index c3e832cf8..59e910bac 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -24,40 +24,40 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController { ]); switch ($code_int) { - case 200 : - header('HTTP/1.1 200 OK'); - break; - case 400: - header('HTTP/1.1 400 Bad Request'); - $this->view->code = 'Error 400 - Bad Request'; - $this->view->errorMessage = ''; - break; - case 403: - header('HTTP/1.1 403 Forbidden'); - $this->view->code = 'Error 403 - Forbidden'; - $this->view->errorMessage = _t('feedback.access.denied'); - break; - case 404: - header('HTTP/1.1 404 Not Found'); - $this->view->code = 'Error 404 - Not found'; - $this->view->errorMessage = _t('feedback.access.not_found'); - break; - case 405: - header('HTTP/1.1 405 Method Not Allowed'); - $this->view->code = 'Error 405 - Method Not Allowed'; - $this->view->errorMessage = ''; - break; - case 503: - header('HTTP/1.1 503 Service Unavailable'); - $this->view->code = 'Error 503 - Service Unavailable'; - $this->view->errorMessage = 'Error 503 - Service Unavailable'; - break; - case 500: - default: - header('HTTP/1.1 500 Internal Server Error'); - $this->view->code = 'Error 500 - Internal Server Error'; - $this->view->errorMessage = 'Error 500 - Internal Server Error'; - break; + case 200: + header('HTTP/1.1 200 OK'); + break; + case 400: + header('HTTP/1.1 400 Bad Request'); + $this->view->code = 'Error 400 - Bad Request'; + $this->view->errorMessage = ''; + break; + case 403: + header('HTTP/1.1 403 Forbidden'); + $this->view->code = 'Error 403 - Forbidden'; + $this->view->errorMessage = _t('feedback.access.denied'); + break; + case 404: + header('HTTP/1.1 404 Not Found'); + $this->view->code = 'Error 404 - Not found'; + $this->view->errorMessage = _t('feedback.access.not_found'); + break; + case 405: + header('HTTP/1.1 405 Method Not Allowed'); + $this->view->code = 'Error 405 - Method Not Allowed'; + $this->view->errorMessage = ''; + break; + case 503: + header('HTTP/1.1 503 Service Unavailable'); + $this->view->code = 'Error 503 - Service Unavailable'; + $this->view->errorMessage = 'Error 503 - Service Unavailable'; + break; + case 500: + default: + header('HTTP/1.1 500 Internal Server Error'); + $this->view->code = 'Error 500 - Internal Server Error'; + $this->view->errorMessage = 'Error 500 - Internal Server Error'; + break; } $error_message = trim(implode($error_logs)); diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index 0029d5e52..6a4d97bea 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -158,7 +158,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { if ($conf !== null && $res === true) { $ext_list = $conf->extensions_enabled; - $ext_list = array_filter($ext_list, static function(string $key) use($type) { + $ext_list = array_filter($ext_list, static function (string $key) use ($type) { // Remove from list the extensions that have disappeared or changed type $extension = Minz_ExtensionManager::findExtension($key); return $extension !== null && $extension->getType() === $type; @@ -220,7 +220,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { if ($conf !== null && $res === true) { $ext_list = $conf->extensions_enabled; - $ext_list = array_filter($ext_list, static function(string $key) use($type) { + $ext_list = array_filter($ext_list, static function (string $key) use ($type) { // Remove from list the extensions that have disappeared or changed type $extension = Minz_ExtensionManager::findExtension($key); return $extension !== null && $extension->getType() === $type; diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 52c70ffe0..2dc25fa2f 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -38,9 +38,15 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { */ private static function megabytes(string $size_str) { switch (substr($size_str, -1)) { - case 'M': case 'm': return (int)$size_str; - case 'K': case 'k': return (int)$size_str / 1024; - case 'G': case 'g': return (int)$size_str * 1024; + case 'M': + case 'm': + return (int)$size_str; + case 'K': + case 'k': + return (int)$size_str / 1024; + case 'G': + case 'g': + return (int)$size_str * 1024; } return $size_str; } @@ -689,15 +695,15 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { private static function filenameToContentType(string $filename): string { $filetype = self::guessFileType($filename); switch ($filetype) { - case 'zip': - return 'application/zip'; - case 'opml': - return 'application/xml; charset=utf-8'; - case 'json_starred': - case 'json_feed': - return 'application/json; charset=utf-8'; - default: - return 'application/octet-stream'; + case 'zip': + return 'application/zip'; + case 'opml': + return 'application/xml; charset=utf-8'; + case 'json_starred': + case 'json_feed': + return 'application/json; charset=utf-8'; + default: + return 'application/octet-stream'; } } } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 2588320b5..2ee72b7b7 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -268,8 +268,8 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { foreach ($entryDAO->listWhere( $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order, $postsPerPage ?? FreshRSS_Context::$number, FreshRSS_Context::$offset, FreshRSS_Context::$first_id, - FreshRSS_Context::$search, $date_min) - as $entry) { + FreshRSS_Context::$search, $date_min + ) as $entry) { yield $entry; } } diff --git a/app/Exceptions/BadUrlException.php b/app/Exceptions/BadUrlException.php index d308d4791..c7111a41f 100644 --- a/app/Exceptions/BadUrlException.php +++ b/app/Exceptions/BadUrlException.php @@ -6,5 +6,4 @@ class FreshRSS_BadUrl_Exception extends FreshRSS_Feed_Exception { public function __construct(string $url) { parent::__construct('`' . $url . '` is not a valid URL'); } - } diff --git a/app/FreshRSS.php b/app/FreshRSS.php index f41ff5d2e..ff766ad47 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -74,10 +74,10 @@ class FreshRSS extends Minz_FrontController { if (!FreshRSS_Context::hasSystemConf() || !(FreshRSS_Auth::isCsrfOk() || (Minz_Request::controllerName() === 'auth' && Minz_Request::actionName() === 'login') || (Minz_Request::controllerName() === 'user' && Minz_Request::actionName() === 'create' && !FreshRSS_Auth::hasAccess('admin')) || - (Minz_Request::controllerName() === 'feed' && Minz_Request::actionName() === 'actualize' - && FreshRSS_Context::systemConf()->allow_anonymous_refresh) || - (Minz_Request::controllerName() === 'javascript' && Minz_Request::actionName() === 'actualize' - && FreshRSS_Context::systemConf()->allow_anonymous) + (Minz_Request::controllerName() === 'feed' && Minz_Request::actionName() === 'actualize' && + FreshRSS_Context::systemConf()->allow_anonymous_refresh) || + (Minz_Request::controllerName() === 'javascript' && Minz_Request::actionName() === 'actualize' && + FreshRSS_Context::systemConf()->allow_anonymous) )) { // Token-based protection against XSRF attacks, except for the login or self-create user forms self::initI18n(); @@ -112,7 +112,7 @@ class FreshRSS extends Minz_FrontController { } $theme = FreshRSS_Themes::load(FreshRSS_Context::userConf()->theme); if ($theme) { - foreach(array_reverse($theme['files']) as $file) { + foreach (array_reverse($theme['files']) as $file) { switch (substr($file, -3)) { case '.js': $theme_id = $theme['id']; diff --git a/app/Mailers/UserMailer.php b/app/Mailers/UserMailer.php index 53d50d01c..4d657bf69 100644 --- a/app/Mailers/UserMailer.php +++ b/app/Mailers/UserMailer.php @@ -38,7 +38,7 @@ class FreshRSS_User_Mailer extends Minz_Mailer { $subject_prefix = '[' . FreshRSS_Context::systemConf()->title . ']'; return $this->mail( $user_config->mail_login, - $subject_prefix . ' ' ._t('user.mailer.email_need_validation.title') + $subject_prefix . ' ' . _t('user.mailer.email_need_validation.title') ); } } diff --git a/app/Models/Auth.php b/app/Models/Auth.php index 416f3061d..f65a59e03 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -54,48 +54,48 @@ class FreshRSS_Auth { private static function accessControl(): bool { $auth_type = FreshRSS_Context::systemConf()->auth_type; switch ($auth_type) { - case 'form': - $credentials = FreshRSS_FormAuth::getCredentialsFromCookie(); - $current_user = ''; - if (isset($credentials[1])) { - $current_user = trim($credentials[0]); - Minz_Session::_params([ + case 'form': + $credentials = FreshRSS_FormAuth::getCredentialsFromCookie(); + $current_user = ''; + if (isset($credentials[1])) { + $current_user = trim($credentials[0]); + Minz_Session::_params([ Minz_User::CURRENT_USER => $current_user, 'passwordHash' => trim($credentials[1]), 'csrf' => false, - ]); - } - return $current_user != ''; - case 'http_auth': - $current_user = httpAuthUser(); - if ($current_user == '') { - return false; - } - $login_ok = FreshRSS_UserDAO::exists($current_user); - if (!$login_ok && FreshRSS_Context::systemConf()->http_auth_auto_register) { - $email = null; - if (FreshRSS_Context::systemConf()->http_auth_auto_register_email_field !== '' && - isset($_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field])) { - $email = (string)$_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field]; + ]); } - $language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::systemConf()->language); - Minz_Translate::init($language); - $login_ok = FreshRSS_user_Controller::createUser($current_user, $email, '', [ + return $current_user != ''; + case 'http_auth': + $current_user = httpAuthUser(); + if ($current_user == '') { + return false; + } + $login_ok = FreshRSS_UserDAO::exists($current_user); + if (!$login_ok && FreshRSS_Context::systemConf()->http_auth_auto_register) { + $email = null; + if (FreshRSS_Context::systemConf()->http_auth_auto_register_email_field !== '' && + isset($_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field])) { + $email = (string)$_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field]; + } + $language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::systemConf()->language); + Minz_Translate::init($language); + $login_ok = FreshRSS_user_Controller::createUser($current_user, $email, '', [ 'language' => $language, - ]); - } - if ($login_ok) { - Minz_Session::_params([ + ]); + } + if ($login_ok) { + Minz_Session::_params([ Minz_User::CURRENT_USER => $current_user, 'csrf' => false, - ]); - } - return $login_ok; - case 'none': - return true; - default: - // TODO load extension - return false; + ]); + } + return $login_ok; + case 'none': + return true; + default: + // TODO load extension + return false; } } @@ -110,19 +110,19 @@ class FreshRSS_Auth { } switch (FreshRSS_Context::systemConf()->auth_type) { - case 'form': - self::$login_ok = Minz_Session::paramString('passwordHash') === FreshRSS_Context::userConf()->passwordHash; - break; - case 'http_auth': - $current_user = Minz_User::name() ?? ''; - self::$login_ok = strcasecmp($current_user, httpAuthUser()) === 0; - break; - case 'none': - self::$login_ok = true; - break; - default: - // TODO: extensions - self::$login_ok = false; + case 'form': + self::$login_ok = Minz_Session::paramString('passwordHash') === FreshRSS_Context::userConf()->passwordHash; + break; + case 'http_auth': + $current_user = Minz_User::name() ?? ''; + self::$login_ok = strcasecmp($current_user, httpAuthUser()) === 0; + break; + case 'none': + self::$login_ok = true; + break; + default: + // TODO: extensions + self::$login_ok = false; } Minz_Session::_params([ @@ -147,13 +147,13 @@ class FreshRSS_Auth { $default_user = FreshRSS_Context::systemConf()->default_user; $ok = self::$login_ok; switch ($scope) { - case 'general': - break; - case 'admin': - $ok &= $default_user === $currentUser || $isAdmin; - break; - default: - $ok = false; + case 'general': + break; + case 'admin': + $ok &= $default_user === $currentUser || $isAdmin; + break; + default: + $ok = false; } return (bool)$ok; } @@ -186,16 +186,16 @@ class FreshRSS_Auth { Minz_User::change($username); switch (FreshRSS_Context::systemConf()->auth_type) { - case 'form': - Minz_Session::_param('passwordHash'); - FreshRSS_FormAuth::deleteCookie(); - break; - case 'http_auth': - case 'none': - // Nothing to do… - break; - default: - // TODO: extensions + case 'form': + Minz_Session::_param('passwordHash'); + FreshRSS_FormAuth::deleteCookie(); + break; + case 'http_auth': + case 'none': + // Nothing to do… + break; + default: + // TODO: extensions } } diff --git a/app/Models/CategoryDAOSQLite.php b/app/Models/CategoryDAOSQLite.php index 5fb0da31d..4aaac07a8 100644 --- a/app/Models/CategoryDAOSQLite.php +++ b/app/Models/CategoryDAOSQLite.php @@ -16,5 +16,4 @@ class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO { } return false; } - } diff --git a/app/Models/Context.php b/app/Models/Context.php index 7efb24ab1..988eedc71 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -347,23 +347,23 @@ final class FreshRSS_Context { $type = substr($get, 0, 1); $id = substr($get, 2); - switch($type) { - case 'a': - return self::$current_get['all']; - case 'i': - return self::$current_get['important']; - case 's': - return self::$current_get['starred']; - case 'f': - return self::$current_get['feed'] == $id; - case 'c': - return self::$current_get['category'] == $id; - case 't': - return self::$current_get['tag'] == $id; - case 'T': - return self::$current_get['tags'] || self::$current_get['tag']; - default: - return false; + switch ($type) { + case 'a': + return self::$current_get['all']; + case 'i': + return self::$current_get['important']; + case 's': + return self::$current_get['starred']; + case 'f': + return self::$current_get['feed'] == $id; + case 'c': + return self::$current_get['category'] == $id; + case 't': + return self::$current_get['tag'] == $id; + case 'T': + return self::$current_get['tags'] || self::$current_get['tag']; + default: + return false; } } @@ -393,84 +393,84 @@ final class FreshRSS_Context { self::$categories = $catDAO->listCategories(true, $details); } - switch($type) { - case 'a': - self::$current_get['all'] = true; - self::$name = _t('index.feed.title'); - self::$description = FreshRSS_Context::systemConf()->meta_description; - self::$get_unread = self::$total_unread; - break; - case 'i': - self::$current_get['important'] = true; - self::$name = _t('index.menu.important'); - self::$description = FreshRSS_Context::systemConf()->meta_description; - self::$get_unread = self::$total_unread; - break; - case 's': - self::$current_get['starred'] = true; - self::$name = _t('index.feed.title_fav'); - self::$description = FreshRSS_Context::systemConf()->meta_description; - self::$get_unread = self::$total_starred['unread']; + switch ($type) { + case 'a': + self::$current_get['all'] = true; + self::$name = _t('index.feed.title'); + self::$description = FreshRSS_Context::systemConf()->meta_description; + self::$get_unread = self::$total_unread; + break; + case 'i': + self::$current_get['important'] = true; + self::$name = _t('index.menu.important'); + self::$description = FreshRSS_Context::systemConf()->meta_description; + self::$get_unread = self::$total_unread; + break; + case 's': + self::$current_get['starred'] = true; + self::$name = _t('index.feed.title_fav'); + self::$description = FreshRSS_Context::systemConf()->meta_description; + self::$get_unread = self::$total_starred['unread']; - // Update state if favorite is not yet enabled. - self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; - break; - case 'f': - // We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description - $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id); - if ($feed === null) { - $feedDAO = FreshRSS_Factory::createFeedDao(); - $feed = $feedDAO->searchById($id); + // Update state if favorite is not yet enabled. + self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; + break; + case 'f': + // We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description + $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id); if ($feed === null) { - throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feed = $feedDAO->searchById($id); + if ($feed === null) { + throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); + } } - } - self::$current_get['feed'] = $id; - self::$current_get['category'] = $feed->categoryId(); - self::$name = $feed->name(); - self::$description = $feed->description(); - self::$get_unread = $feed->nbNotRead(); - break; - case 'c': - // We try to find the corresponding category. - self::$current_get['category'] = $id; - if (!isset(self::$categories[$id])) { - $catDAO = FreshRSS_Factory::createCategoryDao(); - $cat = $catDAO->searchById($id); - if ($cat === null) { - throw new FreshRSS_Context_Exception('Invalid category: ' . $id); + self::$current_get['feed'] = $id; + self::$current_get['category'] = $feed->categoryId(); + self::$name = $feed->name(); + self::$description = $feed->description(); + self::$get_unread = $feed->nbNotRead(); + break; + case 'c': + // We try to find the corresponding category. + self::$current_get['category'] = $id; + if (!isset(self::$categories[$id])) { + $catDAO = FreshRSS_Factory::createCategoryDao(); + $cat = $catDAO->searchById($id); + if ($cat === null) { + throw new FreshRSS_Context_Exception('Invalid category: ' . $id); + } + self::$categories[$id] = $cat; + } else { + $cat = self::$categories[$id]; } - self::$categories[$id] = $cat; - } else { - $cat = self::$categories[$id]; - } - self::$name = $cat->name(); - self::$get_unread = $cat->nbNotRead(); - break; - case 't': - // We try to find the corresponding tag. - self::$current_get['tag'] = $id; - if (!isset(self::$tags[$id])) { + self::$name = $cat->name(); + self::$get_unread = $cat->nbNotRead(); + break; + case 't': + // We try to find the corresponding tag. + self::$current_get['tag'] = $id; + if (!isset(self::$tags[$id])) { + $tagDAO = FreshRSS_Factory::createTagDao(); + $tag = $tagDAO->searchById($id); + if ($tag === null) { + throw new FreshRSS_Context_Exception('Invalid tag: ' . $id); + } + self::$tags[$id] = $tag; + } else { + $tag = self::$tags[$id]; + } + self::$name = $tag->name(); + self::$get_unread = $tag->nbUnread(); + break; + case 'T': $tagDAO = FreshRSS_Factory::createTagDao(); - $tag = $tagDAO->searchById($id); - if ($tag === null) { - throw new FreshRSS_Context_Exception('Invalid tag: ' . $id); - } - self::$tags[$id] = $tag; - } else { - $tag = self::$tags[$id]; - } - self::$name = $tag->name(); - self::$get_unread = $tag->nbUnread(); - break; - case 'T': - $tagDAO = FreshRSS_Factory::createTagDao(); - self::$current_get['tags'] = true; - self::$name = _t('index.menu.tags'); - self::$get_unread = $tagDAO->countNotRead(); - break; - default: - throw new FreshRSS_Context_Exception('Invalid getter: ' . $get); + self::$current_get['tags'] = true; + self::$name = _t('index.menu.tags'); + self::$get_unread = $tagDAO->countNotRead(); + break; + default: + throw new FreshRSS_Context_Exception('Invalid getter: ' . $get); } self::_nextGet(); @@ -493,54 +493,54 @@ final class FreshRSS_Context { $another_unread_id = ''; $found_current_get = false; switch ($get[0]) { - case 'f': - // We search the next unread feed with the following priorities: next in same category, or previous in same category, or next, or previous. - foreach (self::$categories as $cat) { - $sameCat = false; - foreach ($cat->feeds() as $feed) { - if ($found_current_get) { - if ($feed->nbNotRead() > 0) { + case 'f': + // We search the next unread feed with the following priorities: next in same category, or previous in same category, or next, or previous. + foreach (self::$categories as $cat) { + $sameCat = false; + foreach ($cat->feeds() as $feed) { + if ($found_current_get) { + if ($feed->nbNotRead() > 0) { + $another_unread_id = $feed->id(); + break 2; + } + } elseif ($feed->id() == self::$current_get['feed']) { + $found_current_get = true; + } elseif ($feed->nbNotRead() > 0) { $another_unread_id = $feed->id(); - break 2; + $sameCat = true; } - } elseif ($feed->id() == self::$current_get['feed']) { - $found_current_get = true; - } elseif ($feed->nbNotRead() > 0) { - $another_unread_id = $feed->id(); - $sameCat = true; } - } - if ($found_current_get && $sameCat) { - break; - } - } - - // If there is no more unread feed, show main stream - self::$next_get = $another_unread_id == '' ? 'a' : 'f_' . $another_unread_id; - break; - case 'c': - // We search the next category with at least one unread article. - foreach (self::$categories as $cat) { - if ($cat->id() == self::$current_get['category']) { - // Here is our current category! Next one could be our - // champion if it has unread articles. - $found_current_get = true; - continue; - } - - if ($cat->nbNotRead() > 0) { - $another_unread_id = $cat->id(); - if ($found_current_get) { - // Unread articles and the current category has - // already been found? Leave the loop! + if ($found_current_get && $sameCat) { break; } } - } - // If there is no more unread category, show main stream - self::$next_get = $another_unread_id == '' ? 'a' : 'c_' . $another_unread_id; - break; + // If there is no more unread feed, show main stream + self::$next_get = $another_unread_id == '' ? 'a' : 'f_' . $another_unread_id; + break; + case 'c': + // We search the next category with at least one unread article. + foreach (self::$categories as $cat) { + if ($cat->id() == self::$current_get['category']) { + // Here is our current category! Next one could be our + // champion if it has unread articles. + $found_current_get = true; + continue; + } + + if ($cat->nbNotRead() > 0) { + $another_unread_id = $cat->id(); + if ($found_current_get) { + // Unread articles and the current category has + // already been found? Leave the loop! + break; + } + } + } + + // If there is no more unread category, show main stream + self::$next_get = $another_unread_id == '' ? 'a' : 'c_' . $another_unread_id; + break; } } } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ada6e9944..cd7b27291 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -393,7 +393,7 @@ HTML; return timestamptodate($this->date); } public function machineReadableDate(): string { - return @date (DATE_ATOM, $this->date); + return @date(DATE_ATOM, $this->date); } public function lastSeen(): int { @@ -728,17 +728,17 @@ HTML; public function isDay(int $day, int $today): bool { $date = $this->dateAdded(true); switch ($day) { - case FreshRSS_Days::TODAY: - $tomorrow = $today + 86400; - return $date >= $today && $date < $tomorrow; - case FreshRSS_Days::YESTERDAY: - $yesterday = $today - 86400; - return $date >= $yesterday && $date < $today; - case FreshRSS_Days::BEFORE_YESTERDAY: - $yesterday = $today - 86400; - return $date < $yesterday; - default: - return false; + case FreshRSS_Days::TODAY: + $tomorrow = $today + 86400; + return $date >= $today && $date < $tomorrow; + case FreshRSS_Days::YESTERDAY: + $yesterday = $today - 86400; + return $date >= $yesterday && $date < $today; + case FreshRSS_Days::BEFORE_YESTERDAY: + $yesterday = $today - 86400; + return $date < $yesterday; + default: + return false; } } diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index ba0cf1970..cd8373766 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -312,7 +312,7 @@ SQL; } $sql = 'UPDATE `_entry` ' . 'SET is_favorite=? ' - . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)'; + . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1) . '?)'; $values = [$is_favorite ? 1 : 0]; $values = array_merge($values, $ids); $stm = $this->pdo->prepare($sql); @@ -393,7 +393,7 @@ SQL; $sql = 'UPDATE `_entry` ' . 'SET is_read=? ' - . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)'; + . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1) . '?)'; $values = [$is_read ? 1 : 0]; $values = array_merge($values, $ids); $stm = $this->pdo->prepare($sql); @@ -1062,43 +1062,43 @@ SQL; $where = ''; $values = []; switch ($type) { - case 'a': //All PRIORITY_MAIN_STREAM - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_MAIN_STREAM . ' '; - break; - case 'A': //All except PRIORITY_ARCHIVED - $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; - break; - case 'i': //Priority important feeds - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_IMPORTANT . ' '; - break; - case 's': //Starred. Deprecated: use $state instead - $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; - $where .= 'AND e.is_favorite=1 '; - break; - case 'S': //Starred - $where .= 'e.is_favorite=1 '; - break; - case 'c': //Category - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_CATEGORY . ' '; - $where .= 'AND f.category=? '; - $values[] = $id; - break; - case 'f': //Feed - $where .= 'e.id_feed=? '; - $values[] = $id; - break; - case 't': //Tag (label) - $where .= 'et.id_tag=? '; - $values[] = $id; - break; - case 'T': //Any tag (label) - $where .= '1=1 '; - break; - case 'ST': //Starred or tagged (label) - $where .= 'e.is_favorite=1 OR EXISTS (SELECT et2.id_tag FROM `_entrytag` et2 WHERE et2.id_entry = e.id) '; - break; - default: - throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!'); + case 'a': //All PRIORITY_MAIN_STREAM + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_MAIN_STREAM . ' '; + break; + case 'A': //All except PRIORITY_ARCHIVED + $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; + break; + case 'i': //Priority important feeds + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_IMPORTANT . ' '; + break; + case 's': //Starred. Deprecated: use $state instead + $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; + $where .= 'AND e.is_favorite=1 '; + break; + case 'S': //Starred + $where .= 'e.is_favorite=1 '; + break; + case 'c': //Category + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_CATEGORY . ' '; + $where .= 'AND f.category=? '; + $values[] = $id; + break; + case 'f': //Feed + $where .= 'e.id_feed=? '; + $values[] = $id; + break; + case 't': //Tag (label) + $where .= 'et.id_tag=? '; + $values[] = $id; + break; + case 'T': //Any tag (label) + $where .= '1=1 '; + break; + case 'ST': //Starred or tagged (label) + $where .= 'e.is_favorite=1 OR EXISTS (SELECT et2.id_tag FROM `_entrytag` et2 WHERE et2.id_entry = e.id) '; + break; + default: + throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!'); } [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state, $order, $firstId, $date_min); @@ -1257,7 +1257,7 @@ SQL; } $guids = array_unique($guids); $sql = 'SELECT guid, ' . static::sqlHexEncode('hash') . - ' AS hex_hash FROM `_entry` WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)'; + ' AS hex_hash FROM `_entry` WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1) . '?)'; $stm = $this->pdo->prepare($sql); $values = [$id_feed]; $values = array_merge($values, $guids); @@ -1294,7 +1294,7 @@ SQL; } return $affected; } - $sql = 'UPDATE `_entry` SET `lastSeen`=? WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)'; + $sql = 'UPDATE `_entry` SET `lastSeen`=? WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1) . '?)'; $stm = $this->pdo->prepare($sql); if ($mtime <= 0) { $mtime = time(); diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 44c248e82..364d0c153 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -86,11 +86,11 @@ SQL; FreshRSS_UserDAO::touch(); if (is_array($ids)) { //Many IDs at once (used by API) //if (true) { //Speed heuristics //TODO: Not implemented yet for SQLite (so always call IDs one by one) - $affected = 0; - foreach ($ids as $id) { - $affected += ($this->markRead($id, $is_read) ?: 0); - } - return $affected; + $affected = 0; + foreach ($ids as $id) { + $affected += ($this->markRead($id, $is_read) ?: 0); + } + return $affected; //} } else { $this->pdo->beginTransaction(); diff --git a/app/Models/Factory.php b/app/Models/Factory.php index f69c7f6aa..be96c0e58 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -89,5 +89,4 @@ class FreshRSS_Factory { return new FreshRSS_DatabaseDAO($username); } } - } diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 204f95939..11eef4e90 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -464,7 +464,7 @@ SET `cache_nbEntries`=(SELECT COUNT(e1.id) FROM `_entry` e1 WHERE e1.id_feed=`_f `cache_nbUnreads`=(SELECT COUNT(e2.id) FROM `_entry` e2 WHERE e2.id_feed=`_feed`.id AND e2.is_read=0) SQL; if (count($feedIds) > 0) { - $sql .= ' WHERE id IN (' . str_repeat('?,', count($feedIds) - 1). '?)'; + $sql .= ' WHERE id IN (' . str_repeat('?,', count($feedIds) - 1) . '?)'; } $stm = $this->pdo->prepare($sql); if ($stm !== false && $stm->execute($feedIds)) { diff --git a/app/Models/FilterActionsTrait.php b/app/Models/FilterActionsTrait.php index 495dc3eee..9b7ee66d4 100644 --- a/app/Models/FilterActionsTrait.php +++ b/app/Models/FilterActionsTrait.php @@ -84,7 +84,7 @@ trait FreshRSS_FilterActionsTrait { } } //Update existing filter with new action - for ($k = count($filters) - 1; $k >= 0; $k --) { + for ($k = count($filters) - 1; $k >= 0; $k--) { $filter = $filters[$k]; if ($filter === $filterAction->booleanSearch()->getRawInput()) { $actions[] = $action; @@ -100,7 +100,7 @@ trait FreshRSS_FilterActionsTrait { } //Add new filters - for ($k = count($filters) - 1; $k >= 0; $k --) { + for ($k = count($filters) - 1; $k >= 0; $k--) { $filter = $filters[$k]; if ($filter != '') { $filterAction = FreshRSS_FilterAction::fromJSON([ diff --git a/app/Models/Share.php b/app/Models/Share.php index 8d2d70a6a..9c8f2084e 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -157,7 +157,7 @@ class FreshRSS_Share { case 'method': $this->method = strcasecmp($value, 'POST') === 0 ? 'POST' : 'GET'; break; - case 'field'; + case 'field': $this->field = $value; break; } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 3ee481776..6331e24f2 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -371,5 +371,4 @@ SQL; return $translated; } - } diff --git a/app/Models/StatsDAOPGSQL.php b/app/Models/StatsDAOPGSQL.php index 4fd00c29d..ba5cbfca1 100644 --- a/app/Models/StatsDAOPGSQL.php +++ b/app/Models/StatsDAOPGSQL.php @@ -68,7 +68,7 @@ SQL; $periodMax = 12; break; default: - $periodMax = 30; + $periodMax = 30; } $repartition = array_fill(0, $periodMax, 0); @@ -78,5 +78,4 @@ SQL; return $repartition; } - } diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php index 8997f3abe..c45951069 100644 --- a/app/Models/StatsDAOSQLite.php +++ b/app/Models/StatsDAOSQLite.php @@ -43,7 +43,7 @@ SQL; $periodMax = 12; break; default: - $periodMax = 30; + $periodMax = 30; } $repartition = array_fill(0, $periodMax, 0); @@ -53,5 +53,4 @@ SQL; return $repartition; } - } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 7e3f54457..1feba263e 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -381,7 +381,7 @@ SQL; } return $values; } - $sql .= ' AND et.id_entry IN (' . str_repeat('?,', count($entries) - 1). '?)'; + $sql .= ' AND et.id_entry IN (' . str_repeat('?,', count($entries) - 1) . '?)'; if (is_array($entries[0])) { /** @var array> $entries */ foreach ($entries as $entry) { diff --git a/app/Models/TagDAOPGSQL.php b/app/Models/TagDAOPGSQL.php index 107ab6d08..35688c2d0 100644 --- a/app/Models/TagDAOPGSQL.php +++ b/app/Models/TagDAOPGSQL.php @@ -7,5 +7,4 @@ class FreshRSS_TagDAOPGSQL extends FreshRSS_TagDAO { public function sqlIgnore(): string { return ''; //TODO } - } diff --git a/app/Models/TagDAOSQLite.php b/app/Models/TagDAOSQLite.php index 2ecda7735..69584edf0 100644 --- a/app/Models/TagDAOSQLite.php +++ b/app/Models/TagDAOSQLite.php @@ -7,5 +7,4 @@ class FreshRSS_TagDAOSQLite extends FreshRSS_TagDAO { public function sqlIgnore(): string { return 'OR IGNORE'; } - } diff --git a/app/Models/Themes.php b/app/Models/Themes.php index fab29e986..04ce0a36d 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -158,7 +158,7 @@ class FreshRSS_Themes extends Minz_Model { if ($type == self::ICON_DEFAULT) { if ((FreshRSS_Context::hasUserConf() && FreshRSS_Context::userConf()->icons_as_emojis) // default to emoji alternate for some icons - ) { + ) { $type = self::ICON_EMOJI; } else { $type = self::ICON_IMG; diff --git a/app/Models/View.php b/app/Models/View.php index 293bc71ac..c586d8632 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -129,5 +129,4 @@ class FreshRSS_View extends Minz_View { public string $errorMessage; /** @var array */ public array $message; - } diff --git a/app/Models/ViewStats.php b/app/Models/ViewStats.php index ca98c554a..608633f6b 100644 --- a/app/Models/ViewStats.php +++ b/app/Models/ViewStats.php @@ -44,5 +44,4 @@ final class FreshRSS_ViewStats extends FreshRSS_View { public array $repartitionMonth; /** @var array */ public array $topFeed; - } diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 8390fa6bf..93a528532 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -692,7 +692,7 @@
size="10"> diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtml index 4e14d0fc7..b24b859b8 100644 --- a/app/views/stats/index.phtml +++ b/app/views/stats/index.phtml @@ -83,16 +83,15 @@
diff --git a/app/views/subscription/add.phtml b/app/views/subscription/add.phtml index f4651f52b..2aefd3c3e 100644 --- a/app/views/subscription/add.phtml +++ b/app/views/subscription/add.phtml @@ -310,7 +310,7 @@