# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\xampp\htdocs\GSoC\wordtrunk\wp-includes
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: class-wp-xmlrpc-server.php
--- class-wp-xmlrpc-server.php Base (BASE)
+++ class-wp-xmlrpc-server.php Locally Modified (Based On LOCAL)
@@ -63,7 +63,8 @@
 			'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
 			'wp.getMediaItem'		=> 'this:wp_getMediaItem',
 			'wp.getMediaLibrary'	=> 'this:wp_getMediaLibrary',
-			'wp.getPostFormats'     => 'this:wp_getPostFormats',
+			'wp.getPostFormats'		=> 'this:wp_getPostFormats',
+			'wp.getPosts'			=> 'this:wp_getPosts',
 
 			// Blogger API
 			'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
@@ -1702,6 +1703,237 @@
 		return $formats;
 	}
 
+	/**
+	 * Retrieve posts.
+	 *
+	 * Besides the common blog_id, username, and password arguments, it takes
+	 * a filter array and a fields array.
+	 *
+	 * Accepted 'filter' keys are 'post_type', 'post_status', 'numberposts', and 'offset'.
+	 *
+	 * The 'fields' array specifies which post fields will be included in the response.
+	 * Values can be either conceptual groups ('post', 'taxonomies', 'custom_fields')
+	 * or specific field names. By default, all fields are returned.
+	 *
+	 * @since 3.3
+	 *
+	 * @uses wp_get_recent_posts()
+	 * @param array $args Method parameters. Contains:
+	 *  - int     $blog_id
+	 *  - string  $username
+	 *  - string  $password
+	 *  - array   $filter optional
+	 *  - array   $fields optional
+	 * @return array. Contains a collection of posts.
+	 */
+	function wp_getPosts( $args ) {
+		$this->escape( $args );
+
+		$blog_ID    = (int) $args[0];
+		$username   = $args[1];
+		$password   = $args[2];
+
+		if ( isset( $args[3] ) )
+			$filter = $args[3];
+		else
+			$filter = array();
+
+		if ( isset( $args[4] ) )
+			$fields = $args[4];
+		else
+			$fields = array('post', 'taxonomies', 'custom_fields');
+
+		if ( !$user = $this->login( $username, $password ) )
+			return $this->error;
+
+		$query = array();
+
+		if ( isset( $filter['post_type'] ) ) {
+                    
+			$post_type = get_post_type_object( $filter['post_type'] );
+			if( !( (bool)$post_type ) )
+					return new IXR_Error( 403, __( 'The post type specified is not valid' ) );
+
+			if( ! current_user_can( $post_type->cap->edit_posts ) )
+				return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
+			$query['post_type'] = $filter['post_type'];
+                        
+		}
+
+                if ( isset( $filter['post_status'] ) ) {
+                    
+                        $statuses = $filter['post_status'];
+                        $post_statuses = get_post_stati ();
+                        $query_statuses = array();
+                        
+                        foreach ( $statuses as $status ) {
+                            
+                                if( !in_array( $status, $post_statuses ) )
+                                        return new IXR_Error( 403, __( 'One of the post status specified is not valid' ) );
+                                $query_statuses[] = $status;
+                            
+                        }
+
+			$query['post_status'] = $query_statuses;
+                        
+                }
+
+		if ( isset ( $filter['numberposts'] ) ) {
+			$query['numberposts'] = absint( $filter['numberposts'] );
+		}
+                
+                if ( isset ( $filter['offset'] ) ) {
+                        $query['offset'] = absint( $filter['offset'] );
+                }               
+
+		do_action('xmlrpc_call', 'wp.getPosts');
+
+		$posts_list = wp_get_recent_posts( $query );
+
+		if ( !$posts_list )
+			return array( );
+
+		// holds all the posts data
+		$struct = array();
+
+		// pre-calculate conceptual group in_array searches
+		$all_post_fields = in_array( 'post', $fields );
+		$all_taxonomy_fields = in_array( 'taxonomies', $fields );
+
+		foreach ( $posts_list as $post ) {
+
+			$post_type = get_post_type_object( $post['post_type'] );
+
+			if( !current_user_can( $post_type->cap->edit_posts, $post['ID'] ) )
+				continue;
+
+			// holds the data for this post. built up based on $fields
+			$post_data = array( 'postid' => $post['ID'] );
+
+			if ( $all_post_fields || in_array( 'title', $fields ) )
+				$post_data['title'] = $post['post_title'];
+
+			if ( $all_post_fields || in_array( 'dateCreated', $fields ) )
+				$post_data['dateCreated'] = new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ));
+
+			if ( $all_post_fields || in_array( 'date_created_gmt', $fields ) )
+				$post_data['date_created_gmt'] = new IXR_Date(mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ));
+
+			if ( $all_post_fields || in_array( 'post_status', $fields ) ) {
+				// Consider future posts as published
+				if ( $post['post_status'] === 'future' )
+					$post_data['post_status'] = 'publish';
+				else
+					$post_data['post_status'] = $post['post_status'];
+			}
+
+			if ( $all_post_fields || in_array( 'post_type', $fields ) )
+				$post_data['post_type'] = $post['post_type'];
+
+			if ( $all_post_fields || in_array( 'post_format', $fields ) ) {
+				$post_format = get_post_format( $post['ID'] );
+				if ( empty( $post_format ) )
+					$post_format = 'standard';
+				$post_data['post_format'] = $post_format;
+			}
+
+			if ( $all_post_fields || in_array( 'wp_slug', $fields ) )
+				$post_data['wp_slug'] = $post['post_name'];
+
+			if ( $all_post_fields || in_array( 'link', $fields ) )
+				$post_data['link'] = post_permalink( $post['ID'] );
+
+			if ( $all_post_fields || in_array( 'permaLink', $fields ) )
+				$post_data['permaLink'] = post_permalink( $post['ID'] );
+
+			if ( $all_post_fields || in_array( 'userid', $fields ) )
+				$post_data['userid'] = $post['post_author'];
+
+			if ( $all_post_fields || in_array( 'wp_author_id', $fields ) )
+				$post_data['wp_author_id'] = $post['post_author'];
+
+			if ( $all_post_fields || in_array( 'mt_allow_comments', $fields ) )
+				$post_data['mt_allow_comments'] = $post['comment_status'];
+
+			if ( $all_post_fields || in_array( 'mt_allow_pings', $fields ) )
+				$post_data['mt_allow_pings'] = $post['ping_status'];
+
+			if ( $all_post_fields || in_array( 'sticky', $fields ) ) {
+				$sticky = null;
+				if( $post['post_type'] == 'post' ) {
+					$sticky = false;
+					if ( is_sticky( $post['ID'] ) )
+						$sticky = true;
+				}
+				$post_data['sticky'] = $sticky;
+			}
+
+			if ( $all_post_fields || in_array( 'wp_password', $fields ) )
+				$post_data['wp_password'] = $post['post_password'];
+
+			if ( $all_post_fields || in_array( 'mt_excerpt', $fields ) )
+				$post_data['mt_excerpt'] = $post['post_excerpt'];
+
+			if ( $all_post_fields || in_array( 'description', $fields ) ) {
+				$post_content = get_extended( $post['post_content'] );
+				$post_data['description'] = $post_content['main'];
+				$post_data['mt_text_more'] = $post_content['extended'];
+			}
+
+			if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) {
+				$post_type_taxonomies = get_object_taxonomies( $post['post_type'] , 'names');
+				$post_data['terms'] = wp_get_object_terms( $post['ID'], $post_type_taxonomies );;
+			}
+
+			// backward compatiblity
+			if ( $all_taxonomy_fields || in_array( 'mt_keywords', $fields ) ) {
+				$tagnames = array();
+				$tags = wp_get_post_tags( $post['ID'] );
+				if ( !empty( $tags ) ) {
+					foreach ( $tags as $tag )
+						$tagnames[] = $tag->name;
+					$tagnames = implode( ', ', $tagnames );
+				} else {
+					$tagnames = '';
+				}
+				$post_data['mt_keywords'] = $tagnames;
+			}
+
+			// backward compatiblity
+			if ( $all_taxonomy_fields || in_array( 'categories', $fields ) ) {
+				$categories = array();
+				$catids = wp_get_post_categories( $post['ID'] );
+				foreach($catids as $catid) {
+					$categories[] = get_cat_name($catid);
+				}
+				$post_data['categories'] = $categories;
+			}
+
+			if ( in_array( 'custom_fields', $fields ) )
+				$post_data['custom_fields'] = $this->get_custom_fields( $post['ID'] );
+
+			if ( in_array( 'enclosure', $fields ) ) {
+				$enclosure = array();
+				foreach ( (array) get_post_custom( $post['ID'] ) as $key => $val) {
+					if ($key == 'enclosure') {
+						foreach ( (array) $val as $enc ) {
+							$encdata = split("\n", $enc);
+							$enclosure['url'] = trim(htmlspecialchars($encdata[0]));
+							$enclosure['length'] = (int) trim($encdata[1]);
+							$enclosure['type'] = trim($encdata[2]);
+							break 2;
+						}
+					}
+				}
+				$post_data['enclosure'] = $enclosure;
+			}
+
+			$struct[] = $post_data;
+		}
+
+		return $struct;
+	}
+
 	/* Blogger API functions.
 	 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
 	 */
