function phpbb_fetch_poll_voters($vote_id = null) { if ($vote_id and !intval($vote_id)) { phpbb_raise_error('Vote ID must be a numeric value.', __FILE__, __LINE__); } $sql = 'SELECT * FROM ' . VOTE_USERS_TABLE . ' WHERE vote_id = ' . $vote_id . ' ORDER BY vote_user_id'; $result = phpbb_fetch_rows($sql); return $result; }
function phpbb_fetch_online_users($group_id = null) { global $CFG; // // sanity check // if ($group_id and !intval($group_id)) { phpbb_raise_error('Group ID must be a numeric value.', __FILE__, __LINE__); } // // build the sql string // $sql = 'SELECT u.user_id, u.username, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_time'; if ($group_id) { $sql .= ', g.*, ug.*'; } $sql .= ' FROM ' . USERS_TABLE . ' AS u, ' . SESSIONS_TABLE . ' AS s'; if ($group_id) { $sql .= ', ' . GROUPS_TABLE . ' AS g, ' . USER_GROUP_TABLE . ' AS ug'; } $sql .= ' WHERE u.user_id = s.session_user_id AND s.session_time >= ' . (time() - $CFG['users_session_time']); if ($group_id) { $sql .= ' AND g.group_id = ' . $group_id . ' AND ug.group_id = ' . $group_id . ' AND u.user_id = ug.user_id AND ug.user_pending = 0'; } $sql .= ' ORDER BY u.username ASC'; $result = phpbb_fetch_rows($sql); // // delete hidden and guest users // $cleanup = array(); $prev_user = 0; for ($i = 0; $i < count($result); $i++) { if ($result[$i]['session_logged_in']) { $user_id = $result[$i]['user_id']; if ($user_id != $prev_user) { if ($result[$i]['user_allow_viewonline']) { $cleanup[] = $result[$i]; } $prev_user = $user_id; } } } return $cleanup; }
function phpbb_fetch_forums($cat_id = null) { global $CFG, $userdata; // // build a list of categories if an array has been passed // $cat_list = ''; if ($cat_id) { if (!is_array($cat_id)) { $cat_list = $cat_id; } else { for ($i = 0; $i < count($cat_id); $i++) { $cat_list .= $cat_id[$i] . ','; } if ($cat_list) { $cat_list = substr($cat_list, 0, strlen($cat_list) - 1); } } } $sql = 'SELECT c.*, f.* FROM ' . CATEGORIES_TABLE . ' AS c, ' . FORUMS_TABLE . ' AS f WHERE f.forum_status = 0 AND f.cat_id = c.cat_id'; if ($cat_list) { $sql .= ' AND f.cat_id IN (' . $cat_list . ')'; } $sql .= ' ORDER BY c.cat_order, f.forum_order'; $result = phpbb_fetch_rows($sql); // // auth check if requested // if ($result and $CFG['auth_check']) { // // create a list of forums with read permission // (only takes action when auth_check is enabled) // phpbb_get_auth_list(); $authed = array(); for ($i = 0; $i < count($result); $i++) { if (in_array($result[$i]['forum_id'], $CFG['auth_list'])) { $authed[] = $result[$i]; } } $result = $authed; } return $result; }
function phpbb_fetch_newposts() { global $CFG, $userdata; if (!$userdata['session_logged_in']) { return; } $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE post_time >= ' . $userdata['user_lastvisit']; $result = phpbb_fetch_rows($sql); if (!$result) { return; } $search_ids = array(); for ($i = 0; $i < count($result); $i++) { $search_ids[] = $result[$i]['post_id']; } $sql = 'SELECT topic_id FROM ' . POSTS_TABLE . ' WHERE post_id IN (' . implode(', ', $search_ids) . ') GROUP BY topic_id ORDER BY post_time DESC'; $result = phpbb_fetch_rows($sql); if (!$result) { return; } $topic_ids = array(); for ($i = 0; $i < count($result); $i++) { $topic_ids[] = $result[$i]['topic_id']; } $result = phpbb_fetch_topics($topic_ids, POSTS_FETCH_LAST); return $result; }
function phpbb_fetch_stats() { global $CFG; $result = array(); // // total posts // $result['total_posts'] = get_db_stat('postcount'); // // total users // $result['total_users'] = get_db_stat('usercount'); // // newest user // $newest_user = get_db_stat('newestuser'); $result['user_id'] = $newest_user['user_id']; $result['username'] = $newest_user['username']; // // user online // $sql = 'SELECT session_id FROM ' . SESSIONS_TABLE . ' WHERE session_time >= ' . (time() - $CFG['stats_session_time']) . ' GROUP BY session_ip'; $user_online = phpbb_fetch_rows($sql); $result['user_online'] = count($user_online); // // total topics // $sql = 'SELECT COUNT( topic_id ) AS topics FROM ' . TOPICS_TABLE; $total_topics = phpbb_fetch_rows($sql); $result['total_topics'] = $total_topics[0][0]; return $result; }
function pafiledb_fetch_files($category_id = null) { global $CFG; $sql = 'SELECT * FROM phpbb_pa_files WHERE file_approved = 1'; if ($category_id) { if (!is_array($category_id)) { $sql .= ' AND file_catid = ' . $category_id; } else { $sql .= ' AND file_catid IN ('; for ($i = 0; $i < count($category_id); $i++) { $sql .= $category_id[$i] . ','; } $sql = substr($sql, 0, strlen($sql) - 1); $sql .= ')'; } } if ($CFG['pafiledb_fetch_files'] == 'newest') { $sql .= ' ORDER BY file_time DESC'; } if ($CFG['pafiledb_fetch_files'] == 'top') { $sql .= ' ORDER BY file_dls DESC'; } if ($CFG['pafiledb_fetch_files'] == 'random') { $sql .= ' ORDER BY RAND()'; } $sql .= ' LIMIT 0, ' . $CFG['file_limit']; $result = phpbb_fetch_rows($sql); return $result; }