Skip to content

Commit e47d3ec

Browse files
authored
[4.0] Converting several mails to mail templates (#28722)
1 parent 7196289 commit e47d3ec

File tree

21 files changed

+215
-185
lines changed

21 files changed

+215
-185
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INSERT INTO `#__mail_templates` (`template_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES
2+
('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
3+
('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
4+
('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
5+
('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
6+
('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
7+
('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
8+
('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INSERT INTO "#__mail_templates" ("template_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES
2+
('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
3+
('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
4+
('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
5+
('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
6+
('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
7+
('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
8+
('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');

administrator/components/com_mails/src/View/Template/HtmlView.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function display($tpl = null)
8787
$fields = array('subject', 'body', 'htmlbody');
8888
$this->templateData = array();
8989
$language = Factory::getLanguage();
90+
$language->load($component, JPATH_SITE, $this->item->language, true);
9091
$language->load($component, JPATH_ADMINISTRATOR, $this->item->language, true);
9192

9293
foreach ($fields as $field)

administrator/components/com_mails/tmpl/template/edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
$input = $app->input;
3030
list($component, $sub_id) = explode('.', $this->master->template_id, 2);
31+
$sub_id = str_replace('.', '_', $sub_id);
3132

3233
$doc->addScriptOptions('com_mails', ['templateData' => $this->templateData]);
3334

administrator/components/com_mails/tmpl/templates/default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<tbody>
6060
<?php foreach ($this->items as $i => $item) :
6161
list($component, $sub_id) = explode('.', $item->template_id, 2);
62+
$sub_id = str_replace('.', '_', $sub_id);
6263
?>
6364
<tr class="row<?php echo $i % 2; ?>">
6465
<td class="break-word">

administrator/components/com_users/src/Model/MailModel.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Joomla\CMS\Language\Text;
2020
use Joomla\CMS\Log\Log;
2121
use Joomla\CMS\Mail\Exception\MailDisabledException;
22+
use Joomla\CMS\Mail\MailTemplate;
2223
use Joomla\CMS\MVC\Model\AdminModel;
2324
use Joomla\Database\ParameterType;
2425
use PHPMailer\PHPMailer\Exception as phpMailerException;
@@ -97,11 +98,12 @@ protected function preprocessForm(Form $form, $data, $group = 'user')
9798
*/
9899
public function send()
99100
{
100-
$app = Factory::getApplication();
101-
$data = $app->input->post->get('jform', array(), 'array');
102-
$user = Factory::getUser();
103-
$access = new Access;
104-
$db = $this->getDbo();
101+
$app = Factory::getApplication();
102+
$data = $app->input->post->get('jform', array(), 'array');
103+
$user = Factory::getUser();
104+
$access = new Access;
105+
$db = $this->getDbo();
106+
$language = Factory::getLanguage();
105107

106108
$mode = array_key_exists('mode', $data) ? (int) $data['mode'] : 0;
107109
$subject = array_key_exists('subject', $data) ? $data['subject'] : '';
@@ -176,30 +178,40 @@ public function send()
176178
}
177179

178180
// Get the Mailer
179-
$mailer = Factory::getMailer();
181+
$mailer = new MailTemplate('com_users.massmail.mail', $language->getTag());
180182
$params = ComponentHelper::getParams('com_users');
181183

182184
try
183185
{
184186
// Build email message format.
185-
$mailer->setSender(array($app->get('mailfrom'), $app->get('fromname')));
186-
$mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject));
187-
$mailer->setBody($message_body . $params->get('mailBodySuffix'));
188-
$mailer->IsHtml($mode);
187+
$data = [
188+
'subject' => stripslashes($subject),
189+
'body' => $message_body,
190+
'subjectprefix' => $params->get('mailSubjectPrefix', ''),
191+
'bodysuffix' => $params->get('mailBodySuffix', '')
192+
];
193+
$mailer->addTemplateData($data);
189194

190195
// Add recipients
191196
if ($bcc)
192197
{
193-
$mailer->addBcc($rows);
198+
foreach ($rows as $row)
199+
{
200+
$mailer->addRecipient($row, null, 'bcc');
201+
}
202+
194203
$mailer->addRecipient($app->get('mailfrom'));
195204
}
196205
else
197206
{
198-
$mailer->addRecipient($rows);
207+
foreach ($rows as $row)
208+
{
209+
$mailer->addRecipient($row);
210+
}
199211
}
200212

201213
// Send the Mail
202-
$rs = $mailer->Send();
214+
$rs = $mailer->send();
203215
}
204216
catch (MailDisabledException | phpMailerException $exception)
205217
{

administrator/language/en-GB/com_contact.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ COM_CONTACT_HEADING_ASSOCIATION="Association"
141141
COM_CONTACT_ICONS_SETTINGS="Icons"
142142
COM_CONTACT_ID_LABEL="ID"
143143
COM_CONTACT_MAIL_FIELDSET_LABEL="Mail Options"
144+
COM_CONTACT_MAIL_MAIL_COPY_DESC="This mail is sent to the submitter of a mail with the contact form if option \"Send Copy to Submitter\" is switched on in the form settings."
145+
COM_CONTACT_MAIL_MAIL_COPY_TITLE="Contacts: Contact Form Mail Copy"
146+
COM_CONTACT_MAIL_MAIL_DESC="This mail is sent with the contact form."
147+
COM_CONTACT_MAIL_MAIL_TITLE="Contacts: Contact Form Mail"
144148
COM_CONTACT_MANAGER_CONTACTS="Contacts"
145149
COM_CONTACT_MANAGER_CONTACT_EDIT="Contacts: Edit"
146150
COM_CONTACT_MANAGER_CONTACT_NEW="Contacts: New"

administrator/language/en-GB/com_users.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,23 @@ COM_USERS_MAIL_FIELD_SEND_AS_BLIND_CARBON_COPY_LABEL="Recipients as BCC"
178178
COM_USERS_MAIL_FIELD_SEND_IN_HTML_MODE_LABEL="Send in HTML Mode"
179179
COM_USERS_MAIL_FIELD_SUBJECT_LABEL="Subject"
180180
COM_USERS_MAIL_FIELD_VALUE_ALL_USERS_GROUPS="All Users Groups"
181+
COM_USERS_MAIL_MASSMAIL_MAIL_DESC="This mail is sent with the \"Mass Mail Users\" form in backend."
182+
COM_USERS_MAIL_MASSMAIL_MAIL_TITLE="Users: Mass Mail Users"
181183
COM_USERS_MAIL_NO_USERS_COULD_BE_FOUND_IN_THIS_GROUP="No users could be found in this group."
182184
COM_USERS_MAIL_ONLY_YOU_COULD_BE_FOUND_IN_THIS_GROUP="You are the only user in this group."
185+
COM_USERS_MAIL_PASSWORD_RESET_DESC="This mail is sent to a user by using the \"Forgot your password?\" link e.g. in a login form."
186+
COM_USERS_MAIL_PASSWORD_RESET_TITLE="Users: Password Reset"
183187
COM_USERS_MAIL_PLEASE_FILL_IN_THE_FORM_CORRECTLY="Please fill in the form correctly."
184188
COM_USERS_MAIL_PLEASE_FILL_IN_THE_MESSAGE="Please enter a message"
185189
COM_USERS_MAIL_PLEASE_FILL_IN_THE_SUBJECT="Please enter a subject"
186190
COM_USERS_MAIL_PLEASE_SELECT_A_GROUP="Please select a Group"
191+
COM_USERS_MAIL_REMINDER_DESC="This mail is sent to a user when by the \"Forgot your username?\" link e.g. in a login form."
192+
COM_USERS_MAIL_REMINDER_TITLE="Users: Username Reminder"
187193
COM_USERS_MAIL_THE_MAIL_COULD_NOT_BE_SENT="The mail could not be sent."
188194
COM_USERS_MASS_MAIL="Mass Mail Users"
189195
COM_USERS_MASS_MAIL_DESC="Mass Mail options."
196+
COM_USERS_MASSMAIL_MAIL_BODY="{BODY} {BODYSUFFIX}"
197+
COM_USERS_MASSMAIL_MAIL_SUBJECT="{SUBJECTPREFIX} {SUBJECT}"
190198
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N="Password does not have enough digits. At least %s digits are required."
191199
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N_1="Password does not have enough digits. At least 1 digit is required."
192200
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N="Password does not have enough lower case characters. At least %s lower case characters are required."

administrator/language/en-GB/plg_system_updatenotification.ini

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66
PLG_SYSTEM_UPDATENOTIFICATION="System - Joomla! Update Notification"
77
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_LBL="Super User Emails"
88
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_DESC="A comma separated list of the email addresses which will receive the update notification emails. The addresses in the list MUST belong to existing users of your site who have the Super User privilege. If none of the listed emails belongs to Super Users, or if it's left blank, all Super Users of this site will receive the update notification email."
9-
; You can use the following merge codes:
10-
; [NEWVERSION] New Joomla! version, e.g. 1.2.3
11-
; [CURVERSION] Currently installed Joomla! version, e.g. 1.2.0
12-
; [SITENAME] Site name, as set in Global Configuration.
13-
; [URL] URL of the site's frontend page.
14-
; [LINK] Update URL (link to com_joomlaupdate, will request login if the Super User isn't already logged in).
15-
; [RELEASENEWS] URL to the release news on joomla.org
16-
; \n Newline character. Use it to start a new line in the email.
17-
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT="Joomla! Update available for [SITENAME] – [URL]"
18-
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY="This email IS NOT sent by Joomla.org. It is sent automatically by your own site,\n[SITENAME] - [URL] \n\n================================================================================\nUPDATE INFORMATION\n================================================================================\n\nYour site has discovered that there is an updated version of Joomla! available for download.\n\nJoomla! version currently installed: [CURVERSION]\nJoomla! version available for installation: [NEWVERSION]\n\nThis email is sent to you by your site to remind you of this fact.\nThe Joomla! project will never contact you directly about available updates of Joomla! on your site.\n\n================================================================================\nUPDATE INSTRUCTIONS\n================================================================================\n\nTo install the update on [SITENAME] please select the following link. (If the URL is not a link, copy & paste it to your browser).\n\nUpdate link: [LINK]\n\nRelease News can be found here: [RELEASENEWS]\n\n================================================================================\nWHY AM I RECEIVING THIS EMAIL?\n================================================================================\n\nThis email has been automatically sent by a plugin provided by Joomla!, the software which powers your site.\nThis plugin looks for updated versions of Joomla! and sends an email notification to its administrators.\nYou will receive several similar emails from your site until you either update the software or disable these emails.\n\nTo disable these emails, please unpublish the 'System - Joomla! Update Notification' plugin in the Plugin Manager on your site.\n\nIf you do not understand what Joomla! is and what you need to do please do not contact the Joomla! project.\nThey are NOT sending you this email and they cannot help you. Instead, please contact the person who built or manages your site.\n\nIf you are the person who built or manages your website, please note that this plugin may have been activated automatically when you installed or updated Joomla! on your site.\n\n================================================================================\nWHO SENT ME THIS EMAIL?\n================================================================================\n\nThis email is sent to you by your own site, [SITENAME]"
9+
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT="Joomla! Update available for {SITENAME} – {URL}"
10+
PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY="This email IS NOT sent by Joomla.org. It is sent automatically by your own site,\n{SITENAME} - {URL} \n\n================================================================================\nUPDATE INFORMATION\n================================================================================\n\nYour site has discovered that there is an updated version of Joomla! available for download.\n\nJoomla! version currently installed: {CURVERSION}\nJoomla! version available for installation: {NEWVERSION}\n\nThis email is sent to you by your site to remind you of this fact.\nThe Joomla! project will never contact you directly about available updates of Joomla! on your site.\n\n================================================================================\nUPDATE INSTRUCTIONS\n================================================================================\n\nTo install the update on {SITENAME} please select the following link. (If the URL is not a link, copy & paste it to your browser).\n\nUpdate link: {LINK}\n\nRelease News can be found here: {RELEASENEWS}\n\n================================================================================\nWHY AM I RECEIVING THIS EMAIL?\n================================================================================\n\nThis email has been automatically sent by a plugin provided by Joomla!, the software which powers your site.\nThis plugin looks for updated versions of Joomla! and sends an email notification to its administrators.\nYou will receive several similar emails from your site until you either update the software or disable these emails.\n\nTo disable these emails, please unpublish the 'System - Joomla! Update Notification' plugin in the Plugin Manager on your site.\n\nIf you do not understand what Joomla! is and what you need to do please do not contact the Joomla! project.\nThey are NOT sending you this email and they cannot help you. Instead, please contact the person who built or manages your site.\n\nIf you are the person who built or manages your website, please note that this plugin may have been activated automatically when you installed or updated Joomla! on your site.\n\n================================================================================\nWHO SENT ME THIS EMAIL?\n================================================================================\n\nThis email is sent to you by your own site, {SITENAME}"
1911
PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_LBL="Email Language"
2012
PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_DESC="Select a language for the update notification emails. Set to Auto to send them in the site language at the time."
2113
PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_NONE="Auto"
14+
PLG_SYSTEM_UPDATENOTIFICATION_MAIL_MAIL_DESC="This mail is sent to the site administrator when the \"Joomla! Update Notification\" system plugin has detected an available update."
15+
PLG_SYSTEM_UPDATENOTIFICATION_MAIL_MAIL_TITLE="Joomla: Update Notification"
2216
PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME="The Joomla! Update Notification will not run in this configuration"
2317
PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY="In your Installer Configuration you have set the Option Update Cache (in Hours) to 0 this means that Joomla is not caching the Update. This means an email should be sent on every page visit but this is not possible. Please increase the value (6 is default) or confirm that the Joomla! Update Notification will never send you mails."
2418
PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION="Set it back to the default setting (6 Hours)"

administrator/language/en-GB/plg_user_joomla.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ PLG_USER_JOOMLA_FIELD_AUTOREGISTER_LABEL="Auto-create Users"
88
PLG_USER_JOOMLA_FIELD_FORCELOGOUT_LABEL="Force Logout for all Sessions?"
99
PLG_USER_JOOMLA_FIELD_MAILTOUSER_LABEL="Notification Mail to User"
1010
PLG_USER_JOOMLA_FIELD_STRONG_PASSWORDS_LABEL="Strong Passwords"
11-
PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY="Hello %s,\n\n\nYou have been added as a User to %s by an Administrator.\n\nThis email has your username and password to log in to %s\n\nUsername: %s\nPassword: %s\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only."
11+
PLG_USER_JOOMLA_MAIL_MAIL_DESC="This mail is sent to a new user who has just been created in backend."
12+
PLG_USER_JOOMLA_MAIL_MAIL_TITLE="Users: New User"
13+
PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY="Hello {NAME},\n\n\nYou have been added as a User to {SITENAME} by an Administrator.\n\nThis email has your username and password to log in to {URL}\n\nUsername: {USERNAME}\nPassword: {PASSWORD}\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only."
1214
PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT="New User Details"
1315
PLG_USER_JOOMLA_POSTINSTALL_STRONGPW_BTN="Enable Strong Password Encryption"
1416
PLG_USER_JOOMLA_POSTINSTALL_STRONGPW_TEXT="As a security feature, Joomla allows you to switch to strong password encryption.<br>To turn strong passwords on select the button below. Alternatively you can edit the User - Joomla plugin and change the strong password setting to On.<br>Before enabling you should verify that all third party registration/login, user management or bridge extensions installed on your site support this strong password encryption."

0 commit comments

Comments
 (0)