<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11846] trunk:
Ensure that drafts viewed over XMLRPC have a correct gmt date set.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11846">11846</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2009-08-20 06:59:02 +0000 (Thu, 20 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes <a href="http://trac.wordpress.org/ticket/10244">#10244</a> for trunk props josephscott.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesformattingphp">trunk/wp-includes/formatting.php</a></li>
<li><a href="#trunkxmlrpcphp">trunk/xmlrpc.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/formatting.php (11845 => 11846)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/formatting.php        2009-08-20 00:19:00 UTC (rev 11845)
+++ trunk/wp-includes/formatting.php        2009-08-20 06:59:02 UTC (rev 11846)
</span><span class="lines">@@ -1463,18 +1463,20 @@
</span><span class="cx"> * Returns a date in the GMT equivalent.
</span><span class="cx"> *
</span><span class="cx"> * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
</span><del>- * value of the 'gmt_offset' option.
</del><ins>+ * value of the 'gmt_offset' option. Return format can be overridden using the
+ * $format parameter
</ins><span class="cx"> *
</span><span class="cx"> * @since 1.2.0
</span><span class="cx"> *
</span><span class="cx"> * @uses get_option() to retrieve the the value of 'gmt_offset'.
</span><span class="cx"> * @param string $string The date to be converted.
</span><ins>+ * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
</ins><span class="cx"> * @return string GMT version of the date provided.
</span><span class="cx"> */
</span><del>-function get_gmt_from_date($string) {
</del><ins>+function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
</ins><span class="cx">         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);
</span><span class="cx">         $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
</span><del>-        $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600);
</del><ins>+        $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
</ins><span class="cx">         return $string_gmt;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1482,17 +1484,18 @@
</span><span class="cx"> * Converts a GMT date into the correct format for the blog.
</span><span class="cx"> *
</span><span class="cx"> * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of
</span><del>- * gmt_offset.
</del><ins>+ * gmt_offset.Return format can be overridden using the $format parameter
</ins><span class="cx"> *
</span><span class="cx"> * @since 1.2.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $string The date to be converted.
</span><ins>+ * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
</ins><span class="cx"> * @return string Formatted date relative to the GMT offset.
</span><span class="cx"> */
</span><del>-function get_date_from_gmt($string) {
</del><ins>+function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') {
</ins><span class="cx">         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);
</span><span class="cx">         $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
</span><del>-        $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600);
</del><ins>+        $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600);
</ins><span class="cx">         return $string_localtime;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkxmlrpcphp"></a>
<div class="modfile"><h4>Modified: trunk/xmlrpc.php (11845 => 11846)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/xmlrpc.php        2009-08-20 00:19:00 UTC (rev 11845)
+++ trunk/xmlrpc.php        2009-08-20 06:59:02 UTC (rev 11846)
</span><span class="lines">@@ -534,6 +534,11 @@
</span><span class="cx">                         $page_date = mysql2date("Ymd\TH:i:s", $page->post_date, false);
</span><span class="cx">                         $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt, false);
</span><span class="cx">
</span><ins>+                        // 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' );
+                        }
+
</ins><span class="cx">                         // Pull the categories info together.
</span><span class="cx">                         $categories = array();
</span><span class="cx">                         foreach(wp_get_post_categories($page->ID) as $cat_id) {
</span><span class="lines">@@ -798,7 +803,8 @@
</span><span class="cx">                                 post_title page_title,
</span><span class="cx">                                 post_parent page_parent_id,
</span><span class="cx">                                 post_date_gmt,
</span><del>-                                post_date
</del><ins>+                                post_date,
+                                post_status
</ins><span class="cx">                         FROM {$wpdb->posts}
</span><span class="cx">                         WHERE post_type = 'page'
</span><span class="cx">                         ORDER BY ID
</span><span class="lines">@@ -813,8 +819,15 @@
</span><span class="cx">                         $page_list[$i]->dateCreated = new IXR_Date($post_date);
</span><span class="cx">                         $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
</span><span class="cx">
</span><ins>+                        // 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 );
+                        }
+
</ins><span class="cx">                         unset($page_list[$i]->post_date_gmt);
</span><span class="cx">                         unset($page_list[$i]->post_date);
</span><ins>+                        unset($page_list[$i]->post_status);
</ins><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 return($page_list);
</span><span class="lines">@@ -2581,9 +2594,7 @@
</span><span class="cx">
</span><span class="cx">                         // For drafts use the GMT version of the post date
</span><span class="cx">                         if ( $postdata['post_status'] == 'draft' ) {
</span><del>-                                $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 );
</del><ins>+                                $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s' );
</ins><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         $categories = array();
</span><span class="lines">@@ -2702,6 +2713,11 @@
</span><span class="cx">                         $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
</span><span class="cx">                         $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
</span><span class="cx">
</span><ins>+                        // 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' );
+                        }
+
</ins><span class="cx">                         $categories = array();
</span><span class="cx">                         $catids = wp_get_post_categories($entry['ID']);
</span><span class="cx">                         foreach($catids as $catid) {
</span><span class="lines">@@ -2937,6 +2953,11 @@
</span><span class="cx">                         $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);
</span><span class="cx">                         $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);
</span><span class="cx">
</span><ins>+                        // 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' );
+                        }
+
</ins><span class="cx">                         $struct[] = array(
</span><span class="cx">                                 'dateCreated' => new IXR_Date($post_date),
</span><span class="cx">                                 'userid' => $entry['post_author'],
</span></span></pre>
</div>
</div>
</body>
</html>