1 | <?php
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * @package phpBB3
|
---|
5 | * @version $Id$
|
---|
6 | * @copyright (c) 2005 phpBB Group
|
---|
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @ignore
|
---|
13 | */
|
---|
14 | if (!defined('IN_PHPBB'))
|
---|
15 | {
|
---|
16 | exit;
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Display Forums
|
---|
21 | */
|
---|
22 | function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
|
---|
23 | {
|
---|
24 | global $db, $auth, $user, $template;
|
---|
25 | global $phpbb_root_path, $phpEx, $config;
|
---|
26 |
|
---|
27 | $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
|
---|
28 | $parent_id = $visible_forums = 0;
|
---|
29 | $sql_from = '';
|
---|
30 |
|
---|
31 | // Mark forums read?
|
---|
32 | $mark_read = request_var('mark', '');
|
---|
33 |
|
---|
34 | if ($mark_read == 'all')
|
---|
35 | {
|
---|
36 | $mark_read = '';
|
---|
37 | }
|
---|
38 |
|
---|
39 | if (!$root_data)
|
---|
40 | {
|
---|
41 | if ($mark_read == 'forums')
|
---|
42 | {
|
---|
43 | $mark_read = 'all';
|
---|
44 | }
|
---|
45 |
|
---|
46 | $root_data = array('forum_id' => 0);
|
---|
47 | $sql_where = '';
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
|
---|
52 | }
|
---|
53 |
|
---|
54 | // Display list of active topics for this category?
|
---|
55 | $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
|
---|
56 |
|
---|
57 | $sql_array = array(
|
---|
58 | 'SELECT' => 'f.*',
|
---|
59 | 'FROM' => array(
|
---|
60 | FORUMS_TABLE => 'f'
|
---|
61 | ),
|
---|
62 | 'LEFT_JOIN' => array(),
|
---|
63 | );
|
---|
64 |
|
---|
65 | if ($config['load_db_lastread'] && $user->data['is_registered'])
|
---|
66 | {
|
---|
67 | $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');
|
---|
68 | $sql_array['SELECT'] .= ', ft.mark_time';
|
---|
69 | }
|
---|
70 | else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
---|
71 | {
|
---|
72 | $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
|
---|
73 | $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
|
---|
74 |
|
---|
75 | if (!$user->data['is_registered'])
|
---|
76 | {
|
---|
77 | $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | if ($show_active)
|
---|
82 | {
|
---|
83 | $sql_array['LEFT_JOIN'][] = array(
|
---|
84 | 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
|
---|
85 | 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
|
---|
86 | );
|
---|
87 |
|
---|
88 | $sql_array['SELECT'] .= ', fa.user_id';
|
---|
89 | }
|
---|
90 |
|
---|
91 | $sql = $db->sql_build_query('SELECT', array(
|
---|
92 | 'SELECT' => $sql_array['SELECT'],
|
---|
93 | 'FROM' => $sql_array['FROM'],
|
---|
94 | 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
|
---|
95 |
|
---|
96 | 'WHERE' => $sql_where,
|
---|
97 |
|
---|
98 | 'ORDER_BY' => 'f.left_id',
|
---|
99 | ));
|
---|
100 |
|
---|
101 | $result = $db->sql_query($sql);
|
---|
102 |
|
---|
103 | $forum_tracking_info = array();
|
---|
104 | $branch_root_id = $root_data['forum_id'];
|
---|
105 |
|
---|
106 | // Check for unread global announcements (index page only)
|
---|
107 | $ga_unread = false;
|
---|
108 | if ($root_data['forum_id'] == 0)
|
---|
109 | {
|
---|
110 | $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
|
---|
111 |
|
---|
112 | if (!empty($unread_ga_list))
|
---|
113 | {
|
---|
114 | $ga_unread = true;
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | while ($row = $db->sql_fetchrow($result))
|
---|
119 | {
|
---|
120 | $forum_id = $row['forum_id'];
|
---|
121 |
|
---|
122 | // Mark forums read?
|
---|
123 | if ($mark_read == 'forums' || $mark_read == 'all')
|
---|
124 | {
|
---|
125 | if ($auth->acl_get('f_list', $forum_id))
|
---|
126 | {
|
---|
127 | $forum_ids[] = $forum_id;
|
---|
128 | continue;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Category with no members
|
---|
133 | if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
|
---|
134 | {
|
---|
135 | continue;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // Skip branch
|
---|
139 | if (isset($right_id))
|
---|
140 | {
|
---|
141 | if ($row['left_id'] < $right_id)
|
---|
142 | {
|
---|
143 | continue;
|
---|
144 | }
|
---|
145 | unset($right_id);
|
---|
146 | }
|
---|
147 |
|
---|
148 | if (!$auth->acl_get('f_list', $forum_id))
|
---|
149 | {
|
---|
150 | // if the user does not have permissions to list this forum, skip everything until next branch
|
---|
151 | $right_id = $row['right_id'];
|
---|
152 | continue;
|
---|
153 | }
|
---|
154 |
|
---|
155 | $forum_ids[] = $forum_id;
|
---|
156 |
|
---|
157 | if ($config['load_db_lastread'] && $user->data['is_registered'])
|
---|
158 | {
|
---|
159 | $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
|
---|
160 | }
|
---|
161 | else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
---|
162 | {
|
---|
163 | if (!$user->data['is_registered'])
|
---|
164 | {
|
---|
165 | $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
|
---|
166 | }
|
---|
167 | $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'];
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Count the difference of real to public topics, so we can display an information to moderators
|
---|
171 | $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
|
---|
172 | $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
|
---|
173 |
|
---|
174 | // Display active topics from this forum?
|
---|
175 | if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
|
---|
176 | {
|
---|
177 | if (!isset($active_forum_ary['forum_topics']))
|
---|
178 | {
|
---|
179 | $active_forum_ary['forum_topics'] = 0;
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (!isset($active_forum_ary['forum_posts']))
|
---|
183 | {
|
---|
184 | $active_forum_ary['forum_posts'] = 0;
|
---|
185 | }
|
---|
186 |
|
---|
187 | $active_forum_ary['forum_id'][] = $forum_id;
|
---|
188 | $active_forum_ary['enable_icons'][] = $row['enable_icons'];
|
---|
189 | $active_forum_ary['forum_topics'] += $row['forum_topics'];
|
---|
190 | $active_forum_ary['forum_posts'] += $row['forum_posts'];
|
---|
191 |
|
---|
192 | // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
|
---|
193 | if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
|
---|
194 | {
|
---|
195 | $active_forum_ary['exclude_forum_id'][] = $forum_id;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | //
|
---|
200 | if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
|
---|
201 | {
|
---|
202 | if ($row['forum_type'] != FORUM_CAT)
|
---|
203 | {
|
---|
204 | $forum_ids_moderator[] = (int) $forum_id;
|
---|
205 | }
|
---|
206 |
|
---|
207 | // Direct child of current branch
|
---|
208 | $parent_id = $forum_id;
|
---|
209 | $forum_rows[$forum_id] = $row;
|
---|
210 |
|
---|
211 | if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
|
---|
212 | {
|
---|
213 | $branch_root_id = $forum_id;
|
---|
214 | }
|
---|
215 | $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
|
---|
216 | $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
|
---|
217 | }
|
---|
218 | else if ($row['forum_type'] != FORUM_CAT)
|
---|
219 | {
|
---|
220 | $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
|
---|
221 | $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
|
---|
222 | $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
|
---|
223 | $subforums[$parent_id][$forum_id]['children'] = array();
|
---|
224 |
|
---|
225 | if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
|
---|
226 | {
|
---|
227 | $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
|
---|
228 | }
|
---|
229 |
|
---|
230 | if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
|
---|
231 | {
|
---|
232 | $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
|
---|
233 | }
|
---|
234 |
|
---|
235 | $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
|
---|
236 |
|
---|
237 | // Do not list redirects in LINK Forums as Posts.
|
---|
238 | if ($row['forum_type'] != FORUM_LINK)
|
---|
239 | {
|
---|
240 | $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
|
---|
241 | }
|
---|
242 |
|
---|
243 | if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
|
---|
244 | {
|
---|
245 | $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
|
---|
246 | $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
|
---|
247 | $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
|
---|
248 | $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
|
---|
249 | $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
|
---|
250 | $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
|
---|
251 | $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | }
|
---|
255 | $db->sql_freeresult($result);
|
---|
256 |
|
---|
257 | // Handle marking posts
|
---|
258 | if ($mark_read == 'forums' || $mark_read == 'all')
|
---|
259 | {
|
---|
260 | $redirect = build_url(array('mark', 'hash'));
|
---|
261 | $token = request_var('hash', '');
|
---|
262 | if (check_link_hash($token, 'global'))
|
---|
263 | {
|
---|
264 | if ($mark_read == 'all')
|
---|
265 | {
|
---|
266 | markread('all');
|
---|
267 | $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | // Add 0 to forums array to mark global announcements correctly
|
---|
272 | $forum_ids[] = 0;
|
---|
273 | markread('topics', $forum_ids);
|
---|
274 | $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
|
---|
275 | }
|
---|
276 | meta_refresh(3, $redirect);
|
---|
277 | trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
|
---|
278 | }
|
---|
279 | else
|
---|
280 | {
|
---|
281 | $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
|
---|
282 | meta_refresh(3, $redirect);
|
---|
283 | trigger_error($message);
|
---|
284 | }
|
---|
285 |
|
---|
286 | }
|
---|
287 |
|
---|
288 | // Grab moderators ... if necessary
|
---|
289 | if ($display_moderators)
|
---|
290 | {
|
---|
291 | if ($return_moderators)
|
---|
292 | {
|
---|
293 | $forum_ids_moderator[] = $root_data['forum_id'];
|
---|
294 | }
|
---|
295 | get_moderators($forum_moderators, $forum_ids_moderator);
|
---|
296 | }
|
---|
297 |
|
---|
298 | // Used to tell whatever we have to create a dummy category or not.
|
---|
299 | $last_catless = true;
|
---|
300 | foreach ($forum_rows as $row)
|
---|
301 | {
|
---|
302 | // Empty category
|
---|
303 | if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
|
---|
304 | {
|
---|
305 | $template->assign_block_vars('forumrow', array(
|
---|
306 | 'S_IS_CAT' => true,
|
---|
307 | 'FORUM_ID' => $row['forum_id'],
|
---|
308 | 'FORUM_NAME' => $row['forum_name'],
|
---|
309 | 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
|
---|
310 | 'FORUM_FOLDER_IMG' => '',
|
---|
311 | 'FORUM_FOLDER_IMG_SRC' => '',
|
---|
312 | 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
|
---|
313 | 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
|
---|
314 | 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
|
---|
315 | );
|
---|
316 |
|
---|
317 | continue;
|
---|
318 | }
|
---|
319 |
|
---|
320 | $visible_forums++;
|
---|
321 | $forum_id = $row['forum_id'];
|
---|
322 |
|
---|
323 | $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
|
---|
324 |
|
---|
325 | // Mark the first visible forum on index as unread if there's any unread global announcement
|
---|
326 | if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0])
|
---|
327 | {
|
---|
328 | $forum_unread = true;
|
---|
329 | }
|
---|
330 |
|
---|
331 | $folder_image = $folder_alt = $l_subforums = '';
|
---|
332 | $subforums_list = array();
|
---|
333 |
|
---|
334 | // Generate list of subforums if we need to
|
---|
335 | if (isset($subforums[$forum_id]))
|
---|
336 | {
|
---|
337 | foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
|
---|
338 | {
|
---|
339 | $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
|
---|
340 |
|
---|
341 | if (!$subforum_unread && !empty($subforum_row['children']))
|
---|
342 | {
|
---|
343 | foreach ($subforum_row['children'] as $child_id)
|
---|
344 | {
|
---|
345 | if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
|
---|
346 | {
|
---|
347 | // Once we found an unread child forum, we can drop out of this loop
|
---|
348 | $subforum_unread = true;
|
---|
349 | break;
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | if ($subforum_row['display'] && $subforum_row['name'])
|
---|
355 | {
|
---|
356 | $subforums_list[] = array(
|
---|
357 | 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
|
---|
358 | 'name' => $subforum_row['name'],
|
---|
359 | 'unread' => $subforum_unread,
|
---|
360 | );
|
---|
361 | }
|
---|
362 | else
|
---|
363 | {
|
---|
364 | unset($subforums[$forum_id][$subforum_id]);
|
---|
365 | }
|
---|
366 |
|
---|
367 | // If one subforum is unread the forum gets unread too...
|
---|
368 | if ($subforum_unread)
|
---|
369 | {
|
---|
370 | $forum_unread = true;
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
|
---|
375 | $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
|
---|
376 | }
|
---|
377 | else
|
---|
378 | {
|
---|
379 | switch ($row['forum_type'])
|
---|
380 | {
|
---|
381 | case FORUM_POST:
|
---|
382 | $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
|
---|
383 | break;
|
---|
384 |
|
---|
385 | case FORUM_LINK:
|
---|
386 | $folder_image = 'forum_link';
|
---|
387 | break;
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | // Which folder should we display?
|
---|
392 | if ($row['forum_status'] == ITEM_LOCKED)
|
---|
393 | {
|
---|
394 | $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
|
---|
395 | $folder_alt = 'FORUM_LOCKED';
|
---|
396 | }
|
---|
397 | else
|
---|
398 | {
|
---|
399 | $folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
|
---|
400 | }
|
---|
401 |
|
---|
402 | // Create last post link information, if appropriate
|
---|
403 | if ($row['forum_last_post_id'])
|
---|
404 | {
|
---|
405 | $last_post_subject = $row['forum_last_post_subject'];
|
---|
406 | $last_post_time = $user->format_date($row['forum_last_post_time']);
|
---|
407 | $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
|
---|
408 | }
|
---|
409 | else
|
---|
410 | {
|
---|
411 | $last_post_subject = $last_post_time = $last_post_url = '';
|
---|
412 | }
|
---|
413 |
|
---|
414 | // Output moderator listing ... if applicable
|
---|
415 | $l_moderator = $moderators_list = '';
|
---|
416 | if ($display_moderators && !empty($forum_moderators[$forum_id]))
|
---|
417 | {
|
---|
418 | $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
|
---|
419 | $moderators_list = implode(', ', $forum_moderators[$forum_id]);
|
---|
420 | }
|
---|
421 |
|
---|
422 | $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
|
---|
423 | $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
|
---|
424 |
|
---|
425 | $s_subforums_list = array();
|
---|
426 | foreach ($subforums_list as $subforum)
|
---|
427 | {
|
---|
428 | $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['NEW_POSTS'] : $user->lang['NO_NEW_POSTS']) . '">' . $subforum['name'] . '</a>';
|
---|
429 | }
|
---|
430 | $s_subforums_list = (string) implode(', ', $s_subforums_list);
|
---|
431 | $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
|
---|
432 |
|
---|
433 | if ($row['forum_type'] != FORUM_LINK)
|
---|
434 | {
|
---|
435 | $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
|
---|
436 | }
|
---|
437 | else
|
---|
438 | {
|
---|
439 | // If the forum is a link and we count redirects we need to visit it
|
---|
440 | // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
|
---|
441 | if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
|
---|
442 | {
|
---|
443 | $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
|
---|
444 | }
|
---|
445 | else
|
---|
446 | {
|
---|
447 | $u_viewforum = $row['forum_link'];
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | $template->assign_block_vars('forumrow', array(
|
---|
452 | 'S_IS_CAT' => false,
|
---|
453 | 'S_NO_CAT' => $catless && !$last_catless,
|
---|
454 | 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
|
---|
455 | 'S_UNREAD_FORUM' => $forum_unread,
|
---|
456 | 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
|
---|
457 | 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false,
|
---|
458 | 'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false,
|
---|
459 | 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options'])) ? true : false,
|
---|
460 |
|
---|
461 | 'FORUM_ID' => $row['forum_id'],
|
---|
462 | 'FORUM_NAME' => $row['forum_name'],
|
---|
463 | 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
|
---|
464 | 'TOPICS' => $row['forum_topics'],
|
---|
465 | $l_post_click_count => $post_click_count,
|
---|
466 | 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
|
---|
467 | 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
|
---|
468 | 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
|
---|
469 | 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
|
---|
470 | 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
|
---|
471 | 'LAST_POST_SUBJECT' => censor_text($last_post_subject),
|
---|
472 | 'LAST_POST_TIME' => $last_post_time,
|
---|
473 | 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
|
---|
474 | 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
|
---|
475 | 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
|
---|
476 | 'MODERATORS' => $moderators_list,
|
---|
477 | 'SUBFORUMS' => $s_subforums_list,
|
---|
478 |
|
---|
479 | 'L_SUBFORUM_STR' => $l_subforums,
|
---|
480 | 'L_FORUM_FOLDER_ALT' => $folder_alt,
|
---|
481 | 'L_MODERATOR_STR' => $l_moderator,
|
---|
482 |
|
---|
483 | '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']) : '',
|
---|
484 | 'U_VIEWFORUM' => $u_viewforum,
|
---|
485 | 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
|
---|
486 | 'U_LAST_POST' => $last_post_url)
|
---|
487 | );
|
---|
488 |
|
---|
489 | // Assign subforums loop for style authors
|
---|
490 | foreach ($subforums_list as $subforum)
|
---|
491 | {
|
---|
492 | $template->assign_block_vars('forumrow.subforum', array(
|
---|
493 | 'U_SUBFORUM' => $subforum['link'],
|
---|
494 | 'SUBFORUM_NAME' => $subforum['name'],
|
---|
495 | 'S_UNREAD' => $subforum['unread'])
|
---|
496 | );
|
---|
497 | }
|
---|
498 |
|
---|
499 | $last_catless = $catless;
|
---|
500 | }
|
---|
501 |
|
---|
502 | $template->assign_vars(array(
|
---|
503 | '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') : '',
|
---|
504 | 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
|
---|
505 | 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
|
---|
506 | 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
|
---|
507 | 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
|
---|
508 | ));
|
---|
509 |
|
---|
510 | if ($return_moderators)
|
---|
511 | {
|
---|
512 | return array($active_forum_ary, $forum_moderators);
|
---|
513 | }
|
---|
514 |
|
---|
515 | return array($active_forum_ary, array());
|
---|
516 | }
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * Create forum rules for given forum
|
---|
520 | */
|
---|
521 | function generate_forum_rules(&$forum_data)
|
---|
522 | {
|
---|
523 | if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
|
---|
524 | {
|
---|
525 | return;
|
---|
526 | }
|
---|
527 |
|
---|
528 | global $template, $phpbb_root_path, $phpEx;
|
---|
529 |
|
---|
530 | if ($forum_data['forum_rules'])
|
---|
531 | {
|
---|
532 | $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']);
|
---|
533 | }
|
---|
534 |
|
---|
535 | $template->assign_vars(array(
|
---|
536 | 'S_FORUM_RULES' => true,
|
---|
537 | 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
|
---|
538 | 'FORUM_RULES' => $forum_data['forum_rules'])
|
---|
539 | );
|
---|
540 | }
|
---|
541 |
|
---|
542 | /**
|
---|
543 | * Create forum navigation links for given forum, create parent
|
---|
544 | * list if currently null, assign basic forum info to template
|
---|
545 | */
|
---|
546 | function generate_forum_nav(&$forum_data)
|
---|
547 | {
|
---|
548 | global $db, $user, $template, $auth, $config;
|
---|
549 | global $phpEx, $phpbb_root_path;
|
---|
550 |
|
---|
551 | if (!$auth->acl_get('f_list', $forum_data['forum_id']))
|
---|
552 | {
|
---|
553 | return;
|
---|
554 | }
|
---|
555 |
|
---|
556 | // Get forum parents
|
---|
557 | $forum_parents = get_forum_parents($forum_data);
|
---|
558 |
|
---|
559 | // Build navigation links
|
---|
560 | if (!empty($forum_parents))
|
---|
561 | {
|
---|
562 | foreach ($forum_parents as $parent_forum_id => $parent_data)
|
---|
563 | {
|
---|
564 | list($parent_name, $parent_type) = array_values($parent_data);
|
---|
565 |
|
---|
566 | // Skip this parent if the user does not have the permission to view it
|
---|
567 | if (!$auth->acl_get('f_list', $parent_forum_id))
|
---|
568 | {
|
---|
569 | continue;
|
---|
570 | }
|
---|
571 |
|
---|
572 | $template->assign_block_vars('navlinks', array(
|
---|
573 | 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
|
---|
574 | 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
|
---|
575 | 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
|
---|
576 | 'FORUM_NAME' => $parent_name,
|
---|
577 | 'FORUM_ID' => $parent_forum_id,
|
---|
578 | 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
|
---|
579 | );
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | $template->assign_block_vars('navlinks', array(
|
---|
584 | 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
|
---|
585 | 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
|
---|
586 | 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
|
---|
587 | 'FORUM_NAME' => $forum_data['forum_name'],
|
---|
588 | 'FORUM_ID' => $forum_data['forum_id'],
|
---|
589 | 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
|
---|
590 | );
|
---|
591 |
|
---|
592 | $template->assign_vars(array(
|
---|
593 | 'FORUM_ID' => $forum_data['forum_id'],
|
---|
594 | 'FORUM_NAME' => $forum_data['forum_name'],
|
---|
595 | 'FORUM_DESC' => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']),
|
---|
596 |
|
---|
597 | 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
|
---|
598 | ));
|
---|
599 |
|
---|
600 | return;
|
---|
601 | }
|
---|
602 |
|
---|
603 | /**
|
---|
604 | * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
|
---|
605 | */
|
---|
606 | function get_forum_parents(&$forum_data)
|
---|
607 | {
|
---|
608 | global $db;
|
---|
609 |
|
---|
610 | $forum_parents = array();
|
---|
611 |
|
---|
612 | if ($forum_data['parent_id'] > 0)
|
---|
613 | {
|
---|
614 | if ($forum_data['forum_parents'] == '')
|
---|
615 | {
|
---|
616 | $sql = 'SELECT forum_id, forum_name, forum_type
|
---|
617 | FROM ' . FORUMS_TABLE . '
|
---|
618 | WHERE left_id < ' . $forum_data['left_id'] . '
|
---|
619 | AND right_id > ' . $forum_data['right_id'] . '
|
---|
620 | ORDER BY left_id ASC';
|
---|
621 | $result = $db->sql_query($sql);
|
---|
622 |
|
---|
623 | while ($row = $db->sql_fetchrow($result))
|
---|
624 | {
|
---|
625 | $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
|
---|
626 | }
|
---|
627 | $db->sql_freeresult($result);
|
---|
628 |
|
---|
629 | $forum_data['forum_parents'] = serialize($forum_parents);
|
---|
630 |
|
---|
631 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
---|
632 | SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
|
---|
633 | WHERE parent_id = " . $forum_data['parent_id'];
|
---|
634 | $db->sql_query($sql);
|
---|
635 | }
|
---|
636 | else
|
---|
637 | {
|
---|
638 | $forum_parents = unserialize($forum_data['forum_parents']);
|
---|
639 | }
|
---|
640 | }
|
---|
641 |
|
---|
642 | return $forum_parents;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /**
|
---|
646 | * Generate topic pagination
|
---|
647 | */
|
---|
648 | function topic_generate_pagination($replies, $url)
|
---|
649 | {
|
---|
650 | global $config, $user;
|
---|
651 |
|
---|
652 | // Make sure $per_page is a valid value
|
---|
653 | $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
|
---|
654 |
|
---|
655 | if (($replies + 1) > $per_page)
|
---|
656 | {
|
---|
657 | $total_pages = ceil(($replies + 1) / $per_page);
|
---|
658 | $pagination = '';
|
---|
659 |
|
---|
660 | $times = 1;
|
---|
661 | for ($j = 0; $j < $replies + 1; $j += $per_page)
|
---|
662 | {
|
---|
663 | $pagination .= '<a href="' . $url . '&start=' . $j . '">' . $times . '</a>';
|
---|
664 | if ($times == 1 && $total_pages > 5)
|
---|
665 | {
|
---|
666 | $pagination .= ' ... ';
|
---|
667 |
|
---|
668 | // Display the last three pages
|
---|
669 | $times = $total_pages - 3;
|
---|
670 | $j += ($total_pages - 4) * $per_page;
|
---|
671 | }
|
---|
672 | else if ($times < $total_pages)
|
---|
673 | {
|
---|
674 | $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
|
---|
675 | }
|
---|
676 | $times++;
|
---|
677 | }
|
---|
678 | }
|
---|
679 | else
|
---|
680 | {
|
---|
681 | $pagination = '';
|
---|
682 | }
|
---|
683 |
|
---|
684 | return $pagination;
|
---|
685 | }
|
---|
686 |
|
---|
687 | /**
|
---|
688 | * Obtain list of moderators of each forum
|
---|
689 | */
|
---|
690 | function get_moderators(&$forum_moderators, $forum_id = false)
|
---|
691 | {
|
---|
692 | global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
|
---|
693 |
|
---|
694 | $forum_id_ary = array();
|
---|
695 |
|
---|
696 | if ($forum_id !== false)
|
---|
697 | {
|
---|
698 | if (!is_array($forum_id))
|
---|
699 | {
|
---|
700 | $forum_id = array($forum_id);
|
---|
701 | }
|
---|
702 |
|
---|
703 | // Exchange key/value pair to be able to faster check for the forum id existence
|
---|
704 | $forum_id_ary = array_flip($forum_id);
|
---|
705 | }
|
---|
706 |
|
---|
707 | $sql_array = array(
|
---|
708 | 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
|
---|
709 |
|
---|
710 | 'FROM' => array(
|
---|
711 | MODERATOR_CACHE_TABLE => 'm',
|
---|
712 | ),
|
---|
713 |
|
---|
714 | 'LEFT_JOIN' => array(
|
---|
715 | array(
|
---|
716 | 'FROM' => array(USERS_TABLE => 'u'),
|
---|
717 | 'ON' => 'm.user_id = u.user_id',
|
---|
718 | ),
|
---|
719 | array(
|
---|
720 | 'FROM' => array(GROUPS_TABLE => 'g'),
|
---|
721 | 'ON' => 'm.group_id = g.group_id',
|
---|
722 | ),
|
---|
723 | ),
|
---|
724 |
|
---|
725 | 'WHERE' => 'm.display_on_index = 1',
|
---|
726 | );
|
---|
727 |
|
---|
728 | // We query every forum here because for caching we should not have any parameter.
|
---|
729 | $sql = $db->sql_build_query('SELECT', $sql_array);
|
---|
730 | $result = $db->sql_query($sql, 3600);
|
---|
731 |
|
---|
732 | while ($row = $db->sql_fetchrow($result))
|
---|
733 | {
|
---|
734 | $f_id = (int) $row['forum_id'];
|
---|
735 |
|
---|
736 | if (!isset($forum_id_ary[$f_id]))
|
---|
737 | {
|
---|
738 | continue;
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (!empty($row['user_id']))
|
---|
742 | {
|
---|
743 | $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
|
---|
744 | }
|
---|
745 | else
|
---|
746 | {
|
---|
747 | $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
|
---|
748 |
|
---|
749 | if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
|
---|
750 | {
|
---|
751 | $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
|
---|
752 | }
|
---|
753 | else
|
---|
754 | {
|
---|
755 | $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>';
|
---|
756 | }
|
---|
757 | }
|
---|
758 | }
|
---|
759 | $db->sql_freeresult($result);
|
---|
760 |
|
---|
761 | return;
|
---|
762 | }
|
---|
763 |
|
---|
764 | /**
|
---|
765 | * User authorisation levels output
|
---|
766 | *
|
---|
767 | * @param string $mode Can be forum or topic. Not in use at the moment.
|
---|
768 | * @param int $forum_id The current forum the user is in.
|
---|
769 | * @param int $forum_status The forums status bit.
|
---|
770 | */
|
---|
771 | function gen_forum_auth_level($mode, $forum_id, $forum_status)
|
---|
772 | {
|
---|
773 | global $template, $auth, $user, $config;
|
---|
774 |
|
---|
775 | $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
|
---|
776 |
|
---|
777 | $rules = array(
|
---|
778 | ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
|
---|
779 | ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
|
---|
780 | ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
|
---|
781 | ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
|
---|
782 | );
|
---|
783 |
|
---|
784 | if ($config['allow_attachments'])
|
---|
785 | {
|
---|
786 | $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
|
---|
787 | }
|
---|
788 |
|
---|
789 | foreach ($rules as $rule)
|
---|
790 | {
|
---|
791 | $template->assign_block_vars('rules', array('RULE' => $rule));
|
---|
792 | }
|
---|
793 |
|
---|
794 | return;
|
---|
795 | }
|
---|
796 |
|
---|
797 | /**
|
---|
798 | * Generate topic status
|
---|
799 | */
|
---|
800 | function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
|
---|
801 | {
|
---|
802 | global $user, $config;
|
---|
803 |
|
---|
804 | $folder = $folder_new = '';
|
---|
805 |
|
---|
806 | if ($topic_row['topic_status'] == ITEM_MOVED)
|
---|
807 | {
|
---|
808 | $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
|
---|
809 | $folder_img = 'topic_moved';
|
---|
810 | $folder_alt = 'TOPIC_MOVED';
|
---|
811 | }
|
---|
812 | else
|
---|
813 | {
|
---|
814 | switch ($topic_row['topic_type'])
|
---|
815 | {
|
---|
816 | case POST_GLOBAL:
|
---|
817 | $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
|
---|
818 | $folder = 'global_read';
|
---|
819 | $folder_new = 'global_unread';
|
---|
820 | break;
|
---|
821 |
|
---|
822 | case POST_ANNOUNCE:
|
---|
823 | $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
|
---|
824 | $folder = 'announce_read';
|
---|
825 | $folder_new = 'announce_unread';
|
---|
826 | break;
|
---|
827 |
|
---|
828 | case POST_STICKY:
|
---|
829 | $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
|
---|
830 | $folder = 'sticky_read';
|
---|
831 | $folder_new = 'sticky_unread';
|
---|
832 | break;
|
---|
833 |
|
---|
834 | default:
|
---|
835 | $topic_type = '';
|
---|
836 | $folder = 'topic_read';
|
---|
837 | $folder_new = 'topic_unread';
|
---|
838 |
|
---|
839 | // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
|
---|
840 | if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
|
---|
841 | {
|
---|
842 | $folder .= '_hot';
|
---|
843 | $folder_new .= '_hot';
|
---|
844 | }
|
---|
845 | break;
|
---|
846 | }
|
---|
847 |
|
---|
848 | if ($topic_row['topic_status'] == ITEM_LOCKED)
|
---|
849 | {
|
---|
850 | $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
|
---|
851 | $folder .= '_locked';
|
---|
852 | $folder_new .= '_locked';
|
---|
853 | }
|
---|
854 |
|
---|
855 |
|
---|
856 | $folder_img = ($unread_topic) ? $folder_new : $folder;
|
---|
857 | $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
|
---|
858 |
|
---|
859 | // Posted image?
|
---|
860 | if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
|
---|
861 | {
|
---|
862 | $folder_img .= '_mine';
|
---|
863 | }
|
---|
864 | }
|
---|
865 |
|
---|
866 | if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
|
---|
867 | {
|
---|
868 | $topic_type = $user->lang['VIEW_TOPIC_POLL'];
|
---|
869 | }
|
---|
870 | }
|
---|
871 |
|
---|
872 | /**
|
---|
873 | * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
|
---|
874 | * The custom bbcodes buttons will be placed within the template block 'custom_codes'
|
---|
875 | */
|
---|
876 | function display_custom_bbcodes()
|
---|
877 | {
|
---|
878 | global $db, $template, $user;
|
---|
879 |
|
---|
880 | // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
|
---|
881 | $num_predefined_bbcodes = 22;
|
---|
882 |
|
---|
883 | $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
|
---|
884 | FROM ' . BBCODES_TABLE . '
|
---|
885 | WHERE display_on_posting = 1
|
---|
886 | ORDER BY bbcode_tag';
|
---|
887 | $result = $db->sql_query($sql);
|
---|
888 |
|
---|
889 | $i = 0;
|
---|
890 | while ($row = $db->sql_fetchrow($result))
|
---|
891 | {
|
---|
892 | // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
|
---|
893 | if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
|
---|
894 | {
|
---|
895 | $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
|
---|
896 | }
|
---|
897 |
|
---|
898 | $template->assign_block_vars('custom_tags', array(
|
---|
899 | 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
|
---|
900 | 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
|
---|
901 | 'BBCODE_TAG' => $row['bbcode_tag'],
|
---|
902 | 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
|
---|
903 | 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
|
---|
904 | ));
|
---|
905 |
|
---|
906 | $i++;
|
---|
907 | }
|
---|
908 | $db->sql_freeresult($result);
|
---|
909 | }
|
---|
910 |
|
---|
911 | /**
|
---|
912 | * Display reasons
|
---|
913 | */
|
---|
914 | function display_reasons($reason_id = 0)
|
---|
915 | {
|
---|
916 | global $db, $user, $template;
|
---|
917 |
|
---|
918 | $sql = 'SELECT *
|
---|
919 | FROM ' . REPORTS_REASONS_TABLE . '
|
---|
920 | ORDER BY reason_order ASC';
|
---|
921 | $result = $db->sql_query($sql);
|
---|
922 |
|
---|
923 | while ($row = $db->sql_fetchrow($result))
|
---|
924 | {
|
---|
925 | // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
|
---|
926 | if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
|
---|
927 | {
|
---|
928 | $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
|
---|
929 | $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
|
---|
930 | }
|
---|
931 |
|
---|
932 | $template->assign_block_vars('reason', array(
|
---|
933 | 'ID' => $row['reason_id'],
|
---|
934 | 'TITLE' => $row['reason_title'],
|
---|
935 | 'DESCRIPTION' => $row['reason_description'],
|
---|
936 | 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
|
---|
937 | );
|
---|
938 | }
|
---|
939 | $db->sql_freeresult($result);
|
---|
940 | }
|
---|
941 |
|
---|
942 | /**
|
---|
943 | * Display user activity (action forum/topic)
|
---|
944 | */
|
---|
945 | function display_user_activity(&$userdata)
|
---|
946 | {
|
---|
947 | global $auth, $template, $db, $user;
|
---|
948 | global $phpbb_root_path, $phpEx;
|
---|
949 |
|
---|
950 | // Do not display user activity for users having more than 5000 posts...
|
---|
951 | if ($userdata['user_posts'] > 5000)
|
---|
952 | {
|
---|
953 | return;
|
---|
954 | }
|
---|
955 |
|
---|
956 | $forum_ary = array();
|
---|
957 |
|
---|
958 | // Do not include those forums the user is not having read access to...
|
---|
959 | $forum_read_ary = $auth->acl_getf('!f_read');
|
---|
960 |
|
---|
961 | foreach ($forum_read_ary as $forum_id => $not_allowed)
|
---|
962 | {
|
---|
963 | if ($not_allowed['f_read'])
|
---|
964 | {
|
---|
965 | $forum_ary[] = (int) $forum_id;
|
---|
966 | }
|
---|
967 | }
|
---|
968 |
|
---|
969 | $forum_ary = array_unique($forum_ary);
|
---|
970 | $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
|
---|
971 |
|
---|
972 | // Obtain active forum
|
---|
973 | $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
|
---|
974 | FROM ' . POSTS_TABLE . '
|
---|
975 | WHERE poster_id = ' . $userdata['user_id'] . "
|
---|
976 | AND post_postcount = 1
|
---|
977 | $forum_sql
|
---|
978 | GROUP BY forum_id
|
---|
979 | ORDER BY num_posts DESC";
|
---|
980 | $result = $db->sql_query_limit($sql, 1);
|
---|
981 | $active_f_row = $db->sql_fetchrow($result);
|
---|
982 | $db->sql_freeresult($result);
|
---|
983 |
|
---|
984 | if (!empty($active_f_row))
|
---|
985 | {
|
---|
986 | $sql = 'SELECT forum_name
|
---|
987 | FROM ' . FORUMS_TABLE . '
|
---|
988 | WHERE forum_id = ' . $active_f_row['forum_id'];
|
---|
989 | $result = $db->sql_query($sql, 3600);
|
---|
990 | $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
|
---|
991 | $db->sql_freeresult($result);
|
---|
992 | }
|
---|
993 |
|
---|
994 | // Obtain active topic
|
---|
995 | $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
|
---|
996 | FROM ' . POSTS_TABLE . '
|
---|
997 | WHERE poster_id = ' . $userdata['user_id'] . "
|
---|
998 | AND post_postcount = 1
|
---|
999 | $forum_sql
|
---|
1000 | GROUP BY topic_id
|
---|
1001 | ORDER BY num_posts DESC";
|
---|
1002 | $result = $db->sql_query_limit($sql, 1);
|
---|
1003 | $active_t_row = $db->sql_fetchrow($result);
|
---|
1004 | $db->sql_freeresult($result);
|
---|
1005 |
|
---|
1006 | if (!empty($active_t_row))
|
---|
1007 | {
|
---|
1008 | $sql = 'SELECT topic_title
|
---|
1009 | FROM ' . TOPICS_TABLE . '
|
---|
1010 | WHERE topic_id = ' . $active_t_row['topic_id'];
|
---|
1011 | $result = $db->sql_query($sql);
|
---|
1012 | $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
|
---|
1013 | $db->sql_freeresult($result);
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | $userdata['active_t_row'] = $active_t_row;
|
---|
1017 | $userdata['active_f_row'] = $active_f_row;
|
---|
1018 |
|
---|
1019 | $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
|
---|
1020 | if (!empty($active_f_row['num_posts']))
|
---|
1021 | {
|
---|
1022 | $active_f_name = $active_f_row['forum_name'];
|
---|
1023 | $active_f_id = $active_f_row['forum_id'];
|
---|
1024 | $active_f_count = $active_f_row['num_posts'];
|
---|
1025 | $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
|
---|
1029 | if (!empty($active_t_row['num_posts']))
|
---|
1030 | {
|
---|
1031 | $active_t_name = $active_t_row['topic_title'];
|
---|
1032 | $active_t_id = $active_t_row['topic_id'];
|
---|
1033 | $active_t_count = $active_t_row['num_posts'];
|
---|
1034 | $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | $l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE'];
|
---|
1038 |
|
---|
1039 | $template->assign_vars(array(
|
---|
1040 | 'ACTIVE_FORUM' => $active_f_name,
|
---|
1041 | 'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
|
---|
1042 | 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
|
---|
1043 | 'ACTIVE_TOPIC' => censor_text($active_t_name),
|
---|
1044 | 'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
|
---|
1045 | 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
|
---|
1046 | 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
|
---|
1047 | 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
|
---|
1048 | 'S_SHOW_ACTIVITY' => true)
|
---|
1049 | );
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | /**
|
---|
1053 | * Topic and forum watching common code
|
---|
1054 | */
|
---|
1055 | function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
|
---|
1056 | {
|
---|
1057 | global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
|
---|
1058 |
|
---|
1059 | $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
|
---|
1060 | $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
|
---|
1061 | $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
|
---|
1062 | $u_url = "uid={$user->data['user_id']}";
|
---|
1063 | $u_url .= ($mode == 'forum') ? '&f' : '&f=' . $forum_id . '&t';
|
---|
1064 |
|
---|
1065 | // Is user watching this thread?
|
---|
1066 | if ($user_id != ANONYMOUS)
|
---|
1067 | {
|
---|
1068 | $can_watch = true;
|
---|
1069 |
|
---|
1070 | if ($notify_status == 'unset')
|
---|
1071 | {
|
---|
1072 | $sql = "SELECT notify_status
|
---|
1073 | FROM $table_sql
|
---|
1074 | WHERE $where_sql = $match_id
|
---|
1075 | AND user_id = $user_id";
|
---|
1076 | $result = $db->sql_query($sql);
|
---|
1077 |
|
---|
1078 | $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
|
---|
1079 | $db->sql_freeresult($result);
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | if (!is_null($notify_status) && $notify_status !== '')
|
---|
1083 | {
|
---|
1084 |
|
---|
1085 | if (isset($_GET['unwatch']))
|
---|
1086 | {
|
---|
1087 | $uid = request_var('uid', 0);
|
---|
1088 | if ($uid != $user_id)
|
---|
1089 | {
|
---|
1090 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
|
---|
1091 | $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
|
---|
1092 | trigger_error($message);
|
---|
1093 | }
|
---|
1094 | if ($_GET['unwatch'] == $mode)
|
---|
1095 | {
|
---|
1096 | $is_watching = 0;
|
---|
1097 |
|
---|
1098 | $sql = 'DELETE FROM ' . $table_sql . "
|
---|
1099 | WHERE $where_sql = $match_id
|
---|
1100 | AND user_id = $user_id";
|
---|
1101 | $db->sql_query($sql);
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
|
---|
1105 |
|
---|
1106 | meta_refresh(3, $redirect_url);
|
---|
1107 |
|
---|
1108 | $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
|
---|
1109 | trigger_error($message);
|
---|
1110 | }
|
---|
1111 | else
|
---|
1112 | {
|
---|
1113 | $is_watching = true;
|
---|
1114 |
|
---|
1115 | if ($notify_status)
|
---|
1116 | {
|
---|
1117 | $sql = 'UPDATE ' . $table_sql . "
|
---|
1118 | SET notify_status = 0
|
---|
1119 | WHERE $where_sql = $match_id
|
---|
1120 | AND user_id = $user_id";
|
---|
1121 | $db->sql_query($sql);
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 | else
|
---|
1126 | {
|
---|
1127 | if (isset($_GET['watch']))
|
---|
1128 | {
|
---|
1129 | $token = request_var('hash', '');
|
---|
1130 | $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
|
---|
1131 |
|
---|
1132 | if ($_GET['watch'] == $mode && check_link_hash($token, "{$mode}_$match_id"))
|
---|
1133 | {
|
---|
1134 | $is_watching = true;
|
---|
1135 |
|
---|
1136 | $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
|
---|
1137 | VALUES ($user_id, $match_id, 0)";
|
---|
1138 | $db->sql_query($sql);
|
---|
1139 | $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
|
---|
1140 | }
|
---|
1141 | else
|
---|
1142 | {
|
---|
1143 | $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | meta_refresh(3, $redirect_url);
|
---|
1147 |
|
---|
1148 | trigger_error($message);
|
---|
1149 | }
|
---|
1150 | else
|
---|
1151 | {
|
---|
1152 | $is_watching = 0;
|
---|
1153 | }
|
---|
1154 | }
|
---|
1155 | }
|
---|
1156 | else
|
---|
1157 | {
|
---|
1158 | if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
|
---|
1159 | {
|
---|
1160 | login_box();
|
---|
1161 | }
|
---|
1162 | else
|
---|
1163 | {
|
---|
1164 | $can_watch = 0;
|
---|
1165 | $is_watching = 0;
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | if ($can_watch)
|
---|
1170 | {
|
---|
1171 | $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"));
|
---|
1172 | $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
|
---|
1173 | $s_watching['is_watching'] = $is_watching;
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | return;
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | /**
|
---|
1180 | * Get user rank title and image
|
---|
1181 | *
|
---|
1182 | * @param int $user_rank the current stored users rank id
|
---|
1183 | * @param int $user_posts the users number of posts
|
---|
1184 | * @param string &$rank_title the rank title will be stored here after execution
|
---|
1185 | * @param string &$rank_img the rank image as full img tag is stored here after execution
|
---|
1186 | * @param string &$rank_img_src the rank image source is stored here after execution
|
---|
1187 | *
|
---|
1188 | * 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
|
---|
1189 | */
|
---|
1190 | function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
|
---|
1191 | {
|
---|
1192 | global $ranks, $config, $phpbb_root_path;
|
---|
1193 |
|
---|
1194 | if (empty($ranks))
|
---|
1195 | {
|
---|
1196 | global $cache;
|
---|
1197 | $ranks = $cache->obtain_ranks();
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | if (!empty($user_rank))
|
---|
1201 | {
|
---|
1202 | $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
|
---|
1203 | $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
|
---|
1204 | $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
|
---|
1205 | }
|
---|
1206 | else if ($user_posts !== false)
|
---|
1207 | {
|
---|
1208 | if (!empty($ranks['normal']))
|
---|
1209 | {
|
---|
1210 | foreach ($ranks['normal'] as $rank)
|
---|
1211 | {
|
---|
1212 | if ($user_posts >= $rank['rank_min'])
|
---|
1213 | {
|
---|
1214 | $rank_title = $rank['rank_title'];
|
---|
1215 | $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
|
---|
1216 | $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
|
---|
1217 | break;
|
---|
1218 | }
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 | }
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | /**
|
---|
1225 | * Get user avatar
|
---|
1226 | *
|
---|
1227 | * @param string $avatar Users assigned avatar name
|
---|
1228 | * @param int $avatar_type Type of avatar
|
---|
1229 | * @param string $avatar_width Width of users avatar
|
---|
1230 | * @param string $avatar_height Height of users avatar
|
---|
1231 | * @param string $alt Optional language string for alt tag within image, can be a language key or text
|
---|
1232 | * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
|
---|
1233 | *
|
---|
1234 | * @return string Avatar image
|
---|
1235 | */
|
---|
1236 | function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
|
---|
1237 | {
|
---|
1238 | global $user, $config, $phpbb_root_path, $phpEx;
|
---|
1239 |
|
---|
1240 | if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
|
---|
1241 | {
|
---|
1242 | return '';
|
---|
1243 | }
|
---|
1244 |
|
---|
1245 | $avatar_img = '';
|
---|
1246 |
|
---|
1247 | switch ($avatar_type)
|
---|
1248 | {
|
---|
1249 | case AVATAR_UPLOAD:
|
---|
1250 | if (!$config['allow_avatar_upload'] && !$ignore_config)
|
---|
1251 | {
|
---|
1252 | return '';
|
---|
1253 | }
|
---|
1254 | $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
|
---|
1255 | break;
|
---|
1256 |
|
---|
1257 | case AVATAR_GALLERY:
|
---|
1258 | if (!$config['allow_avatar_local'] && !$ignore_config)
|
---|
1259 | {
|
---|
1260 | return '';
|
---|
1261 | }
|
---|
1262 | $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
|
---|
1263 | break;
|
---|
1264 |
|
---|
1265 | case AVATAR_REMOTE:
|
---|
1266 | if (!$config['allow_avatar_remote'] && !$ignore_config)
|
---|
1267 | {
|
---|
1268 | return '';
|
---|
1269 | }
|
---|
1270 | break;
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | $avatar_img .= $avatar;
|
---|
1274 | return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | ?>
|
---|