WordPress.org

Make WordPress Core

Ticket #1683: 1683.diff

File 1683.diff, 5.6 KB (added by skeltoac, 16 years ago)

svn diff

  • wp-includes/functions-post.php

     
    456456        return false;
    457457}
    458458
    459 function wp_new_comment( $commentdata, $spam = false ) {
     459function wp_new_comment( $commentdata, $runchecks = true ) {
    460460        global $wpdb;
    461461
    462462        $commentdata = apply_filters('preprocess_comment', $commentdata);
     
    485485                $post_author = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = '$comment_post_ID' LIMIT 1");
    486486        }
    487487
    488         // Simple duplicate check
    489         $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$author' ";
    490         if ( $email ) $dupe .= "OR comment_author_email = '$email' ";
    491         $dupe .= ") AND comment_content = '$comment' LIMIT 1";
    492         if ( $wpdb->get_var($dupe) )
    493                 die( __('Duplicate comment detected; it looks as though you\'ve already said that!') );
     488        if ( $runchecks ) {
     489                // Simple duplicate check
     490                $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$author' ";
     491                if ( $email ) $dupe .= "OR comment_author_email = '$email' ";
     492                $dupe .= ") AND comment_content = '$comment' LIMIT 1";
     493                if ( $wpdb->get_var($dupe) )
     494                        die( __('Duplicate comment detected; it looks as though you\'ve already said that!') );
    494495
    495         // Simple flood-protection
    496         if ( $lasttime = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = '$user_ip' OR comment_author_email = '$email' ORDER BY comment_date DESC LIMIT 1") ) {
    497                 $time_lastcomment = mysql2date('U', $lasttime);
    498                 $time_newcomment  = mysql2date('U', $now_gmt);
    499                 if ( ($time_newcomment - $time_lastcomment) < 15 ) {
    500                         do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
    501                         die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
     496                // Simple flood-protection
     497                if ( $lasttime = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = '$user_ip' OR comment_author_email = '$email' ORDER BY comment_date DESC LIMIT 1") ) {
     498                        $time_lastcomment = mysql2date('U', $lasttime);
     499                        $time_newcomment  = mysql2date('U', $now_gmt);
     500                        if ( ($time_newcomment - $time_lastcomment) < 15 ) {
     501                                do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
     502                                die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
     503                        }
    502504                }
    503         }
    504505
    505         if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
     506                if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
     507                        $approved = 1;
     508                } else {
     509                        if ( check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) )
     510                                $approved = 1;
     511                        else
     512                                $approved = 0;
     513                        if ( wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) )
     514                                $approved = 'spam';
     515                }
     516
     517                $approved = apply_filters('pre_comment_approved', $approved);
     518        } else {
     519                // Importers can make $runchecks false to ensuring comment approval.
    506520                $approved = 1;
    507         } else {
    508                 if ( check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) )
    509                         $approved = 1;
    510                 else
    511                         $approved = 0;
    512                 if ( wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) )
    513                         $approved = 'spam';
    514521        }
    515522
    516         $approved = apply_filters('pre_comment_approved', $approved);
    517 
    518523        $result = $wpdb->query("INSERT INTO $wpdb->comments
    519524        (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, user_id)
    520525        VALUES
  • wp-admin/import/blogger.php

     
    500500                                                if ( $comment_post_ID == comment_exists($comment_author, $comment_date) ) {
    501501                                                        $skippedcommentcount++;
    502502                                                } else {
    503                                                         $result = $wpdb->query("
    504                                                         INSERT INTO $wpdb->comments
    505                                                         (comment_post_ID,comment_author,comment_author_url,comment_date,comment_content)
    506                                                         VALUES
    507                                                                 ('$comment_post_ID','$comment_author','$comment_author_url','$comment_date','$comment_content')
    508                                                 ");
     503                                                        $commentdata = compact('comment_date', 'comment_author', 'comment_author_url', 'comment_content', 'comment_post_ID');
     504                                                        wp_new_comment($commentdata, false);
    509505                                                }
    510506                                                $commentcount++;
    511507                                        }
     
    582578                if ( count($this->import['blogs']) > 1 )
    583579                        echo "<li>In case you haven't done it already, you can import the posts from any other blogs you may have:" . $this->show_blogs() . "</li>\n";
    584580                if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) )
    585                         echo "<li>Since we had to create $n new users, you probably want to go to <a href='users.php' target='_parent'>Authors & Users</a>, where you can give them new passwords or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.</li>\n";
     581                        echo "<li>Since we had to create $n new user".($n > 1 ? 's' : '').", you probably want to go to <a href='users.php' target='_parent'>Authors & Users</a>, where you can give them new passwords or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.</li>\n";
    586582               
    587583                echo "\n<ul>";
    588584        }