From db77df888178766987398597d4f153831c62a503 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Tue, 14 Feb 2023 19:14:05 +0100 Subject: [PATCH] fix: added check if news or FAQs are active --- phpmyfaq/ajaxservice.php | 9 ++------- phpmyfaq/src/phpMyFAQ/Faq.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/phpmyfaq/ajaxservice.php b/phpmyfaq/ajaxservice.php index 74fd48d1ca..427f87a12e 100644 --- a/phpmyfaq/ajaxservice.php +++ b/phpmyfaq/ajaxservice.php @@ -185,13 +185,8 @@ } if ( - !is_null($username) && !is_null($mailer) && !is_null($comment) && $stopWords->checkBannedWord( - $comment - ) && !$faq->commentDisabled( - $id, - $languageCode, - $type - ) + !is_null($username) && !is_null($mailer) && !is_null($comment) && $stopWords->checkBannedWord($comment) && + !$faq->commentDisabled($id, $languageCode, $type) && !$faq->isActive($id, $languageCode, $type) ) { try { $faqSession->userTracking('save_comment', $id); diff --git a/phpmyfaq/src/phpMyFAQ/Faq.php b/phpmyfaq/src/phpMyFAQ/Faq.php index 834a6168db..b66e2507c7 100755 --- a/phpmyfaq/src/phpMyFAQ/Faq.php +++ b/phpmyfaq/src/phpMyFAQ/Faq.php @@ -1258,6 +1258,39 @@ public function hasTranslation(int $recordId, string $recordLang): bool return false; } + public function isActive(int $recordId, string $recordLang, string $commentType = 'faq'): bool + { + if ('news' === $commentType) { + $table = 'faqnews'; + } else { + $table = 'faqdata'; + } + + $query = sprintf( + " + SELECT + active + FROM + %s%s + WHERE + id = %d + AND + lang = '%s'", + Database::getTablePrefix(), + $table, + $recordId, + $this->config->getDb()->escape($recordLang) + ); + + $result = $this->config->getDb()->query($query); + + if ($row = $this->config->getDb()->fetchObject($result)) { + return !(($row->active === 'y' || $row->active === 'yes')); + } else { + return true; + } + } + /** * Checks, if comments are disabled for the FAQ record. * @@ -1268,7 +1301,7 @@ public function hasTranslation(int $recordId, string $recordLang): bool */ public function commentDisabled(int $recordId, string $recordLang, string $commentType = 'faq'): bool { - if ('news' == $commentType) { + if ('news' === $commentType) { $table = 'faqnews'; } else { $table = 'faqdata';