From cbca20a53513eaee798ec4603b610b63637696f7 Mon Sep 17 00:00:00 2001 From: onli Date: Thu, 13 May 2021 15:03:23 +0200 Subject: [PATCH] php 8 compat fixes for commenting in frontend --- include/functions.inc.php | 2 +- include/functions_comments.inc.php | 17 ++++++++++------- include/functions_routing.inc.php | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index 128811d2..cbd21468 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -557,7 +557,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL } } - if ($serendipity['dumpMail']) { + if ($serendipity['dumpMail'] ?? false) { $fp = fopen($serendipity['serendipityPath'] . '/templates_c/mail.log', 'a'); fwrite($fp, date('Y-m-d H:i') . "\n" . print_r($maildata, true)); fclose($fp); diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php index 225138df..967785fd 100644 --- a/include/functions_comments.inc.php +++ b/include/functions_comments.inc.php @@ -702,6 +702,9 @@ function serendipity_approveComment($cid, $entry_id, $force = false, $moderate = AND (type = 'TRACKBACK' or type = 'PINGBACK') AND entry_id = " . (int)$entry_id . " GROUP BY entry_id", true); + if (! is_array($counter_tb)) { + $counter_tb = ['counter' => 0]; + } $query = "UPDATE {$serendipity['dbPrefix']}entries SET comments = " . (int)$counter_comments['counter'] . ", @@ -869,7 +872,7 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)"; $query .= " VALUES ('". (int)$id ."', '$parentid', '$ip', '$name', '$email', '$url', '$commentsFixed', '$type', '$t', '$title', '$subscribe', '$dbstatus', '$referer')"; - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] SQL: ' . $query . "\n"); } @@ -887,16 +890,16 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source } // Approve with force, if moderation is disabled - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { fwrite($fp, '[' . date('d.m.Y H:i') . '] status: ' . $status . ', moderate: ' . $ca['moderate_comments'] . "\n"); } if ($status != 'confirm' && (empty($ca['moderate_comments']) || serendipity_db_bool($ca['moderate_comments']) == false)) { - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { fwrite($fp, '[' . date('d.m.Y H:i') . '] Approving...' . "\n"); } serendipity_approveComment($cid, $id, true); - } elseif ($GLOBALS['tb_logging']) { + } elseif ($GLOBALS['tb_logging'] ?? false) { fwrite($fp, '[' . date('d.m.Y H:i') . '] No need to approve...' . "\n"); } @@ -941,7 +944,7 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source } } - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { fclose($fp); } serendipity_cleanCache(); @@ -1010,7 +1013,7 @@ function serendipity_saveComment($id, $commentInfo, $type = 'NORMAL', $source = serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo); if (!is_array($ca) || serendipity_db_bool($ca['allow_comments'])) { - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] insert comment into DB' . "\n"); fclose($fp); @@ -1021,7 +1024,7 @@ function serendipity_saveComment($id, $commentInfo, $type = 'NORMAL', $source = serendipity_plugin_api::hook_event('frontend_saveComment_finish', $ca, $commentInfo); return true; } else { - if ($GLOBALS['tb_logging']) { + if ($GLOBALS['tb_logging'] ?? false) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] discarding comment from DB' . "\n"); fclose($fp); diff --git a/include/functions_routing.inc.php b/include/functions_routing.inc.php index bcecf9e6..ed4b50c6 100644 --- a/include/functions_routing.inc.php +++ b/include/functions_routing.inc.php @@ -350,7 +350,7 @@ function serveEntry($matches) { $comment['comment'] = (is_string($serendipity['POST']['comment']) ? trim($serendipity['POST']['comment']) : ''); $comment['name'] = $serendipity['POST']['name']; $comment['email'] = $serendipity['POST']['email']; - $comment['subscribe'] = $serendipity['POST']['subscribe']; + $comment['subscribe'] = $serendipity['POST']['subscribe'] ?? false; $comment['parent_id'] = $serendipity['POST']['replyTo']; if (!empty($comment['comment'])) {