phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / includes / functions_display.php

History | View | Annotate | Download (43.2 kB)

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