Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ public static function getHumanReadableLogMessage($log, $generateLinks = true)
$messageData['type'] = Text::_($messageData['type']);
}

// Remove links from the message template, if we should not generate links.
if (!$generateLinks) {
$message = preg_replace('/<a href=["\'].+?["\']>/', '', $message);
$message = str_replace('</a>', '', $message);
}

$linkMode = Factory::getApplication()->get('force_ssl', 0) >= 1 ? Route::TLS_FORCE : Route::TLS_IGNORE;

foreach ($messageData as $key => $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ protected function sendNotificationEmails($messages, $username, $context)
$lang->load('com_actionlogs', JPATH_ADMINISTRATOR);
ActionlogsHelper::loadTranslationFiles($extension);
$temp = [];
$tempPlain = [];

foreach ($messages as $message) {
$m = [];
Expand All @@ -159,14 +160,23 @@ protected function sendNotificationEmails($messages, $username, $context)
$m['date'] = HTMLHelper::_('date', $message->log_date, 'Y-m-d H:i:s T', 'UTC');
$m['username'] = $username;
$temp[] = $m;

// copy replacement tags array and set non-HTML message.
$mPlain = array_merge([], $m);
$mPlain['message'] = ActionlogsHelper::getHumanReadableLogMessage($message, false);
$tempPlain[] = $mPlain;
}

$templateData = [
'messages' => $temp,
];
$templateDataPlain = [
'messages' => $tempPlain,
];

$mailer = new MailTemplate('com_actionlogs.notification', $app->getLanguage()->getTag());
$mailer->addTemplateData($templateData);
$mailer->addTemplateData($templateDataPlain, true);

foreach ($recipients as $recipient) {
$mailer->addRecipient($recipient);
Expand Down
20 changes: 17 additions & 3 deletions libraries/src/Mail/MailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class MailTemplate
*/
protected $data = [];

/**
*
* @var string[]
* @since __DEPLOY_VERSION__
*/
protected $plain_data = [];

/**
*
* @var string[]
Expand Down Expand Up @@ -164,14 +171,19 @@ public function setReplyTo($mail, $name = '')
* Add data to replace in the template
*
* @param array $data Associative array of strings to replace
* @param bool $plain Only use the data for plain-text emails.
*
* @return void
*
* @since 4.0.0
*/
public function addTemplateData($data)
public function addTemplateData($data, $plain = false)
{
$this->data = array_merge($this->data, $data);
if (!$plain) {
$this->data = array_merge($this->data, $data);
} else {
$this->plain_data = array_merge($this->plain_data, $data);
}
}

/**
Expand Down Expand Up @@ -233,7 +245,9 @@ public function send()
$this->mailer->setSubject($subject);

$mailStyle = $config->get('mail_style', 'plaintext');
$plainBody = $this->replaceTags(Text::_($mail->body), $this->data);
// Use the plain-text replacement data, if specified.
$plainData = $this->plain_data ?: $this->data;
$plainBody = $this->replaceTags(Text::_($mail->body), $plainData);
$htmlBody = $this->replaceTags(Text::_($mail->htmlbody), $this->data);

if ($mailStyle === 'plaintext' || $mailStyle === 'both') {
Expand Down