Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. <?php
  2.  
  3. /*  Copyright 2012 Diana Koenraadt (email : diana at dianakoenraadt dot nl)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License, version 2, as
  7.     published by the Free Software Foundation.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17. */
  18.  
  19.     function replace_dates($post, $string) {
  20.        
  21.         $format_pattern = "([a-zA-Z\s\\\\:\/,]*)";
  22.        
  23.         // PHP 5.3 and upwards compatible, use preg_replace_callback for regular expressions with /e parameter instead of preg_replace
  24.         // http://wordpress.org/support/topic/php-55-preg_replace-e-modifier-depricated?replies=1
  25.         $post_date_gmt = $post->post_date_gmt;
  26.         $string = preg_replace("/\%post_date_gmt\(\)/", mysql2date('F jS, Y', $post_date_gmt), $string);   
  27.         $callback =
  28.             function ($matches) use ($post_date_gmt)
  29.             {
  30.                 return mysql2date($matches[1], $post_date_gmt);
  31.             }; 
  32.         $string = preg_replace_callback("/\%post_date_gmt\(" . $format_pattern . "\)/", $callback, $string);
  33.         $string = str_replace( "%post_date_gmt",    $post_date_gmt,     $string);
  34.  
  35.         $post_date = $post->post_date;
  36.         $string = preg_replace("/\%post_date\(\)/", mysql2date('F jS, Y', $post_date), $string);   
  37.         $callback =
  38.             function ($matches) use ($post_date)
  39.             {
  40.                 return mysql2date($matches[1], $post_date);
  41.             };
  42.         $string = preg_replace_callback("/\%post_date\(" . $format_pattern . "\)/", $callback, $string);
  43.         $string = str_replace( "%post_date",    $post_date,     $string);
  44.  
  45.         $string = str_replace( "%post_status",  $post->post_status,     $string);
  46.  
  47.         $post_modified_gmt = $post->post_modified_gmt;
  48.         $string = preg_replace("/\%post_modified_gmt\(\)/", mysql2date('F jS, Y', $post_modified_gmt), $string);   
  49.         $callback =
  50.             function ($matches) use ($post_modified_gmt)
  51.             {
  52.                 return mysql2date($matches[1], $post_modified_gmt);
  53.             };
  54.         $string = preg_replace_callback("/\%post_modified_gmt\(" . $format_pattern . "\)/", $callback, $string);
  55.         $string = str_replace( "%post_modified_gmt",    $post_modified_gmt,     $string);
  56.  
  57.         $post_modified = $post->post_modified;
  58.         $string = preg_replace("/\%post_modified\(\)/", mysql2date('F jS, Y', $post_modified), $string);
  59.         $callback =
  60.             function ($matches) use ($post_modified)
  61.             {
  62.                 return mysql2date($matches[1], $post_modified);
  63.             };
  64.         $string = preg_replace_callback("/\%post_modified\(" . $format_pattern . "\)/", $callback, $string);
  65.         $string = str_replace( "%post_modified",    $post_modified,     $string);
  66.        
  67.         return $string;
  68.     }
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement