aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions.php1
-rw-r--r--phpBB/includes/notifications/service.php44
-rw-r--r--phpBB/includes/ucp/ucp_notifications.php43
3 files changed, 73 insertions, 15 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 92cea20d10..92d72b6636 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5021,6 +5021,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text,
'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread,
'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'],
+ 'NOTIFICATIONS_CNT' => $user->lang('NOTIFICATIONS_CNT', $notifications['unread_count']),
'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'],
'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'],
diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php
index 174b73f9a5..2c1eb859c7 100644
--- a/phpBB/includes/notifications/service.php
+++ b/phpBB/includes/notifications/service.php
@@ -503,6 +503,46 @@ class phpbb_notifications_service
}
/**
+ * Get subscriptions
+ *
+ * @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
+ * @param bool $only_global True to select only global subscription options (item_id = 0)
+ *
+ * @return array Subscriptions
+ */
+ public function get_subscriptions($user_id = false, $only_global = false)
+ {
+ $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id;
+
+ $subscriptions = array();
+
+ $sql = 'SELECT *
+ FROM ' . USER_NOTIFICATIONS_TABLE . '
+ WHERE user_id = ' . (int) $user_id .
+ (($only_global) ? ' AND item_id = 0' : '');
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if ($only_global)
+ {
+ if (!isset($subscriptions[$row['item_type']]))
+ {
+ $subscriptions[$row['item_type']] = array();
+ }
+
+ $subscriptions[$row['item_type']][] = $row['method'];
+ }
+ else
+ {
+ $subscriptions[] = $row;
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return $subscriptions;
+ }
+
+ /**
* Add a subscription
*
* @param string $item_type Type identifier of the subscription
@@ -510,7 +550,7 @@ class phpbb_notifications_service
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
- public function add_subscription($item_type, $item_id, $method = '', $user_id = false)
+ public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
$this->get_item_type_class_name($item_type);
@@ -534,7 +574,7 @@ class phpbb_notifications_service
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
- public function delete_subscription($item_type, $item_id, $method = '', $user_id = false)
+ public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
$this->get_item_type_class_name($item_type);
diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php
index 86052ada14..ad399ca290 100644
--- a/phpBB/includes/ucp/ucp_notifications.php
+++ b/phpBB/includes/ucp/ucp_notifications.php
@@ -28,29 +28,37 @@ class ucp_notifications
$user = $phpbb_container->get('user');
$request = $phpbb_container->get('request');
+ $subscriptions = $phpbb_notifications->get_subscriptions(false, true);
+
+ // Add/remove subscriptions
if ($request->is_set_post('submit'))
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
- foreach($phpbb_notifications->get_subscription_types() as $type)
+
+ foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
- if ($request->is_set_post($type . '_notification'))
+ if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type]))
{
// add
+ $phpbb_notifications->add_subscription($type);
}
- else
+ else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type]))
{
// remove
+ $phpbb_notifications->delete_subscription($type);
}
foreach($notification_methods as $method)
{
- if ($request->is_set_post($type . '_' . $method))
+ if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type])))
{
// add
+ $phpbb_notifications->add_subscription($type, 0, $method);
}
- else
+ else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type]))
{
// remove
+ $phpbb_notifications->delete_subscription($type, 0, $method);
}
}
}
@@ -76,15 +84,29 @@ class ucp_notifications
*/
public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
+ $notification_methods = $phpbb_notifications->get_subscription_methods();
+ $subscriptions = $phpbb_notifications->get_subscriptions(false, true);
+
foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
$template->assign_block_vars($block, array(
'TYPE' => $type,
- 'NAME' => (isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
+ 'NAME' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
+
+ 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false,
));
- $this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user);
+ foreach($notification_methods as $method)
+ {
+ $template->assign_block_vars($block . '.notification_methods', array(
+ 'METHOD' => $method,
+
+ 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)),
+
+ 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false,
+ ));
+ }
}
}
@@ -98,12 +120,7 @@ class ucp_notifications
*/
public function output_notification_methods($block = 'notification_methods', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
- static $notification_methods = false;
-
- if ($notification_methods === false)
- {
- $notification_methods = $phpbb_notifications->get_subscription_methods();
- }
+ $notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($notification_methods as $method)
{