b95eda3937ed9f0c1474b9f7dabc20b547028233
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\type;
3 use wcf\data\user\notification\recipient\UserNotificationRecipient;
4 use wcf\data\user\notification\UserNotification;
5 use wcf\data\user\UserEditor;
6 use wcf\system\mail\Mail;
7 use wcf\system\user\notification\event\IUserNotificationEvent;
8 use wcf\util\FileUtil;
9 use wcf\util\StringUtil;
10
11 /**
12 * A notification type for sending mail notifications.
13 *
14 * @author Marcel Werk, Oliver Kliebisch
15 * @copyright 2001-2011 WoltLab GmbH, Oliver Kliebisch
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf.notification
18 * @subpackage system.user.notification.type
19 * @category Community Framework
20 */
21 class MailUserNotificationType extends AbstractUserNotificationType {
22 /**
23 * @see wcf\system\user\notification\type\IUserNotificationType::send()
24 */
25 public function send(UserNotification $notification, UserNotificationRecipient $user, IUserNotificationEvent $event) {
26 // get message
27 $message = $event->getMessage($this, array(
28 'user' => $user,
29 'pageURL' => FileUtil::addTrailingSlash(PAGE_URL)
30 ));
31
32 // append notification mail footer
33 $token = $user->notificationMailToken;
34 if (!$token) {
35 // generate token if not present
36 $token = StringUtil::substring($token = StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
37 $editor = new UserEditor($user->getDecoratedObject());
38 $editor->updateUserOptions(array('notificationMailToken' => $token));
39 }
40 $message .= "\n".$user->getLanguage()->getDynamicVariable('wcf.user.notification.type.mail.footer', array(
41 'user' => $user,
42 'pageURL' => FileUtil::addTrailingSlash(PAGE_URL),
43 'token' => $token,
44 'notification' => $notification
45 ));
46
47 // use short output as mail subject and strip its HTML
48 $shortMessage = StringUtil::stripHTML($notification->shortOutput);
49
50 // build mail
51 $mail = new Mail(array($user->username => $user->email), $user->getLanguage()->getDynamicVariable('wcf.user.notification.type.mail.subject', array('title' => $shortMessage)), $message);
52 $mail->send();
53 }
54
55 /**
56 * @see wcf\system\user\notification\type\IUserNotificationType::revoke()
57 */
58 public function revoke(UserNotification $notification, UserNotificationRecipient $user, IUserNotificationEvent $event) {
59 // unsupported
60 return;
61 }
62 }