Skip to content
Open
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
17 changes: 17 additions & 0 deletions custom/templates/DefaultRevamp/email/notification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>[Sitename] &bull; [Title]</title>
</head>

<body>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<h3>[Greeting]</h3>
<p>[Content]</p>
<a href="[Link]">[Link]</a>
<hr>
[Thanks]<br />[Sitename]
</div>
</body>
</html>
30 changes: 20 additions & 10 deletions modules/Core/classes/Core/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,32 @@ class Notification {
/**
* Instantiate a new notification
*
* @param string $type Type of notification
* @param AlertTemplate $alertTemplate Alert template
* @param EmailTemplate $emailTemplate Email template
* @param int|int[] $recipients Notification recipient or recipients - array of user IDs
* @param int $authorId User ID that sent the notification
* @param bool $bypassNotificationSettings Whether to bypass the user's notification settings
* @param string $type Type of notification
* @param string|LanguageKey $title Title of notification
* @param string|LanguageKey $content Notification content. For alerts, if $alertUrl is set, this will ignored. If $alertUrl is not set, this will be the content of the alert. This will always be the content of the email.
* @param int|int[] $recipients Notification recipient or recipients - array of user IDs
* @param int $authorId User ID that sent the notification
* @param bool $bypassNotificationSettings Whether to bypass the user's notification settings
* @param ?string $link Optional URL to link to when clicking the alert
*
* @throws NotificationTypeNotFoundException
*/
public function __construct(
string $type,
AlertTemplate $alertTemplate,
EmailTemplate $emailTemplate,
string|LanguageKey $title,
string|LanguageKey $content,
int|array $recipients,
int $authorId,
bool $bypassNotificationSettings = false,
?string $link = null,
) {
if (!in_array($type, array_column(self::getTypes(), 'key'))) {
throw new NotificationTypeNotFoundException("Type $type not registered");
}

$this->_type = $type;
$this->_alertTemplate = $alertTemplate;
$this->_emailTemplate = $emailTemplate;
$this->_alertTemplate = new AlertTemplate($title, $link ? null : $content, $link);
$this->_emailTemplate = new NotificationEmailTemplate($title, $content, $link);
$this->_authorId = $authorId;
$this->_bypassNotificationSettings = $bypassNotificationSettings;

Expand All @@ -72,6 +74,14 @@ public function __construct(
}, $recipients);
}

public function setAlertTemplate(AlertTemplate $template): void {
$this->_alertTemplate = $template;
}

public function setEmailTemplate(EmailTemplate $template): void {
$this->_emailTemplate = $template;
}

public function send(): void {
/** @var array $recipient */
foreach ($this->_recipients as $recipient) {
Expand Down
24 changes: 24 additions & 0 deletions modules/Core/classes/Email_Templates/NotificationEmailTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class NotificationEmailTemplate extends EmailTemplate
{
private string $subject;

public function __construct(string $subject, string $content, ?string $link)
{
$this->subject = $subject;

$this->addPlaceholder('[Title]', $subject);
$this->addPlaceholder('[Content]', $content);

// Register all notifications to nl2_alerts even if alert preference is off? Then all links can be sent to /user/alerts/?id={ID} then it will direct user + mark as read
$this->addPlaceholder('[Link]', $link ?? URL::getSelfURL());

parent::__construct();
}

public function subject(): string
{
return $this->subject;
}
}
14 changes: 6 additions & 8 deletions modules/Core/classes/Tasks/MassMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ public function run(): string {

$notification = new Notification(
'mass_message',
new AlertTemplate(
$title,
$content,
),
new MassMessageEmailTemplate(
$title,
$content,
),
$title,
$content,
array_map(static fn ($r) => $r->id, $recipients->results()),
$this->getUserId(),
(bool) $this->getData()['bypass_notification_settings'],
);
$notification->setEmailTemplate(new MassMessageEmailTemplate(
$title,
$content,
));
$notification->send();

$this->setOutput(['userIds' => $whereVars, 'start' => $start, 'end' => $end, 'next_status' => $nextStatus]);
Expand Down
28 changes: 15 additions & 13 deletions modules/Forum/pages/forum/view_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,25 @@

$notification = new Notification(
'forum_topic_reply',
new AlertTemplate(
new LanguageKey('forum', 'new_reply_in_topic', [
'author' => $user->data()->username, 'topic' => $topic->topic_title
], ROOT_PATH . '/modules/Forum/language'),
null,
$post_link,
),
new ForumTopicReplyEmailTemplate(
$user,
$topic->topic_title,
$original_content,
$post_link,
),
$topic->topic_title,
$original_content,
$users_following,
$user->data()->id,

);
$notification->setAlertTemplate(new AlertTemplate(
new LanguageKey('forum', 'new_reply_in_topic', [
'author' => $user->data()->username, 'topic' => $topic->topic_title
], ROOT_PATH . '/modules/Forum/language'),
null,
$post_link,
));
$notification->setEmailTemplate(new ForumTopicReplyEmailTemplate(
$user,
$topic->topic_title,
$original_content,
$post_link,
));
$notification->send();

if (count($users_following)) {
Expand Down