get_var("SHOW TABLES LIKE \"$rating_table_name\"") != $rating_table_name) { $wpdb->query("CREATE TABLE IF NOT EXISTS $rating_table_name ( 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', comment_id int(11) NOT NULL, PRIMARY KEY (rating_id) ) ENGINE=MyISAM"); } /** * Function Name: geocraft_save_comment_rating * Description: Inserts rating values * @global type $wpdb * @global string $rating_table_name * @global type $post * @global type $user_ID * @global type $current_user * @param type $comment_id */ function geocraft_save_comment_rating($comment_id = 0) { global $wpdb, $post, $user_ID, $current_user; $rating_table_name = GC_RATING_TBL; $rate_user = $user_ID; $rate_userid = $user_ID; $post_id = $_REQUEST['post_id']; $post_title = $post->post_title; $rating_var = "post_" . $post_id . "_rating"; $rating_val = $_REQUEST["$rating_var"]; if (!$rating_val) { $rating_val = 0; } $rating_ip = getenv("REMOTE_ADDR"); if (!$rate_userid) { $rate_userid = $current_user->ID; } $wpdb->insert( $rating_table_name, array( 'rating_postid' => $post_id, 'rating_rating' => $rating_val, 'comment_id' => $comment_id, 'rating_ip' => $rating_ip, 'rating_userid' => $rate_userid ) ); } add_action('wp_insert_comment', 'geocraft_save_comment_rating'); /** * Function Name: geocraft_del_comment_rating * Description: Delete the rating with comment * @global type $wpdb * @global string $rating_table_name * @global type $post * @global type $user_ID * @param type $comment_id */ function geocraft_del_comment_rating($comment_id = 0) { global $wpdb, $post, $user_ID; $rating_table_name = GC_RATING_TBL; if ($comment_id) { $wpdb->query("delete from $rating_table_name where comment_id=\"$comment_id\""); } } add_action('wp_delete_comment', 'geocraft_del_comment_rating'); /** * Function Name: geocraft_draw_rating_star * Description: Displaying users ratings * @global type $rating_star_on * @global type $rating_star_off * @param type $avg_rating * @return string */ function geocraft_display_rating_star($avg_rating) { $rating_star_on = GC_RATING_STAR_ON; $rating_star_off = GC_RATING_STAR_OFF; $rtn_str = ''; for ($i = 0; $i < $avg_rating; $i++) { $rtn_str .= '