1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-05 22:14:59 +02:00

[ticket/11103] Topic/Post in queue notification

Also, bug fixes and cleanup

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-09-15 14:33:15 -05:00
parent 05b573ebf7
commit 7454d5c2d5
16 changed files with 325 additions and 56 deletions

View File

@ -2220,10 +2220,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
}
// Send Notifications
$phpbb_notifications = $phpbb_container->get('notifications');
if ($post_approval)
{
$phpbb_notifications = $phpbb_container->get('notifications');
switch ($mode)
{
case 'post' :
@ -2258,6 +2257,34 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
break;
}
}
else
{
switch ($mode)
{
case 'post' :
$phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array(
'post_username' => $username,
'poster_id' => (int) $user->data['user_id'],
)));
break;
case 'reply' :
case 'quote' :
$phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array(
'post_username' => $username,
'poster_id' => (int) $user->data['user_id'],
)));
break;
case 'edit_topic' :
case 'edit_first_post' :
case 'edit' :
case 'edit_last_post' :
$phpbb_notifications->delete_notifications('topic', $data['topic_id']);
$phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']);
break;
}
}
$params = $add_anchor = '';

View File

@ -606,6 +606,9 @@ function approve_post($post_id_list, $id, $mode)
{
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{
// Delete topic in queue notifications
$phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']);
// Forum Notifications
$phpbb_notifications->add_notifications('topic', $post_data);
@ -617,6 +620,9 @@ function approve_post($post_id_list, $id, $mode)
}
else
{
// Delete post in queue notification
$phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id);
// Topic Notifications
$phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data);
@ -847,13 +853,26 @@ function disapprove_post($post_id_list, $id, $mode)
}
}
// Handle notifications (topic/post in queue)
$phpbb_notifications = $phpbb_container->get('notifications');
foreach ($post_info as $post_id => $post_data)
{
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{
$phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']);
}
else
{
$phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id);
}
}
// Notify Poster?
if ($notify_poster)
{
$lang_reasons = array();
// Handle notifications
$phpbb_notifications = $phpbb_container->get('notifications');
foreach ($post_info as $post_id => $post_data)
{
$post_data['disapprove_reason'] = '';

View File

@ -262,7 +262,7 @@ class phpbb_notifications_service
{
foreach ($item_type as $type)
{
$this->add_notifications($type, $data);
$this->add_notifications_for_users($type, $data, $notify_users);
}
return;
@ -353,7 +353,7 @@ class phpbb_notifications_service
{
foreach ($item_type as $type)
{
$this->add_notifications($type, $data);
$this->update_notifications($type, $data);
}
return;
@ -386,12 +386,22 @@ class phpbb_notifications_service
/**
* Delete a notification
*
* @param string $item_type Type identifier
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)
* @param int|array $item_id Identifier within the type (or array of ids)
* @param array $data Data specific for this type that will be updated
*/
public function delete_notifications($item_type, $item_id)
{
if (is_array($item_type))
{
foreach ($item_type as $type)
{
$this->delete_notifications($type, $item_id);
}
return;
}
$this->get_item_type_class_name($item_type);
$sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
@ -400,6 +410,7 @@ class phpbb_notifications_service
$this->db->sql_query($sql);
}
/*
public function add_subscription($item_type, $item_id, $method = '')
{
$this->get_item_type_class_name($item_type);
@ -413,6 +424,7 @@ class phpbb_notifications_service
));
$this->db->sql_query($sql);
}
*/
/**
* Load user helper

View File

@ -82,21 +82,6 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos
return $notify_users;
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
return array(
'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}",
);
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
@ -109,8 +94,10 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos
{
$this->set_data('post_subject', $post['post_subject']);
$this->time = time();
$data = parent::create_insert_array($post);
return parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -82,20 +82,6 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to
return $notify_users;
}
/**
* 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_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}",
);
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
@ -106,8 +92,10 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to
*/
public function create_insert_array($post)
{
$this->time = time();
$data = parent::create_insert_array($post);
return parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -79,10 +79,9 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_
*/
public function get_email_template_variables()
{
return array(
'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')),
);
return array_merge(parent::get_email_template_variables(), array(
'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')),
));
}
/**
@ -95,11 +94,12 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_
*/
public function create_insert_array($post)
{
$this->set_data('post_subject', $post['post_subject']);
$this->set_data('disapprove_reason', $post['disapprove_reason']);
$this->time = time();
$data = parent::create_insert_array($post);
return parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -79,11 +79,9 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type
*/
public function get_email_template_variables()
{
return array(
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
return array_merge(parent::get_email_template_variables(), array(
'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')),
);
));
}
/**
@ -97,8 +95,11 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type
public function create_insert_array($post)
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
$this->time = time();
return parent::create_insert_array($post);
$data = parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -167,10 +167,13 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
public function get_email_template_variables()
{
return array(
'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))),
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}",
'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_VIEW_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",
);
@ -210,6 +213,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
$this->set_data('topic_title', $post['topic_title']);
$this->set_data('post_subject', $post['post_subject']);
$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']);

View File

@ -0,0 +1,97 @@
<?php
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Topic notifications class
* This class handles notifications for new topics
*
* @package notifications
*/
class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_post
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'notifications/post_in_queue';
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_POST_IN_QUEUE';
/**
* Get the type of notification this is
* phpbb_notifications_type_
*/
public static function get_item_type()
{
return 'post_in_queue';
}
/**
* Find the users who want to receive notifications
*
* @param ContainerBuilder $phpbb_container
* @param array $post Data from the post
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post)
{
/* todo
* find what type of notification they'd like to receive
*/
$auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']);
if (empty($auth_approve))
{
return array();
}
$notify_users = array();
foreach ($auth_approve[$post['forum_id']]['m_approve'] as $user_id)
{
$notify_users[$user_id] = array('');
}
return $notify_users;
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
*
* @param array $post Data from submit_post
*
* @return array Array of data ready to be inserted into the database
*/
public function create_insert_array($post)
{
$data = parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -183,8 +183,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post
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

@ -72,7 +72,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
* Find the users who want to receive notifications
*
* @param ContainerBuilder $phpbb_container
* @param array $post Data from
* @param array $topic Data from the topic
*
* @return array
*/
@ -171,6 +171,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base
'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')),
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))),
'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}",
'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}",
'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",
);

