From 29e599983ef6ac6f24a6bfa33958213705cb2a78 Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 16:49:03 +0200 Subject: [PATCH 1/6] Add smarty dependency on NotificationService --- action/add_comment.php | 2 +- adminstuds.php | 2 +- app/classes/Framadate/Services/NotificationService.php | 4 +++- studs.php | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/action/add_comment.php b/action/add_comment.php index 71b9ca3..11c9152 100644 --- a/action/add_comment.php +++ b/action/add_comment.php @@ -43,7 +43,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $securityService = new SecurityService(); /* PAGE */ diff --git a/adminstuds.php b/adminstuds.php index 26a2e28..93e7b41 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -51,7 +51,7 @@ $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $sessionService = new SessionService(); /* PAGE */ diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index 615629c..02a74e4 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -15,9 +15,11 @@ class NotificationService { const DELETED_POLL = 11; private $mailService; + private $smarty; - function __construct(MailService $mailService) { + function __construct(MailService $mailService, \Smarty $smarty) { $this->mailService = $mailService; + $this->smarty = $smarty; } /** diff --git a/studs.php b/studs.php index 5dec7c9..2d30882 100644 --- a/studs.php +++ b/studs.php @@ -59,7 +59,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $securityService = new SecurityService(); $sessionService = new SessionService(); From ad8f8ab22cdfe88071cad8ff9b6923dee04e16c5 Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 15:27:39 +0200 Subject: [PATCH 2/6] Extract creation mails content into smarty templates --- create_classic_poll.php | 21 ++++++++----------- tpl/mail/creation_notification_email.html.tpl | 4 ++++ tpl/mail/participants_forward_email.html.tpl | 9 ++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 tpl/mail/creation_notification_email.html.tpl create mode 100644 tpl/mail/participants_forward_email.html.tpl diff --git a/create_classic_poll.php b/create_classic_poll.php index 2950aa9..5c8be30 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -184,19 +184,16 @@ switch ($step) { $admin_poll_id = $ids[1]; // Send confirmation by mail if enabled - if ($config['use_smtp'] === true) { - $message = __('Mail', "This is the message to forward to the poll participants."); - $message .= '

'; - $message .= Utils::htmlMailEscape($form->admin_name) . ' ' . __('Mail', 'has just created a poll called') . ' : "' . Utils::htmlMailEscape($form->title) . '".
'; - $message .= sprintf(__('Mail', 'Thank you for participating in the poll at the following link') . ' :

%1$s', Utils::getUrlSondage($poll_id)); + if ($config['use_smtp'] === true && $mailService->isValidEmail($form->admin_mail)) { + $smarty->assign('poll_creator_name', Utils::htmlMailEscape($form->admin_name)); + $smarty->assign('poll_name', Utils::htmlMailEscape($form->title)); + $smarty->assign('poll_url', Utils::getUrlSondage($poll_id)); + $message_participants = $smarty->fetch('mail/participants_forward_email.html.tpl'); + $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_participants); - $message_admin = __('Mail', "This message should NOT be sent to the poll participants. You should keep it private.

You can modify your poll at the following link"); - $message_admin .= sprintf(' :

%1$s', Utils::getUrlSondage($admin_poll_id, true)); - - if ($mailService->isValidEmail($form->admin_mail)) { - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin); - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message); - } + $smarty->assign('poll_admin_url', Utils::getUrlSondage($admin_poll_id, true)); + $message_admin = $smarty->fetch('mail/creation_notification_email.html.tpl'); + $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin); } // Clean Form data in $_SESSION diff --git a/tpl/mail/creation_notification_email.html.tpl b/tpl/mail/creation_notification_email.html.tpl new file mode 100644 index 0000000..3c46de4 --- /dev/null +++ b/tpl/mail/creation_notification_email.html.tpl @@ -0,0 +1,4 @@ +{__('Mail', "This message should NOT be sent to the poll participants. You should keep it private.

You can modify your poll at the following link")}: +
+
+{$poll_admin_url} diff --git a/tpl/mail/participants_forward_email.html.tpl b/tpl/mail/participants_forward_email.html.tpl new file mode 100644 index 0000000..1df4544 --- /dev/null +++ b/tpl/mail/participants_forward_email.html.tpl @@ -0,0 +1,9 @@ +{__('Mail', "This is the message to forward to the poll participants.")} +
+
+{$poll_creator_name} {__('Mail', 'has just created a poll called')} {$poll_name} +
+{__('Mail', 'Thank you for participating in the poll at the following link')}: +
+
+{$poll_url} From 8dcea674e8ed4ad921589b6b08d369307ed78305 Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 16:50:00 +0200 Subject: [PATCH 3/6] Add notificationservice->sendPollCreationMails --- .../Framadate/Services/NotificationService.php | 12 ++++++++++++ tpl/mail/participants_forward_email.html.tpl | 10 +--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index 02a74e4..aca76c3 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -85,4 +85,16 @@ class NotificationService { { return $type >= self::UPDATE_POLL; } + + function sendPollCreationMails($creator_mail, $creator_name, $poll_name, $poll_id, $admin_poll_id) { + $this->smarty->assign('poll_creator_name', Utils::htmlMailEscape($creator_name)); + $this->smarty->assign('poll_name', Utils::htmlMailEscape($poll_name)); + $this->smarty->assign('poll_url', Utils::getUrlSondage($poll_id)); + $message_participants = $this->smarty->fetch('mail/participants_forward_email.html.tpl'); + $this->mailService->send($creator_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $poll_name, $message_participants); + + $this->smarty->assign('poll_admin_url', Utils::getUrlSondage($admin_poll_id, true)); + $message_admin = $this->smarty->fetch('mail/creation_notification_email.html.tpl'); + $this->mailService->send($creator_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $poll_name, $message_admin); + } } diff --git a/tpl/mail/participants_forward_email.html.tpl b/tpl/mail/participants_forward_email.html.tpl index 1df4544..dc8c3cf 100644 --- a/tpl/mail/participants_forward_email.html.tpl +++ b/tpl/mail/participants_forward_email.html.tpl @@ -1,9 +1 @@ -{__('Mail', "This is the message to forward to the poll participants.")} -
-
-{$poll_creator_name} {__('Mail', 'has just created a poll called')} {$poll_name} -
-{__('Mail', 'Thank you for participating in the poll at the following link')}: -
-
-{$poll_url} +{__('Mail', "This is the message to forward to the poll participants.")}

{$poll_creator_name} {__('Mail', 'has just created a poll called')} {$poll_name}
{__('Mail', 'Thank you for participating in the poll at the following link')}:

{$poll_url} From fb05b82e66d654a3eb5b626c9b99111ba7f81ffb Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 16:50:39 +0200 Subject: [PATCH 4/6] Use NotificationService to send poll creation mails --- create_classic_poll.php | 12 +++--------- create_date_poll.php | 20 ++++---------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/create_classic_poll.php b/create_classic_poll.php index 5c8be30..15966ad 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -21,6 +21,7 @@ use Framadate\Form; use Framadate\Services\InputService; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; use Framadate\Services\PurgeService; use Framadate\Services\SessionService; @@ -33,6 +34,7 @@ include_once __DIR__ . '/app/inc/init.php'; $logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); +$notificationService = new NotificationService($mailService, $smarty); $purgeService = new PurgeService($connect, $logService); $sessionService = new SessionService(); @@ -185,15 +187,7 @@ switch ($step) { // Send confirmation by mail if enabled if ($config['use_smtp'] === true && $mailService->isValidEmail($form->admin_mail)) { - $smarty->assign('poll_creator_name', Utils::htmlMailEscape($form->admin_name)); - $smarty->assign('poll_name', Utils::htmlMailEscape($form->title)); - $smarty->assign('poll_url', Utils::getUrlSondage($poll_id)); - $message_participants = $smarty->fetch('mail/participants_forward_email.html.tpl'); - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_participants); - - $smarty->assign('poll_admin_url', Utils::getUrlSondage($admin_poll_id, true)); - $message_admin = $smarty->fetch('mail/creation_notification_email.html.tpl'); - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin); + $notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id); } // Clean Form data in $_SESSION diff --git a/create_date_poll.php b/create_date_poll.php index af3378c..998653f 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -21,6 +21,7 @@ use Framadate\Form; use Framadate\Services\InputService; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; use Framadate\Services\PurgeService; use Framadate\Services\SessionService; @@ -33,6 +34,7 @@ include_once __DIR__ . '/app/inc/init.php'; $logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); +$notificationService = new NotificationService($mailService, $smarty); $purgeService = new PurgeService($connect, $logService); $inputService = new InputService(); $sessionService = new SessionService(); @@ -223,22 +225,8 @@ switch ($step) { $admin_poll_id = $ids[1]; // Send confirmation by mail if enabled - if ($config['use_smtp'] === true) { - $message = __('Mail', "This is the message to forward to the poll participants."); - $message .= '

'; - $message .= Utils::htmlEscape($form->admin_name) . ' ' . __('Mail', 'has just created a poll called') . ' : "' . Utils::htmlEscape($form->title) . '".
'; - $message .= __('Mail', 'Thank you for participating in the poll at the following link') . ' :

%1$s'; - - $message_admin = __('Mail', "This message should NOT be sent to the poll participants. You should keep it private.

You can modify your poll at the following link"); - $message_admin .= ' :

%1$s'; - - $message = sprintf($message, Utils::getUrlSondage($poll_id)); - $message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true)); - - if ($mailService->isValidEmail($form->admin_mail)) { - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin); - $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message); - } + if ($config['use_smtp'] === true && $mailService->isValidEmail($form->admin_mail)) { + $notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id); } // Clean Form data in $_SESSION From 26d35522764348c111728ad0f089f468594bb12a Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 17:31:06 +0200 Subject: [PATCH 5/6] Move edit link mail notification to NotificationService --- action/send_edit_link_by_email_action.php | 13 +++---------- .../Framadate/Services/NotificationService.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/action/send_edit_link_by_email_action.php b/action/send_edit_link_by_email_action.php index 500fab7..8bf4232 100644 --- a/action/send_edit_link_by_email_action.php +++ b/action/send_edit_link_by_email_action.php @@ -20,6 +20,7 @@ use Framadate\Message; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; use Framadate\Services\SessionService; use Framadate\Utils; @@ -29,6 +30,7 @@ include_once __DIR__ . '/../app/inc/init.php'; $logService = new LogService(); $sessionService = new SessionService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); +$notificationService = new NotificationService($mailService, $smarty); $pollService = new PollService($connect, $logService); $result = false; @@ -70,16 +72,7 @@ if (is_null($message)) { } if (is_null($message)) { - $url = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId); - - $smarty->assign('poll', $poll); - $smarty->assign('poll_id', $poll_id); - $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); - $body = $smarty->fetch('mail/remember_edit_link.tpl'); - - $subject = '[' . NOMAPPLICATION . '][' . __('EditLink', 'REMINDER') . '] ' . __f('EditLink', 'Edit link for poll "%s"', $poll->title); - - $mailService->send($email, $subject, $body); + $notificationService->sendEditedVoteNotification($email, $poll, $poll_id, $editedVoteUniqueId); $sessionService->remove("Common", SESSION_EDIT_LINK_TOKEN); $sessionService->set("Common", SESSION_EDIT_LINK_TIME, time()); diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index aca76c3..c2df0e5 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -97,4 +97,17 @@ class NotificationService { $message_admin = $this->smarty->fetch('mail/creation_notification_email.html.tpl'); $this->mailService->send($creator_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $poll_name, $message_admin); } + + function sendEditedVoteNotification($email, &$poll, $poll_id, $edited_vote_id) { + $url = Utils::getUrlSondage($poll_id, false, $edited_vote_id); + + $this->smarty->assign('poll', $poll); + $this->smarty->assign('poll_id', $poll_id); + $this->smarty->assign('editedVoteUniqueId', $edited_vote_id); + $body = $this->smarty->fetch('mail/remember_edit_link.tpl'); + + $subject = '[' . NOMAPPLICATION . '][' . __('EditLink', 'REMINDER') . '] ' . __f('EditLink', 'Edit link for poll "%s"', $poll->title); + + $this->mailService->send($email, $subject, $body); + } } From c72dfa17b833d5ab4bfaede6040a0b3961c7815a Mon Sep 17 00:00:00 2001 From: Liquidsoul Date: Wed, 17 Apr 2019 17:39:33 +0200 Subject: [PATCH 6/6] Extract mail creation for FindPollsByMail into NotificationService --- app/classes/Framadate/Services/NotificationService.php | 7 +++++++ find_polls.php | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index c2df0e5..e0ae590 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -110,4 +110,11 @@ class NotificationService { $this->mailService->send($email, $subject, $body); } + + function sendFindPollsByMailNotification($mail, &$polls) { + $this->smarty->assign('polls', $polls); + $body = $this->smarty->fetch('mail/find_polls.tpl'); + + $this->mailService->send($mail, __('FindPolls', 'List of your polls') . ' - ' . NOMAPPLICATION, $body, 'SEND_POLLS'); + } } diff --git a/find_polls.php b/find_polls.php index 7fda3b3..0a1b3f9 100644 --- a/find_polls.php +++ b/find_polls.php @@ -20,6 +20,7 @@ use Framadate\Message; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; include_once __DIR__ . '/app/inc/init.php'; @@ -29,6 +30,7 @@ include_once __DIR__ . '/app/inc/init.php'; $logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); +$notificationService = new NotificationService($mailService, $smarty); /* PAGE */ /* ---- */ @@ -40,10 +42,7 @@ if (!empty($_POST['mail'])) { $polls = $pollService->findAllByAdminMail($mail); if (count($polls) > 0) { - $smarty->assign('polls', $polls); - $body = $smarty->fetch('mail/find_polls.tpl'); - - $mailService->send($mail, __('FindPolls', 'List of your polls') . ' - ' . NOMAPPLICATION, $body, 'SEND_POLLS'); + $notificationService->sendFindPollsByMailNotification($mail, $polls); $message = new Message('success', __('FindPolls', 'Polls sent')); } else { $message = new Message('warning', __('Error', 'No polls found'));