Changeset 46083

Show
Ignore:
Timestamp:
05/15/08 20:01:06 (2 months ago)
Author:
Kalessin
Message:

Added support for times and dates of comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • uk-time/trunk/readme.txt

    r37866 r46083  
    11=== Plugin Name === 
    2 Contributors: Kalessin 
    3 Tags: time zone, british summer time, utc, daylight saving time 
     2Contributors: Alex Coles 
     3Tags: british summer time, bst, daylight saving time, gmt, greenwich mean time, time zone, utc 
    44Requires at least: 2.0 
    5 Tested up to: 2.5 
    6 Stable tag: 1.0 
     5Tested up to: 2.5.1 
     6Stable tag: 1.2 
    77 
    88Plugin to automatically adjust for British Summer Time. 
     
    1010== Description == 
    1111 
    12 The UK Time plugin reads the modification time of each post being displayed and adds an hour if it falls inside British Summer Time. 
     12The UK Time plugin reads the modification time of each post and comment being displayed and adds an hour if it falls inside British Summer Time. 
    1313 
    14 * Works with existing posts 
    1514* No need to adjust the UTC offset ever again 
    16 * Nothing is permanently changed 
     15* Works with existing posts and comments, even if you used to adjust the UTC offset 
     16* No times or dates are permanently changed 
    1717 
    1818Requires the web server's time zone to be UTC. 
     
    22221. Unzip and upload the `uktime.php` file to the `/wp-content/plugins` directory 
    23231. Activate the plugin from the `Plugins` menu in WordPress 
    24 1. Ensure your themes use `<?php the_time() ?>` to display the time and `<?php the_date()` to display the date.* 
     241. Ensure your theme uses `<?php the_time() ?>` to display the time and `<?php the_date()` to display the date.* 
    2525 
    26 * Hint: The default theme supplied with WordPress uses `<?php the_time('F jS, Y') ?>`. This will be left unmodified by the UK Time plugin. To control the format of the date and time, go to the `Settings` menu in WordPress. 
     26* Note: The default theme supplied with WordPress uses its own parameters to control the format of the date and time: `<?php the_time('F jS, Y') ?>`. The UK Time plugin will not modify any times and dates which do not use the global date and time format. To adjust the global date and time format, go to the `Settings` menu in WordPress. 
  • uk-time/trunk/uktime.php

    r37866 r46083  
    55Description: Checks dates and times and adjusts for British Summer Time if applicable. Requires the use of the defaults <code>the_time()</code> and <code>the_date()</code> in the active theme. No times are permanently changed. 
    66Author: Alex Coles 
    7 Version: 1.0 
     7Version: 1.2 
    88Author URI: http://www.alexcoles.com 
    99*/  
    1010 
    11 function adjust_for_BST($supplied_time
     11function adjust_for_BST($timestamp
    1212{ 
    13       //  Check if supplied arg is a date or a time (so this function can be used for both) 
    14       if ($supplied_time==get_post_time(get_settings('time_format'))) 
    15       { 
    16             $filter='time'; 
    17       } 
    18       elseif ($supplied_time==get_post_time(get_settings('date_format'))) 
    19       { 
    20             $filter='date'; 
    21       } 
    22       //  Date or time format is set by theme -- do nothing. 
    23       else 
    24       { 
    25             return $supplied_time; 
    26       } 
    27       // retrieve post time in Unix timestamp format 
    28       $timestamp=get_post_time('U',true); 
    2913      //  find the year of the supplied timestamp 
    3014      $supplied_year=(date('Y',$timestamp)); 
     
    4024      //  Add an hour to the time, if the date falls within BST. 
    4125      if (($timestamp>=$BST_start) && ($timestamp<$BST_end)) { $timestamp=$timestamp+3600; } 
     26      return $timestamp; 
     27} 
     28 
     29function adjust_post_time($supplied_time) 
     30{ 
     31      //  Check if supplied arg is a date or a time (so this function can be used for both) 
     32      if ( $supplied_time==get_post_time(get_settings('time_format')) ) 
     33      { 
     34            $filter='time'; 
     35      } 
     36      elseif ( $supplied_time==get_post_time(get_settings('date_format')) ) 
     37      { 
     38            $filter='date'; 
     39      } 
     40      //  Date or time format is set by theme -- do nothing. 
     41      else 
     42      { 
     43            return $supplied_time; 
     44      } 
     45      // retrieve post time in Unix timestamp format 
     46      $timestamp=adjust_for_BST(get_post_time('U',true)); 
    4247      if ($filter=='time') 
    4348      { 
     
    5055} 
    5156 
    52 add_filter('the_time', 'adjust_for_BST'); 
    53 add_filter('the_date', 'adjust_for_BST'); 
     57function adjust_comment_time($supplied_time) 
     58
     59      global $comment; 
     60      //  Check if supplied arg is a date or a time (so this function can be used for both) 
     61      if ( $supplied_time==mysql2date(get_option('time_format'), $comment->comment_date_gmt) ) 
     62      { 
     63            $filter='time'; 
     64      } 
     65      elseif ( $supplied_time==mysql2date(get_option('date_format'), $comment->comment_date_gmt) ) 
     66      { 
     67            $filter='date'; 
     68      } 
     69      //  Date or time format is set by theme -- do nothing. 
     70      else 
     71      { 
     72            return $supplied_time; 
     73      } 
     74      // retrieve post time in Unix timestamp format 
     75      $timestamp=adjust_for_BST(mysql2date('U', $comment->comment_date_gmt)); 
     76      if ($filter=='time') 
     77      { 
     78            return date(get_settings('time_format'),$timestamp); 
     79      } 
     80      else 
     81      { 
     82            return date(get_settings('date_format'),$timestamp); 
     83      } 
     84
     85 
     86add_filter('the_time', 'adjust_post_time'); 
     87add_filter('the_date', 'adjust_post_time'); 
     88add_filter('get_comment_time', 'adjust_comment_time'); 
     89add_filter('get_comment_date', 'adjust_comment_time'); 
    5490?>