From 7ffa8c9bcaf8d76560869b23724e1108a9fa0f2a Mon Sep 17 00:00:00 2001
From: Ahonen Mika J
Date: Tue, 2 Mar 2021 17:10:56 +0200
Subject: [PATCH 1/5] Sends a feedback with a Subject field. Next steps:
language support/unittests
---
controller/WebController.php | 15 +++++----------
resource/js/docready.js | 2 +-
view/feedback.twig | 2 ++
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/controller/WebController.php b/controller/WebController.php
index 0b41b6ecd..c7708b0f0 100644
--- a/controller/WebController.php
+++ b/controller/WebController.php
@@ -213,18 +213,16 @@ public function invokeFeedbackForm($request)
}
$feedbackName = $request->getQueryParamPOST('name');
$feedbackEmail = $request->getQueryParamPOST('email');
+ $msgSubject = $request->getQueryParamPOST('msgsubject');
$feedbackVocab = $request->getQueryParamPOST('vocab');
-
$feedbackVocabEmail = ($feedbackVocab !== null && $feedbackVocab !== '') ?
$this->model->getVocabulary($feedbackVocab)->getConfig()->getFeedbackRecipient() : null;
-
// if the hidden field has been set a value we have found a spam bot
// and we do not actually send the message.
if ($this->honeypot->validateHoneypot($request->getQueryParamPOST('item-description')) &&
$this->honeypot->validateHoneytime($request->getQueryParamPOST('user-captcha'), $this->model->getConfig()->getHoneypotTime())) {
- $this->sendFeedback($request, $feedbackMsg, $feedbackName, $feedbackEmail, $feedbackVocab, $feedbackVocabEmail);
+ $this->sendFeedback($request, $feedbackMsg, $feedbackName, $feedbackEmail, $feedbackVocab, $feedbackVocabEmail, $msgSubject);
}
-
echo $template->render(
array(
'languages' => $this->languages,
@@ -245,7 +243,6 @@ private function createFeedbackHeaders($fromName, $fromEmail, $toMail, $sender)
if (!empty($fromEmail)) {
$headers .= "Reply-To: $fromName <$fromEmail>\r\n";
}
-
$service = $this->model->getConfig()->getServiceName();
return $headers . "From: $fromName via $service <$sender>";
}
@@ -253,11 +250,12 @@ private function createFeedbackHeaders($fromName, $fromEmail, $toMail, $sender)
/**
* Sends the user entered message through the php's mailer.
* @param string $message only required parameter is the actual message.
+ * @param string $messageSubject from the sender.
* @param string $fromName senders own name.
* @param string $fromEmail senders email address.
* @param string $fromVocab which vocabulary is the feedback related to.
*/
- public function sendFeedback($request, $message, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
+ public function sendFeedback($request, $message, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null, $messageSubject)
{
$toAddress = ($toMail) ? $toMail : $this->model->getConfig()->getFeedbackAddress();
if ($fromVocab !== null && $fromVocab !== '') {
@@ -265,7 +263,6 @@ public function sendFeedback($request, $message, $fromName = null, $fromEmail =
}
$envelopeSender = $this->model->getConfig()->getFeedbackEnvelopeSender();
- $subject = $this->model->getConfig()->getServiceName() . " feedback";
// determine the sender address of the message
$sender = $this->model->getConfig()->getFeedbackSender();
if (empty($sender)) $sender = $envelopeSender;
@@ -273,10 +270,8 @@ public function sendFeedback($request, $message, $fromName = null, $fromEmail =
// determine sender name - default to "anonymous user" if not given by user
if (empty($fromName)) $fromName = "anonymous user";
-
$headers = $this->createFeedbackHeaders($fromName, $fromEmail, $toMail, $sender);
$params = empty($envelopeSender) ? '' : "-f $envelopeSender";
-
// adding some information about the user for debugging purposes.
$message = $message . "
Debugging information:"
. " Timestamp: " . date(DATE_RFC2822)
@@ -284,7 +279,7 @@ public function sendFeedback($request, $message, $fromName = null, $fromEmail =
. " Referer: " . $request->getServerConstant('HTTP_REFERER');
try {
- mail($toAddress, $subject, $message, $headers, $params);
+ mail($toAddress, $messageSubject, $message, $headers, $params);
} catch (Exception $e) {
header("HTTP/1.0 404 Not Found");
$template = $this->twig->loadTemplate('error-page.twig');
diff --git a/resource/js/docready.js b/resource/js/docready.js
index 2300065e3..bf662f386 100644
--- a/resource/js/docready.js
+++ b/resource/js/docready.js
@@ -712,7 +712,7 @@ $(function() { // DOCUMENT READY
// changes the response so it can be easily displayed in the handlebars template.
filter: function(data) {
// looping the matches to see if there are hits where the concept has been hit by a property other than hiddenLabel
- var hasNonHiddenMatch = {};
+ var hasNonHiddenMatch = {feedback};
for (var i = 0; i < data.results.length; i++) {
var hit = data.results[i];
if (!hit.hiddenLabel) {
diff --git a/view/feedback.twig b/view/feedback.twig
index f5869e9be..f385aae95 100644
--- a/view/feedback.twig
+++ b/view/feedback.twig
@@ -35,6 +35,8 @@