Skip to content

Commit

Permalink
Fixed <!-- s2_last_comments --> and <!-- s2_last_discussions --> plac…
Browse files Browse the repository at this point in the history
…eholders processing when comments are disabled (closes #5).
  • Loading branch information
parpalak committed May 3, 2024
1 parent 0abb664 commit 6c45828
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
18 changes: 10 additions & 8 deletions _extensions/s2_blog/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 10 additions & 8 deletions _include/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions _include/templates/mainpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<!-- s2_menu_children -->
<!-- s2_menu_subsections -->
<!-- s2_last_comments -->
<!-- s2_last_discussions -->
<!-- s2_blog_last_comments -->
<!-- s2_blog_last_discussions -->
</div>
<div class="clearing"></div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions _tests/acceptance/InstallCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ private function testAdminCommentManagement(AcceptanceTester $I): void
$I->sendAjaxPostRequest('/_admin/site_ajax.php?action=save_options', $data);
$I->seeResponseCodeIsSuccessful();

// Test <!-- s2_last_comments --> and <!-- s2_last_discussions --> 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');
Expand Down

0 comments on commit 6c45828

Please sign in to comment.