Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
2.64% |
22 / 832 |
|
0.00% |
0 / 13 |
CRAP | n/a |
0 / 0 |
|
display_forums | |
0.00% |
0 / 344 |
|
0.00% |
0 / 1 |
18632 | |||
generate_forum_rules | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
generate_forum_nav | |
0.00% |
0 / 50 |
|
0.00% |
0 / 1 |
210 | |||
get_forum_parents | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
20 | |||
get_moderators | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
110 | |||
gen_forum_auth_level | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
380 | |||
topic_status | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
306 | |||
display_custom_bbcodes | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
20 | |||
display_user_activity | |
0.00% |
0 / 77 |
|
0.00% |
0 / 1 |
210 | |||
watch_topic_forum | |
0.00% |
0 / 100 |
|
0.00% |
0 / 1 |
1640 | |||
phpbb_get_user_rank | |
70.00% |
21 / 30 |
|
0.00% |
0 / 1 |
15.89 | |||
phpbb_show_profile | |
0.00% |
0 / 75 |
|
0.00% |
0 / 1 |
3422 | |||
phpbb_sort_last_active | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | /** |
15 | * @ignore |
16 | */ |
17 | if (!defined('IN_PHPBB')) |
18 | { |
19 | exit; |
20 | } |
21 | |
22 | /** |
23 | * Display Forums |
24 | */ |
25 | function display_forums($root_data = '', $display_moderators = true, $return_moderators = false) |
26 | { |
27 | global $db, $auth, $user, $template; |
28 | global $phpbb_root_path, $phpEx, $config; |
29 | global $request, $phpbb_dispatcher, $phpbb_container; |
30 | |
31 | $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); |
32 | $parent_id = $visible_forums = 0; |
33 | $parent_subforum_limit = false; |
34 | |
35 | // Mark forums read? |
36 | $mark_read = $request->variable('mark', ''); |
37 | |
38 | if ($mark_read == 'all') |
39 | { |
40 | $mark_read = ''; |
41 | } |
42 | |
43 | if (!$root_data) |
44 | { |
45 | if ($mark_read == 'forums') |
46 | { |
47 | $mark_read = 'all'; |
48 | } |
49 | |
50 | $root_data = array('forum_id' => 0); |
51 | $sql_where = ''; |
52 | } |
53 | else |
54 | { |
55 | $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id']; |
56 | } |
57 | |
58 | // Handle marking everything read |
59 | if ($mark_read == 'all') |
60 | { |
61 | $redirect = build_url(array('mark', 'hash', 'mark_time')); |
62 | meta_refresh(3, $redirect); |
63 | |
64 | if (check_link_hash($request->variable('hash', ''), 'global')) |
65 | { |
66 | markread('all', false, false, $request->variable('mark_time', 0)); |
67 | |
68 | if ($request->is_ajax()) |
69 | { |
70 | // Tell the ajax script what language vars and URL need to be replaced |
71 | $data = array( |
72 | 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], |
73 | 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], |
74 | 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time(), false) : '', |
75 | 'MESSAGE_TITLE' => $user->lang['INFORMATION'], |
76 | 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED'] |
77 | ); |
78 | $json_response = new \phpbb\json_response(); |
79 | $json_response->send($data); |
80 | } |
81 | |
82 | trigger_error( |
83 | $user->lang['FORUMS_MARKED'] . '<br /><br />' . |
84 | sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>') |
85 | ); |
86 | } |
87 | else |
88 | { |
89 | trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>')); |
90 | } |
91 | } |
92 | |
93 | // Display list of active topics for this category? |
94 | $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false; |
95 | |
96 | $sql_array = array( |
97 | 'SELECT' => 'f.*', |
98 | 'FROM' => array( |
99 | FORUMS_TABLE => 'f' |
100 | ), |
101 | 'LEFT_JOIN' => array(), |
102 | ); |
103 | |
104 | if ($config['load_db_lastread'] && $user->data['is_registered']) |
105 | { |
106 | $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'); |
107 | $sql_array['SELECT'] .= ', ft.mark_time'; |
108 | } |
109 | else if ($config['load_anon_lastread'] || $user->data['is_registered']) |
110 | { |
111 | $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE); |
112 | $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array(); |
113 | |
114 | if (!$user->data['is_registered']) |
115 | { |
116 | $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0; |
117 | } |
118 | } |
119 | |
120 | if ($show_active) |
121 | { |
122 | $sql_array['LEFT_JOIN'][] = array( |
123 | 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'), |
124 | 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'" |
125 | ); |
126 | |
127 | $sql_array['SELECT'] .= ', fa.user_id'; |
128 | } |
129 | |
130 | $sql_ary = array( |
131 | 'SELECT' => $sql_array['SELECT'], |
132 | 'FROM' => $sql_array['FROM'], |
133 | 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], |
134 | |
135 | 'WHERE' => $sql_where, |
136 | |
137 | 'ORDER_BY' => 'f.left_id', |
138 | ); |
139 | |
140 | /** |
141 | * Event to modify the SQL query before the forum data is queried |
142 | * |
143 | * @event core.display_forums_modify_sql |
144 | * @var array sql_ary The SQL array to get the data of the forums |
145 | * @since 3.1.0-a1 |
146 | */ |
147 | $vars = array('sql_ary'); |
148 | extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars))); |
149 | |
150 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
151 | $result = $db->sql_query($sql); |
152 | |
153 | $forum_tracking_info = $valid_categories = array(); |
154 | $branch_root_id = $root_data['forum_id']; |
155 | |
156 | /* @var $phpbb_content_visibility \phpbb\content_visibility */ |
157 | $phpbb_content_visibility = $phpbb_container->get('content.visibility'); |
158 | |
159 | while ($row = $db->sql_fetchrow($result)) |
160 | { |
161 | /** |
162 | * Event to modify the data set of a forum |
163 | * |
164 | * This event is triggered once per forum |
165 | * |
166 | * @event core.display_forums_modify_row |
167 | * @var int branch_root_id Last top-level forum |
168 | * @var array row The data of the forum |
169 | * @since 3.1.0-a1 |
170 | */ |
171 | $vars = array('branch_root_id', 'row'); |
172 | extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars))); |
173 | |
174 | $forum_id = $row['forum_id']; |
175 | |
176 | // Mark forums read? |
177 | if ($mark_read == 'forums') |
178 | { |
179 | if ($auth->acl_get('f_list', $forum_id)) |
180 | { |
181 | $forum_ids[] = $forum_id; |
182 | } |
183 | |
184 | continue; |
185 | } |
186 | |
187 | // Category with no members |
188 | if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) |
189 | { |
190 | continue; |
191 | } |
192 | |
193 | // Skip branch |
194 | if (isset($right_id)) |
195 | { |
196 | if ($row['left_id'] < $right_id) |
197 | { |
198 | continue; |
199 | } |
200 | unset($right_id); |
201 | } |
202 | |
203 | if (!$auth->acl_get('f_list', $forum_id)) |
204 | { |
205 | // if the user does not have permissions to list this forum, skip everything until next branch |
206 | $right_id = $row['right_id']; |
207 | continue; |
208 | } |
209 | |
210 | if ($config['load_db_lastread'] && $user->data['is_registered']) |
211 | { |
212 | $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark']; |
213 | } |
214 | else if ($config['load_anon_lastread'] || $user->data['is_registered']) |
215 | { |
216 | if (!$user->data['is_registered']) |
217 | { |
218 | $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0; |
219 | } |
220 | $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark']; |
221 | } |
222 | |
223 | // Lets check whether there are unapproved topics/posts, so we can display an information to moderators |
224 | $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved']) ? $forum_id : 0; |
225 | $row['forum_id_unapproved_posts'] = ($auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved']) ? $forum_id : 0; |
226 | $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id); |
227 | $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id); |
228 | |
229 | // Display active topics from this forum? |
230 | if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) |
231 | { |
232 | if (!isset($active_forum_ary['forum_topics'])) |
233 | { |
234 | $active_forum_ary['forum_topics'] = 0; |
235 | } |
236 | |
237 | if (!isset($active_forum_ary['forum_posts'])) |
238 | { |
239 | $active_forum_ary['forum_posts'] = 0; |
240 | } |
241 | |
242 | $active_forum_ary['forum_id'][] = $forum_id; |
243 | $active_forum_ary['enable_icons'][] = $row['enable_icons']; |
244 | $active_forum_ary['forum_topics'] += $row['forum_topics']; |
245 | $active_forum_ary['forum_posts'] += $row['forum_posts']; |
246 | |
247 | // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it... |
248 | if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) |
249 | { |
250 | $active_forum_ary['exclude_forum_id'][] = $forum_id; |
251 | } |
252 | } |
253 | |
254 | // Fill list of categories with forums |
255 | if (isset($forum_rows[$row['parent_id']])) |
256 | { |
257 | $valid_categories[$row['parent_id']] = true; |
258 | } |
259 | |
260 | // |
261 | if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) |
262 | { |
263 | if ($row['forum_type'] != FORUM_CAT) |
264 | { |
265 | $forum_ids_moderator[] = (int) $forum_id; |
266 | } |
267 | |
268 | // Direct child of current branch |
269 | $parent_id = $forum_id; |
270 | $parent_subforum_limit = $row['display_subforum_limit'] ?? false; |
271 | $forum_rows[$forum_id] = $row; |
272 | |
273 | if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) |
274 | { |
275 | $branch_root_id = $forum_id; |
276 | } |
277 | $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; |
278 | $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password']; |
279 | $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; |
280 | } |
281 | else if ($row['forum_type'] != FORUM_CAT) |
282 | { |
283 | $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index'] && (!$parent_subforum_limit || $parent_id == $row['parent_id'])); |
284 | $subforums[$parent_id][$forum_id]['name'] = $row['forum_name']; |
285 | $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; |
286 | $subforums[$parent_id][$forum_id]['children'] = array(); |
287 | $subforums[$parent_id][$forum_id]['type'] = $row['forum_type']; |
288 | |
289 | if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index']) |
290 | { |
291 | $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id; |
292 | } |
293 | |
294 | if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics']) |
295 | { |
296 | $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id; |
297 | } |
298 | |
299 | if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts']) |
300 | { |
301 | $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id; |
302 | } |
303 | |
304 | $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics']; |
305 | |
306 | // Do not list redirects in LINK Forums as Posts. |
307 | if ($row['forum_type'] != FORUM_LINK) |
308 | { |
309 | $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts']; |
310 | } |
311 | |
312 | if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) |
313 | { |
314 | $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id']; |
315 | $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject']; |
316 | $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time']; |
317 | $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id']; |
318 | $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name']; |
319 | $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour']; |
320 | $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id; |
321 | $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password']; |
322 | } |
323 | } |
324 | |
325 | /** |
326 | * Event to modify the forum rows data set |
327 | * |
328 | * This event is triggered once per forum |
329 | * |
330 | * @event core.display_forums_modify_forum_rows |
331 | * @var array forum_rows Data array of all forums we display |
332 | * @var array subforums Data array of all subforums we display |
333 | * @var int branch_root_id Current top-level forum |
334 | * @var int parent_id Current parent forum |
335 | * @var array row The data of the forum |
336 | * @since 3.1.0-a1 |
337 | */ |
338 | $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row'); |
339 | extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars))); |
340 | } |
341 | $db->sql_freeresult($result); |
342 | |
343 | // Handle marking posts |
344 | if ($mark_read == 'forums') |
345 | { |
346 | $redirect = build_url(array('mark', 'hash', 'mark_time')); |
347 | $token = $request->variable('hash', ''); |
348 | if (check_link_hash($token, 'global')) |
349 | { |
350 | markread('topics', $forum_ids, false, $request->variable('mark_time', 0)); |
351 | $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>'); |
352 | meta_refresh(3, $redirect); |
353 | |
354 | if ($request->is_ajax()) |
355 | { |
356 | // Tell the ajax script what language vars and URL need to be replaced |
357 | $data = array( |
358 | 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], |
359 | 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], |
360 | 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time(), false) : '', |
361 | 'MESSAGE_TITLE' => $user->lang['INFORMATION'], |
362 | 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED'] |
363 | ); |
364 | $json_response = new \phpbb\json_response(); |
365 | $json_response->send($data); |
366 | } |
367 | |
368 | trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message); |
369 | } |
370 | else |
371 | { |
372 | $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'); |
373 | meta_refresh(3, $redirect); |
374 | trigger_error($message); |
375 | } |
376 | |
377 | } |
378 | |
379 | // Grab moderators ... if necessary |
380 | if ($display_moderators) |
381 | { |
382 | if ($return_moderators) |
383 | { |
384 | $forum_ids_moderator[] = $root_data['forum_id']; |
385 | } |
386 | get_moderators($forum_moderators, $forum_ids_moderator); |
387 | } |
388 | |
389 | /** |
390 | * Event to perform additional actions before the forum list is being generated |
391 | * |
392 | * @event core.display_forums_before |
393 | * @var array active_forum_ary Array with forum data to display active topics |
394 | * @var bool display_moderators Flag indicating if we display forum moderators |
395 | * @var array forum_moderators Array with forum moderators list |
396 | * @var array forum_rows Data array of all forums we display |
397 | * @var bool return_moderators Flag indicating if moderators list should be returned |
398 | * @var array root_data Array with the root forum data |
399 | * @since 3.1.4-RC1 |
400 | */ |
401 | $vars = array( |
402 | 'active_forum_ary', |
403 | 'display_moderators', |
404 | 'forum_moderators', |
405 | 'forum_rows', |
406 | 'return_moderators', |
407 | 'root_data', |
408 | ); |
409 | extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars))); |
410 | |
411 | // Used to tell whatever we have to create a dummy category or not. |
412 | $last_catless = true; |
413 | foreach ($forum_rows as $row) |
414 | { |
415 | // Category |
416 | if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) |
417 | { |
418 | // Do not display categories without any forums to display |
419 | if (!isset($valid_categories[$row['forum_id']])) |
420 | { |
421 | continue; |
422 | } |
423 | |
424 | $cat_row = array( |
425 | 'S_IS_CAT' => true, |
426 | 'FORUM_ID' => $row['forum_id'], |
427 | 'FORUM_NAME' => $row['forum_name'], |
428 | 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), |
429 | 'FORUM_FOLDER_IMG' => '', |
430 | 'FORUM_FOLDER_IMG_SRC' => '', |
431 | 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', |
432 | 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', |
433 | 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']), |
434 | ); |
435 | |
436 | /** |
437 | * Modify the template data block of the 'category' |
438 | * |
439 | * This event is triggered once per 'category' |
440 | * |
441 | * @event core.display_forums_modify_category_template_vars |
442 | * @var array cat_row Template data of the 'category' |
443 | * @var bool last_catless The flag indicating whether the last forum had a parent category |
444 | * @var array root_data Array with the root forum data |
445 | * @var array row The data of the 'category' |
446 | * @since 3.1.0-RC4 |
447 | * @changed 3.1.7-RC1 Removed undefined catless variable |
448 | */ |
449 | $vars = array( |
450 | 'cat_row', |
451 | 'last_catless', |
452 | 'root_data', |
453 | 'row', |
454 | ); |
455 | extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars))); |
456 | |
457 | $template->assign_block_vars('forumrow', $cat_row); |
458 | |
459 | continue; |
460 | } |
461 | |
462 | $visible_forums++; |
463 | $forum_id = $row['forum_id']; |
464 | |
465 | $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false; |
466 | |
467 | $folder_image = $folder_alt = $l_subforums = ''; |
468 | $subforums_list = array(); |
469 | |
470 | // Generate list of subforums if we need to |
471 | if (isset($subforums[$forum_id])) |
472 | { |
473 | foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) |
474 | { |
475 | $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false; |
476 | |
477 | if (!$subforum_unread && !empty($subforum_row['children'])) |
478 | { |
479 | foreach ($subforum_row['children'] as $child_id) |
480 | { |
481 | if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id]) |
482 | { |
483 | // Once we found an unread child forum, we can drop out of this loop |
484 | $subforum_unread = true; |
485 | break; |
486 | } |
487 | } |
488 | } |
489 | |
490 | if ($subforum_row['display'] && $subforum_row['name']) |
491 | { |
492 | $subforums_list[] = array( |
493 | 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id), |
494 | 'name' => $subforum_row['name'], |
495 | 'unread' => $subforum_unread, |
496 | 'type' => $subforum_row['type'], |
497 | ); |
498 | } |
499 | else |
500 | { |
501 | unset($subforums[$forum_id][$subforum_id]); |
502 | } |
503 | |
504 | // If one subforum is unread the forum gets unread too... |
505 | if ($subforum_unread) |
506 | { |
507 | $forum_unread = true; |
508 | } |
509 | } |
510 | |
511 | $l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS']; |
512 | $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum'; |
513 | } |
514 | else |
515 | { |
516 | switch ($row['forum_type']) |
517 | { |
518 | case FORUM_POST: |
519 | $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read'; |
520 | break; |
521 | |
522 | case FORUM_LINK: |
523 | $folder_image = 'forum_link'; |
524 | break; |
525 | } |
526 | } |
527 | |
528 | // Which folder should we display? |
529 | if ($row['forum_status'] == ITEM_LOCKED) |
530 | { |
531 | $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked'; |
532 | $folder_alt = 'FORUM_LOCKED'; |
533 | } |
534 | else |
535 | { |
536 | $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS'; |
537 | } |
538 | |
539 | // Create last post link information, if appropriate |
540 | if ($row['forum_last_post_id']) |
541 | { |
542 | if ($row['forum_password_last_post'] === '' && $auth->acl_gets('f_read', 'f_list_topics', $row['forum_id_last_post'])) |
543 | { |
544 | $last_post_subject = utf8_decode_ncr(censor_text($row['forum_last_post_subject'])); |
545 | |
546 | $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']); |
547 | } |
548 | else |
549 | { |
550 | $last_post_subject = $last_post_subject_truncated = ''; |
551 | } |
552 | $last_post_time = $user->format_date($row['forum_last_post_time']); |
553 | $last_post_time_rfc3339 = gmdate(DATE_RFC3339, $row['forum_last_post_time']); |
554 | $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id']; |
555 | } |
556 | else |
557 | { |
558 | $last_post_subject = $last_post_time = $last_post_time_rfc3339 = $last_post_url = $last_post_subject_truncated = ''; |
559 | } |
560 | |
561 | // Output moderator listing ... if applicable |
562 | $l_moderator = $moderators_list = ''; |
563 | if ($display_moderators && !empty($forum_moderators[$forum_id])) |
564 | { |
565 | $l_moderator = (count($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS']; |
566 | $moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]); |
567 | } |
568 | |
569 | $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS'; |
570 | $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : ''; |
571 | |
572 | $s_subforums_list = $subforums_row = array(); |
573 | foreach ($subforums_list as $subforum) |
574 | { |
575 | $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>'; |
576 | $subforums_row[] = array( |
577 | 'U_SUBFORUM' => $subforum['link'], |
578 | 'SUBFORUM_NAME' => $subforum['name'], |
579 | 'S_UNREAD' => $subforum['unread'], |
580 | 'IS_LINK' => $subforum['type'] == FORUM_LINK, |
581 | ); |
582 | } |
583 | $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list); |
584 | $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false; |
585 | |
586 | if ($row['forum_type'] != FORUM_LINK) |
587 | { |
588 | $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']); |
589 | } |
590 | else |
591 | { |
592 | // If the forum is a link and we count redirects we need to visit it |
593 | // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum |
594 | if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id)) |
595 | { |
596 | $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']); |
597 | } |
598 | else |
599 | { |
600 | $u_viewforum = $row['forum_link']; |
601 | } |
602 | } |
603 | |
604 | $forum_row = array( |
605 | 'S_IS_CAT' => false, |
606 | 'S_NO_CAT' => $catless && !$last_catless, |
607 | 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false, |
608 | 'S_UNREAD_FORUM' => $forum_unread, |
609 | 'S_AUTH_READ' => $auth->acl_get('f_read', $row['forum_id']), |
610 | 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false, |
611 | 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false, |
612 | 'S_SUBFORUMS' => (count($subforums_list)) ? true : false, |
613 | 'S_DISPLAY_SUBJECT' => ($last_post_subject !== '' && $config['display_last_subject']) ? true : false, |
614 | 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false, |
615 | |
616 | 'FORUM_ID' => $row['forum_id'], |
617 | 'FORUM_NAME' => $row['forum_name'], |
618 | 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), |
619 | 'TOPICS' => $row['forum_topics'], |
620 | $l_post_click_count => $post_click_count, |
621 | 'FORUM_IMG_STYLE' => $folder_image, |
622 | 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), |
623 | 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '', |
624 | 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '', |
625 | 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', |
626 | 'LAST_POST_SUBJECT' => $last_post_subject, |
627 | 'LAST_POST_SUBJECT_TRUNCATED' => $last_post_subject_truncated, |
628 | 'LAST_POST_TIME' => $last_post_time, |
629 | 'LAST_POST_TIME_RFC3339'=> $last_post_time_rfc3339, |
630 | 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), |
631 | 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), |
632 | 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), |
633 | 'MODERATORS' => $moderators_list, |
634 | 'SUBFORUMS' => $s_subforums_list, |
635 | |
636 | 'L_SUBFORUM_STR' => $l_subforums, |
637 | 'L_MODERATOR_STR' => $l_moderator, |
638 | |
639 | 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '', |
640 | 'U_UNAPPROVED_POSTS' => ($row['forum_id_unapproved_posts']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_posts&f=' . $row['forum_id_unapproved_posts']) : '', |
641 | 'U_VIEWFORUM' => $u_viewforum, |
642 | 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), |
643 | 'U_LAST_POST' => $last_post_url, |
644 | ); |
645 | |
646 | /** |
647 | * Modify the template data block of the forum |
648 | * |
649 | * This event is triggered once per forum |
650 | * |
651 | * @event core.display_forums_modify_template_vars |
652 | * @var array forum_row Template data of the forum |
653 | * @var array row The data of the forum |
654 | * @var array subforums_row Template data of subforums |
655 | * @since 3.1.0-a1 |
656 | * @changed 3.1.0-b5 Added var subforums_row |
657 | */ |
658 | $vars = array('forum_row', 'row', 'subforums_row'); |
659 | extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars))); |
660 | |
661 | $template->assign_block_vars('forumrow', $forum_row); |
662 | |
663 | // Assign subforums loop for style authors |
664 | $template->assign_block_vars_array('forumrow.subforum', $subforums_row); |
665 | |
666 | /** |
667 | * Modify and/or assign additional template data for the forum |
668 | * after forumrow loop has been assigned. This can be used |
669 | * to create additional forumrow subloops in extensions. |
670 | * |
671 | * This event is triggered once per forum |
672 | * |
673 | * @event core.display_forums_add_template_data |
674 | * @var array forum_row Template data of the forum |
675 | * @var array row The data of the forum |
676 | * @var array subforums_list The data of subforums |
677 | * @var array subforums_row Template data of subforums |
678 | * @var bool catless The flag indicating whether a forum has a parent category |
679 | * @since 3.1.0-b5 |
680 | */ |
681 | $vars = array( |
682 | 'forum_row', |
683 | 'row', |
684 | 'subforums_list', |
685 | 'subforums_row', |
686 | 'catless', |
687 | ); |
688 | extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars))); |
689 | |
690 | $last_catless = $catless; |
691 | } |
692 | |
693 | $template->assign_vars(array( |
694 | 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '', |
695 | 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false, |
696 | 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], |
697 | 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), |
698 | 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'), |
699 | 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM'), |
700 | )); |
701 | |
702 | /** |
703 | * Event to perform additional actions after the forum list has been generated |
704 | * |
705 | * @event core.display_forums_after |
706 | * @var array active_forum_ary Array with forum data to display active topics |
707 | * @var bool display_moderators Flag indicating if we display forum moderators |
708 | * @var array forum_moderators Array with forum moderators list |
709 | * @var array forum_rows Data array of all forums we display |
710 | * @var bool return_moderators Flag indicating if moderators list should be returned |
711 | * @var array root_data Array with the root forum data |
712 | * @since 3.1.0-RC5 |
713 | */ |
714 | $vars = array( |
715 | 'active_forum_ary', |
716 | 'display_moderators', |
717 | 'forum_moderators', |
718 | 'forum_rows', |
719 | 'return_moderators', |
720 | 'root_data', |
721 | ); |
722 | extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars))); |
723 | |
724 | if ($return_moderators) |
725 | { |
726 | return array($active_forum_ary, $forum_moderators); |
727 | } |
728 | |
729 | return array($active_forum_ary, array()); |
730 | } |
731 | |
732 | /** |
733 | * Create forum rules for given forum |
734 | */ |
735 | function generate_forum_rules(&$forum_data) |
736 | { |
737 | if ($forum_data['forum_rules']) |
738 | { |
739 | $forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']); |
740 | } |
741 | |
742 | if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link']) |
743 | { |
744 | return; |
745 | } |
746 | |
747 | global $template; |
748 | |
749 | $template->assign_vars(array( |
750 | 'S_FORUM_RULES' => true, |
751 | 'U_FORUM_RULES' => $forum_data['forum_rules_link'], |
752 | 'FORUM_RULES' => $forum_data['forum_rules']) |
753 | ); |
754 | } |
755 | |
756 | /** |
757 | * Create forum navigation links for given forum, create parent |
758 | * list if currently null, assign basic forum info to template |
759 | */ |
760 | function generate_forum_nav(&$forum_data_ary) |
761 | { |
762 | global $template, $auth, $config; |
763 | global $phpEx, $phpbb_root_path, $phpbb_dispatcher; |
764 | |
765 | if (!$auth->acl_get('f_list', $forum_data_ary['forum_id'])) |
766 | { |
767 | return; |
768 | } |
769 | |
770 | $navlinks_parents = array(); |
771 | |
772 | // Get forum parents |
773 | $forum_parents = get_forum_parents($forum_data_ary); |
774 | |
775 | $microdata_attr = 'data-forum-id'; |
776 | |
777 | // Build navigation links |
778 | if (!empty($forum_parents)) |
779 | { |
780 | foreach ($forum_parents as $parent_forum_id => $parent_data) |
781 | { |
782 | list($parent_name, $parent_type) = array_values($parent_data); |
783 | |
784 | // Skip this parent if the user does not have the permission to view it |
785 | if (!$auth->acl_get('f_list', $parent_forum_id)) |
786 | { |
787 | continue; |
788 | } |
789 | |
790 | $navlinks_parents[] = array( |
791 | 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false, |
792 | 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false, |
793 | 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false, |
794 | 'BREADCRUMB_NAME' => $parent_name, |
795 | 'FORUM_ID' => $parent_forum_id, |
796 | 'MICRODATA' => $microdata_attr . '="' . $parent_forum_id . '"', |
797 | 'U_BREADCRUMB' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id), |
798 | ); |
799 | } |
800 | } |
801 | |
802 | $navlinks = array( |
803 | 'S_IS_CAT' => ($forum_data_ary['forum_type'] == FORUM_CAT) ? true : false, |
804 | 'S_IS_LINK' => ($forum_data_ary['forum_type'] == FORUM_LINK) ? true : false, |
805 | 'S_IS_POST' => ($forum_data_ary['forum_type'] == FORUM_POST) ? true : false, |
806 | 'BREADCRUMB_NAME' => $forum_data_ary['forum_name'], |
807 | 'FORUM_ID' => $forum_data_ary['forum_id'], |
808 | 'MICRODATA' => $microdata_attr . '="' . $forum_data_ary['forum_id'] . '"', |
809 | 'U_BREADCRUMB' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data_ary['forum_id']), |
810 | ); |
811 | |
812 | $forum_template_data = array( |
813 | 'FORUM_ID' => $forum_data_ary['forum_id'], |
814 | 'FORUM_NAME' => $forum_data_ary['forum_name'], |
815 | 'FORUM_DESC' => generate_text_for_display($forum_data_ary['forum_desc'], $forum_data_ary['forum_desc_uid'], $forum_data_ary['forum_desc_bitfield'], $forum_data_ary['forum_desc_options']), |
816 | |
817 | 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data_ary['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data_ary['forum_options'])) ? true : false, |
818 | ); |
819 | |
820 | $forum_data = $forum_data_ary; |
821 | /** |
822 | * Event to modify the navlinks text |
823 | * |
824 | * @event core.generate_forum_nav |
825 | * @var array forum_data Array with the forum data |
826 | * @var array forum_template_data Array with generic forum template data |
827 | * @var string microdata_attr The microdata attribute |
828 | * @var array navlinks_parents Array with the forum parents navlinks data |
829 | * @var array navlinks Array with the forum navlinks data |
830 | * @since 3.1.5-RC1 |
831 | */ |
832 | $vars = array( |
833 | 'forum_data', |
834 | 'forum_template_data', |
835 | 'microdata_attr', |
836 | 'navlinks_parents', |
837 | 'navlinks', |
838 | ); |
839 | extract($phpbb_dispatcher->trigger_event('core.generate_forum_nav', compact($vars))); |
840 | $forum_data_ary = $forum_data; |
841 | unset($forum_data); |
842 | |
843 | $template->assign_block_vars_array('navlinks', $navlinks_parents); |
844 | $template->assign_block_vars('navlinks', $navlinks); |
845 | $template->assign_vars($forum_template_data); |
846 | } |
847 | |
848 | /** |
849 | * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise |
850 | */ |
851 | function get_forum_parents(&$forum_data) |
852 | { |
853 | global $db; |
854 | |
855 | $forum_parents = array(); |
856 | |
857 | if ($forum_data['parent_id'] > 0) |
858 | { |
859 | if ($forum_data['forum_parents'] == '') |
860 | { |
861 | $sql = 'SELECT forum_id, forum_name, forum_type |
862 | FROM ' . FORUMS_TABLE . ' |
863 | WHERE left_id < ' . $forum_data['left_id'] . ' |
864 | AND right_id > ' . $forum_data['right_id'] . ' |
865 | ORDER BY left_id ASC'; |
866 | $result = $db->sql_query($sql); |
867 | |
868 | while ($row = $db->sql_fetchrow($result)) |
869 | { |
870 | $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']); |
871 | } |
872 | $db->sql_freeresult($result); |
873 | |
874 | $forum_data['forum_parents'] = serialize($forum_parents); |
875 | |
876 | $sql = 'UPDATE ' . FORUMS_TABLE . " |
877 | SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "' |
878 | WHERE parent_id = " . $forum_data['parent_id']; |
879 | $db->sql_query($sql); |
880 | } |
881 | else |
882 | { |
883 | $forum_parents = unserialize($forum_data['forum_parents']); |
884 | } |
885 | } |
886 | |
887 | return $forum_parents; |
888 | } |
889 | |
890 | /** |
891 | * Obtain list of moderators of each forum |
892 | */ |
893 | function get_moderators(&$forum_moderators, $forum_id = false) |
894 | { |
895 | global $db, $phpbb_root_path, $phpEx, $user, $auth; |
896 | global $phpbb_container; |
897 | |
898 | $forum_id_ary = array(); |
899 | |
900 | if ($forum_id !== false) |
901 | { |
902 | if (!is_array($forum_id)) |
903 | { |
904 | $forum_id = array($forum_id); |
905 | } |
906 | |
907 | // Exchange key/value pair to be able to faster check for the forum id existence |
908 | $forum_id_ary = array_flip($forum_id); |
909 | } |
910 | |
911 | $sql_array = array( |
912 | 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type', |
913 | |
914 | 'FROM' => array( |
915 | MODERATOR_CACHE_TABLE => 'm', |
916 | ), |
917 | |
918 | 'LEFT_JOIN' => array( |
919 | array( |
920 | 'FROM' => array(USERS_TABLE => 'u'), |
921 | 'ON' => 'm.user_id = u.user_id', |
922 | ), |
923 | array( |
924 | 'FROM' => array(GROUPS_TABLE => 'g'), |
925 | 'ON' => 'm.group_id = g.group_id', |
926 | ), |
927 | ), |
928 | |
929 | 'WHERE' => 'm.display_on_index = 1', |
930 | ); |
931 | |
932 | /** @var \phpbb\group\helper $group_helper */ |
933 | $group_helper = $phpbb_container->get('group_helper'); |
934 | |
935 | // We query every forum here because for caching we should not have any parameter. |
936 | $sql = $db->sql_build_query('SELECT', $sql_array); |
937 | $result = $db->sql_query($sql, 3600); |
938 | |
939 | while ($row = $db->sql_fetchrow($result)) |
940 | { |
941 | $f_id = (int) $row['forum_id']; |
942 | |
943 | if (!isset($forum_id_ary[$f_id])) |
944 | { |
945 | continue; |
946 | } |
947 | |
948 | if (!empty($row['user_id'])) |
949 | { |
950 | $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); |
951 | } |
952 | else |
953 | { |
954 | $group_name = $group_helper->get_name($row['group_name']); |
955 | |
956 | if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')) |
957 | { |
958 | $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>'; |
959 | } |
960 | else |
961 | { |
962 | $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']) . '">' . $group_name . '</a>'; |
963 | } |
964 | } |
965 | } |
966 | $db->sql_freeresult($result); |
967 | } |
968 | |
969 | /** |
970 | * User authorisation levels output |
971 | * |
972 | * @param string $mode Can be forum or topic. Not in use at the moment. |
973 | * @param int $forum_id The current forum the user is in. |
974 | * @param int $forum_status The forums status bit. |
975 | */ |
976 | function gen_forum_auth_level($mode, $forum_id, $forum_status) |
977 | { |
978 | global $template, $auth, $user, $config; |
979 | |
980 | $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false; |
981 | |
982 | $rules = array( |
983 | ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'], |
984 | ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'], |
985 | ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'], |
986 | ($user->data['is_registered'] && ($auth->acl_gets('f_delete', 'm_delete', $forum_id) || $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'], |
987 | ); |
988 | |
989 | if ($config['allow_attachments']) |
990 | { |
991 | $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT']; |
992 | } |
993 | |
994 | foreach ($rules as $rule) |
995 | { |
996 | $template->assign_block_vars('rules', array('RULE' => $rule)); |
997 | } |
998 | } |
999 | |
1000 | /** |
1001 | * Generate topic status |
1002 | */ |
1003 | function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type) |
1004 | { |
1005 | global $user, $config; |
1006 | |
1007 | if ($topic_row['topic_status'] == ITEM_MOVED) |
1008 | { |
1009 | $topic_type = $user->lang['VIEW_TOPIC_MOVED']; |
1010 | $folder_img = 'topic_moved'; |
1011 | $folder_alt = 'TOPIC_MOVED'; |
1012 | } |
1013 | else |
1014 | { |
1015 | switch ($topic_row['topic_type']) |
1016 | { |
1017 | case POST_GLOBAL: |
1018 | $topic_type = $user->lang['VIEW_TOPIC_GLOBAL']; |
1019 | $folder = 'global_read'; |
1020 | $folder_new = 'global_unread'; |
1021 | break; |
1022 | |
1023 | case POST_ANNOUNCE: |
1024 | $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT']; |
1025 | $folder = 'announce_read'; |
1026 | $folder_new = 'announce_unread'; |
1027 | break; |
1028 | |
1029 | case POST_STICKY: |
1030 | $topic_type = $user->lang['VIEW_TOPIC_STICKY']; |
1031 | $folder = 'sticky_read'; |
1032 | $folder_new = 'sticky_unread'; |
1033 | break; |
1034 | |
1035 | default: |
1036 | $topic_type = ''; |
1037 | $folder = 'topic_read'; |
1038 | $folder_new = 'topic_unread'; |
1039 | |
1040 | // Hot topic threshold is for posts in a topic, which is replies + the first post. ;) |
1041 | if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED) |
1042 | { |
1043 | $folder .= '_hot'; |
1044 | $folder_new .= '_hot'; |
1045 | } |
1046 | break; |
1047 | } |
1048 | |
1049 | if ($topic_row['topic_status'] == ITEM_LOCKED) |
1050 | { |
1051 | $topic_type = $user->lang['VIEW_TOPIC_LOCKED']; |
1052 | $folder .= '_locked'; |
1053 | $folder_new .= '_locked'; |
1054 | } |
1055 | |
1056 | $folder_img = ($unread_topic) ? $folder_new : $folder; |
1057 | $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS'); |
1058 | |
1059 | // Posted image? |
1060 | if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted']) |
1061 | { |
1062 | $folder_img .= '_mine'; |
1063 | } |
1064 | } |
1065 | |
1066 | if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED) |
1067 | { |
1068 | $topic_type = $user->lang['VIEW_TOPIC_POLL']; |
1069 | } |
1070 | } |
1071 | |
1072 | /** |
1073 | * Assign/Build custom bbcodes for display in screens supporting using of bbcodes |
1074 | * The custom bbcodes buttons will be placed within the template block 'custom_tags' |
1075 | */ |
1076 | function display_custom_bbcodes() |
1077 | { |
1078 | global $db, $template, $user, $phpbb_dispatcher; |
1079 | |
1080 | // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing) |
1081 | $num_predefined_bbcodes = NUM_PREDEFINED_BBCODES; |
1082 | |
1083 | $sql_ary = [ |
1084 | 'SELECT' => 'b.bbcode_id, b.bbcode_tag, b.bbcode_helpline, b.bbcode_match', |
1085 | 'FROM' => [BBCODES_TABLE => 'b'], |
1086 | 'WHERE' => 'b.display_on_posting = 1', |
1087 | 'ORDER_BY' => 'b.bbcode_tag', |
1088 | ]; |
1089 | |
1090 | /** |
1091 | * Event to modify the SQL query before custom bbcode data is queried |
1092 | * |
1093 | * @event core.display_custom_bbcodes_modify_sql |
1094 | * @var array sql_ary The SQL array to get the bbcode data |
1095 | * @var int num_predefined_bbcodes The number of predefined core bbcodes |
1096 | * (multiplied by factor of 2) |
1097 | * @since 3.1.0-a3 |
1098 | */ |
1099 | $vars = array('sql_ary', 'num_predefined_bbcodes'); |
1100 | extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_sql', compact($vars))); |
1101 | |
1102 | $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); |
1103 | |
1104 | $i = 0; |
1105 | while ($row = $db->sql_fetchrow($result)) |
1106 | { |
1107 | // If the helpline is defined within the language file, we will use the localised version, else just use the database entry... |
1108 | if (isset($user->lang[strtoupper($row['bbcode_helpline'])])) |
1109 | { |
1110 | $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])]; |
1111 | } |
1112 | |
1113 | // Convert Numeric Character References to UTF-8 chars. |
1114 | $row['bbcode_helpline'] = utf8_decode_ncr($row['bbcode_helpline']); |
1115 | |
1116 | // Does the closing bbcode tag exists? If so display it. |
1117 | $bbcode_close_tag = '%\[\/' . utf8_strtolower($row['bbcode_tag']) . '\]%'; |
1118 | $bbcode_match_str = utf8_strtolower($row['bbcode_match']); |
1119 | $bbcode_name_clean = preg_match($bbcode_close_tag, $bbcode_match_str) ? "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'" : "'[{$row['bbcode_tag']}]', ''"; |
1120 | |
1121 | $custom_tags = [ |
1122 | 'BBCODE_NAME' => $bbcode_name_clean, |
1123 | 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2), |
1124 | 'BBCODE_TAG' => $row['bbcode_tag'], |
1125 | 'BBCODE_TAG_CLEAN' => str_replace('=', '-', $row['bbcode_tag']), |
1126 | 'BBCODE_HELPLINE' => $row['bbcode_helpline'], |
1127 | ]; |
1128 | |
1129 | /** |
1130 | * Event to modify the template data block of a custom bbcode |
1131 | * |
1132 | * This event is triggered once per bbcode |
1133 | * |
1134 | * @event core.display_custom_bbcodes_modify_row |
1135 | * @var array custom_tags Template data of the bbcode |
1136 | * @var array row The data of the bbcode |
1137 | * @since 3.1.0-a1 |
1138 | */ |
1139 | $vars = array('custom_tags', 'row'); |
1140 | extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars))); |
1141 | |
1142 | $template->assign_block_vars('custom_tags', $custom_tags); |
1143 | |
1144 | $i++; |
1145 | } |
1146 | $db->sql_freeresult($result); |
1147 | |
1148 | /** |
1149 | * Display custom bbcodes |
1150 | * |
1151 | * @event core.display_custom_bbcodes |
1152 | * @since 3.1.0-a1 |
1153 | */ |
1154 | $phpbb_dispatcher->trigger_event('core.display_custom_bbcodes'); |
1155 | } |
1156 | |
1157 | /** |
1158 | * Display user activity (action forum/topic) |
1159 | */ |
1160 | function display_user_activity(&$userdata_ary) |
1161 | { |
1162 | global $auth, $template, $db, $user, $config; |
1163 | global $phpbb_root_path, $phpEx; |
1164 | global $phpbb_container, $phpbb_dispatcher; |
1165 | |
1166 | // Do not display user activity for users having too many posts... |
1167 | $limit = $config['load_user_activity_limit']; |
1168 | if ($userdata_ary['user_posts'] > $limit && $limit != 0) |
1169 | { |
1170 | return; |
1171 | } |
1172 | |
1173 | $forum_ary = array(); |
1174 | |
1175 | $forum_read_ary = $auth->acl_getf('f_read'); |
1176 | foreach ($forum_read_ary as $forum_id => $allowed) |
1177 | { |
1178 | if ($allowed['f_read']) |
1179 | { |
1180 | $forum_ary[] = (int) $forum_id; |
1181 | } |
1182 | } |
1183 | |
1184 | $forum_ary = array_diff($forum_ary, $user->get_passworded_forums()); |
1185 | |
1186 | $active_f_row = $active_t_row = array(); |
1187 | if (!empty($forum_ary)) |
1188 | { |
1189 | /* @var $phpbb_content_visibility \phpbb\content_visibility */ |
1190 | $phpbb_content_visibility = $phpbb_container->get('content.visibility'); |
1191 | |
1192 | // Obtain active forum |
1193 | $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts |
1194 | FROM ' . POSTS_TABLE . ' |
1195 | WHERE poster_id = ' . $userdata_ary['user_id'] . ' |
1196 | AND post_postcount = 1 |
1197 | AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' |
1198 | GROUP BY forum_id |
1199 | ORDER BY num_posts DESC'; |
1200 | $result = $db->sql_query_limit($sql, 1); |
1201 | $active_f_row = $db->sql_fetchrow($result); |
1202 | $db->sql_freeresult($result); |
1203 | |
1204 | if (!empty($active_f_row)) |
1205 | { |
1206 | $sql = 'SELECT forum_name |
1207 | FROM ' . FORUMS_TABLE . ' |
1208 | WHERE forum_id = ' . $active_f_row['forum_id']; |
1209 | $result = $db->sql_query($sql, 3600); |
1210 | $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name'); |
1211 | $db->sql_freeresult($result); |
1212 | } |
1213 | |
1214 | // Obtain active topic |
1215 | $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts |
1216 | FROM ' . POSTS_TABLE . ' |
1217 | WHERE poster_id = ' . $userdata_ary['user_id'] . ' |
1218 | AND post_postcount = 1 |
1219 | AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' |
1220 | GROUP BY topic_id |
1221 | ORDER BY num_posts DESC'; |
1222 | $result = $db->sql_query_limit($sql, 1); |
1223 | $active_t_row = $db->sql_fetchrow($result); |
1224 | $db->sql_freeresult($result); |
1225 | |
1226 | if (!empty($active_t_row)) |
1227 | { |
1228 | $sql = 'SELECT topic_title |
1229 | FROM ' . TOPICS_TABLE . ' |
1230 | WHERE topic_id = ' . $active_t_row['topic_id']; |
1231 | $result = $db->sql_query($sql); |
1232 | $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); |
1233 | $db->sql_freeresult($result); |
1234 | } |
1235 | } |
1236 | |
1237 | $userdata = $userdata_ary; |
1238 | $show_user_activity = true; |
1239 | /** |
1240 | * Alter list of forums and topics to display as active |
1241 | * |
1242 | * @event core.display_user_activity_modify_actives |
1243 | * @var array userdata User's data |
1244 | * @var array active_f_row List of active forums |
1245 | * @var array active_t_row List of active posts |
1246 | * @var bool show_user_activity Show user forum and topic activity |
1247 | * @since 3.1.0-RC3 |
1248 | * @changed 3.2.5-RC1 Added show_user_activity into event |
1249 | */ |
1250 | $vars = array('userdata', 'active_f_row', 'active_t_row', 'show_user_activity'); |
1251 | extract($phpbb_dispatcher->trigger_event('core.display_user_activity_modify_actives', compact($vars))); |
1252 | $userdata_ary = $userdata; |
1253 | unset($userdata); |
1254 | |
1255 | $userdata_ary['active_t_row'] = $active_t_row; |
1256 | $userdata_ary['active_f_row'] = $active_f_row; |
1257 | |
1258 | $active_f_name = $active_f_id = $active_f_count = $active_f_pct = ''; |
1259 | if (!empty($active_f_row['num_posts'])) |
1260 | { |
1261 | $active_f_name = $active_f_row['forum_name']; |
1262 | $active_f_id = $active_f_row['forum_id']; |
1263 | $active_f_count = $active_f_row['num_posts']; |
1264 | $active_f_pct = ($userdata_ary['user_posts']) ? ($active_f_count / $userdata_ary['user_posts']) * 100 : 0; |
1265 | } |
1266 | |
1267 | $active_t_name = $active_t_id = $active_t_count = $active_t_pct = ''; |
1268 | if (!empty($active_t_row['num_posts'])) |
1269 | { |
1270 | $active_t_name = $active_t_row['topic_title']; |
1271 | $active_t_id = $active_t_row['topic_id']; |
1272 | $active_t_count = $active_t_row['num_posts']; |
1273 | $active_t_pct = ($userdata_ary['user_posts']) ? ($active_t_count / $userdata_ary['user_posts']) * 100 : 0; |
1274 | } |
1275 | |
1276 | $l_active_pct = ($userdata_ary['user_id'] != ANONYMOUS && $userdata_ary['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE']; |
1277 | |
1278 | $template->assign_vars(array( |
1279 | 'ACTIVE_FORUM' => $active_f_name, |
1280 | 'ACTIVE_FORUM_POSTS' => $user->lang('USER_POSTS', (int) $active_f_count), |
1281 | 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct), |
1282 | 'ACTIVE_TOPIC' => censor_text($active_t_name), |
1283 | 'ACTIVE_TOPIC_POSTS' => $user->lang('USER_POSTS', (int) $active_t_count), |
1284 | 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct), |
1285 | 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id), |
1286 | 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id), |
1287 | 'S_SHOW_ACTIVITY' => $show_user_activity) |
1288 | ); |
1289 | } |
1290 | |
1291 | /** |
1292 | * Topic and forum watching common code |
1293 | */ |
1294 | function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '') |
1295 | { |
1296 | global $db, $user, $phpEx, $start, $phpbb_root_path; |
1297 | global $request; |
1298 | |
1299 | $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE; |
1300 | $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id'; |
1301 | $match_id = ($mode == 'forum') ? $forum_id : $topic_id; |
1302 | $u_url = "uid={$user->data['user_id']}"; |
1303 | $u_url .= ($mode == 'forum') ? '&f' : '&f=' . $forum_id . '&t'; |
1304 | $is_watching = 0; |
1305 | |
1306 | // Is user watching this topic? |
1307 | if ($user_id != ANONYMOUS) |
1308 | { |
1309 | $can_watch = true; |
1310 | |
1311 | if ($notify_status == 'unset') |
1312 | { |
1313 | $sql = "SELECT notify_status |
1314 | FROM $table_sql |
1315 | WHERE $where_sql = $match_id |
1316 | AND user_id = $user_id"; |
1317 | $result = $db->sql_query($sql); |
1318 | |
1319 | $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL; |
1320 | $db->sql_freeresult($result); |
1321 | } |
1322 | |
1323 | if (!is_null($notify_status) && $notify_status !== '') |
1324 | { |
1325 | if (isset($_GET['unwatch'])) |
1326 | { |
1327 | $uid = $request->variable('uid', 0); |
1328 | $token = $request->variable('hash', ''); |
1329 | |
1330 | if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true)) |
1331 | { |
1332 | if ($uid != $user_id || $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) != $mode) |
1333 | { |
1334 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); |
1335 | $message = $user->lang['ERR_UNWATCHING']; |
1336 | |
1337 | if (!$request->is_ajax()) |
1338 | { |
1339 | $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); |
1340 | } |
1341 | trigger_error($message); |
1342 | } |
1343 | |
1344 | $sql = 'DELETE FROM ' . $table_sql . " |
1345 | WHERE $where_sql = $match_id |
1346 | AND user_id = $user_id"; |
1347 | $db->sql_query($sql); |
1348 | |
1349 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); |
1350 | $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)]; |
1351 | |
1352 | if (!$request->is_ajax()) |
1353 | { |
1354 | $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); |
1355 | } |
1356 | meta_refresh(3, $redirect_url); |
1357 | trigger_error($message); |
1358 | } |
1359 | else |
1360 | { |
1361 | $s_hidden_fields = array( |
1362 | 'uid' => $user->data['user_id'], |
1363 | 'unwatch' => $mode, |
1364 | 'start' => $start, |
1365 | 'f' => $forum_id, |
1366 | ); |
1367 | if ($mode != 'forum') |
1368 | { |
1369 | $s_hidden_fields['t'] = $topic_id; |
1370 | } |
1371 | |
1372 | if ($item_title == '') |
1373 | { |
1374 | $confirm_box_message = 'UNWATCH_' . strtoupper($mode); |
1375 | } |
1376 | else |
1377 | { |
1378 | $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title); |
1379 | } |
1380 | confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields)); |
1381 | } |
1382 | } |
1383 | else |
1384 | { |
1385 | $is_watching = true; |
1386 | |
1387 | if ($notify_status != NOTIFY_YES) |
1388 | { |
1389 | $sql = 'UPDATE ' . $table_sql . " |
1390 | SET notify_status = " . NOTIFY_YES . " |
1391 | WHERE $where_sql = $match_id |
1392 | AND user_id = $user_id"; |
1393 | $db->sql_query($sql); |
1394 | } |
1395 | } |
1396 | } |
1397 | else |
1398 | { |
1399 | if (isset($_GET['watch'])) |
1400 | { |
1401 | $uid = $request->variable('uid', 0); |
1402 | $token = $request->variable('hash', ''); |
1403 | |
1404 | if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true)) |
1405 | { |
1406 | if ($uid != $user_id || $request->variable('watch', '', false, \phpbb\request\request_interface::GET) != $mode) |
1407 | { |
1408 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); |
1409 | $message = $user->lang['ERR_WATCHING']; |
1410 | |
1411 | if (!$request->is_ajax()) |
1412 | { |
1413 | $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); |
1414 | } |
1415 | trigger_error($message); |
1416 | } |
1417 | |
1418 | $is_watching = true; |
1419 | |
1420 | $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status) |
1421 | VALUES ($user_id, $match_id, " . NOTIFY_YES . ')'; |
1422 | $db->sql_query($sql); |
1423 | |
1424 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start"); |
1425 | $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)]; |
1426 | |
1427 | if (!$request->is_ajax()) |
1428 | { |
1429 | $message .= '<br /><br />' . $user->lang('RETURN_' . strtoupper($mode), '<a href="' . $redirect_url . '">', '</a>'); |
1430 | } |
1431 | meta_refresh(3, $redirect_url); |
1432 | trigger_error($message); |
1433 | } |
1434 | else |
1435 | { |
1436 | $s_hidden_fields = array( |
1437 | 'uid' => $user->data['user_id'], |
1438 | 'watch' => $mode, |
1439 | 'start' => $start, |
1440 | 'f' => $forum_id, |
1441 | ); |
1442 | if ($mode != 'forum') |
1443 | { |
1444 | $s_hidden_fields['t'] = $topic_id; |
1445 | } |
1446 | |
1447 | $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title)); |
1448 | confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields)); |
1449 | } |
1450 | } |
1451 | else |
1452 | { |
1453 | $is_watching = 0; |
1454 | } |
1455 | } |
1456 | } |
1457 | else |
1458 | { |
1459 | if ((isset($_GET['unwatch']) && $request->variable('unwatch', '', false, \phpbb\request\request_interface::GET) == $mode) || |
1460 | (isset($_GET['watch']) && $request->variable('watch', '', false, \phpbb\request\request_interface::GET) == $mode)) |
1461 | { |
1462 | login_box(); |
1463 | } |
1464 | else |
1465 | { |
1466 | $can_watch = 0; |
1467 | $is_watching = 0; |
1468 | } |
1469 | } |
1470 | |
1471 | if ($can_watch) |
1472 | { |
1473 | $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id")); |
1474 | $s_watching['link_toggle'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . ((!$is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id")); |
1475 | $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; |
1476 | $s_watching['title_toggle'] = $user->lang[((!$is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)]; |
1477 | $s_watching['is_watching'] = $is_watching; |
1478 | } |
1479 | } |
1480 | |
1481 | /** |
1482 | * Get user rank title and image |
1483 | * |
1484 | * @param array $user_data the current stored users data |
1485 | * @param int|false $user_posts the users number of posts or false if guest |
1486 | * |
1487 | * @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src) |
1488 | * |
1489 | * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false |
1490 | */ |
1491 | function phpbb_get_user_rank($user_data, $user_posts) |
1492 | { |
1493 | global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher; |
1494 | |
1495 | $user_rank_data = array( |
1496 | 'title' => null, |
1497 | 'img' => null, |
1498 | 'img_src' => null, |
1499 | ); |
1500 | |
1501 | /** |
1502 | * Preparing a user's rank before displaying |
1503 | * |
1504 | * @event core.modify_user_rank |
1505 | * @var array user_data Array with user's data |
1506 | * @var int user_posts User_posts to change |
1507 | * @since 3.1.0-RC4 |
1508 | */ |
1509 | |
1510 | $vars = array('user_data', 'user_posts'); |
1511 | extract($phpbb_dispatcher->trigger_event('core.modify_user_rank', compact($vars))); |
1512 | |
1513 | if (empty($ranks)) |
1514 | { |
1515 | global $cache; |
1516 | $ranks = $cache->obtain_ranks(); |
1517 | } |
1518 | |
1519 | if (!empty($user_data['user_rank'])) |
1520 | { |
1521 | |
1522 | $user_rank_data['title'] = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : ''; |
1523 | |
1524 | $user_rank_data['img_src'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : ''; |
1525 | |
1526 | $user_rank_data['img'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" />' : ''; |
1527 | } |
1528 | else if ($user_posts !== false) |
1529 | { |
1530 | if (!empty($ranks['normal'])) |
1531 | { |
1532 | foreach ($ranks['normal'] as $rank) |
1533 | { |
1534 | if ($user_posts >= $rank['rank_min']) |
1535 | { |
1536 | $user_rank_data['title'] = $rank['rank_title']; |
1537 | $user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image']) : ''; |
1538 | $user_rank_data['img'] = (!empty($rank['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : ''; |
1539 | break; |
1540 | } |
1541 | } |
1542 | } |
1543 | } |
1544 | |
1545 | /** |
1546 | * Modify a user's rank before displaying |
1547 | * |
1548 | * @event core.get_user_rank_after |
1549 | * @var array user_data Array with user's data |
1550 | * @var int user_posts User_posts to change |
1551 | * @var array user_rank_data User rank data |
1552 | * @since 3.1.11-RC1 |
1553 | */ |
1554 | |
1555 | $vars = array( |
1556 | 'user_data', |
1557 | 'user_posts', |
1558 | 'user_rank_data', |
1559 | ); |
1560 | extract($phpbb_dispatcher->trigger_event('core.get_user_rank_after', compact($vars))); |
1561 | |
1562 | return $user_rank_data; |
1563 | } |
1564 | |
1565 | /** |
1566 | * Prepare profile data |
1567 | */ |
1568 | function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false, $check_can_receive_pm = true) |
1569 | { |
1570 | global $config, $auth, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher, $phpbb_container; |
1571 | |
1572 | $username = $data['username']; |
1573 | $user_id = $data['user_id']; |
1574 | |
1575 | $user_rank_data = phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts'])); |
1576 | |
1577 | if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) |
1578 | { |
1579 | $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']); |
1580 | } |
1581 | else |
1582 | { |
1583 | $email = ''; |
1584 | } |
1585 | |
1586 | if ($config['load_onlinetrack']) |
1587 | { |
1588 | $update_time = $config['load_online_time'] * 60; |
1589 | $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false; |
1590 | } |
1591 | else |
1592 | { |
1593 | $online = false; |
1594 | } |
1595 | |
1596 | if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline')) |
1597 | { |
1598 | $last_active = $data['user_last_active'] ?: ($data['session_time'] ?? 0); |
1599 | } |
1600 | else |
1601 | { |
1602 | $last_active = ''; |
1603 | } |
1604 | |
1605 | $age = ''; |
1606 | |
1607 | if ($config['allow_birthdays'] && $data['user_birthday']) |
1608 | { |
1609 | list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday'])); |
1610 | |
1611 | if ($bday_year) |
1612 | { |
1613 | $now = $user->create_datetime(); |
1614 | $now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset()); |
1615 | |
1616 | $diff = $now['mon'] - $bday_month; |
1617 | if ($diff == 0) |
1618 | { |
1619 | $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0; |
1620 | } |
1621 | else |
1622 | { |
1623 | $diff = ($diff < 0) ? 1 : 0; |
1624 | } |
1625 | |
1626 | $age = max(0, (int) ($now['year'] - $bday_year - $diff)); |
1627 | } |
1628 | } |
1629 | |
1630 | if (!function_exists('phpbb_get_banned_user_ids')) |
1631 | { |
1632 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
1633 | } |
1634 | |
1635 | /** @var \phpbb\ban\manager $ban_manager */ |
1636 | $ban_manager = $phpbb_container->get('ban.manager'); |
1637 | $user_banned = $ban_manager->check($data); |
1638 | |
1639 | // Can this user receive a Private Message? |
1640 | $can_receive_pm = $check_can_receive_pm && ( |
1641 | // They must be a "normal" user |
1642 | $data['user_type'] != USER_IGNORE && |
1643 | |
1644 | // They must not be deactivated by the administrator |
1645 | ($data['user_type'] != USER_INACTIVE || $data['user_inactive_reason'] != INACTIVE_MANUAL) && |
1646 | |
1647 | // They must be able to read PMs |
1648 | count($auth->acl_get_list($user_id, 'u_readpm')) && |
1649 | |
1650 | // They must not be permanently banned |
1651 | (empty($user_banned) || $user_banned['end'] > 0) && |
1652 | |
1653 | // They must allow users to contact via PM |
1654 | (($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) || $data['user_allow_pm']) |
1655 | ); |
1656 | |
1657 | /** @var \phpbb\avatar\helper $avatar_helper */ |
1658 | $avatar_helper = $phpbb_container->get('avatar.helper'); |
1659 | |
1660 | $avatar = $avatar_helper->get_user_avatar($data); |
1661 | $avatar_vars = $avatar_helper->get_template_vars($avatar); |
1662 | |
1663 | // Dump it out to the template |
1664 | $template_data = array_merge($avatar_vars, [ |
1665 | 'AGE' => $age, |
1666 | 'RANK_TITLE' => $user_rank_data['title'], |
1667 | 'JOINED' => $user->format_date($data['user_regdate']), |
1668 | 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active), |
1669 | 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0, |
1670 | 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0, |
1671 | |
1672 | 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $data['user_colour']), |
1673 | 'USERNAME' => get_username_string('username', $user_id, $username, $data['user_colour']), |
1674 | 'USER_COLOR' => get_username_string('colour', $user_id, $username, $data['user_colour']), |
1675 | 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $data['user_colour']), |
1676 | |
1677 | 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])), |
1678 | |
1679 | 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), |
1680 | 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, |
1681 | 'RANK_IMG' => $user_rank_data['img'], |
1682 | 'RANK_IMG_SRC' => $user_rank_data['img_src'], |
1683 | 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false, |
1684 | |
1685 | 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false, |
1686 | |
1687 | 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&sr=posts") : '', |
1688 | 'U_NOTES' => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $user_id) : '', |
1689 | 'U_WARN' => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $user_id) : '', |
1690 | 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && $can_receive_pm) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $user_id) : '', |
1691 | 'U_EMAIL' => $email, |
1692 | 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '', |
1693 | |
1694 | 'USER_JABBER' => ($config['jab_enable'] && $auth->acl_get('u_sendim')) ? $data['user_jabber'] : '', |
1695 | 'USER_JABBER_IMG' => ($config['jab_enable'] && $auth->acl_get('u_sendim') && $data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '', |
1696 | |
1697 | 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $username), |
1698 | 'L_CONTACT_USER' => $user->lang('CONTACT_USER', $username), |
1699 | 'L_VIEWING_PROFILE' => $user->lang('VIEWING_PROFILE', $username), |
1700 | ]); |
1701 | |
1702 | /** |
1703 | * Preparing a user's data before displaying it in profile and memberlist |
1704 | * |
1705 | * @event core.memberlist_prepare_profile_data |
1706 | * @var array data Array with user's data |
1707 | * @var array template_data Template array with user's data |
1708 | * @since 3.1.0-a1 |
1709 | */ |
1710 | $vars = array('data', 'template_data'); |
1711 | extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); |
1712 | |
1713 | return $template_data; |
1714 | } |
1715 | |
1716 | function phpbb_sort_last_active($first, $second) |
1717 | { |
1718 | global $id_cache, $sort_dir; |
1719 | |
1720 | $lesser_than = ($sort_dir === 'd') ? -1 : 1; |
1721 | |
1722 | if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader'])) |
1723 | { |
1724 | return -1; |
1725 | } |
1726 | else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader']) |
1727 | { |
1728 | return 1; |
1729 | } |
1730 | else |
1731 | { |
1732 | return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']); |
1733 | } |
1734 | } |