function bbpvotes_post_vote_ajax() { $result = array('success' => false); if (!isset($_POST['post_id'])) { return false; } $action = $_POST['action']; $post_id = $_POST['post_id']; if ($action == 'bbpvotes_post_vote_up') { $nonce = 'vote-up-post_' . $post_id; } else { if ($action == 'bbpvotes_post_vote_down') { $nonce = 'vote-down-post_' . $post_id; } } if (!wp_verify_nonce($_POST['_wpnonce'], $nonce)) { return false; } if ($action == 'bbpvotes_post_vote_up') { $vote = bbpvotes()->do_post_vote($post_id, true); } else { if ($action == 'bbpvotes_post_vote_down') { $vote = bbpvotes()->do_post_vote($post_id, false); } } if (!is_wp_error($vote)) { $result['success'] = true; $score = bbpvotes_get_votes_score_for_post($post_id); $score_display = bbpvotes_number_format($score); $votes_count = bbpvotes_get_votes_count_for_post($post_id); $vote_count_display = bbpvotes_number_format($votes_count); $result['score_text'] = sprintf(__('Score: %1$s', 'bbpvotes'), $score_display); $result['score_title'] = sprintf(__('Votes count: %1$s', 'bbpvotes'), $vote_count_display); } else { $result['message'] = $vote->get_error_message(); } header('Content-type: application/json'); echo json_encode($result); die; }
function bbpvotes_get_post_votes_log($post_id = 0) { if (!($votes = bbpvotes_get_votes_for_post($post_id))) { return; } $r = "\n\n" . '<div id="bbpvotes-post-votes-log-' . esc_attr($post_id) . '" class="bbpvotes-post-votes-log">' . "\n\n"; if (!bbpvotes()->options['anonymous_vote']) { foreach ($votes as $user_id => $score) { $user_id = bbp_get_user_id($user_id); if (!($user = get_userdata($user_id))) { continue; } if ($score > 0) { $title = sprintf(esc_html__('%1$s voted up', 'bbpvotes'), $user->display_name); $icon = '<i class="bbpvotes-avatar-icon-vote bbpvotes-avatar-icon-plus fa fa-plus-square"></i>'; } else { $title = sprintf(esc_html__('%1$s voted down', 'bbpvotes'), $user->display_name); $icon = '<i class="bbpvotes-avatar-icon-vote bbpvotes-avatar-icon-minus fa fa-minus-square"></i>'; } $user_avatar = get_avatar($user_id, 30); $user_vote_link = sprintf('<a title="%1$s" href="%2$s">%3$s</a>', $title, esc_url(bbp_get_user_profile_url($user_id)), $user_avatar . $icon); $r .= apply_filters('bbpvotes_get_post_votes_log_user', $user_vote_link, $user_id, $score); } } else { $votes_str = array(); if ($votes_up = bbpvotes_get_votes_up_for_post($post_id)) { $votes_up_count = count($votes_up); $votes_up_count_display = bbpvotes_number_format($votes_up_count); $votes_str[] = sprintf(_n('%s vote up', '%s votes up', $votes_up_count), '<span class="bbpvotes-score">' . $votes_up_count_display . '</span>'); } if ($votes_down = bbpvotes_get_votes_down_for_post($post_id)) { $votes_down_count = count($votes_down); $votes_down_count_display = bbpvotes_number_format($votes_down_count); $votes_str[] = sprintf(_n('%s vote down', '%s votes down', $votes_down_count), '<span class="bbpvotes-score">' . $votes_down_count_display . '</span>'); } $votes_str = implode(' ' . __('and', 'bbpvotes') . ' ', $votes_str); $r .= sprintf(__('This reply has received %1$s.', 'bbpvotes'), $votes_str); } $r .= "\n" . '</div>' . "\n\n"; return apply_filters('bbpvotes_get_post_votes_log', $r, $post_id); }
function display_topic_score() { if (!($votes = bbpvotes_get_votes_for_post(bbp_get_topic_id()))) { return; } $score = bbpvotes_get_votes_score_for_post(bbp_get_topic_id()); $score_display = bbpvotes_number_format($score); printf('<span class="bbpvotes-topic-score">%1$s</span>', sprintf(__('Score: %s pts', 'bbpvotes'), '<span class="bbpvotes-score">' . $score_display . '</span>')); }