Make WordPress Core

Changeset 20353


Ignore:
Timestamp:
04/04/2012 09:32:28 PM (13 years ago)
Author:
westi
Message:

XMLRPC: Make sure that we always return valid dates when no date is currently set - for example if the post is pending. Fixes #19733 props markoheijnen and koke.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r20351 r20353  
    500500     *
    501501     * @access protected
    502     .*
     502     *
    503503     * @param array|object $taxonomy The unprepared taxonomy data
    504504     * @return array The prepared taxonomy data
     
    516516     *
    517517     * @access protected
    518     .*
     518     *
    519519     * @param array|object $term The unprepared term data
    520520     * @return array The prepared term data
     
    553553
    554554    /**
     555     * Convert a WordPress gmt date string to an IXR_Date object.
     556     *
     557     * @access protected
     558     *
     559     * @param $date
     560     * @return IXR_Date
     561     */
     562    protected function _convert_date_gmt( $date_gmt, $date ) {
     563        if ( $date !== '0000-00-00 00:00:00' && $date_gmt === '0000-00-00 00:00:00' ) {
     564            return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) );
     565        }
     566        return $this->_convert_date( $date_gmt );
     567    }
     568
     569    /**
    555570     * Prepares post data for return in an XML-RPC object.
    556571     *
     
    569584            'post_title'        => $post['post_title'],
    570585            'post_date'         => $this->_convert_date( $post['post_date'] ),
    571             'post_date_gmt'     => $this->_convert_date( $post['post_date_gmt'] ),
     586            'post_date_gmt'     => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ),
    572587            'post_modified'     => $this->_convert_date( $post['post_modified'] ),
    573             'post_modified_gmt' => $this->_convert_date( $post['post_modified_gmt'] ),
     588            'post_modified_gmt' => $this->_convert_date_gmt( $post['post_modified_gmt'], $post['post_modified'] ),
    574589            'post_status'       => $post['post_status'],
    575590            'post_type'         => $post['post_type'],
     
    17151730
    17161731            // Format page date.
    1717             $page_date = mysql2date('Ymd\TH:i:s', $page->post_date, false);
    1718             $page_date_gmt = mysql2date('Ymd\TH:i:s', $page->post_date_gmt, false);
    1719 
    1720             // For drafts use the GMT version of the date
    1721             if ( $page->post_status == 'draft' )
    1722                 $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s' );
     1732            $page_date = $this->_convert_date( $page->post_date );
     1733            $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );
    17231734
    17241735            // Pull the categories info together.
     
    17361747
    17371748            $page_struct = array(
    1738                 'dateCreated'           => new IXR_Date($page_date),
     1749                'dateCreated'           => $page_date,
    17391750                'userid'                => $page->post_author,
    17401751                'page_id'               => $page->ID,
     
    17571768                'wp_author_id'          => (string) $author->ID,
    17581769                'wp_author_display_name'    => $author->display_name,
    1759                 'date_created_gmt'      => new IXR_Date($page_date_gmt),
     1770                'date_created_gmt'      => $page_date_gmt,
    17601771                'custom_fields'         => $this->get_custom_fields($page_id),
    17611772                'wp_page_template'      => $page_template
     
    19761987        $num_pages = count($page_list);
    19771988        for ( $i = 0; $i < $num_pages; $i++ ) {
    1978             $post_date = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date, false);
    1979             $post_date_gmt = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date_gmt, false);
    1980 
    1981             $page_list[$i]->dateCreated = new IXR_Date($post_date);
    1982             $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
    1983 
    1984             // For drafts use the GMT version of the date
    1985             if ( $page_list[$i]->post_status == 'draft' ) {
    1986                 $page_list[$i]->date_created_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page_list[$i]->post_date ), 'Ymd\TH:i:s' );
    1987                 $page_list[$i]->date_created_gmt = new IXR_Date( $page_list[$i]->date_created_gmt );
    1988             }
     1989            $page_list[$i]->dateCreated = $this->_convert_date(  $page_list[$i]->post_date );
     1990            $page_list[$i]->date_created_gmt = $this->_convert_date_gmt( $page_list[$i]->post_date_gmt, $page_list[$i]->post_date );
    19891991
    19901992            unset($page_list[$i]->post_date_gmt);
     
    22312233
    22322234        // Format page date.
    2233         $comment_date = mysql2date('Ymd\TH:i:s', $comment->comment_date, false);
    2234         $comment_date_gmt = mysql2date('Ymd\TH:i:s', $comment->comment_date_gmt, false);
     2235        $comment_date = $this->_convert_date( $comment->comment_date );
     2236        $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date );
    22352237
    22362238        if ( '0' == $comment->comment_approved )
     
    22462248
    22472249        $comment_struct = array(
    2248             'date_created_gmt'      => new IXR_Date($comment_date_gmt),
     2250            'date_created_gmt'      => $comment_date_gmt,
    22492251            'user_id'               => $comment->user_id,
    22502252            'comment_id'            => $comment->comment_ID,
     
    28252827
    28262828        // Format page date.
    2827         $attachment_date = mysql2date('Ymd\TH:i:s', $attachment->post_date, false);
    2828         $attachment_date_gmt = mysql2date('Ymd\TH:i:s', $attachment->post_date_gmt, false);
     2829        $attachment_date = $this->_convert_date( $attachment->post_date );
     2830        $attachment_date_gmt = $this->_convert_date_gmt( $attachment->post_date_gmt, $attachment->post_date );
    28292831
    28302832        $link = wp_get_attachment_url($attachment->ID);
     
    28322834
    28332835        $attachment_struct = array(
    2834             'date_created_gmt'      => new IXR_Date($attachment_date_gmt),
     2836            'date_created_gmt'      => $attachment_date_gmt,
    28352837            'parent'                => $attachment->post_parent,
    28362838            'link'                  => $link,
     
    31833185        $struct = array(
    31843186            'userid'    => $post_data['post_author'],
    3185             'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'], false)),
     3187            'dateCreated' => $this->_convert_date( $post_data['post_date'] ),
    31863188            'content'     => $content,
    31873189            'postid'  => (string) $post_data['ID']
     
    32283230                continue;
    32293231
    3230             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
     3232            $post_date  = $this->_convert_date( $entry['post_date'] );
    32313233            $categories = implode(',', wp_get_post_categories($entry['ID']));
    32323234
     
    32373239            $struct[] = array(
    32383240                'userid' => $entry['post_author'],
    3239                 'dateCreated' => new IXR_Date($post_date),
     3241                'dateCreated' => $post_date,
    32403242                'content' => $content,
    32413243                'postid' => (string) $entry['ID'],
     
    41244126
    41254127        if ($postdata['post_date'] != '') {
    4126             $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date'], false);
    4127             $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt'], false);
    4128             $post_modified = mysql2date('Ymd\TH:i:s', $postdata['post_modified'], false);
    4129             $post_modified_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_modified_gmt'], false);
    4130 
    4131             // For drafts use the GMT version of the post date
    4132             if ( $postdata['post_status'] == 'draft' ) {
    4133                 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' );
    4134                 $post_modified_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_modified'] ), 'Ymd\TH:i:s' );
    4135             }
     4128            $post_date = $this->_convert_date( $postdata['post_date'] );
     4129            $post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'],  $postdata['post_date'] );
     4130            $post_modified = $this->_convert_date( $postdata['post_modified'] );
     4131            $post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] );
    41364132
    41374133            $categories = array();
     
    41864182
    41874183            $resp = array(
    4188                 'dateCreated' => new IXR_Date($post_date),
     4184                'dateCreated' => $post_date,
    41894185                'userid' => $postdata['post_author'],
    41904186                'postid' => $postdata['ID'],
     
    42054201                'wp_password' => $postdata['post_password'],
    42064202                'wp_author_id' => (string) $author->ID,
    4207                 'wp_author_display_name'    => $author->display_name,
    4208                 'date_created_gmt' => new IXR_Date($post_date_gmt),
     4203                'wp_author_display_name' => $author->display_name,
     4204                'date_created_gmt' => $post_date_gmt,
    42094205                'post_status' => $postdata['post_status'],
    42104206                'custom_fields' => $this->get_custom_fields($post_ID),
    42114207                'wp_post_format' => $post_format,
    42124208                'sticky' => $sticky,
    4213                 'date_modified' => new IXR_Date( $post_modified ),
    4214                 'date_modified_gmt' => new IXR_Date( $post_modified_gmt )
     4209                'date_modified' => $post_modified,
     4210                'date_modified_gmt' => $post_modified_gmt
    42154211            );
    42164212
     
    42604256                continue;
    42614257
    4262             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
    4263             $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
    4264             $post_modified = mysql2date('Ymd\TH:i:s', $entry['post_modified'], false);
    4265             $post_modified_gmt = mysql2date('Ymd\TH:i:s', $entry['post_modified_gmt'], false);
    4266 
    4267             // For drafts use the GMT version of the date
    4268             if ( $entry['post_status'] == 'draft' ) {
    4269                 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
    4270                 $post_modified_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_modified'] ), 'Ymd\TH:i:s' );
    4271             }
     4258            $post_date = $this->_convert_date( $entry['post_date'] );
     4259            $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
     4260            $post_modified = $this->_convert_date( $entry['post_modified'] );
     4261            $post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] );
    42724262
    42734263            $categories = array();
     
    43064296
    43074297            $struct[] = array(
    4308                 'dateCreated' => new IXR_Date($post_date),
     4298                'dateCreated' => $post_date,
    43094299                'userid' => $entry['post_author'],
    43104300                'postid' => (string) $entry['ID'],
     
    43264316                'wp_author_id' => (string) $author->ID,
    43274317                'wp_author_display_name' => $author->display_name,
    4328                 'date_created_gmt' => new IXR_Date($post_date_gmt),
     4318                'date_created_gmt' => $post_date_gmt,
    43294319                'post_status' => $entry['post_status'],
    43304320                'custom_fields' => $this->get_custom_fields($entry['ID']),
    43314321                'wp_post_format' => $post_format,
    4332                 'date_modified' => new IXR_Date( $post_modified ),
    4333                 'date_modified_gmt' => new IXR_Date( $post_modified_gmt )
     4322                'date_modified' => $post_modified,
     4323                'date_modified_gmt' => $post_modified_gmt
    43344324            );
    43354325
     
    45174507                continue;
    45184508
    4519             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
    4520             $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
    4521 
    4522             // For drafts use the GMT version of the date
    4523             if ( $entry['post_status'] == 'draft' )
    4524                 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
     4509            $post_date = $this->_convert_date( $entry['post_date'] );
     4510            $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
    45254511
    45264512            $struct[] = array(
    4527                 'dateCreated' => new IXR_Date($post_date),
     4513                'dateCreated' => $post_date,
    45284514                'userid' => $entry['post_author'],
    45294515                'postid' => (string) $entry['ID'],
    45304516                'title' => $entry['post_title'],
    45314517                'post_status' => $entry['post_status'],
    4532                 'date_created_gmt' => new IXR_Date($post_date_gmt)
     4518                'date_created_gmt' => $post_date_gmt
    45334519            );
    45344520
Note: See TracChangeset for help on using the changeset viewer.