WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/20/2005 03:17:43 AM (14 years ago)
Author:
ryan
Message:

wp_insert_comment(), wp_update_comment(), wp_allow_comment(), and wp_filter_comment() from skeltoac. fixes #1683

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions-post.php

    r2887 r2894  
    457457}
    458458
    459 function wp_new_comment( $commentdata, $spam = false ) {
    460     global $wpdb;
    461 
    462     $commentdata = apply_filters('preprocess_comment', $commentdata);
    463     extract($commentdata);
    464 
    465     $comment_post_ID = (int) $comment_post_ID;
    466 
    467     $user_id = apply_filters('pre_user_id', $user_ID);
    468     $author  = apply_filters('pre_comment_author_name', $comment_author);
    469     $email   = apply_filters('pre_comment_author_email', $comment_author_email);
    470     $url     = apply_filters('pre_comment_author_url', $comment_author_url);
    471     $comment = apply_filters('pre_comment_content', $comment_content);
    472     $comment = apply_filters('post_comment_text', $comment); // Deprecated
    473     $comment = apply_filters('comment_content_presave', $comment); // Deprecated
    474 
    475     $user_ip     = apply_filters('pre_comment_user_ip', $_SERVER['REMOTE_ADDR']);
    476     $user_domain = apply_filters('pre_comment_user_domain', gethostbyaddr($user_ip) );
    477     $user_agent  = apply_filters('pre_comment_user_agent', $_SERVER['HTTP_USER_AGENT']);
    478 
    479     $now     = current_time('mysql');
    480     $now_gmt = current_time('mysql', 1);
    481 
    482     if ( $user_id ) {
    483         $userdata = get_userdata($user_id);
    484         $user = new WP_User($user_id);
    485         $post_author = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = '$comment_post_ID' LIMIT 1");
    486     }
    487 
    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!') );
    494 
    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.') );
    502         }
    503     }
    504 
    505     if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
    506         $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';
    514     }
    515 
    516     $approved = apply_filters('pre_comment_approved', $approved);
    517 
    518     $result = $wpdb->query("INSERT INTO $wpdb->comments
    519     (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)
    520     VALUES
    521     ('$comment_post_ID', '$author', '$email', '$url', '$user_ip', '$now', '$now_gmt', '$comment', '$approved', '$user_agent', '$comment_type', '$user_id')
    522     ");
    523 
    524     $comment_id = $wpdb->insert_id;
    525     do_action('comment_post', $comment_id, $approved);
    526 
    527     if ( 'spam' !== $approved ) { // If it's spam save it silently for later crunching
    528         if ( '0' == $approved )
    529             wp_notify_moderator($comment_id);
    530    
    531         if ( get_settings('comments_notify') && $approved )
    532             wp_notify_postauthor($comment_id, $comment_type);
    533     }
    534 
    535     return $result;
    536 }
    537 
    538 function wp_update_comment($commentarr) {
    539     global $wpdb;
    540 
    541     // First, get all of the original fields
    542     $comment = get_comment($commentarr['comment_ID'], ARRAY_A);
    543 
    544     // Escape data pulled from DB.
    545     foreach ($comment as $key => $value)
    546         $comment[$key] = $wpdb->escape($value);
    547 
    548     // Merge old and new fields with new fields overwriting old ones.
    549     $commentarr = array_merge($comment, $commentarr);
    550 
    551     // Now extract the merged array.
    552     extract($commentarr);
    553 
    554     $comment_content = apply_filters('comment_save_pre', $comment_content);
    555 
    556     $result = $wpdb->query(
    557         "UPDATE $wpdb->comments SET
    558             comment_content = '$comment_content',
    559             comment_author = '$comment_author',
    560             comment_author_email = '$comment_author_email',
    561             comment_approved = '$comment_approved',
    562             comment_author_url = '$comment_author_url',
    563             comment_date = '$comment_date'
    564         WHERE comment_ID = $comment_ID" );
    565 
    566     $rval = $wpdb->rows_affected;
    567 
    568     do_action('edit_comment', $comment_ID);
    569 
    570     return $rval;   
    571 }
    572 
    573459function do_trackbacks($post_id) {
    574460    global $wpdb;
Note: See TracChangeset for help on using the changeset viewer.