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