|
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 index extends filter implements action_interface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \phpbb\auth\auth */ |
|
17
|
|
|
protected $auth; |
|
18
|
|
|
|
|
19
|
|
|
/** @var \phpbb\config\config */ |
|
20
|
|
|
protected $config; |
|
21
|
|
|
|
|
22
|
|
|
/** @var \phpbb\controller\helper */ |
|
23
|
|
|
protected $controller_helper; |
|
24
|
|
|
|
|
25
|
|
|
/** @var \phpbb\pagination */ |
|
26
|
|
|
protected $pagination; |
|
27
|
|
|
|
|
28
|
|
|
/** @var \phpbb\user */ |
|
29
|
|
|
protected $user; |
|
30
|
|
|
|
|
31
|
|
|
/** @var \blitze\content\services\types */ |
|
32
|
|
|
protected $content_types; |
|
33
|
|
|
|
|
34
|
|
|
/* @var \blitze\content\services\fields */ |
|
35
|
|
|
protected $fields; |
|
36
|
|
|
|
|
37
|
|
|
/** @var \blitze\sitemaker\services\forum\data */ |
|
|
|
|
|
|
38
|
|
|
protected $forum; |
|
39
|
|
|
|
|
40
|
|
|
/* @var \blitze\content\services\helper */ |
|
41
|
|
|
protected $helper; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string */ |
|
44
|
|
|
protected $phpbb_root_path; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
protected $php_ext; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string */ |
|
50
|
|
|
protected $base_url; |
|
51
|
|
|
|
|
52
|
|
|
/** @var string */ |
|
53
|
|
|
protected $redirect_url; |
|
54
|
|
|
|
|
55
|
|
|
/** @var int */ |
|
56
|
|
|
protected $topics_per_page; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor |
|
60
|
|
|
* |
|
61
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
|
62
|
|
|
* @param \phpbb\config\config $config Config object |
|
63
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database connection |
|
64
|
|
|
* @param \phpbb\controller\helper $controller_helper Controller Helper object |
|
65
|
|
|
* @param \phpbb\pagination $pagination Pagination object |
|
66
|
|
|
* @param \phpbb\request\request_interface $request Request object |
|
67
|
|
|
* @param \phpbb\template\template $template Template object |
|
68
|
|
|
* @param \phpbb\user $user User object |
|
69
|
|
|
* @param \blitze\content\services\types $content_types Content types object |
|
70
|
|
|
* @param \blitze\content\services\fields $fields Content fields object |
|
71
|
|
|
* @param \blitze\sitemaker\services\forum\data $forum Forum query object |
|
72
|
|
|
* @param \blitze\content\services\helper $helper Content helper object |
|
73
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
|
74
|
|
|
* @param string $php_ext php file extension |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $controller_helper, \phpbb\pagination $pagination, \phpbb\request\request_interface $request, \phpbb\template\template $template, \phpbb\user $user, \blitze\content\services\types $content_types, \blitze\content\services\fields $fields, \blitze\sitemaker\services\forum\data $forum, \blitze\content\services\helper $helper, $phpbb_root_path, $php_ext) |
|
77
|
|
|
{ |
|
78
|
|
|
parent::__construct($db, $request, $template); |
|
79
|
|
|
|
|
80
|
|
|
$this->auth = $auth; |
|
81
|
|
|
$this->config = $config; |
|
82
|
|
|
$this->controller_helper = $controller_helper; |
|
83
|
|
|
$this->pagination = $pagination; |
|
84
|
|
|
$this->user = $user; |
|
85
|
|
|
$this->content_types = $content_types; |
|
86
|
|
|
$this->fields = $fields; |
|
87
|
|
|
$this->forum = $forum; |
|
88
|
|
|
$this->helper = $helper; |
|
89
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
|
90
|
|
|
$this->php_ext = $php_ext; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @inheritdoc |
|
95
|
|
|
*/ |
|
96
|
|
|
public function execute($u_action, $mode = '') |
|
97
|
|
|
{ |
|
98
|
|
|
include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
|
99
|
|
|
|
|
100
|
|
|
$this->user->add_lang('viewforum'); |
|
|
|
|
|
|
101
|
|
|
$this->template->assign_var('MODE', $mode); |
|
102
|
|
|
|
|
103
|
|
|
$content_types = $this->content_types->get_all_types(); |
|
104
|
|
|
$this->content_forums = $this->content_types->get_forum_types(); |
|
105
|
|
|
$this->topics_per_page = (int) $this->config['topics_per_page']; |
|
106
|
|
|
$this->redirect_url = build_url(); |
|
107
|
|
|
|
|
108
|
|
|
if (sizeof($content_types)) |
|
109
|
|
|
{ |
|
110
|
|
|
$sql_where_array = array(); |
|
111
|
|
|
$search_info = $this->apply_search_filter($sql_where_array); |
|
|
|
|
|
|
112
|
|
|
$filter_topic_status = $this->apply_topic_status_filter($sql_where_array); |
|
113
|
|
|
$filter_content_type = $this->apply_content_type_filter(); |
|
114
|
|
|
|
|
115
|
|
|
$this->generate_search_filter($search_info, $u_action); |
|
|
|
|
|
|
116
|
|
|
$this->generate_content_type_filter($filter_content_type, $content_types, $u_action); |
|
117
|
|
|
$this->generate_topic_status_filter($filter_topic_status, $u_action); |
|
118
|
|
|
|
|
119
|
|
|
$this->forum->query() |
|
120
|
|
|
->fetch_forum(array_keys($this->content_forums)) |
|
121
|
|
|
->set_sorting('t.topic_time') |
|
122
|
|
|
->fetch_custom(array('WHERE' => $sql_where_array)); |
|
123
|
|
|
|
|
124
|
|
|
$this->base_url = $u_action; |
|
125
|
|
|
$callable = 'init_' . $mode . '_mode'; |
|
126
|
|
|
$this->$callable($content_types); |
|
127
|
|
|
|
|
128
|
|
|
$start = $this->generate_pagination($u_action); |
|
129
|
|
|
$this->show_topics($mode, $u_action, $start); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
protected function init_mcp_mode() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->forum->build(true, false, false); |
|
139
|
|
|
|
|
140
|
|
|
$s_can_approve = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('m_approve', true))); |
|
141
|
|
|
$s_can_make_sticky = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('f_sticky', true))); |
|
142
|
|
|
$s_can_make_announce = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('f_announce', true))); |
|
143
|
|
|
$s_can_delete = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('m_delete', true))); |
|
144
|
|
|
$s_can_lock = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('m_lock', true))); |
|
145
|
|
|
$user_is_mod = (bool) sizeof(array_intersect_key($this->content_forums, $this->auth->acl_getf('m_', true))); |
|
146
|
|
|
|
|
147
|
|
|
$this->template->assign_vars(array( |
|
148
|
|
|
'S_CAN_DELETE' => $s_can_delete, |
|
149
|
|
|
'S_CAN_RESTORE' => $s_can_approve, |
|
150
|
|
|
'S_CAN_LOCK' => $s_can_lock, |
|
151
|
|
|
'S_CAN_SYNC' => $user_is_mod, |
|
152
|
|
|
'S_CAN_APPROVE' => $s_can_approve, |
|
153
|
|
|
'S_CAN_MAKE_NORMAL' => ($s_can_make_sticky || $s_can_make_announce), |
|
154
|
|
|
'S_CAN_MAKE_STICKY' => $s_can_make_sticky, |
|
155
|
|
|
'S_CAN_MAKE_ANNOUNCE' => $s_can_make_announce, |
|
156
|
|
|
'U_MCP_ACTION' => $this->base_url . '&do=moderate&redirect=' . $this->get_redirect_url($this->base_url), |
|
157
|
|
|
)); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param array $content_types |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function init_ucp_mode(array $content_types) |
|
164
|
|
|
{ |
|
165
|
|
|
$sql_where_array['WHERE'] = 't.topic_poster = ' . (int) $this->user->data['user_id']; |
|
|
|
|
|
|
166
|
|
|
$this->forum->fetch_custom($sql_where_array) |
|
167
|
|
|
->build(false, false, false); |
|
168
|
|
|
|
|
169
|
|
|
// list all content types that the user can post in |
|
170
|
|
|
$postable_forums = array_intersect_key($this->content_forums, $this->auth->acl_getf('f_post', true)); |
|
171
|
|
|
$postable_types = array_intersect_key($content_types, array_flip($postable_forums)); |
|
172
|
|
|
$redirect = '&redirect=' . urlencode($this->redirect_url); |
|
173
|
|
|
|
|
174
|
|
|
/** @var \blitze\content\model\entity\type $entity */ |
|
175
|
|
|
foreach ($postable_types as $type => $entity) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->template->assign_block_vars('postable', array( |
|
178
|
|
|
'TYPE' => $entity->get_content_langname(), |
|
179
|
|
|
'COLOUR' => $entity->get_content_colour(), |
|
180
|
|
|
'U_POST' => append_sid("{$this->phpbb_root_path}posting." . $this->php_ext, 'mode=post&f=' . $entity->get_forum_id() . $redirect), |
|
181
|
|
|
)); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param string $mode |
|
187
|
|
|
* @param string $u_action |
|
188
|
|
|
* @param int $start |
|
189
|
|
|
* @return void |
|
190
|
|
|
*/ |
|
191
|
|
|
protected function show_topics($mode, $u_action, $start) |
|
192
|
|
|
{ |
|
193
|
|
|
$topics_data = $this->forum->get_topic_data($this->topics_per_page, $start); |
|
194
|
|
|
$posts_data = $this->forum->get_post_data('first'); |
|
195
|
|
|
$users_cache = $this->forum->get_posters_info(); |
|
196
|
|
|
$topic_tracking_info = $this->forum->get_topic_tracking_info(); |
|
197
|
|
|
|
|
198
|
|
|
$attachments = $update_count = array(); |
|
199
|
|
|
foreach ($topics_data as $topic_id => $topic_row) |
|
200
|
|
|
{ |
|
201
|
|
|
$post_row = array_shift($posts_data[$topic_id]); |
|
202
|
|
|
$content_type = $this->content_forums[$topic_row['forum_id']]; |
|
203
|
|
|
$tpl_data = $this->fields->show($content_type, $topic_row, $post_row, $users_cache, $attachments, $update_count, $topic_tracking_info, array(), $this->redirect_url); |
|
204
|
|
|
|
|
205
|
|
|
$this->template->assign_block_vars('topicrow', array_merge($tpl_data, |
|
206
|
|
|
$this->get_content_type_info($content_type), |
|
207
|
|
|
$this->get_topic_type_info($tpl_data['S_UNREAD_POST'], $tpl_data['TOPIC_COMMENTS'], $topic_row), |
|
208
|
|
|
$this->get_topic_status_info($topic_row), |
|
209
|
|
|
$this->get_topic_info($content_type, $u_action, $topic_row), |
|
210
|
|
|
$this->get_moderator_info($mode, $topic_id, $tpl_data['S_POST_UNAPPROVED'], false, $tpl_data['S_TOPIC_DELETED']) |
|
211
|
|
|
)); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param string $content_type |
|
217
|
|
|
* @param string $u_action |
|
218
|
|
|
* @param array $row |
|
219
|
|
|
* @return array |
|
220
|
|
|
*/ |
|
221
|
|
|
protected function get_topic_info($content_type, $u_action, array $row) |
|
222
|
|
|
{ |
|
223
|
|
|
return array( |
|
224
|
|
|
'ATTACH_ICON_IMG' => $this->get_attachment_icon($row), |
|
225
|
|
|
'U_REVIEW_TOPIC' => $u_action . "&do=view&type=$content_type&t={$row['topic_id']}&redirect=" . $this->redirect_url, |
|
226
|
|
|
); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @param string $type |
|
231
|
|
|
* @return array |
|
232
|
|
|
*/ |
|
233
|
|
|
protected function get_content_type_info($type) |
|
234
|
|
|
{ |
|
235
|
|
|
$entity = $this->content_types->get_type($type); |
|
236
|
|
|
$comments_type = $entity->get_comments(); |
|
237
|
|
|
|
|
238
|
|
|
$this->fields->set_comments_type($comments_type); |
|
239
|
|
|
|
|
240
|
|
|
return array( |
|
241
|
|
|
'CONTENT_TYPE' => $entity->get_content_langname(), |
|
242
|
|
|
'CONTENT_TYPE_COLOR' => $entity->get_content_colour(), |
|
243
|
|
|
'S_COMMENTS' => (bool) $comments_type, |
|
244
|
|
|
'U_CONTENT_TYPE' => $this->content_type_base_url . "&type=$type", |
|
245
|
|
|
); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Get folder img, topic status/type related information |
|
250
|
|
|
* @param bool $unread_topic |
|
251
|
|
|
* @param int $num_comments |
|
252
|
|
|
* @param array $row |
|
253
|
|
|
* @return array |
|
254
|
|
|
*/ |
|
255
|
|
|
protected function get_topic_type_info($unread_topic, $num_comments, $row) |
|
256
|
|
|
{ |
|
257
|
|
|
$folder_img = $folder_alt = $topic_type = ''; |
|
258
|
|
|
topic_status($row, $num_comments, $unread_topic, $folder_img, $folder_alt, $topic_type); |
|
259
|
|
|
|
|
260
|
|
|
return array( |
|
261
|
|
|
'TOPIC_TYPE' => $topic_type, |
|
262
|
|
|
'TOPIC_IMG_STYLE' => $folder_img, |
|
263
|
|
|
'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), |
|
264
|
|
|
); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @param array $row |
|
269
|
|
|
* @return array |
|
270
|
|
|
*/ |
|
271
|
|
|
protected function get_topic_status_info(array $row) |
|
272
|
|
|
{ |
|
273
|
|
|
$unapproved = true; |
|
274
|
|
|
$topic_status = $this->get_topic_status_filters()[$row['topic_visibility']]; |
|
275
|
|
|
|
|
276
|
|
|
if ($row['topic_visibility'] == ITEM_APPROVED) |
|
277
|
|
|
{ |
|
278
|
|
|
$unapproved = false; |
|
279
|
|
|
$topic_status = $this->get_topic_type($row); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
return array( |
|
283
|
|
|
'TOPIC_STATUS' => $topic_status, |
|
284
|
|
|
'S_POST_UNAPPROVED' => $unapproved, |
|
285
|
|
|
'U_TOPIC_STATUS' => $this->topic_status_base_url . '&status=' . $topic_status, |
|
286
|
|
|
); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @param array $row |
|
291
|
|
|
* @return string |
|
292
|
|
|
*/ |
|
293
|
|
|
protected function get_topic_type(array $row) |
|
294
|
|
|
{ |
|
295
|
|
|
return $this->get_topic_types_filters()[$row['topic_type']]; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @param array $row |
|
300
|
|
|
* @return string |
|
301
|
|
|
*/ |
|
302
|
|
|
protected function get_attachment_icon(array $row) |
|
303
|
|
|
{ |
|
304
|
|
|
return ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment']) ? $this->user->img('icon_topic_attach', $this->language->lang('TOTAL_ATTACHMENTS')) : ''; |
|
|
|
|
|
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @param string $mode |
|
309
|
|
|
* @param int $topic_id |
|
310
|
|
|
* @param bool $topic_unapproved |
|
311
|
|
|
* @param bool $posts_unapproved |
|
312
|
|
|
* @param bool $topic_deleted |
|
313
|
|
|
* @return array |
|
314
|
|
|
*/ |
|
315
|
|
|
protected function get_moderator_info($mode, $topic_id, $topic_unapproved, $posts_unapproved, $topic_deleted) |
|
316
|
|
|
{ |
|
317
|
|
|
$u_mcp_queue = ''; |
|
318
|
|
|
if ($mode === 'mcp') |
|
319
|
|
|
{ |
|
320
|
|
|
$u_mcp_queue = $this->get_mcp_queue_url($topic_unapproved, $posts_unapproved, $topic_id); |
|
321
|
|
|
$u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&mode=deleted_topics&t=' . $topic_id, true, $this->user->session_id) : $u_mcp_queue; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
return array( |
|
325
|
|
|
'U_MCP_QUEUE' => $u_mcp_queue, |
|
326
|
|
|
); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @param bool $topic_unapproved |
|
331
|
|
|
* @param bool $posts_unapproved |
|
332
|
|
|
* @param int $topic_id |
|
333
|
|
|
* @return string |
|
334
|
|
|
*/ |
|
335
|
|
|
protected function get_mcp_queue_url($topic_unapproved, $posts_unapproved, $topic_id) |
|
336
|
|
|
{ |
|
337
|
|
|
return ($topic_unapproved || $posts_unapproved) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $this->user->session_id) : ''; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* @param string $base_url |
|
342
|
|
|
* @return string |
|
343
|
|
|
*/ |
|
344
|
|
|
protected function get_redirect_url($base_url) |
|
345
|
|
|
{ |
|
346
|
|
|
$base_url .= (sizeof($this->params)) ? '&' . http_build_query($this->params) : ''; |
|
347
|
|
|
return urlencode(str_replace('&', '&', $base_url)); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @param string $u_action |
|
352
|
|
|
* @return int |
|
353
|
|
|
*/ |
|
354
|
|
|
protected function generate_pagination($u_action) |
|
355
|
|
|
{ |
|
356
|
|
|
$start = $this->request->variable('start', 0); |
|
357
|
|
|
|
|
358
|
|
|
$topics_count = $this->forum->get_topics_count(); |
|
359
|
|
|
$page_url = $this->get_filter_type_base_url($u_action); |
|
360
|
|
|
|
|
361
|
|
|
$this->template->assign_vars(array( |
|
362
|
|
|
'TOTAL_TOPICS' => $this->user->lang('VIEW_FORUM_TOPICS', $topics_count), |
|
|
|
|
|
|
363
|
|
|
)); |
|
364
|
|
|
|
|
365
|
|
|
$start = $this->pagination->validate_start($start, $this->topics_per_page, $topics_count); |
|
366
|
|
|
$this->pagination->generate_template_pagination($page_url, 'pagination', 'start', $topics_count, $this->topics_per_page, $start); |
|
367
|
|
|
|
|
368
|
|
|
return $start; |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
|
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