[ticket/11103] Use appropriate email templates to send notifications

Fixing a number of bugs

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-09-14 18:05:13 -05:00
parent 8e977544fb
commit 959c81d00e
13 changed files with 156 additions and 59 deletions

View file

@ -2229,6 +2229,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
case 'post' :
$phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array(
'post_username' => $username,
'poster_id' => (int) $user->data['user_id'],
)));
break;
@ -2236,6 +2237,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
case 'quote' :
$phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array(
'post_username' => $username,
'poster_id' => (int) $user->data['user_id'],
)));
break;

View file

@ -82,19 +82,15 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base
continue;
}
$messenger->template('notification', $user['user_lang']);
$messenger->template($notification->email_template, $user['user_lang']);
$messenger->to($user['user_email'], $user['username']);
$messenger->assign_vars(array(
'USERNAME' => $user['username'],
$messenger->assign_vars(array_merge(array(
'USERNAME' => $user['username'],
'MESSAGE' => htmlspecialchars_decode($notification->get_title()),
'U_VIEW_MESSAGE' => $notification->get_full_url(),
'U_UNSUBSCRIBE' => $notification->get_unsubscribe_url(),
));
'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=notifications', // todo Update URL
), $notification->get_email_template_variables()));
$messenger->send($this->notify_method);
}

View file

@ -153,7 +153,7 @@ class phpbb_notifications_service
{
foreach ($item_type as $type)
{
$this->mark_notifications_read($type, $item_id, $user_id, $time);
$this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time);
}
return;

View file

@ -157,7 +157,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
public function create_insert_array($type_data)
{
// Defaults
$data = array_merge(array(
$this->data = array_merge(array(
'item_id' => static::get_item_id($type_data),
'item_type' => $this->get_item_type(),
'item_parent_id' => static::get_item_parent_id($type_data),
@ -168,6 +168,8 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
'data' => array(),
), $this->data);
$data = $this->data;
$data['data'] = serialize($data['data']);
return $data;

View file

@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'notifications/bookmark';
/**
* Language key used to output the text
*

View file

@ -31,9 +31,9 @@ interface phpbb_notifications_type_interface
public function get_formatted_title();
public function get_url();
public function get_email_template_variables();
public function get_full_url();
public function get_url();
public function get_unsubscribe_url($method);

View file

@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notifications_type_pm extends phpbb_notifications_type_base
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'privmsg_notify';
/**
* Get the type of notification this is
* phpbb_notifications_type_
@ -135,6 +142,23 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject'));
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$user_data = $this->service->get_user($this->get_data('from_user_id'));
return array(
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))),
'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}",
);
}
/**
* Get the url to this item
*
@ -145,16 +169,6 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}");
}
/**
* Get the full url to this item
*
* @return string URL
*/
public function get_full_url()
{
return generate_board_url() . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$this->item_id}";
}
/**
* Users needed to query before this notification can be displayed
*

View file

@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notifications_type_post extends phpbb_notifications_type_base
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'topic_notify';
/**
* Language key used to output the text
*
@ -174,6 +181,23 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
);
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
return array(
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread",
'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}",
'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic",
);
}
/**
* Get the url to this item
*
@ -184,16 +208,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}");
}
/**
* Get the full url to this item
*
* @return string URL
*/
public function get_full_url()
{
return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}";
}
/**
* Users needed to query before this notification can be displayed
*
@ -220,6 +234,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
$this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : ''));
$this->set_data('forum_id', $post['forum_id']);
$this->set_data('forum_name', $post['forum_name']);
return parent::create_insert_array($post);

View file

@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notifications_type_quote extends phpbb_notifications_type_post
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'notifications/quote';
/**
* regular expression to match to find usernames
*
@ -161,4 +168,20 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post
// return true to continue with the update code in the notifications service (this will update the rest of the notifications)
return true;
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$user_data = $this->service->get_user($this->get_data('poster_id'));
return array_merge(parent::get_email_template_variables(), array(
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
'U_QUOTED_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
));
}
}

View file

@ -25,6 +25,13 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notifications_type_topic extends phpbb_notifications_type_base
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'newtopic_notify';
/**
* Get the type of notification this is
* phpbb_notifications_type_
@ -169,6 +176,22 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
);
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
return array(
'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')),
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}",
'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum",
);
}
/**
* Get the url to this item
*
@ -179,16 +202,6 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}");
}
/**
* Get the full url to this item
*
* @return string URL
*/
public function get_full_url()
{
return generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}";
}
/**
* Users needed to query before this notification can be displayed
*

View file

@ -1,16 +0,0 @@
Subject: Notification from {SITENAME}
Hello {USERNAME},
{MESSAGE}
You can view this by clicking on the following link:
{U_VIEW_MESSAGE}
<!-- IF U_UNSUBSCRIBE -->
You may unsubscribe by clicking on the following link:
{U_UNSUBSCRIBE}
<!-- ENDIF -->
{EMAIL_SIG}

View file

@ -0,0 +1,20 @@
Subject: Topic reply notification - "{TOPIC_TITLE}"
Hello {USERNAME},
You are receiving this notification because the topic you bookmarked, "{TOPIC_TITLE}" at "{SITENAME}" has received a reply since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic.
If you want to view the newest post made since your last visit, click the following link:
{U_NEWEST_POST}
If you want to view the topic, click the following link:
{U_TOPIC}
If you want to view the forum, click the following link:
{U_FORUM}
If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here:
{U_NOTIFICATION_SETTINGS}
{EMAIL_SIG}

View file

@ -0,0 +1,20 @@
Subject: Topic reply notification - "{TOPIC_TITLE}"
Hello {USERNAME},
You are receiving this notification because "{AUTHOR_NAME}" quoted you in the topic, "{TOPIC_TITLE}" at "{SITENAME}". You can use the following link to view the reply made.
If you want to view the quoted post, click the following link:
{U_QUOTED_POST}
If you want to view the topic, click the following link:
{U_TOPIC}
If you want to view the forum, click the following link:
{U_FORUM}
If you no longer wish to receive updates about replies quoting you, please update your notification settings here:
{U_NOTIFICATION_SETTINGS}
{EMAIL_SIG}