# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /var/www/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)
@@ -64,6 +64,7 @@
 			'wp.getMediaItem'		=> 'this:wp_getMediaItem',
 			'wp.getMediaLibrary'	=> 'this:wp_getMediaLibrary',
 			'wp.getPostFormats'     => 'this:wp_getPostFormats',
+                        'wp.getPosts'           => 'this:wp_getPosts',
 
 			// Blogger API
 			'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
@@ -1702,6 +1703,177 @@
 		return $formats;
 	}
 
+        /**
+         * Retrieve  posts
+         *
+         * @uses wp_get_recent_posts()
+         * @param array $args Method parameters. Contains:
+         *  - int     $blog_id
+         *  - string  $username
+         *  - string  $password
+         *  - array   $filter optional
+         * @return array
+         */
+        function wp_getPosts( $args ) {
+
+		$this->escape( $args );
+
+                $blog_ID    = (int) $args[0];
+                $username   = $args[1];
+                $password   = $args[2];
+                $filter     = $args[3];
+
+		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'];
+
+                }
+
+                $query['numberposts'] = apply_filters( 'xmlrpc_getPosts_maxvalue', 10 );// maximum value
+                if ( isset ( $filter['numberposts'] ) ) {
+
+                        if( absint( $filter['numberposts'] ) < 10 )
+                                $query['number'] = absint( $filter['numberposts'] );
+
+                }
+
+		$posts = wp_get_recent_posts( $query );
+
+		if ( ! $posts )
+			return array( );
+
+                // holds all the post data
+                $struct = array();
+
+                foreach ( $posts as $post ) {
+
+                        $post_type = get_post_type_object( $post['post_type'] );
+
+                        if( ! current_user_can( $post_type->cap->edit_posts ) )
+                                continue;
+
+                        $post_date = mysql2date( 'Ymd\TH:i:s', $post['post_date'], false );
+                        $post_date_gmt = mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false );
+
+                        // For drafts use the GMT version of the post date
+                        if ( $post['post_status'] == 'draft' )
+                                $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post['post_date'] ), 'Ymd\TH:i:s' );
+
+                        $post_content = get_extended( $post['post_content'] );
+                        $link = post_permalink( $post['ID'] );
+
+                        // Consider future posts as published
+                        if ( $post['post_status'] === 'future' )
+                                $post['post_status'] = 'publish';
+
+                        // Get post format
+                        $post_format = get_post_format( $post_ID );
+                        if ( empty( $post_format ) )
+                                $post_format = 'standard';
+
+                        $sticky = null;
+                        if( $post['post_type'] == 'post' ) {
+
+                                $sticky = false;
+                                if ( is_sticky( $post_ID ) )
+                                        $sticky = true;
+
+                        }
+
+
+                        $post_type_taxonomies = get_object_taxonomies( $post['post_type'] , 'names');
+                        $terms = wp_get_object_terms( $post_ID, $post_type_taxonomies );
+
+                        $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;
+                                        }
+                                }
+                        }
+
+
+                        // backward compatiblity
+                        $categories = array();
+                        $catids = wp_get_post_categories($post_ID);
+                        foreach($catids as $catid) {
+                                $categories[] = get_cat_name($catid);
+                        }
+
+                        $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[] = array(
+                                    'postid'            => $post['ID'],
+                                    'title'             => $post['post_title'],
+                                    'description'       => $post_content['main'],
+                                    'mt_excerpt'        => $post['post_excerpt'],
+
+                                    'post_status'       => $post['post_status'],
+                                    'post_type'         => $post['post_type'],
+                                    'wp_slug'           => $post['post_name'],
+                                    'wp_password'       => $post['post_password'],
+
+                                    'wp_page_order'     => $post['menu_order'],
+                                    'wp_page_parent_id' => $post['post_parent'],
+
+                                    'wp_author_id'      => $post['post_author'],
+
+                                    'mt_allow_comments' => $post['comment_status'],
+                                    'mt_allow_pings'    => $post['ping_status'],
+
+                                    'dateCreated'       => new IXR_Date($post_date),
+                                    'date_created_gmt'  => new IXR_Date($post_date_gmt),
+
+                                    'userid'            => $post['post_author'],
+                                    'sticky'            => $sticky,
+                                    'custom_fields'     => $wp_xmlrpc_server->get_custom_fields($post_ID),
+                                    'terms'             => $terms,
+
+                                    'link'              => $link,
+                                    'permaLink'         => $link,
+
+                                    // backward compatibility
+                                    'categories'	=> $categories,
+                                    'mt_keywords'       => $tagnames,
+                                    'wp_post_format'    => $post_format,
+
+                        );
+
+                        if ( ! empty( $enclosure ) )
+                                $post_data['enclosure'] = $enclosure;
+
+                        $struct[] = $post_date;
+
+                }
+                
+                return $struct;   
+        
+        }
+        
 	/* Blogger API functions.
 	 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
 	 */
