Exemplo n.º 1
0
function display_pollvote($poll_id, $display_loading = true)
{
    do_action('wp_polls_display_pollvote');
    global $wpdb;
    // Temp Poll Result
    $temp_pollvote = '';
    // Get Poll Question Data
    $poll_question = $wpdb->get_row("SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM {$wpdb->pollsq} WHERE pollq_id = {$poll_id} LIMIT 1");
    // Poll Question Variables
    $poll_question_text = wp_kses_post(stripslashes($poll_question->pollq_question));
    $poll_question_id = intval($poll_question->pollq_id);
    $poll_question_totalvotes = intval($poll_question->pollq_totalvotes);
    $poll_question_totalvoters = intval($poll_question->pollq_totalvoters);
    $poll_start_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_question->pollq_timestamp));
    $poll_expiry = trim($poll_question->pollq_expiry);
    if (empty($poll_expiry)) {
        $poll_end_date = __('No Expiry', 'wp-polls');
    } else {
        $poll_end_date = mysql2date(sprintf(__('%s @ %s', 'wp-polls'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', $poll_expiry));
    }
    $poll_multiple_ans = intval($poll_question->pollq_multiple);
    $template_question = stripslashes(get_option('poll_template_voteheader'));
    $template_question = apply_filters('poll_template_voteheader_markup', $template_question, $poll_question, array('%POLL_QUESTION%' => $poll_question_text, '%POLL_ID%' => $poll_question_id, '%POLL_TOTALVOTES%' => $poll_question_totalvotes, '%POLL_TOTALVOTERS%' => $poll_question_totalvoters, '%POLL_START_DATE%' => $poll_start_date, '%POLL_END_DATE%' => $poll_end_date, '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1));
    // Get Poll Answers Data
    list($order_by, $sort_order) = _polls_get_ans_sort();
    $poll_answers = $wpdb->get_results("SELECT polla_aid, polla_qid, polla_answers, polla_votes FROM {$wpdb->pollsa} WHERE polla_qid = {$poll_question_id} ORDER BY {$order_by} {$sort_order}");
    // If There Is Poll Question With Answers
    if ($poll_question && $poll_answers) {
        // Display Poll Voting Form
        $temp_pollvote .= "<div id=\"polls-{$poll_question_id}\" class=\"wp-polls\">\n";
        $temp_pollvote .= "\t<form id=\"polls_form_{$poll_question_id}\" class=\"wp-polls-form\" action=\"" . esc_attr($_SERVER['SCRIPT_NAME']) . "\" method=\"post\">\n";
        $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_{$poll_question_id}_nonce\" name=\"wp-polls-nonce\" value=\"" . wp_create_nonce('poll_' . $poll_question_id . '-nonce') . "\" /></p>\n";
        $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" name=\"poll_id\" value=\"{$poll_question_id}\" /></p>\n";
        if ($poll_multiple_ans > 0) {
            $temp_pollvote .= "\t\t<p style=\"display: none;\"><input type=\"hidden\" id=\"poll_multiple_ans_{$poll_question_id}\" name=\"poll_multiple_ans_{$poll_question_id}\" value=\"{$poll_multiple_ans}\" /></p>\n";
        }
        // Print Out Voting Form Header Template
        $temp_pollvote .= "\t\t{$template_question}\n";
        foreach ($poll_answers as $poll_answer) {
            // Poll Answer Variables
            $poll_answer_id = intval($poll_answer->polla_aid);
            $poll_answer_text = wp_kses_post(stripslashes($poll_answer->polla_answers));
            $poll_answer_votes = intval($poll_answer->polla_votes);
            $poll_answer_percentage = $poll_question_totalvoters > 0 ? round($poll_answer_votes / $poll_question_totalvoters * 100) : 0;
            $template_answer = stripslashes(get_option('poll_template_votebody'));
            $template_answer = apply_filters('poll_template_votebody_markup', $template_answer, $poll_answer, array('%POLL_ID%' => $poll_question_id, '%POLL_ANSWER_ID%' => $poll_answer_id, '%POLL_ANSWER%' => $poll_answer_text, '%POLL_ANSWER_VOTES%' => number_format_i18n($poll_answer_votes), '%POLL_ANSWER_PERCENTAGE%' => $poll_answer_percentage, "%POLL_CHECKBOX_RADIO%" => $poll_multiple_ans > 0 ? 'checkbox' : 'radio'));
            // Print Out Voting Form Body Template
            $temp_pollvote .= "\t\t{$template_answer}\n";
        }
        // Determine Poll Result URL
        $poll_result_url = $_SERVER['REQUEST_URI'];
        $poll_result_url = preg_replace('/pollresult=(\\d+)/i', 'pollresult=' . $poll_question_id, $poll_result_url);
        if (isset($_GET['pollresult']) && intval($_GET['pollresult']) == 0) {
            if (strpos($poll_result_url, '?') !== false) {
                $poll_result_url = "{$poll_result_url}&amp;pollresult={$poll_question_id}";
            } else {
                $poll_result_url = "{$poll_result_url}?pollresult={$poll_question_id}";
            }
        }
        // Voting Form Footer Variables
        $template_footer = stripslashes(get_option('poll_template_votefooter'));
        $template_footer = apply_filters('poll_template_votefooter_markup', $template_footer, $poll_question, array('%POLL_ID%' => $poll_question_id, '%POLL_RESULT_URL%' => $poll_result_url, '%POLL_START_DATE%' => $poll_start_date, '%POLL_END_DATE%' => $poll_end_date, '%POLL_MULTIPLE_ANS_MAX%' => $poll_multiple_ans > 0 ? $poll_multiple_ans : 1));
        // Print Out Voting Form Footer Template
        $temp_pollvote .= "\t\t{$template_footer}\n";
        $temp_pollvote .= "\t</form>\n";
        $temp_pollvote .= "</div>\n";
        if ($display_loading) {
            $poll_ajax_style = get_option('poll_ajax_style');
            if (intval($poll_ajax_style['loading']) == 1) {
                $temp_pollvote .= "<div id=\"polls-{$poll_question_id}-loading\" class=\"wp-polls-loading\"><img src=\"" . plugins_url('wp-polls/images/loading.gif') . "\" width=\"16\" height=\"16\" alt=\"" . __('Loading', 'wp-polls') . " ...\" title=\"" . __('Loading', 'wp-polls') . " ...\" class=\"wp-polls-image\" />&nbsp;" . __('Loading', 'wp-polls') . " ...</div>\n";
            }
        }
    } else {
        $temp_pollvote .= stripslashes(get_option('poll_template_disable'));
    }
    // Return Poll Vote Template
    return $temp_pollvote;
}
Exemplo n.º 2
0
### Check Whether User Can Manage Polls
if (!current_user_can('manage_polls')) {
    die('Access Denied');
}
### Variables
$max_records = 2000;
$pollip_answers = array();
$poll_question_data = $wpdb->get_row("SELECT pollq_multiple, pollq_question, pollq_totalvoters FROM {$wpdb->pollsq} WHERE pollq_id = {$poll_id}");
$poll_question = wp_kses_post(stripslashes($poll_question_data->pollq_question));
$poll_totalvoters = intval($poll_question_data->pollq_totalvoters);
$poll_multiple = intval($poll_question_data->pollq_multiple);
$poll_registered = $wpdb->get_var("SELECT COUNT(pollip_userid) FROM {$wpdb->pollsip} WHERE pollip_qid = {$poll_id} AND pollip_userid > 0");
$poll_comments = $wpdb->get_var("SELECT COUNT(pollip_user) FROM {$wpdb->pollsip} WHERE pollip_qid = {$poll_id} AND pollip_user != '" . __('Guest', 'wp-polls') . "' AND pollip_userid = 0");
$poll_guest = $wpdb->get_var("SELECT COUNT(pollip_user) FROM {$wpdb->pollsip} WHERE pollip_qid = {$poll_id} AND pollip_user = '******'Guest', 'wp-polls') . "'");
$poll_totalrecorded = $poll_registered + $poll_comments + $poll_guest;
list($order_by, $sort_order) = _polls_get_ans_sort();
$poll_answers_data = $wpdb->get_results("SELECT polla_aid, polla_answers FROM {$wpdb->pollsa} WHERE polla_qid = {$poll_id} ORDER BY " . $order_by . ' ' . $sort_order);
$poll_voters = $wpdb->get_col("SELECT DISTINCT pollip_user FROM {$wpdb->pollsip} WHERE pollip_qid = {$poll_id} AND pollip_user != '" . __('Guest', 'wp-polls') . "' ORDER BY pollip_user ASC");
$poll_logs_count = $wpdb->get_var("SELECT COUNT(pollip_id) FROM {$wpdb->pollsip} WHERE pollip_qid = {$poll_id}");
$exclude_registered = 0;
$exclude_comment = 0;
$exclude_guest = 0;
### Process Filters
if (!empty($_POST['do'])) {
    check_admin_referer('wp-polls_logs');
    $registered_sql = '';
    $comment_sql = '';
    $guest_sql = '';
    $users_voted_for_sql = '';
    $what_user_voted_sql = '';
    $num_choices_sql = '';