| @@ -1,35 +1,33 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: Timed Content |
| 4 | 4 | Text Domain: timed-content |
| 5 | +Domain Path: /lang | |
| 5 | 6 | Plugin URI: http://wordpress.org/plugins/timed-content/ |
| 6 | 7 | Description: Plugin to show or hide portions of a Page or Post based on specific date/time characteristics. These actions can either be processed either server-side or client-side, depending on the desired effect. |
| 7 | -Author: K. Tough | |
| 8 | -Version: 2.1.2 | |
| 8 | +Author: K. Tough, Arno Welzel | |
| 9 | +Version: 2.7 | |
| 9 | 10 | Author URI: http://wordpress.org/plugins/timed-content/ |
| 10 | 11 | */ |
| 11 | 12 | if ( !class_exists( "timedContentPlugin" ) ) { |
| 12 | 13 | |
| 13 | - define( "TIMED_CONTENT_VERSION", "2.1.2" ); | |
| 14 | - define( "TIMED_CONTENT_PLUGIN_URL", plugins_url() . '/timed-content' ); | |
| 15 | - define( "TIMED_CONTENT_CLIENT_TAG", "timed-content-client" ); | |
| 14 | + define( "TIMED_CONTENT_VERSION", "2.7" ); | |
| 15 | + define( "TIMED_CONTENT_SLUG", "timed-content" ); | |
| 16 | + define( "TIMED_CONTENT_PLUGIN_URL", plugins_url() . '/' . TIMED_CONTENT_SLUG ); | |
| 17 | + define( "TIMED_CONTENT_CLIENT_TAG", "timed-content-client" ); | |
| 16 | 18 | define( "TIMED_CONTENT_SERVER_TAG", "timed-content-server" ); |
| 17 | 19 | define( "TIMED_CONTENT_RULE_TAG", "timed-content-rule" ); |
| 18 | 20 | define( "TIMED_CONTENT_ZERO_TIME", "1970-Jan-01 00:00:00 +000" ); // Start of Unix Epoch |
| 19 | 21 | define( "TIMED_CONTENT_END_TIME", "2038-Jan-19 03:14:07 +000" ); // End of Unix Epoch |
| 20 | - /* translators: date/time format for debugging messages. */ | |
| 21 | - define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i A T" , 'timed-content' ) ); | |
| 22 | 22 | define( "TIMED_CONTENT_RULE_TYPE", "timed_content_rule" ); |
| 23 | 23 | define( "TIMED_CONTENT_RULE_POSTMETA_PREFIX", TIMED_CONTENT_RULE_TYPE . "_" ); |
| 24 | 24 | define( "TIMED_CONTENT_CSS", TIMED_CONTENT_PLUGIN_URL . "/css/timed-content.css" ); |
| 25 | - define( "TIMED_CONTENT_CSS_DASHICONS", TIMED_CONTENT_PLUGIN_URL . "/css/timed-content-icons/style.css" ); | |
| 26 | - // Required for styling the JQuery UI Datepicker and JQuery UI Timepicker | |
| 25 | + define( "TIMED_CONTENT_CSS_DASHICONS", TIMED_CONTENT_PLUGIN_URL . "/css/ca-aliencyborg-dashicons/style.css" ); | |
| 26 | + // Required for styling the jQuery UI Datepicker and jQuery UI Timepicker | |
| 27 | 27 | define( "TIMED_CONTENT_JQUERY_UI_CSS", TIMED_CONTENT_PLUGIN_URL . "/css/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" ); |
| 28 | - define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS", TIMED_CONTENT_PLUGIN_URL."/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.js" ); | |
| 29 | - define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS", TIMED_CONTENT_PLUGIN_URL."/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.css" ); | |
| 30 | - require_once( "lib/customFields-settings.php" ); | |
| 31 | - require_once( "lib/customFieldsInterface.php" ); | |
| 28 | + define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS", TIMED_CONTENT_PLUGIN_URL . "/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.js" ); | |
| 29 | + define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS", TIMED_CONTENT_PLUGIN_URL . "/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.css" ); | |
| 32 | 30 | |
| 33 | 31 | |
| 34 | 32 | /** |
| 35 | 33 | * Class timedContentPlugin |
| @@ -38,14 +36,156 @@ | ||
| 38 | 36 | * the possibility of name collisions with other plugins. |
| 39 | 37 | */ |
| 40 | 38 | class timedContentPlugin { |
| 41 | 39 | |
| 40 | + function __construct() { | |
| 41 | + //constructor | |
| 42 | + | |
| 43 | + } | |
| 44 | + | |
| 42 | 45 | function timedContentPlugin() { |
| 43 | - //constructor | |
| 46 | + self::__construct(); | |
| 44 | 47 | |
| 45 | 48 | } |
| 49 | + | |
| 50 | + /** https://core.trac.wordpress.org/ticket/25768 | |
| 51 | + * | |
| 52 | + * Modified from the original patch to use the currently set | |
| 53 | + * timezone from PHP, like PHP's date(), and to make the code | |
| 54 | + * more readable. | |
| 55 | + * | |
| 56 | + * @param $j | |
| 57 | + * @param $req_format | |
| 58 | + * @param bool $i | |
| 59 | + * @param bool $gmt | |
| 60 | + * @return bool|string | |
| 61 | + */ | |
| 62 | + function fix_date_i18n($j, $req_format, $i = false, $gmt = false) | |
| 63 | + { | |
| 64 | + /* @var $wp_locale WP_Locale */ | |
| 65 | + global $wp_locale; | |
| 66 | + $timestamp = $i; | |
| 46 | 67 | |
| 47 | - /** | |
| 68 | + // get current timestamp if $i is false | |
| 69 | + if (false === $timestamp) | |
| 70 | + { | |
| 71 | + if ($gmt) | |
| 72 | + $timestamp = time(); | |
| 73 | + else | |
| 74 | + $timestamp = current_time('timestamp'); | |
| 75 | + } | |
| 76 | + | |
| 77 | + | |
| 78 | + // get components of the date (timestamp) as array | |
| 79 | + $date_components = getdate($timestamp); | |
| 80 | + | |
| 81 | + // numeric representation of a month, with leading zeros | |
| 82 | + $date_month = $wp_locale->get_month($date_components['mon']); | |
| 83 | + $date_month_abbrev = $wp_locale->get_month_abbrev($date_month); | |
| 84 | + // numeric representation of the day of the week | |
| 85 | + $date_weekday = $wp_locale->get_weekday($date_components['wday']); | |
| 86 | + $date_weekday_abbrev = $wp_locale->get_weekday_abbrev($date_weekday); | |
| 87 | + // get if hour is Ante meridiem or Post meridiem | |
| 88 | + $meridiem = $date_components['hours'] >= 12 ? 'pm' : 'am'; | |
| 89 | + // lowercase Ante meridiem and Post meridiem hours | |
| 90 | + $date_meridiem = $wp_locale->get_meridiem($meridiem); | |
| 91 | + // uppercase Ante meridiem and Post meridiem | |
| 92 | + $date_meridiem_capital = $wp_locale->get_meridiem(strtoupper($meridiem)); | |
| 93 | + | |
| 94 | + // escape literals | |
| 95 | + $date_weekday_abbrev = backslashit($date_weekday_abbrev); | |
| 96 | + $date_month = backslashit($date_month); | |
| 97 | + $date_weekday = backslashit($date_weekday); | |
| 98 | + $date_month_abbrev = backslashit($date_month_abbrev); | |
| 99 | + $date_meridiem = backslashit($date_meridiem); | |
| 100 | + $date_meridiem_capital = backslashit($date_meridiem_capital); | |
| 101 | + | |
| 102 | + // the translated format string | |
| 103 | + $translated_date_format_string = ''; | |
| 104 | + // the 2 arrays map a format literal to its translation (e. g. 'F' to the escaped month translation) | |
| 105 | + $translate_formats = array('D', 'F', 'l', 'M', 'a', 'A', 'c', 'r'); | |
| 106 | + $translations = array( | |
| 107 | + $date_weekday_abbrev, // D | |
| 108 | + $date_month, // F | |
| 109 | + $date_weekday, // l | |
| 110 | + $date_month_abbrev, // M | |
| 111 | + $date_meridiem, // a | |
| 112 | + $date_meridiem_capital, // A | |
| 113 | + 'Y-m-d\TH:i:sP', // c | |
| 114 | + sprintf('%s, d %s Y H:i:s O', $date_weekday_abbrev, $date_month_abbrev), // r | |
| 115 | + ); | |
| 116 | + | |
| 117 | + // find each format literal that needs translation and replace it by its translation | |
| 118 | + // respects the escaping | |
| 119 | + // iterate $req_format from ending to beginning | |
| 120 | + for ($i = strlen($req_format) - 1; $i > -1; $i--) | |
| 121 | + { | |
| 122 | + // test if current char is format literal that needs translation | |
| 123 | + $translate_formats_index = array_search($req_format[$i], $translate_formats); | |
| 124 | + | |
| 125 | + if ($translate_formats_index !== false) | |
| 126 | + { | |
| 127 | + // counts the slashes (the escape char) in front of the current char | |
| 128 | + $slashes_counter = 0; | |
| 129 | + | |
| 130 | + // count all slashes left-hand side of the current char | |
| 131 | + for ($j = $i - 1; $j > -1; $j--) | |
| 132 | + { | |
| 133 | + if ($req_format[$j] == '\\') | |
| 134 | + $slashes_counter++; | |
| 135 | + else | |
| 136 | + break; | |
| 137 | + } | |
| 138 | + | |
| 139 | + // number of slashes is even | |
| 140 | + if ($slashes_counter % 2 == 0) | |
| 141 | + // current char is not escaped, therefore it is a format literal | |
| 142 | + $translated_date_format_string = $translations[$translate_formats_index] . $translated_date_format_string; | |
| 143 | + else | |
| 144 | + // current char is escaped, therefore it is not a format literal, just add it unchanged | |
| 145 | + $translated_date_format_string = $req_format[$i] . $translated_date_format_string; | |
| 146 | + } | |
| 147 | + else | |
| 148 | + // current char is no a format literal, just add it unchanged | |
| 149 | + $translated_date_format_string = $req_format[$i] . $translated_date_format_string; | |
| 150 | + } | |
| 151 | + | |
| 152 | + $req_format = $translated_date_format_string; | |
| 153 | + | |
| 154 | + if ($gmt) | |
| 155 | + // get GMT date string | |
| 156 | + $date_formatted = gmdate($req_format, $timestamp); | |
| 157 | + else | |
| 158 | + { | |
| 159 | + // get Wordpress time zone | |
| 160 | + // $timezone_string = get_option('timezone_string'); | |
| 161 | + // Haha, just kidding. Let's get the currently set timezone, as God and Rasmus intended | |
| 162 | + $timezone_string = date_default_timezone_get(); | |
| 163 | + | |
| 164 | + if ($timezone_string) | |
| 165 | + { | |
| 166 | + // create time zone object | |
| 167 | + $timezone_object = timezone_open($timezone_string); | |
| 168 | + // create date object from time zone object | |
| 169 | + $local_date_object = date_create(null, $timezone_object); | |
| 170 | + // set time and date of $local_date_object to $timestamp | |
| 171 | + $date_components = isset($date_components) ? $date_components : getdate($timestamp); | |
| 172 | + date_date_set($local_date_object, $date_components['year'], $date_components['mon'], $date_components['mday']); | |
| 173 | + date_time_set($local_date_object, $date_components['hours'], $date_components['minutes'], $date_components['seconds']); | |
| 174 | + // format date according to the Wordpress time zone | |
| 175 | + $date_formatted = date_format($local_date_object, $req_format); | |
| 176 | + } | |
| 177 | + else | |
| 178 | + { | |
| 179 | + // fall back if no Wordpress time zone set | |
| 180 | + $date_formatted = date($req_format, $i); | |
| 181 | + } | |
| 182 | + } | |
| 183 | + | |
| 184 | + return $date_formatted; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 48 | 188 | * Creates the Timed Content Rule post type and registers it with Wordpress |
| 49 | 189 | * |
| 50 | 190 | */ |
| 51 | 191 | function timedContentRuleTypeInit() |
| @@ -52,9 +192,9 @@ | ||
| 52 | 192 | { |
| 53 | 193 | $labels = array( |
| 54 | 194 | 'name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' ), |
| 55 | 195 | 'singular_name' => _x( 'Timed Content Rule', 'post type singular name', 'timed-content' ), |
| 56 | - 'add_new' => _x( 'Add New', TIMED_CONTENT_RULE_TYPE, 'timed-content' ), | |
| 196 | + 'add_new' => _x( 'Add New', 'Menu item/button label on Timed Content Rules admin page', 'timed-content' ), | |
| 57 | 197 | 'add_new_item' => __( 'Add New Timed Content Rule', 'timed-content' ), |
| 58 | 198 | 'edit_item' => __( 'Edit Timed Content Rule', 'timed-content' ), |
| 59 | 199 | 'new_item' => __( 'New Timed Content Rule', 'timed-content' ), |
| 60 | 200 | 'view_item' => __( 'View Timed Content Rule', 'timed-content' ), |
| @@ -61,9 +201,9 @@ | ||
| 61 | 201 | 'search_items' => __( 'Search Timed Content Rules', 'timed-content' ), |
| 62 | 202 | 'not_found' => __( 'No Timed Content Rules found', 'timed-content' ), |
| 63 | 203 | 'not_found_in_trash' => __( 'No Timed Content Rules found in Trash', 'timed-content' ), |
| 64 | 204 | 'parent_item_colon' => '', |
| 65 | - 'menu_name' =>_x( 'Timed Content Rules', 'post type general name', 'timed-content' ) | |
| 205 | + 'menu_name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' ) | |
| 66 | 206 | ); |
| 67 | 207 | $args = array( |
| 68 | 208 | 'labels' => $labels, |
| 69 | 209 | 'description' => __( 'Create regular schedules to show or hide selected content in a Page or Post.', 'timed-content' ), |
| @@ -84,9 +224,8 @@ | ||
| 84 | 224 | ); |
| 85 | 225 | register_post_type( TIMED_CONTENT_RULE_TYPE, $args ); |
| 86 | 226 | } |
| 87 | 227 | |
| 88 | - | |
| 89 | 228 | /** |
| 90 | 229 | * Filter to customize CRUD messages for Timed Content Rules |
| 91 | 230 | * |
| 92 | 231 | * @param array $messages Array of currently defined messages for post types |
| @@ -93,10 +232,12 @@ | ||
| 93 | 232 | * @return mixed Array of messages with appropriate messages for Timed Content Rules added in |
| 94 | 233 | */ |
| 95 | 234 | function timedContentRuleUpdatedMessages( $messages ) { |
| 96 | 235 | global $post; |
| 97 | -// global $post_ID; | |
| 98 | - | |
| 236 | + | |
| 237 | + /* translators: date and time format to activate rule. http://ca2.php.net/manual/en/function.date.php*/ | |
| 238 | + $post_date = date_i18n( __( 'M j, Y @ G:i', 'timed-content' ), strtotime( $post->post_date ) ); | |
| 239 | + | |
| 99 | 240 | $messages[TIMED_CONTENT_RULE_TYPE] = array( |
| 100 | 241 | 0 => '', // Unused. Messages start at index 1. |
| 101 | 242 | 1 => __( 'Timed Content Rule updated.', 'timed-content' ), |
| 102 | 243 | 2 => __( 'Custom field updated.', 'timed-content' ), |
| @@ -106,10 +247,10 @@ | ||
| 106 | 247 | 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Timed Content Rule restored to revision from %s', 'timed-content' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
| 107 | 248 | 6 => __( 'Timed Content Rule published.', 'timed-content' ), |
| 108 | 249 | 7 => __( 'Timed Content Rule saved.', 'timed-content' ), |
| 109 | 250 | 8 => __( 'Timed Content Rule submitted.', 'timed-content' ), |
| 110 | - /* translators: %s: date and time to activate rule */ | |
| 111 | - 9 => sprintf( __('Timed Content Rule scheduled for: <strong>%1$s</strong>.', 'timed-content' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ), | |
| 251 | + /* translators: %s: date and time to activate rule. */ | |
| 252 | + 9 => sprintf( __( 'Timed Content Rule scheduled for: %s.' , 'timed-content' ), "<strong>" . $post_date . "</strong>" ), | |
| 112 | 253 | 10 => __( 'Timed Content Rule draft updated.', 'timed-content' ) |
| 113 | 254 | ); |
| 114 | 255 | |
| 115 | 256 | return $messages; |
| @@ -114,8 +255,37 @@ | ||
| 114 | 255 | |
| 115 | 256 | return $messages; |
| 116 | 257 | } |
| 117 | 258 | |
| 259 | + function __datetimeToEnglish( $date, $time = "" ) { | |
| 260 | + $months = array( "January", | |
| 261 | + "February", | |
| 262 | + "March", | |
| 263 | + "April", | |
| 264 | + "May", | |
| 265 | + "June", | |
| 266 | + "July", | |
| 267 | + "August", | |
| 268 | + "September", | |
| 269 | + "October", | |
| 270 | + "November", | |
| 271 | + "December" ); | |
| 272 | + $monthsI18N = array( __( "January", 'timed-content' ), | |
| 273 | + __( "February", 'timed-content' ), | |
| 274 | + __( "March", 'timed-content' ), | |
| 275 | + __( "April", 'timed-content' ), | |
| 276 | + __( "May", 'timed-content' ), | |
| 277 | + __( "June", 'timed-content' ), | |
| 278 | + __( "July", 'timed-content' ), | |
| 279 | + __( "August", 'timed-content' ), | |
| 280 | + __( "September", 'timed-content' ), | |
| 281 | + __( "October", 'timed-content' ), | |
| 282 | + __( "November", 'timed-content' ), | |
| 283 | + __( "December", 'timed-content' ) ); | |
| 284 | + $english_date = str_replace( $monthsI18N, $months, $date ); | |
| 285 | + return $english_date . " " . $time; | |
| 286 | + } | |
| 287 | + | |
| 118 | 288 | /** |
| 119 | 289 | * Advances a date/time by a set number of days |
| 120 | 290 | * |
| 121 | 291 | * @param int $current UNIX timestamp of the date/time before incrementing |
| @@ -156,9 +326,12 @@ | ||
| 156 | 326 | |
| 157 | 327 | // Otherwise, set up an array combining the days of the week to repeat on and the current day |
| 158 | 328 | // (keys and values of the array will be the same, and the array is sorted) |
| 159 | 329 | $currentDayOfWeekIndex = date( "w", $current ); |
| 160 | - sort( array_values( array_unique( array_merge( array( $currentDayOfWeekIndex ), $days ) ) ) ); | |
| 330 | + $days = array_merge( array( $currentDayOfWeekIndex ), $days ); | |
| 331 | + $days = array_unique( $days ); | |
| 332 | + $days = array_values( $days ); | |
| 333 | + sort( $days ); | |
| 161 | 334 | $daysOfWeek = array_combine( $days, $days ); |
| 162 | 335 | |
| 163 | 336 | // If the current day is the last one of the days of the week to repeat on, jump ahead to |
| 164 | 337 | // the next week to be repeating on and get the earliest day in the array |
| @@ -290,27 +463,27 @@ | ||
| 290 | 463 | $the_day = ""; |
| 291 | 464 | |
| 292 | 465 | if ( $day == 7 ) { // If $day is "day of the month", get the day of month based on the ordinal |
| 293 | 466 | switch ( $ordinal ) { |
| 294 | - case 1 : $the_day = "1"; break; // First day of the month // | |
| 295 | - case 2 : $the_day = "2"; break; // Second day of the month // | |
| 296 | - case 3 : $the_day = "3"; break; // Third day of the month // | |
| 297 | - case 4 : $the_day = "4"; break; // Fourth day of the month // | |
| 298 | - case 5 : $the_day = $lastDayThisMonth; break; // Last day of the month // | |
| 467 | + case 0 : $the_day = "1"; break; // First day of the month // | |
| 468 | + case 1 : $the_day = "2"; break; // Second day of the month // | |
| 469 | + case 2 : $the_day = "3"; break; // Third day of the month // | |
| 470 | + case 3 : $the_day = "4"; break; // Fourth day of the month // | |
| 471 | + case 4 : $the_day = $lastDayThisMonth; break; // Last day of the month // | |
| 299 | 472 | default : $the_day = "1"; break; |
| 300 | 473 | } |
| 301 | 474 | } else { // If $day is one of the days of the week... |
| 302 | 475 | $day_range = array(); |
| 303 | 476 | switch ( $ordinal ) { // ...get a 7-day range based on the ordinal... |
| 304 | - case 1 : $day_range = range( 1, 7 ); break; // First 7 days of the month // | |
| 305 | - case 2 : $day_range = range( 8, 14 ); break; // Second 7 days of the month // | |
| 306 | - case 3 : $day_range = range( 15, 21 ); break; // Third 7 days of the month // | |
| 307 | - case 4 : $day_range = range( 22, 28 ); break; // Fourth 7 days of the month // | |
| 308 | - case 5 : $day_range = range( $lastDayThisMonth - 6, $lastDayThisMonth ); break; // Last 7 days of the month // | |
| 477 | + case 0 : $day_range = range( 1, 7 ); break; // First 7 days of the month // | |
| 478 | + case 1 : $day_range = range( 8, 14 ); break; // Second 7 days of the month // | |
| 479 | + case 2 : $day_range = range( 15, 21 ); break; // Third 7 days of the month // | |
| 480 | + case 3 : $day_range = range( 22, 28 ); break; // Fourth 7 days of the month // | |
| 481 | + case 4 : $day_range = range( $lastDayThisMonth - 6, $lastDayThisMonth ); break; // Last 7 days of the month // | |
| 309 | 482 | default : $day_range = range( 1, 7 ); break; |
| 310 | 483 | } |
| 311 | 484 | foreach ( $day_range as $a_day ) { // ...and find the matching weekday in that range. |
| 312 | - if ( $day == date( "l", strtotime( $the_month . " " . $a_day . ", " . $the_year ) ) ) { | |
| 485 | + if ( $day == date( "w", strtotime( $the_month . " " . $a_day . ", " . $the_year ) ) ) { | |
| 313 | 486 | $the_day = $a_day; |
| 314 | 487 | break; |
| 315 | 488 | } |
| 316 | 489 | } |
| @@ -341,11 +514,11 @@ | ||
| 341 | 514 | */ |
| 342 | 515 | function __validate( $args ) { |
| 343 | 516 | $errors = array(); |
| 344 | 517 | |
| 345 | - $instance_start = strtotime( $args['instance_start']['date'] . '' . $args['instance_start']['time'] . ' ' . $args['timezone'] ); | |
| 346 | - $instance_end = strtotime( $args['instance_end']['date'] . '' . $args['instance_end']['time'] . ' ' . $args['timezone'] ); | |
| 347 | - $end_date = strtotime( $args['end_date'] . '' . $args['instance_start']['time'] . ' ' . $args['timezone'] ); | |
| 518 | + $instance_start = strtotime( $this->__datetimeToEnglish( $args['instance_start']['date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] ); | |
| 519 | + $instance_end = strtotime( $this->__datetimeToEnglish( $args['instance_end']['date'], $args['instance_end']['time'] ) . ' ' . $args['timezone'] ); | |
| 520 | + $end_date = strtotime( $this->__datetimeToEnglish( $args['end_date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] ); | |
| 348 | 521 | |
| 349 | 522 | if ( $args['instance_start']['date'] == "" ) |
| 350 | 523 | $errors[] = __( "Date in Starting Date/Time must not be empty.", 'timed-content' ); |
| 351 | 524 | if ( $args['instance_start']['time'] == "" ) |
| @@ -403,16 +576,18 @@ | ||
| 403 | 576 | $instance_end_time = $args['instance_end']['time']; |
| 404 | 577 | $monthly_pattern = $args['monthly_pattern']; |
| 405 | 578 | $monthly_pattern_ord = $args['monthly_pattern_ord']; |
| 406 | 579 | $monthly_pattern_day = $args['monthly_pattern_day']; |
| 580 | + $exceptions_dates = $args['exceptions_dates']; | |
| 407 | 581 | //print_r($days_of_week); |
| 408 | 582 | |
| 583 | + add_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4); | |
| 409 | 584 | $temp_tz = date_default_timezone_get(); |
| 410 | 585 | date_default_timezone_set( $timezone ); |
| 411 | - $right_now_t = time(); | |
| 586 | + $right_now_t = current_time( 'timestamp', 1 ); | |
| 412 | 587 | |
| 413 | - $instance_start = strtotime( $instance_start_date . " " . $instance_start_time . " " . $timezone ); // Beginning of first occurrence | |
| 414 | - $instance_end = strtotime( $instance_end_date . " " . $instance_end_time . " " . $timezone ); // End of first occurrence | |
| 588 | + $instance_start = strtotime( $this->__datetimeToEnglish( $instance_start_date, $instance_start_time ) . " " . $timezone ); // Beginning of first occurrence | |
| 589 | + $instance_end = strtotime( $this->__datetimeToEnglish( $instance_end_date, $instance_end_time ) . " " . $timezone ); // End of first occurrence | |
| 415 | 590 | $current = $instance_start; |
| 416 | 591 | $end_current = $instance_end; |
| 417 | 592 | |
| 418 | 593 | if ( $recurr_type == "recurrence_duration_num_repeat" ) |
| @@ -417,27 +592,27 @@ | ||
| 417 | 592 | |
| 418 | 593 | if ( $recurr_type == "recurrence_duration_num_repeat" ) |
| 419 | 594 | $last_occurrence_start = strtotime( TIMED_CONTENT_END_TIME ); |
| 420 | 595 | else |
| 421 | - $last_occurrence_start = strtotime( $end_date . " " . $instance_start_time . " " . $timezone ); | |
| 596 | + $last_occurrence_start = strtotime( $this->__datetimeToEnglish( $end_date, $instance_start_time ) . " " . $timezone ); | |
| 422 | 597 | |
| 423 | 598 | if ( $human_readable == true ) { |
| 424 | - $active_periods[$period_count]["start"] = date( TIMED_CONTENT_DT_FORMAT, $current ); | |
| 425 | - $active_periods[$period_count]["end"] = date( TIMED_CONTENT_DT_FORMAT, $end_current ); | |
| 599 | + $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current ); | |
| 600 | + $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current ); | |
| 601 | + if ( $right_now_t < $current ) { | |
| 602 | + $active_periods[$period_count]["status"] = "upcoming"; | |
| 603 | + $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $right_now_t, $current ) ); | |
| 604 | + } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) { | |
| 605 | + $active_periods[$period_count]["status"] = "active"; | |
| 606 | + $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' ); | |
| 607 | + } else { | |
| 608 | + $active_periods[$period_count]["status"] = "expired"; | |
| 609 | + $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) ); | |
| 610 | + } | |
| 426 | 611 | } else { |
| 427 | 612 | $active_periods[$period_count]["start"] = $current; |
| 428 | 613 | $active_periods[$period_count]["end"] = $end_current; |
| 429 | 614 | } |
| 430 | - if ( $right_now_t < $current ) { | |
| 431 | - $active_periods[$period_count]["status"] = "upcoming"; | |
| 432 | - $active_periods[$period_count]["time"] = sprintf( __( '%s from now.', 'timed-content' ), human_time_diff( $current, $right_now_t ) ); | |
| 433 | - } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) { | |
| 434 | - $active_periods[$period_count]["status"] = "active"; | |
| 435 | - $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' ); | |
| 436 | - } else { | |
| 437 | - $active_periods[$period_count]["status"] = "expired"; | |
| 438 | - $active_periods[$period_count]["time"] = sprintf( __( '%s ago.', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) ); | |
| 439 | - } | |
| 440 | 615 | $period_count++; |
| 441 | 616 | |
| 442 | 617 | if ( $recurr_type == "recurrence_duration_end_date" ) |
| 443 | 618 | $loop_test = "return ( \$current < \$last_occurrence_start );"; |
| @@ -454,37 +629,51 @@ | ||
| 454 | 629 | $current = $this->__getNextWeek( $current, $interval_multiplier, $days_of_week ); |
| 455 | 630 | elseif ( $freq == 3 ) { |
| 456 | 631 | $current = $this->__getNextMonth( $current, $instance_start, $interval_multiplier ); |
| 457 | 632 | $temp_current = $current; |
| 458 | - if ( $monthly_pattern == "yes" ) $current = $this->__getNthWeekdayOfMonth( $current, $monthly_pattern_ord, $monthly_pattern_day ); | |
| 633 | + if ( $monthly_pattern == "yes" ) | |
| 634 | + $current = $this->__getNthWeekdayOfMonth( $current, $monthly_pattern_ord, $monthly_pattern_day ); | |
| 635 | + else | |
| 636 | + $current = $temp_current; | |
| 459 | 637 | } elseif ( $freq == 4 ) |
| 460 | 638 | $current = $this->__getNextYear( $current, $interval_multiplier ); |
| 461 | - | |
| 462 | - if ( eval ( $loop_test ) ) { | |
| 639 | + | |
| 640 | + $exception_period = false; | |
| 641 | + if ( is_array( $exceptions_dates ) ) { | |
| 642 | + foreach ($exceptions_dates as $date) { | |
| 643 | + if (($current >= $date) && ($current < strtotime("+1 day", $date))) { | |
| 644 | + $exception_period = true; | |
| 645 | + break; | |
| 646 | + } | |
| 647 | + } | |
| 648 | + } | |
| 649 | + | |
| 650 | + if ( ( eval ( $loop_test ) ) && ( !($exception_period) ) ) { | |
| 463 | 651 | $end_current = $current + ( $instance_end - $instance_start ); |
| 464 | 652 | if ( $human_readable == true ) { |
| 465 | - $active_periods[$period_count]["start"] = date( TIMED_CONTENT_DT_FORMAT, $current ); | |
| 466 | - $active_periods[$period_count]["end"] = date( TIMED_CONTENT_DT_FORMAT, $end_current ); | |
| 653 | + $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current ); | |
| 654 | + $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current ); | |
| 655 | + if ( $right_now_t < $current ) { | |
| 656 | + $active_periods[$period_count]["status"] = "upcoming"; | |
| 657 | + $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) ); | |
| 658 | + } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) { | |
| 659 | + $active_periods[$period_count]["status"] = "active"; | |
| 660 | + $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' ); | |
| 661 | + } else { | |
| 662 | + $active_periods[$period_count]["status"] = "expired"; | |
| 663 | + $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) ); | |
| 664 | + } | |
| 467 | 665 | } else { |
| 468 | 666 | $active_periods[$period_count]["start"] = $current; |
| 469 | 667 | $active_periods[$period_count]["end"] = $end_current; |
| 470 | 668 | } |
| 471 | - if ( $right_now_t < $current ) { | |
| 472 | - $active_periods[$period_count]["status"] = "upcoming"; | |
| 473 | - $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) ); | |
| 474 | - } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) { | |
| 475 | - $active_periods[$period_count]["status"] = "active"; | |
| 476 | - $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' ); | |
| 477 | - } else { | |
| 478 | - $active_periods[$period_count]["status"] = "expired"; | |
| 479 | - $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) ); | |
| 480 | - } | |
| 481 | - $period_count++; | |
| 669 | + if ( !($exception_period) ) | |
| 670 | + $period_count++; | |
| 482 | 671 | } |
| 483 | 672 | |
| 484 | - if ( ( $freq == 3 ) && ( $monthly_pattern == "yes" ) ) $current = $temp_current; | |
| 485 | 673 | } |
| 486 | 674 | date_default_timezone_set( $temp_tz ); |
| 675 | + remove_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4); | |
| 487 | 676 | return $active_periods; |
| 488 | 677 | } |
| 489 | 678 | |
| 490 | 679 | /** |
| @@ -519,9 +708,10 @@ | ||
| 519 | 708 | $args['instance_end'] = get_post_meta( $ID, $prefix . 'instance_end', true ); |
| 520 | 709 | $args['monthly_pattern'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true ); |
| 521 | 710 | $args['monthly_pattern_ord'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true ); |
| 522 | 711 | $args['monthly_pattern_day'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true ); |
| 523 | - | |
| 712 | + $args['exceptions_dates'] = get_post_meta( $ID, $prefix . 'exceptions_dates', true ); | |
| 713 | + | |
| 524 | 714 | return $this->__getRulePeriods( $args ); |
| 525 | 715 | |
| 526 | 716 | } |
| 527 | 717 | |
| @@ -546,9 +736,10 @@ | ||
| 546 | 736 | $args['instance_end'] = $_POST[$prefix . 'instance_end']; |
| 547 | 737 | $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month']; |
| 548 | 738 | $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth']; |
| 549 | 739 | $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday']; |
| 550 | - | |
| 740 | + $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() ); | |
| 741 | + | |
| 551 | 742 | $response = json_encode( $this->__getRulePeriods( $args ) ); |
| 552 | 743 | |
| 553 | 744 | // response output |
| 554 | 745 | header( "Content-Type: application/json" ); |
| @@ -564,9 +755,9 @@ | ||
| 564 | 755 | * @param $args Array of Timed Content Rule parameters |
| 565 | 756 | * @return string |
| 566 | 757 | */ |
| 567 | 758 | function __getScheduleDescription( $args ) { |
| 568 | - require("lib/Arrays_Definitions.php"); | |
| 759 | + include("lib/Arrays_Definitions.php"); | |
| 569 | 760 | |
| 570 | 761 | $interval_multiplier = 1; |
| 571 | 762 | $desc = ""; |
| 572 | 763 | |
| @@ -601,11 +792,12 @@ | ||
| 601 | 792 | $instance_end_time = $args['instance_end']['time']; |
| 602 | 793 | $monthly_pattern = $args['monthly_pattern']; |
| 603 | 794 | $monthly_pattern_ord = $args['monthly_pattern_ord']; |
| 604 | 795 | $monthly_pattern_day = $args['monthly_pattern_day']; |
| 796 | + $exceptions_dates = $args['exceptions_dates']; | |
| 797 | + | |
| 798 | + $desc = sprintf( _x( '%1$s on %2$s @ %3$s until %4$s @ %5$s.', 'Perform action (%1$s) from date/time of first active period (%2$s @ %3$s) until date/time of last active period (%4$s @ %5$s).', 'timed-content' ), $action, $instance_start_date, $instance_start_time, $instance_end_date, $instance_end_time ); | |
| 605 | 799 | |
| 606 | - $desc = sprintf( _x( '%1$s on %2$s @ %3$s until %4$s @ %5$s.', 'Dates/times of first active period', 'timed-content' ), $action, $instance_start_date, $instance_start_time, $instance_end_date, $instance_end_time ); | |
| 607 | - | |
| 608 | 800 | if ( $freq == 0 ) |
| 609 | 801 | $desc .= " " . sprintf( _n( 'Repeat this action every hour.', 'Repeat this action every %d hours.', $interval_multiplier, 'timed-content' ), $interval_multiplier ); |
| 610 | 802 | elseif ( $freq == 1 ) |
| 611 | 803 | $desc .= " " . sprintf( _n( 'Repeat this action every day.', 'Repeat this action every %d days.', $interval_multiplier, 'timed-content' ), $interval_multiplier ); |
| @@ -632,11 +824,11 @@ | ||
| 632 | 824 | |
| 633 | 825 | } elseif ( $freq == 3 ) { |
| 634 | 826 | if ( $monthly_pattern == "yes" ) { |
| 635 | 827 | if ( $interval_multiplier == 1 ) |
| 636 | - $desc .= " " . sprintf( __( 'Repeat this action every month on the %1$s %2$s of the month.', 'timed-content' ), $timed_content_rule_ordinal_array[$monthly_pattern_ord], $timed_content_rule_ordinal_days_array[$monthly_pattern_day] ); | |
| 828 | + $desc .= " " . sprintf( _x( 'Repeat this action every month on the %1$s %2$s of the month.', "Example: 'Repeat this action every month on the second Friday of the month.'", 'timed-content' ), $timed_content_rule_ordinal_array[$monthly_pattern_ord], $timed_content_rule_ordinal_days_array[$monthly_pattern_day] ); | |
| 637 | 829 | else |
| 638 | - $desc .= " " . sprintf( __( 'Repeat this action every %1$d months on the %2$s %3$s of the month.', 'timed-content' ), $interval_multiplier, $timed_content_rule_ordinal_array[$monthly_pattern_ord], $timed_content_rule_ordinal_days_array[$monthly_pattern_day] ); | |
| 830 | + $desc .= " " . sprintf( _x( 'Repeat this action every %1$d months on the %2$s %3$s of the month.', "Example: 'Repeat this action every 2 months on the second Friday of the month.'", 'timed-content' ), $interval_multiplier, $timed_content_rule_ordinal_array[$monthly_pattern_ord], $timed_content_rule_ordinal_days_array[$monthly_pattern_day] ); | |
| 639 | 831 | } else |
| 640 | 832 | $desc .= " " . sprintf( _n( 'Repeat this action every month.', 'Repeat this action every %d months.', $interval_multiplier, 'timed-content' ), $interval_multiplier ); |
| 641 | 833 | } elseif ( $freq == 4 ) |
| 642 | 834 | $desc .= " " . sprintf( _n( 'Repeat this action every year.', 'Repeat this action every %d years.', $interval_multiplier, 'timed-content' ), $interval_multiplier ); |
| @@ -644,9 +836,22 @@ | ||
| 644 | 836 | if ( $recurr_type == "recurrence_duration_num_repeat" ) |
| 645 | 837 | $desc .= " " . sprintf( _n( 'This rule will be active for 1 repetition.', 'This rule will be active for %d repetitions.', $num_repeat, 'timed-content' ), $num_repeat ); |
| 646 | 838 | elseif ( $recurr_type == "recurrence_duration_end_date" ) |
| 647 | 839 | $desc .= " " . sprintf( __( 'This rule will be active until %s.', 'timed-content' ), $end_date ); |
| 648 | - | |
| 840 | + | |
| 841 | + if ( ( $exceptions_dates ) && ( is_array( $exceptions_dates ) ) ) { | |
| 842 | + sort( $exceptions_dates, SORT_NUMERIC ); | |
| 843 | + $exceptions_dates = array_unique( $exceptions_dates ); | |
| 844 | + if ( $exceptions_dates[0] == 0 ) | |
| 845 | + array_shift( $exceptions_dates ); | |
| 846 | + if ( !empty( $exceptions_dates ) ) { | |
| 847 | + $formatted_dates = array(); | |
| 848 | + foreach ( $exceptions_dates as $a_date ) | |
| 849 | + $formatted_dates[] = date( _x( "F j, Y" , "Date format for schedule description", 'timed-content' ), $a_date ); | |
| 850 | + $desc .= " " . sprintf( __( 'This rule will be inactive on the following dates: %s.', 'timed-content' ), join( ", ", $formatted_dates ) ); | |
| 851 | + } | |
| 852 | + } | |
| 853 | + | |
| 649 | 854 | $desc .= " " . sprintf( __( 'All times are in the %s timezone.', 'timed-content' ), $timezone ); |
| 650 | 855 | return $desc; |
| 651 | 856 | } |
| 652 | 857 | |
| @@ -656,9 +861,12 @@ | ||
| 656 | 861 | * @param int $ID ID of the Timed Content Rule |
| 657 | 862 | * @return string |
| 658 | 863 | */ |
| 659 | 864 | function getScheduleDescriptionById( $ID ) { |
| 660 | - global $timed_content_rule_occurrence_custom_fields, $timed_content_rule_pattern_custom_fields, $timed_content_rule_recurrence_custom_fields; | |
| 865 | + global $timed_content_rule_occurrence_custom_fields, | |
| 866 | + $timed_content_rule_pattern_custom_fields, | |
| 867 | + $timed_content_rule_recurrence_custom_fields, | |
| 868 | + $timed_content_rule_exceptions_custom_fields; | |
| 661 | 869 | $defaults = array(); |
| 662 | 870 | |
| 663 | 871 | foreach ( $timed_content_rule_occurrence_custom_fields as $field ) { |
| 664 | 872 | $defaults[$field['name']] = $field['default']; |
| @@ -665,11 +873,14 @@ | ||
| 665 | 873 | } |
| 666 | 874 | foreach ( $timed_content_rule_pattern_custom_fields as $field ) { |
| 667 | 875 | $defaults[$field['name']] = $field['default']; |
| 668 | 876 | } |
| 669 | - foreach ( $timed_content_rule_recurrence_custom_fields as $field ) { | |
| 670 | - $defaults[$field['name']] = $field['default']; | |
| 671 | - } | |
| 877 | + foreach ( $timed_content_rule_recurrence_custom_fields as $field ) { | |
| 878 | + $defaults[$field['name']] = $field['default']; | |
| 879 | + } | |
| 880 | + foreach ( $timed_content_rule_exceptions_custom_fields as $field ) { | |
| 881 | + $defaults[$field['name']] = $field['default']; | |
| 882 | + } | |
| 672 | 883 | |
| 673 | 884 | $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX; |
| 674 | 885 | $args = array(); |
| 675 | 886 | |
| @@ -689,8 +900,9 @@ | ||
| 689 | 900 | $args['instance_end'] = ( false === get_post_meta( $ID, $prefix . 'instance_end', true ) ? $defaults['instance_end'] : get_post_meta( $ID, $prefix . 'instance_end', true ) ); |
| 690 | 901 | $args['monthly_pattern'] = ( false === get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true ) ? $defaults['monthly_nth_weekday_of_month'] : get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true ) ); |
| 691 | 902 | $args['monthly_pattern_ord'] = ( false === get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true ) ? $defaults['monthly_nth_weekday_of_month_nth'] : get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true ) ); |
| 692 | 903 | $args['monthly_pattern_day'] = ( false === get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true ) ? $defaults['monthly_nth_weekday_of_month_weekday'] : get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true ) ); |
| 904 | + $args['exceptions_dates'] = ( false === get_post_meta( $ID, $prefix . 'exceptions_dates', true ) ? $defaults['exceptions_dates'] : get_post_meta( $ID, $prefix . 'exceptions_dates', true ) ); | |
| 693 | 905 | |
| 694 | 906 | return $this->__getScheduleDescription( $args ); |
| 695 | 907 | |
| 696 | 908 | } |
| @@ -716,9 +928,10 @@ | ||
| 716 | 928 | $args['instance_end'] = $_POST[$prefix . 'instance_end']; |
| 717 | 929 | $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month']; |
| 718 | 930 | $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth']; |
| 719 | 931 | $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday']; |
| 720 | - | |
| 932 | + $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() ); | |
| 933 | + | |
| 721 | 934 | $response = $this->__getScheduleDescription( $args ); |
| 722 | 935 | |
| 723 | 936 | // response output |
| 724 | 937 | header( "Content-Type: text/plain" ); |
| @@ -752,10 +965,20 @@ | ||
| 752 | 965 | |
| 753 | 966 | $the_class = TIMED_CONTENT_CLIENT_TAG . $show_attr . $hide_attr ; |
| 754 | 967 | $the_tag = ( $display == "div" ? "div" : "span" ); |
| 755 | 968 | |
| 756 | - $the_HTML = "<" . $the_tag . " class='" . $the_class . "'" . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">" . do_shortcode( $content ) . "</" . $the_tag . ">"; | |
| 969 | + $the_filter = "timed_content_filter"; | |
| 970 | + $the_filter = apply_filters( "timed_content_filter_override", $the_filter ); | |
| 757 | 971 | |
| 972 | + $the_HTML = "<" | |
| 973 | + . $the_tag | |
| 974 | + . " class='" | |
| 975 | + . $the_class | |
| 976 | + . "'" | |
| 977 | + . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">" | |
| 978 | + . str_replace( ']]>', ']]>', apply_filters( $the_filter, $content ) ) | |
| 979 | + . "</" . $the_tag . ">"; | |
| 980 | + | |
| 758 | 981 | return $the_HTML; |
| 759 | 982 | } |
| 760 | 983 | |
| 761 | 984 | /** |
| @@ -767,14 +990,18 @@ | ||
| 767 | 990 | */ |
| 768 | 991 | function serverShowHTML( $atts, $content = null ) { |
| 769 | 992 | global $post; |
| 770 | 993 | extract( shortcode_atts( array( 'show' => TIMED_CONTENT_ZERO_TIME , 'hide' => TIMED_CONTENT_END_TIME, 'debug' => 'false' ), $atts ) ); |
| 771 | - $show_t = strtotime( $show ); | |
| 772 | - $hide_t = strtotime( $hide ); | |
| 773 | - $right_now_t = time(); | |
| 994 | + $show_t = strtotime( $this->__datetimeToEnglish( $show ) ); | |
| 995 | + $hide_t = strtotime( $this->__datetimeToEnglish( $hide ) ); | |
| 996 | + $right_now_t = current_time( 'timestamp', 1 ); | |
| 774 | 997 | $debug_message = ""; |
| 775 | 998 | |
| 999 | + $the_filter = "timed_content_filter"; | |
| 1000 | + $the_filter = apply_filters( "timed_content_filter_override", $the_filter ); | |
| 1001 | + | |
| 776 | 1002 | if ( ( $debug == "true" ) && ( current_user_can( "edit_post", $post->post_id ) ) ) { |
| 1003 | + add_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4); | |
| 777 | 1004 | $temp_tz = date_default_timezone_get(); |
| 778 | 1005 | date_default_timezone_set( get_option( 'timezone_string' ) ); |
| 779 | 1006 | |
| 780 | 1007 | $right_now = date_i18n( TIMED_CONTENT_DT_FORMAT, $right_now_t ); |
| @@ -789,37 +1016,43 @@ | ||
| 789 | 1016 | $hide_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) ); |
| 790 | 1017 | |
| 791 | 1018 | $debug_message = "<div class=\"tcr-warning\">\n"; |
| 792 | 1019 | $debug_message .= "<p class=\"heading\">" . _x( "Notice", "Noun", 'timed-content' ) . "</p>\n"; |
| 793 | - $debug_message .= "<p>" . __( "Debugging has been turned on for a <code>[timed-content-server]</code> shortcode on this Post/Page. Only website users who are currently logged in and can edit this Post/Page will see this. To turn off this message, remove the <code>debug</code> attribute from the shortcode.", 'timed-content' ) . "</p>\n"; | |
| 1020 | + $debug_message .= "<p>" . sprintf( __( 'Debugging has been turned on for a %1$s shortcode on this Post/Page. Only website users who are currently logged in and can edit this Post/Page will see this. To turn off this message, remove the %2$s attribute from the shortcode.', 'timed-content' ), "<code>[timed-content-server]</code>" , "<code>debug</code>" ) . "</p>\n"; | |
| 794 | 1021 | |
| 795 | 1022 | if ( $show == TIMED_CONTENT_ZERO_TIME ) |
| 796 | - $debug_message .= "<p>" . __( 'The <code>show</code> attribute is not set.', 'timed-content') . "</p>\n"; | |
| 1023 | + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ), "<code>show</code>" ) . "</p>\n"; | |
| 797 | 1024 | else |
| 798 | - $debug_message .= "<p>" . __( 'The <code>show</code> attribute is currently set to', 'timed-content') . ": " . $show . ",<br />\n " | |
| 1025 | + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>show</code>" ) . ": " . $show . ",<br />\n " | |
| 799 | 1026 | . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $show_t ) |
| 800 | 1027 | . " (" . $show_diff_str . ")</p>\n"; |
| 801 | 1028 | |
| 802 | 1029 | if ( $hide == TIMED_CONTENT_END_TIME ) |
| 803 | - $debug_message .= "<p>" . __( 'The <code>hide</code> attribute is not set.' , 'timed-content') . "</p>\n"; | |
| 1030 | + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.' , 'timed-content' ), "<code>hide</code>" ) . "</p>\n"; | |
| 804 | 1031 | else |
| 805 | - $debug_message .= "<p>" . __( 'The <code>hide</code> attribute is currently set to', 'timed-content') . ": " . $hide . ",<br />\n" | |
| 1032 | + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>hide</code>" ) . ": " . $hide . ",<br />\n" | |
| 806 | 1033 | . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $hide_t ) |
| 807 | 1034 | . " (" . $hide_diff_str . ").</p>\n"; |
| 808 | 1035 | |
| 809 | - $debug_message .= "<p>" . __( 'Current time', 'timed-content') . " : " . $right_now . "</p>\n"; | |
| 810 | - $debug_message .= "<p>" . __( 'Content', "Noun", 'timed-content') . " : " . $content . "</p>\n"; | |
| 1036 | + $debug_message .= "<p>" . __( 'Current Date/Time:', 'timed-content') . " " . $right_now . "<br />\n"; | |
| 1037 | + $debug_message .= __( 'Content Filter:', 'timed-content') . " " . $the_filter . "</p>\n"; | |
| 1038 | + $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content') . " " . $content . "</p>\n"; | |
| 811 | 1039 | |
| 812 | 1040 | $debug_message .= "</div>\n"; |
| 813 | 1041 | |
| 814 | 1042 | date_default_timezone_set( $temp_tz ); |
| 1043 | + remove_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4); | |
| 815 | 1044 | } |
| 816 | - | |
| 817 | - if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) ) | |
| 818 | - return $debug_message . do_shortcode( $content ) . "\n"; | |
| 819 | - else | |
| 820 | - return $debug_message . "\n"; | |
| 821 | 1045 | |
| 1046 | + | |
| 1047 | + if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) ) { | |
| 1048 | + do_action("timed_content_server_show", $post->ID, $show, $hide, $content); | |
| 1049 | + return $debug_message . str_replace(']]>', ']]>', apply_filters($the_filter, $content)) . "\n"; | |
| 1050 | + } else { | |
| 1051 | + do_action("timed_content_server_hide", $post->ID, $show, $hide, $content); | |
| 1052 | + return $debug_message . "\n"; | |
| 1053 | + } | |
| 1054 | + | |
| 822 | 1055 | } |
| 823 | 1056 | |
| 824 | 1057 | /** |
| 825 | 1058 | * Processes the [timed-content-rule] shortcode. |
| @@ -828,13 +1061,19 @@ | ||
| 828 | 1061 | * @param null $content |
| 829 | 1062 | * @return string |
| 830 | 1063 | */ |
| 831 | 1064 | function rulesShowHTML( $atts, $content = null ) { |
| 832 | - extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); | |
| 1065 | + global $post; | |
| 1066 | + extract( shortcode_atts( array( 'id' => 0 ), $atts ) ); | |
| 1067 | + if ( !is_numeric( $id ) ) { | |
| 1068 | + $page = get_page_by_title( $id, OBJECT, TIMED_CONTENT_RULE_TYPE ); | |
| 1069 | + if ( $page == null ) return; | |
| 1070 | + $id = $page->ID; | |
| 1071 | + } | |
| 833 | 1072 | if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $id ) ) return; |
| 834 | 1073 | |
| 835 | 1074 | $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX; |
| 836 | - $right_now_t = time(); | |
| 1075 | + $right_now_t = current_time( 'timestamp', 1 ); | |
| 837 | 1076 | $rule_is_active = false; |
| 838 | 1077 | |
| 839 | 1078 | $active_periods = $this->getRulePeriodsById( $id, false ); |
| 840 | 1079 | $action_is_show = (bool) get_post_meta( $id, $prefix . 'action', true ); |
| @@ -844,13 +1083,19 @@ | ||
| 844 | 1083 | $rule_is_active = true; |
| 845 | 1084 | break; |
| 846 | 1085 | } |
| 847 | 1086 | } |
| 848 | - | |
| 849 | - if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) ) | |
| 850 | - return do_shortcode( $content ); | |
| 851 | - else | |
| 852 | - return ""; | |
| 1087 | + | |
| 1088 | + $the_filter = "timed_content_filter"; | |
| 1089 | + $the_filter = apply_filters( "timed_content_filter_override", $the_filter ); | |
| 1090 | + | |
| 1091 | + if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) ) { | |
| 1092 | + do_action("timed_content_rule_show", $post->ID, $id, $content); | |
| 1093 | + return str_replace(']]>', ']]>', apply_filters($the_filter, $content)); | |
| 1094 | + } else { | |
| 1095 | + do_action("timed_content_rule_hide", $post->ID, $id, $content); | |
| 1096 | + return ""; | |
| 1097 | + } | |
| 853 | 1098 | } |
| 854 | 1099 | |
| 855 | 1100 | /** |
| 856 | 1101 | * Enqueues the JavaScript code necessary for the functionality of the [timed-content-client] shortcode. |
| @@ -879,30 +1124,35 @@ | ||
| 879 | 1124 | <?php |
| 880 | 1125 | } |
| 881 | 1126 | |
| 882 | 1127 | /** |
| 883 | - * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens. Echo'd to output. | |
| 1128 | + * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens | |
| 1129 | + * and the TinyMCE editor. Echo'd to output. | |
| 884 | 1130 | */ |
| 885 | 1131 | function addPostTypeIcons() { |
| 886 | - wp_enqueue_style( 'timed-content-css-dashicons', TIMED_CONTENT_CSS_DASHICONS, false, TIMED_CONTENT_VERSION ); | |
| 1132 | + wp_enqueue_style( 'ca-aliencyborg-dashicons', TIMED_CONTENT_CSS_DASHICONS, false, TIMED_CONTENT_VERSION ); | |
| 887 | 1133 | ?> |
| 888 | 1134 | <style type="text/css" media="screen"> |
| 889 | 1135 | #adminmenu #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.menu-icon-post div.wp-menu-image:before { |
| 890 | - font-family: 'timed-content-icons' !important; | |
| 891 | - content: '\e600'; | |
| 1136 | + font-family: 'ca-aliencyborg-dashicons' !important; | |
| 1137 | + content: '\e601'; | |
| 892 | 1138 | } |
| 893 | 1139 | #dashboard_right_now li.<?php echo TIMED_CONTENT_RULE_TYPE; ?>-count a:before { |
| 894 | - font-family: 'timed-content-icons' !important; | |
| 895 | - content: '\e600'; | |
| 1140 | + font-family: 'ca-aliencyborg-dashicons' !important; | |
| 1141 | + content: '\e601'; | |
| 896 | 1142 | } |
| 897 | - span.mce_timed_content:before { | |
| 898 | - font-family: 'timed-content-icons' !important; | |
| 899 | - content: '\e600'; | |
| 1143 | + .mce-i-timed_content:before { | |
| 1144 | + font: 400 24px/1 'ca-aliencyborg-dashicons' !important; | |
| 1145 | + padding: 0; | |
| 1146 | + vertical-align: top; | |
| 1147 | + margin-left: -2px; | |
| 1148 | + padding-right: 2px; | |
| 1149 | + content: '\e601'; | |
| 900 | 1150 | } |
| 901 | 1151 | </style> |
| 902 | 1152 | <?php |
| 903 | 1153 | } |
| 904 | - | |
| 1154 | + | |
| 905 | 1155 | /** |
| 906 | 1156 | * Enqueues the JavaScript code necessary for the functionality of the Timed Content Rules management screens. |
| 907 | 1157 | */ |
| 908 | 1158 | function addAdminHeaderCode() { |
| @@ -908,25 +1158,30 @@ | ||
| 908 | 1158 | function addAdminHeaderCode() { |
| 909 | 1159 | if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == TIMED_CONTENT_RULE_TYPE ) |
| 910 | 1160 | || ( isset( $post_type ) && $post_type == TIMED_CONTENT_RULE_TYPE ) |
| 911 | 1161 | || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == TIMED_CONTENT_RULE_TYPE ) ) { |
| 912 | - wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION ); | |
| 1162 | + wp_enqueue_style( 'thickbox' ); | |
| 1163 | + wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION ); | |
| 913 | 1164 | // Enqueue the JavaScript file that manages the meta box UI |
| 914 | 1165 | wp_enqueue_script( 'timed-content-admin_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin.js', array( 'jquery' ), TIMED_CONTENT_VERSION ); |
| 915 | 1166 | // Enqueue the JavaScript file that makes AJAX requests |
| 916 | - wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'jquery-ui-dialog' ), TIMED_CONTENT_VERSION ); | |
| 1167 | + wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'thickbox' ), TIMED_CONTENT_VERSION ); | |
| 917 | 1168 | |
| 1169 | + // Set up local variables used in the Admin JavaScript file | |
| 1170 | + wp_localize_script( 'timed-content-admin_js', 'timedContentRuleAdmin', array( | |
| 1171 | + 'no_exceptions_label' => __( "- No exceptions set -", 'timed-content' ) ) ); | |
| 1172 | + | |
| 918 | 1173 | // Set up local variables used in the AJAX JavaScript file |
| 919 | 1174 | wp_localize_script( 'timed-content-ajax_js', 'timedContentRuleAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 920 | 1175 | 'start_label' => _x( 'Start', 'Scheduled Dates/Times dialog - Beginning of active period table header', 'timed-content' ), |
| 921 | 1176 | 'end_label' => _x( 'End', 'Scheduled Dates/Times dialog - End of active period table header', 'timed-content' ), |
| 922 | - 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ), | |
| 923 | - 'dialog_width' => 800, | |
| 924 | - 'dialog_height' => 500, | |
| 925 | - 'close_label' => _x( 'Close', 'Scheduled Dates/Times dialog - Close button HTML label', 'timed-content' ), | |
| 926 | - 'loadingimg' => TIMED_CONTENT_PLUGIN_URL . '/img/wpspin.gif', | |
| 927 | - 'error' => __( "Error", 'timed-content' ), | |
| 928 | - 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) ); | |
| 1177 | + 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ), | |
| 1178 | + 'button_loading_label' => __( 'Calculating Dates/Times', 'timed-content' ), | |
| 1179 | + 'button_finished_label' => __( 'Show Projected Dates/Times', 'timed-content' ), | |
| 1180 | + 'dialog_width' => 800, | |
| 1181 | + 'dialog_height' => 500, | |
| 1182 | + 'error' => __( "Error", 'timed-content' ), | |
| 1183 | + 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) ); | |
| 929 | 1184 | } |
| 930 | 1185 | } |
| 931 | 1186 | |
| 932 | 1187 | /** |
| @@ -943,9 +1198,9 @@ | ||
| 943 | 1198 | } |
| 944 | 1199 | } |
| 945 | 1200 | |
| 946 | 1201 | /** |
| 947 | - * Sets up variables to use in the TinyMCE plugin's editor_plugin_src.js. | |
| 1202 | + * Sets up variables to use in the TinyMCE plugin's plugin.js. | |
| 948 | 1203 | * |
| 949 | 1204 | */ |
| 950 | 1205 | function setTinyMCEPluginVars() { |
| 951 | 1206 | global $wp_version; |
| @@ -953,18 +1208,17 @@ | ||
| 953 | 1208 | return; |
| 954 | 1209 | |
| 955 | 1210 | // Add only in Rich Editor mode |
| 956 | 1211 | if ( get_user_option( 'rich_editing' ) == 'true' ) { |
| 957 | - if ( version_compare( $wp_version, "3.8", ">=" ) ) | |
| 1212 | + if ( version_compare( $wp_version, "3.8", "<" ) ) | |
| 958 | 1213 | $image = "/clock.gif"; |
| 959 | 1214 | else |
| 960 | 1215 | $image = ""; |
| 961 | - wp_enqueue_script( 'timed-content-admin_tinymce_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin-tinymce.js', array(), TIMED_CONTENT_VERSION ); | |
| 962 | - wp_localize_script( 'timed-content-admin_tinymce_js', | |
| 963 | - 'timedContentAdminTinyMCEOptionsVars', | |
| 964 | - array( 'version' => TIMED_CONTENT_VERSION, | |
| 965 | - 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ), | |
| 966 | - 'image' => $image ) ); | |
| 1216 | + wp_localize_script( 'editor', | |
| 1217 | + 'timedContentAdminTinyMCEOptions', | |
| 1218 | + array( 'version' => TIMED_CONTENT_VERSION, | |
| 1219 | + 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ), | |
| 1220 | + 'image' => $image ) ); | |
| 967 | 1221 | } |
| 968 | 1222 | } |
| 969 | 1223 | |
| 970 | 1224 | /** |
| @@ -983,9 +1237,9 @@ | ||
| 983 | 1237 | * @param array $plugin_array Array of plugins already registered with TinyMCE |
| 984 | 1238 | * @return array The array of TinyMCE plugins with ours now loaded in as well |
| 985 | 1239 | */ |
| 986 | 1240 | function addTimedContentTinyMCEPlugin( $plugin_array ) { |
| 987 | - $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/editor_plugin.js"; | |
| 1241 | + $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/plugin.js"; | |
| 988 | 1242 | return $plugin_array; |
| 989 | 1243 | } |
| 990 | 1244 | |
| 991 | 1245 | /** |
| @@ -1001,10 +1255,13 @@ | ||
| 1001 | 1255 | foreach ( $the_rules as $rule ) { |
| 1002 | 1256 | $desc = $this->getScheduleDescriptionById( $rule->ID ); |
| 1003 | 1257 | // Only add a rule if there's no errors or warnings |
| 1004 | 1258 | if ( false === strpos( $desc, "tcr-warning" ) ) |
| 1005 | - $the_js .= " { 'ID': " . $rule->ID . ", 'title': '" . esc_js( $rule->post_title ) . "', 'desc': '" . esc_js( $desc ) . "' },\n"; | |
| 1259 | + $the_js .= " { 'ID': " . $rule->ID . ", 'title': '" . esc_js( ( ( strlen( $rule->post_title ) > 0 ) ? $rule->post_title : _x( "(no title)", "No Timed Content Rule title", "timed-content" ) ) ) . "', 'desc': '" . esc_js( $desc ) . "' },\n"; | |
| 1006 | 1260 | } |
| 1261 | + if ( empty( $the_rules ) ) | |
| 1262 | + $the_js .= " { 'ID': -999, 'title': ' ---- ', 'desc': '" . __( 'No Timed Content Rules found', 'timed-content' ) . "' }\n"; | |
| 1263 | + | |
| 1007 | 1264 | $the_js .= "];\n"; |
| 1008 | 1265 | return $the_js; |
| 1009 | 1266 | } |
| 1010 | 1267 | /** |
| @@ -1011,17 +1268,25 @@ | ||
| 1011 | 1268 | * Display a dialog box for this plugin's associated TinyMCE plugin. Called from TinyMCE via AJAX. |
| 1012 | 1269 | * |
| 1013 | 1270 | */ |
| 1014 | 1271 | function timedContentPluginGetTinyMCEDialog() { |
| 1015 | - wp_enqueue_style( 'timed-content-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS, false, TIMED_CONTENT_VERSION ); | |
| 1016 | - wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 1017 | - wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS, array( TIMED_CONTENT_JQUERY_UI_CSS ), TIMED_CONTENT_VERSION ); | |
| 1018 | - wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' ); | |
| 1019 | - wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array( 'jquery', 'jquery-ui-datepicker' ), TIMED_CONTENT_VERSION ); | |
| 1020 | - wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' ); | |
| 1272 | + include("lib/jquery-ui-datetime-i18n.php"); | |
| 1021 | 1273 | |
| 1274 | + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS); | |
| 1275 | + wp_enqueue_script('jquery-ui-datepicker'); | |
| 1276 | + wp_register_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS); | |
| 1277 | + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css'); | |
| 1278 | + wp_register_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION); | |
| 1279 | + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js'); | |
| 1280 | + if (!(wp_script_is(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'registered'))) { | |
| 1281 | + wp_register_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', TIMED_CONTENT_PLUGIN_URL . "/js/content-protector-datetime-i18n.js", array('jquery', 'jquery-ui-datepicker', TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js'), TIMED_CONTENT_VERSION); | |
| 1282 | + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js'); | |
| 1283 | + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQDatepickerI18n', $jquery_ui_datetime_datepicker_i18n); | |
| 1284 | + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQTimepickerI18n', $jquery_ui_datetime_timepicker_i18n); | |
| 1285 | + } | |
| 1286 | + | |
| 1022 | 1287 | ob_start(); |
| 1023 | - include("tinymce_plugin/dialog.php"); | |
| 1288 | + include( "tinymce_plugin/dialog.php" ); | |
| 1024 | 1289 | $content = ob_get_contents(); |
| 1025 | 1290 | ob_end_clean(); |
| 1026 | 1291 | echo $content; |
| 1027 | 1292 | die(); |
| @@ -1027,14 +1292,14 @@ | ||
| 1027 | 1292 | die(); |
| 1028 | 1293 | } |
| 1029 | 1294 | |
| 1030 | 1295 | /** |
| 1031 | - * Displays a count of Timed Content Rules of the Dashboard's Right now widget | |
| 1296 | + * Adds support for i18n (internationalization) | |
| 1032 | 1297 | * |
| 1033 | 1298 | */ |
| 1034 | 1299 | function i18nInit() { |
| 1035 | 1300 | $plugin_dir = basename( dirname( __FILE__ ) ) . "/lang/"; |
| 1036 | - load_plugin_textdomain( 'timed-content', null, $plugin_dir ); | |
| 1301 | + load_plugin_textdomain( 'timed-content', false, $plugin_dir ); | |
| 1037 | 1302 | } |
| 1038 | 1303 | |
| 1039 | 1304 | /** |
| 1040 | 1305 | * Add custom columns to the Timed Content Rules overview page |
| @@ -1075,9 +1340,9 @@ | ||
| 1075 | 1340 | } |
| 1076 | 1341 | |
| 1077 | 1342 | $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE ); |
| 1078 | 1343 | $num = number_format_i18n( $num_posts->publish ); |
| 1079 | - $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ) ); | |
| 1344 | + $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' ); | |
| 1080 | 1345 | if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
| 1081 | 1346 | $num = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>"; |
| 1082 | 1347 | $text = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>"; |
| 1083 | 1348 | } |
| @@ -1087,9 +1352,9 @@ | ||
| 1087 | 1352 | echo '</tr>'; |
| 1088 | 1353 | |
| 1089 | 1354 | if ( $num_posts->pending > 0 ) { |
| 1090 | 1355 | $num = number_format_i18n( $num_posts->pending ); |
| 1091 | - $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ) ); | |
| 1356 | + $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' ); | |
| 1092 | 1357 | if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
| 1093 | 1358 | $num = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>"; |
| 1094 | 1359 | $text = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>"; |
| 1095 | 1360 | } |
| @@ -1110,9 +1375,9 @@ | ||
| 1110 | 1375 | } |
| 1111 | 1376 | |
| 1112 | 1377 | $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE ); |
| 1113 | 1378 | $num = number_format_i18n( $num_posts->publish ); |
| 1114 | - $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ) ); | |
| 1379 | + $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' ); | |
| 1115 | 1380 | if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) |
| 1116 | 1381 | echo "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" |
| 1117 | 1382 | . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">' |
| 1118 | 1383 | . $num |
| @@ -1121,9 +1386,9 @@ | ||
| 1121 | 1386 | . '</a></li>'; |
| 1122 | 1387 | |
| 1123 | 1388 | if ( $num_posts->pending > 0 ) { |
| 1124 | 1389 | $num = number_format_i18n( $num_posts->pending ); |
| 1125 | - $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ) ); | |
| 1390 | + $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' ); | |
| 1126 | 1391 | if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) |
| 1127 | 1392 | echo "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" |
| 1128 | 1393 | . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">' |
| 1129 | 1394 | . $num |
| @@ -1131,8 +1396,54 @@ | ||
| 1131 | 1396 | . $text |
| 1132 | 1397 | . '</a></li>'; |
| 1133 | 1398 | } |
| 1134 | 1399 | } |
| 1400 | + | |
| 1401 | + function setUpCustomFields() { | |
| 1402 | + require_once( "lib/customFields-settings.php" ); | |
| 1403 | + require_once( "lib/customFieldsInterface.php" ); | |
| 1404 | + | |
| 1405 | + $scf = new customFieldsInterface( "timed_content_rule_schedule", | |
| 1406 | + __( 'Rule Description/Schedule', 'timed-content' ), | |
| 1407 | + "<div id=\"schedule_desc\" style=\"font-style: italic;\">" | |
| 1408 | + . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $this->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $this->getScheduleDescriptionById( intval( 0 ) ) ) | |
| 1409 | + . "</div>" | |
| 1410 | + . "<div id=\"tcr-dialogHolder\" style=\"display:none;\"></div>" | |
| 1411 | + . "<div style=\"padding-top: 10px;\"><input type=\"button\" class=\"button button-primary\" id=\"timed_content_rule_test\" value=\"" . __( 'Show Projected Dates/Times', 'timed-content' ) . "\" /></div>", | |
| 1412 | + TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1413 | + array( TIMED_CONTENT_RULE_TYPE ), | |
| 1414 | + array() ); | |
| 1415 | + $ocf = new customFieldsInterface( "timed_content_rule_initial_event", | |
| 1416 | + __( 'Action/Initial Event', 'timed-content' ), | |
| 1417 | + __( 'Set the action to be taken and when it should first run.', 'timed-content' ), | |
| 1418 | + TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1419 | + array( TIMED_CONTENT_RULE_TYPE ), | |
| 1420 | + $timed_content_rule_occurrence_custom_fields ); | |
| 1421 | + $pcf = new customFieldsInterface( "timed_content_rule_recurrence", | |
| 1422 | + __( 'Repeating Pattern', 'timed-content' ), | |
| 1423 | + __( 'Set how often the action should repeat.', 'timed-content' ), | |
| 1424 | + TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1425 | + array( TIMED_CONTENT_RULE_TYPE ), | |
| 1426 | + $timed_content_rule_pattern_custom_fields ); | |
| 1427 | + $rcf = new customFieldsInterface( "timed_content_rule_stop_condition", | |
| 1428 | + __( 'Stopping Condition', 'timed-content' ), | |
| 1429 | + __( 'Set how long or how many times the action should occur.', 'timed-content' ), | |
| 1430 | + TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1431 | + array( TIMED_CONTENT_RULE_TYPE ), | |
| 1432 | + $timed_content_rule_recurrence_custom_fields ); | |
| 1433 | + $ecf = new customFieldsInterface( "timed_content_rule_exceptions", | |
| 1434 | + __( 'Exceptions', 'timed-content' ), | |
| 1435 | + __( 'Set up any exceptions to this Timed Content Rule.', 'timed-content' ), | |
| 1436 | + TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1437 | + array( TIMED_CONTENT_RULE_TYPE ), | |
| 1438 | + $timed_content_rule_exceptions_custom_fields ); | |
| 1439 | + | |
| 1440 | + // Initially loaded at the top; defining this constant here means it can get i18n'd | |
| 1441 | + /* translators: date/time format for debugging messages. http://ca2.php.net/manual/en/function.date.php */ | |
| 1442 | + define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i A T" , 'timed-content' ) ); | |
| 1443 | + | |
| 1444 | + } | |
| 1445 | + | |
| 1135 | 1446 | } |
| 1136 | 1447 | |
| 1137 | 1448 | } //End Class timedContentPlugin |
| 1138 | 1449 | |
| @@ -1142,37 +1453,20 @@ | ||
| 1142 | 1453 | } |
| 1143 | 1454 | |
| 1144 | 1455 | // Actions and Filters |
| 1145 | 1456 | if ( isset( $timedContentPluginInstance ) ) { |
| 1146 | - $scf = new customFieldsInterface( "cfi_s", | |
| 1147 | - __( 'Rule Description/Schedule', 'timed-content' ), | |
| 1148 | - "<div id=\"schedule_desc\" style=\"font-style: italic;\">" | |
| 1149 | - . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $timedContentPluginInstance->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $timedContentPluginInstance->getScheduleDescriptionById( intval( 0 ) ) ) | |
| 1150 | - . "</div>" | |
| 1151 | - . "<div style=\"padding-top: 10px;\"><input type=\"button\" class=\"button-primary\" id=\"timed_content_rule_test\" value=\"Show Projected Dates/Times\" /></div>", | |
| 1152 | - TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1153 | - array( TIMED_CONTENT_RULE_TYPE ), | |
| 1154 | - array() ); | |
| 1155 | - $ocf = new customFieldsInterface( "cfi_o", | |
| 1156 | - __( 'Action/Initial Event', 'timed-content' ), | |
| 1157 | - __( 'Set the action to be taken and when it should first run.', 'timed-content' ), | |
| 1158 | - TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1159 | - array( TIMED_CONTENT_RULE_TYPE ), | |
| 1160 | - $timed_content_rule_occurrence_custom_fields ); | |
| 1161 | - $pcf = new customFieldsInterface( "cfi_p", | |
| 1162 | - __( 'Repeating Pattern', 'timed-content' ), | |
| 1163 | - __( 'Set how often the action should repeat.', 'timed-content' ), | |
| 1164 | - TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1165 | - array( TIMED_CONTENT_RULE_TYPE ), | |
| 1166 | - $timed_content_rule_pattern_custom_fields ); | |
| 1167 | - $rcf = new customFieldsInterface( "cfi_r", | |
| 1168 | - __( 'Stopping Condition', 'timed-content' ), | |
| 1169 | - __( 'Set how long or how many times the action should occur.', 'timed-content' ), | |
| 1170 | - TIMED_CONTENT_RULE_POSTMETA_PREFIX, | |
| 1171 | - array( TIMED_CONTENT_RULE_TYPE ), | |
| 1172 | - $timed_content_rule_recurrence_custom_fields ); | |
| 1173 | - add_action( "init", array( &$timedContentPluginInstance, "i18nInit" ), 1 ); | |
| 1457 | + global $wp_version; | |
| 1458 | + | |
| 1459 | + add_filter('timed_content_filter', 'wptexturize'); | |
| 1460 | + add_filter('timed_content_filter', 'convert_smilies'); | |
| 1461 | + add_filter('timed_content_filter', 'convert_chars'); | |
| 1462 | + add_filter('timed_content_filter', 'wpautop'); | |
| 1463 | + add_filter('timed_content_filter', 'prepend_attachment'); | |
| 1464 | + add_filter('timed_content_filter', 'do_shortcode'); | |
| 1465 | + | |
| 1466 | + add_action( "plugins_loaded", array( &$timedContentPluginInstance, "i18nInit" ), 1 ); | |
| 1174 | 1467 | add_action( "init", array( &$timedContentPluginInstance, "timedContentRuleTypeInit" ), 2 ); |
| 1468 | + add_action( "init", array( &$timedContentPluginInstance, "setUpCustomFields" ), 2 ); | |
| 1175 | 1469 | add_action( "wp_head", array( &$timedContentPluginInstance, "addHeaderCode" ), 1 ); |
| 1176 | 1470 | add_filter( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_columns", array( &$timedContentPluginInstance, "addDescColumnHead" ) ); |
| 1177 | 1471 | add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2); |
| 1178 | 1472 | add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 ); |
| @@ -1177,9 +1471,8 @@ | ||
| 1177 | 1471 | add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2); |
| 1178 | 1472 | add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 ); |
| 1179 | 1473 | add_action( "admin_init", array( &$timedContentPluginInstance, "setTinyMCEPluginVars" ), 1 ); |
| 1180 | 1474 | add_action( "admin_init", array( &$timedContentPluginInstance, "initTinyMCEPlugin" ), 2 ); |
| 1181 | - add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons" ), 1 ); | |
| 1182 | 1475 | add_action( 'wp_ajax_timedContentPluginGetTinyMCEDialog', array( &$timedContentPluginInstance, "timedContentPluginGetTinyMCEDialog" ), 1 ); |
| 1183 | 1476 | add_action( 'wp_ajax_timedContentPluginGetRulePeriodsAjax', array( &$timedContentPluginInstance, "timedContentPluginGetRulePeriodsAjax" ), 1 ); |
| 1184 | 1477 | add_action( 'wp_ajax_timedContentPluginGetScheduleDescriptionAjax', array( &$timedContentPluginInstance, "timedContentPluginGetScheduleDescriptionAjax" ), 1 ); |
| 1185 | 1478 | add_filter( "post_updated_messages", array( &$timedContentPluginInstance, "timedContentRuleUpdatedMessages" ), 1 ); |