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; |
11
|
|
|
|
12
|
|
|
class helper |
13
|
|
|
{ |
14
|
|
|
/** @var \phpbb\auth\auth */ |
15
|
|
|
protected $auth; |
16
|
|
|
|
17
|
|
|
/** @var \phpbb\config\db */ |
18
|
|
|
protected $config; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\user */ |
21
|
|
|
protected $user; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
protected $phpbb_root_path; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
protected $php_ext; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Constructor |
31
|
|
|
* |
32
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
33
|
|
|
* @param \phpbb\config\db $config Config object |
34
|
|
|
* @param \phpbb\user $user User object |
35
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
36
|
|
|
* @param string $php_ext php file extension |
37
|
|
|
*/ |
38
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user, $phpbb_root_path, $php_ext) |
39
|
|
|
{ |
40
|
|
|
$this->auth = $auth; |
41
|
|
|
$this->config = $config; |
42
|
|
|
$this->user = $user; |
43
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
44
|
|
|
$this->php_ext = $php_ext; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $post_data |
49
|
|
|
* @param array $topic_data |
50
|
|
|
* @param string $cp_mode |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function get_edit_url(array $post_data, array $topic_data, $cp_mode = '') |
54
|
|
|
{ |
55
|
|
|
$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode); |
56
|
|
|
return ($this->edit_allowed($post_data, $topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=edit&f={$topic_data['forum_id']}&p={$post_data['post_id']}" . $cp_param) : ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $post_data |
61
|
|
|
* @param array $topic_data |
62
|
|
|
* @param string $cp_mode |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function get_delete_url(array $post_data, array $topic_data, $cp_mode = '') |
66
|
|
|
{ |
67
|
|
|
$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode); |
68
|
|
|
return ($this->delete_allowed($post_data, $topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", 'mode=' . (($this->softdelete_allowed($topic_data, $post_data)) ? 'soft_delete' : 'delete') . "&f={$post_data['forum_id']}&p={$post_data['post_id']}" . $cp_param) : ''; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param array $post_data |
73
|
|
|
* @param array $topic_data |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function get_quote_url(array $post_data, array $topic_data) |
77
|
|
|
{ |
78
|
|
|
return ($this->post_is_quotable($post_data, $topic_data) && $this->quote_allowed($topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=quote&f={$topic_data['forum_id']}&p={$post_data['post_id']}") : ''; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $post_data |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function get_info_url(array $post_data) |
86
|
|
|
{ |
87
|
|
|
$forum_id = $post_data['forum_id']; |
88
|
|
|
return ($this->auth->acl_get('m_info', $forum_id)) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=main&mode=post_details&f=$forum_id&p=" . $post_data['post_id'], true, $this->user->session_id) : ''; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param array $post_data |
93
|
|
|
* @param string $viewtopic_url |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function get_approve_url(array $post_data, $viewtopic_url) |
97
|
|
|
{ |
98
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=queue&p={$post_data['post_id']}&f={$post_data['forum_id']}&redirect=" . urlencode(str_replace('&', '&', $viewtopic_url . '&p=' . $post_data['post_id'] . '#p' . $post_data['post_id']))); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param array $post_data |
103
|
|
|
* @param array $topic_data |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function get_mcp_edit_url(array $post_data, array $topic_data) |
107
|
|
|
{ |
108
|
|
|
return append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=edit&f={$topic_data['forum_id']}&p={$post_data['post_id']}&cp=mcp"); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $post_data |
113
|
|
|
* @return string |
114
|
|
|
* |
115
|
|
|
public function get_mcp_approve_url(array $post_data) |
116
|
|
|
{ |
117
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&mode=approve_details&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'], true, $this->user->session_id); |
118
|
|
|
} |
119
|
|
|
*/ |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param array $post_data |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function get_mcp_report_url(array $post_data) |
126
|
|
|
{ |
127
|
|
|
return ($this->auth->acl_get('m_report', $post_data['forum_id'])) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=reports&mode=report_details&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'], true, $this->user->session_id) : ''; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param array $post_data |
132
|
|
|
* @param array $topic_data |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function get_mcp_restore_url(array $post_data, array $topic_data) |
136
|
|
|
{ |
137
|
|
|
return ($this->auth->acl_get('m_approve', $post_data['forum_id'])) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&mode=' . (($topic_data['topic_visibility'] != ITEM_DELETED) ? 'deleted_posts' : 'deleted_topics') . '&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'], true, $this->user->session_id) : ''; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param array $post_data |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function get_notes_url(array $post_data) |
145
|
|
|
{ |
146
|
|
|
return ($this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=notes&mode=user_notes&u=' . $post_data['poster_id'], true, $this->user->session_id) : ''; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param array $post_data |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function get_warning_url(array $post_data) |
154
|
|
|
{ |
155
|
|
|
return ($this->auth->acl_get('m_warn') && !$this->user_is_poster($post_data['poster_id']) && $post_data['poster_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=warn&mode=warn_post&f=' . $post_data['forum_id'] . '&p=' . $post_data['post_id'], true, $this->user->session_id) : ''; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param int $topic_id |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function get_mcp_queue_url($topic_id) |
163
|
|
|
{ |
164
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=queue&mode=unapproved_posts&t=$topic_id", true, $this->user->session_id); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $content_type |
169
|
|
|
* @param int $topic_id |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function get_mcp_review_url($content_type, $topic_id) |
173
|
|
|
{ |
174
|
|
|
return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=-blitze-content-mcp-content_module&mode=content&do=view&type=$content_type&t=$topic_id"); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param array $post_data |
179
|
|
|
* @return bool |
180
|
|
|
*/ |
181
|
|
|
public function display_attachments_notice(array $post_data) |
182
|
|
|
{ |
183
|
|
|
return (!$this->auth->acl_get('f_download', $post_data['forum_id']) && $post_data['post_attachment']); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param array $post_data |
188
|
|
|
* @return bool |
189
|
|
|
*/ |
190
|
|
|
public function permanent_delete_allowed(array $post_data) |
191
|
|
|
{ |
192
|
|
|
return ($this->auth->acl_get('m_delete', $post_data['forum_id']) || |
193
|
|
|
($this->auth->acl_get('f_delete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id'])); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param int $poster_id |
198
|
|
|
* @return bool |
199
|
|
|
*/ |
200
|
|
|
public function user_is_poster($poster_id) |
201
|
|
|
{ |
202
|
|
|
return ($poster_id == $this->user->data['user_id']); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param int $forum_id |
207
|
|
|
* @return bool |
208
|
|
|
*/ |
209
|
|
|
public function can_report_post($forum_id) |
210
|
|
|
{ |
211
|
|
|
return ($this->auth->acl_get('f_report', $forum_id)); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param array $topic_data |
216
|
|
|
* @return bool |
217
|
|
|
* |
218
|
|
|
public function topic_is_unapproved(array $topic_data) |
219
|
|
|
{ |
220
|
|
|
return (($topic_data['topic_visibility'] == ITEM_UNAPPROVED || $topic_data['topic_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $topic_data['forum_id'])); |
221
|
|
|
} |
222
|
|
|
*/ |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param array $topic_data |
226
|
|
|
* @return bool |
227
|
|
|
*/ |
228
|
|
|
public function topic_has_unapproved_posts(array $topic_data) |
229
|
|
|
{ |
230
|
|
|
return ($topic_data['topic_visibility'] == ITEM_APPROVED && $topic_data['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $topic_data['forum_id'])); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param array $topic_data |
235
|
|
|
* @return bool |
236
|
|
|
*/ |
237
|
|
|
public function topic_is_reported(array $topic_data) |
238
|
|
|
{ |
239
|
|
|
return ($topic_data['topic_reported'] && !$topic_data['topic_moved_id'] && $this->auth->acl_get('m_report', $topic_data['forum_id'])) ? true : false; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param array $topic_data |
244
|
|
|
* @return bool |
245
|
|
|
*/ |
246
|
|
|
public function topic_is_locked(array $topic_data) |
247
|
|
|
{ |
248
|
|
|
return ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param array $post_data |
253
|
|
|
* @return bool |
254
|
|
|
*/ |
255
|
|
|
public function post_is_unapproved(array $post_data) |
256
|
|
|
{ |
257
|
|
|
return (($post_data['post_visibility'] == ITEM_UNAPPROVED || $post_data['post_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $topic_data['forum_id'])) ? true : false; |
|
|
|
|
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @param array $post_data |
262
|
|
|
* @param array $topic_data |
263
|
|
|
* @param string $cp_class |
|
|
|
|
264
|
|
|
* @return string |
265
|
|
|
*/ |
266
|
|
|
protected function get_cp_param(array $post_data, array $topic_data, $cp_mode) |
267
|
|
|
{ |
268
|
|
|
$cp_param = ''; |
269
|
|
|
if ($topic_data['topic_first_post_id'] == $post_data['post_id']) |
270
|
|
|
{ |
271
|
|
|
$cp_param = '&cp=' . ((!$cp_mode) ? (($this->user_is_poster($post_data['poster_id'])) ? 'ucp' : 'mcp') : $cp_mode); |
272
|
|
|
} |
273
|
|
|
return $cp_param; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @param array $post_data |
278
|
|
|
* @param array $topic_data |
279
|
|
|
* @return bool |
280
|
|
|
*/ |
281
|
|
|
protected function edit_allowed(array $post_data, array $topic_data) |
282
|
|
|
{ |
283
|
|
|
return ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit', $post_data['forum_id']) || ( |
284
|
|
|
!$this->cannot_edit($post_data) && |
285
|
|
|
!$this->cannot_edit_time($post_data) && |
286
|
|
|
!$this->cannot_edit_locked($post_data, $topic_data) |
287
|
|
|
))); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param array $topic_data |
292
|
|
|
* @return bool |
293
|
|
|
*/ |
294
|
|
|
protected function quote_allowed(array $topic_data) |
295
|
|
|
{ |
296
|
|
|
return $this->auth->acl_get('m_edit', $topic_data['forum_id']) || ($topic_data['topic_status'] != ITEM_LOCKED && |
297
|
|
|
($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('f_reply', $topic_data['forum_id'])) |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param array $post_data |
303
|
|
|
* @param array $topic_data |
304
|
|
|
* @return bool |
305
|
|
|
*/ |
306
|
|
|
protected function post_is_quotable(array $post_data, array $topic_data) |
307
|
|
|
{ |
308
|
|
|
return ($post_data['post_visibility'] == ITEM_APPROVED && $topic_data['topic_first_post_id'] != $post_data['post_id']); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param array $post_data |
313
|
|
|
* @param array $topic_data |
314
|
|
|
* @return bool |
315
|
|
|
*/ |
316
|
|
|
protected function delete_allowed(array $post_data, array $topic_data) |
317
|
|
|
{ |
318
|
|
|
return ($this->user->data['is_registered'] && (($this->auth->acl_get('m_delete', $post_data['forum_id']) || ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) && $post_data['post_visibility'] != ITEM_DELETED)) || ( |
319
|
|
|
!$this->cannot_delete($post_data) && |
320
|
|
|
!$this->cannot_delete_lastpost($post_data, $topic_data) && |
321
|
|
|
!$this->cannot_delete_time($post_data) && |
322
|
|
|
!$this->cannot_delete_locked($post_data, $topic_data) |
323
|
|
|
))); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @param array $post_data |
328
|
|
|
* @return bool |
329
|
|
|
*/ |
330
|
|
|
protected function softdelete_allowed(array $post_data) |
331
|
|
|
{ |
332
|
|
|
return ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) || |
333
|
|
|
($this->auth->acl_get('f_softdelete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id'])) && ($post_data['post_visibility'] != ITEM_DELETED); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @param array $post_data |
338
|
|
|
* @return bool |
339
|
|
|
*/ |
340
|
|
|
protected function cannot_edit(array $post_data) |
341
|
|
|
{ |
342
|
|
|
return (!$this->auth->acl_get('f_edit', $post_data['forum_id']) || $this->user->data['user_id'] != $post_data['poster_id']); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param array $post_data |
347
|
|
|
* @return bool |
348
|
|
|
*/ |
349
|
|
|
protected function cannot_edit_time(array $post_data) |
350
|
|
|
{ |
351
|
|
|
return ($this->config['edit_time'] && $post_data['post_time'] <= time() - ($this->config['edit_time'] * 60)); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param array $post_data |
356
|
|
|
* @param array $topic_data |
357
|
|
|
* @return bool |
358
|
|
|
*/ |
359
|
|
|
protected function cannot_edit_locked(array $post_data, array $topic_data) |
360
|
|
|
{ |
361
|
|
|
return ($topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked']); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @param array $post_data |
366
|
|
|
* @return bool |
367
|
|
|
*/ |
368
|
|
|
protected function cannot_delete(array $post_data) |
369
|
|
|
{ |
370
|
|
|
return $this->user->data['user_id'] != $post_data['poster_id'] || ( |
371
|
|
|
!$this->auth->acl_get('f_delete', $post_data['forum_id']) && |
372
|
|
|
(!$this->auth->acl_get('f_softdelete', $post_data['forum_id']) || $post_data['post_visibility'] == ITEM_DELETED) |
373
|
|
|
); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @param array $post_data |
378
|
|
|
* @param array $topic_data |
379
|
|
|
* @return bool |
380
|
|
|
*/ |
381
|
|
|
protected function cannot_delete_lastpost(array $post_data, array $topic_data) |
382
|
|
|
{ |
383
|
|
|
return $topic_data['topic_last_post_id'] != $post_data['post_id']; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @param array $post_data |
388
|
|
|
* @return bool |
389
|
|
|
*/ |
390
|
|
|
protected function cannot_delete_time(array $post_data) |
391
|
|
|
{ |
392
|
|
|
return $this->config['delete_time'] && $post_data['post_time'] <= time() - ($this->config['delete_time'] * 60); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* we do not want to allow removal of the last post if a moderator locked it! |
397
|
|
|
* @param array $post_data |
398
|
|
|
* @param array $topic_data |
399
|
|
|
* @return bool |
400
|
|
|
*/ |
401
|
|
|
protected function cannot_delete_locked(array $post_data, array $topic_data) |
402
|
|
|
{ |
403
|
|
|
return $topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked']; |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.