function phpbb_fetch_poll($forum_id = null) { global $CFG; // // create a list of forums with read permission // (only takes action when auth_check is enabled) // phpbb_get_auth_list(); // // determine the forum list based on the user input // and/or permissions (depends on auth check) // $forum_list = phpbb_get_forum_list($forum_id); // // if read permissions do not allow us to fetch anything // we return nicely // if (!$forum_list and $CFG['auth_check']) { return; } $sql = 'SELECT f.*, p.*, pt.*, t.*, u.*, vd.* FROM ' . TOPICS_TABLE . ' AS t, ' . USERS_TABLE . ' AS u, ' . POSTS_TEXT_TABLE . ' AS pt, ' . POSTS_TABLE . ' AS p, ' . FORUMS_TABLE . ' AS f, ' . VOTE_DESC_TABLE . ' AS vd WHERE t.topic_poster = u.user_id AND t.topic_first_post_id = pt.post_id AND t.topic_first_post_id = p.post_id AND t.topic_status <> 1 AND t.topic_status <> 2 AND t.topic_vote = 1 AND t.forum_id = f.forum_id AND t.topic_id = vd.topic_id'; if ($forum_list) { $sql .= ' AND t.forum_id IN (' . $forum_list . ')'; } $sql .= ' ORDER BY p.post_time DESC LIMIT 0,1'; $result = phpbb_fetch_row($sql); if ($result) { $sql = 'SELECT * FROM ' . VOTE_RESULTS_TABLE . ' WHERE vote_id = ' . $result['vote_id'] . ' ORDER BY vote_option_id'; $result['options'] = phpbb_fetch_rows($sql); } return $result; }
function phpbb_fetch_posts($forum_id = null, $fetch_mode = POSTS_FETCH_FIRST) { global $CFG, $userdata; // // sanity check for dates // if ($CFG['posts_date_offset_start'] >= $CFG['posts_date_offset_end']) { phpbb_raise_error('\'posts_date_offset_start\' has to be smaller ' . 'than \'posts_date_offset_end\''); } // // create a list of forums with read permission // (only takes action when auth_check is enabled) // phpbb_get_auth_list(); // // determine the forum list based on the user input // and/or permissions (depends on auth check) // $forum_list = phpbb_get_forum_list($forum_id); // // if read permissions do not allow us to fetch anything // we return nicely // if (!$forum_list and $CFG['auth_check']) { return; } $sql = 'SELECT f.*, p.*, pt.*, t.*, u.*'; if (!$CFG['posts_hide_ranks']) { $sql .= ', r.*'; } $sql .= ' FROM ' . TOPICS_TABLE . ' AS t, ' . USERS_TABLE . ' AS u, ' . POSTS_TEXT_TABLE . ' AS pt, ' . POSTS_TABLE . ' AS p, ' . FORUMS_TABLE . ' AS f'; if (!$CFG['posts_hide_ranks']) { $sql .= ', ' . RANKS_TABLE . ' AS r'; } $sql .= ' WHERE'; if ($forum_list) { $sql .= ' t.forum_id IN (' . $forum_list . ') AND'; } if ($fetch_mode == POSTS_FETCH_FIRST) { $sql .= ' t.topic_first_post_id = pt.post_id AND t.topic_first_post_id = p.post_id AND'; } else { $sql .= ' t.topic_last_post_id = pt.post_id AND t.topic_last_post_id = p.post_id AND'; } if ($CFG['posts_date_offset_start']) { $sql .= ' p.post_time >= ' . $CFG['posts_date_offset_start'] . ' AND'; } if ($CFG['posts_date_offset_end']) { $sql .= ' p.post_time <= ' . $CFG['posts_date_offset_end'] . ' AND'; } if ($CFG['posts_hide_normal']) { $sql .= ' t.topic_type <> 0 AND'; } if ($CFG['posts_hide_sticky']) { $sql .= ' t.topic_type <> 1 AND'; } if ($CFG['posts_hide_announcements']) { $sql .= ' t.topic_type <> 2 AND'; } if ($CFG['posts_hide_locked']) { $sql .= ' t.topic_status <> 1 AND'; } if ($CFG['posts_hide_moved']) { $sql .= ' t.topic_status <> 2 AND'; } if ($CFG['posts_hide_polls']) { $sql .= ' t.topic_vote <> 1 AND'; } if ($CFG['posts_search_string']) { $sql .= ' (' . $CFG['posts_search_string'] . ') AND'; } $sql .= ' t.forum_id = f.forum_id AND'; if (!$CFG['posts_hide_ranks']) { $sql .= ' r.rank_id = u.user_rank AND'; } $sql .= ' u.user_id = p.poster_id'; $sql .= ' ORDER BY ' . $CFG['posts_order']; if ($CFG['posts_span_pages']) { $CFG['posts_span_pages_numrows'] = phpbb_numrows(phpbb_query($sql)); if ($CFG['posts_span_pages_offset'] > $CFG['posts_span_pages_numrows']) { $CFG['posts_span_pages_offset'] = $CFG['posts_span_pages_numrows'] - 1; } $CFG['posts_offset'] = $CFG['posts_span_pages_offset']; } else { $CFG['posts_offset'] = 0; } if ($CFG['posts_limit'] != 0) { $sql .= ' LIMIT ' . $CFG['posts_offset'] . ',' . $CFG['posts_limit']; } $result = phpbb_fetch_rows($sql); if ($result) { $orig_word = array(); $replacement_word = array(); obtain_word_list($orig_word, $replacement_word); for ($i = 0; $i < count($result); $i++) { $result[$i]['post_time'] = $result[$i]['post_time'] + $CFG['time_zone']; $result[$i]['topic_time'] = $result[$i]['topic_time'] + $CFG['time_zone']; $result[$i]['date'] = date($CFG['date_format'], $result[$i]['post_time']); $result[$i]['time'] = date($CFG['time_format'], $result[$i]['post_time']); if (isset($result[$i]['post_edit_time'])) { $result[$i]['edit_date'] = date($CFG['date_format'], $result[$i]['post_edit_time']); $result[$i]['edit_time'] = date($CFG['time_format'], $result[$i]['post_edit_time']); } else { $result[$i]['edit_date'] = ''; $result[$i]['edit_time'] = ''; } $result[$i]['post_text'] = phpbb_parse_text($result[$i]['post_text'], $result[$i]['bbcode_uid'], $result[$i]['enable_smilies'], $CFG['posts_enable_bbcode'], $CFG['posts_enable_html'], $CFG['posts_hide_images'], $CFG['posts_replace_images']); if (count($orig_word)) { $result[$i]['topic_title'] = preg_replace($orig_word, $replacement_word, $result[$i]['topic_title']); $result[$i]['post_text'] = preg_replace($orig_word, $replacement_word, $result[$i]['post_text']); } $result[$i]['trimmed'] = false; phpbb_trim_text($result[$i]['post_text'], $result[$i]['trimmed'], $CFG['posts_trim_text_character'], $CFG['posts_trim_text_number'], $CFG['posts_trim_text_words']); $result[$i]['topic_trimmed'] = false; phpbb_trim_text($result[$i]['topic_title'], $result[$i]['topic_trimmed'], '', $CFG['posts_trim_topic_number'], ''); } } return $result; }