/** * check witch rating plugin exist in wp and rate post * @param int $postId * @param int $rating * @param int $user_id * @return bool */ function wiziapp_do_actual_rating($postId, $rating = 0, $user_id = 0) { $GLOBALS['WiziappLog']->write('info', "Got a rating request with {$postId}::{$rating}::{$user_id}", "wiziapp_do_rating"); $postId = intval($postId); $rating = intval($rating); if (filter_var($user_id, FILTER_VALIDATE_IP)) { $ip = $user_id; $user_id = 0; } else { $ip = $_SERVER['REMOTE_ADDR']; $user_id = intval($user_id); } if ($rating < 1 && $rating > 5) { return false; } //polldaddy rating $id = get_option('pd-rating-posts-id'); if (function_exists('polldaddy_show_rating_comments') && $id > 0) { $url = 'http://polldaddy.com/ratings/rate.php?'; $url_query = array(); $url_query['cmd'] = 'get'; $url_query['id'] = get_option('pd-rating-posts-id'); $url_query['uid'] = 'wp-post-' . $postId; $url_query['item_id'] = '_post_' . $postId; $link = $url . http_build_query($url_query); $matches = array(); $get_content = wiziapp_general_http_request('', $link, 'GET'); $get_content = $get_content['body']; preg_match("/\\.token='([a-z0-9]*)/", $get_content, $matches); $url_query['token'] = $matches[1]; preg_match("/\\.avg_rating = ([a-z0-9]*)/", $get_content, $matches); $url_query['avg'] = $matches[1]; preg_match("/\\.votes = ([a-z0-9]*)/", $get_content, $matches); $url_query['votes'] = $matches[1]; $post = get_post($postId); $url_query['title'] = str_replace('&', '&', $post->post_title); $url_query['permalink'] = $post->guid; $url_query['type'] = 'stars'; $url_query['cmd'] = 'rate'; $url_query['r'] = $rating; $link = $url . http_build_query($url_query); wiziapp_general_http_request('', $link, 'GET'); return true; } //GD Star rating global $gdsr; if (is_object($gdsr) && get_class($gdsr) == 'GDStarRating') { $ua = $_SERVER["HTTP_USER_AGENT"]; gdsrBlgDB::save_vote($postId, $user_id, $ip, $ua, $rating); gdsrFrontHelp::save_cookie($postId); do_action("gdsr_vote_rating_article", $postId, $user_id, $rating); return true; } //WP-PostRatings if (function_exists('process_ratings') && $postId > 0 && $user_id > 0) { $_GET['rate'] = $rating; $_GET['pid'] = $postId; global $user_ID; $user_ID = $user_id; process_ratings(); return true; } return false; }
add_post_meta($post_ID, 'ratings_average', 0, true); } } ### Function:Delete Rating Custom Fields add_action('delete_post', 'delete_ratings_fields'); function delete_ratings_fields($post_ID) { global $wpdb; if (!wp_is_post_revision($post_ID)) { delete_post_meta($post_ID, 'ratings_users'); delete_post_meta($post_ID, 'ratings_score'); delete_post_meta($post_ID, 'ratings_average'); } } ### Function: Process Ratings process_ratings(); function process_ratings() { global $wpdb, $user_identity, $user_ID; $rate = intval($_GET['rate']); $post_id = intval($_GET['pid']); if ($rate > 0 && $post_id > 0 && check_allowtorate()) { // Check For Bot $bots_useragent = array('googlebot', 'google', 'msnbot', 'ia_archiver', 'lycos', 'jeeves', 'scooter', 'fast-webcrawler', 'slurp@inktomi', 'turnitinbot', 'technorati', 'yahoo', 'findexa', 'findlinks', 'gaisbo', 'zyborg', 'surveybot', 'bloglines', 'blogsearch', 'ubsub', 'syndic8', 'userland', 'gigabot', 'become.com'); $useragent = $_SERVER['HTTP_USER_AGENT']; foreach ($bots_useragent as $bot) { if (stristr($useragent, $bot) !== false) { return; } } header('Content-Type: text/html; charset=' . get_option('blog_charset') . '');