PluginProbe
Timed Content / 2.3
Timed Content v2.3
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
timed-content / timed-content.php

timed-content.php in Timed Content 2.3, at timed-content.php

1,306 lines 71.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Timed Content
4 Text Domain: timed-content
5 Domain Path: /lang
6 Plugin URI: http://wordpress.org/plugins/timed-content/
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.
8 Author: K. Tough
9 Version: 2.3
10 Author URI: http://wordpress.org/plugins/timed-content/
11 */
12 if ( !class_exists( "timedContentPlugin" ) ) {
13
14 define( "TIMED_CONTENT_VERSION", "2.3" );
15 define( "TIMED_CONTENT_PLUGIN_URL", plugins_url() . '/timed-content' );
16 define( "TIMED_CONTENT_CLIENT_TAG", "timed-content-client" );
17 define( "TIMED_CONTENT_SERVER_TAG", "timed-content-server" );
18 define( "TIMED_CONTENT_RULE_TAG", "timed-content-rule" );
19 define( "TIMED_CONTENT_ZERO_TIME", "1970-Jan-01 00:00:00 +000" ); // Start of Unix Epoch
20 define( "TIMED_CONTENT_END_TIME", "2038-Jan-19 03:14:07 +000" ); // End of Unix Epoch
21 define( "TIMED_CONTENT_RULE_TYPE", "timed_content_rule" );
22 define( "TIMED_CONTENT_RULE_POSTMETA_PREFIX", TIMED_CONTENT_RULE_TYPE . "_" );
23 define( "TIMED_CONTENT_CSS", TIMED_CONTENT_PLUGIN_URL . "/css/timed-content.css" );
24 define( "TIMED_CONTENT_CSS_DASHICONS", TIMED_CONTENT_PLUGIN_URL . "/css/ca-aliencyborg-dashicons/style.css" );
25 // Required for styling the jQuery UI Datepicker and jQuery UI Timepicker
26 define( "TIMED_CONTENT_JQUERY_UI_CSS", TIMED_CONTENT_PLUGIN_URL . "/css/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" );
27 define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS", TIMED_CONTENT_PLUGIN_URL . "/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.js" );
28 define( "TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS", TIMED_CONTENT_PLUGIN_URL . "/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.css" );
29
30
31 /**
32 * Class timedContentPlugin
33 *
34 * Class that contains all of the functions required to run the plugin. This cuts down on
35 * the possibility of name collisions with other plugins.
36 */
37 class timedContentPlugin {
38
39 function timedContentPlugin() {
40 //constructor
41
42 }
43
44 /**
45 * Creates the Timed Content Rule post type and registers it with Wordpress
46 *
47 */
48 function timedContentRuleTypeInit()
49 {
50 $labels = array(
51 'name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' ),
52 'singular_name' => _x( 'Timed Content Rule', 'post type singular name', 'timed-content' ),
53 'add_new' => _x( 'Add New', 'Menu item/button label on Timed Content Rules admin page', 'timed-content' ),
54 'add_new_item' => __( 'Add New Timed Content Rule', 'timed-content' ),
55 'edit_item' => __( 'Edit Timed Content Rule', 'timed-content' ),
56 'new_item' => __( 'New Timed Content Rule', 'timed-content' ),
57 'view_item' => __( 'View Timed Content Rule', 'timed-content' ),
58 'search_items' => __( 'Search Timed Content Rules', 'timed-content' ),
59 'not_found' => __( 'No Timed Content Rules found', 'timed-content' ),
60 'not_found_in_trash' => __( 'No Timed Content Rules found in Trash', 'timed-content' ),
61 'parent_item_colon' => '',
62 'menu_name' => _x( 'Timed Content Rules', 'post type general name', 'timed-content' )
63 );
64 $args = array(
65 'labels' => $labels,
66 'description' => __( 'Create regular schedules to show or hide selected content in a Page or Post.', 'timed-content' ),
67 'public' => false,
68 'publicly_queryable' => false,
69 'exclude_from_search' => false,
70 'show_ui' => true,
71 'show_in_menu' => true,
72 'show_in_nav_menus' => true,
73 'show_in_admin_bar' => true,
74 'query_var' => false,
75 'rewrite' => false,
76 'capability_type' => 'post',
77 'has_archive' => false,
78 'hierarchical' => false,
79 'menu_position' => 5,
80 'supports' => array( 'title' )
81 );
82 register_post_type( TIMED_CONTENT_RULE_TYPE, $args );
83 }
84
85
86 /**
87 * Filter to customize CRUD messages for Timed Content Rules
88 *
89 * @param array $messages Array of currently defined messages for post types
90 * @return mixed Array of messages with appropriate messages for Timed Content Rules added in
91 */
92 function timedContentRuleUpdatedMessages( $messages ) {
93 global $post;
94
95 /* translators: date and time format to activate rule. http://ca2.php.net/manual/en/function.date.php*/
96 $post_date = date_i18n( __( 'M j, Y @ G:i', 'timed-content' ), strtotime( $post->post_date ) );
97
98 $messages[TIMED_CONTENT_RULE_TYPE] = array(
99 0 => '', // Unused. Messages start at index 1.
100 1 => __( 'Timed Content Rule updated.', 'timed-content' ),
101 2 => __( 'Custom field updated.', 'timed-content' ),
102 3 => __( 'Custom field deleted.', 'timed-content' ),
103 4 => __( 'Timed Content Rule updated.', 'timed-content' ),
104 /* translators: %s: date and time of the revision */
105 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Timed Content Rule restored to revision from %s', 'timed-content' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
106 6 => __( 'Timed Content Rule published.', 'timed-content' ),
107 7 => __( 'Timed Content Rule saved.', 'timed-content' ),
108 8 => __( 'Timed Content Rule submitted.', 'timed-content' ),
109 /* translators: %s: date and time to activate rule. */
110 9 => sprintf( __( 'Timed Content Rule scheduled for: %s.' , 'timed-content' ), "<strong>" . $post_date . "</strong>" ),
111 10 => __( 'Timed Content Rule draft updated.', 'timed-content' )
112 );
113
114 return $messages;
115 }
116
117 function __datetimeToEnglish( $date, $time = "" ) {
118 $months = array( "January",
119 "February",
120 "March",
121 "April",
122 "May",
123 "June",
124 "July",
125 "August",
126 "September",
127 "October",
128 "November",
129 "December" );
130 $monthsI18N = array( __( "January", 'timed-content' ),
131 __( "February", 'timed-content' ),
132 __( "March", 'timed-content' ),
133 __( "April", 'timed-content' ),
134 __( "May", 'timed-content' ),
135 __( "June", 'timed-content' ),
136 __( "July", 'timed-content' ),
137 __( "August", 'timed-content' ),
138 __( "September", 'timed-content' ),
139 __( "October", 'timed-content' ),
140 __( "November", 'timed-content' ),
141 __( "December", 'timed-content' ) );
142 $english_date = str_replace( $monthsI18N, $months, $date );
143 return $english_date . " " . $time;
144 }
145
146 /**
147 * Advances a date/time by a set number of days
148 *
149 * @param int $current UNIX timestamp of the date/time before incrementing
150 * @param int $interval_multiplier Number of days to advance
151 * @return int Unix timestamp of the new date/time
152 */
153 function __getNextDay( $current, $interval_multiplier ) {
154 return strtotime( $interval_multiplier . " day", $current );
155 }
156
157 /**
158 * Advances a date/time by a set number of hours
159 *
160 * @param int $current UNIX timestamp of the date/time before incrementing
161 * @param int $interval_multiplier Number of hours to advance
162 * @return int Unix timestamp of the new date/time
163 */
164 function __getNextHour( $current, $interval_multiplier ) {
165 return strtotime( $interval_multiplier . " hour", $current );
166 }
167
168 /**
169 * Advances a date/time by a set number of weeks
170 *
171 * Advances a date/time by a set number of weeks. If given an array of days of the week, this function will
172 * advance the date/time to the next day in that array in the jumped-to week. Use this function if you're
173 * repeating an action on specific days of the week (i.e., on Weekdays, Tuesdays and Thursdays, etc.).
174 *
175 * @param int $current UNIX timestamp of the date/time before incrementing
176 * @param int $interval_multiplier Number of weeks to advance
177 * @param array $days Array of integers symbolizing the days of the week to
178 * repeat on (0 - Sunday, 1 - Monday, ..., 6 - Saturday).
179 * @return int Unix timestamp of the new date/time
180 */
181 function __getNextWeek( $current, $interval_multiplier, $days = array() ) {
182 // If $days is empty, advance $interval_multiplier weeks from $current and return the timestamp
183 if ( empty( $days ) ) return strtotime( $interval_multiplier . " week", $current );
184
185 // Otherwise, set up an array combining the days of the week to repeat on and the current day
186 // (keys and values of the array will be the same, and the array is sorted)
187 $currentDayOfWeekIndex = date( "w", $current );
188 $days = array_merge( array( $currentDayOfWeekIndex ), $days );
189 $days = array_unique( $days );
190 $days = array_values( $days );
191 sort( $days );
192 $daysOfWeek = array_combine( $days, $days );
193
194 // If the current day is the last one of the days of the week to repeat on, jump ahead to
195 // the next week to be repeating on and get the earliest day in the array
196 if ( $currentDayOfWeekIndex == max( $daysOfWeek ) )
197 $pattern = ( ( 7 - $currentDayOfWeekIndex ) + ( 7 * ( $interval_multiplier - 1 ) ) + ( min( array_keys( $daysOfWeek ) ) ) ) . " day";
198 // Otherwise, cycle through the array until we find the next day to repeat on
199 else {
200 $nextDayOfWeekIndex = $currentDayOfWeekIndex;
201 do {} while ( !isset( $daysOfWeek[++$nextDayOfWeekIndex] ) );
202 $pattern = ( $nextDayOfWeekIndex - $currentDayOfWeekIndex ) . " day";
203 }
204 return strtotime( $pattern, $current );
205 }
206
207 /**
208 * Advances a date/time by a set number of months
209 *
210 * Advances a date/time by a set number of months. When the date/time of the first active period lies
211 * on the 29th, 30th, or 31st of the month, this function will return a date/time on the the last day
212 * of the month for those months not containing those days.
213 *
214 * @param int $current UNIX timestamp of the date/time before incrementing
215 * @param int $start UNIX timestamp of the first active period's date/time
216 * @param int $interval_multiplier Number of months to advance
217 * @return int Unix timestamp of the new date/time
218 */
219 function __getNextMonth( $current, $start, $interval_multiplier ) {
220
221 // For most days in the month, it's pretty easy. Get the day of month of the starting date.
222 $startDay = date( "j", $start );
223
224 // If it's before or on the 28th, just jump the number of months and be done with it.
225 if ( $startDay <= 28 )
226 return strtotime( $interval_multiplier . " month", $current );
227
228 // If it's on the 29th, 30th, or 31st, it gets tricky. Some months don't have those days - so on those
229 // months we need to repeat on the last day of the month instead, but we also need to jump back to the
230 // correct day the following month. Let's say we want to repeat something on the 31st every month: this
231 // is what we expect to see for a pattern:
232 //
233 // .
234 // .
235 // .
236 // December 31st
237 // January 31st
238 // February 28th
239 // March 31st
240 // April 30th
241 // .
242 // .
243 // .
244 //
245 // Unfortunately, PHP relative date handling isn't that smart (add "+1 month" to January 31st, and you
246 // end up in March), so we'll have to figure it out ourselves by figuring out how many days to jump instead.
247
248 // We'll need to calculate this for each interval and return the timestamp after the last jump.
249 $temp_current = $current;
250 for ( $i = 0; $i < $interval_multiplier; $i++ ) {
251 // The pattern for jumping will be different in each interval.
252 /** @noinspection PhpUnusedLocalVariableInspection */
253 $temp_pattern = "";
254
255 // Get the month number of the current date.
256 //$currentMonth = date( "n", $temp_current );
257
258 // Get the number of days in the month of the current date.
259 $lastDayThisMonth = date( "t", strtotime( "this month", $temp_current ) );
260
261 // Get the number of days for the next month relative to the current date .
262 // Subtract 3 days from the next month to counter known month skipping bugs in PHP's relative date
263 // handling, that being the difference between the shortest possible month (non-leap February - 28 days)
264 // and the longest (Jan., Mar., May, Jul., Aug., Oct., Dec. - 31 days). This may be fixed in PHP 5.3.x
265 // but this should be backwards-compatible anyway.
266 $lastDayNextMonth = date( "t", strtotime( "-3 day next month", $temp_current ) );
267
268 // If the current month is longer than next month, follow this block
269 if ( $lastDayThisMonth > $lastDayNextMonth ) {
270 // If we're repeating on the last day of this month, jump the number of days next month
271 if ( $startDay == $lastDayThisMonth )
272 $temp_pattern = $lastDayNextMonth . " days";
273 // If the start day doesn't exist in the next month (i.e., no "31st" in June), jump the
274 // number of days next month plus the difference between the start day and the number of days this month
275 elseif ( $startDay > $lastDayNextMonth )
276 $temp_pattern = ( $lastDayThisMonth + $lastDayNextMonth - $startDay ). " days";
277 // Otherwise, jump ahead the number of days in this month
278 else
279 $temp_pattern = $lastDayThisMonth . " days";
280 }
281 // Or, if the current month is shorter than next month
282 elseif ( $lastDayThisMonth < $lastDayNextMonth ) {
283 // If the start day doesn't exist in this month (i.e., no "31st" in June), jump the
284 // number of days next month plus the difference between the start day and the number of days this month
285 if ( $startDay >= $lastDayThisMonth )
286 $temp_pattern = $startDay . " days";
287 // Otherwise, jump ahead the number of days in this month
288 else
289 $temp_pattern = $lastDayThisMonth . " days";
290 }
291 // If the current month and next month are equally long, jumping by "1 month" is fine
292 else
293 $temp_pattern = "1 month";
294
295 $temp_current = strtotime( $temp_pattern, $temp_current );
296 }
297 return $temp_current;
298
299 }
300
301 /**
302 * Advances a date/time to the 'n'th weekday of the next month (eg., first Wednesday, third Monday, last Friday, etc.).
303 *
304 * NB: if $ordinal is set to '4' and $day is set to '7', it wil return the last day of the month.
305 *
306 * @param int $current UNIX timestamp of the date/time before incrementing
307 * @param int $ordinal Integer symbolizing the ordinal (0 - first, 1 - second, 2 - third, 3 - fourth, 4 - last)
308 * @param int $day integers symbolizing the days of the week to
309 * repeat on (0 - Sunday, 1 - Monday, ..., 6 - Saturday, 7 - day).
310 * @return int Unix timestamp of the new date/time
311 */
312 function __getNthWeekdayOfMonth( $current, $ordinal, $day ) {
313
314 // First, get the month/year we need to work with
315 $the_month = date( "F", $current );
316 $the_year = date( "Y", $current );
317 $lastDayThisMonth = date( "t", $current );
318
319 // Get the time for the $current timestamp
320 $current_time = date( "g:i A", $current );
321 $the_day = "";
322
323 if ( $day == 7 ) { // If $day is "day of the month", get the day of month based on the ordinal
324 switch ( $ordinal ) {
325 case 0 : $the_day = "1"; break; // First day of the month //
326 case 1 : $the_day = "2"; break; // Second day of the month //
327 case 2 : $the_day = "3"; break; // Third day of the month //
328 case 3 : $the_day = "4"; break; // Fourth day of the month //
329 case 4 : $the_day = $lastDayThisMonth; break; // Last day of the month //
330 default : $the_day = "1"; break;
331 }
332 } else { // If $day is one of the days of the week...
333 $day_range = array();
334 switch ( $ordinal ) { // ...get a 7-day range based on the ordinal...
335 case 0 : $day_range = range( 1, 7 ); break; // First 7 days of the month //
336 case 1 : $day_range = range( 8, 14 ); break; // Second 7 days of the month //
337 case 2 : $day_range = range( 15, 21 ); break; // Third 7 days of the month //
338 case 3 : $day_range = range( 22, 28 ); break; // Fourth 7 days of the month //
339 case 4 : $day_range = range( $lastDayThisMonth - 6, $lastDayThisMonth ); break; // Last 7 days of the month //
340 default : $day_range = range( 1, 7 ); break;
341 }
342 foreach ( $day_range as $a_day ) { // ...and find the matching weekday in that range.
343 if ( $day == date( "w", strtotime( $the_month . " " . $a_day . ", " . $the_year ) ) ) {
344 $the_day = $a_day;
345 break;
346 }
347 }
348 }
349
350 // Build the date/time string for the correct day and return its timestamp
351 $pattern = $the_month . " " . $the_day . ", " . $the_year . ", " . $current_time;
352 return strtotime( $pattern );
353
354 }
355
356 /**
357 * Advances a date/time by a set number of years
358 *
359 * @param int $current UNIX timestamp of the date/time before incrementing
360 * @param int $interval_multiplier Number of years to advance
361 * @return int Unix timestamp of the new date/time
362 */
363 function __getNextYear( $current, $interval_multiplier ) {
364 return strtotime( $interval_multiplier . " year", $current );
365 }
366
367 /**
368 * Validates the various Timed Content Rule parameters and returns a series of error messages.
369 *
370 * @param $args Array of Timed Content Rule parameters
371 * @return array Array of error messages
372 */
373 function __validate( $args ) {
374 $errors = array();
375
376 $instance_start = strtotime( $this->__datetimeToEnglish( $args['instance_start']['date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] );
377 $instance_end = strtotime( $this->__datetimeToEnglish( $args['instance_end']['date'], $args['instance_end']['time'] ) . ' ' . $args['timezone'] );
378 $end_date = strtotime( $this->__datetimeToEnglish( $args['end_date'], $args['instance_start']['time'] ) . ' ' . $args['timezone'] );
379
380 if ( $args['instance_start']['date'] == "" )
381 $errors[] = __( "Date in Starting Date/Time must not be empty.", 'timed-content' );
382 if ( $args['instance_start']['time'] == "" )
383 $errors[] = __( "Time in Starting Date/Time must not be empty.", 'timed-content' );
384 if ( $args['instance_end']['date'] == "" )
385 $errors[] = __( "Date in Ending Date/Time must not be empty.", 'timed-content' );
386 if ( $args['instance_end']['time'] == "" )
387 $errors[] = __( "Time in Ending Date/Time must not be empty.", 'timed-content' );
388 if ( $args['interval_multiplier'] == "" )
389 $errors[] = __( "Repeat How Often? must not be empty.", 'timed-content' );
390 if ( !is_numeric( $args['interval_multiplier'] ) )
391 $errors[] = __( "Repeat How Often? must be a number.", 'timed-content' );
392 if ( ( $args['num_repeat'] == "" ) && ( $args['recurr_type'] == "recurrence_duration_num_repeat" ) )
393 $errors[] = __( "Repeat How Many Times? must not be empty.", 'timed-content' );
394 if ( ( !is_numeric( $args['num_repeat'] ) ) && ( $args['recurr_type'] == "recurrence_duration_num_repeat" ) )
395 $errors[] = __( "Repeat How Many Times? must be a number.", 'timed-content' );
396 if ( ( $args['end_date'] == "" ) && ( $args['recurr_type'] == "recurrence_duration_end_date" ) )
397 $errors[] = __( "End Date must not be empty.", 'timed-content' );
398 if ( false === $instance_start )
399 $errors[] = __( "Starting Date/Time must be valid.", 'timed-content' );
400 if ( false === $instance_end )
401 $errors[] = __( "Ending Date/Time must be valid.", 'timed-content' );
402 if ( $instance_start > $instance_end )
403 $errors[] = __( "Starting Date/Time must be before Ending Date/Time.", 'timed-content' );
404 if ( ( $instance_end > $end_date ) && ( $args['recurr_type'] == "recurrence_duration_end_date" ) )
405 $errors[] = __( "End Date must be after Ending Date/Time.", 'timed-content' );
406
407 return $errors;
408 }
409
410 /**
411 * Calculates the active periods for a Timed Content Rule
412 *
413 * @param $args Array of Timed Content Rule parameters
414 * @return array Array of active periods. Each value in the array describes an active period as
415 * an array itself with "start" and "end" keys and values that are either UNIX
416 * timestamps or human-readable dates, based on whether $args['human_readable']
417 * is set to true or false.
418 */
419 function __getRulePeriods( $args ) {
420 $active_periods = array();
421 $period_count = 0;
422
423 $human_readable = $args['human_readable'];
424 $freq = $args['freq'];
425 $timezone = $args['timezone'];
426 $recurr_type = $args['recurr_type'];
427 $num_repeat = intval( $args['num_repeat'] );
428 $end_date = $args['end_date'];
429 $days_of_week = $args['days_of_week'];
430 $interval_multiplier = $args['interval_multiplier'];
431 $instance_start_date = $args['instance_start']['date'];
432 $instance_start_time = $args['instance_start']['time'];
433 $instance_end_date = $args['instance_end']['date'];
434 $instance_end_time = $args['instance_end']['time'];
435 $monthly_pattern = $args['monthly_pattern'];
436 $monthly_pattern_ord = $args['monthly_pattern_ord'];
437 $monthly_pattern_day = $args['monthly_pattern_day'];
438 $exceptions_dates = $args['exceptions_dates'];
439 //print_r($days_of_week);
440
441 $temp_tz = date_default_timezone_get();
442 date_default_timezone_set( $timezone );
443 $right_now_t = time();
444
445 $instance_start = strtotime( $this->__datetimeToEnglish( $instance_start_date, $instance_start_time ) . " " . $timezone ); // Beginning of first occurrence
446 $instance_end = strtotime( $this->__datetimeToEnglish( $instance_end_date, $instance_end_time ) . " " . $timezone ); // End of first occurrence
447 $current = $instance_start;
448 $end_current = $instance_end;
449
450 if ( $recurr_type == "recurrence_duration_num_repeat" )
451 $last_occurrence_start = strtotime( TIMED_CONTENT_END_TIME );
452 else
453 $last_occurrence_start = strtotime( $this->__datetimeToEnglish( $end_date, $instance_start_time ) . " " . $timezone );
454
455 if ( $human_readable == true ) {
456 $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current );
457 $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current );
458 } else {
459 $active_periods[$period_count]["start"] = $current;
460 $active_periods[$period_count]["end"] = $end_current;
461 }
462 if ( $right_now_t < $current ) {
463 $active_periods[$period_count]["status"] = "upcoming";
464 $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
465 } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
466 $active_periods[$period_count]["status"] = "active";
467 $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
468 } else {
469 $active_periods[$period_count]["status"] = "expired";
470 $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
471 }
472 $period_count++;
473
474 if ( $recurr_type == "recurrence_duration_end_date" )
475 $loop_test = "return ( \$current < \$last_occurrence_start );";
476 else
477 $loop_test = "return ( \$period_count <= \$num_repeat );";
478
479 while ( eval ( $loop_test ) ) {
480 $temp_current = "";
481 if ( $freq == 0 )
482 $current = $this->__getNextHour( $current, $interval_multiplier );
483 elseif ( $freq == 1 )
484 $current = $this->__getNextDay( $current, $interval_multiplier );
485 elseif ( $freq == 2 )
486 $current = $this->__getNextWeek( $current, $interval_multiplier, $days_of_week );
487 elseif ( $freq == 3 ) {
488 $current = $this->__getNextMonth( $current, $instance_start, $interval_multiplier );
489 $temp_current = $current;
490 if ( $monthly_pattern == "yes" )
491 $current = $this->__getNthWeekdayOfMonth( $current, $monthly_pattern_ord, $monthly_pattern_day );
492 else
493 $current = $temp_current;
494 } elseif ( $freq == 4 )
495 $current = $this->__getNextYear( $current, $interval_multiplier );
496
497 $exception_period = false;
498 foreach ( $exceptions_dates as $date ) {
499 if ( ( $current >= $date ) && ( $current < strtotime( "+1 day", $date ) ) ) {
500 $exception_period = true;
501 break;
502 }
503 }
504
505 if ( ( eval ( $loop_test ) ) && ( !($exception_period) ) ) {
506 $end_current = $current + ( $instance_end - $instance_start );
507 if ( $human_readable == true ) {
508 $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current );
509 $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current );
510 } else {
511 $active_periods[$period_count]["start"] = $current;
512 $active_periods[$period_count]["end"] = $end_current;
513 }
514 if ( $right_now_t < $current ) {
515 $active_periods[$period_count]["status"] = "upcoming";
516 $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
517 } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
518 $active_periods[$period_count]["status"] = "active";
519 $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
520 } else {
521 $active_periods[$period_count]["status"] = "expired";
522 $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
523 }
524 if ( !($exception_period) )
525 $period_count++;
526 }
527
528 }
529 date_default_timezone_set( $temp_tz );
530 return $active_periods;
531 }
532
533 /**
534 * Wrapper for calling timedContentPlugin::__getRulePeriods() by the ID of a Timed Content Rule
535 *
536 * @param int $ID ID of the Timed Content Rule
537 * @param bool $human_readable If true, the active periods are returned as a human-readable date/time
538 * as defined by the constant TIMED_CONTENT_DT_FORMAT; otherwise, they are
539 * returned as UNIX timestamps.
540 * @return array Array of active periods
541 */
542 function getRulePeriodsById( $ID, $human_readable = false ) {
543 if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $ID ) )
544 return array();
545
546 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
547 $args = array();
548
549 $args['human_readable'] = (bool) $human_readable;
550 $args['freq'] = get_post_meta( $ID, $prefix . 'frequency', true );
551 $args['timezone'] = get_post_meta( $ID, $prefix . 'timezone', true );
552 $args['recurr_type'] = get_post_meta( $ID, $prefix . 'recurrence_duration', true );
553 $args['num_repeat'] = get_post_meta( $ID, $prefix . 'recurrence_duration_num_repeat', true );
554 $args['end_date'] = get_post_meta( $ID, $prefix . 'recurrence_duration_end_date', true );
555 $args['days_of_week'] = get_post_meta( $ID, $prefix . 'weekly_days_of_week_to_repeat', true );
556 if ( $args['freq'] == 0 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'hourly_num_of_hours', true );
557 if ( $args['freq'] == 1 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'daily_num_of_days', true );
558 if ( $args['freq'] == 2 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'weekly_num_of_weeks', true );
559 if ( $args['freq'] == 3 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'monthly_num_of_months', true );
560 if ( $args['freq'] == 4 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'yearly_num_of_years', true );
561 $args['instance_start'] = get_post_meta( $ID, $prefix . 'instance_start', true );
562 $args['instance_end'] = get_post_meta( $ID, $prefix . 'instance_end', true );
563 $args['monthly_pattern'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true );
564 $args['monthly_pattern_ord'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true );
565 $args['monthly_pattern_day'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true );
566 $args['exceptions_dates'] = get_post_meta( $ID, $prefix . 'exceptions_dates', true );
567
568 return $this->__getRulePeriods( $args );
569
570 }
571
572 /**
573 * Wrapper for calling timedContentPlugin::__getRulePeriods() based on the contents of the form fields
574 * of the Add Timed Content Rule and Edit Timed Content Rule screens. Output is sent to output as JSON
575 */
576 function timedContentPluginGetRulePeriodsAjax() {
577 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
578 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
579 $args = array();
580
581 $args['human_readable'] = ( ( ( isset( $_POST[$prefix . 'human_readable'] ) ) && ( $_POST[$prefix . 'human_readable'] == 'true' ) ) ? (bool)$_POST[$prefix . 'human_readable'] : false );
582 $args['freq'] = $_POST[$prefix . 'frequency'];
583 $args['timezone'] = $_POST[$prefix . 'timezone'];
584 $args['recurr_type'] = $_POST[$prefix . 'recurrence_duration'];
585 $args['num_repeat'] = $_POST[$prefix . 'recurrence_duration_num_repeat'];
586 $args['end_date'] = $_POST[$prefix . 'recurrence_duration_end_date'];
587 $args['days_of_week'] = ( isset( $_POST[$prefix . 'weekly_days_of_week_to_repeat'] ) ? $_POST[$prefix . 'weekly_days_of_week_to_repeat'] : array() );
588 $args['interval_multiplier'] = $_POST[$prefix . 'interval_multiplier'];
589 $args['instance_start'] = $_POST[$prefix . 'instance_start'];
590 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
591 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
592 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
593 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
594 $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
595
596 $response = json_encode( $this->__getRulePeriods( $args ) );
597
598 // response output
599 header( "Content-Type: application/json" );
600 echo $response;
601 }
602 die();
603
604 }
605
606 /**
607 * Returns a human-readable description of a Timed Content Rule
608 *
609 * @param $args Array of Timed Content Rule parameters
610 * @return string
611 */
612 function __getScheduleDescription( $args ) {
613 include("lib/Arrays_Definitions.php");
614
615 $interval_multiplier = 1;
616 $desc = "";
617
618 $errors = $this->__validate( $args );
619 if ( $errors ) {
620 $messages = "<div class=\"tcr-warning\">\n";
621 $messages .= "<p class=\"heading\">" . __( "Warning!", 'timed-content' ) . "</p>\n";
622 $messages .= "<p>" . __( "Some problems have been detected. Although you can still publish this rule, it may not work the way you expect.", 'timed-content' ) . "</p>\n";
623 $messages .= "<ul>\n";
624 foreach ( $errors as $error )
625 $messages .= " <li>" . $error . "</li>\n";
626 $messages .= "</ul>\n";
627 $messages .= "<p>" . __( "Check that all of the conditions for this rule are correct, and use Show Projected Dates/Times to ensure your rule is working properly.", 'timed-content' ) . "</p>\n";
628 $messages .= "</div>\n";
629 return $messages;
630 }
631
632 if ( $args['action'] )
633 $action = __( "Show the content", 'timed-content' );
634 else
635 $action = __( "Hide the content", 'timed-content' );
636 $freq = $args['freq'];
637 $timezone = $args['timezone'];
638 $recurr_type = $args['recurr_type'];
639 $num_repeat = intval( $args['num_repeat'] );
640 $end_date = $args['end_date'];
641 $days_of_week = $args['days_of_week'];
642 $interval_multiplier = $args['interval_multiplier'];
643 $instance_start_date = $args['instance_start']['date'];
644 $instance_start_time = $args['instance_start']['time'];
645 $instance_end_date = $args['instance_end']['date'];
646 $instance_end_time = $args['instance_end']['time'];
647 $monthly_pattern = $args['monthly_pattern'];
648 $monthly_pattern_ord = $args['monthly_pattern_ord'];
649 $monthly_pattern_day = $args['monthly_pattern_day'];
650 $exceptions_dates = $args['exceptions_dates'];
651
652 $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 );
653
654 if ( $freq == 0 )
655 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every hour.', 'Repeat this action every %d hours.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
656 elseif ( $freq == 1 )
657 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every day.', 'Repeat this action every %d days.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
658 elseif ( $freq == 2 ) {
659 if ( ( $days_of_week ) && ( is_array( $days_of_week ) ) ) {
660 $days = array(); $days_list = "";
661 foreach ( $days_of_week as $v )
662 $days[] = $timed_content_rule_days_array[$v];
663 switch ( count( $days ) ) {
664 case 1: $days_list = sprintf( _x( '%1$s', 'List of one weekday', 'timed-content' ), $days[0] ); break;
665 case 2: $days_list = sprintf( _x( '%1$s and %2$s', 'List of two weekdays', 'timed-content' ), $days[0], $days[1] ); break;
666 case 3: $days_list = sprintf( _x( '%1$s, %2$s, and %3$s', 'List of three weekdays', 'timed-content' ), $days[0], $days[1], $days[2] ); break;
667 case 4: $days_list = sprintf( _x( '%1$s, %2$s, %3$s, and %4$s', 'List of four weekdays', 'timed-content' ), $days[0], $days[1], $days[2], $days[3] ); break;
668 case 5: $days_list = sprintf( _x( '%1$s, %2$s, %3$s, %4$s, and %5$s', 'List of five weekdays', 'timed-content' ), $days[0], $days[1], $days[2], $days[3], $days[4] ); break;
669 case 6: $days_list = sprintf( _x( '%1$s, %2$s, %3$s, %4$s, %5$s, and %6$s', 'List of six weekdays', 'timed-content' ), $days[0], $days[1], $days[2], $days[3], $days[4], $days[5] ); break;
670 case 7: $days_list = sprintf( _x( '%1$s, %2$s, %3$s, %4$s, %5$s, %6$s, and %7$s', 'List of all weekdays', 'timed-content' ), $days[0], $days[1], $days[2], $days[3], $days[4], $days[5], $days[6] ); break;
671 }
672 if ( $interval_multiplier == 1 )
673 $desc .= "&nbsp;" . sprintf( _x( 'Repeat this action every week on %s.', 'List the weekdays to repeat the rule when frequency is every week. %s is the list of weekdays.', 'timed-content' ), $days_list );
674 else
675 $desc .= "&nbsp;" . sprintf( _x( 'Repeat this action every %1$d weeks on %2$s.', 'List the weekdays to repeat the rule when frequency is every %1$d weeks. %2$s is the list of weekdays.', 'timed-content' ), $interval_multiplier, $days_list );
676 } else
677 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every week.', 'Repeat this action every %d weeks.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
678
679 } elseif ( $freq == 3 ) {
680 if ( $monthly_pattern == "yes" ) {
681 if ( $interval_multiplier == 1 )
682 $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] );
683 else
684 $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] );
685 } else
686 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every month.', 'Repeat this action every %d months.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
687 } elseif ( $freq == 4 )
688 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every year.', 'Repeat this action every %d years.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
689
690 if ( $recurr_type == "recurrence_duration_num_repeat" )
691 $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 );
692 elseif ( $recurr_type == "recurrence_duration_end_date" )
693 $desc .= "&nbsp;" . sprintf( __( 'This rule will be active until %s.', 'timed-content' ), $end_date );
694
695 if ( ( $exceptions_dates ) && ( is_array( $exceptions_dates ) ) ) {
696 sort( $exceptions_dates, SORT_NUMERIC );
697 $exceptions_dates = array_unique( $exceptions_dates );
698 if ( $exceptions_dates[0] == 0 )
699 array_shift( $exceptions_dates );
700 if ( !empty( $exceptions_dates ) ) {
701 $formatted_dates = array();
702 foreach ( $exceptions_dates as $a_date )
703 $formatted_dates[] = date( _x( "F j, Y" , "Date format for schedule description", 'timed-content' ), $a_date );
704 $desc .= "&nbsp;" . sprintf( __( 'This rule will be inactive on the following dates: %s.', 'timed-content' ), join( ", ", $formatted_dates ) );
705 }
706 }
707
708 $desc .= "&nbsp;" . sprintf( __( 'All times are in the %s timezone.', 'timed-content' ), $timezone );
709 return $desc;
710 }
711
712 /**
713 * Wrapper for calling timedContentPlugin::__getScheduleDescription() by the ID of a Timed Content Rule
714 *
715 * @param int $ID ID of the Timed Content Rule
716 * @return string
717 */
718 function getScheduleDescriptionById( $ID ) {
719 global $timed_content_rule_occurrence_custom_fields,
720 $timed_content_rule_pattern_custom_fields,
721 $timed_content_rule_recurrence_custom_fields,
722 $timed_content_rule_exceptions_custom_fields;
723 $defaults = array();
724
725 foreach ( $timed_content_rule_occurrence_custom_fields as $field ) {
726 $defaults[$field['name']] = $field['default'];
727 }
728 foreach ( $timed_content_rule_pattern_custom_fields as $field ) {
729 $defaults[$field['name']] = $field['default'];
730 }
731 foreach ( $timed_content_rule_recurrence_custom_fields as $field ) {
732 $defaults[$field['name']] = $field['default'];
733 }
734 foreach ( $timed_content_rule_exceptions_custom_fields as $field ) {
735 $defaults[$field['name']] = $field['default'];
736 }
737
738 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
739 $args = array();
740
741 $args['action'] = ( false === get_post_meta( $ID, $prefix . 'action', true ) ? $defaults['action'] : get_post_meta( $ID, $prefix . 'action', true ) );
742 $args['freq'] = ( false === get_post_meta( $ID, $prefix . 'frequency', true ) ? $defaults['frequency'] : get_post_meta( $ID, $prefix . 'frequency', true ) );
743 $args['timezone'] = ( false === get_post_meta( $ID, $prefix . 'timezone', true ) ? $defaults['timezone'] : get_post_meta( $ID, $prefix . 'timezone', true ) );
744 $args['recurr_type'] = ( false === get_post_meta( $ID, $prefix . 'recurrence_duration', true ) ? $defaults['recurrence_duration'] : get_post_meta( $ID, $prefix . 'recurrence_duration', true ) );
745 $args['num_repeat'] = ( false === get_post_meta( $ID, $prefix . 'recurrence_duration_num_repeat', true ) ? $defaults['recurrence_duration_num_repeat'] : get_post_meta( $ID, $prefix . 'recurrence_duration_num_repeat', true ) );
746 $args['end_date'] = ( false === get_post_meta( $ID, $prefix . 'recurrence_duration_end_date', true ) ? $defaults['recurrence_duration_end_date'] : get_post_meta( $ID, $prefix . 'recurrence_duration_end_date', true ) );
747 $args['days_of_week'] = ( false === get_post_meta( $ID, $prefix . 'weekly_days_of_week_to_repeat', true ) ? $defaults['weekly_days_of_week_to_repeat'] : get_post_meta( $ID, $prefix . 'weekly_days_of_week_to_repeat', true ) );
748 if ( $args['freq'] == 0 ) $args['interval_multiplier'] = ( false === get_post_meta( $ID, $prefix . 'hourly_num_of_hours', true ) ? $defaults['hourly_num_of_hours'] : get_post_meta( $ID, $prefix . 'hourly_num_of_hours', true ) );
749 if ( $args['freq'] == 1 ) $args['interval_multiplier'] = ( false === get_post_meta( $ID, $prefix . 'daily_num_of_days', true ) ? $defaults['daily_num_of_days'] : get_post_meta( $ID, $prefix . 'daily_num_of_days', true ) );
750 if ( $args['freq'] == 2 ) $args['interval_multiplier'] = ( false === get_post_meta( $ID, $prefix . 'weekly_num_of_weeks', true ) ? $defaults['weekly_num_of_weeks'] : get_post_meta( $ID, $prefix . 'weekly_num_of_weeks', true ) );
751 if ( $args['freq'] == 3 ) $args['interval_multiplier'] = ( false === get_post_meta( $ID, $prefix . 'monthly_num_of_months', true ) ? $defaults['monthly_num_of_months'] : get_post_meta( $ID, $prefix . 'monthly_num_of_months', true ) );
752 if ( $args['freq'] == 4 ) $args['interval_multiplier'] = ( false === get_post_meta( $ID, $prefix . 'yearly_num_of_years', true ) ? $defaults['yearly_num_of_years'] : get_post_meta( $ID, $prefix . 'yearly_num_of_years', true ) );
753 $args['instance_start'] = ( false === get_post_meta( $ID, $prefix . 'instance_start', true ) ? $defaults['instance_start'] : get_post_meta( $ID, $prefix . 'instance_start', true ) );
754 $args['instance_end'] = ( false === get_post_meta( $ID, $prefix . 'instance_end', true ) ? $defaults['instance_end'] : get_post_meta( $ID, $prefix . 'instance_end', true ) );
755 $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 ) );
756 $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 ) );
757 $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 ) );
758 $args['exceptions_dates'] = ( false === get_post_meta( $ID, $prefix . 'exceptions_dates', true ) ? $defaults['exceptions_dates'] : get_post_meta( $ID, $prefix . 'exceptions_dates', true ) );
759
760 return $this->__getScheduleDescription( $args );
761
762 }
763
764 /**
765 * Wrapper for calling timedContentPlugin::__getRulePeriods() based on the contents of the form fields
766 * of the Add Timed Content Rule and Edit Timed Content Rule screens. Output is sent to output as plain text
767 */
768 function timedContentPluginGetScheduleDescriptionAjax() {
769 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
770 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
771 $args = array();
772
773 $args['action'] = $_POST[$prefix . 'action'];
774 $args['freq'] = $_POST[$prefix . 'frequency'];
775 $args['timezone'] = $_POST[$prefix . 'timezone'];
776 $args['recurr_type'] = $_POST[$prefix . 'recurrence_duration'];
777 $args['num_repeat'] = $_POST[$prefix . 'recurrence_duration_num_repeat'];
778 $args['end_date'] = $_POST[$prefix . 'recurrence_duration_end_date'];
779 $args['days_of_week'] = ( isset( $_POST[$prefix . 'weekly_days_of_week_to_repeat'] ) ? $_POST[$prefix . 'weekly_days_of_week_to_repeat'] : array() );
780 $args['interval_multiplier'] = $_POST[$prefix . 'interval_multiplier'];
781 $args['instance_start'] = $_POST[$prefix . 'instance_start'];
782 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
783 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
784 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
785 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
786 $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
787
788 $response = $this->__getScheduleDescription( $args );
789
790 // response output
791 header( "Content-Type: text/plain" );
792 echo $response;
793 }
794 die();
795 }
796
797 /**
798 * Processes the [timed-content-client] shortcode.
799 *
800 * @param array $atts
801 * @param null $content
802 * @return string
803 */
804 function clientShowHTML( $atts, $content = null ) {
805 $show_attr = "";
806 $hide_attr = "";
807 extract( shortcode_atts( array( 'show' => '0:00:000' , 'hide' => '0:00:000' , 'display' => 'div' ), $atts ) );
808
809 // Initialize show/hide arguments
810 $s_min = 0; $s_sec = 0; $s_fade = 0;
811 $h_min = 0; $h_sec = 0; $h_fade = 0;
812 @list( $s_min, $s_sec, $s_fade ) = explode( ":", $show );
813 @list( $h_min, $h_sec, $h_fade ) = explode( ":", $hide );
814
815 if ( ( (int)$s_min + (int)$s_sec ) > 0 )
816 $show_attr = "_show_" . $s_min . "_" . $s_sec . "_" . $s_fade;
817 if ( ( (int)$h_min + (int)$h_sec ) > 0 )
818 $hide_attr = "_hide_" . $h_min . "_" . $h_sec . "_" . $h_fade;
819
820 $the_class = TIMED_CONTENT_CLIENT_TAG . $show_attr . $hide_attr ;
821 $the_tag = ( $display == "div" ? "div" : "span" );
822
823 $the_HTML = "<" . $the_tag . " class='" . $the_class . "'" . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">" . do_shortcode( $content ) . "</" . $the_tag . ">";
824
825 return $the_HTML;
826 }
827
828 /**
829 * Processes the [timed-content-server] shortcode.
830 *
831 * @param array $atts
832 * @param null $content
833 * @return string
834 */
835 function serverShowHTML( $atts, $content = null ) {
836 global $post;
837 extract( shortcode_atts( array( 'show' => TIMED_CONTENT_ZERO_TIME , 'hide' => TIMED_CONTENT_END_TIME, 'debug' => 'false' ), $atts ) );
838 $show_t = strtotime( $this->__datetimeToEnglish( $show ) );
839 $hide_t = strtotime( $this->__datetimeToEnglish( $hide ) );
840 $right_now_t = time();
841 $debug_message = "";
842
843 if ( ( $debug == "true" ) && ( current_user_can( "edit_post", $post->post_id ) ) ) {
844 $temp_tz = date_default_timezone_get();
845 date_default_timezone_set( get_option( 'timezone_string' ) );
846
847 $right_now = date_i18n( TIMED_CONTENT_DT_FORMAT, $right_now_t );
848
849 if ( $show_t > $right_now_t )
850 $show_diff_str = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $show_t, $right_now_t ) );
851 else
852 $show_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $show_t, $right_now_t ) );
853 if ( $hide_t > $right_now_t )
854 $hide_diff_str = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) );
855 else
856 $hide_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) );
857
858 $debug_message = "<div class=\"tcr-warning\">\n";
859 $debug_message .= "<p class=\"heading\">" . _x( "Notice", "Noun", 'timed-content' ) . "</p>\n";
860 $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";
861
862 if ( $show == TIMED_CONTENT_ZERO_TIME )
863 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ), "<code>show</code>" ) . "</p>\n";
864 else
865 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>show</code>" ) . ": " . $show . ",<br />\n "
866 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $show_t )
867 . " (" . $show_diff_str . ")</p>\n";
868
869 if ( $hide == TIMED_CONTENT_END_TIME )
870 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.' , 'timed-content' ), "<code>hide</code>" ) . "</p>\n";
871 else
872 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>hide</code>" ) . ": " . $hide . ",<br />\n"
873 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $hide_t )
874 . " (" . $hide_diff_str . ").</p>\n";
875
876 $debug_message .= "<p>" . __( 'Current Date/Time:', 'timed-content') . "&nbsp;" . $right_now . "</p>\n";
877 $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content') . "&nbsp;" . $content . "</p>\n";
878
879 $debug_message .= "</div>\n";
880
881 date_default_timezone_set( $temp_tz );
882 }
883
884 if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) )
885 return $debug_message . do_shortcode( $content ) . "\n";
886 else
887 return $debug_message . "\n";
888
889 }
890
891 /**
892 * Processes the [timed-content-rule] shortcode.
893 *
894 * @param array $atts
895 * @param null $content
896 * @return string
897 */
898 function rulesShowHTML( $atts, $content = null ) {
899 extract( shortcode_atts( array( 'id' => '0' ), $atts ) );
900 if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $id ) ) return;
901
902 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
903 $right_now_t = time();
904 $rule_is_active = false;
905
906 $active_periods = $this->getRulePeriodsById( $id, false );
907 $action_is_show = (bool) get_post_meta( $id, $prefix . 'action', true );
908
909 foreach ( $active_periods as $period ) {
910 if ( ( $period['start'] <= $right_now_t ) && ( $right_now_t <= $period['end'] ) ) {
911 $rule_is_active = true;
912 break;
913 }
914 }
915
916 if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) )
917 return do_shortcode( $content );
918 else
919 return "";
920 }
921
922 /**
923 * Enqueues the JavaScript code necessary for the functionality of the [timed-content-client] shortcode.
924 */
925 function addHeaderCode() {
926 if ( ! is_admin() ) {
927 wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
928 wp_enqueue_script( 'timed-content_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
929 }
930 }
931
932 /**
933 * 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.
934 */
935 function addPostTypeIcons37() {
936 ?>
937 <style type="text/css" media="screen">
938 #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> .wp-menu-image {
939 background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_icon.png) no-repeat 6px 6px !important;
940 }
941 #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 {
942 background-position: -22px 6px !important;
943 }
944 #icon-edit.icon32-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> {background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_32x32.png) no-repeat;}
945 </style>
946 <?php
947 }
948
949 /**
950 * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens
951 * and the TinyMCE editor. Echo'd to output.
952 */
953 function addPostTypeIcons() {
954 wp_enqueue_style( 'ca-aliencyborg-dashicons', TIMED_CONTENT_CSS_DASHICONS, false, TIMED_CONTENT_VERSION );
955 ?>
956 <style type="text/css" media="screen">
957 #adminmenu #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.menu-icon-post div.wp-menu-image:before {
958 font-family: 'ca-aliencyborg-dashicons' !important;
959 content: '\e601';
960 }
961 #dashboard_right_now li.<?php echo TIMED_CONTENT_RULE_TYPE; ?>-count a:before {
962 font-family: 'ca-aliencyborg-dashicons' !important;
963 content: '\e601';
964 }
965 .mce-i-timed_content:before {
966 font: 400 24px/1 'ca-aliencyborg-dashicons' !important;
967 padding: 0;
968 vertical-align: top;
969 margin-left: -2px;
970 padding-right: 2px;
971 content: '\e601';
972 }
973 </style>
974 <?php
975 }
976
977 /**
978 * Enqueues the JavaScript code necessary for the functionality of the Timed Content Rules management screens.
979 */
980 function addAdminHeaderCode() {
981 if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == TIMED_CONTENT_RULE_TYPE )
982 || ( isset( $post_type ) && $post_type == TIMED_CONTENT_RULE_TYPE )
983 || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == TIMED_CONTENT_RULE_TYPE ) ) {
984 wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
985 // Enqueue the JavaScript file that manages the meta box UI
986 wp_enqueue_script( 'timed-content-admin_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
987 // Enqueue the JavaScript file that makes AJAX requests
988 wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'jquery-ui-dialog' ), TIMED_CONTENT_VERSION );
989
990 // Set up local variables used in the Admin JavaScript file
991 wp_localize_script( 'timed-content-admin_js', 'timedContentRuleAdmin', array(
992 'no_exceptions_label' => __( "- No exceptions set -", 'timed-content' ) ) );
993
994 // Set up local variables used in the AJAX JavaScript file
995 wp_localize_script( 'timed-content-ajax_js', 'timedContentRuleAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
996 'start_label' => _x( 'Start', 'Scheduled Dates/Times dialog - Beginning of active period table header', 'timed-content' ),
997 'end_label' => _x( 'End', 'Scheduled Dates/Times dialog - End of active period table header', 'timed-content' ),
998 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ),
999 'dialog_width' => 800,
1000 'dialog_height' => 500,
1001 'close_label' => _x( 'Close', 'Scheduled Dates/Times dialog - Close button HTML label', 'timed-content' ),
1002 'loadingimg' => TIMED_CONTENT_PLUGIN_URL . '/img/wpspin.gif',
1003 'error' => __( "Error", 'timed-content' ),
1004 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) );
1005 }
1006 }
1007
1008 /**
1009 * Initializes the TinyMCE plugin bundled with this Wordpress plugin
1010 */
1011 function initTinyMCEPlugin() {
1012 if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) )
1013 return;
1014
1015 // Add only in Rich Editor mode
1016 if ( get_user_option( 'rich_editing' ) == 'true' ) {
1017 add_filter( "mce_external_plugins", array( &$this, "addTimedContentTinyMCEPlugin" ) );
1018 add_filter( "mce_buttons", array( &$this, "registerTinyMCEButton" ) );
1019 }
1020 }
1021
1022 /**
1023 * Sets up variables to use in the TinyMCE plugin's plugin.js.
1024 *
1025 */
1026 function setTinyMCEPluginVars() {
1027 global $wp_version;
1028 if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) )
1029 return;
1030
1031 // Add only in Rich Editor mode
1032 if ( get_user_option( 'rich_editing' ) == 'true' ) {
1033 if ( version_compare( $wp_version, "3.8", "<" ) )
1034 $image = "/clock.gif";
1035 else
1036 $image = "";
1037 wp_enqueue_script( 'timed-content-admin_tinymce_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin-tinymce.js', array(), TIMED_CONTENT_VERSION );
1038 wp_localize_script( 'timed-content-admin_tinymce_js',
1039 'timedContentAdminTinyMCEOptionsVars',
1040 array( 'version' => TIMED_CONTENT_VERSION,
1041 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ),
1042 'image' => $image ) );
1043 }
1044 }
1045
1046 /**
1047 * Sets up the button for the associated TinyMCE plugin for use in the editor menubar.
1048 * @param array $buttons Array of menu buttons already registered with TinyMCE
1049 * @return array The array of TinyMCE menu buttons with ours now loaded in as well
1050 */
1051 function registerTinyMCEButton( $buttons ) {
1052 array_push( $buttons, "|", "timed_content" );
1053 return $buttons;
1054 }
1055
1056 /**
1057 * Loads the associated TinyMCE plugin into TinyMCE's plugin array
1058 *
1059 * @param array $plugin_array Array of plugins already registered with TinyMCE
1060 * @return array The array of TinyMCE plugins with ours now loaded in as well
1061 */
1062 function addTimedContentTinyMCEPlugin( $plugin_array ) {
1063 $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/plugin.js";
1064 return $plugin_array;
1065 }
1066
1067 /**
1068 * Generates JavaScript array of objects describing Timed Content Rules. Used in the dialog box created by
1069 * timedContentPlugin::timedContentPluginGetTinyMCEDialog().
1070 *
1071 * @return string
1072 */
1073 function __getRulesJS() {
1074 $the_js = "var rules = [\n";
1075 $args = array( 'post_type' => TIMED_CONTENT_RULE_TYPE, 'posts_per_page' => -1, 'post_status' => 'publish' );
1076 $the_rules = get_posts( $args );
1077 foreach ( $the_rules as $rule ) {
1078 $desc = $this->getScheduleDescriptionById( $rule->ID );
1079 // Only add a rule if there's no errors or warnings
1080 if ( false === strpos( $desc, "tcr-warning" ) )
1081 $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";
1082 }
1083 if ( empty( $the_rules ) )
1084 $the_js .= " { 'ID': -999, 'title': ' ---- ', 'desc': '" . __( 'No Timed Content Rules found', 'timed-content' ) . "' }\n";
1085
1086 $the_js .= "];\n";
1087 return $the_js;
1088 }
1089 /**
1090 * Display a dialog box for this plugin's associated TinyMCE plugin. Called from TinyMCE via AJAX.
1091 *
1092 */
1093 function timedContentPluginGetTinyMCEDialog() {
1094 include( "lib/jquery-ui-datetime-i18n.php" );
1095
1096 wp_enqueue_style( 'timed-content-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS, false, TIMED_CONTENT_VERSION );
1097 wp_enqueue_script( 'jquery-ui-datepicker' );
1098 if( !( wp_script_is( 'timed-content-jquery-ui-datepicker-i18n-js', 'registered' ) ) ) {
1099 wp_register_script( 'timed-content-jquery-ui-datepicker-i18n-js', TIMED_CONTENT_PLUGIN_URL . "/js/timed-content-datepicker-i18n.js", array( 'jquery', 'jquery-ui-datepicker' ), TIMED_CONTENT_VERSION );
1100 wp_enqueue_script( 'timed-content-jquery-ui-datepicker-i18n-js' );
1101 wp_localize_script( 'timed-content-jquery-ui-datepicker-i18n-js', 'TimedContentJQDatepickerI18n', $jquery_ui_datetime_datepicker_i18n );
1102 }
1103 wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS, array( TIMED_CONTENT_JQUERY_UI_CSS ), TIMED_CONTENT_VERSION );
1104 wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' );
1105 wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array( 'jquery', 'jquery-ui-datepicker' ), TIMED_CONTENT_VERSION );
1106 wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' );
1107 if( !( wp_script_is( 'timed-content-jquery-ui-timepicker-i18n-js', 'registered' ) ) ) {
1108 wp_register_script( 'timed-content-jquery-ui-timepicker-i18n-js', TIMED_CONTENT_PLUGIN_URL . "/js/timed-content-timepicker-i18n.js", array( 'jquery', 'jquery-ui-datepicker', 'timed-content-jquery-ui-timepicker-js' ), TIMED_CONTENT_VERSION );
1109 wp_enqueue_script( 'timed-content-jquery-ui-timepicker-i18n-js' );
1110 wp_localize_script( 'timed-content-jquery-ui-timepicker-i18n-js', 'TimedContentJQTimepickerI18n', $jquery_ui_datetime_timepicker_i18n );
1111 }
1112
1113 ob_start();
1114 include( "tinymce_plugin/dialog.php" );
1115 $content = ob_get_contents();
1116 ob_end_clean();
1117 echo $content;
1118 die();
1119 }
1120
1121 /**
1122 * Adds support for i18n (internationalization)
1123 *
1124 */
1125 function i18nInit() {
1126 $plugin_dir = basename( dirname( __FILE__ ) ) . "/lang/";
1127 load_plugin_textdomain( 'timed-content', false, $plugin_dir );
1128 }
1129
1130 /**
1131 * Add custom columns to the Timed Content Rules overview page
1132 *
1133 */
1134 function addDescColumnHead( $defaults ) {
1135 unset( $defaults['date'] );
1136 $defaults['description'] = __( 'Description', 'timed-content' );
1137 $defaults['shortcode'] = __( 'Shortcode', 'timed-content' );
1138 return $defaults;
1139 }
1140
1141 /**
1142 * Display content associated with custom columns on the Timed Content Rules overview page
1143 *
1144 * @param $column_name Name of the column to be displayed
1145 * @param $post_ID ID of the Timed Content Rule being listed
1146 */
1147 function addDescColumnContent( $column_name, $post_ID ) {
1148 if ( $column_name == 'shortcode' ) {
1149 echo '<code>[' . TIMED_CONTENT_RULE_TAG . ' id="' . $post_ID . '"]...[/' . TIMED_CONTENT_RULE_TAG . ']</code>';
1150 }
1151 if ( $column_name == 'description' ) {
1152 $desc = $this->getScheduleDescriptionById( $post_ID );
1153 if ( $desc ) {
1154 echo '<em>' . $desc . '</em>';
1155 }
1156 }
1157 }
1158
1159 /**
1160 * Display a count of Timed Content Rules in the Dashboard's Right Now widget for Wordpress versions 3.7.1 and below
1161 *
1162 */
1163 function addRulesCount37() {
1164 if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
1165 return;
1166 }
1167
1168 $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1169 $num = number_format_i18n( $num_posts->publish );
1170 $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1171 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1172 $num = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1173 $text = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1174 }
1175 echo '<tr>';
1176 echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1177 echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1178 echo '</tr>';
1179
1180 if ( $num_posts->pending > 0 ) {
1181 $num = number_format_i18n( $num_posts->pending );
1182 $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1183 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1184 $num = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1185 $text = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1186 }
1187 echo '<tr>';
1188 echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1189 echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1190 echo '</tr>';
1191 }
1192 }
1193
1194 /**
1195 * Display a count of Timed Content Rules in the Dashboard's Right Now widget
1196 *
1197 */
1198 function addRulesCount() {
1199 if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
1200 return;
1201 }
1202
1203 $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1204 $num = number_format_i18n( $num_posts->publish );
1205 $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1206 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1207 echo "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1208 . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1209 . $num
1210 . ' '
1211 . $text
1212 . '</a></li>';
1213
1214 if ( $num_posts->pending > 0 ) {
1215 $num = number_format_i18n( $num_posts->pending );
1216 $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1217 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1218 echo "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1219 . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1220 . $num
1221 . ' '
1222 . $text
1223 . '</a></li>';
1224 }
1225 }
1226
1227 function setUpCustomFields() {
1228 require_once( "lib/customFields-settings.php" );
1229 require_once( "lib/customFieldsInterface.php" );
1230
1231 $scf = new customFieldsInterface( "timed_content_rule_schedule",
1232 __( 'Rule Description/Schedule', 'timed-content' ),
1233 "<div id=\"schedule_desc\" style=\"font-style: italic;\">"
1234 . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $this->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $this->getScheduleDescriptionById( intval( 0 ) ) )
1235 . "</div>"
1236 . "<div style=\"padding-top: 10px;\"><input type=\"button\" class=\"button-primary\" id=\"timed_content_rule_test\" value=\"" . __( 'Show Projected Dates/Times', 'timed-content' ) . "\" /></div>",
1237 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1238 array( TIMED_CONTENT_RULE_TYPE ),
1239 array() );
1240 $ocf = new customFieldsInterface( "timed_content_rule_initial_event",
1241 __( 'Action/Initial Event', 'timed-content' ),
1242 __( 'Set the action to be taken and when it should first run.', 'timed-content' ),
1243 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1244 array( TIMED_CONTENT_RULE_TYPE ),
1245 $timed_content_rule_occurrence_custom_fields );
1246 $pcf = new customFieldsInterface( "timed_content_rule_recurrence",
1247 __( 'Repeating Pattern', 'timed-content' ),
1248 __( 'Set how often the action should repeat.', 'timed-content' ),
1249 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1250 array( TIMED_CONTENT_RULE_TYPE ),
1251 $timed_content_rule_pattern_custom_fields );
1252 $rcf = new customFieldsInterface( "timed_content_rule_stop_condition",
1253 __( 'Stopping Condition', 'timed-content' ),
1254 __( 'Set how long or how many times the action should occur.', 'timed-content' ),
1255 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1256 array( TIMED_CONTENT_RULE_TYPE ),
1257 $timed_content_rule_recurrence_custom_fields );
1258 $ecf = new customFieldsInterface( "timed_content_rule_exceptions",
1259 __( 'Exceptions', 'timed-content' ),
1260 __( 'Set up any exceptions to this Timed Content Rule.', 'timed-content' ),
1261 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1262 array( TIMED_CONTENT_RULE_TYPE ),
1263 $timed_content_rule_exceptions_custom_fields );
1264
1265 // Initially loaded at the top; defining this constant here means it can get i18n'd
1266 /* translators: date/time format for debugging messages. http://ca2.php.net/manual/en/function.date.php */
1267 define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i A T" , 'timed-content' ) );
1268
1269 }
1270 }
1271
1272 } //End Class timedContentPlugin
1273
1274 // Initialize plugin
1275 if ( class_exists( "timedContentPlugin" ) ) {
1276 $timedContentPluginInstance = new timedContentPlugin();
1277 }
1278
1279 // Actions and Filters
1280 if ( isset( $timedContentPluginInstance ) ) {
1281 add_action( "plugins_loaded", array( &$timedContentPluginInstance, "i18nInit" ), 1 );
1282 add_action( "init", array( &$timedContentPluginInstance, "timedContentRuleTypeInit" ), 2 );
1283 add_action( "init", array( &$timedContentPluginInstance, "setUpCustomFields" ), 2 );
1284 add_action( "wp_head", array( &$timedContentPluginInstance, "addHeaderCode" ), 1 );
1285 add_filter( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_columns", array( &$timedContentPluginInstance, "addDescColumnHead" ) );
1286 add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2);
1287 add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 );
1288 add_action( "admin_init", array( &$timedContentPluginInstance, "setTinyMCEPluginVars" ), 1 );
1289 add_action( "admin_init", array( &$timedContentPluginInstance, "initTinyMCEPlugin" ), 2 );
1290 add_action( 'wp_ajax_timedContentPluginGetTinyMCEDialog', array( &$timedContentPluginInstance, "timedContentPluginGetTinyMCEDialog" ), 1 );
1291 add_action( 'wp_ajax_timedContentPluginGetRulePeriodsAjax', array( &$timedContentPluginInstance, "timedContentPluginGetRulePeriodsAjax" ), 1 );
1292 add_action( 'wp_ajax_timedContentPluginGetScheduleDescriptionAjax', array( &$timedContentPluginInstance, "timedContentPluginGetScheduleDescriptionAjax" ), 1 );
1293 add_filter( "post_updated_messages", array( &$timedContentPluginInstance, "timedContentRuleUpdatedMessages" ), 1 );
1294 if ( version_compare( $wp_version, "3.8", ">=" ) ) {
1295 add_action( "dashboard_glance_items", array( &$timedContentPluginInstance, "addRulesCount" ) );
1296 add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons" ), 1 );
1297 } else {
1298 add_action( "right_now_content_table_end", array( &$timedContentPluginInstance, "addRulesCount37" ) );
1299 add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons37" ), 1 );
1300 }
1301
1302 add_shortcode( TIMED_CONTENT_CLIENT_TAG, array( &$timedContentPluginInstance, "clientShowHTML" ), 1 );
1303 add_shortcode( TIMED_CONTENT_SERVER_TAG, array( &$timedContentPluginInstance, "serverShowHTML" ), 1 );
1304 add_shortcode( TIMED_CONTENT_RULE_TAG, array( &$timedContentPluginInstance, "rulesShowHTML" ), 1 );
1305 }
1306 ?>