Make WordPress Core

Changeset 1359


Ignore:
Timestamp:
05/24/2004 10:07:30 PM (22 years ago)
Author:
michelvaldrighi
Message:

database-related functions such as wp_insert_post are now in wp-includes/functions-post.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r1355 r1359  
    369369$wp_xmlrpc_server = new wp_xmlrpc_server();
    370370
    371 
    372 
    373 /* functions that we ought to relocate
    374  * and/or roll into a WP class as extension of wpdb
    375  */
    376 
    377 function wp_insert_post($postarr = array()) {
    378         global $wpdb, $post_default_category;
    379        
    380         // export array as variables
    381         extract($postarr);
    382        
    383         // Do some escapes for safety
    384         $post_title = $wpdb->escape($post_title);
    385         $post_name = sanitize_title($post_title);
    386         $post_excerpt = $wpdb->escape($post_excerpt);
    387         $post_content = $wpdb->escape($post_content);
    388         $post_author = (int) $post_author;
    389 
    390         // Make sure we set a valid category
    391         if (0 == count($post_category) || !is_array($post_category)) {
    392                 $post_category = array($post_default_category);
    393         }
    394 
    395         $post_cat = $post_category[0];
    396        
    397         if (empty($post_date))
    398                 $post_date = current_time('mysql');
    399         // Make sure we have a good gmt date:
    400         if (empty($post_date_gmt))
    401                 $post_date_gmt = get_gmt_from_date($post_date);
    402        
    403         $sql = "INSERT INTO $wpdb->posts
    404                 (post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name)
    405                 VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_cat', '$post_status', '$post_name')";
    406        
    407         $result = $wpdb->query($sql);
    408         $post_ID = $wpdb->insert_id;
    409         $blog_ID = (isset($blog_ID)) ? $blog_ID : 1;
    410 
    411         wp_set_post_cats($blog_ID, $post_ID, $post_category);
    412        
    413         // Return insert_id if we got a good result, otherwise return zero.
    414         return $result ? $post_ID : 0;
    415 }
    416 
    417 
    418 function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
    419         global $wpdb;
    420         // If $post_categories isn't already an array, make it one:
    421         if (!is_array($post_categories)) {
    422                 if (!$post_categories) {
    423                         $post_categories = 1;
    424                 }
    425                 $post_categories = array($post_categories);
    426         }
    427 
    428         $post_categories = array_unique($post_categories);
    429 
    430         // First the old categories
    431         $old_categories = $wpdb->get_col("
    432                 SELECT category_id
    433                 FROM $wpdb->post2cat
    434                 WHERE post_id = $post_ID");
    435        
    436         if (!$old_categories) {
    437                 $old_categories = array();
    438         } else {
    439                 $old_categories = array_unique($old_categories);
    440         }
    441 
    442 
    443         $oldies = print_r($old_categories,1);
    444         $newbies = print_r($post_categories,1);
    445 
    446         logio("O","Old: $oldies\nNew: $newbies\n");
    447 
    448         // Delete any?
    449         $delete_cats = array_diff($old_categories,$post_categories);
    450 
    451         logio("O","Delete: " . print_r($delete_cats,1));
    452                
    453         if ($delete_cats) {
    454                 foreach ($delete_cats as $del) {
    455                         $wpdb->query("
    456                                 DELETE FROM $wpdb->post2cat
    457                                 WHERE category_id = $del
    458                                         AND post_id = $post_ID
    459                                 ");
    460 
    461                         logio("O","deleting post/cat: $post_ID, $del");
    462                 }
    463         }
    464 
    465         // Add any?
    466         $add_cats = array_diff($post_categories, $old_categories);
    467 
    468         logio("O","Add: " . print_r($add_cats,1));
    469                
    470         if ($add_cats) {
    471                 foreach ($add_cats as $new_cat) {
    472                         $wpdb->query("
    473                                 INSERT INTO $wpdb->post2cat (post_id, category_id)
    474                                 VALUES ($post_ID, $new_cat)");
    475 
    476                                 logio("O","adding post/cat: $post_ID, $new_cat");
    477                 }
    478         }
    479 }
    480 
    481 
    482 function wp_get_post_cats($blogid = '1', $post_ID = 0) {
    483         global $wpdb;
    484        
    485         $sql = "SELECT category_id
    486                 FROM $wpdb->post2cat
    487                 WHERE post_id = $post_ID
    488                 ORDER BY category_id";
    489 
    490         $result = $wpdb->get_col($sql);
    491 
    492         return array_unique($result);
    493 }
    494 
    495 
    496 
    497371?>
Note: See TracChangeset for help on using the changeset viewer.