mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11103] Use the language system, topic notifications
PHPBB3-11103
This commit is contained in:
parent
74e2a8f893
commit
3624d2c50a
5 changed files with 200 additions and 8 deletions
|
@ -50,7 +50,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base
|
|||
// We do not send emails to banned users
|
||||
if (!function_exists('phpbb_get_banned_user_ids'))
|
||||
{
|
||||
include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext'));
|
||||
include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext'));
|
||||
}
|
||||
$banned_users = phpbb_get_banned_user_ids($user_ids);
|
||||
|
||||
|
@ -68,13 +68,13 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base
|
|||
// Time to go through the queue and send emails
|
||||
foreach ($this->queue as $notification)
|
||||
{
|
||||
if (in_array($notification->user_id, $banned_users))
|
||||
$user = $this->service->get_user($notification->user_id);
|
||||
|
||||
if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $this->service->get_user($notification->user_id);
|
||||
|
||||
$messenger->template('notification', $user['user_lang']);
|
||||
|
||||
$messenger->to($user['user_email'], $user['username']);
|
||||
|
|
|
@ -101,7 +101,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
|
|||
|
||||
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
|
||||
|
||||
return $username . ' sent you a private message titled: ' . $this->get_data('message_subject');
|
||||
return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base
|
|||
{
|
||||
$user_data = $this->service->get_user($this->get_data('from_user_id'));
|
||||
|
||||
return $user_data['username'] . ' sent you a private message titled: ' . $this->get_data('message_subject');
|
||||
return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,7 +96,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
|||
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
|
||||
}
|
||||
|
||||
return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title'));
|
||||
return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,10 +112,12 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
|||
}
|
||||
else
|
||||
{
|
||||
$user_data = $this->service->get_user($this->get_data('poster_id'));
|
||||
|
||||
$username = $user_data['username'];
|
||||
}
|
||||
|
||||
return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title'));
|
||||
return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,6 +168,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
|||
|
||||
$this->set_data('post_username', $post['post_username']);
|
||||
|
||||
$this->set_data('forum_name', $post['forum_name']);
|
||||
|
||||
return parent::create_insert_array($post);
|
||||
}
|
||||
}
|
||||
|
|
185
phpBB/includes/notifications/type/topic.php
Normal file
185
phpBB/includes/notifications/type/topic.php
Normal file
|
@ -0,0 +1,185 @@
|
|||
<?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 extends phpbb_notifications_type_base
|
||||
{
|
||||
/**
|
||||
* Get the type of notification this is
|
||||
* phpbb_notifications_type_
|
||||
*/
|
||||
public static function get_item_type()
|
||||
{
|
||||
return 'topic';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the
|
||||
*
|
||||
* @param array $post The data from the post
|
||||
*/
|
||||
public static function get_item_id($post)
|
||||
{
|
||||
return $post['topic_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the users who want to receive notifications
|
||||
*
|
||||
* @param ContainerBuilder $phpbb_container
|
||||
* @param array $post Data from
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic)
|
||||
{
|
||||
$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']);
|
||||
|
||||
if (!sizeof($users))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $topic['forum_id']);
|
||||
|
||||
if (empty($auth_read))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$notify_users = array();
|
||||
|
||||
foreach ($auth_read[$topic['forum_id']]['f_read'] as $user_id)
|
||||
{
|
||||
$notify_users[$user_id] = $users[$user_id];
|
||||
}
|
||||
|
||||
return $notify_users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML formatted title of this notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_title()
|
||||
{
|
||||
if ($this->get_data('post_username'))
|
||||
{
|
||||
$username = $this->get_data('post_username');
|
||||
}
|
||||
else
|
||||
{
|
||||
$user_data = $this->service->get_user($this->get_data('poster_id'));
|
||||
|
||||
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
|
||||
}
|
||||
|
||||
return $this->phpbb_container->get('user')->lang(
|
||||
'NOTIFICATION_TOPIC',
|
||||
$username,
|
||||
censor_text($this->get_data('topic_title')),
|
||||
$this->get_data('forum_name')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of this notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
if ($this->get_data('post_username'))
|
||||
{
|
||||
$username = $this->get_data('post_username');
|
||||
}
|
||||
else
|
||||
{
|
||||
$user_data = $this->service->get_user($this->get_data('poster_id'));
|
||||
|
||||
$username = $user_data['username'];
|
||||
}
|
||||
|
||||
return $this->phpbb_container->get('user')->lang(
|
||||
'NOTIFICATION_TOPIC',
|
||||
$username,
|
||||
censor_text($this->get_data('topic_title')),
|
||||
$this->get_data('forum_name')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to this item
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "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}?t{$this->item_id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Users needed to query before this notification can be displayed
|
||||
*
|
||||
* @return array Array of user_ids
|
||||
*/
|
||||
public function users_to_query()
|
||||
{
|
||||
return array($this->data['poster_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->item_id = $post['post_id'];
|
||||
|
||||
$this->set_data('poster_id', $post['poster_id']);
|
||||
|
||||
$this->set_data('topic_title', $post['topic_title']);
|
||||
|
||||
$this->set_data('post_username', $post['post_username']);
|
||||
|
||||
$this->set_data('forum_name', $post['forum_name']);
|
||||
|
||||
return parent::create_insert_array($post);
|
||||
}
|
||||
}
|
|
@ -385,6 +385,9 @@ $lang = array_merge($lang, array(
|
|||
'NOT_AUTHORISED' => 'You are not authorised to access this area.',
|
||||
'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.',
|
||||
'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.',
|
||||
'NOTIFICATION_PM' => '%1$s sent you a Private Message titled: %2$s.',
|
||||
'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".',
|
||||
'NOTIFICATION_TOPIC' => '%1$s posted a new topic "%2$s" in the forum "%3$s".',
|
||||
'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.',
|
||||
|
|
Loading…
Add table
Reference in a new issue