Skip to content

Commit

Permalink
[FEATURE] Add Honeypot
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed Oct 20, 2023
1 parent 1520ef4 commit 86543cc
Showing 1 changed file with 66 additions and 36 deletions.
102 changes: 66 additions & 36 deletions src/content_feedback_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class content_feedback_form extends base_content {
'Privacy Confirmation',
'require_privacy_confirmation' => ['Require', 'isNum', FALSE, 'yesno', NULL, '', 0],
'msg_privacy' => ['Privacy declaration', 'isSomeText', FALSE, 'simplerichtext', 5, '', ''],
'Honeypot',
'use_honeypot' => ['Use', 'isNum', FALSE, 'yesno', NULL, '', 0],
'honeypot_label' => ['Label', 'isSomeText', TRUE, 'input', '', 100, 'To'],
'honeypot_name' => ['Name', 'isAlphaNum', TRUE, 'input', '', 20, 'to'],
'Confirmation email',
'confirm_subject' => [
'subject', 'isNoHTML', FALSE, 'input',
Expand Down Expand Up @@ -249,48 +253,55 @@ function getParsedData($parseParams = NULL) {
$this->getXHTMLString($this->data['msg_error_privacy'])
);
}
if (!$this->dialogData->checkDialogInputs()) {
$dialogChecked = FALSE;
if ($this->isHoneypotActivated()) {
$result .= sprintf(
'<message type="error" identifier="error-field">%s<ul><li>%s</li></ul></message>'.LF,
$this->getXHTMLString($this->data['msg_error']),
implode('</li><li>', $this->dialogData->inputErrors)
'<message type="normal">%s</message>'.LF,
$this->getXHTMLString($this->data['msg_send'])
);
}
if ($privacyConfirmed && $dialogChecked) {
// Save data in Session to use later in PDF-Popup
$this->setSessionValue('feedback_params', $this->params);
switch ($this->data['msg_store']) {
case 0: // Send email
$result .= $this->sendEmail();
break;
case 1: // Store feedback in database
$result .= $this->storeFeedback();
break;
case 2: // Store feedback in database and send it as email
$result .= $this->sendEmail();
$this->storeFeedback();
} else {
if (!$this->dialogData->checkDialogInputs()) {
$dialogChecked = FALSE;
$result .= sprintf(
'<message type="error" identifier="error-field">%s<ul><li>%s</li></ul></message>'.LF,
$this->getXHTMLString($this->data['msg_error']),
implode('</li><li>', $this->dialogData->inputErrors)
);
}
if (isset($this->data['result_type']) && isset($this->data['pdf_popup'])) {
if ($this->data['result_type'] >= 1) { // + PDF from 1
$linkPopup = $this->getAbsoluteURL($this->getWebLink(NULL, NULL, 'pdf'));
$result .= sprintf(
'<pdf-popup>'.LF.
'<target>%s</target>'.LF.
'<text>%s</text>'.LF.
'<link>%s</link>'.LF.
'</pdf-popup>'.LF,
papaya_strings::escapeHTMLChars($this->data['pdf_popup']),
$this->getXHTMLString($this->data['save_popup_text'], TRUE),
papaya_strings::escapeHTMLChars($linkPopup)
);
if ($privacyConfirmed && $dialogChecked) {
// Save data in Session to use later in PDF-Popup
$this->setSessionValue('feedback_params', $this->params);
switch ($this->data['msg_store']) {
case 0: // Send email
$result .= $this->sendEmail();
break;
case 1: // Store feedback in database
$result .= $this->storeFeedback();
break;
case 2: // Store feedback in database and send it as email
$result .= $this->sendEmail();
$this->storeFeedback();
}
if ($this->data['result_type'] == 2) { // PDF + HTML
$result .= $this->dialogData->getDialogXML();
if (isset($this->data['result_type']) && isset($this->data['pdf_popup'])) {
if ($this->data['result_type'] >= 1) { // + PDF from 1
$linkPopup = $this->getAbsoluteURL($this->getWebLink(NULL, NULL, 'pdf'));
$result .= sprintf(
'<pdf-popup>'.LF.
'<target>%s</target>'.LF.
'<text>%s</text>'.LF.
'<link>%s</link>'.LF.
'</pdf-popup>'.LF,
papaya_strings::escapeHTMLChars($this->data['pdf_popup']),
$this->getXHTMLString($this->data['save_popup_text'], TRUE),
papaya_strings::escapeHTMLChars($linkPopup)
);
}
if ($this->data['result_type'] == 2) { // PDF + HTML
$result .= $this->dialogData->getDialogXML();
}
}
} else {
$result .= $this->dialogData->getDialogXML();
}
} else {
$result .= $this->dialogData->getDialogXML();
}
} elseif ($params = $this->getSessionValue('feedback_params')) {
$this->params = $params;
Expand All @@ -300,6 +311,14 @@ function getParsedData($parseParams = NULL) {
// Nothing received, return form
$result .= $this->dialogData->getDialogXML();
}
if ($this->data['use_honeypot']) {
$result .= sprintf(
'<honeypot label="%s" name="%s[%s]"/>',
papaya_strings::escapeHTMLChars($this->data['honeypot_label']),
papaya_strings::escapeHTMLChars($this->paramName),
papaya_strings::escapeHTMLChars($this->data['honeypot_name'])
);
}
$result .= sprintf(
'<privacy require-confirmation="%s" name="%s[confirm_privacy]">%s</privacy>',
$this->data['require_privacy_confirmation'] ? 'yes' : 'no',
Expand Down Expand Up @@ -700,4 +719,15 @@ public function isPrivacyConfirmed() {
(isset($this->params['confirm_privacy']) && $this->params['confirm_privacy'])
);
}

public function isHoneypotActivated() {
$name = $this->data['honeypot_name'];
if ($this->data['use_honeypot'] && $name) {
return (
!isset($this->params[$name]) ||
$this->params[$name] !== ''
);
}
return FALSE;
}
}

0 comments on commit 86543cc

Please sign in to comment.