View File

@ -0,0 +1,97 @@
<?php
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Topic notifications class
* This class handles notifications for new topics
*
* @package notifications
*/
class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_topic
{
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = 'notifications/topic_in_queue';
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE';
/**
* Get the type of notification this is
* phpbb_notifications_type_
*/
public static function get_item_type()
{
return 'topic_in_queue';
}
/**
* Find the users who want to receive notifications
*
* @param ContainerBuilder $phpbb_container
* @param array $topic Data from the topic
*
* @return array
*/
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic)
{
/* todo
* find what type of notification they'd like to receive
*/
$auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']);
if (empty($auth_approve))
{
return array();
}
$notify_users = array();
foreach ($auth_approve[$topic['forum_id']]['m_approve'] as $user_id)
{
$notify_users[$user_id] = array('');
}
return $notify_users;
}
/**
* Function for preparing the data for insertion in an SQL query
* (The service handles insertion)
*
* @param array $topic Data from submit_post
*
* @return array Array of data ready to be inserted into the database
*/
public function create_insert_array($topic)
{
$data = parent::create_insert_array($post);
$this->time = $data['time'] = time();
return $data;
}
}

View File

@ -391,10 +391,12 @@ $lang = array_merge($lang, array(
'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".',
'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".',
'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved because "%2$s".',
'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by "%1$s" and needs approval.',
'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".',
'NOTIFICATION_TOPIC' => '%1$s posted a new topic "%2$s" in the forum "%3$s".',
'NOTIFICATION_TOPIC_APPROVED' => 'Your topic "%2$s" in the forum "%3$s" was approved.',
'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved because "%2$s".',
'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by "%1$s" and needs approval.',
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>',
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',

View File

@ -0,0 +1,17 @@
Subject: Topic reply notification - "{TOPIC_TITLE}"
Hello {USERNAME},
You are receiving this notification because the post, "{POST_SUBJECT}" at "{SITENAME}" needs approval.
If you want to view the post, click the following link:
{U_VIEW_POST}
If you want to view the topic, click the following link:
{U_TOPIC}
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

@ -5,7 +5,7 @@ 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}
{U_VIEW_POST}
If you want to view the topic, click the following link:
{U_TOPIC}

View File

@ -0,0 +1,17 @@
Subject: Topic reply notification - "{TOPIC_TITLE}"
Hello {USERNAME},
You are receiving this notification because the topic , "{TOPIC_TITLE}" at "{SITENAME}" needs approval.
If you want to view the topic, click the following link:
{U_VIEW_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}