Changeset 6237

Show
Ignore:
Timestamp:
10/13/07 00:48:52 (1 year ago)
Author:
markjaquith
Message:

More use of db_insert()/db_update(). see #5178

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/post.php

    r6229 r6237  
    641641    } 
    642642 
     643    if ( $update ) { 
     644        $post_modified     = current_time( 'mysql' ); 
     645        $post_modified_gmt = current_time( 'mysql', 1 ); 
     646    } else { 
     647        $post_modified     = $post_date; 
     648        $post_modified_gmt = $post_date_gmt; 
     649    } 
     650 
    643651    if ( 'publish' == $post_status ) { 
    644652        $now = gmdate('Y-m-d H:i:59'); 
     
    678686 
    679687    if ( 'draft' != $post_status ) { 
    680         // expected_slashed ($post_name, $post_type) 
    681         $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_type = '$post_type' AND ID != %d AND post_parent = %d LIMIT 1", $post_ID, $post_parent)); 
     688        $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $post_name, $post_type, $post_ID, $post_parent)); 
    682689 
    683690        if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) { 
     
    693700    } 
    694701 
     702    // expected_slashed (everything!) 
     703    $data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order' ) ); 
     704    $data = stripslashes_deep( $data ); 
     705 
    695706    if ($update) { 
    696         // expected_slashed (everything!) 
    697         $wpdb->query( 
    698             "UPDATE IGNORE $wpdb->posts SET 
    699             post_author = '$post_author', 
    700             post_date = '$post_date', 
    701             post_date_gmt = '$post_date_gmt', 
    702             post_content = '$post_content', 
    703             post_content_filtered = '$post_content_filtered', 
    704             post_title = '$post_title', 
    705             post_excerpt = '$post_excerpt', 
    706             post_status = '$post_status', 
    707             post_type = '$post_type', 
    708             comment_status = '$comment_status', 
    709             ping_status = '$ping_status', 
    710             post_password = '$post_password', 
    711             post_name = '$post_name', 
    712             to_ping = '$to_ping', 
    713             pinged = '$pinged', 
    714             post_modified = '".current_time('mysql')."', 
    715             post_modified_gmt = '".current_time('mysql',1)."', 
    716             post_parent = '$post_parent', 
    717             menu_order = '$menu_order' 
    718             WHERE ID = $post_ID"); 
    719     } else { 
    720         // expected_slashed (everything!) 
    721         $wpdb->query( 
    722             "INSERT IGNORE INTO $wpdb->posts 
    723             (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type) 
    724             VALUES 
    725             ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')"); 
    726             $post_ID = (int) $wpdb->insert_id; 
     707        $wpdb->db_update( $wpdb->posts, $data, 'ID', $post_ID ); 
     708    } else { 
     709        $data['post_mime_type'] = stripslashes( $post_mime_type ); // This isn't in the update 
     710        $wpdb->db_insert( $wpdb->posts, $data ); 
     711        $post_ID = (int) $wpdb->insert_id; 
    727712    } 
    728713 
    729714    if ( empty($post_name) && 'draft' != $post_status ) { 
    730715        $post_name = sanitize_title($post_title, $post_ID); 
    731         // expected_slashed ($post_name) 
    732         $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = %d", $post_ID)); 
     716        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $post_name, $post_ID ) ); 
    733717    } 
    734718 
     
    13071291 
    13081292    // expected_slashed (everything!) 
    1309     $data = array(); 
    1310     foreach ( array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid') as $f ) 
    1311         $data[$f] = stripslashes($$f); 
    1312     unset($f); 
     1293    $data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' ) ); 
     1294    $data = stripslashes_deep( $data ); 
    13131295 
    13141296    if ($update) {