Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes #10244 for 2.8 branch props josephscott.

git-svn-id: http://svn.automattic.com/wordpress/branches/2.8@11847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-08-20 07:06:08 +00:00
parent 3958df020f
commit 15aee919f7
2 changed files with 34 additions and 10 deletions

View File

@ -1452,18 +1452,20 @@ function wp_iso_descrambler($string) {
* Returns a date in the GMT equivalent.
*
* Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
* value of the 'gmt_offset' option.
* value of the 'gmt_offset' option. Return format can be overridden using the
* $format parameter
*
* @since 1.2.0
*
* @uses get_option() to retrieve the the value of 'gmt_offset'.
* @param string $string The date to be converted.
* @param string $format The format string for the returned date (default is Y-m-d H:i:s)
* @return string GMT version of the date provided.
*/
function get_gmt_from_date($string) {
function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
$string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600);
$string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
return $string_gmt;
}
@ -1471,17 +1473,18 @@ function get_gmt_from_date($string) {
* Converts a GMT date into the correct format for the blog.
*
* Requires and returns in the Y-m-d H:i:s format. Simply adds the value of
* gmt_offset.
* gmt_offset.Return format can be overridden using the $format parameter
*
* @since 1.2.0
*
* @param string $string The date to be converted.
* @param string $format The format string for the returned date (default is Y-m-d H:i:s)
* @return string Formatted date relative to the GMT offset.
*/
function get_date_from_gmt($string) {
function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') {
preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
$string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600);
$string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600);
return $string_localtime;
}

View File

@ -526,6 +526,11 @@ class wp_xmlrpc_server extends IXR_Server {
$page_date = mysql2date("Ymd\TH:i:s", $page->post_date, false);
$page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt, false);
// For drafts use the GMT version of the date
if ( $page->post_status == 'draft' ) {
$page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s' );
}
// Pull the categories info together.
$categories = array();
foreach(wp_get_post_categories($page->ID) as $cat_id) {
@ -790,7 +795,8 @@ class wp_xmlrpc_server extends IXR_Server {
post_title page_title,
post_parent page_parent_id,
post_date_gmt,
post_date
post_date,
post_status
FROM {$wpdb->posts}
WHERE post_type = 'page'
ORDER BY ID
@ -805,8 +811,15 @@ class wp_xmlrpc_server extends IXR_Server {
$page_list[$i]->dateCreated = new IXR_Date($post_date);
$page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
// For drafts use the GMT version of the date
if ( $page_list[$i]->post_status == 'draft' ) {
$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' );
$page_list[$i]->date_created_gmt = new IXR_Date( $page_list[$i]->date_created_gmt );
}
unset($page_list[$i]->post_date_gmt);
unset($page_list[$i]->post_date);
unset($page_list[$i]->post_status);
}
return($page_list);
@ -2576,9 +2589,7 @@ class wp_xmlrpc_server extends IXR_Server {
// For drafts use the GMT version of the post date
if ( $postdata['post_status'] == 'draft' ) {
$post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ) );
$post_date_gmt = preg_replace( '|\-|', '', $post_date_gmt );
$post_date_gmt = preg_replace( '| |', 'T', $post_date_gmt );
$post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' );
}
$categories = array();
@ -2697,6 +2708,11 @@ class wp_xmlrpc_server extends IXR_Server {
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
$post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
// For drafts use the GMT version of the date
if ( $entry['post_status'] == 'draft' ) {
$post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
}
$categories = array();
$catids = wp_get_post_categories($entry['ID']);
foreach($catids as $catid) {
@ -2932,6 +2948,11 @@ class wp_xmlrpc_server extends IXR_Server {
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
$post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
// For drafts use the GMT version of the date
if ( $entry['post_status'] == 'draft' ) {
$post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s' );
}
$struct[] = array(
'dateCreated' => new IXR_Date($post_date),
'userid' => $entry['post_author'],