phpBB
Statistics
| Revision:

root / trunk / phpBB / includes / functions_display.php

History | View | Annotate | Download (42.6 kB)

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