Changeset 837066
- Timestamp:
- 01/12/2014 10:57:34 AM (12 years ago)
- Location:
- wp-timezone/tags/1.3
- Files:
-
- 5 added
- 2 edited
- 1 copied
-
. (copied) (copied from wp-timezone/trunk)
-
languages (added)
-
languages/wp-timezone-de_DE.mo (added)
-
languages/wp-timezone-de_DE.po (added)
-
languages/wp-timezone-nl_NL.mo (added)
-
languages/wp-timezone-nl_NL.po (added)
-
readme.txt (modified) (2 diffs)
-
wp-timezone.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-timezone/tags/1.3/readme.txt
r799407 r837066 5 5 Requires at least: 3.1 6 6 Tested up to: 3.7.1 7 Stable tag: 1. 27 Stable tag: 1.3 8 8 License: GPL v3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 29 29 == Changelog == 30 30 31 = 1.3 = 32 * Bugfix 33 * Even better and faster code 34 31 35 = 1.2 = 32 36 * 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 1 1 <?php 2 2 /** 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/>. 10 25 */ 11 12 /* Copyright (c) 2013, Ezra Verheijen - [email protected]13 14 This program is free software: you can redistribute it and/or modify15 it under the terms of the GNU General Public License as published by16 the Free Software Foundation, either version 3 of the License, or17 (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 of21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the22 GNU General Public License for more details.23 24 You should have received a copy of the GNU General Public License25 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 be29 placed in 'mu-plugins' (http://codex.wordpress.org/Must_Use_Plugins). */30 31 if ( ! defined( 'ABSPATH' ) ) exit; // exit if accessed directly32 26 33 27 /** … … 36 30 * @since 1.1 37 31 */ 38 class WP_Timezone { 39 40 /** 41 * Constructor. 42 * 43 * Attaches all functionalities of this plugin to the correct Wordpress hooks. 32 class WP_TimeZone { 33 34 /** 35 * Attach all functionalities to the correct hooks and filters. 44 36 * 45 37 * @since 1.1 … … 47 39 function __construct() { 48 40 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 ); 56 45 add_filter( 'plugin_row_meta', array( $this, 'filter_plugin_meta' ), 10, 2 ); 57 46 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. 62 65 * 63 66 * @since 1.0 64 67 */ 65 68 function set_utc_offset() { 66 67 /* WordPress default sets to UTC timezone in wp-settings.php */68 69 69 70 if ( function_exists( 'date_default_timezone_set' ) ) 70 71 date_default_timezone_set( 'Europe/Amsterdam' ); // choose one, it's all the same 71 72 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 75 77 if ( function_exists( 'date_default_timezone_set' ) ) 76 78 date_default_timezone_set( 'UTC' ); 77 79 80 $offset = 'CET' === $timezone ? 1 : 2; 81 78 82 $current_offset = get_option( 'gmt_offset' ); 79 80 $offset = 1; // new offset for CET (UTC+1)81 82 if ( 'CEST' === $timezone )83 $offset = 2;84 83 85 84 if ( $offset !== $current_offset ) … … 87 86 88 87 /** 89 * Set default timezone to show/handle on admin configpage88 * Set the default timezone to show/handle on the `General Settings` page 90 89 * 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. 93 91 */ 94 92 $timezone_string = ''; 95 93 96 / ** Check if a user messed with the settings */94 // Check if a user messed with the settings 97 95 $current_string = get_option( 'timezone_string' ); 98 96 … … 104 102 105 103 /** 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. 113 112 * 114 113 * @since 1.2 115 114 * 116 * @global wpdb $wpdb WordPress' class for database manipulations.117 * 118 * @return null Return s earlyif 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. 119 118 */ 120 119 function check_missed_schedules() { 120 121 global $wpdb; 121 122 122 123 $last_check = get_option( 'wpt_scheduled_check' ); … … 129 130 update_option( 'wpt_scheduled_check', time() ); 130 131 131 global $wpdb;132 133 132 $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'future' AND post_date < %s LIMIT 0, 10"; 134 133 … … 144 143 145 144 /** 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ür die Verö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. 180 160 * 181 161 * @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ä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; 217 186 218 187 } … … 223 192 * @since 1.1 224 193 * 225 * @param array $links The current links.194 * @param array $links Current links. 226 195 * @param string $file Path to this plugin directory. 227 * @return array $linksAll links including donate link.196 * @return array All links including donate link. 228 197 */ 229 198 function filter_plugin_meta( $links, $file ) { 230 199 231 200 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 242 201 return array_merge( 243 202 $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' ) ) ) 245 204 ); 246 205 } 247 206 248 207 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 249 222 } 250 223 251 224 } 252 225 253 $wp_timezone = new WP_Time zone();226 $wp_timezone = new WP_TimeZone();
Note: See TracChangeset
for help on using the changeset viewer.