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
|
|
|
static public 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 Gorups "Last Visit" listeners |
57
|
|
|
'core.session_create_after' => 'last_visit_check', |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Delete autogroups rules when their related group is deleted |
63
|
|
|
* |
64
|
|
|
* @param \phpbb\event\data $event The event object |
65
|
|
|
* @return void |
66
|
|
|
* @access public |
67
|
|
|
*/ |
68
|
|
|
public function delete_group_rules($event) |
69
|
|
|
{ |
70
|
|
|
$this->manager->purge_autogroups_group($event['group_id']); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Load common language files during user setup |
75
|
|
|
* |
76
|
|
|
* @param \phpbb\event\data $event The event object |
77
|
|
|
* @return void |
78
|
|
|
* @access public |
79
|
|
|
*/ |
80
|
|
|
public function load_language_on_setup($event) |
81
|
|
|
{ |
82
|
|
|
$lang_set_ext = $event['lang_set_ext']; |
83
|
|
|
$lang_set_ext[] = array( |
84
|
|
|
'ext_name' => 'phpbb/autogroups', |
85
|
|
|
'lang_set' => 'autogroups_common', |
86
|
|
|
); |
87
|
|
|
$event['lang_set_ext'] = $lang_set_ext; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Check user's post count after submitting a post for auto groups |
92
|
|
|
* |
93
|
|
|
* @param \phpbb\event\data $event The event object |
94
|
|
|
* @return void |
95
|
|
|
* @access public |
96
|
|
|
*/ |
97
|
|
|
public function submit_post_check($event) |
98
|
|
|
{ |
99
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
100
|
|
|
'users' => $event['data']['poster_id'], |
101
|
|
|
)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Check user's post count after deleting a post for auto groups |
106
|
|
|
* |
107
|
|
|
* @param \phpbb\event\data $event The event object |
108
|
|
|
* @return void |
109
|
|
|
* @access public |
110
|
|
|
*/ |
111
|
|
|
public function delete_post_check($event) |
112
|
|
|
{ |
113
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
114
|
|
|
'action' => 'delete', |
115
|
|
|
'users' => $event['poster_ids'], |
116
|
|
|
)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Check user's post count after approving a post for auto groups |
121
|
|
|
* |
122
|
|
|
* @param \phpbb\event\data $event The event object |
123
|
|
|
* @return void |
124
|
|
|
* @access public |
125
|
|
|
*/ |
126
|
|
|
public function approve_post_check($event) |
127
|
|
|
{ |
128
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.posts', array( |
129
|
|
|
'users' => array_column($event['post_info'], 'poster_id'), |
130
|
|
|
)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Check user's warnings count after receiving a warning for auto groups |
135
|
|
|
* |
136
|
|
|
* @param \phpbb\event\data $event The event object |
137
|
|
|
* @return void |
138
|
|
|
* @access public |
139
|
|
|
*/ |
140
|
|
|
public function add_warning_check($event) |
141
|
|
|
{ |
142
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.warnings', array( |
143
|
|
|
'users' => $event['user_row']['user_id'], |
144
|
|
|
)); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Check user's last visit status when they log in |
149
|
|
|
* |
150
|
|
|
* @param \phpbb\event\data $event The event object |
151
|
|
|
* @return void |
152
|
|
|
* @access public |
153
|
|
|
*/ |
154
|
|
|
public function last_visit_check($event) |
155
|
|
|
{ |
156
|
|
|
$this->manager->check_condition('phpbb.autogroups.type.lastvisit', array( |
157
|
|
|
'users' => $event['session_data']['session_user_id'], |
158
|
|
|
)); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|