PluginProbe
Timed Content / 2.9
Timed Content v2.9
2.99 trunk 1.0 1.1 1.2 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.10 2.11 2.12 2.15 2.2 2.3 2.3.1 2.4 2.5 2.5.1 2.50 2.51 2.52 All 67 releases
← All changes | timed-content.php +601 -196 2.12.9 View file →
@@ -1,33 +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
8 +Author: K. Tough, Arno Welzel
9 +Version: 2.9
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 );
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.9" );
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 - // Required for styling the JQuery UI Datepicker and JQuery UI Timepicker
25 - define( "TIMED_CONTENT_JQUERY_UI_CSS", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" );
26 - define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS", TIMED_CONTENT_PLUGIN_URL."/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.js" );
27 - define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS", TIMED_CONTENT_PLUGIN_URL."/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.css" );
28 - require_once( "lib/customFields-settings.php" );
29 - require_once( "lib/customFieldsInterface.php" );
24 + define( "TIMED_CONTENT_CSS", TIMED_CONTENT_PLUGIN_URL . "/css/timed-content.css" );
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 + 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 30
31 31
32 32 /**
33 33 * Class timedContentPlugin
@@ -36,14 +36,161 @@
36 36 * the possibility of name collisions with other plugins.
37 37 */
38 38 class timedContentPlugin {
39 39
40 + function __construct() {
41 + //constructor
42 +
43 + }
44 +
40 45 function timedContentPlugin() {
41 - //constructor
46 + self::__construct();
42 47
43 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;
44 67
45 - /**
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 + // use debug parameter if current user is allowed to edit the post
77 + if(isset($_GET['tctest']) && current_user_can( "edit_post", $post->post_id)) {
78 + $dt = DateTime::createFromFormat('Y-m-d H:i:s', $_GET['tctest']);
79 + if($dt != FALSE) $timestamp = $dt->getTimestamp();
80 + }
81 + }
82 +
83 + // get components of the date (timestamp) as array
84 + $date_components = getdate($timestamp);
85 +
86 + // numeric representation of a month, with leading zeros
87 + $date_month = $wp_locale->get_month($date_components['mon']);
88 + $date_month_abbrev = $wp_locale->get_month_abbrev($date_month);
89 + // numeric representation of the day of the week
90 + $date_weekday = $wp_locale->get_weekday($date_components['wday']);
91 + $date_weekday_abbrev = $wp_locale->get_weekday_abbrev($date_weekday);
92 + // get if hour is Ante meridiem or Post meridiem
93 + $meridiem = $date_components['hours'] >= 12 ? 'pm' : 'am';
94 + // lowercase Ante meridiem and Post meridiem hours
95 + $date_meridiem = $wp_locale->get_meridiem($meridiem);
96 + // uppercase Ante meridiem and Post meridiem
97 + $date_meridiem_capital = $wp_locale->get_meridiem(strtoupper($meridiem));
98 +
99 + // escape literals
100 + $date_weekday_abbrev = backslashit($date_weekday_abbrev);
101 + $date_month = backslashit($date_month);
102 + $date_weekday = backslashit($date_weekday);
103 + $date_month_abbrev = backslashit($date_month_abbrev);
104 + $date_meridiem = backslashit($date_meridiem);
105 + $date_meridiem_capital = backslashit($date_meridiem_capital);
106 +
107 + // the translated format string
108 + $translated_date_format_string = '';
109 + // the 2 arrays map a format literal to its translation (e. g. 'F' to the escaped month translation)
110 + $translate_formats = array('D', 'F', 'l', 'M', 'a', 'A', 'c', 'r');
111 + $translations = array(
112 + $date_weekday_abbrev, // D
113 + $date_month, // F
114 + $date_weekday, // l
115 + $date_month_abbrev, // M
116 + $date_meridiem, // a
117 + $date_meridiem_capital, // A
118 + 'Y-m-d\TH:i:sP', // c
119 + sprintf('%s, d %s Y H:i:s O', $date_weekday_abbrev, $date_month_abbrev), // r
120 + );
121 +
122 + // find each format literal that needs translation and replace it by its translation
123 + // respects the escaping
124 + // iterate $req_format from ending to beginning
125 + for ($i = strlen($req_format) - 1; $i > -1; $i--)
126 + {
127 + // test if current char is format literal that needs translation
128 + $translate_formats_index = array_search($req_format[$i], $translate_formats);
129 +
130 + if ($translate_formats_index !== false)
131 + {
132 + // counts the slashes (the escape char) in front of the current char
133 + $slashes_counter = 0;
134 +
135 + // count all slashes left-hand side of the current char
136 + for ($j = $i - 1; $j > -1; $j--)
137 + {
138 + if ($req_format[$j] == '\\')
139 + $slashes_counter++;
140 + else
141 + break;
142 + }
143 +
144 + // number of slashes is even
145 + if ($slashes_counter % 2 == 0)
146 + // current char is not escaped, therefore it is a format literal
147 + $translated_date_format_string = $translations[$translate_formats_index] . $translated_date_format_string;
148 + else
149 + // current char is escaped, therefore it is not a format literal, just add it unchanged
150 + $translated_date_format_string = $req_format[$i] . $translated_date_format_string;
151 + }
152 + else
153 + // current char is no a format literal, just add it unchanged
154 + $translated_date_format_string = $req_format[$i] . $translated_date_format_string;
155 + }
156 +
157 + $req_format = $translated_date_format_string;
158 +
159 + if ($gmt)
160 + // get GMT date string
161 + $date_formatted = gmdate($req_format, $timestamp);
162 + else
163 + {
164 + // get Wordpress time zone
165 + // $timezone_string = get_option('timezone_string');
166 + // Haha, just kidding. Let's get the currently set timezone, as God and Rasmus intended
167 + $timezone_string = date_default_timezone_get();
168 +
169 + if ($timezone_string)
170 + {
171 + // create time zone object
172 + $timezone_object = timezone_open($timezone_string);
173 + // create date object from time zone object
174 + $local_date_object = date_create(null, $timezone_object);
175 + // set time and date of $local_date_object to $timestamp
176 + $date_components = isset($date_components) ? $date_components : getdate($timestamp);
177 + date_date_set($local_date_object, $date_components['year'], $date_components['mon'], $date_components['mday']);
178 + date_time_set($local_date_object, $date_components['hours'], $date_components['minutes'], $date_components['seconds']);
179 + // format date according to the Wordpress time zone
180 + $date_formatted = date_format($local_date_object, $req_format);
181 + }
182 + else
183 + {
184 + // fall back if no Wordpress time zone set
185 + $date_formatted = date($req_format, $i);
186 + }
187 + }
188 +
189 + return $date_formatted;
190 + }
191 +
192 + /**
46 193 * Creates the Timed Content Rule post type and registers it with Wordpress
47 194 *
48 195 */
49 196 function timedContentRuleTypeInit()
@@ -50,9 +197,9 @@
50 197 {
51 198 $labels = array(
52 199 'name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' ),
53 200 'singular_name' => _x( 'Timed Content Rule', 'post type singular name', 'timed-content' ),
54 - 'add_new' => _x( 'Add New', TIMED_CONTENT_RULE_TYPE, 'timed-content' ),
201 + 'add_new' => _x( 'Add New', 'Menu item/button label on Timed Content Rules admin page', 'timed-content' ),
55 202 'add_new_item' => __( 'Add New Timed Content Rule', 'timed-content' ),
56 203 'edit_item' => __( 'Edit Timed Content Rule', 'timed-content' ),
57 204 'new_item' => __( 'New Timed Content Rule', 'timed-content' ),
58 205 'view_item' => __( 'View Timed Content Rule', 'timed-content' ),
@@ -59,9 +206,9 @@
59 206 'search_items' => __( 'Search Timed Content Rules', 'timed-content' ),
60 207 'not_found' => __( 'No Timed Content Rules found', 'timed-content' ),
61 208 'not_found_in_trash' => __( 'No Timed Content Rules found in Trash', 'timed-content' ),
62 209 'parent_item_colon' => '',
63 - 'menu_name' =>_x( 'Timed Content Rules', 'post type general name', 'timed-content' )
210 + 'menu_name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' )
64 211 );
65 212 $args = array(
66 213 'labels' => $labels,
67 214 'description' => __( 'Create regular schedules to show or hide selected content in a Page or Post.', 'timed-content' ),
@@ -81,10 +228,26 @@
81 228 'supports' => array( 'title' )
82 229 );
83 230 register_post_type( TIMED_CONTENT_RULE_TYPE, $args );
84 231 }
232 +
233 + /**
234 + * Filter to change sort order to title
235 + *
236 + * @param array $messages Array of currently defined messages for post types
237 + * @return mixed Array of messages with appropriate messages for Timed Content Rules added in
238 + */
239 + function timedContentPreGetPosts($query) {
240 + if($query->is_admin) {
241 + if ($query->get('post_type') == TIMED_CONTENT_RULE_TYPE)
242 + {
243 + $query->set('orderby', 'title');
244 + $query->set('order', 'ASC');
245 + }
246 + }
247 + return $query;
248 + }
85 249
86 -
87 250 /**
88 251 * Filter to customize CRUD messages for Timed Content Rules
89 252 *
90 253 * @param array $messages Array of currently defined messages for post types
@@ -91,10 +254,12 @@
91 254 * @return mixed Array of messages with appropriate messages for Timed Content Rules added in
92 255 */
93 256 function timedContentRuleUpdatedMessages( $messages ) {
94 257 global $post;
95 -// global $post_ID;
96 -
258 +
259 + /* translators: date and time format to activate rule. http://ca2.php.net/manual/en/function.date.php*/
260 + $post_date = date_i18n( __( 'M j, Y @ G:i', 'timed-content' ), strtotime( $post->post_date ) );
261 +
97 262 $messages[TIMED_CONTENT_RULE_TYPE] = array(
98 263 0 => '', // Unused. Messages start at index 1.
99 264 1 => __( 'Timed Content Rule updated.', 'timed-content' ),
100 265 2 => __( 'Custom field updated.', 'timed-content' ),
@@ -104,10 +269,10 @@
104 269 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Timed Content Rule restored to revision from %s', 'timed-content' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
105 270 6 => __( 'Timed Content Rule published.', 'timed-content' ),
106 271 7 => __( 'Timed Content Rule saved.', 'timed-content' ),
107 272 8 => __( 'Timed Content Rule submitted.', 'timed-content' ),
108 - /* translators: %s: date and time to activate rule */
109 - 9 => sprintf( __('Timed Content Rule scheduled for: <strong>%1$s</strong>.', 'timed-content' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ),
273 + /* translators: %s: date and time to activate rule. */
274 + 9 => sprintf( __( 'Timed Content Rule scheduled for: %s.' , 'timed-content' ), "<strong>" . $post_date . "</strong>" ),
110 275 10 => __( 'Timed Content Rule draft updated.', 'timed-content' )
111 276 );
112 277
113 278 return $messages;
@@ -112,8 +277,37 @@
112 277
113 278 return $messages;
114 279 }
115 280
281 + function __datetimeToEnglish( $date, $time = "" ) {
282 + $months = array( "January",
283 + "February",
284 + "March",
285 + "April",
286 + "May",
287 + "June",
288 + "July",
289 + "August",
290 + "September",
291 + "October",
292 + "November",
293 + "December" );
294 + $monthsI18N = array( __( "January", 'timed-content' ),
295 + __( "February", 'timed-content' ),
296 + __( "March", 'timed-content' ),
297 + __( "April", 'timed-content' ),
298 + __( "May", 'timed-content' ),
299 + __( "June", 'timed-content' ),
300 + __( "July", 'timed-content' ),
301 + __( "August", 'timed-content' ),
302 + __( "September", 'timed-content' ),
303 + __( "October", 'timed-content' ),
304 + __( "November", 'timed-content' ),
305 + __( "December", 'timed-content' ) );
306 + $english_date = str_replace( $monthsI18N, $months, $date );
307 + return $english_date . " " . $time;
308 + }
309 +
116 310 /**
117 311 * Advances a date/time by a set number of days
118 312 *
119 313 * @param int $current UNIX timestamp of the date/time before incrementing
@@ -154,9 +348,12 @@
154 348
155 349 // Otherwise, set up an array combining the days of the week to repeat on and the current day
156 350 // (keys and values of the array will be the same, and the array is sorted)
157 351 $currentDayOfWeekIndex = date( "w", $current );
158 - sort( array_values( array_unique( array_merge( array( $currentDayOfWeekIndex ), $days ) ) ) );
352 + $days = array_merge( array( $currentDayOfWeekIndex ), $days );
353 + $days = array_unique( $days );
354 + $days = array_values( $days );
355 + sort( $days );
159 356 $daysOfWeek = array_combine( $days, $days );
160 357
161 358 // If the current day is the last one of the days of the week to repeat on, jump ahead to
162 359 // the next week to be repeating on and get the earliest day in the array
@@ -288,27 +485,27 @@
288 485 $the_day = "";
289 486
290 487 if ( $day == 7 ) { // If $day is "day of the month", get the day of month based on the ordinal
291 488 switch ( $ordinal ) {
292 - case 1 : $the_day = "1"; break; // First day of the month //
293 - case 2 : $the_day = "2"; break; // Second day of the month //
294 - case 3 : $the_day = "3"; break; // Third day of the month //
295 - case 4 : $the_day = "4"; break; // Fourth day of the month //
296 - case 5 : $the_day = $lastDayThisMonth; break; // Last day of the month //
489 + case 0 : $the_day = "1"; break; // First day of the month //
490 + case 1 : $the_day = "2"; break; // Second day of the month //
491 + case 2 : $the_day = "3"; break; // Third day of the month //
492 + case 3 : $the_day = "4"; break; // Fourth day of the month //
493 + case 4 : $the_day = $lastDayThisMonth; break; // Last day of the month //
297 494 default : $the_day = "1"; break;
298 495 }
299 496 } else { // If $day is one of the days of the week...
300 497 $day_range = array();
301 498 switch ( $ordinal ) { // ...get a 7-day range based on the ordinal...
302 - case 1 : $day_range = range( 1, 7 ); break; // First 7 days of the month //
303 - case 2 : $day_range = range( 8, 14 ); break; // Second 7 days of the month //
304 - case 3 : $day_range = range( 15, 21 ); break; // Third 7 days of the month //
305 - case 4 : $day_range = range( 22, 28 ); break; // Fourth 7 days of the month //
306 - case 5 : $day_range = range( $lastDayThisMonth - 6, $lastDayThisMonth ); break; // Last 7 days of the month //
499 + case 0 : $day_range = range( 1, 7 ); break; // First 7 days of the month //
500 + case 1 : $day_range = range( 8, 14 ); break; // Second 7 days of the month //
501 + case 2 : $day_range = range( 15, 21 ); break; // Third 7 days of the month //
502 + case 3 : $day_range = range( 22, 28 ); break; // Fourth 7 days of the month //
503 + case 4 : $day_range = range( $lastDayThisMonth - 6, $lastDayThisMonth ); break; // Last 7 days of the month //
307 504 default : $day_range = range( 1, 7 ); break;
308 505 }
309 506 foreach ( $day_range as $a_day ) { // ...and find the matching weekday in that range.
310 - if ( $day == date( "l", strtotime( $the_month . " " . $a_day . ", " . $the_year ) ) ) {
507 + if ( $day == date( "w", strtotime( $the_month . " " . $a_day . ", " . $the_year ) ) ) {
311 508 $the_day = $a_day;
312 509 break;
313 510 }
314 511 }
@@ -339,11 +536,11 @@
339 536 */
340 537 function __validate( $args ) {
341 538 $errors = array();
342 539
343 - $instance_start = strtotime( $args['instance_start']['date'] . '' . $args['instance_start']['time'] . ' ' . $args['timezone'] );
344 - $instance_end = strtotime( $args['instance_end']['date'] . '' . $args['instance_end']['time'] . ' ' . $args['timezone'] );
345 - $end_date = strtotime( $args['end_date'] . '' . $args['instance_start']['time'] . ' ' . $args['timezone'] );
540 + $instance_start = strtotime( $this->__datetimeToEnglish( $args['instance_start']['date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] );
541 + $instance_end = strtotime( $this->__datetimeToEnglish( $args['instance_end']['date'], $args['instance_end']['time'] ) . ' ' . $args['timezone'] );
542 + $end_date = strtotime( $this->__datetimeToEnglish( $args['end_date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] );
346 543
347 544 if ( $args['instance_start']['date'] == "" )
348 545 $errors[] = __( "Date in Starting Date/Time must not be empty.", 'timed-content' );
349 546 if ( $args['instance_start']['time'] == "" )
@@ -401,16 +598,24 @@
401 598 $instance_end_time = $args['instance_end']['time'];
402 599 $monthly_pattern = $args['monthly_pattern'];
403 600 $monthly_pattern_ord = $args['monthly_pattern_ord'];
404 601 $monthly_pattern_day = $args['monthly_pattern_day'];
602 + $exceptions_dates = $args['exceptions_dates'];
405 603 //print_r($days_of_week);
406 604
605 + add_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4);
407 606 $temp_tz = date_default_timezone_get();
408 607 date_default_timezone_set( $timezone );
409 - $right_now_t = time();
608 + $right_now_t = current_time( 'timestamp', 1 );
410 609
411 - $instance_start = strtotime( $instance_start_date . " " . $instance_start_time . " " . $timezone ); // Beginning of first occurrence
412 - $instance_end = strtotime( $instance_end_date . " " . $instance_end_time . " " . $timezone ); // End of first occurrence
610 + // use debug parameter if current user is allowed to edit the post
611 + if(isset($_GET['tctest']) && current_user_can( "edit_post", $post->post_id)) {
612 + $dt = DateTime::createFromFormat('Y-m-d H:i:s', $_GET['tctest']);
613 + if($dt != FALSE) $right_now_t = $dt->getTimestamp();
614 + }
615 +
616 + $instance_start = strtotime( $this->__datetimeToEnglish( $instance_start_date, $instance_start_time ) . " " . $timezone ); // Beginning of first occurrence
617 + $instance_end = strtotime( $this->__datetimeToEnglish( $instance_end_date, $instance_end_time ) . " " . $timezone ); // End of first occurrence
413 618 $current = $instance_start;
414 619 $end_current = $instance_end;
415 620
416 621 if ( $recurr_type == "recurrence_duration_num_repeat" )
@@ -415,27 +620,27 @@
415 620
416 621 if ( $recurr_type == "recurrence_duration_num_repeat" )
417 622 $last_occurrence_start = strtotime( TIMED_CONTENT_END_TIME );
418 623 else
419 - $last_occurrence_start = strtotime( $end_date . " " . $instance_start_time . " " . $timezone );
624 + $last_occurrence_start = strtotime( $this->__datetimeToEnglish( $end_date, $instance_start_time ) . " " . $timezone );
420 625
421 626 if ( $human_readable == true ) {
422 - $active_periods[$period_count]["start"] = date( TIMED_CONTENT_DT_FORMAT, $current );
423 - $active_periods[$period_count]["end"] = date( TIMED_CONTENT_DT_FORMAT, $end_current );
627 + $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current );
628 + $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current );
629 + if ( $right_now_t < $current ) {
630 + $active_periods[$period_count]["status"] = "upcoming";
631 + $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $right_now_t, $current ) );
632 + } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
633 + $active_periods[$period_count]["status"] = "active";
634 + $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
635 + } else {
636 + $active_periods[$period_count]["status"] = "expired";
637 + $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
638 + }
424 639 } else {
425 640 $active_periods[$period_count]["start"] = $current;
426 641 $active_periods[$period_count]["end"] = $end_current;
427 642 }
428 - if ( $right_now_t < $current ) {
429 - $active_periods[$period_count]["status"] = "upcoming";
430 - $active_periods[$period_count]["time"] = sprintf( __( '%s from now.', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
431 - } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
432 - $active_periods[$period_count]["status"] = "active";
433 - $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
434 - } else {
435 - $active_periods[$period_count]["status"] = "expired";
436 - $active_periods[$period_count]["time"] = sprintf( __( '%s ago.', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
437 - }
438 643 $period_count++;
439 644
440 645 if ( $recurr_type == "recurrence_duration_end_date" )
441 646 $loop_test = "return ( \$current < \$last_occurrence_start );";
@@ -452,37 +657,51 @@
452 657 $current = $this->__getNextWeek( $current, $interval_multiplier, $days_of_week );
453 658 elseif ( $freq == 3 ) {
454 659 $current = $this->__getNextMonth( $current, $instance_start, $interval_multiplier );
455 660 $temp_current = $current;
456 - if ( $monthly_pattern == "yes" ) $current = $this->__getNthWeekdayOfMonth( $current, $monthly_pattern_ord, $monthly_pattern_day );
661 + if ( $monthly_pattern == "yes" )
662 + $current = $this->__getNthWeekdayOfMonth( $current, $monthly_pattern_ord, $monthly_pattern_day );
663 + else
664 + $current = $temp_current;
457 665 } elseif ( $freq == 4 )
458 666 $current = $this->__getNextYear( $current, $interval_multiplier );
459 -
460 - if ( eval ( $loop_test ) ) {
667 +
668 + $exception_period = false;
669 + if ( is_array( $exceptions_dates ) ) {
670 + foreach ($exceptions_dates as $date) {
671 + if (($current >= $date) && ($current < strtotime("+1 day", $date))) {
672 + $exception_period = true;
673 + break;
674 + }
675 + }
676 + }
677 +
678 + if ( ( eval ( $loop_test ) ) && ( !($exception_period) ) ) {
461 679 $end_current = $current + ( $instance_end - $instance_start );
462 680 if ( $human_readable == true ) {
463 - $active_periods[$period_count]["start"] = date( TIMED_CONTENT_DT_FORMAT, $current );
464 - $active_periods[$period_count]["end"] = date( TIMED_CONTENT_DT_FORMAT, $end_current );
681 + $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current );
682 + $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current );
683 + if ( $right_now_t < $current ) {
684 + $active_periods[$period_count]["status"] = "upcoming";
685 + $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
686 + } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
687 + $active_periods[$period_count]["status"] = "active";
688 + $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
689 + } else {
690 + $active_periods[$period_count]["status"] = "expired";
691 + $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
692 + }
465 693 } else {
466 694 $active_periods[$period_count]["start"] = $current;
467 695 $active_periods[$period_count]["end"] = $end_current;
468 696 }
469 - if ( $right_now_t < $current ) {
470 - $active_periods[$period_count]["status"] = "upcoming";
471 - $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
472 - } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
473 - $active_periods[$period_count]["status"] = "active";
474 - $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
475 - } else {
476 - $active_periods[$period_count]["status"] = "expired";
477 - $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
478 - }
479 - $period_count++;
697 + if ( !($exception_period) )
698 + $period_count++;
480 699 }
481 700
482 - if ( ( $freq == 3 ) && ( $monthly_pattern == "yes" ) ) $current = $temp_current;
483 701 }
484 702 date_default_timezone_set( $temp_tz );
703 + remove_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4);
485 704 return $active_periods;
486 705 }
487 706
488 707 /**
@@ -517,9 +736,10 @@
517 736 $args['instance_end'] = get_post_meta( $ID, $prefix . 'instance_end', true );
518 737 $args['monthly_pattern'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true );
519 738 $args['monthly_pattern_ord'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true );
520 739 $args['monthly_pattern_day'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true );
521 -
740 + $args['exceptions_dates'] = get_post_meta( $ID, $prefix . 'exceptions_dates', true );
741 +
522 742 return $this->__getRulePeriods( $args );
523 743
524 744 }
525 745
@@ -544,9 +764,10 @@
544 764 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
545 765 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
546 766 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
547 767 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
548 -
768 + $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
769 +
549 770 $response = json_encode( $this->__getRulePeriods( $args ) );
550 771
551 772 // response output
552 773 header( "Content-Type: application/json" );
@@ -562,9 +783,9 @@
562 783 * @param $args Array of Timed Content Rule parameters
563 784 * @return string
564 785 */
565 786 function __getScheduleDescription( $args ) {
566 - require("lib/Arrays_Definitions.php");
787 + include("lib/Arrays_Definitions.php");
567 788
568 789 $interval_multiplier = 1;
569 790 $desc = "";
570 791
@@ -599,11 +820,12 @@
599 820 $instance_end_time = $args['instance_end']['time'];
600 821 $monthly_pattern = $args['monthly_pattern'];
601 822 $monthly_pattern_ord = $args['monthly_pattern_ord'];
602 823 $monthly_pattern_day = $args['monthly_pattern_day'];
824 + $exceptions_dates = $args['exceptions_dates'];
825 +
826 + $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 );
603 827
604 - $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 );
605 -
606 828 if ( $freq == 0 )
607 829 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every hour.', 'Repeat this action every %d hours.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
608 830 elseif ( $freq == 1 )
609 831 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every day.', 'Repeat this action every %d days.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
@@ -630,11 +852,11 @@
630 852
631 853 } elseif ( $freq == 3 ) {
632 854 if ( $monthly_pattern == "yes" ) {
633 855 if ( $interval_multiplier == 1 )
634 - $desc .= "&nbsp;" . 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] );
856 + $desc .= "&nbsp;" . 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] );
635 857 else
636 - $desc .= "&nbsp;" . 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] );
858 + $desc .= "&nbsp;" . 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] );
637 859 } else
638 860 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every month.', 'Repeat this action every %d months.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
639 861 } elseif ( $freq == 4 )
640 862 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every year.', 'Repeat this action every %d years.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
@@ -642,9 +864,22 @@
642 864 if ( $recurr_type == "recurrence_duration_num_repeat" )
643 865 $desc .= "&nbsp;" . sprintf( _n( 'This rule will be active for 1 repetition.', 'This rule will be active for %d repetitions.', $num_repeat, 'timed-content' ), $num_repeat );
644 866 elseif ( $recurr_type == "recurrence_duration_end_date" )
645 867 $desc .= "&nbsp;" . sprintf( __( 'This rule will be active until %s.', 'timed-content' ), $end_date );
646 -
868 +
869 + if ( ( $exceptions_dates ) && ( is_array( $exceptions_dates ) ) ) {
870 + sort( $exceptions_dates, SORT_NUMERIC );
871 + $exceptions_dates = array_unique( $exceptions_dates );
872 + if ( $exceptions_dates[0] == 0 )
873 + array_shift( $exceptions_dates );
874 + if ( !empty( $exceptions_dates ) ) {
875 + $formatted_dates = array();
876 + foreach ( $exceptions_dates as $a_date )
877 + $formatted_dates[] = date( _x( "F j, Y" , "Date format for schedule description", 'timed-content' ), $a_date );
878 + $desc .= "&nbsp;" . sprintf( __( 'This rule will be inactive on the following dates: %s.', 'timed-content' ), join( ", ", $formatted_dates ) );
879 + }
880 + }
881 +
647 882 $desc .= "&nbsp;" . sprintf( __( 'All times are in the %s timezone.', 'timed-content' ), $timezone );
648 883 return $desc;
649 884 }
650 885
@@ -654,9 +889,12 @@
654 889 * @param int $ID ID of the Timed Content Rule
655 890 * @return string
656 891 */
657 892 function getScheduleDescriptionById( $ID ) {
658 - global $timed_content_rule_occurrence_custom_fields, $timed_content_rule_pattern_custom_fields, $timed_content_rule_recurrence_custom_fields;
893 + global $timed_content_rule_occurrence_custom_fields,
894 + $timed_content_rule_pattern_custom_fields,
895 + $timed_content_rule_recurrence_custom_fields,
896 + $timed_content_rule_exceptions_custom_fields;
659 897 $defaults = array();
660 898
661 899 foreach ( $timed_content_rule_occurrence_custom_fields as $field ) {
662 900 $defaults[$field['name']] = $field['default'];
@@ -663,11 +901,14 @@
663 901 }
664 902 foreach ( $timed_content_rule_pattern_custom_fields as $field ) {
665 903 $defaults[$field['name']] = $field['default'];
666 904 }
667 - foreach ( $timed_content_rule_recurrence_custom_fields as $field ) {
668 - $defaults[$field['name']] = $field['default'];
669 - }
905 + foreach ( $timed_content_rule_recurrence_custom_fields as $field ) {
906 + $defaults[$field['name']] = $field['default'];
907 + }
908 + foreach ( $timed_content_rule_exceptions_custom_fields as $field ) {
909 + $defaults[$field['name']] = $field['default'];
910 + }
670 911
671 912 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
672 913 $args = array();
673 914
@@ -687,8 +928,9 @@
687 928 $args['instance_end'] = ( false === get_post_meta( $ID, $prefix . 'instance_end', true ) ? $defaults['instance_end'] : get_post_meta( $ID, $prefix . 'instance_end', true ) );
688 929 $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 ) );
689 930 $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 ) );
690 931 $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 ) );
932 + $args['exceptions_dates'] = ( false === get_post_meta( $ID, $prefix . 'exceptions_dates', true ) ? $defaults['exceptions_dates'] : get_post_meta( $ID, $prefix . 'exceptions_dates', true ) );
691 933
692 934 return $this->__getScheduleDescription( $args );
693 935
694 936 }
@@ -714,9 +956,10 @@
714 956 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
715 957 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
716 958 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
717 959 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
718 -
960 + $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
961 +
719 962 $response = $this->__getScheduleDescription( $args );
720 963
721 964 // response output
722 965 header( "Content-Type: text/plain" );
@@ -750,10 +993,20 @@
750 993
751 994 $the_class = TIMED_CONTENT_CLIENT_TAG . $show_attr . $hide_attr ;
752 995 $the_tag = ( $display == "div" ? "div" : "span" );
753 996
754 - $the_HTML = "<" . $the_tag . " class='" . $the_class . "'" . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">" . do_shortcode( $content ) . "</" . $the_tag . ">";
997 + $the_filter = "timed_content_filter";
998 + $the_filter = apply_filters( "timed_content_filter_override", $the_filter );
755 999
1000 + $the_HTML = "<"
1001 + . $the_tag
1002 + . " class='"
1003 + . $the_class
1004 + . "'"
1005 + . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">"
1006 + . str_replace( ']]>', ']]&gt;', apply_filters( $the_filter, $content ) )
1007 + . "</" . $the_tag . ">";
1008 +
756 1009 return $the_HTML;
757 1010 }
758 1011
759 1012 /**
@@ -765,14 +1018,24 @@
765 1018 */
766 1019 function serverShowHTML( $atts, $content = null ) {
767 1020 global $post;
768 1021 extract( shortcode_atts( array( 'show' => TIMED_CONTENT_ZERO_TIME , 'hide' => TIMED_CONTENT_END_TIME, 'debug' => 'false' ), $atts ) );
769 - $show_t = strtotime( $show );
770 - $hide_t = strtotime( $hide );
771 - $right_now_t = time();
1022 + $show_t = strtotime( $this->__datetimeToEnglish( $show ) );
1023 + $hide_t = strtotime( $this->__datetimeToEnglish( $hide ) );
1024 + $right_now_t = current_time( 'timestamp', 1 );
772 1025 $debug_message = "";
1026 +
1027 + // use debug parameter if current user is allowed to edit the post
1028 + if(isset($_GET['tctest']) && current_user_can( "edit_post", $post->post_id)) {
1029 + $dt = DateTime::createFromFormat('Y-m-d H:i:s', $_GET['tctest']);
1030 + if($dt != FALSE) $right_now_t = $dt->getTimestamp();
1031 + }
1032 +
1033 + $the_filter = "timed_content_filter";
1034 + $the_filter = apply_filters( "timed_content_filter_override", $the_filter );
773 1035
774 1036 if ( ( $debug == "true" ) && ( current_user_can( "edit_post", $post->post_id ) ) ) {
1037 + add_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4);
775 1038 $temp_tz = date_default_timezone_get();
776 1039 date_default_timezone_set( get_option( 'timezone_string' ) );
777 1040
778 1041 $right_now = date_i18n( TIMED_CONTENT_DT_FORMAT, $right_now_t );
@@ -787,37 +1050,43 @@
787 1050 $hide_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) );
788 1051
789 1052 $debug_message = "<div class=\"tcr-warning\">\n";
790 1053 $debug_message .= "<p class=\"heading\">" . _x( "Notice", "Noun", 'timed-content' ) . "</p>\n";
791 - $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";
1054 + $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";
792 1055
793 1056 if ( $show == TIMED_CONTENT_ZERO_TIME )
794 - $debug_message .= "<p>" . __( 'The <code>show</code> attribute is not set.', 'timed-content') . "</p>\n";
1057 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ), "<code>show</code>" ) . "</p>\n";
795 1058 else
796 - $debug_message .= "<p>" . __( 'The <code>show</code> attribute is currently set to', 'timed-content') . ": " . $show . ",<br />\n "
1059 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>show</code>" ) . ": " . $show . ",<br />\n "
797 1060 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $show_t )
798 1061 . " (" . $show_diff_str . ")</p>\n";
799 1062
800 1063 if ( $hide == TIMED_CONTENT_END_TIME )
801 - $debug_message .= "<p>" . __( 'The <code>hide</code> attribute is not set.' , 'timed-content') . "</p>\n";
1064 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.' , 'timed-content' ), "<code>hide</code>" ) . "</p>\n";
802 1065 else
803 - $debug_message .= "<p>" . __( 'The <code>hide</code> attribute is currently set to', 'timed-content') . ": " . $hide . ",<br />\n"
1066 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>hide</code>" ) . ": " . $hide . ",<br />\n"
804 1067 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $hide_t )
805 1068 . " (" . $hide_diff_str . ").</p>\n";
806 1069
807 - $debug_message .= "<p>" . __( 'Current time', 'timed-content') . " : " . $right_now . "</p>\n";
808 - $debug_message .= "<p>" . __( 'Content', "Noun", 'timed-content') . " : " . $content . "</p>\n";
1070 + $debug_message .= "<p>" . __( 'Current Date/Time:', 'timed-content') . "&nbsp;" . $right_now . "<br />\n";
1071 + $debug_message .= __( 'Content Filter:', 'timed-content') . "&nbsp;" . $the_filter . "</p>\n";
1072 + $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content') . "&nbsp;" . $content . "</p>\n";
809 1073
810 1074 $debug_message .= "</div>\n";
811 1075
812 1076 date_default_timezone_set( $temp_tz );
1077 + remove_filter('date_i18n', array( &$this, "fix_date_i18n" ), 10, 4);
813 1078 }
814 -
815 - if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) )
816 - return $debug_message . do_shortcode( $content ) . "\n";
817 - else
818 - return $debug_message . "\n";
819 1079
1080 +
1081 + if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) ) {
1082 + do_action("timed_content_server_show", $post->ID, $show, $hide, $content);
1083 + return $debug_message . str_replace(']]>', ']]&gt;', apply_filters($the_filter, $content)) . "\n";
1084 + } else {
1085 + do_action("timed_content_server_hide", $post->ID, $show, $hide, $content);
1086 + return $debug_message . "\n";
1087 + }
1088 +
820 1089 }
821 1090
822 1091 /**
823 1092 * Processes the [timed-content-rule] shortcode.
@@ -826,14 +1095,26 @@
826 1095 * @param null $content
827 1096 * @return string
828 1097 */
829 1098 function rulesShowHTML( $atts, $content = null ) {
830 - extract( shortcode_atts( array( 'id' => '0' ), $atts ) );
1099 + global $post;
1100 + extract( shortcode_atts( array( 'id' => 0 ), $atts ) );
1101 + if ( !is_numeric( $id ) ) {
1102 + $page = get_page_by_title( $id, OBJECT, TIMED_CONTENT_RULE_TYPE );
1103 + if ( $page == null ) return;
1104 + $id = $page->ID;
1105 + }
831 1106 if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $id ) ) return;
832 1107
833 1108 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
834 - $right_now_t = time();
1109 + $right_now_t = current_time( 'timestamp', 1 );
835 1110 $rule_is_active = false;
1111 +
1112 + // use debug parameter if current user is allowed to edit the post
1113 + if(isset($_GET['tctest']) && current_user_can( "edit_post", $post->post_id)) {
1114 + $dt = DateTime::createFromFormat('Y-m-d H:i:s', $_GET['tctest']);
1115 + if($dt != FALSE) $right_now_t = $dt->getTimestamp();
1116 + }
836 1117
837 1118 $active_periods = $this->getRulePeriodsById( $id, false );
838 1119 $action_is_show = (bool) get_post_meta( $id, $prefix . 'action', true );
839 1120
@@ -842,13 +1123,19 @@
842 1123 $rule_is_active = true;
843 1124 break;
844 1125 }
845 1126 }
846 -
847 - if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) )
848 - return do_shortcode( $content );
849 - else
850 - return "";
1127 +
1128 + $the_filter = "timed_content_filter";
1129 + $the_filter = apply_filters( "timed_content_filter_override", $the_filter );
1130 +
1131 + if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) ) {
1132 + do_action("timed_content_rule_show", $post->ID, $id, $content);
1133 + return str_replace(']]>', ']]&gt;', apply_filters($the_filter, $content));
1134 + } else {
1135 + do_action("timed_content_rule_hide", $post->ID, $id, $content);
1136 + return "";
1137 + }
851 1138 }
852 1139
853 1140 /**
854 1141 * Enqueues the JavaScript code necessary for the functionality of the [timed-content-client] shortcode.
@@ -854,30 +1141,58 @@
854 1141 * Enqueues the JavaScript code necessary for the functionality of the [timed-content-client] shortcode.
855 1142 */
856 1143 function addHeaderCode() {
857 1144 if ( ! is_admin() ) {
858 - wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_PLUGIN_URL . '/timed-content.css' );
1145 + wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
859 1146 wp_enqueue_script( 'timed-content_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
860 1147 }
861 1148 }
862 1149
1150 + /**
1151 + * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens for WP 3.7.1 and under. Echo'd to output.
1152 + */
1153 + function addPostTypeIcons37() {
1154 + ?>
1155 + <style type="text/css" media="screen">
1156 + #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> .wp-menu-image {
1157 + background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_icon.png) no-repeat 6px 6px !important;
1158 + }
1159 + #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>:hover .wp-menu-image, #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.wp-has-current-submenu .wp-menu-image {
1160 + background-position: -22px 6px !important;
1161 + }
1162 + #icon-edit.icon32-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> {background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_32x32.png) no-repeat;}
1163 + </style>
1164 + <?php
1165 + }
1166 +
863 1167 /**
864 - * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens. Echo'd to output.
1168 + * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens
1169 + * and the TinyMCE editor. Echo'd to output.
865 1170 */
866 1171 function addPostTypeIcons() {
867 -?>
868 -<style type="text/css" media="screen">
869 - #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> .wp-menu-image {
870 - background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_icon.png) no-repeat 6px 6px !important;
871 - }
872 - #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>:hover .wp-menu-image, #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.wp-has-current-submenu .wp-menu-image {
873 - background-position: -22px 6px !important;
874 - }
875 - #icon-edit.icon32-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> {background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_32x32.png) no-repeat;}
876 -</style>
1172 + wp_enqueue_style( 'ca-aliencyborg-dashicons', TIMED_CONTENT_CSS_DASHICONS, false, TIMED_CONTENT_VERSION );
1173 + ?>
1174 + <style type="text/css" media="screen">
1175 + #adminmenu #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.menu-icon-post div.wp-menu-image:before {
1176 + font-family: 'ca-aliencyborg-dashicons' !important;
1177 + content: '\e601';
1178 + }
1179 + #dashboard_right_now li.<?php echo TIMED_CONTENT_RULE_TYPE; ?>-count a:before {
1180 + font-family: 'ca-aliencyborg-dashicons' !important;
1181 + content: '\e601';
1182 + }
1183 + .mce-i-timed_content:before {
1184 + font: 400 24px/1 'ca-aliencyborg-dashicons' !important;
1185 + padding: 0;
1186 + vertical-align: top;
1187 + margin-left: -2px;
1188 + padding-right: 2px;
1189 + content: '\e601';
1190 + }
1191 + </style>
877 1192 <?php
878 1193 }
879 -
1194 +
880 1195 /**
881 1196 * Enqueues the JavaScript code necessary for the functionality of the Timed Content Rules management screens.
882 1197 */
883 1198 function addAdminHeaderCode() {
@@ -883,25 +1198,30 @@
883 1198 function addAdminHeaderCode() {
884 1199 if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == TIMED_CONTENT_RULE_TYPE )
885 1200 || ( isset( $post_type ) && $post_type == TIMED_CONTENT_RULE_TYPE )
886 1201 || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == TIMED_CONTENT_RULE_TYPE ) ) {
887 - wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_PLUGIN_URL . '/timed-content.css' );
1202 + wp_enqueue_style( 'thickbox' );
1203 + wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
888 1204 // Enqueue the JavaScript file that manages the meta box UI
889 1205 wp_enqueue_script( 'timed-content-admin_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
890 1206 // Enqueue the JavaScript file that makes AJAX requests
891 - wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'jquery-ui-dialog' ), TIMED_CONTENT_VERSION );
1207 + wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'thickbox' ), TIMED_CONTENT_VERSION );
892 1208
1209 + // Set up local variables used in the Admin JavaScript file
1210 + wp_localize_script( 'timed-content-admin_js', 'timedContentRuleAdmin', array(
1211 + 'no_exceptions_label' => __( "- No exceptions set -", 'timed-content' ) ) );
1212 +
893 1213 // Set up local variables used in the AJAX JavaScript file
894 1214 wp_localize_script( 'timed-content-ajax_js', 'timedContentRuleAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
895 1215 'start_label' => _x( 'Start', 'Scheduled Dates/Times dialog - Beginning of active period table header', 'timed-content' ),
896 1216 'end_label' => _x( 'End', 'Scheduled Dates/Times dialog - End of active period table header', 'timed-content' ),
897 - 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ),
898 - 'dialog_width' => 800,
899 - 'dialog_height' => 500,
900 - 'close_label' => _x( 'Close', 'Scheduled Dates/Times dialog - Close button HTML label', 'timed-content' ),
901 - 'loadingimg' => TIMED_CONTENT_PLUGIN_URL . '/img/wpspin.gif',
902 - 'error' => __( "Error", 'timed-content' ),
903 - 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) );
1217 + 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ),
1218 + 'button_loading_label' => __( 'Calculating Dates/Times', 'timed-content' ),
1219 + 'button_finished_label' => __( 'Show Projected Dates/Times', 'timed-content' ),
1220 + 'dialog_width' => 800,
1221 + 'dialog_height' => 500,
1222 + 'error' => __( "Error", 'timed-content' ),
1223 + 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) );
904 1224 }
905 1225 }
906 1226
907 1227 /**
@@ -918,22 +1238,27 @@
918 1238 }
919 1239 }
920 1240
921 1241 /**
922 - * Sets up variables to use in the TinyMCE plugin's editor_plugin_src.js.
1242 + * Sets up variables to use in the TinyMCE plugin's plugin.js.
923 1243 *
924 1244 */
925 1245 function setTinyMCEPluginVars() {
1246 + global $wp_version;
926 1247 if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) )
927 1248 return;
928 1249
929 1250 // Add only in Rich Editor mode
930 1251 if ( get_user_option( 'rich_editing' ) == 'true' ) {
931 - wp_enqueue_script( 'timed-content-admin_tinymce_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin-tinymce.js', array(), TIMED_CONTENT_VERSION );
932 - wp_localize_script( 'timed-content-admin_tinymce_js',
933 - 'timedContentAdminTinyMCEOptionsVars',
934 - array( 'version' => TIMED_CONTENT_VERSION,
935 - 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ) ) );
1252 + if ( version_compare( $wp_version, "3.8", "<" ) )
1253 + $image = "/clock.gif";
1254 + else
1255 + $image = "";
1256 + wp_localize_script( 'editor',
1257 + 'timedContentAdminTinyMCEOptions',
1258 + array( 'version' => TIMED_CONTENT_VERSION,
1259 + 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ),
1260 + 'image' => $image ) );
936 1261 }
937 1262 }
938 1263
939 1264 /**
@@ -952,9 +1277,9 @@
952 1277 * @param array $plugin_array Array of plugins already registered with TinyMCE
953 1278 * @return array The array of TinyMCE plugins with ours now loaded in as well
954 1279 */
955 1280 function addTimedContentTinyMCEPlugin( $plugin_array ) {
956 - $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/editor_plugin.js";
1281 + $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/plugin.js";
957 1282 return $plugin_array;
958 1283 }
959 1284
960 1285 /**
@@ -970,10 +1295,13 @@
970 1295 foreach ( $the_rules as $rule ) {
971 1296 $desc = $this->getScheduleDescriptionById( $rule->ID );
972 1297 // Only add a rule if there's no errors or warnings
973 1298 if ( false === strpos( $desc, "tcr-warning" ) )
974 - $the_js .= " { 'ID': " . $rule->ID . ", 'title': '" . esc_js( $rule->post_title ) . "', 'desc': '" . esc_js( $desc ) . "' },\n";
1299 + $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";
975 1300 }
1301 + if ( empty( $the_rules ) )
1302 + $the_js .= " { 'ID': -999, 'title': ' ---- ', 'desc': '" . __( 'No Timed Content Rules found', 'timed-content' ) . "' }\n";
1303 +
976 1304 $the_js .= "];\n";
977 1305 return $the_js;
978 1306 }
979 1307 /**
@@ -980,17 +1308,25 @@
980 1308 * Display a dialog box for this plugin's associated TinyMCE plugin. Called from TinyMCE via AJAX.
981 1309 *
982 1310 */
983 1311 function timedContentPluginGetTinyMCEDialog() {
984 - wp_enqueue_style( 'timed-content-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS );
985 - wp_enqueue_script( 'jquery-ui-datepicker' );
986 - wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS );
987 - wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' );
988 - wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION );
989 - wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' );
1312 + include("lib/jquery-ui-datetime-i18n.php");
990 1313
1314 + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS);
1315 + wp_enqueue_script('jquery-ui-datepicker');
1316 + wp_register_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS);
1317 + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css');
1318 + wp_register_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION);
1319 + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js');
1320 + if (!(wp_script_is(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'registered'))) {
1321 + 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);
1322 + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js');
1323 + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQDatepickerI18n', $jquery_ui_datetime_datepicker_i18n);
1324 + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQTimepickerI18n', $jquery_ui_datetime_timepicker_i18n);
1325 + }
1326 +
991 1327 ob_start();
992 - include("tinymce_plugin/dialog.php");
1328 + include( "tinymce_plugin/dialog.php" );
993 1329 $content = ob_get_contents();
994 1330 ob_end_clean();
995 1331 echo $content;
996 1332 die();
@@ -996,14 +1332,14 @@
996 1332 die();
997 1333 }
998 1334
999 1335 /**
1000 - * Displays a count of Timed Content Rules of the Dashboard's Right now widget
1336 + * Adds support for i18n (internationalization)
1001 1337 *
1002 1338 */
1003 1339 function i18nInit() {
1004 1340 $plugin_dir = basename( dirname( __FILE__ ) ) . "/lang/";
1005 - load_plugin_textdomain( 'timed-content', null, $plugin_dir );
1341 + load_plugin_textdomain( 'timed-content', false, $plugin_dir );
1006 1342 }
1007 1343
1008 1344 /**
1009 1345 * Add custom columns to the Timed Content Rules overview page
@@ -1033,11 +1369,45 @@
1033 1369 }
1034 1370 }
1035 1371 }
1036 1372
1373 + /**
1374 + * Display a count of Timed Content Rules in the Dashboard's Right Now widget for Wordpress versions 3.7.1 and below
1375 + *
1376 + */
1377 + function addRulesCount37() {
1378 + if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
1379 + return;
1380 + }
1037 1381
1382 + $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1383 + $num = number_format_i18n( $num_posts->publish );
1384 + $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1385 + if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1386 + $num = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1387 + $text = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1388 + }
1389 + echo '<tr>';
1390 + echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1391 + echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1392 + echo '</tr>';
1393 +
1394 + if ( $num_posts->pending > 0 ) {
1395 + $num = number_format_i18n( $num_posts->pending );
1396 + $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1397 + if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1398 + $num = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1399 + $text = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1400 + }
1401 + echo '<tr>';
1402 + echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1403 + echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1404 + echo '</tr>';
1405 + }
1406 + }
1407 +
1038 1408 /**
1039 - * Display a count of Timed Content Rules of the Dashboard's Right now widget
1409 + * Display a count of Timed Content Rules in the Dashboard's Right Now widget
1040 1410 *
1041 1411 */
1042 1412 function addRulesCount() {
1043 1413 if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
@@ -1045,31 +1415,75 @@
1045 1415 }
1046 1416
1047 1417 $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1048 1418 $num = number_format_i18n( $num_posts->publish );
1049 - $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ) );
1050 - if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1051 - $num = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>$num</a>";
1052 - $text = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>$text</a>";
1053 - }
1054 - echo '<tr>';
1055 - echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1056 - echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1057 - echo '</tr>';
1419 + $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1420 + if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1421 + echo "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1422 + . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1423 + . $num
1424 + . ' '
1425 + . $text
1426 + . '</a></li>';
1058 1427
1059 1428 if ( $num_posts->pending > 0 ) {
1060 1429 $num = number_format_i18n( $num_posts->pending );
1061 - $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ) );
1062 - if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1063 - $num = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>$num</a>";
1064 - $text = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>$text</a>";
1065 - }
1066 - echo '<tr>';
1067 - echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1068 - echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1069 - echo '</tr>';
1070 - }
1430 + $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1431 + if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1432 + echo "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1433 + . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1434 + . $num
1435 + . ' '
1436 + . $text
1437 + . '</a></li>';
1438 + }
1071 1439 }
1440 +
1441 + function setUpCustomFields() {
1442 + require_once( "lib/customFields-settings.php" );
1443 + require_once( "lib/customFieldsInterface.php" );
1444 +
1445 + $scf = new customFieldsInterface( "timed_content_rule_schedule",
1446 + __( 'Rule Description/Schedule', 'timed-content' ),
1447 + "<div id=\"schedule_desc\" style=\"font-style: italic;\">"
1448 + . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $this->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $this->getScheduleDescriptionById( intval( 0 ) ) )
1449 + . "</div>"
1450 + . "<div id=\"tcr-dialogHolder\" style=\"display:none;\"></div>"
1451 + . "<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>",
1452 + TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1453 + array( TIMED_CONTENT_RULE_TYPE ),
1454 + array() );
1455 + $ocf = new customFieldsInterface( "timed_content_rule_initial_event",
1456 + __( 'Action/Initial Event', 'timed-content' ),
1457 + __( 'Set the action to be taken and when it should first run.', 'timed-content' ),
1458 + TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1459 + array( TIMED_CONTENT_RULE_TYPE ),
1460 + $timed_content_rule_occurrence_custom_fields );
1461 + $pcf = new customFieldsInterface( "timed_content_rule_recurrence",
1462 + __( 'Repeating Pattern', 'timed-content' ),
1463 + __( 'Set how often the action should repeat.', 'timed-content' ),
1464 + TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1465 + array( TIMED_CONTENT_RULE_TYPE ),
1466 + $timed_content_rule_pattern_custom_fields );
1467 + $rcf = new customFieldsInterface( "timed_content_rule_stop_condition",
1468 + __( 'Stopping Condition', 'timed-content' ),
1469 + __( 'Set how long or how many times the action should occur.', 'timed-content' ),
1470 + TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1471 + array( TIMED_CONTENT_RULE_TYPE ),
1472 + $timed_content_rule_recurrence_custom_fields );
1473 + $ecf = new customFieldsInterface( "timed_content_rule_exceptions",
1474 + __( 'Exceptions', 'timed-content' ),
1475 + __( 'Set up any exceptions to this Timed Content Rule.', 'timed-content' ),
1476 + TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1477 + array( TIMED_CONTENT_RULE_TYPE ),
1478 + $timed_content_rule_exceptions_custom_fields );
1479 +
1480 + // Initially loaded at the top; defining this constant here means it can get i18n'd
1481 + /* translators: date/time format for debugging messages. http://ca2.php.net/manual/en/function.date.php */
1482 + define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i A T" , 'timed-content' ) );
1483 +
1484 + }
1485 +
1072 1486 }
1073 1487
1074 1488 } //End Class timedContentPlugin
1075 1489
@@ -1079,38 +1493,20 @@
1079 1493 }
1080 1494
1081 1495 // Actions and Filters
1082 1496 if ( isset( $timedContentPluginInstance ) ) {
1083 - $scf = new customFieldsInterface( "cfi_s",
1084 - __( 'Rule Description/Schedule', 'timed-content' ),
1085 - "<div id=\"schedule_desc\" style=\"font-style: italic;\">"
1086 - . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $timedContentPluginInstance->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $timedContentPluginInstance->getScheduleDescriptionById( intval( 0 ) ) )
1087 - . "</div>"
1088 - . "<div style=\"padding-top: 10px;\"><input type=\"button\" class=\"button-primary\" id=\"timed_content_rule_test\" value=\"Show Projected Dates/Times\" /></div>",
1089 - TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1090 - array( TIMED_CONTENT_RULE_TYPE ),
1091 - array() );
1092 - $ocf = new customFieldsInterface( "cfi_o",
1093 - __( 'Action/Initial Event', 'timed-content' ),
1094 - __( 'Set the action to be taken and when it should first run.', 'timed-content' ),
1095 - TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1096 - array( TIMED_CONTENT_RULE_TYPE ),
1097 - $timed_content_rule_occurrence_custom_fields );
1098 - $pcf = new customFieldsInterface( "cfi_p",
1099 - __( 'Repeating Pattern', 'timed-content' ),
1100 - __( 'Set how often the action should repeat.', 'timed-content' ),
1101 - TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1102 - array( TIMED_CONTENT_RULE_TYPE ),
1103 - $timed_content_rule_pattern_custom_fields );
1104 - $rcf = new customFieldsInterface( "cfi_r",
1105 - __( 'Stopping Condition', 'timed-content' ),
1106 - __( 'Set how long or how many times the action should occur.', 'timed-content' ),
1107 - TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1108 - array( TIMED_CONTENT_RULE_TYPE ),
1109 - $timed_content_rule_recurrence_custom_fields );
1110 - add_action( "init", array( &$timedContentPluginInstance, "i18nInit" ), 1 );
1497 + global $wp_version;
1498 +
1499 + add_filter('timed_content_filter', 'wptexturize');
1500 + add_filter('timed_content_filter', 'convert_smilies');
1501 + add_filter('timed_content_filter', 'convert_chars');
1502 + add_filter('timed_content_filter', 'wpautop');
1503 + add_filter('timed_content_filter', 'prepend_attachment');
1504 + add_filter('timed_content_filter', 'do_shortcode');
1505 +
1506 + add_action( "plugins_loaded", array( &$timedContentPluginInstance, "i18nInit" ), 1 );
1111 1507 add_action( "init", array( &$timedContentPluginInstance, "timedContentRuleTypeInit" ), 2 );
1112 - add_action( "right_now_content_table_end", array( &$timedContentPluginInstance, "addRulesCount" ) );
1508 + add_action( "init", array( &$timedContentPluginInstance, "setUpCustomFields" ), 2 );
1113 1509 add_action( "wp_head", array( &$timedContentPluginInstance, "addHeaderCode" ), 1 );
1114 1510 add_filter( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_columns", array( &$timedContentPluginInstance, "addDescColumnHead" ) );
1115 1511 add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2);
1116 1512 add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 );
@@ -1115,14 +1511,23 @@
1115 1511 add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2);
1116 1512 add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 );
1117 1513 add_action( "admin_init", array( &$timedContentPluginInstance, "setTinyMCEPluginVars" ), 1 );
1118 1514 add_action( "admin_init", array( &$timedContentPluginInstance, "initTinyMCEPlugin" ), 2 );
1119 - add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons" ), 1 );
1120 1515 add_action( 'wp_ajax_timedContentPluginGetTinyMCEDialog', array( &$timedContentPluginInstance, "timedContentPluginGetTinyMCEDialog" ), 1 );
1121 1516 add_action( 'wp_ajax_timedContentPluginGetRulePeriodsAjax', array( &$timedContentPluginInstance, "timedContentPluginGetRulePeriodsAjax" ), 1 );
1122 1517 add_action( 'wp_ajax_timedContentPluginGetScheduleDescriptionAjax', array( &$timedContentPluginInstance, "timedContentPluginGetScheduleDescriptionAjax" ), 1 );
1123 1518 add_filter( "post_updated_messages", array( &$timedContentPluginInstance, "timedContentRuleUpdatedMessages" ), 1 );
1124 - add_shortcode( TIMED_CONTENT_CLIENT_TAG, array( &$timedContentPluginInstance, "clientShowHTML" ), 1 );
1519 + if ( version_compare( $wp_version, "3.8", ">=" ) ) {
1520 + add_action( "dashboard_glance_items", array( &$timedContentPluginInstance, "addRulesCount" ) );
1521 + add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons" ), 1 );
1522 + } else {
1523 + add_action( "right_now_content_table_end", array( &$timedContentPluginInstance, "addRulesCount37" ) );
1524 + add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons37" ), 1 );
1525 + }
1526 +
1527 + add_shortcode( TIMED_CONTENT_CLIENT_TAG, array( &$timedContentPluginInstance, "clientShowHTML" ), 1 );
1125 1528 add_shortcode( TIMED_CONTENT_SERVER_TAG, array( &$timedContentPluginInstance, "serverShowHTML" ), 1 );
1126 1529 add_shortcode( TIMED_CONTENT_RULE_TAG, array( &$timedContentPluginInstance, "rulesShowHTML" ), 1 );
1530 +
1531 + add_filter('pre_get_posts', array( &$timedContentPluginInstance, "timedContentPreGetPosts") );
1127 1532 }
1128 1533 ?>