pollpress_filter('the_content'); $this->factory = new pollpress_poll_factory(); $this->options_controller = new pollpress_controller_options(); } function generate_report($matches) { $poll_id = $matches[1]; $poll = $this->factory->get_poll($poll_id); $options = $poll->get_options(); $report = ''; // spit out the css file if ( !$css_included ) { $report .= ''; $css_included = true; } // Tally up the total votes $total_votes = 0; foreach ( $options as $option ) { $total_votes += $option->get_votes(); } // Actually generate the code $report .= '
'; foreach ( $options as $option ) { $percentage = 0; if ( $total_votes != 0 ) $percentage = round( ($option->get_votes() * 100) / $total_votes ); $report .= ''; $report .= ''; $report .= ''; $report .= ''; $report .= ''; $report .= ''; $report .= '
' . $option->get_text() . '
' . $option->get_votes() . ' ' . __('votes') . ' / ' . $percentage . '%
'; } $report .= '

' . $total_votes . ' ' . __('total votes.') . '

'; $report .= '
'; $report .= '
'; return $report; } function process($data) { $this->color = $this->options_controller->get_bar_color(); // $regex = '/<[p|P][o|O][l|L][l|L]\s+[i|I][d|D]\s*=\s*"(\d+)"\s+\/>/'; $modified_data = preg_replace_callback($regex, array(&$this, 'generate_report'), $data); return $modified_data; } } ?>