-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCommentNotifiable.php
122 lines (101 loc) · 3.16 KB
/
CommentNotifiable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace SilverStripe\CommentNotifications\Extensions;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Control\Email\Email;
use SilverStripe\Security\Member;
use Traversable;
class CommentNotifiable extends DataExtension
{
/**
* Default subject line if the owner doesn't override it
*
* @config
* @var string
*/
private static $default_notification_subject = 'A new comment has been posted';
/**
* Default sender
*
* @config
* @var string
*/
private static $default_notification_sender = 'noreply@{host}';
/**
* Default template to use for comment notifications
*
* @config
* @var string
*/
private static $default_notification_template = 'SilverStripe\\CommentNotifications\\CommentEmail';
/**
* Return the list of members or emails to send comment notifications to
*
* @param Comment $comment
* @return array|Traversable
*/
public function notificationRecipients($comment)
{
$list = [];
if ($adminEmail = Email::config()->admin_email) {
$list[] = $adminEmail;
}
$this->owner->invokeWithExtensions('updateNotificationRecipients', $list, $comment);
return $list;
}
/**
* Gets the email subject line for comment notifications
*
* @param Comment $comment Comment
* @param Member|string $recipient
* @return string
*/
public function notificationSubject($comment, $recipient)
{
$subject = $this->owner->config()->default_notification_subject;
$this->owner->invokeWithExtensions('updateNotificationSubject', $subject, $comment, $recipient);
return $subject;
}
/**
* Get the sender email address to use for email notifications
*
* @param Comment $comment
* @param Member|string $recipient
* @return string
*/
public function notificationSender($comment, $recipient)
{
$sender = $this->owner->config()->default_notification_sender;
// Do hostname substitution
$host = isset($_SERVER['HTTP_HOST'])
? preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST'])
: 'localhost';
$sender = preg_replace('/{host}/', $host ?? '', $sender ?? '');
$this->owner->invokeWithExtensions('updateNotificationSender', $sender, $comment, $recipient);
return $sender;
}
/**
* Determine the template to use for this email
*
* @param Comment $comment
* @param Member|string $recipient
* @return string Template name (excluding .ss extension)
*/
public function notificationTemplate($comment, $recipient)
{
$template = $this->owner->config()->default_notification_template;
$this->owner->invokeWithExtensions('updateNotificationTemplate', $template, $comment, $recipient);
return $template;
}
/**
* Update the notification email
*
* @param Email $email
* @param Comment $comment
* @param Member|string $recipient
*/
public function updateCommentNotification($email, $comment, $recipient)
{
//
}
}