Completed
Pull Request — master (#9)
by Helpful
02:04
created
code/CommentNotifiable.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -6,104 +6,104 @@
 block discarded – undo
6 6
  */
7 7
 class CommentNotifiable extends DataExtension
8 8
 {
9
-    /**
10
-     * Default subject line if the owner doesn't override it
11
-     *
12
-     * @config
13
-     * @var string
14
-     */
15
-    private static $default_notification_subject = 'A new comment has been posted';
9
+	/**
10
+	 * Default subject line if the owner doesn't override it
11
+	 *
12
+	 * @config
13
+	 * @var string
14
+	 */
15
+	private static $default_notification_subject = 'A new comment has been posted';
16 16
 
17
-    /**
18
-     * Default sender
19
-     *
20
-     * @config
21
-     * @var string
22
-     */
23
-    private static $default_notification_sender = 'noreply@{host}';
17
+	/**
18
+	 * Default sender
19
+	 *
20
+	 * @config
21
+	 * @var string
22
+	 */
23
+	private static $default_notification_sender = 'noreply@{host}';
24 24
 
25
-    /**
26
-     * Default template to use for comment notifications
27
-     *
28
-     * @config
29
-     * @var string
30
-     */
31
-    private static $default_notification_template = 'CommentEmail';
25
+	/**
26
+	 * Default template to use for comment notifications
27
+	 *
28
+	 * @config
29
+	 * @var string
30
+	 */
31
+	private static $default_notification_template = 'CommentEmail';
32 32
 
33
-    /**
34
-     * Return the list of members or emails to send comment notifications to
35
-     *
36
-     * @param Comment $comment
37
-     * @return array|Traversable
38
-     */
39
-    public function notificationRecipients($comment)
40
-    {
41
-        // Override this in your extending class to declare recipients
42
-        $list = array();
43
-        if ($adminEmail = Email::config()->admin_email) {
44
-            $list[] = $adminEmail;
45
-        }
46
-        $this->owner->extend('updateNotificationRecipients', $list, $comment);
47
-        return $list;
48
-    }
33
+	/**
34
+	 * Return the list of members or emails to send comment notifications to
35
+	 *
36
+	 * @param Comment $comment
37
+	 * @return array|Traversable
38
+	 */
39
+	public function notificationRecipients($comment)
40
+	{
41
+		// Override this in your extending class to declare recipients
42
+		$list = array();
43
+		if ($adminEmail = Email::config()->admin_email) {
44
+			$list[] = $adminEmail;
45
+		}
46
+		$this->owner->extend('updateNotificationRecipients', $list, $comment);
47
+		return $list;
48
+	}
49 49
 
50
-    /**
51
-     * Gets the email subject line for comment notifications
52
-     *
53
-     * @param Comment $comment Comment
54
-     * @param Member|string $recipient
55
-     * @return string
56
-     */
57
-    public function notificationSubject($comment, $recipient)
58
-    {
59
-        $subject = $this->owner->config()->default_notification_subject;
60
-        $this->owner->extend('updateNotificationSubject', $subject, $comment, $recipient);
61
-        return $subject;
62
-    }
50
+	/**
51
+	 * Gets the email subject line for comment notifications
52
+	 *
53
+	 * @param Comment $comment Comment
54
+	 * @param Member|string $recipient
55
+	 * @return string
56
+	 */
57
+	public function notificationSubject($comment, $recipient)
58
+	{
59
+		$subject = $this->owner->config()->default_notification_subject;
60
+		$this->owner->extend('updateNotificationSubject', $subject, $comment, $recipient);
61
+		return $subject;
62
+	}
63 63
 
64
-    /**
65
-     * Get the sender email address to use for email notifications
66
-     *
67
-     * @param Comment $comment
68
-     * @param Member|string $recipient
69
-     * @return string
70
-     */
71
-    public function notificationSender($comment, $recipient)
72
-    {
73
-        $sender = $this->owner->config()->default_notification_sender;
64
+	/**
65
+	 * Get the sender email address to use for email notifications
66
+	 *
67
+	 * @param Comment $comment
68
+	 * @param Member|string $recipient
69
+	 * @return string
70
+	 */
71
+	public function notificationSender($comment, $recipient)
72
+	{
73
+		$sender = $this->owner->config()->default_notification_sender;
74 74
 
75
-        // Do hostname substitution
76
-        $host = isset($_SERVER['HTTP_HOST'])
77
-            ? preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST'])
78
-            : 'localhost';
79
-        $sender = preg_replace('/{host}/', $host, $sender);
75
+		// Do hostname substitution
76
+		$host = isset($_SERVER['HTTP_HOST'])
77
+			? preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST'])
78
+			: 'localhost';
79
+		$sender = preg_replace('/{host}/', $host, $sender);
80 80
         
81
-        $this->owner->extend('updateNotificationSender', $sender, $comment, $recipient);
82
-        return $sender;
83
-    }
81
+		$this->owner->extend('updateNotificationSender', $sender, $comment, $recipient);
82
+		return $sender;
83
+	}
84 84
 
85
-    /**
86
-     * Determine the template to use for this email
87
-     *
88
-     * @param Comment $comment
89
-     * @param Member|string $recipient
90
-     * @return string Template name (excluding .ss extension)
91
-     */
92
-    public function notificationTemplate($comment, $recipient)
93
-    {
94
-        $template = $this->owner->config()->default_notification_template;
95
-        $this->owner->extend('updateNotificationTemplate', $template, $comment, $recipient);
96
-        return $template;
97
-    }
85
+	/**
86
+	 * Determine the template to use for this email
87
+	 *
88
+	 * @param Comment $comment
89
+	 * @param Member|string $recipient
90
+	 * @return string Template name (excluding .ss extension)
91
+	 */
92
+	public function notificationTemplate($comment, $recipient)
93
+	{
94
+		$template = $this->owner->config()->default_notification_template;
95
+		$this->owner->extend('updateNotificationTemplate', $template, $comment, $recipient);
96
+		return $template;
97
+	}
98 98
 
99
-    /**
100
-     * Update the notification email
101
-     * 
102
-     * @param Email $email
103
-     * @param Comment $comment
104
-     * @param Member|string $recipient
105
-     */
106
-    public function updateCommentNotification($email, $comment, $recipient)
107
-    {
108
-    }
99
+	/**
100
+	 * Update the notification email
101
+	 * 
102
+	 * @param Email $email
103
+	 * @param Comment $comment
104
+	 * @param Member|string $recipient
105
+	 */
106
+	public function updateCommentNotification($email, $comment, $recipient)
107
+	{
108
+	}
109 109
 }
Please login to merge, or discard this patch.
code/CommentNotifier.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -7,97 +7,97 @@
 block discarded – undo
7 7
  */
8 8
 class CommentNotifier extends Extension
9 9
 {
10
-    /**
11
-     * Notify Members of the post there is a new comment.
12
-     *
13
-     * @param Comment $comment
14
-     */
15
-    public function onAfterPostComment(Comment $comment)
16
-    {
17
-        $parent = $comment->getParent();
18
-        if (!$parent) {
19
-            return;
20
-        }
10
+	/**
11
+	 * Notify Members of the post there is a new comment.
12
+	 *
13
+	 * @param Comment $comment
14
+	 */
15
+	public function onAfterPostComment(Comment $comment)
16
+	{
17
+		$parent = $comment->getParent();
18
+		if (!$parent) {
19
+			return;
20
+		}
21 21
         
22
-        // Ask parent to submit all recipients
23
-        $recipients = $parent->notificationRecipients($comment);
24
-        foreach ($recipients as $recipient) {
25
-            $this->notifyCommentRecipient($comment, $parent, $recipient);
26
-        }
27
-    }
22
+		// Ask parent to submit all recipients
23
+		$recipients = $parent->notificationRecipients($comment);
24
+		foreach ($recipients as $recipient) {
25
+			$this->notifyCommentRecipient($comment, $parent, $recipient);
26
+		}
27
+	}
28 28
 
29
-    /**
30
-     * Validates for RFC 2822 compliant email adresses.
31
-     *
32
-     * @see http://www.regular-expressions.info/email.html
33
-     * @see http://www.ietf.org/rfc/rfc2822.txt
34
-     *
35
-     * @param string $email
36
-     * @return boolean
37
-     */
38
-    public function isValidEmail($email)
39
-    {
40
-        if (!$email) {
41
-            return false;
42
-        }
29
+	/**
30
+	 * Validates for RFC 2822 compliant email adresses.
31
+	 *
32
+	 * @see http://www.regular-expressions.info/email.html
33
+	 * @see http://www.ietf.org/rfc/rfc2822.txt
34
+	 *
35
+	 * @param string $email
36
+	 * @return boolean
37
+	 */
38
+	public function isValidEmail($email)
39
+	{
40
+		if (!$email) {
41
+			return false;
42
+		}
43 43
 
44
-        $pcrePattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*'
45
-            . '@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$';
44
+		$pcrePattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*'
45
+			. '@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$';
46 46
 
47
-        // PHP uses forward slash (/) to delimit start/end of pattern, so it must be escaped
48
-        $pregSafePattern = str_replace('/', '\\/', $pcrePattern);
47
+		// PHP uses forward slash (/) to delimit start/end of pattern, so it must be escaped
48
+		$pregSafePattern = str_replace('/', '\\/', $pcrePattern);
49 49
 
50
-        return preg_match('/' . $pregSafePattern . '/i', $email);
51
-    }
50
+		return preg_match('/' . $pregSafePattern . '/i', $email);
51
+	}
52 52
 
53
-    /**
54
-     * Send comment notification to a given recipient
55
-     *
56
-     * @param Comment $comment
57
-     * @param DataObject $parent Object with the {@see CommentNotifiable} extension applied
58
-     * @param Member|string $recipient Either a member object or an email address to which notifications should be sent
59
-     */
60
-    public function notifyCommentRecipient($comment, $parent, $recipient)
61
-    {
62
-        $subject = $parent->notificationSubject($comment, $recipient);
63
-        $sender = $parent->notificationSender($comment, $recipient);
64
-        $template = $parent->notificationTemplate($comment, $recipient);
53
+	/**
54
+	 * Send comment notification to a given recipient
55
+	 *
56
+	 * @param Comment $comment
57
+	 * @param DataObject $parent Object with the {@see CommentNotifiable} extension applied
58
+	 * @param Member|string $recipient Either a member object or an email address to which notifications should be sent
59
+	 */
60
+	public function notifyCommentRecipient($comment, $parent, $recipient)
61
+	{
62
+		$subject = $parent->notificationSubject($comment, $recipient);
63
+		$sender = $parent->notificationSender($comment, $recipient);
64
+		$template = $parent->notificationTemplate($comment, $recipient);
65 65
 
66
-        // Validate email
67
-        // Important in case of the owner being a default-admin or a username with no contact email
68
-        $to = $recipient instanceof Member
69
-            ? $recipient->Email
70
-            : $recipient;
71
-        if (!$this->isValidEmail($to)) {
72
-            return;
73
-        }
66
+		// Validate email
67
+		// Important in case of the owner being a default-admin or a username with no contact email
68
+		$to = $recipient instanceof Member
69
+			? $recipient->Email
70
+			: $recipient;
71
+		if (!$this->isValidEmail($to)) {
72
+			return;
73
+		}
74 74
 
75
-        // Prepare the email
76
-        $email = new Email();
77
-        $email->setSubject($subject);
78
-        $email->setFrom($sender);
79
-        $email->setTo($to);
80
-        $email->setTemplate($template);
81
-        $email->populateTemplate(array(
82
-            'Parent' => $parent,
83
-            'Comment' => $comment,
84
-            'Recipient' => $recipient
85
-        ));
86
-        if ($recipient instanceof Member) {
87
-            $email->populateTemplate(array(
88
-                'ApproveLink' => $comment->ApproveLink($recipient),
89
-                'HamLink' => $comment->HamLink($recipient),
90
-                'SpamLink' => $comment->SpamLink($recipient),
91
-                'DeleteLink' => $comment->DeleteLink($recipient),
92
-            ));
93
-        }
75
+		// Prepare the email
76
+		$email = new Email();
77
+		$email->setSubject($subject);
78
+		$email->setFrom($sender);
79
+		$email->setTo($to);
80
+		$email->setTemplate($template);
81
+		$email->populateTemplate(array(
82
+			'Parent' => $parent,
83
+			'Comment' => $comment,
84
+			'Recipient' => $recipient
85
+		));
86
+		if ($recipient instanceof Member) {
87
+			$email->populateTemplate(array(
88
+				'ApproveLink' => $comment->ApproveLink($recipient),
89
+				'HamLink' => $comment->HamLink($recipient),
90
+				'SpamLink' => $comment->SpamLink($recipient),
91
+				'DeleteLink' => $comment->DeleteLink($recipient),
92
+			));
93
+		}
94 94
 
95
-        // Until invokeWithExtensions supports multiple arguments
96
-        if (method_exists($this->owner, 'updateCommentNotification')) {
97
-            $this->owner->updateCommentNotification($email, $comment, $recipient);
98
-        }
99
-        $this->owner->extend('updateCommentNotification', $email, $comment, $recipient);
95
+		// Until invokeWithExtensions supports multiple arguments
96
+		if (method_exists($this->owner, 'updateCommentNotification')) {
97
+			$this->owner->updateCommentNotification($email, $comment, $recipient);
98
+		}
99
+		$this->owner->extend('updateCommentNotification', $email, $comment, $recipient);
100 100
         
101
-        return $email->send();
102
-    }
101
+		return $email->send();
102
+	}
103 103
 }
Please login to merge, or discard this patch.