Make WordPress Core


Ignore:
Timestamp:
09/26/2005 11:55:36 PM (20 years ago)
Author:
ryan
Message:

Image uploading widget from skeltoac. fixes #1710

File:
1 edited

Legend:

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

    r2894 r2921  
    129129        $postquery =
    130130            "INSERT INTO $wpdb->posts
    131             (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
     131            (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order, post_type)
    132132            VALUES
    133             ('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order')";
     133            ('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_type')";
    134134    }
    135135   
     
    186186}
    187187
     188function wp_attach_object($object, $post_parent = 0) {
     189    global $wpdb, $user_ID;
     190   
     191    // Export array as variables
     192    extract($object);
     193
     194    // Get the basics.
     195    $post_content    = apply_filters('content_save_pre',   $post_content);
     196    $post_excerpt    = apply_filters('excerpt_save_pre',   $post_excerpt);
     197    $post_title      = apply_filters('title_save_pre',     $post_title);
     198    $post_category   = apply_filters('category_save_pre',  $post_category);
     199    $post_name       = apply_filters('name_save_pre',      $post_name);
     200    $comment_status  = apply_filters('comment_status_pre', $comment_status);
     201    $ping_status     = apply_filters('ping_status_pre',    $ping_status);
     202    $post_type       = apply_filters('post_type_pre',      $post_type);
     203
     204    // Make sure we set a valid category
     205    if (0 == count($post_category) || !is_array($post_category)) {
     206        $post_category = array(get_option('default_category'));
     207    }
     208    $post_cat = $post_category[0];
     209
     210    if ( empty($post_author) )
     211        $post_author = $user_ID;
     212
     213    $post_status = 'object';
     214
     215    // Get the post ID.
     216    if ( $update ) {
     217        $post_ID = $ID;
     218    } else {
     219        $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->posts'");
     220        $post_ID = $id_result->Auto_increment;
     221    }
     222
     223    // Create a valid post name.
     224    if ( empty($post_name) ) {
     225        $post_name = sanitize_title($post_title, $post_ID);
     226    } else {
     227        $post_name = sanitize_title($post_name, $post_ID);
     228    }
     229   
     230    if (empty($post_date))
     231        $post_date = current_time('mysql');
     232    if (empty($post_date_gmt))
     233        $post_date_gmt = current_time('mysql', 1);
     234
     235    if ( empty($comment_status) ) {
     236        if ( $update )
     237            $comment_status = 'closed';
     238        else
     239            $comment_status = get_settings('default_comment_status');
     240    }
     241    if ( empty($ping_status) )
     242        $ping_status = get_settings('default_ping_status');
     243    if ( empty($post_pingback) )
     244        $post_pingback = get_option('default_pingback_flag');
     245
     246    if ( isset($to_ping) )
     247        $to_ping = preg_replace('|\s+|', "\n", $to_ping);
     248    else
     249        $to_ping = '';
     250   
     251    $post_parent = (int) $post_parent;
     252
     253    if ( isset($menu_order) )
     254        $menu_order = (int) $menu_order;
     255    else
     256        $menu_order = 0;
     257
     258    if ( !isset($post_password) )
     259        $post_password = '';
     260
     261    if ($update) {
     262        $postquery =
     263            "UPDATE $wpdb->posts SET
     264            post_author = '$post_author',
     265            post_date = '$post_date',
     266            post_date_gmt = '$post_date_gmt',
     267            post_content = '$post_content',
     268            post_title = '$post_title',
     269            post_excerpt = '$post_excerpt',
     270            post_status = '$post_status',
     271            comment_status = '$comment_status',
     272            ping_status = '$ping_status',
     273            post_password = '$post_password',
     274            post_name = '$post_name',
     275            to_ping = '$to_ping',
     276            post_modified = '$post_date',
     277            post_modified_gmt = '$post_date_gmt',
     278            post_parent = '$post_parent',
     279            menu_order = '$menu_order',
     280            post_type = '$post_type',
     281            guid = '$guid'
     282            WHERE ID = $post_ID";
     283    } else {
     284        $postquery =
     285            "INSERT INTO $wpdb->posts
     286            (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order, post_type, guid)
     287            VALUES
     288            ('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_type', '$guid')";
     289    }
     290   
     291    $result = $wpdb->query($postquery);
     292
     293    wp_set_post_cats('', $post_ID, $post_category);
     294
     295    clean_post_cache($post_ID);
     296
     297    if ( $update) {
     298        do_action('edit_object', $post_ID);
     299    } else {
     300        do_action('attach_object', $post_ID);
     301    }
     302   
     303    return $post_ID;
     304}
     305
    188306function wp_get_single_post($postid = 0, $mode = OBJECT) {
    189307    global $wpdb;
Note: See TracChangeset for help on using the changeset viewer.