|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Auto Groups extension for the phpBB Forum Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace phpbb\autogroups\event; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Event listener |
|
17
|
|
|
*/ |
|
18
|
|
|
class listener implements EventSubscriberInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var \phpbb\autogroups\conditions\manager */ |
|
21
|
|
|
protected $manager; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor |
|
25
|
|
|
* |
|
26
|
|
|
* @param \phpbb\autogroups\conditions\manager $manager Auto groups condition manager object |
|
27
|
|
|
* @access public |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(\phpbb\autogroups\conditions\manager $manager) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->manager = $manager; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Assign functions defined in this class to event listeners in the core |
|
36
|
|
|
* |
|
37
|
|
|
* @return array |
|
38
|
|
|
* @static |
|
39
|
|
|
* @access public |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function getSubscribedEvents() |
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
'core.delete_group_after' => 'delete_group_rules', |
|
45
|
|
|
'core.user_setup' => 'load_language_on_setup', |
|
46
|
|
|
|
|
47
|
|
|
// Auto Groups "Posts" listeners |
|
48
|
|
|
'core.submit_post_end' => 'submit_post_check', |
|
49
|
|
|
'core.delete_posts_after' => 'delete_post_check', |
|
50
|
|
|
'core.approve_posts_after' => 'approve_post_check', |
|
51
|
|
|
|
|
52
|
|
|
// Auto Groups "Warnings" listeners |
|
53
|
|
|
'core.mcp_warn_post_after' => 'add_warning_check', |
|
54
|
|
|
'core.mcp_warn_user_after' => 'add_warning_check', |
|
55
|
|
|
|
|
56
|
|
|
// Auto Groups "User Session" listeners |
|
57
|
|
|
'core.session_create_after' => [['last_visit_check'], ['membership_check']], |
|
58
|
|
|
|
|
59
|
|
|
// Auto Groups "Membership" listeners |
|
60
|
|
|
'core.user_add_after' => 'membership_check', |
|
61
|
|
|
'core.user_active_flip_after' => 'membership_check', |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Delete autogroups rules when their related group is deleted |
|
67
|
|
|
* |
|
68
|
|
|
* @param \phpbb\event\data $event The event object |
|
|
|
|
|
|
69
|
|
|
* @return void |
|
70
|
|
|
* @access public |
|
71
|
|
|
*/ |
|
72
|
|
|
public function delete_group_rules($event) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->manager->purge_autogroups_group($event['group_id']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Load common language files during user setup |
|
79
|
|
|
* |
|
80
|
|
|
* @param \phpbb\event\data $event The event object |
|
81
|
|
|
* @return void |
|
82
|
|
|
* @access public |
|
83
|
|
|
*/ |
|
84
|
|
|
public function load_language_on_setup($event) |
|
85
|
|
|
{ |
|
86
|
|
|
$lang_set_ext = $event['lang_set_ext']; |
|
87
|
|
|
$lang_set_ext[] = array( |
|
88
|
|
|
'ext_name' => 'phpbb/autogroups', |
|
89
|
|
|
'lang_set' => 'autogroups_common', |
|
90
|
|
|
); |
|
91
|
|
|
$event['lang_set_ext'] = $lang_set_ext; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Check user's post count after submitting a post for auto groups |
|
96
|
|
|
* |
|
97
|
|
|
* @param \phpbb\event\data $event The event object |
|
98
|
|
|
* @return void |
|
99
|
|
|
* @access public |
|
100
|
|
|
*/ |
|
101
|
|
|
public function submit_post_check($event) |
|
102
|
|
|
{ |
|
103
|
|
|
if (!isset($event['data']['poster_id'])) |
|
104
|
|
|
{ |
|
105
|
|
|
return; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
|
109
|
|
|
'users' => $event['data']['poster_id'], |
|
110
|
|
|
)); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Check user's post count after deleting a post for auto groups |
|
115
|
|
|
* |
|
116
|
|
|
* @param \phpbb\event\data $event The event object |
|
117
|
|
|
* @return void |
|
118
|
|
|
* @access public |
|
119
|
|
|
*/ |
|
120
|
|
|
public function delete_post_check($event) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
|
123
|
|
|
'action' => 'delete', |
|
124
|
|
|
'users' => $event['poster_ids'], |
|
125
|
|
|
)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Check user's post count after approving a post for auto groups |
|
130
|
|
|
* |
|
131
|
|
|
* @param \phpbb\event\data $event The event object |
|
132
|
|
|
* @return void |
|
133
|
|
|
* @access public |
|
134
|
|
|
*/ |
|
135
|
|
|
public function approve_post_check($event) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
|
138
|
|
|
'users' => array_column($event['post_info'], 'poster_id'), |
|
139
|
|
|
)); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Check user's warnings count after receiving a warning for auto groups |
|
144
|
|
|
* |
|
145
|
|
|
* @param \phpbb\event\data $event The event object |
|
146
|
|
|
* @return void |
|
147
|
|
|
* @access public |
|
148
|
|
|
*/ |
|
149
|
|
|
public function add_warning_check($event) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.warnings', array( |
|
152
|
|
|
'users' => $event['user_row']['user_id'], |
|
153
|
|
|
)); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Check user's last visit status when they log in |
|
158
|
|
|
* |
|
159
|
|
|
* @param \phpbb\event\data $event The event object |
|
160
|
|
|
* @return void |
|
161
|
|
|
* @access public |
|
162
|
|
|
*/ |
|
163
|
|
|
public function last_visit_check($event) |
|
164
|
|
|
{ |
|
165
|
|
|
// only check session at login (this will prevent repeated excessive attempts at this check) |
|
166
|
|
|
if (strpos($event['session_data']['session_page'], 'login') === false) |
|
167
|
|
|
{ |
|
168
|
|
|
return; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.lastvisit', array( |
|
172
|
|
|
'users' => $event['session_data']['session_user_id'], |
|
173
|
|
|
)); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Check membership after user creation, activation, or login |
|
178
|
|
|
* |
|
179
|
|
|
* @param \phpbb\event\data $event The event object |
|
180
|
|
|
* @return void |
|
181
|
|
|
* @access public |
|
182
|
|
|
*/ |
|
183
|
|
|
public function membership_check($event) |
|
184
|
|
|
{ |
|
185
|
|
|
if ($event->offsetExists('session_data')) // core.session_create_after |
|
186
|
|
|
{ |
|
187
|
|
|
// only check session at login (this will prevent repeated excessive attempts at this check) |
|
188
|
|
|
$users = strpos($event['session_data']['session_page'], 'login') !== false ? $event['session_data']['session_user_id'] : null; |
|
189
|
|
|
} |
|
190
|
|
|
else if ($event->offsetExists('user_id_ary')) // core.user_add_after |
|
191
|
|
|
{ |
|
192
|
|
|
$users = $event['user_id_ary']; |
|
193
|
|
|
} |
|
194
|
|
|
else // core.user_active_flip_after |
|
195
|
|
|
{ |
|
196
|
|
|
$users = $event['user_id']; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
if (null === $users) |
|
200
|
|
|
{ |
|
201
|
|
|
return; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.membership', array( |
|
205
|
|
|
'users' => $users, |
|
206
|
|
|
)); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths