Plugin Directory

Changeset 837066


Ignore:
Timestamp:
01/12/2014 10:57:34 AM (12 years ago)
Author:
ezraverheijen
Message:

Version 1.3

Location:
wp-timezone/tags/1.3
Files:
5 added
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-timezone/tags/1.3/readme.txt

    r799407 r837066  
    55Requires at least: 3.1
    66Tested up to: 3.7.1
    7 Stable tag: 1.2
     7Stable tag: 1.3
    88License: GPL v3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2929== Changelog ==
    3030
     31= 1.3 =
     32* Bugfix
     33* Even better and faster code
     34
    3135= 1.2 =
    3236* Added fix for a reported issue where scheduled posts missed their schedule again since timezone changed from CEST to CET. All possible cases should be covered now.
  • wp-timezone/tags/1.3/wp-timezone.php

    r799407 r837066  
    11<?php
    22/**
    3  * Plugin Name: WP TimeZone
    4  * Plugin URI:  http://wordpress.org/plugins/wp-timezone/
    5  * Description: Takes care of publishing posts that missed their schedule, for CET/CEST time zones only.
    6  * Version:     1.2
    7  * Author:      Ezra Verheijen
    8  * Author URI:  http://www.qualityinternetsolutions.nl/
    9  * License:     GPL v3
     3 * Plugin Name: WP TimeZone
     4 * Plugin URI:  http://wordpress.org/plugins/wp-timezone/
     5 * Description: Takes care of publishing posts that missed their schedule, for CET/CEST time zones only.
     6 * Version:     1.3
     7 * Author:      Ezra Verheijen
     8 * Author URI:  http://profiles.wordpress.org/ezraverheijen/
     9 * License:     GPL v3
     10 *
     11 * Copyright (c) 2013, Ezra Verheijen
     12 *
     13 * WP Timezone is free software: you can redistribute it and/or modify
     14 * it under the terms of the GNU General Public License as published by
     15 * the Free Software Foundation, either version 3 of the License, or
     16 * (at your option) any later version.
     17 *
     18 * WP Timezone is distributed in the hope that it will be useful,
     19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     21 * GNU General Public License for more details.
     22 *
     23 * You should have received a copy of the GNU General Public License
     24 * along with WP Timezone. If not, see <http://www.gnu.org/licenses/>.
    1025 */
    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/>.
    26 */
    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 
    31 if ( ! defined( 'ABSPATH' ) ) exit; // exit if accessed directly
    3226
    3327/**
     
    3630 * @since 1.1
    3731 */
    38 class WP_Timezone {
    39    
    40     /**
    41      * Constructor.
    42      *
    43      * Attaches all functionalities of this plugin to the correct Wordpress hooks.
     32class WP_TimeZone {
     33   
     34    /**
     35     * Attach all functionalities to the correct hooks and filters.
    4436     *
    4537     * @since 1.1
     
    4739    function __construct() {
    4840       
    49         add_option( 'wpt_scheduled_check' );
    50        
    51         add_action( 'init', array( $this, 'set_utc_offset' ) );
    52         add_action( 'init', array( $this, 'check_missed_schedules' ) );
    53         add_action( 'admin_head-edit.php', array( $this, 'change_posts_overview_screen' ) );
    54         add_action( 'admin_head-options-general.php', array( $this, 'change_settings_screen' ) );
    55        
     41        add_action( 'init', array( $this, 'init' ) );
     42        add_action( 'plugins_loaded', array( $this, 'plugin_translation' ) );
     43       
     44        add_filter( 'gettext', array( $this, 'replace_text' ), 20, 3 );
    5645        add_filter( 'plugin_row_meta', array( $this, 'filter_plugin_meta' ), 10, 2 );
    5746       
    58     }
    59    
    60     /**
    61      * Set UTC offset based on CET/CEST.
     47        register_activation_hook( __FILE__, array( $this, 'add_scheduled_check_option' ) );
     48       
     49    }
     50   
     51    /**
     52     * Attach functions to the "init" hook.
     53     *
     54     * @since 1.3
     55     */
     56    function init() {
     57       
     58        $this->set_utc_offset();
     59        $this->check_missed_schedules();
     60       
     61    }
     62   
     63    /**
     64     * Set UTC offset and timezone string based on CET/CEST.
    6265     *
    6366     * @since 1.0
    6467     */
    6568    function set_utc_offset() {
    66        
    67         /* WordPress default sets to UTC timezone in wp-settings.php */
    6869       
    6970        if ( function_exists( 'date_default_timezone_set' ) )
    7071            date_default_timezone_set( 'Europe/Amsterdam' ); // choose one, it's all the same
    7172       
    72         /* Now we have the local timezone stored in $timezone,
    73         so lets restore WordPress setting as in wp-settings.php */
    74        
     73        // Store local timezone
     74        $timezone = date( 'T' );
     75       
     76        // Restore default WordPress setting
    7577        if ( function_exists( 'date_default_timezone_set' ) )
    7678            date_default_timezone_set( 'UTC' );
    7779       
     80        $offset = 'CET' === $timezone ? 1 : 2;
     81       
    7882        $current_offset = get_option( 'gmt_offset' );
    79        
    80         $offset = 1; // new offset for CET (UTC+1)
    81        
    82         if ( 'CEST' === $timezone )
    83             $offset = 2;
    8483       
    8584        if ( $offset !== $current_offset )
     
    8786       
    8887        /**
    89          * Set default timezone to show/handle on admin config page
     88         * Set the default timezone to show/handle on the `General Settings` page
    9089         * to avoid confusion and avoid user interference.
    91          * Leave empty so WordPress can automatically
    92          * fill in the offset being used.
     90         * Leave empty so WordPress can automatically fill in the offset being used.
    9391         */
    9492        $timezone_string = '';
    9593       
    96         /** Check if a user messed with the settings */
     94        // Check if a user messed with the settings
    9795        $current_string = get_option( 'timezone_string' );
    9896       
     
    104102   
    105103    /**
    106      * Check missed schedules.
    107      *
    108      * This one is for the nasty WTF!? issues where $this->set_utc_offset() is not enough.
    109      *
    110      * Checks every 5 minutes (if there is traffic on the site)
    111      * for scheduled posts that missed their schedule.
    112      * If it finds them, it publishes them, max 10 items at once.
     104     * Look for scheduled posts that missed their schedule.
     105     *
     106     * This one is for the nasty WTF!? issues where set_utc_offset()
     107     * is not enough or not working.
     108     *
     109     * Checks every 5 minutes (if there is traffic on the site) for
     110     * scheduled posts that missed their schedule.
     111     * If it finds them, it publishes them, max. 10 items at once.
    113112     *
    114113     * @since 1.2
    115114     *
    116      * @global wpdb $wpdb WordPress' class for database manipulations.
    117      *
    118      * @return null Returns early if last check was less than 5 minutes ago.
     115     * @global wpdb $wpdb Interface with the database.
     116     *
     117     * @return null Return null if last check was less than 5 minutes ago.
    119118     */
    120119    function check_missed_schedules() {
     120       
     121        global $wpdb;
    121122       
    122123        $last_check = get_option( 'wpt_scheduled_check' );
     
    129130        update_option( 'wpt_scheduled_check', time() );
    130131       
    131         global $wpdb;
    132        
    133132        $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'future' AND post_date < %s LIMIT 0, 10";
    134133       
     
    144143   
    145144    /**
    146      * Change posts overview page.
    147      *
    148      * Changes the 'Planning failed' message to something more reassuring.
    149      *
    150      * @since 1.2
    151      */
    152     function change_posts_overview_screen() {
    153        
    154         $language = get_bloginfo( 'language' );
    155        
    156         $message = "Planning failed. The WP TimeZone plugin takes care of publication within 5 minutes.";
    157         if ( 'nl-NL' === $language )
    158             $message = "Planning mislukt. De WP TimeZone plugin zorgt voor publicatie binnen 5 minuten.";
    159         if ( 'de-DE' === $language ) {
    160             $message = "Planung gescheitert. Der WP TimeZone Plugin sorgt innerhalb von 5 Minuten f&uuml;r die Ver&ouml;ffentlichung.";
    161             $message = html_entity_decode( $message, ENT_QUOTES, 'UTF-8' );
    162         }
    163        
    164         ?>
    165         <script type="text/javascript">
    166             jQuery(document).ready(function($) {
    167                 $(".column-date .attention").text("<?php echo $message; ?>");
    168             });
    169         </script>
    170         <?php
    171            
    172     }
    173    
    174     /**
    175      * Change the Settings->General Screen to be more clever.
    176      *
    177      * I wish there was a nicer way to do this,
    178      * but the admin pages lack the proper hooks for it.
    179      * Until it gets them, this works.
     145     * Load the plugin's translated strings.
     146     *
     147     * @since 1.3
     148     */
     149    function plugin_translation() {
     150       
     151        load_plugin_textdomain( 'wp-timezone', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     152       
     153    }
     154   
     155    /**
     156     * Replace translatable text generated by WordPress.
     157     *
     158     * - Adds a comment to the `Options General` page so users know the plugin is working.
     159     * - Changes the default `Planning failed` message from WordPress to something more reassuring.
    180160     *
    181161     * @since 1.0
    182      */
    183      function change_settings_screen() {
    184         ob_start( array( $this, 'replace_text' ) );
    185     }
    186    
    187     /**
    188      * Replace WordPress generated text with a comment.
    189      *
    190      * @since 1.0
    191      *
    192      * @param  $buffer The output buffer holding the page data.
    193      * @return $final The page data with the replaced text.
    194      */
    195     function replace_text( $buffer ) {
    196        
    197         $converted = htmlentities( $buffer, ENT_QUOTES, 'UTF-8' );
    198        
    199         $search = array(
    200             'Kies een plaats in dezelfde tijdzone als waarin je zit.', // Dutch
    201             'Choose a city in the same timezone as you.',              // English
    202             'W&auml;hle eine Stadt, die in deiner Zeitzone liegt.',    // German
    203         );
    204         $replace = array(
    205             'Tijdzones worden autmatisch beheerd door de WP TimeZone plugin.',
    206             'Timezones are automatically managed by the WP TimeZone plugin.',
    207             'Zeitzonen werden automatisch verwaltet bei der WP TimeZone Plugin.',
    208         );
    209        
    210         $new_string = str_replace( $search, $replace, $converted );
    211        
    212         $final = html_entity_decode( $new_string, ENT_QUOTES, 'UTF-8' );
    213        
    214         return $final;
    215        
    216         ob_end_clean();
     162     *
     163     * @param  string $translated_text Translated text.
     164     * @param  string $untranslated_text Untranslated text.
     165     * @param  string $text_domain Text domain.
     166     * @return string Translated text.
     167     */
     168    function replace_text( $translated_text, $untranslated_text, $text_domain ) {
     169       
     170        global $pagenow;
     171       
     172        if ( ! is_admin() )
     173            return $translated_text;
     174       
     175        if ( 'options-general.php' === $pagenow ) {
     176            if ( 'Choose a city in the same timezone as you.' === $untranslated_text )
     177                $translated_text = __( 'Timezones are automatically managed by the WP TimeZone plugin.', 'wp-timezone' );
     178        }
     179       
     180        if ( 'edit.php' === $pagenow ) {
     181            if ( 'Missed schedule' === $untranslated_text )
     182                $translated_text = __( 'Missed schedule. The WP TimeZone plugin takes care of publication within 5 minutes.', 'wp-timezone' );
     183        }
     184       
     185        return $translated_text;
    217186       
    218187    }
     
    223192     * @since 1.1
    224193     *
    225      * @param  array $links The current links.
     194     * @param  array $links Current links.
    226195     * @param  string $file Path to this plugin directory.
    227      * @return array $links All links including donate link.
     196     * @return array All links including donate link.
    228197     */
    229198    function filter_plugin_meta( $links, $file ) {
    230199       
    231200        if ( plugin_basename( __FILE__ ) === $file ) {
    232            
    233             $language = get_bloginfo( 'language' );
    234             $donate   = 'Donate';
    235            
    236             if ( 'nl-NL' === $language )
    237                 $donate = 'Doneer';
    238            
    239             if ( 'de-DE' === $language )
    240                 $donate = 'Spenden';
    241            
    242201            return array_merge(
    243202                    $links,
    244                     array( sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3H3RWC5JULGJ4" target="_blank">%s</a>', __( $donate ) ) )
     203                    array( sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3H3RWC5JULGJ4" target="_blank">%s</a>', __( 'Donate', 'wp-timezone' ) ) )
    245204            );
    246205        }
    247206       
    248207        return $links;
     208       
     209    }
     210   
     211    /**
     212     * Add an option to the database for checking of scheduled posts that missed their schedule.
     213     *
     214     * @see check_missed_schedules()
     215     *
     216     * @since 1.2
     217     */
     218    function add_scheduled_check_option() {
     219       
     220        add_option( 'wpt_scheduled_check', time() );
     221       
    249222    }
    250223   
    251224}
    252225
    253 $wp_timezone = new WP_Timezone();
     226$wp_timezone = new WP_TimeZone();
Note: See TracChangeset for help on using the changeset viewer.