[wp-cvs] wordpress/wp-admin xmlrpc.php,1.4,1.5

Michel Valdrighi michelvaldrighi at users.sourceforge.net
Mon May 24 17:07:33 CDT 2004


Update of /cvsroot/cafelog/wordpress/wp-admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv872/wp-admin

Modified Files:
	xmlrpc.php 
Log Message:
database-related functions such as wp_insert_post are now in wp-includes/functions-post.php

Index: xmlrpc.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/xmlrpc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** xmlrpc.php	24 May 2004 08:22:17 -0000	1.4
--- xmlrpc.php	24 May 2004 22:07:30 -0000	1.5
***************
*** 369,497 ****
  $wp_xmlrpc_server = new wp_xmlrpc_server();
  
- 
- 
- /* functions that we ought to relocate
-  * and/or roll into a WP class as extension of wpdb
-  */
- 
- function wp_insert_post($postarr = array()) {
- 	global $wpdb, $post_default_category;
- 	
- 	// export array as variables
- 	extract($postarr);
- 	
- 	// Do some escapes for safety
- 	$post_title = $wpdb->escape($post_title);
- 	$post_name = sanitize_title($post_title);
- 	$post_excerpt = $wpdb->escape($post_excerpt);
- 	$post_content = $wpdb->escape($post_content);
- 	$post_author = (int) $post_author;
- 
- 	// Make sure we set a valid category
- 	if (0 == count($post_category) || !is_array($post_category)) {
- 		$post_category = array($post_default_category);
- 	}
- 
- 	$post_cat = $post_category[0];
- 	
- 	if (empty($post_date))
- 		$post_date = current_time('mysql');
- 	// Make sure we have a good gmt date:
- 	if (empty($post_date_gmt)) 
- 		$post_date_gmt = get_gmt_from_date($post_date);
- 	
- 	$sql = "INSERT INTO $wpdb->posts 
- 		(post_author, post_date, post_date_gmt, post_modified, post_modified_gmt, post_content, post_title, post_excerpt, post_category, post_status, post_name) 
- 		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')";
- 	
- 	$result = $wpdb->query($sql);
- 	$post_ID = $wpdb->insert_id;
- 	$blog_ID = (isset($blog_ID)) ? $blog_ID : 1;
- 
- 	wp_set_post_cats($blog_ID, $post_ID, $post_category);
- 	
- 	// Return insert_id if we got a good result, otherwise return zero.
- 	return $result ? $post_ID : 0;
- }
- 
- 
- function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {
- 	global $wpdb;
- 	// If $post_categories isn't already an array, make it one:
- 	if (!is_array($post_categories)) {
- 		if (!$post_categories) {
- 			$post_categories = 1;
- 		}
- 		$post_categories = array($post_categories);
- 	}
- 
- 	$post_categories = array_unique($post_categories);
- 
- 	// First the old categories
- 	$old_categories = $wpdb->get_col("
- 		SELECT category_id 
- 		FROM $wpdb->post2cat 
- 		WHERE post_id = $post_ID");
- 	
- 	if (!$old_categories) {
- 		$old_categories = array();
- 	} else {
- 		$old_categories = array_unique($old_categories);
- 	}
- 
- 
- 	$oldies = print_r($old_categories,1);
- 	$newbies = print_r($post_categories,1);
- 
- 	logio("O","Old: $oldies\nNew: $newbies\n");
- 
- 	// Delete any?
- 	$delete_cats = array_diff($old_categories,$post_categories);
- 
- 	logio("O","Delete: " . print_r($delete_cats,1));
- 		
- 	if ($delete_cats) {
- 		foreach ($delete_cats as $del) {
- 			$wpdb->query("
- 				DELETE FROM $wpdb->post2cat 
- 				WHERE category_id = $del 
- 					AND post_id = $post_ID 
- 				");
- 
- 			logio("O","deleting post/cat: $post_ID, $del");
- 		}
- 	}
- 
- 	// Add any?
- 	$add_cats = array_diff($post_categories, $old_categories);
- 
- 	logio("O","Add: " . print_r($add_cats,1));
- 		
- 	if ($add_cats) {
- 		foreach ($add_cats as $new_cat) {
- 			$wpdb->query("
- 				INSERT INTO $wpdb->post2cat (post_id, category_id) 
- 				VALUES ($post_ID, $new_cat)");
- 
- 				logio("O","adding post/cat: $post_ID, $new_cat");
- 		}
- 	}
- }
- 
- 
- function wp_get_post_cats($blogid = '1', $post_ID = 0) {
- 	global $wpdb;
- 	
- 	$sql = "SELECT category_id 
- 		FROM $wpdb->post2cat 
- 		WHERE post_id = $post_ID 
- 		ORDER BY category_id";
- 
- 	$result = $wpdb->get_col($sql);
- 
- 	return array_unique($result);
- }
- 
- 
- 
  ?>
\ No newline at end of file
--- 369,371 ----




More information about the cvs mailing list