1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
<?php
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class ucp_notifications
{
public $u_action;
public function main($id, $mode)
{
global $phpbb_container;
add_form_key('ucp_notification_options');
$phpbb_notifications = $phpbb_container->get('notifications');
$template = $phpbb_container->get('template');
$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'))
{
if (!check_form_key('ucp_notification_options'))
{
trigger_error('FORM_INVALID');
}
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($phpbb_notifications->get_subscription_types() as $type => $data)
{
if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type]))
{
// add
$phpbb_notifications->add_subscription($type);
}
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) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type])))
{
// add
$phpbb_notifications->add_subscription($type, 0, $method);
}
else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type]))
{
// remove
$phpbb_notifications->delete_subscription($type, 0, $method);
}
}
}
}
// todo include language files for extensions?
$this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user);
$this->output_notification_types('notification_types', $phpbb_notifications, $template, $user);
$this->tpl_name = 'ucp_notifications';
$this->page_title = 'UCP_NOTIFICATIONS';
}
/**
* Output all the notification types to the template
*
* @param string $block
* @param phpbb_notification_manager $phpbb_notifications
* @param phpbb_template $template
* @param phpbb_user $user
*/
public function output_notification_types($block = 'notification_types', phpbb_notification_manager $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' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)),
'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false,
));
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,
));
}
}
}
/**
* Output all the notification methods to the template
*
* @param string $block
* @param phpbb_notification_manager $phpbb_notifications
* @param phpbb_template $template
* @param phpbb_user $user
*/
public function output_notification_methods($block = 'notification_methods', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user)
{
$notification_methods = $phpbb_notifications->get_subscription_methods();
foreach($notification_methods as $method)
{
$template->assign_block_vars($block, array(
'METHOD' => $method,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)),
));
}
}
}
|