Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes #10244 for trunk props josephscott.
git-svn-id: http://svn.automattic.com/wordpress/trunk@11846 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
934eadc858
commit
f9aff1739a
|
@ -1463,18 +1463,20 @@ function wp_iso_descrambler($string) {
|
||||||
* Returns a date in the GMT equivalent.
|
* Returns a date in the GMT equivalent.
|
||||||
*
|
*
|
||||||
* Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
|
* 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
|
* @since 1.2.0
|
||||||
*
|
*
|
||||||
* @uses get_option() to retrieve the the value of 'gmt_offset'.
|
* @uses get_option() to retrieve the the value of 'gmt_offset'.
|
||||||
* @param string $string The date to be converted.
|
* @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.
|
* @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);
|
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_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;
|
return $string_gmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1482,17 +1484,18 @@ function get_gmt_from_date($string) {
|
||||||
* Converts a GMT date into the correct format for the blog.
|
* 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
|
* 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
|
* @since 1.2.0
|
||||||
*
|
*
|
||||||
* @param string $string The date to be converted.
|
* @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.
|
* @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);
|
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_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;
|
return $string_localtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
xmlrpc.php
29
xmlrpc.php
|
@ -534,6 +534,11 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$page_date = mysql2date("Ymd\TH:i:s", $page->post_date, false);
|
$page_date = mysql2date("Ymd\TH:i:s", $page->post_date, false);
|
||||||
$page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt, 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.
|
// Pull the categories info together.
|
||||||
$categories = array();
|
$categories = array();
|
||||||
foreach(wp_get_post_categories($page->ID) as $cat_id) {
|
foreach(wp_get_post_categories($page->ID) as $cat_id) {
|
||||||
|
@ -798,7 +803,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
post_title page_title,
|
post_title page_title,
|
||||||
post_parent page_parent_id,
|
post_parent page_parent_id,
|
||||||
post_date_gmt,
|
post_date_gmt,
|
||||||
post_date
|
post_date,
|
||||||
|
post_status
|
||||||
FROM {$wpdb->posts}
|
FROM {$wpdb->posts}
|
||||||
WHERE post_type = 'page'
|
WHERE post_type = 'page'
|
||||||
ORDER BY ID
|
ORDER BY ID
|
||||||
|
@ -813,8 +819,15 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$page_list[$i]->dateCreated = new IXR_Date($post_date);
|
$page_list[$i]->dateCreated = new IXR_Date($post_date);
|
||||||
$page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
|
$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_gmt);
|
||||||
unset($page_list[$i]->post_date);
|
unset($page_list[$i]->post_date);
|
||||||
|
unset($page_list[$i]->post_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return($page_list);
|
return($page_list);
|
||||||
|
@ -2581,9 +2594,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
|
|
||||||
// For drafts use the GMT version of the post date
|
// For drafts use the GMT version of the post date
|
||||||
if ( $postdata['post_status'] == 'draft' ) {
|
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 = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' );
|
||||||
$post_date_gmt = preg_replace( '|\-|', '', $post_date_gmt );
|
|
||||||
$post_date_gmt = preg_replace( '| |', 'T', $post_date_gmt );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$categories = array();
|
$categories = array();
|
||||||
|
@ -2702,6 +2713,11 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
|
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
|
||||||
$post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], 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();
|
$categories = array();
|
||||||
$catids = wp_get_post_categories($entry['ID']);
|
$catids = wp_get_post_categories($entry['ID']);
|
||||||
foreach($catids as $catid) {
|
foreach($catids as $catid) {
|
||||||
|
@ -2937,6 +2953,11 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
|
$post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
|
||||||
$post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], 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(
|
$struct[] = array(
|
||||||
'dateCreated' => new IXR_Date($post_date),
|
'dateCreated' => new IXR_Date($post_date),
|
||||||
'userid' => $entry['post_author'],
|
'userid' => $entry['post_author'],
|
||||||
|
|
Loading…
Reference in New Issue