pollpress_controller('edit.php', 'Polls', 'pollpress_view_manage.php');
}
function dispatch() {
// For now, just get all the polls. Later we should filter them
$this->factory = new pollpress_poll_factory();
// See if this is an operation or not
if ( isset( $_GET['op'] ) && isset( $_GET['id'] ) ) {
$id = (int) $_GET['id'];
$poll = $this->factory->get_poll( $option_id );
switch ( $_GET['op'] ) {
case 'delete':
check_admin_referer('delete-poll_' . $poll->get_id());
if ( current_user_can('edit_post', $poll->get_post_id() ) )
$poll->destroy();
break;
}
}
// Get the all appropriate polls for this page
if ( isset( $_GET['s'] ) ) {
$this->polls = $this->factory->get_polls_with_text( $_GET['s'] );
} else if ( isset( $_GET['m'] ) ) {
$year = (int)substr($_GET['m'], 0, 4);
$month = (int)substr($_GET['m'], 4, 2);
$this->polls = $this->factory->get_polls_in_month($year, $month);
} else if ( isset( $_GET['id'] ) && isset( $_GET['c'] ) ) {
$id = (int) $_GET['id'];
$this->poll = $this->factory->get_poll($id);
array_push($this->polls, $this->poll);
} else {
$this->polls = $this->factory->get_all_polls_by_date();
}
// Figure out what page we're on
$this->poll_count = count($this->polls);
if ( isset( $_GET['p'] ) ) {
$this->current_page = (int)$_GET['p'];
}
$this->poll_start_index = $this->current_page * $this->polls_per_page;
$this->poll_stop_index = $this->poll_start_index + $this->polls_per_page;
if ( $this->poll_stop_index > $this->poll_count )
$this->poll_stop_index = $this->poll_count;
// Now that we know the indices, strip down the array
$this->polls = array_slice($this->polls, $this->poll_start_index, $this->poll_stop_index - $this->poll_start_index);
}
function get_polls() {
return $this->polls;
}
function get_months_for_polls() {
return $this->factory->get_months_for_polls();
}
function next_polls_link($text) {
if ( $this->poll_stop_index < $this->poll_count ) {
$next_page = $this->current_page + 1;
echo '' . $text . '';
}
}
function previous_polls_link($text) {
if ( $this->current_page > 0 ) {
$next_page = $this->current_page - 1;
echo '' . $text . '';
}
}
function page_title() {
if ( isset( $_GET['m'] ) ) {
global $month;
$my_year = substr($_GET['m'], 0, 4);
$my_month = $month[substr($_GET['m'], 4, 2)];
echo ' ' . $my_month . ' ' . $my_year;
} elseif ( isset( $_GET['s'] ) ) {
printf(__('Search Polls for “%s”'), wp_specialchars($_GET['s']) );
} else {
if ( isset( $_GET['c'] ) )
printf(__('Comments on %s'), $this->poll->get_title());
elseif ( ! isset( $_GET['p'] ) || $_GET['p'] == 0 )
_e('Last 15 Polls');
else
_e('Previous Polls');
}
}
function drafts($drafts) {
$i = 0;
foreach ($drafts as $draft) {
if (0 != $i)
echo ', ';
$poll_title = stripslashes($draft->get_title());
if ($poll_title == '')
$poll_title = sprintf(__('Poll #%s'), $draft->get_id());
echo "" . $poll_title . "";
++$i;
}
}
function get_users_poll_drafts($user_id) {
$user_id = (int) $user_id;
return $this->factory->get_draft_polls($user_id);
}
function get_others_poll_drafts($user_id) {
$user_id = (int) $user_id;
return $this->factory->get_others_draft_polls($user_id);
}
}
?>