コード例 #1
0
ファイル: wp-postratings.php プロジェクト: nvvetal/water
function create_ratinglogs_table()
{
    global $wpdb;
    postratings_textdomain();
    if (@is_file(ABSPATH . '/wp-admin/includes/upgrade.php')) {
        include_once ABSPATH . '/wp-admin/includes/upgrade.php';
    } else {
        die('We have problem finding your \'/wp-admin/upgrade-functions.php\' and \'/wp-admin/includes/upgrade.php\'');
    }
    $charset_collate = '';
    if ($wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    // Create Post Ratings Table
    $create_ratinglogs_sql = "CREATE TABLE {$wpdb->ratings} (" . "rating_id INT(11) NOT NULL auto_increment," . "rating_postid INT(11) NOT NULL ," . "rating_posttitle TEXT NOT NULL," . "rating_rating INT(2) NOT NULL ," . "rating_timestamp VARCHAR(15) NOT NULL ," . "rating_ip VARCHAR(40) NOT NULL ," . "rating_host VARCHAR(200) NOT NULL," . "rating_username VARCHAR(50) NOT NULL," . "rating_userid int(10) NOT NULL default '0'," . "PRIMARY KEY (rating_id)) {$charset_collate};";
    maybe_create_table($wpdb->ratings, $create_ratinglogs_sql);
    // Add In Options (4 Records)
    add_option('postratings_image', 'stars');
    add_option('postratings_max', '5');
    add_option('postratings_template_vote', '%RATINGS_IMAGES_VOTE% (<strong>%RATINGS_USERS%</strong> ' . __('votes', 'wp-postratings') . __(',', 'wp-postratings') . ' ' . __('average', 'wp-postratings') . ': <strong>%RATINGS_AVERAGE%</strong> ' . __('out of', 'wp-postratings') . ' %RATINGS_MAX%)<br />%RATINGS_TEXT%');
    add_option('postratings_template_text', '%RATINGS_IMAGES% (<em><strong>%RATINGS_USERS%</strong> ' . __('votes', 'wp-postratings') . __(',', 'wp-postratings') . ' ' . __('average', 'wp-postratings') . ': <strong>%RATINGS_AVERAGE%</strong> ' . __('out of', 'wp-postratings') . ' %RATINGS_MAX%' . __(',', 'wp-postratings') . ' <strong>' . __('rated', 'wp-postratings') . '</strong></em>)');
    add_option('postratings_template_none', '%RATINGS_IMAGES_VOTE% (' . __('No Ratings Yet', 'wp-postratings') . ')<br />%RATINGS_TEXT%');
    // Database Upgrade For WP-PostRatings 1.02
    add_option('postratings_logging_method', '3');
    add_option('postratings_allowtorate', '2');
    // Database Uprade For WP-PostRatings 1.04
    maybe_add_column($wpdb->ratings, 'rating_userid', "ALTER TABLE {$wpdb->ratings} ADD rating_userid INT( 10 ) NOT NULL DEFAULT '0';");
    // Database Uprade For WP-PostRatings 1.05
    add_option('postratings_ratingstext', array(__('1 Star', 'wp-postratings'), __('2 Stars', 'wp-postratings'), __('3 Stars', 'wp-postratings'), __('4 Stars', 'wp-postratings'), __('5 Stars', 'wp-postratings')));
    add_option('postratings_template_highestrated', '<li><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a> %RATINGS_IMAGES% (%RATINGS_AVERAGE% ' . __('out of', 'wp-postratings') . ' %RATINGS_MAX%)</li>');
    // Database Upgrade For WP-PostRatings 1.11
    add_option('postratings_ajax_style', array('loading' => 1, 'fading' => 1));
    // Database Upgrade For WP-PostRatings 1.20
    add_option('postratings_ratingsvalue', array(1, 2, 3, 4, 5));
    add_option('postratings_customrating', 0);
    add_option('postratings_template_permission', '%RATINGS_IMAGES% (<em><strong>%RATINGS_USERS%</strong> ' . __('votes', 'wp-postratings') . __(',', 'wp-postratings') . ' ' . __('average', 'wp-postratings') . ': <strong>%RATINGS_AVERAGE%</strong> ' . __('out of', 'wp-postratings') . ' %RATINGS_MAX%</em>)<br /><em>' . __('You need to be a registered member to rate this post.', 'wp-postratings') . '</em>');
    // Database Upgrade For WP-PostRatings 1.30
    add_option('postratings_template_mostrated', '<li><a href="%POST_URL%"  title="%POST_TITLE%">%POST_TITLE%</a> - %RATINGS_USERS% ' . __('votes', 'wp-postratings') . '</li>');
    // Database Upgrade For WP-PostRatings 1.50
    delete_option('widget_ratings_highest_rated');
    delete_option('widget_ratings_most_rated');
    // Set 'manage_ratings' Capabilities To Administrator
    $role = get_role('administrator');
    if (!$role->has_cap('manage_ratings')) {
        $role->add_cap('manage_ratings');
    }
}
コード例 #2
0
function widget_ratings_init()
{
    postratings_textdomain();
    register_widget('WP_Widget_PostRatings');
}
コード例 #3
0
function process_ratings()
{
    global $wpdb, $user_identity, $user_ID;
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'postratings') {
        $rate = intval($_REQUEST['rate']);
        $post_id = intval($_REQUEST['pid']);
        // Verify Referer
        if (!check_ajax_referer('postratings_' . $post_id . '-nonce', 'postratings_' . $post_id . '_nonce', false)) {
            _e('Failed To Verify Referrer', 'wp-postratings');
            exit;
        }
        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') . '');
            postratings_textdomain();
            $rated = check_rated($post_id);
            // Check Whether Post Has Been Rated By User
            if (!$rated) {
                // Check Whether Is There A Valid Post
                $post = get_post($post_id);
                // If Valid Post Then We Rate It
                if ($post && !wp_is_post_revision($post)) {
                    $ratings_max = intval(get_option('postratings_max'));
                    $ratings_custom = intval(get_option('postratings_customrating'));
                    $ratings_value = get_option('postratings_ratingsvalue');
                    $post_title = addslashes($post->post_title);
                    $post_ratings = get_post_custom($post_id);
                    $post_ratings_users = !empty($post_ratings['ratings_users']) ? intval($post_ratings['ratings_users'][0]) : 0;
                    $post_ratings_score = !empty($post_ratings['ratings_score']) ? intval($post_ratings['ratings_score'][0]) : 0;
                    // Check For Ratings Lesser Than 1 And Greater Than $ratings_max
                    if ($rate < 1 || $rate > $ratings_max) {
                        $rate = 0;
                    }
                    $post_ratings_users = $post_ratings_users + 1;
                    $post_ratings_score = $post_ratings_score + intval($ratings_value[$rate - 1]);
                    $post_ratings_average = round($post_ratings_score / $post_ratings_users, 2);
                    update_post_meta($post_id, 'ratings_users', $post_ratings_users);
                    update_post_meta($post_id, 'ratings_score', $post_ratings_score);
                    update_post_meta($post_id, 'ratings_average', $post_ratings_average);
                    // Add Log
                    if (!empty($user_identity)) {
                        $rate_user = addslashes($user_identity);
                    } elseif (!empty($_COOKIE['comment_author_' . COOKIEHASH])) {
                        $rate_user = addslashes($_COOKIE['comment_author_' . COOKIEHASH]);
                    } else {
                        $rate_user = __('Guest', 'wp-postratings');
                    }
                    $rate_user = apply_filters('wp_postratings_process_ratings_user', $rate_user);
                    $rate_userid = apply_filters('wp_postratings_process_ratings_userid', intval($user_ID));
                    // Only Create Cookie If User Choose Logging Method 1 Or 3
                    $postratings_logging_method = intval(get_option('postratings_logging_method'));
                    if ($postratings_logging_method == 1 || $postratings_logging_method == 3) {
                        $rate_cookie = setcookie("rated_" . $post_id, $ratings_value[$rate - 1], apply_filters('wp_postratings_cookie_expiration', time() + 30000000), apply_filters('wp_postratings_cookiepath', SITECOOKIEPATH));
                    }
                    // Log Ratings No Matter What
                    $rate_log = $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->ratings} VALUES (%d, %d, %s, %d, %d, %s, %s, %s, %d )", 0, $post_id, $post_title, $ratings_value[$rate - 1], current_time('timestamp'), get_ipaddress(), @gethostbyaddr(get_ipaddress()), $rate_user, $rate_userid));
                    // Allow Other Plugins To Hook When A Post Is Rated
                    do_action('rate_post', $rate_userid, $post_id, $ratings_value[$rate - 1]);
                    // Output AJAX Result
                    echo the_ratings_results($post_id, $post_ratings_users, $post_ratings_score, $post_ratings_average);
                    exit;
                } else {
                    printf(__('Invalid Post ID (#%s).', 'wp-postratings'), $post_id);
                    exit;
                }
                // End if($post)
            } else {
                printf(__('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'), $post_id);
                exit;
            }
            // End if(!$rated)
        }
        // End if($rate && $post_id && check_allowtorate())
    }
    // End if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'postratings')
}