Make WordPress Core

Ticket #18432: wp.getPost.patch

File wp.getPost.patch, 7.4 KB (added by nprasath002, 12 years ago)
  • class-wp-xmlrpc-server.php

    # 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.
     
    6464                        'wp.getMediaItem'               => 'this:wp_getMediaItem',
    6565                        'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary',
    6666                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
     67                        'wp.getPost'            => 'this:wp_getPost',
    6768
    6869                        // Blogger API
    6970                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     
    17021703                return $formats;
    17031704        }
    17041705
     1706        /**
     1707         * Retrieve  post
     1708         *
     1709         * @uses wp_get_single_post()
     1710         * @param array $args Method parameters. Contains:
     1711         *  - int     $post_id
     1712         *  - string  $username
     1713         *  - string  $password
     1714         * @return array contains:
     1715         *  - 'postid'
     1716         *  - 'title'
     1717         *  - 'description'
     1718         *  - 'mt_excerpt'
     1719         *  - 'post_status'
     1720         *  - 'post_type'
     1721         *  - 'wp_slug'
     1722         *  - 'wp_password'
     1723         *  - 'wp_page_order'
     1724         *  - 'wp_page_parent_id'
     1725         *  - 'wp_author_id'
     1726         *  - 'mt_allow_comments'
     1727         *  - 'mt_allow_pings'
     1728         *  - 'dateCreated'
     1729         *  - 'date_created_gmt'
     1730         *  - 'userid'
     1731         *  - 'sticky'
     1732         *  - 'custom_fields'
     1733         *  - 'terms'
     1734         *  - 'link'
     1735         *  - 'permaLink'
     1736         *  - 'categories'
     1737         *  - 'mt_keywords'
     1738         *  - 'wp_post_format'
     1739         */
     1740        function wp_getPost( $args ) {
     1741
     1742                $this->escape( $args );
     1743
     1744                $post_ID            = (int) $args[0];
     1745                $username           = $args[1];
     1746                $password           = $args[2];
     1747
     1748                if ( ! $user = $this->login( $username, $password ) )
     1749                        return $this->error;
     1750
     1751                $post = wp_get_single_post( $post_ID, ARRAY_A );
     1752                if ( empty( $post["ID"] ) )
     1753                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
     1754
     1755                $post_type = get_post_type_object( $post['post_type'] );
     1756                if( ! current_user_can( $post_type->cap->edit_posts, $post_ID ) )
     1757                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
     1758
     1759                //return $post;
     1760
     1761                $post_date = mysql2date( 'Ymd\TH:i:s', $post['post_date'], false );
     1762                $post_date_gmt = mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false );
     1763
     1764                // For drafts use the GMT version of the post date
     1765                if ( $post['post_status'] == 'draft' )
     1766                        $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post['post_date'] ), 'Ymd\TH:i:s' );
     1767
     1768                $post_content = get_extended( $post['post_content'] );
     1769                $link = post_permalink( $post['ID'] );
     1770
     1771                // Consider future posts as published
     1772                if ( $post['post_status'] === 'future' )
     1773                        $post['post_status'] = 'publish';
     1774
     1775                // Get post format
     1776                $post_format = get_post_format( $post_ID );
     1777                if ( empty( $post_format ) )
     1778                        $post_format = 'standard';
     1779
     1780                $sticky = null;
     1781                if( $post['post_type'] == 'post' ) {
     1782
     1783                        $sticky = false;
     1784                        if ( is_sticky( $post_ID ) )
     1785                                $sticky = true;
     1786
     1787                }
     1788
     1789
     1790                $post_type_taxonomies = get_object_taxonomies( $post['post_type'] , 'names');
     1791                $terms = wp_get_object_terms( $post_ID, $post_type_taxonomies );
     1792
     1793                $enclosure = array();
     1794                foreach ( (array) get_post_custom($post_ID) as $key => $val) {
     1795                        if ($key == 'enclosure') {
     1796                                foreach ( (array) $val as $enc ) {
     1797                                        $encdata = split("\n", $enc);
     1798                                        $enclosure['url'] = trim(htmlspecialchars($encdata[0]));
     1799                                        $enclosure['length'] = (int) trim($encdata[1]);
     1800                                        $enclosure['type'] = trim($encdata[2]);
     1801                                        break 2;
     1802                                }
     1803                        }
     1804                }
     1805
     1806
     1807                // backward compatiblity
     1808                $categories = array();
     1809                $catids = wp_get_post_categories($post_ID);
     1810                foreach($catids as $catid) {
     1811                        $categories[] = get_cat_name($catid);
     1812                }
     1813               
     1814                $tagnames = array();
     1815                $tags = wp_get_post_tags( $post_ID );
     1816                if ( !empty( $tags ) ) {
     1817                        foreach ( $tags as $tag )
     1818                                $tagnames[] = $tag->name;
     1819                        $tagnames = implode( ', ', $tagnames );
     1820                } else {
     1821                        $tagnames = '';
     1822                }
     1823
     1824                $struct = array(
     1825                            'postid'            => $post['ID'],
     1826                            'title'             => $post['post_title'],
     1827                            'description'       => $post_content['main'],
     1828                            'mt_excerpt'        => $post['post_excerpt'],
     1829
     1830                            'post_status'       => $post['post_status'],
     1831                            'post_type'         => $post['post_type'],
     1832                            'wp_slug'           => $post['post_name'],
     1833                            'wp_password'       => $post['post_password'],
     1834                   
     1835                            'wp_page_order'     => $post['menu_order'],
     1836                            'wp_page_parent_id' => $post['post_parent'],
     1837
     1838                            'wp_author_id'      => $post['post_author'],
     1839
     1840                            'mt_allow_comments' => $post['comment_status'],
     1841                            'mt_allow_pings'    => $post['ping_status'],
     1842                   
     1843                            'dateCreated'       => new IXR_Date($post_date),
     1844                            'date_created_gmt'  => new IXR_Date($post_date_gmt),
     1845                   
     1846                            'userid'            => $post['post_author'],
     1847                            'sticky'            => $sticky,
     1848                            'custom_fields'     => $wp_xmlrpc_server->get_custom_fields( $post_ID ),
     1849                            'terms'             => $terms,
     1850
     1851                            'link'              => $link,
     1852                            'permaLink'         => $link,
     1853                   
     1854                            // backward compatibility
     1855                            'categories'        => $categories,
     1856                            'mt_keywords'       => $tagnames,
     1857                            'wp_post_format'    => $post_format,
     1858
     1859                );
     1860
     1861                if ( ! empty( $enclosure ) )
     1862                        $resp['enclosure'] = $enclosure;
     1863
     1864                return $struct;
     1865
     1866
     1867        }
     1868       
    17051869        /* Blogger API functions.
    17061870         * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
    17071871         */