1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2016 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\content\services\actions\topic; |
11
|
|
|
|
12
|
|
|
use blitze\content\services\actions\action_interface; |
13
|
|
|
|
14
|
|
|
class moderate implements action_interface |
15
|
|
|
{ |
16
|
|
|
/** @var \phpbb\auth\auth */ |
17
|
|
|
protected $auth; |
18
|
|
|
|
19
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
20
|
|
|
protected $db; |
21
|
|
|
|
22
|
|
|
/** @var \phpbb\language\language */ |
23
|
|
|
protected $language; |
24
|
|
|
|
25
|
|
|
/** @var \phpbb\request\request_interface */ |
26
|
|
|
protected $request; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
protected $phpbb_root_path; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $php_ext; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor |
36
|
|
|
* |
37
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
38
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database connection |
39
|
|
|
* @param \phpbb\language\language $language Language object |
40
|
|
|
* @param \phpbb\request\request_interface $request Request object |
41
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
42
|
|
|
* @param string $php_ext php file extension |
43
|
|
|
*/ |
44
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\request\request_interface $request, $phpbb_root_path, $php_ext) |
45
|
|
|
{ |
46
|
|
|
$this->auth = $auth; |
47
|
|
|
$this->db = $db; |
48
|
|
|
$this->language = $language; |
49
|
|
|
$this->request = $request; |
50
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
51
|
|
|
$this->php_ext = $php_ext; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
|
|
public function execute($u_action, $mode = '') |
58
|
|
|
{ |
59
|
|
|
$this->language->add_lang('cp', 'blitze/content'); |
60
|
|
|
|
61
|
|
|
include($this->phpbb_root_path . 'includes/mcp/mcp_main.' . $this->php_ext); |
62
|
|
|
include($this->phpbb_root_path . 'includes/mcp/mcp_forum.' . $this->php_ext); |
63
|
|
|
include($this->phpbb_root_path . 'includes/mcp/mcp_queue.' . $this->php_ext); |
64
|
|
|
include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); |
65
|
|
|
|
66
|
|
|
$action = $this->request->variable('action', ''); |
67
|
|
|
$topic_ids = array_filter($this->request->variable('topic_id_list', array(0))); |
68
|
|
|
|
69
|
|
|
if (!sizeof($topic_ids) && !$this->request->is_set_post('confirm')) |
70
|
|
|
{ |
71
|
|
|
trigger_error('NO_TOPIC_SELECTED'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (method_exists($this, $action)) |
75
|
|
|
{ |
76
|
|
|
$forum_ids = $this->get_selected_forum_ids($topic_ids); |
77
|
|
|
$this->{$action}($topic_ids, $forum_ids); |
78
|
|
|
} |
79
|
|
|
else |
80
|
|
|
{ |
81
|
|
|
$message = $this->language->lang('INVALID_REQUEST', $action); |
82
|
|
|
trigger_error($message . '<br /><br />' . $this->language->lang('RETURN_PAGE', '<a href="' . $u_action . '">', '</a>')); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param array $topic_ids |
88
|
|
|
* @param array $forum_ids |
89
|
|
|
* @param bool $execute |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
protected function approve(array $topic_ids, array $forum_ids, $execute = true) |
93
|
|
|
{ |
94
|
|
|
if (!(sizeof(array_intersect_key($forum_ids, $this->auth->acl_getf('m_approve', true))))) |
95
|
|
|
{ |
96
|
|
|
trigger_error('NOT_AUTHORISED'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($execute) |
100
|
|
|
{ |
101
|
|
|
\mcp_queue::approve_topics('approve', $topic_ids, '-blitze-content-mcp-content_module', 'content'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param array $topic_ids |
107
|
|
|
* @param array $forum_ids |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
protected function disapprove(array $topic_ids, array $forum_ids) |
111
|
|
|
{ |
112
|
|
|
$post_id_list = $this->get_selected_post_ids($topic_ids); |
113
|
|
|
|
114
|
|
|
if (!empty($post_id_list)) |
115
|
|
|
{ |
116
|
|
|
$this->approve($topic_ids, $forum_ids, false); |
117
|
|
|
\mcp_queue::disapprove_posts($post_id_list, '-blitze-content-mcp-content_module', 'content'); |
118
|
|
|
} |
119
|
|
|
else |
120
|
|
|
{ |
121
|
|
|
trigger_error('NO_POST_SELECTED'); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param array $topic_ids |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
protected function restore_topic(array $topic_ids) |
130
|
|
|
{ |
131
|
|
|
mcp_restore_topic($topic_ids); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param array $topic_ids |
136
|
|
|
* @param array $forum_ids |
137
|
|
|
*/ |
138
|
|
|
protected function delete_topic(array $topic_ids, array $forum_ids) |
139
|
|
|
{ |
140
|
|
|
$this->language->add_lang('viewtopic'); |
141
|
|
|
|
142
|
|
|
$can_delete = (sizeof(array_intersect_key($forum_ids, $this->auth->acl_getf('m_delete', true)))) ? true : false; |
143
|
|
|
$soft_delete = (($this->request->is_set_post('confirm') && !$this->request->is_set_post('delete_permanent')) || !$can_delete) ? true : false; |
144
|
|
|
|
145
|
|
|
mcp_delete_topic($topic_ids, $soft_delete, $this->request->variable('delete_reason', '', true)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param array $topic_ids |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
protected function resync(array $topic_ids) |
153
|
|
|
{ |
154
|
|
|
mcp_resync_topics($topic_ids); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param $action |
159
|
|
|
* @param array $topic_ids |
160
|
|
|
*/ |
161
|
|
|
protected function change_topic_type($action, array $topic_ids) |
162
|
|
|
{ |
163
|
|
|
change_topic_type($action, $topic_ids); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param array $topic_ids |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
protected function make_announce(array $topic_ids) |
171
|
|
|
{ |
172
|
|
|
$this->change_topic_type('make_announce', $topic_ids); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param array $topic_ids |
177
|
|
|
* @return void |
178
|
|
|
*/ |
179
|
|
|
protected function make_sticky(array $topic_ids) |
180
|
|
|
{ |
181
|
|
|
$this->change_topic_type('make_sticky', $topic_ids); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param array $topic_ids |
186
|
|
|
* @return void |
187
|
|
|
*/ |
188
|
|
|
protected function make_global(array $topic_ids) |
189
|
|
|
{ |
190
|
|
|
$this->change_topic_type('make_global', $topic_ids); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param array $topic_ids |
195
|
|
|
* @return void |
196
|
|
|
*/ |
197
|
|
|
protected function make_normal(array $topic_ids) |
198
|
|
|
{ |
199
|
|
|
$this->change_topic_type('make_normal', $topic_ids); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param array $topic_ids |
204
|
|
|
* @return void |
205
|
|
|
*/ |
206
|
|
|
protected function lock(array $topic_ids) |
207
|
|
|
{ |
208
|
|
|
lock_unlock('lock', $topic_ids); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @param array $topic_ids |
213
|
|
|
* @return void |
214
|
|
|
*/ |
215
|
|
|
protected function unlock(array $topic_ids) |
216
|
|
|
{ |
217
|
|
|
lock_unlock('unlock', $topic_ids); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param array $topic_ids |
222
|
|
|
* @return array |
223
|
|
|
*/ |
224
|
|
|
protected function get_selected_forum_ids(array $topic_ids) |
225
|
|
|
{ |
226
|
|
|
if (!sizeof($topic_ids)) |
227
|
|
|
{ |
228
|
|
|
return array(); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
$sql = 'SELECT forum_id |
232
|
|
|
FROM ' . TOPICS_TABLE . ' |
233
|
|
|
WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); |
234
|
|
|
$result = $this->db->sql_query($sql); |
235
|
|
|
|
236
|
|
|
$forum_ids = array(); |
237
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
238
|
|
|
{ |
239
|
|
|
$forum_ids[$row['forum_id']] = $row['forum_id']; |
240
|
|
|
} |
241
|
|
|
$this->db->sql_freeresult($result); |
242
|
|
|
|
243
|
|
|
return $forum_ids; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param array $topic_ids |
248
|
|
|
* @return array |
249
|
|
|
*/ |
250
|
|
|
protected function get_selected_post_ids(array $topic_ids) |
251
|
|
|
{ |
252
|
|
|
$post_id_list = array_filter($this->request->variable('post_id_list', array(0))); |
253
|
|
|
|
254
|
|
|
if (sizeof($post_id_list)) |
255
|
|
|
{ |
256
|
|
|
return $post_id_list; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$sql = 'SELECT post_id |
260
|
|
|
FROM ' . POSTS_TABLE . ' |
261
|
|
|
WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); |
262
|
|
|
$result = $this->db->sql_query($sql); |
263
|
|
|
|
264
|
|
|
$post_id_list = array(); |
265
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
266
|
|
|
{ |
267
|
|
|
$post_id_list[] = (int) $row['post_id']; |
268
|
|
|
} |
269
|
|
|
$this->db->sql_freeresult($result); |
270
|
|
|
|
271
|
|
|
return $post_id_list; |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|