Make WordPress Core

Ticket #3944: post-php2.diff

File post-php2.diff, 1.9 KB (added by JDTrower, 17 years ago)

Fix to make sure all posts created/updated have valid post_date fields based on the patch for admin-functions.php and makes changes to time normalization.

  • post.php

     
    8383                $mn = $_POST['mn'];
    8484                $ss = $_POST['ss'];
    8585                $jj = ($jj > 31 ) ? 31 : $jj;
    86                 $hh = ($hh > 23 ) ? $hh -24 : $hh;
    87                 $mn = ($mn > 59 ) ? $mn -60 : $mn;
    88                 $ss = ($ss > 59 ) ? $ss -60 : $ss;
    89                 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    90                 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
     86                $hh %= 24;
     87                $mn %= 60;
     88                $ss %= 60;
     89
     90               
     91                // Ensure a real, valid date here before saving to database
     92            // by converting to a Unix timestamp and then back
     93            $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     94            $tmp_post_date = strtotime( $tmp_post_date );
     95            $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     96                         
     97            $_POST['post_date'] = $tmp_post_date;
     98            $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    9199        }
    92100
    93101        // Meta Stuff
     
    274282                $mn = $_POST['mn'];
    275283                $ss = $_POST['ss'];
    276284                $jj = ($jj > 31 ) ? 31 : $jj;
    277                 $hh = ($hh > 23 ) ? $hh -24 : $hh;
    278                 $mn = ($mn > 59 ) ? $mn -60 : $mn;
    279                 $ss = ($ss > 59 ) ? $ss -60 : $ss;
    280                 $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    281                 $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
     285                $hh %= 24;
     286                $mn %= 60;
     287                $ss %= 60;
     288
     289               
     290                // Ensure a real, valid date here before saving to database
     291                // by converting to a Unix timestamp and then back
     292            $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     293            $tmp_post_date = strtotime( $tmp_post_date );
     294            $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     295                         
     296            $_POST['post_date'] = $tmp_post_date;
     297            $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    282298        }
    283299
    284300        // Create the post.