pollpress_filter('the_content'); $this->factory = new pollpress_poll_factory(); } function generate_page($matches) { $page = ''; // Strip down to the base URL $base_url = $_SERVER['REQUEST_URI']; $base_url = preg_replace('/[\?|\&]offset=\d+/', '', $base_url); $base_url = preg_replace('/[\?|\&]op=edit/', '', $base_url); $base_url = preg_replace('/[\?|\&]id=\d+/', '', $base_url); $append_option = '?'; if ( strstr($base_url, '?') ) $append_option = '&'; if ( isset( $_GET['id'] ) && isset( $_GET['op'] ) && $_GET['op'] == 'edit') { $id = (int) $_GET['id']; $page = $this->generate_voting_booth($base_url, $append_option, $id); } else { $page = $this->generate_poll_list($base_url, $append_option); } return $page; } function generate_voting_booth($base_url, $append_option, $poll_id) { $page = get_pollpress_voting_booth($poll_id, false); return $page; } function generate_poll_list($base_url, $append_option) { $page = ''; // Figure out what page we're on $polls = $this->factory->get_all_published_polls_by_date(); $poll_count = count($polls); if ( isset( $_GET['offset'] ) ) { $this->current_page = (int)$_GET['offset']; } $poll_start_index = $this->current_page * $this->polls_per_page; $poll_stop_index = $poll_start_index + $this->polls_per_page; if ( $poll_stop_index > $poll_count ) $poll_stop_index = $poll_count; // Now that we know the indices, strip down the array $polls = array_slice($polls, $poll_start_index, $poll_stop_index - $poll_start_index); // Iterate all the polls and output them if ( $poll_count ) { $page .= ''; $page .= ''; } // Navigation controls $page .= '

'; if ( $poll_stop_index < $poll_count ) { $next_page = $this->current_page + 1; $page .= '' . __('« Last 15 matches') . ''; } if ( ($poll_stop_index < $poll_count) && ($this->current_page > 0) ) { $page .= ' | '; } if ( $this->current_page > 0 ) { $next_page = $this->current_page - 1; $page .= '' . __('Next 15 matches »') . ''; } $page .= '

'; return $page; } function process($data) { // $regex = '/<[p|P][o|O][l|L][l|L]-[l|L][i|I][s|S][t|T]\s+\/>/'; $modified_data = preg_replace_callback($regex, array(&$this, 'generate_page'), $data); return $modified_data; } } ?>