1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/functions_display.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1343 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package phpBB3
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* Display Forums
1.24 +*/
1.25 +function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
1.26 +{
1.27 + global $db, $auth, $user, $template;
1.28 + global $phpbb_root_path, $phpEx, $config;
1.29 +
1.30 + $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
1.31 + $parent_id = $visible_forums = 0;
1.32 + $sql_from = '';
1.33 +
1.34 + // Mark forums read?
1.35 + $mark_read = request_var('mark', '');
1.36 +
1.37 + if ($mark_read == 'all')
1.38 + {
1.39 + $mark_read = '';
1.40 + }
1.41 +
1.42 + if (!$root_data)
1.43 + {
1.44 + if ($mark_read == 'forums')
1.45 + {
1.46 + $mark_read = 'all';
1.47 + }
1.48 +
1.49 + $root_data = array('forum_id' => 0);
1.50 + $sql_where = '';
1.51 + }
1.52 + else
1.53 + {
1.54 + $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
1.55 + }
1.56 +
1.57 + // Handle marking everything read
1.58 + if ($mark_read == 'all')
1.59 + {
1.60 + $redirect = build_url(array('mark', 'hash'));
1.61 + meta_refresh(3, $redirect);
1.62 +
1.63 + if (check_link_hash(request_var('hash', ''), 'global'))
1.64 + {
1.65 + markread('all');
1.66 +
1.67 + trigger_error(
1.68 + $user->lang['FORUMS_MARKED'] . '<br /><br />' .
1.69 + sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>')
1.70 + );
1.71 + }
1.72 + else
1.73 + {
1.74 + trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
1.75 + }
1.76 + }
1.77 +
1.78 + // Display list of active topics for this category?
1.79 + $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
1.80 +
1.81 + $sql_array = array(
1.82 + 'SELECT' => 'f.*',
1.83 + 'FROM' => array(
1.84 + FORUMS_TABLE => 'f'
1.85 + ),
1.86 + 'LEFT_JOIN' => array(),
1.87 + );
1.88 +
1.89 + if ($config['load_db_lastread'] && $user->data['is_registered'])
1.90 + {
1.91 + $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');
1.92 + $sql_array['SELECT'] .= ', ft.mark_time';
1.93 + }
1.94 + else if ($config['load_anon_lastread'] || $user->data['is_registered'])
1.95 + {
1.96 + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
1.97 + $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
1.98 +
1.99 + if (!$user->data['is_registered'])
1.100 + {
1.101 + $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
1.102 + }
1.103 + }
1.104 +
1.105 + if ($show_active)
1.106 + {
1.107 + $sql_array['LEFT_JOIN'][] = array(
1.108 + 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
1.109 + 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
1.110 + );
1.111 +
1.112 + $sql_array['SELECT'] .= ', fa.user_id';
1.113 + }
1.114 +
1.115 + $sql = $db->sql_build_query('SELECT', array(
1.116 + 'SELECT' => $sql_array['SELECT'],
1.117 + 'FROM' => $sql_array['FROM'],
1.118 + 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
1.119 +
1.120 + 'WHERE' => $sql_where,
1.121 +
1.122 + 'ORDER_BY' => 'f.left_id',
1.123 + ));
1.124 +
1.125 + $result = $db->sql_query($sql);
1.126 +
1.127 + $forum_tracking_info = array();
1.128 + $branch_root_id = $root_data['forum_id'];
1.129 +
1.130 + // Check for unread global announcements (index page only)
1.131 + $ga_unread = false;
1.132 + if ($root_data['forum_id'] == 0)
1.133 + {
1.134 + $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
1.135 +
1.136 + if (!empty($unread_ga_list))
1.137 + {
1.138 + $ga_unread = true;
1.139 + }
1.140 + }
1.141 +
1.142 + while ($row = $db->sql_fetchrow($result))
1.143 + {
1.144 + $forum_id = $row['forum_id'];
1.145 +
1.146 + // Mark forums read?
1.147 + if ($mark_read == 'forums')
1.148 + {
1.149 + if ($auth->acl_get('f_list', $forum_id))
1.150 + {
1.151 + $forum_ids[] = $forum_id;
1.152 + }
1.153 +
1.154 + continue;
1.155 + }
1.156 +
1.157 + // Category with no members
1.158 + if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
1.159 + {
1.160 + continue;
1.161 + }
1.162 +
1.163 + // Skip branch
1.164 + if (isset($right_id))
1.165 + {
1.166 + if ($row['left_id'] < $right_id)
1.167 + {
1.168 + continue;
1.169 + }
1.170 + unset($right_id);
1.171 + }
1.172 +
1.173 + if (!$auth->acl_get('f_list', $forum_id))
1.174 + {
1.175 + // if the user does not have permissions to list this forum, skip everything until next branch
1.176 + $right_id = $row['right_id'];
1.177 + continue;
1.178 + }
1.179 +
1.180 + if ($config['load_db_lastread'] && $user->data['is_registered'])
1.181 + {
1.182 + $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
1.183 + }
1.184 + else if ($config['load_anon_lastread'] || $user->data['is_registered'])
1.185 + {
1.186 + if (!$user->data['is_registered'])
1.187 + {
1.188 + $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
1.189 + }
1.190 + $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'];
1.191 + }
1.192 +
1.193 + // Count the difference of real to public topics, so we can display an information to moderators
1.194 + $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
1.195 + $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
1.196 +
1.197 + // Display active topics from this forum?
1.198 + if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
1.199 + {
1.200 + if (!isset($active_forum_ary['forum_topics']))
1.201 + {
1.202 + $active_forum_ary['forum_topics'] = 0;
1.203 + }
1.204 +
1.205 + if (!isset($active_forum_ary['forum_posts']))
1.206 + {
1.207 + $active_forum_ary['forum_posts'] = 0;
1.208 + }
1.209 +
1.210 + $active_forum_ary['forum_id'][] = $forum_id;
1.211 + $active_forum_ary['enable_icons'][] = $row['enable_icons'];
1.212 + $active_forum_ary['forum_topics'] += $row['forum_topics'];
1.213 + $active_forum_ary['forum_posts'] += $row['forum_posts'];
1.214 +
1.215 + // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
1.216 + if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
1.217 + {
1.218 + $active_forum_ary['exclude_forum_id'][] = $forum_id;
1.219 + }
1.220 + }
1.221 +
1.222 + //
1.223 + if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
1.224 + {
1.225 + if ($row['forum_type'] != FORUM_CAT)
1.226 + {
1.227 + $forum_ids_moderator[] = (int) $forum_id;
1.228 + }
1.229 +
1.230 + // Direct child of current branch
1.231 + $parent_id = $forum_id;
1.232 + $forum_rows[$forum_id] = $row;
1.233 +
1.234 + if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
1.235 + {
1.236 + $branch_root_id = $forum_id;
1.237 + }
1.238 + $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
1.239 + $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
1.240 + }
1.241 + else if ($row['forum_type'] != FORUM_CAT)
1.242 + {
1.243 + $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
1.244 + $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
1.245 + $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
1.246 + $subforums[$parent_id][$forum_id]['children'] = array();
1.247 +
1.248 + if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
1.249 + {
1.250 + $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
1.251 + }
1.252 +
1.253 + if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
1.254 + {
1.255 + $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
1.256 + }
1.257 +
1.258 + $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
1.259 +
1.260 + // Do not list redirects in LINK Forums as Posts.
1.261 + if ($row['forum_type'] != FORUM_LINK)
1.262 + {
1.263 + $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
1.264 + }
1.265 +
1.266 + if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
1.267 + {
1.268 + $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
1.269 + $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
1.270 + $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
1.271 + $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
1.272 + $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
1.273 + $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
1.274 + $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
1.275 + }
1.276 + }
1.277 + }
1.278 + $db->sql_freeresult($result);
1.279 +
1.280 + // Handle marking posts
1.281 + if ($mark_read == 'forums')
1.282 + {
1.283 + $redirect = build_url(array('mark', 'hash'));
1.284 + $token = request_var('hash', '');
1.285 + if (check_link_hash($token, 'global'))
1.286 + {
1.287 + // Add 0 to forums array to mark global announcements correctly
1.288 + $forum_ids[] = 0;
1.289 + markread('topics', $forum_ids);
1.290 + $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
1.291 + meta_refresh(3, $redirect);
1.292 + trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
1.293 + }
1.294 + else
1.295 + {
1.296 + $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
1.297 + meta_refresh(3, $redirect);
1.298 + trigger_error($message);
1.299 + }
1.300 +
1.301 + }
1.302 +
1.303 + // Grab moderators ... if necessary
1.304 + if ($display_moderators)
1.305 + {
1.306 + if ($return_moderators)
1.307 + {
1.308 + $forum_ids_moderator[] = $root_data['forum_id'];
1.309 + }
1.310 + get_moderators($forum_moderators, $forum_ids_moderator);
1.311 + }
1.312 +
1.313 + // Used to tell whatever we have to create a dummy category or not.
1.314 + $last_catless = true;
1.315 + foreach ($forum_rows as $row)
1.316 + {
1.317 + // Empty category
1.318 + if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
1.319 + {
1.320 + $template->assign_block_vars('forumrow', array(
1.321 + 'S_IS_CAT' => true,
1.322 + 'FORUM_ID' => $row['forum_id'],
1.323 + 'FORUM_NAME' => $row['forum_name'],
1.324 + 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
1.325 + 'FORUM_FOLDER_IMG' => '',
1.326 + 'FORUM_FOLDER_IMG_SRC' => '',
1.327 + 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
1.328 + 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
1.329 + 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
1.330 + );
1.331 +
1.332 + continue;
1.333 + }
1.334 +
1.335 + $visible_forums++;
1.336 + $forum_id = $row['forum_id'];
1.337 +
1.338 + $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
1.339 +
1.340 + // Mark the first visible forum on index as unread if there's any unread global announcement
1.341 + if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0])
1.342 + {
1.343 + $forum_unread = true;
1.344 + }
1.345 +
1.346 + $folder_image = $folder_alt = $l_subforums = '';
1.347 + $subforums_list = array();
1.348 +
1.349 + // Generate list of subforums if we need to
1.350 + if (isset($subforums[$forum_id]))
1.351 + {
1.352 + foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
1.353 + {
1.354 + $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
1.355 +
1.356 + if (!$subforum_unread && !empty($subforum_row['children']))
1.357 + {
1.358 + foreach ($subforum_row['children'] as $child_id)
1.359 + {
1.360 + if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
1.361 + {
1.362 + // Once we found an unread child forum, we can drop out of this loop
1.363 + $subforum_unread = true;
1.364 + break;
1.365 + }
1.366 + }
1.367 + }
1.368 +
1.369 + if ($subforum_row['display'] && $subforum_row['name'])
1.370 + {
1.371 + $subforums_list[] = array(
1.372 + 'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
1.373 + 'name' => $subforum_row['name'],
1.374 + 'unread' => $subforum_unread,
1.375 + );
1.376 + }
1.377 + else
1.378 + {
1.379 + unset($subforums[$forum_id][$subforum_id]);
1.380 + }
1.381 +
1.382 + // If one subforum is unread the forum gets unread too...
1.383 + if ($subforum_unread)
1.384 + {
1.385 + $forum_unread = true;
1.386 + }
1.387 + }
1.388 +
1.389 + $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
1.390 + $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
1.391 + }
1.392 + else
1.393 + {
1.394 + switch ($row['forum_type'])
1.395 + {
1.396 + case FORUM_POST:
1.397 + $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
1.398 + break;
1.399 +
1.400 + case FORUM_LINK:
1.401 + $folder_image = 'forum_link';
1.402 + break;
1.403 + }
1.404 + }
1.405 +
1.406 + // Which folder should we display?
1.407 + if ($row['forum_status'] == ITEM_LOCKED)
1.408 + {
1.409 + $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
1.410 + $folder_alt = 'FORUM_LOCKED';
1.411 + }
1.412 + else
1.413 + {
1.414 + $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
1.415 + }
1.416 +
1.417 + // Create last post link information, if appropriate
1.418 + if ($row['forum_last_post_id'])
1.419 + {
1.420 + $last_post_subject = $row['forum_last_post_subject'];
1.421 + $last_post_time = $user->format_date($row['forum_last_post_time']);
1.422 + $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
1.423 + }
1.424 + else
1.425 + {
1.426 + $last_post_subject = $last_post_time = $last_post_url = '';
1.427 + }
1.428 +
1.429 + // Output moderator listing ... if applicable
1.430 + $l_moderator = $moderators_list = '';
1.431 + if ($display_moderators && !empty($forum_moderators[$forum_id]))
1.432 + {
1.433 + $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
1.434 + $moderators_list = implode(', ', $forum_moderators[$forum_id]);
1.435 + }
1.436 +
1.437 + $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
1.438 + $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
1.439 +
1.440 + $s_subforums_list = array();
1.441 + foreach ($subforums_list as $subforum)
1.442 + {
1.443 + $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>';
1.444 + }
1.445 + $s_subforums_list = (string) implode(', ', $s_subforums_list);
1.446 + $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
1.447 +
1.448 + if ($row['forum_type'] != FORUM_LINK)
1.449 + {
1.450 + $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
1.451 + }
1.452 + else
1.453 + {
1.454 + // If the forum is a link and we count redirects we need to visit it
1.455 + // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
1.456 + if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
1.457 + {
1.458 + $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
1.459 + }
1.460 + else
1.461 + {
1.462 + $u_viewforum = $row['forum_link'];
1.463 + }
1.464 + }
1.465 +
1.466 + $template->assign_block_vars('forumrow', array(
1.467 + 'S_IS_CAT' => false,
1.468 + 'S_NO_CAT' => $catless && !$last_catless,
1.469 + 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
1.470 + 'S_UNREAD_FORUM' => $forum_unread,
1.471 + 'S_AUTH_READ' => $auth->acl_get('f_read', $row['forum_id']),
1.472 + 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
1.473 + 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false,
1.474 + 'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false,
1.475 + 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
1.476 +
1.477 + 'FORUM_ID' => $row['forum_id'],
1.478 + 'FORUM_NAME' => $row['forum_name'],
1.479 + 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
1.480 + 'TOPICS' => $row['forum_topics'],
1.481 + $l_post_click_count => $post_click_count,
1.482 + 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
1.483 + 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
1.484 + 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
1.485 + 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
1.486 + 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
1.487 + 'LAST_POST_SUBJECT' => censor_text($last_post_subject),
1.488 + 'LAST_POST_TIME' => $last_post_time,
1.489 + 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.490 + 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.491 + 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.492 + 'MODERATORS' => $moderators_list,
1.493 + 'SUBFORUMS' => $s_subforums_list,
1.494 +
1.495 + 'L_SUBFORUM_STR' => $l_subforums,
1.496 + 'L_MODERATOR_STR' => $l_moderator,
1.497 +
1.498 + 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '',
1.499 + 'U_VIEWFORUM' => $u_viewforum,
1.500 + 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.501 + 'U_LAST_POST' => $last_post_url)
1.502 + );
1.503 +
1.504 + // Assign subforums loop for style authors
1.505 + foreach ($subforums_list as $subforum)
1.506 + {
1.507 + $template->assign_block_vars('forumrow.subforum', array(
1.508 + 'U_SUBFORUM' => $subforum['link'],
1.509 + 'SUBFORUM_NAME' => $subforum['name'],
1.510 + 'S_UNREAD' => $subforum['unread'])
1.511 + );
1.512 + }
1.513 +
1.514 + $last_catless = $catless;
1.515 + }
1.516 +
1.517 + $template->assign_vars(array(
1.518 + 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums') : '',
1.519 + 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
1.520 + 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
1.521 + 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
1.522 + 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
1.523 + ));
1.524 +
1.525 + if ($return_moderators)
1.526 + {
1.527 + return array($active_forum_ary, $forum_moderators);
1.528 + }
1.529 +
1.530 + return array($active_forum_ary, array());
1.531 +}
1.532 +
1.533 +/**
1.534 +* Create forum rules for given forum
1.535 +*/
1.536 +function generate_forum_rules(&$forum_data)
1.537 +{
1.538 + if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
1.539 + {
1.540 + return;
1.541 + }
1.542 +
1.543 + global $template, $phpbb_root_path, $phpEx;
1.544 +
1.545 + if ($forum_data['forum_rules'])
1.546 + {
1.547 + $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']);
1.548 + }
1.549 +
1.550 + $template->assign_vars(array(
1.551 + 'S_FORUM_RULES' => true,
1.552 + 'U_FORUM_RULES' => $forum_data['forum_rules_link'],
1.553 + 'FORUM_RULES' => $forum_data['forum_rules'])
1.554 + );
1.555 +}
1.556 +
1.557 +/**
1.558 +* Create forum navigation links for given forum, create parent
1.559 +* list if currently null, assign basic forum info to template
1.560 +*/
1.561 +function generate_forum_nav(&$forum_data)
1.562 +{
1.563 + global $db, $user, $template, $auth, $config;
1.564 + global $phpEx, $phpbb_root_path;
1.565 +
1.566 + if (!$auth->acl_get('f_list', $forum_data['forum_id']))
1.567 + {
1.568 + return;
1.569 + }
1.570 +
1.571 + // Get forum parents
1.572 + $forum_parents = get_forum_parents($forum_data);
1.573 +
1.574 + // Build navigation links
1.575 + if (!empty($forum_parents))
1.576 + {
1.577 + foreach ($forum_parents as $parent_forum_id => $parent_data)
1.578 + {
1.579 + list($parent_name, $parent_type) = array_values($parent_data);
1.580 +
1.581 + // Skip this parent if the user does not have the permission to view it
1.582 + if (!$auth->acl_get('f_list', $parent_forum_id))
1.583 + {
1.584 + continue;
1.585 + }
1.586 +
1.587 + $template->assign_block_vars('navlinks', array(
1.588 + 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false,
1.589 + 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false,
1.590 + 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false,
1.591 + 'FORUM_NAME' => $parent_name,
1.592 + 'FORUM_ID' => $parent_forum_id,
1.593 + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
1.594 + );
1.595 + }
1.596 + }
1.597 +
1.598 + $template->assign_block_vars('navlinks', array(
1.599 + 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
1.600 + 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
1.601 + 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
1.602 + 'FORUM_NAME' => $forum_data['forum_name'],
1.603 + 'FORUM_ID' => $forum_data['forum_id'],
1.604 + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
1.605 + );
1.606 +
1.607 + $template->assign_vars(array(
1.608 + 'FORUM_ID' => $forum_data['forum_id'],
1.609 + 'FORUM_NAME' => $forum_data['forum_name'],
1.610 + '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']),
1.611 +
1.612 + '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,
1.613 + ));
1.614 +
1.615 + return;
1.616 +}
1.617 +
1.618 +/**
1.619 +* Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
1.620 +*/
1.621 +function get_forum_parents(&$forum_data)
1.622 +{
1.623 + global $db;
1.624 +
1.625 + $forum_parents = array();
1.626 +
1.627 + if ($forum_data['parent_id'] > 0)
1.628 + {
1.629 + if ($forum_data['forum_parents'] == '')
1.630 + {
1.631 + $sql = 'SELECT forum_id, forum_name, forum_type
1.632 + FROM ' . FORUMS_TABLE . '
1.633 + WHERE left_id < ' . $forum_data['left_id'] . '
1.634 + AND right_id > ' . $forum_data['right_id'] . '
1.635 + ORDER BY left_id ASC';
1.636 + $result = $db->sql_query($sql);
1.637 +
1.638 + while ($row = $db->sql_fetchrow($result))
1.639 + {
1.640 + $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
1.641 + }
1.642 + $db->sql_freeresult($result);
1.643 +
1.644 + $forum_data['forum_parents'] = serialize($forum_parents);
1.645 +
1.646 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.647 + SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
1.648 + WHERE parent_id = " . $forum_data['parent_id'];
1.649 + $db->sql_query($sql);
1.650 + }
1.651 + else
1.652 + {
1.653 + $forum_parents = unserialize($forum_data['forum_parents']);
1.654 + }
1.655 + }
1.656 +
1.657 + return $forum_parents;
1.658 +}
1.659 +
1.660 +/**
1.661 +* Generate topic pagination
1.662 +*/
1.663 +function topic_generate_pagination($replies, $url)
1.664 +{
1.665 + global $config, $user;
1.666 +
1.667 + // Make sure $per_page is a valid value
1.668 + $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
1.669 +
1.670 + if (($replies + 1) > $per_page)
1.671 + {
1.672 + $total_pages = ceil(($replies + 1) / $per_page);
1.673 + $pagination = '';
1.674 +
1.675 + $times = 1;
1.676 + for ($j = 0; $j < $replies + 1; $j += $per_page)
1.677 + {
1.678 + $pagination .= '<a href="' . $url . ($j == 0 ? '' : '&start=' . $j) . '">' . $times . '</a>';
1.679 + if ($times == 1 && $total_pages > 5)
1.680 + {
1.681 + $pagination .= '<span class="page-dots"> ... </span>';
1.682 +
1.683 + // Display the last three pages
1.684 + $times = $total_pages - 3;
1.685 + $j += ($total_pages - 4) * $per_page;
1.686 + }
1.687 + else if ($times < $total_pages)
1.688 + {
1.689 + $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
1.690 + }
1.691 + $times++;
1.692 + }
1.693 + }
1.694 + else
1.695 + {
1.696 + $pagination = '';
1.697 + }
1.698 +
1.699 + return $pagination;
1.700 +}
1.701 +
1.702 +/**
1.703 +* Obtain list of moderators of each forum
1.704 +*/
1.705 +function get_moderators(&$forum_moderators, $forum_id = false)
1.706 +{
1.707 + global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
1.708 +
1.709 + $forum_id_ary = array();
1.710 +
1.711 + if ($forum_id !== false)
1.712 + {
1.713 + if (!is_array($forum_id))
1.714 + {
1.715 + $forum_id = array($forum_id);
1.716 + }
1.717 +
1.718 + // Exchange key/value pair to be able to faster check for the forum id existence
1.719 + $forum_id_ary = array_flip($forum_id);
1.720 + }
1.721 +
1.722 + $sql_array = array(
1.723 + 'SELECT' => 'm.*, u.user_colour, g.group_colour, g.group_type',
1.724 +
1.725 + 'FROM' => array(
1.726 + MODERATOR_CACHE_TABLE => 'm',
1.727 + ),
1.728 +
1.729 + 'LEFT_JOIN' => array(
1.730 + array(
1.731 + 'FROM' => array(USERS_TABLE => 'u'),
1.732 + 'ON' => 'm.user_id = u.user_id',
1.733 + ),
1.734 + array(
1.735 + 'FROM' => array(GROUPS_TABLE => 'g'),
1.736 + 'ON' => 'm.group_id = g.group_id',
1.737 + ),
1.738 + ),
1.739 +
1.740 + 'WHERE' => 'm.display_on_index = 1',
1.741 + );
1.742 +
1.743 + // We query every forum here because for caching we should not have any parameter.
1.744 + $sql = $db->sql_build_query('SELECT', $sql_array);
1.745 + $result = $db->sql_query($sql, 3600);
1.746 +
1.747 + while ($row = $db->sql_fetchrow($result))
1.748 + {
1.749 + $f_id = (int) $row['forum_id'];
1.750 +
1.751 + if (!isset($forum_id_ary[$f_id]))
1.752 + {
1.753 + continue;
1.754 + }
1.755 +
1.756 + if (!empty($row['user_id']))
1.757 + {
1.758 + $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
1.759 + }
1.760 + else
1.761 + {
1.762 + $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
1.763 +
1.764 + if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
1.765 + {
1.766 + $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
1.767 + }
1.768 + else
1.769 + {
1.770 + $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']) . '">' . $group_name . '</a>';
1.771 + }
1.772 + }
1.773 + }
1.774 + $db->sql_freeresult($result);
1.775 +
1.776 + return;
1.777 +}
1.778 +
1.779 +/**
1.780 +* User authorisation levels output
1.781 +*
1.782 +* @param string $mode Can be forum or topic. Not in use at the moment.
1.783 +* @param int $forum_id The current forum the user is in.
1.784 +* @param int $forum_status The forums status bit.
1.785 +*/
1.786 +function gen_forum_auth_level($mode, $forum_id, $forum_status)
1.787 +{
1.788 + global $template, $auth, $user, $config;
1.789 +
1.790 + $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
1.791 +
1.792 + $rules = array(
1.793 + ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
1.794 + ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
1.795 + ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
1.796 + ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
1.797 + );
1.798 +
1.799 + if ($config['allow_attachments'])
1.800 + {
1.801 + $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
1.802 + }
1.803 +
1.804 + foreach ($rules as $rule)
1.805 + {
1.806 + $template->assign_block_vars('rules', array('RULE' => $rule));
1.807 + }
1.808 +
1.809 + return;
1.810 +}
1.811 +
1.812 +/**
1.813 +* Generate topic status
1.814 +*/
1.815 +function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
1.816 +{
1.817 + global $user, $config;
1.818 +
1.819 + $folder = $folder_new = '';
1.820 +
1.821 + if ($topic_row['topic_status'] == ITEM_MOVED)
1.822 + {
1.823 + $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
1.824 + $folder_img = 'topic_moved';
1.825 + $folder_alt = 'TOPIC_MOVED';
1.826 + }
1.827 + else
1.828 + {
1.829 + switch ($topic_row['topic_type'])
1.830 + {
1.831 + case POST_GLOBAL:
1.832 + $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
1.833 + $folder = 'global_read';
1.834 + $folder_new = 'global_unread';
1.835 + break;
1.836 +
1.837 + case POST_ANNOUNCE:
1.838 + $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
1.839 + $folder = 'announce_read';
1.840 + $folder_new = 'announce_unread';
1.841 + break;
1.842 +
1.843 + case POST_STICKY:
1.844 + $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
1.845 + $folder = 'sticky_read';
1.846 + $folder_new = 'sticky_unread';
1.847 + break;
1.848 +
1.849 + default:
1.850 + $topic_type = '';
1.851 + $folder = 'topic_read';
1.852 + $folder_new = 'topic_unread';
1.853 +
1.854 + // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
1.855 + if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
1.856 + {
1.857 + $folder .= '_hot';
1.858 + $folder_new .= '_hot';
1.859 + }
1.860 + break;
1.861 + }
1.862 +
1.863 + if ($topic_row['topic_status'] == ITEM_LOCKED)
1.864 + {
1.865 + $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
1.866 + $folder .= '_locked';
1.867 + $folder_new .= '_locked';
1.868 + }
1.869 +
1.870 +
1.871 + $folder_img = ($unread_topic) ? $folder_new : $folder;
1.872 + $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
1.873 +
1.874 + // Posted image?
1.875 + if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
1.876 + {
1.877 + $folder_img .= '_mine';
1.878 + }
1.879 + }
1.880 +
1.881 + if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
1.882 + {
1.883 + $topic_type = $user->lang['VIEW_TOPIC_POLL'];
1.884 + }
1.885 +}
1.886 +
1.887 +/**
1.888 +* Assign/Build custom bbcodes for display in screens supporting using of bbcodes
1.889 +* The custom bbcodes buttons will be placed within the template block 'custom_codes'
1.890 +*/
1.891 +function display_custom_bbcodes()
1.892 +{
1.893 + global $db, $template, $user;
1.894 +
1.895 + // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
1.896 + $num_predefined_bbcodes = 22;
1.897 +
1.898 + $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
1.899 + FROM ' . BBCODES_TABLE . '
1.900 + WHERE display_on_posting = 1
1.901 + ORDER BY bbcode_tag';
1.902 + $result = $db->sql_query($sql);
1.903 +
1.904 + $i = 0;
1.905 + while ($row = $db->sql_fetchrow($result))
1.906 + {
1.907 + // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
1.908 + if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
1.909 + {
1.910 + $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
1.911 + }
1.912 +
1.913 + $template->assign_block_vars('custom_tags', array(
1.914 + 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
1.915 + 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
1.916 + 'BBCODE_TAG' => $row['bbcode_tag'],
1.917 + 'BBCODE_HELPLINE' => $row['bbcode_helpline'],
1.918 + 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
1.919 + ));
1.920 +
1.921 + $i++;
1.922 + }
1.923 + $db->sql_freeresult($result);
1.924 +}
1.925 +
1.926 +/**
1.927 +* Display reasons
1.928 +*/
1.929 +function display_reasons($reason_id = 0)
1.930 +{
1.931 + global $db, $user, $template;
1.932 +
1.933 + $sql = 'SELECT *
1.934 + FROM ' . REPORTS_REASONS_TABLE . '
1.935 + ORDER BY reason_order ASC';
1.936 + $result = $db->sql_query($sql);
1.937 +
1.938 + while ($row = $db->sql_fetchrow($result))
1.939 + {
1.940 + // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1.941 + if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1.942 + {
1.943 + $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
1.944 + $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
1.945 + }
1.946 +
1.947 + $template->assign_block_vars('reason', array(
1.948 + 'ID' => $row['reason_id'],
1.949 + 'TITLE' => $row['reason_title'],
1.950 + 'DESCRIPTION' => $row['reason_description'],
1.951 + 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false)
1.952 + );
1.953 + }
1.954 + $db->sql_freeresult($result);
1.955 +}
1.956 +
1.957 +/**
1.958 +* Display user activity (action forum/topic)
1.959 +*/
1.960 +function display_user_activity(&$userdata)
1.961 +{
1.962 + global $auth, $template, $db, $user;
1.963 + global $phpbb_root_path, $phpEx;
1.964 +
1.965 + // Do not display user activity for users having more than 5000 posts...
1.966 + if ($userdata['user_posts'] > 5000)
1.967 + {
1.968 + return;
1.969 + }
1.970 +
1.971 + $forum_ary = array();
1.972 +
1.973 + // Do not include those forums the user is not having read access to...
1.974 + $forum_read_ary = $auth->acl_getf('!f_read');
1.975 +
1.976 + foreach ($forum_read_ary as $forum_id => $not_allowed)
1.977 + {
1.978 + if ($not_allowed['f_read'])
1.979 + {
1.980 + $forum_ary[] = (int) $forum_id;
1.981 + }
1.982 + }
1.983 +
1.984 + $forum_ary = array_unique($forum_ary);
1.985 + $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
1.986 +
1.987 + $fid_m_approve = $auth->acl_getf('m_approve', true);
1.988 + $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : '';
1.989 +
1.990 + // Obtain active forum
1.991 + $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
1.992 + FROM ' . POSTS_TABLE . '
1.993 + WHERE poster_id = ' . $userdata['user_id'] . "
1.994 + AND post_postcount = 1
1.995 + AND (post_approved = 1
1.996 + $sql_m_approve)
1.997 + $forum_sql
1.998 + GROUP BY forum_id
1.999 + ORDER BY num_posts DESC";
1.1000 + $result = $db->sql_query_limit($sql, 1);
1.1001 + $active_f_row = $db->sql_fetchrow($result);
1.1002 + $db->sql_freeresult($result);
1.1003 +
1.1004 + if (!empty($active_f_row))
1.1005 + {
1.1006 + $sql = 'SELECT forum_name
1.1007 + FROM ' . FORUMS_TABLE . '
1.1008 + WHERE forum_id = ' . $active_f_row['forum_id'];
1.1009 + $result = $db->sql_query($sql, 3600);
1.1010 + $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
1.1011 + $db->sql_freeresult($result);
1.1012 + }
1.1013 +
1.1014 + // Obtain active topic
1.1015 + // We need to exclude passworded forums here so we do not leak the topic title
1.1016 + $forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums()));
1.1017 + $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : '';
1.1018 +
1.1019 + $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
1.1020 + FROM ' . POSTS_TABLE . '
1.1021 + WHERE poster_id = ' . $userdata['user_id'] . "
1.1022 + AND post_postcount = 1
1.1023 + AND (post_approved = 1
1.1024 + $sql_m_approve)
1.1025 + $forum_sql_topic
1.1026 + GROUP BY topic_id
1.1027 + ORDER BY num_posts DESC";
1.1028 + $result = $db->sql_query_limit($sql, 1);
1.1029 + $active_t_row = $db->sql_fetchrow($result);
1.1030 + $db->sql_freeresult($result);
1.1031 +
1.1032 + if (!empty($active_t_row))
1.1033 + {
1.1034 + $sql = 'SELECT topic_title
1.1035 + FROM ' . TOPICS_TABLE . '
1.1036 + WHERE topic_id = ' . $active_t_row['topic_id'];
1.1037 + $result = $db->sql_query($sql);
1.1038 + $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
1.1039 + $db->sql_freeresult($result);
1.1040 + }
1.1041 +
1.1042 + $userdata['active_t_row'] = $active_t_row;
1.1043 + $userdata['active_f_row'] = $active_f_row;
1.1044 +
1.1045 + $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
1.1046 + if (!empty($active_f_row['num_posts']))
1.1047 + {
1.1048 + $active_f_name = $active_f_row['forum_name'];
1.1049 + $active_f_id = $active_f_row['forum_id'];
1.1050 + $active_f_count = $active_f_row['num_posts'];
1.1051 + $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
1.1052 + }
1.1053 +
1.1054 + $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
1.1055 + if (!empty($active_t_row['num_posts']))
1.1056 + {
1.1057 + $active_t_name = $active_t_row['topic_title'];
1.1058 + $active_t_id = $active_t_row['topic_id'];
1.1059 + $active_t_count = $active_t_row['num_posts'];
1.1060 + $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
1.1061 + }
1.1062 +
1.1063 + $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'];
1.1064 +
1.1065 + $template->assign_vars(array(
1.1066 + 'ACTIVE_FORUM' => $active_f_name,
1.1067 + 'ACTIVE_FORUM_POSTS' => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
1.1068 + 'ACTIVE_FORUM_PCT' => sprintf($l_active_pct, $active_f_pct),
1.1069 + 'ACTIVE_TOPIC' => censor_text($active_t_name),
1.1070 + 'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
1.1071 + 'ACTIVE_TOPIC_PCT' => sprintf($l_active_pct, $active_t_pct),
1.1072 + 'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
1.1073 + 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
1.1074 + 'S_SHOW_ACTIVITY' => true)
1.1075 + );
1.1076 +}
1.1077 +
1.1078 +/**
1.1079 +* Topic and forum watching common code
1.1080 +*/
1.1081 +function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')
1.1082 +{
1.1083 + global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
1.1084 +
1.1085 + $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
1.1086 + $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
1.1087 + $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
1.1088 + $u_url = "uid={$user->data['user_id']}";
1.1089 + $u_url .= ($mode == 'forum') ? '&f' : '&f=' . $forum_id . '&t';
1.1090 + $is_watching = 0;
1.1091 +
1.1092 + // Is user watching this thread?
1.1093 + if ($user_id != ANONYMOUS)
1.1094 + {
1.1095 + $can_watch = true;
1.1096 +
1.1097 + if ($notify_status == 'unset')
1.1098 + {
1.1099 + $sql = "SELECT notify_status
1.1100 + FROM $table_sql
1.1101 + WHERE $where_sql = $match_id
1.1102 + AND user_id = $user_id";
1.1103 + $result = $db->sql_query($sql);
1.1104 +
1.1105 + $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1.1106 + $db->sql_freeresult($result);
1.1107 + }
1.1108 +
1.1109 + if (!is_null($notify_status) && $notify_status !== '')
1.1110 + {
1.1111 +
1.1112 + if (isset($_GET['unwatch']))
1.1113 + {
1.1114 + $uid = request_var('uid', 0);
1.1115 + $token = request_var('hash', '');
1.1116 +
1.1117 + if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1.1118 + {
1.1119 + if ($uid != $user_id || $_GET['unwatch'] != $mode)
1.1120 + {
1.1121 + $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1.1122 + $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1.1123 + trigger_error($message);
1.1124 + }
1.1125 +
1.1126 + $sql = 'DELETE FROM ' . $table_sql . "
1.1127 + WHERE $where_sql = $match_id
1.1128 + AND user_id = $user_id";
1.1129 + $db->sql_query($sql);
1.1130 +
1.1131 + $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1.1132 + $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />';
1.1133 + $message .= sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1.1134 + meta_refresh(3, $redirect_url);
1.1135 + trigger_error($message);
1.1136 + }
1.1137 + else
1.1138 + {
1.1139 + $s_hidden_fields = array(
1.1140 + 'uid' => $user->data['user_id'],
1.1141 + 'unwatch' => $mode,
1.1142 + 'start' => $start,
1.1143 + 'f' => $forum_id,
1.1144 + );
1.1145 + if ($mode != 'forum')
1.1146 + {
1.1147 + $s_hidden_fields['t'] = $topic_id;
1.1148 + }
1.1149 +
1.1150 + if ($item_title == '')
1.1151 + {
1.1152 + $confirm_box_message = 'UNWATCH_' . strtoupper($mode);
1.1153 + }
1.1154 + else
1.1155 + {
1.1156 + $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title);
1.1157 + }
1.1158 + confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1.1159 + }
1.1160 + }
1.1161 + else
1.1162 + {
1.1163 + $is_watching = true;
1.1164 +
1.1165 + if ($notify_status != NOTIFY_YES)
1.1166 + {
1.1167 + $sql = 'UPDATE ' . $table_sql . "
1.1168 + SET notify_status = " . NOTIFY_YES . "
1.1169 + WHERE $where_sql = $match_id
1.1170 + AND user_id = $user_id";
1.1171 + $db->sql_query($sql);
1.1172 + }
1.1173 + }
1.1174 + }
1.1175 + else
1.1176 + {
1.1177 + if (isset($_GET['watch']))
1.1178 + {
1.1179 + $uid = request_var('uid', 0);
1.1180 + $token = request_var('hash', '');
1.1181 +
1.1182 + if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
1.1183 + {
1.1184 + if ($uid != $user_id || $_GET['watch'] != $mode)
1.1185 + {
1.1186 + $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1.1187 + $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1.1188 + trigger_error($message);
1.1189 + }
1.1190 +
1.1191 + $is_watching = true;
1.1192 +
1.1193 + $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1.1194 + VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
1.1195 + $db->sql_query($sql);
1.1196 +
1.1197 + $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&start=$start");
1.1198 + $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1.1199 + meta_refresh(3, $redirect_url);
1.1200 + trigger_error($message);
1.1201 + }
1.1202 + else
1.1203 + {
1.1204 + $s_hidden_fields = array(
1.1205 + 'uid' => $user->data['user_id'],
1.1206 + 'watch' => $mode,
1.1207 + 'start' => $start,
1.1208 + 'f' => $forum_id,
1.1209 + );
1.1210 + if ($mode != 'forum')
1.1211 + {
1.1212 + $s_hidden_fields['t'] = $topic_id;
1.1213 + }
1.1214 +
1.1215 + $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title));
1.1216 + confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
1.1217 + }
1.1218 + }
1.1219 + else
1.1220 + {
1.1221 + $is_watching = 0;
1.1222 + }
1.1223 + }
1.1224 + }
1.1225 + else
1.1226 + {
1.1227 + if ((isset($_GET['unwatch']) && $_GET['unwatch'] == $mode) || (isset($_GET['watch']) && $_GET['watch'] == $mode))
1.1228 + {
1.1229 + login_box();
1.1230 + }
1.1231 + else
1.1232 + {
1.1233 + $can_watch = 0;
1.1234 + $is_watching = 0;
1.1235 + }
1.1236 + }
1.1237 +
1.1238 + if ($can_watch)
1.1239 + {
1.1240 + $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&start=$start&hash=" . generate_link_hash("{$mode}_$match_id"));
1.1241 + $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1.1242 + $s_watching['is_watching'] = $is_watching;
1.1243 + }
1.1244 +
1.1245 + return;
1.1246 +}
1.1247 +
1.1248 +/**
1.1249 +* Get user rank title and image
1.1250 +*
1.1251 +* @param int $user_rank the current stored users rank id
1.1252 +* @param int $user_posts the users number of posts
1.1253 +* @param string &$rank_title the rank title will be stored here after execution
1.1254 +* @param string &$rank_img the rank image as full img tag is stored here after execution
1.1255 +* @param string &$rank_img_src the rank image source is stored here after execution
1.1256 +*
1.1257 +* 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
1.1258 +*/
1.1259 +function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1.1260 +{
1.1261 + global $ranks, $config, $phpbb_root_path;
1.1262 +
1.1263 + if (empty($ranks))
1.1264 + {
1.1265 + global $cache;
1.1266 + $ranks = $cache->obtain_ranks();
1.1267 + }
1.1268 +
1.1269 + if (!empty($user_rank))
1.1270 + {
1.1271 + $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1.1272 + $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'] . '" />' : '';
1.1273 + $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1.1274 + }
1.1275 + else if ($user_posts !== false)
1.1276 + {
1.1277 + if (!empty($ranks['normal']))
1.1278 + {
1.1279 + foreach ($ranks['normal'] as $rank)
1.1280 + {
1.1281 + if ($user_posts >= $rank['rank_min'])
1.1282 + {
1.1283 + $rank_title = $rank['rank_title'];
1.1284 + $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'] . '" />' : '';
1.1285 + $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1.1286 + break;
1.1287 + }
1.1288 + }
1.1289 + }
1.1290 + }
1.1291 +}
1.1292 +
1.1293 +/**
1.1294 +* Get user avatar
1.1295 +*
1.1296 +* @param string $avatar Users assigned avatar name
1.1297 +* @param int $avatar_type Type of avatar
1.1298 +* @param string $avatar_width Width of users avatar
1.1299 +* @param string $avatar_height Height of users avatar
1.1300 +* @param string $alt Optional language string for alt tag within image, can be a language key or text
1.1301 +* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1.1302 +*
1.1303 +* @return string Avatar image
1.1304 +*/
1.1305 +function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
1.1306 +{
1.1307 + global $user, $config, $phpbb_root_path, $phpEx;
1.1308 +
1.1309 + if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
1.1310 + {
1.1311 + return '';
1.1312 + }
1.1313 +
1.1314 + $avatar_img = '';
1.1315 +
1.1316 + switch ($avatar_type)
1.1317 + {
1.1318 + case AVATAR_UPLOAD:
1.1319 + if (!$config['allow_avatar_upload'] && !$ignore_config)
1.1320 + {
1.1321 + return '';
1.1322 + }
1.1323 + $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
1.1324 + break;
1.1325 +
1.1326 + case AVATAR_GALLERY:
1.1327 + if (!$config['allow_avatar_local'] && !$ignore_config)
1.1328 + {
1.1329 + return '';
1.1330 + }
1.1331 + $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1.1332 + break;
1.1333 +
1.1334 + case AVATAR_REMOTE:
1.1335 + if (!$config['allow_avatar_remote'] && !$ignore_config)
1.1336 + {
1.1337 + return '';
1.1338 + }
1.1339 + break;
1.1340 + }
1.1341 +
1.1342 + $avatar_img .= $avatar;
1.1343 + return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
1.1344 +}
1.1345 +
1.1346 +?>
1.1347 \ No newline at end of file