Plugin Directory

Changeset 782055


Ignore:
Timestamp:
10/03/2013 05:40:45 PM (12 years ago)
Author:
ezraverheijen
Message:

Version 1.1

Location:
wp-timezone/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-timezone/trunk/readme.txt

    r743629 r782055  
    11=== WP TimeZone ===
    22Contributors: ezraverheijen
    3 Donate link: http://www.qualityinternetsolutions.nl/
     3Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3H3RWC5JULGJ4
    44Tags: timezone, time zone, daylight saving, time, zone, scheduled posts, offset, cet, cest, utc, utc+1, utc+2, central european summer time, central european time
    55Requires at least: 3.1
    6 Tested up to: 3.5.2
    7 Stable tag: 1.0
     6Tested up to: 3.6.1
     7Stable tag: 1.1
    88License: GPL v3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    1313== Description ==
    1414
    15 This plugin can be used if WP's automatic daylight saving and scheduled posts are not working properly due to whatever reason.
     15This lightweight plugin can be used if the scheduled post feature is not working for you (missed scheduled post errors), and you host your site in a European country using CEST in the summer and CET during the winter.
    1616
    1717== Installation ==
    1818
    19191. Upload the `wp-timezone` folder to the `/wp-content/plugins/` directory
    20 1. Activate the WP TimeZone plugin through the 'Plugins' menu in WordPress
    21 1. No need to configure. It just works!
     201. Activate WP TimeZone through the 'Plugins' menu in WordPress
     211. No need to configure, it just works!
     22
     23If WP TimeZone needs to be installed on a multisite, it can also be placed in ['mu-plugins'](http://codex.wordpress.org/Must_Use_Plugins).
    2224
    2325== Screenshots ==
     
    2729== Changelog ==
    2830
     31= 1.1 =
     32* Some code improvements
     33
    2934= 1.0 =
    3035* Initial release
  • wp-timezone/trunk/wp-timezone.php

    r743629 r782055  
    11<?php
    2 /*
    3 Plugin Name: WP TimeZone
    4 Plugin URI: http://wordpress.org/plugins/wp-timezone/
    5 Description: Automatically changes the WordPress timezone settings based on CET and CEST
    6 Version: 1.0
    7 Author: Ezra Verheijen
    8 Author URI: http://www.qualityinternetsolutions.nl/
    9 
    10     Copyright (C) 2013  Ezra Verheijen @ QIS ([email protected])
    11 
    12     This program is free software; you can redistribute it and/or modify
    13     it under the terms of the GNU General Public License, version 3, or
    14     any later version, as published by the Free Software Foundation.
    15 
    16     This program is distributed in the hope that it will be useful,
    17     but WITHOUT ANY WARRANTY; without even the implied warranty of
    18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    19     GNU General Public License for more details.
    20 
    21     You should have received a copy of the GNU General Public License
    22     along with this program; if not, visit <http://www.gnu.org/licenses/>.
     2/**
     3 * Plugin Name: WP TimeZone
     4 * Plugin URI:  http://wordpress.org/plugins/wp-timezone/
     5 * Description: Automatically changes the WordPress timezone settings based on CET and CEST.
     6 * Version:     1.1
     7 * Author:      Ezra Verheijen
     8 * Author URI:  http://www.qualityinternetsolutions.nl/
     9 * License:     GPL v3
     10 */
     11
     12/*  Copyright (c) 2013, Ezra Verheijen - [email protected]
     13   
     14    This program is free software: you can redistribute it and/or modify
     15    it under the terms of the GNU General Public License as published by
     16    the Free Software Foundation, either version 3 of the License, or
     17    (at your option) any later version.
     18   
     19    This program is distributed in the hope that it will be useful,
     20    but WITHOUT ANY WARRANTY; without even the implied warranty of
     21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     22    GNU General Public License for more details.
     23   
     24    You should have received a copy of the GNU General Public License
     25    along with this program. If not, see <http://www.gnu.org/licenses/>.
    2326*/
    2427
    25 /*  This plugin can be used if WP's automatic daylight saving and
    26     scheduled posts are not working properly due to whatever reason.
    27    
    28     If this plugin needs to be installed on a multisite, it can also be
    29     placed in 'mu-plugins' (http://codex.wordpress.org/Must_Use_Plugins).
    30 */
     28/*  If this plugin needs to be installed on a multisite, it can also be
     29    placed in 'mu-plugins' (http://codex.wordpress.org/Must_Use_Plugins). */
    3130
    3231/**
    33  * Set UTC offset based on CET/CEST
     32 * WP TimeZone init class
    3433 *
    35  * Runs after WordPress has finished loading
    36  * but before any headers are sent.
     34 * @since 1.1
    3735 */
    38 add_action( 'init', function() {
    39 
    40     global $wpdb;
    41        
    42     /* WordPress default sets to UTC timezone in wp-settings.php */
    43        
    44     if ( function_exists( 'date_default_timezone_set' ) )
    45         date_default_timezone_set( 'Europe/Amsterdam' ); // Choose one, it's all the same
    46 
    47     $timezone = date( 'T' );
    48 
    49     /* Now we have the local timezone stored in $timezone,
    50     so lets restore WordPress setting as in wp-settings.php */
    51 
    52     if ( function_exists( 'date_default_timezone_set' ) )
    53         date_default_timezone_set( 'UTC' );
    54    
    55     /** Get current offset */
    56     $current_offset = get_option( 'gmt_offset' );
    57    
    58     if ( 'CEST' == $timezone ) // Central European Summer Time
    59         $offset = '2';
    60     elseif ( 'CET' == $timezone ) // Central European Time
    61         $offset = '1';
    62    
    63     // Update offset in database if new offset is different
    64     if ( $offset != $current_offset )
    65         update_option( 'gmt_offset', $offset );
    66    
    67     /**
    68      * Set the default timezone to show/handle on admin config page
    69      * to avoid confusion and avoid user interference.
    70      * Leave empty so WordPress can automatically
    71      * fill in the offset being used.
    72      */
    73     $timezone_string = '';
    74    
    75     /** Check if a user messed with the settings */
    76     $current_string = get_option( 'timezone_string' );
    77    
    78     // If so, set back to default
    79     if ( $timezone_string != $current_string )
    80         update_option( 'timezone_string', $timezone_string );
    81 
    82 } );
    83 
    84 /**
    85  * Change the Settings->General Screen to be more clever
    86  *
    87  * Note: I wish there was a nicer way to do this,
    88  * but the admin pages lack the proper hooks for it.
    89  * Until it gets them, this works.
    90  */
    91 add_action( 'admin_head', function() {
    92 
    93     global $pagenow;
    94    
    95     // Check to see if we're loading the options-general page
    96     if ( 'options-general.php' != $pagenow )
    97         return;
    98 
    99     // All looks good, turn on the output buffer and attach our callback
    100     ob_start( 'wpt_general_callback' );
    101 
    102 } );
    103 
    104 /**
    105  * Put a better comment on the Settings->General page
    106  *
    107  * @param string $data - The output buffer holding the page data
    108  */
    109 function wpt_general_callback( $data ) {
    110    
    111     /** Convert all applicable characters to HTML entities */
    112     $converted = htmlentities( $data, ENT_QUOTES, 'UTF-8' );
    113    
    114     $replace = array(
    115         'Kies een plaats in dezelfde tijdzone als waarin je zit.', // Dutch
    116         'Choose a city in the same timezone as you.', // English
    117         'W&auml;hle eine Stadt, die in deiner Zeitzone liegt.' // German
    118     );
    119     $with = array(
    120         'Tijdzones worden autmatisch beheerd door de WP TimeZone plugin.', // Dutch
    121         'Timezones are automatically managed by the WP TimeZone plugin.', // English
    122         'Zeitzonen werden automatisch verwaltet bei der WP TimeZone Plugin.' // German
    123     );
    124    
    125     $new_string = str_replace( $replace, $with, $converted );
    126      
    127     /** Convert all HTML entities back to their applicable characters */
    128     $final = html_entity_decode( $new_string, ENT_QUOTES, 'UTF-8' );
    129    
    130     return $final;
     36class WP_Timezone {
     37   
     38    /**
     39     * Constructor
     40     *
     41     * @since 1.1
     42     */
     43    function __construct() {
     44       
     45        add_action( 'init', array( $this, 'set_utc_offset' ) );
     46        add_action( 'admin_head', array( $this, 'change_settings_screen' ) );
     47       
     48        add_filter( 'plugin_row_meta', array( $this, 'wpt_filter_plugin_meta' ), 10, 2 );
     49       
     50    }
     51   
     52    /**
     53     * Set UTC offset based on CET/CEST
     54     *
     55     * Runs after WordPress has finished loading
     56     * but before any headers are sent.
     57     *
     58     * @since 1.0
     59     */
     60    function set_utc_offset() {
     61       
     62        /* WordPress default sets to UTC timezone in wp-settings.php */
     63       
     64        if ( function_exists( 'date_default_timezone_set' ) )
     65            date_default_timezone_set( 'Europe/Amsterdam' ); // choose one, it's all the same
     66       
     67        $timezone = date( 'T' );
     68       
     69        /* Now we have the local timezone stored in $timezone,
     70        so lets restore WordPress setting as in wp-settings.php */
     71       
     72        if ( function_exists( 'date_default_timezone_set' ) )
     73            date_default_timezone_set( 'UTC' );
     74       
     75        /** Get current offset */
     76        $current_offset = get_option( 'gmt_offset' );
     77       
     78        /** Set new offset */
     79        $offset = 1; // Central European Time (UTC+1)
     80       
     81        if ( 'CEST' == $timezone ) // Central European Summer Time
     82            $offset = 2;
     83       
     84        // Update offset in database if new offset is different than current offset
     85        if ( $offset != $current_offset )
     86            update_option( 'gmt_offset', $offset );
     87       
     88        /**
     89         * Set default timezone to show/handle on admin config page
     90         * to avoid confusion and avoid user interference.
     91         * Leave empty so WordPress can automatically
     92         * fill in the offset being used.
     93         */
     94        $timezone_string = '';
     95       
     96        /** Check if a user messed with the settings */
     97        $current_string = get_option( 'timezone_string' );
     98       
     99        // If so, set back to default
     100        if ( $timezone_string != $current_string )
     101            update_option( 'timezone_string', $timezone_string );
     102       
     103    }
     104   
     105    /**
     106     * Change the Settings->General Screen to be more clever
     107     *
     108     * Note: I wish there was a nicer way to do this,
     109     * but the admin pages lack the proper hooks for it.
     110     * Until it gets them, this works.
     111     *
     112     * @return null Returns early if not on the options-general page
     113     *
     114     * @since 1.0
     115     */
     116     function change_settings_screen() {
     117       
     118        global $pagenow;
     119       
     120        if ( 'options-general.php' != $pagenow )
     121            return;
     122       
     123        // All looks good, turn on the output buffer and attach our callback
     124        ob_start( array( $this, 'replace_text' ) );
     125       
     126    }
     127   
     128    /**
     129     * Put a better comment on the Settings->General page
     130     *
     131     * @param $buffer The output buffer holding the page data
     132     *
     133     * @return $final The page data with the replaced text
     134     *
     135     * @since 1.0
     136     */
     137    function replace_text( $buffer ) {
     138       
     139        /** Convert all applicable characters to HTML entities */
     140        $converted = htmlentities( $buffer, ENT_QUOTES, 'UTF-8' );
     141       
     142        $search = array(
     143            'Kies een plaats in dezelfde tijdzone als waarin je zit.', // Dutch
     144            'Choose a city in the same timezone as you.',              // English
     145            'W&auml;hle eine Stadt, die in deiner Zeitzone liegt.',    // German
     146        );
     147        $replace = array(
     148            'Tijdzones worden autmatisch beheerd door de WP TimeZone plugin.',    // Dutch
     149            'Timezones are automatically managed by the WP TimeZone plugin.',     // English
     150            'Zeitzonen werden automatisch verwaltet bei der WP TimeZone Plugin.', // German
     151        );
     152       
     153        $new_string = str_replace( $search, $replace, $converted );
     154       
     155        /** Convert all HTML entities back to their applicable characters */
     156        $final = html_entity_decode( $new_string, ENT_QUOTES, 'UTF-8' );
     157       
     158        return $final;
     159       
     160        // Clean output buffer and turn off output buffering
     161        ob_end_clean();
     162       
     163    }
     164   
     165    /**
     166     * Add a "Donate" link to the plugin meta info
     167     *
     168     * @param $links The existing links
     169     * @param $file plugin basename
     170     *
     171     * @return $links
     172     *
     173     * @since 1.1
     174     */
     175    function wpt_filter_plugin_meta( $links, $file ) {
     176       
     177        if ( plugin_basename( __FILE__ ) == $file ) {
     178           
     179            $lang = get_locale();
     180           
     181            $donate = 'Donate';
     182           
     183            if ( 'nl_NL' == $lang )
     184                $donate = 'Doneer';
     185           
     186            if ( 'de_DE' == $lang )
     187                $donate = 'Spenden';
     188           
     189            return array_merge(
     190                    $links,
     191                    array( sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3H3RWC5JULGJ4" target="_blank">%s</a>', __( $donate ) ) )
     192            );
     193           
     194        }
     195       
     196        return $links;
     197       
     198    }
    131199   
    132200}
    133201
    134 // Clean (erase) output buffer and turn off output buffering
    135 ob_end_clean();
     202$wp_timezone = new WP_Timezone();
Note: See TracChangeset for help on using the changeset viewer.