Skip to content

Commit

Permalink
fix: added check if news or FAQs are active
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Feb 14, 2023
1 parent 5061e58 commit db77df8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
9 changes: 2 additions & 7 deletions phpmyfaq/ajaxservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 34 additions & 1 deletion phpmyfaq/src/phpMyFAQ/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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';
Expand Down

0 comments on commit db77df8

Please sign in to comment.