_active('main', 'topic_view'); break; default: trigger_error("$action not allowed as quickmod"); } } else { // Select the active module $module->set_active($id, $mode); } // Hide some of the options if we don't have the relevant information to use them if (!$post_id) { $module->set_display('main', 'post_details', false); $module->set_display('warn', 'warn_post', false); } if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts') { $module->set_display('queue', 'approve_details', false); } if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed') { $module->set_display('reports', 'report_details', false); } if (!$topic_id) { $module->set_display('main', 'topic_view', false); $module->set_display('logs', 'topic_logs', false); } if (!$forum_id) { $module->set_display('main', 'forum_view', false); $module->set_display('logs', 'forum_logs', false); } if (!$user_id && $username == '') { $module->set_display('notes', 'user_notes', false); $module->set_display('warn', 'warn_user', false); } // Load and execute the relevant module $module->load_active(); // Assign data to the template engine for the list of modules $module->assign_tpl_vars(append_sid("{$phpbb_root_path}mcp.$phpEx")); // Generate urls for letting the moderation control panel being accessed in different modes $template->assign_vars(array( 'U_MCP' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main'), 'U_MCP_FORUM' => ($forum_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=forum_view&f=$forum_id") : '', 'U_MCP_TOPIC' => ($forum_id && $topic_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=topic_view&t=$topic_id") : '', 'U_MCP_POST' => ($forum_id && $topic_id && $post_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=post_details&t=$topic_id&p=$post_id") : '', )); // Generate the page, do not display/query online list $module->display($module->get_page_title(), false); /** * Functions used to generate additional URL paramters */ function _module__url($mode, &$module_row) { return extra_url(); } function _module_notes_url($mode, &$module_row) { if ($mode == 'front') { return ''; } global $user_id; return ($user_id) ? "&u=$user_id" : ''; } function _module_warn_url($mode, &$module_row) { if ($mode == 'front' || $mode == 'list') { global $forum_id; return ($forum_id) ? "&f=$forum_id" : ''; } if ($mode == 'warn_post') { global $forum_id, $post_id; $url_extra = ($forum_id) ? "&f=$forum_id" : ''; $url_extra .= ($post_id) ? "&p=$post_id" : ''; return $url_extra; } else { global $user_id; return ($user_id) ? "&u=$user_id" : ''; } } function _module_main_url($mode, &$module_row) { return extra_url(); } function _module_logs_url($mode, &$module_row) { return extra_url(); } function _module_ban_url($mode, &$module_row) { return extra_url(); } function _module_queue_url($mode, &$module_row) { return extra_url(); } function _module_reports_url($mode, &$module_row) { return extra_url(); } function extra_url() { global $forum_id, $topic_id, $post_id, $user_id; $url_extra = ''; $url_extra .= ($forum_id) ? "&f=$forum_id" : ''; $url_extra .= ($topic_id) ? "&t=$topic_id" : ''; $url_extra .= ($post_id) ? "&p=$post_id" : ''; $url_extra .= ($user_id) ? "&u=$user_id" : ''; return $url_extra; } /** * Get simple topic data */ function get_topic_data($topic_ids, $acl_list = false, $read_tracking = false) { global $auth, $db, $config, $user; static $rowset = array(); $topics = array(); if (!sizeof($topic_ids)) { return array(); } // cache might not contain read tracking info, so we can't use it if read // tracking information is requested if (!$read_tracking) { $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset)); $topic_ids = array_diff($topic_ids, array_keys($rowset)); } else { $cache_topic_ids = array(); } if (sizeof($topic_ids)) { $sql_array = array( 'SELECT' => 't.*, f.*', 'FROM' => array( TOPICS_TABLE => 't', ), 'LEFT_JOIN' => array( array( 'FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id' ) ), 'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids) ); if ($read_tracking && $config['load_db_lastread']) { $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time'; $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id' ); $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id' ); } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!$row['forum_id']) { // Global Announcement? $row['forum_id'] = request_var('f', 0); } $rowset[$row['topic_id']] = $row; if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) { continue; } $topics[$row['topic_id']] = $row; } $db->sql_freeresult($result); } foreach ($cache_topic_ids as $id) { if (!$acl_list || $auth->acl_gets($acl_list, $rowset[$id]['forum_id'])) { $topics[$id] = $rowset[$id]; } } return $topics; } /** * Get simple post data */ function get_post_data($post_ids, $acl_list = false, $read_tracking = false) { global $db, $auth, $config, $user; $rowset = array(); if (!sizeof($post_ids)) { return array(); } $sql_array = array( 'SELECT' => 'p.*, u.*, t.*, f.*', 'FROM' => array( USERS_TABLE => 'u', POSTS_TABLE => 'p', TOPICS_TABLE => 't', ), 'LEFT_JOIN' => array( array( 'FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id' ) ), 'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . ' AND u.user_id = p.poster_id AND t.topic_id = p.topic_id', ); if ($read_tracking && $config['load_db_lastread']) { $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time'; $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id' ); $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id' ); } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); unset($sql_array); while ($row = $db->sql_fetchrow($result)) { if (!$row['forum_id']) { // Global Announcement? $row['forum_id'] = request_var('f', 0); } if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) { continue; } if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) { // Moderators without the permission to approve post should at least not see them. ;) continue; } $rowset[$row['post_id']] = $row; } $db->sql_freeresult($result); return $rowset; } /** * Get simple forum data */ function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false) { global $auth, $db, $user, $config; $rowset = array(); if (!is_array($forum_id)) { $forum_id = array($forum_id); } if (!sizeof($forum_id)) { return array(); } if ($read_tracking && $config['load_db_lastread']) { $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)'; $read_tracking_select = ', ft.mark_time'; } else { $read_tracking_join = $read_tracking_select = ''; } $sql = "SELECT f.* $read_tracking_select FROM " . FORUMS_TABLE . " f$read_tracking_join WHERE " . $db->sql_in_set('f.forum_id', $forum_id); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) { continue; } if ($auth->acl_get('m_approve', $row['forum_id'])) { $row['forum_topics'] = $row['forum_topics_real']; } $rowset[$row['forum_id']] = $row; } $db->sql_freeresult($result); return $rowset; } /** * sorting in mcp * * @param string $where_sql should either be WHERE (default if ommited) or end with AND or OR */ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, &$sort_order_sql, &$total, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE') { global $db, $user, $auth, $template; $sort_days = request_var('st', 0); $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0; switch ($mode) { case 'viewforum': $type = 'topics'; $default_key = 't'; $default_dir = 'd'; $sql = 'SELECT COUNT(topic_id) AS total FROM ' . TOPICS_TABLE . " $where_sql forum_id = $forum_id AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ") AND topic_last_post_time >= $min_time"; if (!$auth->acl_get('m_approve', $forum_id)) { $sql .= 'AND topic_approved = 1'; } break; case 'viewtopic': $type = 'posts'; $default_key = 't'; $default_dir = 'a'; $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . " $where_sql topic_id = $topic_id AND post_time >= $min_time"; if (!$auth->acl_get('m_approve', $forum_id)) { $sql .= 'AND post_approved = 1'; } break; case 'unapproved_posts': $type = 'posts'; $default_key = 't'; $default_dir = 'd'; $where_sql .= ($topic_id) ? ' topic_id = ' . $topic_id . ' AND' : ''; $sql = 'SELECT COUNT(post_id) AS total FROM ' . POSTS_TABLE . " $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . ' AND post_approved = 0'; if ($min_time) { $sql .= ' AND post_time >= ' . $min_time; } break; case 'unapproved_topics': $type = 'topics'; $default_key = 't'; $default_dir = 'd'; $sql = 'SELECT COUNT(topic_id) AS total FROM ' . TOPICS_TABLE . " $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . ' AND topic_approved = 0'; if ($min_time) { $sql .= ' AND topic_time >= ' . $min_time; } break; case 'reports': case 'reports_closed': $type = 'reports'; $default_key = 't'; $default_dir = 'd'; $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : ''; if ($topic_id) { $where_sql .= ' p.topic_id = ' . $topic_id; } else if ($forum_id) { $where_sql .= ' p.forum_id = ' . $forum_id; } else { $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list('!m_report'), true, true); } if ($mode == 'reports') { $where_sql .= ' AND r.report_closed = 0'; } else { $where_sql .= ' AND r.report_closed = 1'; } $sql = 'SELECT COUNT(r.report_id) AS total FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p $where_sql AND p.post_id = r.post_id $limit_time_sql"; break; case 'viewlogs': $type = 'logs'; $default_key = 't'; $default_dir = 'd'; $sql = 'SELECT COUNT(log_id) AS total FROM ' . LOG_TABLE . " $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_')) . ' AND log_time >= ' . $min_time . ' AND log_type = ' . LOG_MOD; break; } $sort_key = request_var('sk', $default_key); $sort_dir = request_var('sd', $default_dir); $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); switch ($type) { case 'topics': $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views'); $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : ''; break; case 'posts': $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject'); $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : ''; break; case 'reports': $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']); $sort_by_sql = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.post_time', 't' => 'r.report_time', 's' => 'p.post_subject'); break; case 'logs': $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : ''; break; } if (!isset($sort_by_sql[$sort_key])) { $sort_key = $default_key; } $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url); $template->assign_vars(array( 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days) ); if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts')) || $where_sql != 'WHERE') { $result = $db->sql_query($sql); $total = (int) $db->sql_fetchfield('total'); $db->sql_freeresult($result); } else { $total = -1; } } /** * Validate ids * * @param array &$ids The relevant ids to check * @param string $table The table to find the ids in * @param string $sql_id The ids relevant column name * @param array $acl_list A list of permissions the user need to have * @param mixed $singe_forum Limit to one forum id (int) or the first forum found (true) * * @return mixed False if no ids were able to be retrieved, true if at least one id left. * Additionally, this value can be the forum_id assigned if $single_forum was set. * Therefore checking the result for with !== false is the best method. */ function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false) { global $db, $auth; if (!is_array($ids) || empty($ids)) { return false; } $sql = "SELECT $sql_id, forum_id FROM $table WHERE " . $db->sql_in_set($sql_id, $ids); $result = $db->sql_query($sql); $ids = array(); $forum_id = false; while ($row = $db->sql_fetchrow($result)) { if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id'])) { continue; } if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list)) { continue; } // Limit forum? If not, just assign the id. if ($single_forum === false) { $ids[] = $row[$sql_id]; continue; } // Limit forum to a specific forum id? // This can get really tricky, because we do not want to create a failure on global topics. :) if ($row['forum_id']) { if ($single_forum !== true && $row['forum_id'] == (int) $single_forum) { $forum_id = (int) $single_forum; } else if ($forum_id === false) { $forum_id = $row['forum_id']; } if ($row['forum_id'] == $forum_id) { $ids[] = $row[$sql_id]; } } else { // Always add a global topic $ids[] = $row[$sql_id]; } } $db->sql_freeresult($result); if (!sizeof($ids)) { return false; } // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id) return ($single_forum === false) ? true : (int) $forum_id; } ?>N' => generate_pagination($u_search, $total_match_count, $per_page, $start), 'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start), 'TOTAL_MATCHES' => $total_match_count, 'SEARCH_IN_RESULTS' => ($search_id) ? false : true, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_SEARCH_ACTION' => $u_search, 'S_SHOW_TOPICS' => ($show_results == 'posts') ? false : true, 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'), 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'U_SEARCH_WORDS' => $u_search, )); if ($sql_where) { if ($show_results == 'posts') { // @todo Joining this query to the one below? $sql = 'SELECT zebra_id, friend, foe FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $zebra = array(); while ($row = $db->sql_fetchrow($result)) { $zebra[($row['friend']) ? 'friend' : 'foe'][] = $row['zebra_id']; } $db->sql_freeresult($result); $sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_colour FROM ' . POSTS_TABLE . ' p LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id) LEFT JOIN ' . FORUMS_TABLE . ' f ON (p.forum_id = f.forum_id) LEFT JOIN ' . USERS_TABLE . " u ON (p.poster_id = u.user_id) WHERE $sql_where"; } else { $sql_from = TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id) ' . (($sort_key == 'a') ? ' LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = t.topic_poster) ' : ''); $sql_select = 't.*, f.forum_id, f.forum_name'; if ($user->data['is_registered']) { if ($config['load_db_track']) { $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tp.topic_id)'; $sql_select .= ', tp.topic_posted'; } if ($config['load_db_lastread']) { $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id) LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)'; $sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time'; } } if ($config['load_anon_lastread'] || ($user->data['is_registered'] && !$config['load_db_lastread'])) { $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : ''; $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array(); } $sql = "SELECT $sql_select FROM $sql_from WHERE $sql_where"; } $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); $result = $db->sql_query($sql); $result_topic_id = 0; $rowset = array(); if ($show_results == 'topics') { $forums = $rowset = $shadow_topic_list = array(); while ($row = $db->sql_fetchrow($result)) { if ($row['topic_status'] == ITEM_MOVED) { $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id']; } $rowset[$row['topic_id']] = $row; if (!isset($forums[$row['forum_id']]) && $user->data['is_registered'] && $config['load_db_lastread']) { $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time']; } $forums[$row['forum_id']]['topic_list'][] = $row['topic_id']; $forums[$row['forum_id']]['rowset'][$row['topic_id']] = &$rowset[$row['topic_id']]; } $db->sql_freeresult($result); // If we have some shadow topics, update the rowset to reflect their topic information if (sizeof($shadow_topic_list)) { $sql = 'SELECT * FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $orig_topic_id = $shadow_topic_list[$row['topic_id']]; // We want to retain some values $row = array_merge($row, array( 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'], 'topic_status' => $rowset[$orig_topic_id]['topic_status'], 'forum_name' => $rowset[$orig_topic_id]['forum_name']) ); $rowset[$orig_topic_id] = $row; } $db->sql_freeresult($result); } unset($shadow_topic_list); foreach ($forums as $forum_id => $forum) { if ($user->data['is_registered'] && $config['load_db_lastread']) { $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), ($forum_id) ? false : $forum['topic_list']); } else if ($config['load_anon_lastread'] || $user->data['is_registered']) { $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']); if (!$user->data['is_registered']) { $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0; } } } unset($forums); } else { $bbcode_bitfield = $text_only_message = ''; $attach_list = array(); while ($row = $db->sql_fetchrow($result)) { // We pre-process some variables here for later usage $row['post_text'] = censor_text($row['post_text']); $text_only_message = $row['post_text']; // make list items visible as such if ($row['bbcode_uid']) { $text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '⋅ ', $text_only_message); // no BBCode in text only message strip_bbcode($text_only_message, $row['bbcode_uid']); } if ($return_chars == -1 || utf8_strlen($text_only_message) < ($return_chars + 3)) { $row['display_text_only'] = false; $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); // Does this post have an attachment? If so, add it to the list if ($row['post_attachment'] && $config['allow_attachments']) { $attach_list[$row['forum_id']][] = $row['post_id']; } } else { $row['post_text'] = $text_only_message; $row['display_text_only'] = true; } $rowset[] = $row; } $db->sql_freeresult($result); unset($text_only_message); // Instantiate BBCode if needed if ($bbcode_bitfield !== '') { include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); $bbcode = new bbcode(base64_encode($bbcode_bitfield)); } // Pull attachment data if (sizeof($attach_list)) { $use_attach_list = $attach_list; $attach_list = array(); foreach ($use_attach_list as $forum_id => $_list) { if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id)) { $attach_list = array_merge($attach_list, $_list); } } } if (sizeof($attach_list)) { $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . ' AND in_message = 0 ORDER BY filetime DESC, post_msg_id ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $attachments[$row['post_msg_id']][] = $row; } $db->sql_freeresult($result); } } if ($hilit) { // Remove bad highlights $hilit_array = array_filter(explode('|', $hilit), 'strlen'); foreach ($hilit_array as $key => $value) { $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($value, '#')); $hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]); } $hilit = implode('|', $hilit_array); } foreach ($rowset as $row) { $forum_id = $row['forum_id']; $result_topic_id = $row['topic_id']; $topic_title = censor_text($row['topic_title']); // we need to select a forum id for this global topic if (!$forum_id) { if (!isset($g_forum_id)) { // Get a list of forums the user cannot read $forum_ary = array_unique(array_keys($auth->acl_getf('!f_read', true))); // Determine first forum the user is able to read (must not be a category) $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST; if (sizeof($forum_ary)) { $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true); } $result = $db->sql_query_limit($sql, 1); $g_forum_id = (int) $db->sql_fetchfield('forum_id'); } $u_forum_id = $g_forum_id; } else { $u_forum_id = $forum_id; } $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$u_forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : '')); $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; if ($show_results == 'topics') { $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type); $unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false; $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$result_topic_id", true, $user->session_id) : ''; $row['topic_title'] = preg_replace('#(?!<.*)(?]*(?:)#is', '$1', $row['topic_title']); $tpl_ary = array( 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '', 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'S_TOPIC_GLOBAL' => (!$forum_id) ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $forum_id)) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread', 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&t=' . $result_topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, ); } else { if ((isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe'])) && (!$view || $view != 'show' || $post_id != $row['post_id'])) { $template->assign_block_vars('searchresults', array( 'S_IGNORE_POST' => true, 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "', '')) ); continue; } // Replace naughty words such as farty pants $row['post_subject'] = censor_text($row['post_subject']); if ($row['display_text_only']) { // now find context for the searched words $row['post_text'] = get_context($row['post_text'], array_filter(explode('|', $hilit), 'strlen'), $return_chars); $row['post_text'] = bbcode_nl2br($row['post_text']); } else { // Second parse bbcode here if ($row['bbcode_bitfield']) { $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']); } $row['post_text'] = bbcode_nl2br($row['post_text']); $row['post_text'] = smiley_text($row['post_text']); if (!empty($attachments[$row['post_id']])) { parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count); // we only display inline attachments unset($attachments[$row['post_id']]); } } if ($hilit) { // post highlighting $row['post_text'] = preg_replace('#(?!<.*)(?]*(?:)#is', '$1', $row['post_text']); $row['post_subject'] = preg_replace('#(?!<.*)(?]*(?:)#is', '$1', $row['post_subject']); } $tpl_ary = array( 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_SUBJECT' => $row['post_subject'], 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '', 'MESSAGE' => $row['post_text'] ); } $template->assign_block_vars('searchresults', array_merge($tpl_ary, array( 'FORUM_ID' => $forum_id, 'TOPIC_ID' => $result_topic_id, 'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false, 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_TITLE' => $topic_title, 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id), 'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . (($u_hilit) ? '&hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '') )); } if ($topic_id && ($topic_id == $result_topic_id)) { $template->assign_vars(array( 'SEARCH_TOPIC' => $topic_title, 'U_SEARCH_TOPIC' => $view_topic_url )); } } unset($rowset); page_header(($l_search_title) ? $l_search_title : $user->lang['SEARCH']); $template->set_filenames(array( 'body' => 'search_results.html') ); make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer(); } // Search forum $s_forums = ''; $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.left_id, f.right_id, f.forum_password, fa.user_id FROM ' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "') ORDER BY f.left_id ASC"; $result = $db->sql_query($sql); $right = $cat_right = $padding_inc = 0; $padding = $forum_list = $holding = ''; $pad_store = array('0' => ''); while ($row = $db->sql_fetchrow($result)) { if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) { // Non-postable forum with no subforums, don't display continue; } if ($row['forum_type'] == FORUM_LINK || ($row['forum_password'] && !$row['user_id'])) { // if this forum is a link or password protected (user has not entered the password yet) then skip to the next branch continue; } if ($row['left_id'] < $right) { $padding .= '   '; $pad_store[$row['parent_id']] = $padding; } else if ($row['left_id'] > $right + 1) { if (isset($pad_store[$row['parent_id']])) { $padding = $pad_store[$row['parent_id']]; } else { continue; } } $right = $row['right_id']; if ($auth->acl_gets('!f_search', '!f_list', $row['forum_id'])) { // if the user does not have permissions to search or see this forum skip only this forum/category continue; } $selected = (in_array($row['forum_id'], $search_forum)) ? ' selected="selected"' : ''; if ($row['left_id'] > $cat_right) { // make sure we don't forget anything $s_forums .= $holding; $holding = ''; } if ($row['right_id'] - $row['left_id'] > 1) { $cat_right = max($cat_right, $row['right_id']); $holding .= ''; } else { $s_forums .= $holding . ''; $holding = ''; } } if ($holding) { $s_forums .= $holding; } $db->sql_freeresult($result); unset($pad_store); if (!$s_forums) { trigger_error('NO_SEARCH'); } // Number of chars returned $s_characters = ''; $s_characters .= ''; $s_characters .= ''; $s_characters .= ''; for ($i = 100; $i <= 1000 ; $i += 100) { $selected = ($i == 300) ? ' selected="selected"' : ''; $s_characters .= ''; } $s_hidden_fields = array('t' => $topic_id); if ($_SID) { $s_hidden_fields['sid'] = $_SID; } if (!empty($_EXTRA_URL)) { foreach ($_EXTRA_URL as $url_param) { $url_param = explode('=', $url_param, 2); $s_hidden_fields[$url_param[0]] = $url_param[1]; } } $template->assign_vars(array( 'S_SEARCH_ACTION' => "{$phpbb_root_path}search.$phpEx", 'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields), 'S_CHARACTER_OPTIONS' => $s_characters, 'S_FORUM_OPTIONS' => $s_forums, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_IN_SEARCH' => true, )); // only show recent searches to search administrators if ($auth->acl_get('a_search')) { // Handle large objects differently for Oracle and MSSQL switch ($db->sql_layer) { case 'oracle': $sql = 'SELECT search_time, search_keywords FROM ' . SEARCH_RESULTS_TABLE . ' WHERE dbms_lob.getlength(search_keywords) > 0 ORDER BY search_time DESC'; break; case 'mssql': case 'mssql_odbc': $sql = 'SELECT search_time, search_keywords FROM ' . SEARCH_RESULTS_TABLE . ' WHERE DATALENGTH(search_keywords) > 0 ORDER BY search_time DESC'; break; default: $sql = 'SELECT search_time, search_keywords FROM ' . SEARCH_RESULTS_TABLE . ' WHERE search_keywords <> \'\' ORDER BY search_time DESC'; break; } $result = $db->sql_query_limit($sql, 5); while ($row = $db->sql_fetchrow($result)) { $keywords = $row['search_keywords']; $template->assign_block_vars('recentsearch', array( 'KEYWORDS' => $keywords, 'TIME' => $user->format_date($row['search_time']), 'U_KEYWORDS' => append_sid("{$phpbb_root_path}search.$phpEx", 'keywords=' . urlencode(htmlspecialchars_decode($keywords))) )); } $db->sql_freeresult($result); } // Output the basic page page_header($user->lang['SEARCH']); $template->set_filenames(array( 'body' => 'search_body.html') ); make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer(); ?>