Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Version 2.7-alpha1 ()
------------------------------------------------------------------------

* Fix division by zero error when accessing all PHP comments on PHP 8
(thanks to @qbi)

* Fix error message and 404 status code on plugin pages when cache
was active (thanks to @fasterit/DLange)

Expand Down
10 changes: 7 additions & 3 deletions include/admin/comments.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

$data = array();

$commentsPerPage = (int)(!empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10);
$commentsPerPage = !empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10;
if ($commentsPerPage != COMMENTS_FILTER_ALL) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, good catch and good fix!

My suggestion would be to change the first section as follows.
This introduces a stricter (type-safe) check against COMMENTS_FILTER_ALL.

if ($commentsPerPage !== COMMENTS_FILTER_ALL) {
    $commentsPerPage = (int)$commentsPerPage;
}

What do you think?

$commentsPerPage = (int)($commentsPerPage);
}

$summaryLength = 200;

$errormsg = array();
Expand Down Expand Up @@ -257,7 +261,7 @@
$sql = serendipity_db_query("SELECT COUNT(*) AS total FROM {$serendipity['dbPrefix']}comments c WHERE 1 = 1 " . ($c_type !== null ? " AND c.type = '$c_type' " : '') . $and, true);

$totalComments = $sql['total'];
$pages = ($commentsPerPage == COMMENTS_FILTER_ALL ? 1 : ceil($totalComments/(int)$commentsPerPage));
$pages = ($commentsPerPage === COMMENTS_FILTER_ALL ? 1 : ceil($totalComments/(int)$commentsPerPage));
if (isset($serendipity['GET']['page'])) {
$page = (int)$serendipity['GET']['page'];
} else {
Expand All @@ -271,7 +275,7 @@
$linkNext = 'serendipity_admin.php?serendipity[adminModule]=comments&serendipity[page]='. ($page+1) . $searchString;
$filter_vals = array(10, 20, 50, COMMENTS_FILTER_ALL);

if ($commentsPerPage == COMMENTS_FILTER_ALL) {
if ($commentsPerPage === COMMENTS_FILTER_ALL) {
$limit = '';
} else {
$limit = serendipity_db_limit_sql(serendipity_db_limit(($page-1)*(int)$commentsPerPage, (int)$commentsPerPage));
Expand Down