From 6c45828169169ea5b8a0a1360fb5d8f29cfa0d81 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Fri, 3 May 2024 19:02:00 +0300 Subject: [PATCH] Fixed and placeholders processing when comments are disabled (closes #5). --- _extensions/s2_blog/Placeholder.php | 18 ++++++++++-------- _include/Placeholder.php | 18 ++++++++++-------- _include/templates/mainpage.php | 2 ++ _tests/acceptance/InstallCest.php | 4 ++++ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/_extensions/s2_blog/Placeholder.php b/_extensions/s2_blog/Placeholder.php index ad1f8db7..f4cb6273 100644 --- a/_extensions/s2_blog/Placeholder.php +++ b/_extensions/s2_blog/Placeholder.php @@ -14,12 +14,13 @@ class Placeholder { - public static function recent_comments () - { + public static function recent_comments (): array + { global $request_uri; - if (!S2_SHOW_COMMENTS) - return ''; + if (!S2_SHOW_COMMENTS) { + return []; + } /** @var DbLayer $s2_db */ $s2_db = \Container::get(DbLayer::class); @@ -62,12 +63,13 @@ public static function recent_comments () return $output; } - public static function recent_discussions () - { + public static function recent_discussions (): array + { global $request_uri; - if (!S2_SHOW_COMMENTS) - return ''; + if (!S2_SHOW_COMMENTS) { + return []; + } /** @var DbLayer $s2_db */ $s2_db = \Container::get(DbLayer::class); diff --git a/_include/Placeholder.php b/_include/Placeholder.php index bb0b51d1..7de07837 100644 --- a/_include/Placeholder.php +++ b/_include/Placeholder.php @@ -180,10 +180,11 @@ public static function tags_list () // // Fetching last comments (for template placeholders) // - public static function last_article_comments () - { - if (!S2_SHOW_COMMENTS) - return ''; + public static function last_article_comments (): array + { + if (!S2_SHOW_COMMENTS) { + return []; + } /** @var DbLayer $s2_db */ $s2_db = \Container::get(DbLayer::class); @@ -236,10 +237,11 @@ public static function last_article_comments () return $output; } - public static function last_discussions () - { - if (!S2_SHOW_COMMENTS) - return ''; + public static function last_discussions (): array + { + if (!S2_SHOW_COMMENTS) { + return []; + } /** @var DbLayer $s2_db */ $s2_db = \Container::get(DbLayer::class); diff --git a/_include/templates/mainpage.php b/_include/templates/mainpage.php index 936adbd0..8006ca19 100644 --- a/_include/templates/mainpage.php +++ b/_include/templates/mainpage.php @@ -26,7 +26,9 @@ + +
diff --git a/_tests/acceptance/InstallCest.php b/_tests/acceptance/InstallCest.php index a1bb73a9..c71c9265 100644 --- a/_tests/acceptance/InstallCest.php +++ b/_tests/acceptance/InstallCest.php @@ -574,6 +574,10 @@ private function testAdminCommentManagement(AcceptanceTester $I): void $I->sendAjaxPostRequest('/_admin/site_ajax.php?action=save_options', $data); $I->seeResponseCodeIsSuccessful(); + // Test and placeholders when comments are disabled + $I->amOnPage('/index.php?/'); + $I->seeResponseCodeIsSuccessful(); + // Check conditional get when the comment form is disabled. Otherwise, there are some random tokens. // Last comments must be also hidden. $I->amOnPage('/index.php?/section1/new_page1');