PluginProbe
Timed Content / 2.3.1
Timed Content v2.3.1
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.1, at timed-content.php

1,322 lines 72.2 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.1
10 Author URI: http://wordpress.org/plugins/timed-content/
11 */
12 if ( !class_exists( "timedContentPlugin" ) ) {
13
14 define( "TIMED_CONTENT_VERSION", "2.3.1" );
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 if ( $right_now_t < $current ) {
459 $active_periods[$period_count]["status"] = "upcoming";
460 $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
461 } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
462 $active_periods[$period_count]["status"] = "active";
463 $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
464 } else {
465 $active_periods[$period_count]["status"] = "expired";
466 $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
467 }
468 } else {
469 $active_periods[$period_count]["start"] = $current;
470 $active_periods[$period_count]["end"] = $end_current;
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 if ( is_array( $exceptions_dates ) ) {
499 foreach ($exceptions_dates as $date) {
500 if (($current >= $date) && ($current < strtotime("+1 day", $date))) {
501 $exception_period = true;
502 break;
503 }
504 }
505 }
506
507 if ( ( eval ( $loop_test ) ) && ( !($exception_period) ) ) {
508 $end_current = $current + ( $instance_end - $instance_start );
509 if ( $human_readable == true ) {
510 $active_periods[$period_count]["start"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $current );
511 $active_periods[$period_count]["end"] = date_i18n( TIMED_CONTENT_DT_FORMAT, $end_current );
512 if ( $right_now_t < $current ) {
513 $active_periods[$period_count]["status"] = "upcoming";
514 $active_periods[$period_count]["time"] = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $current, $right_now_t ) );
515 } elseif ( ( $current <= $right_now_t ) && ( $right_now_t <= $end_current ) ) {
516 $active_periods[$period_count]["status"] = "active";
517 $active_periods[$period_count]["time"] = __( "Right now!", 'timed-content' );
518 } else {
519 $active_periods[$period_count]["status"] = "expired";
520 $active_periods[$period_count]["time"] = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $end_current, $right_now_t ) );
521 }
522 } else {
523 $active_periods[$period_count]["start"] = $current;
524 $active_periods[$period_count]["end"] = $end_current;
525 }
526 if ( !($exception_period) )
527 $period_count++;
528 }
529
530 }
531 date_default_timezone_set( $temp_tz );
532 return $active_periods;
533 }
534
535 /**
536 * Wrapper for calling timedContentPlugin::__getRulePeriods() by the ID of a Timed Content Rule
537 *
538 * @param int $ID ID of the Timed Content Rule
539 * @param bool $human_readable If true, the active periods are returned as a human-readable date/time
540 * as defined by the constant TIMED_CONTENT_DT_FORMAT; otherwise, they are
541 * returned as UNIX timestamps.
542 * @return array Array of active periods
543 */
544 function getRulePeriodsById( $ID, $human_readable = false ) {
545 if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $ID ) )
546 return array();
547
548 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
549 $args = array();
550
551 $args['human_readable'] = (bool) $human_readable;
552 $args['freq'] = get_post_meta( $ID, $prefix . 'frequency', true );
553 $args['timezone'] = get_post_meta( $ID, $prefix . 'timezone', true );
554 $args['recurr_type'] = get_post_meta( $ID, $prefix . 'recurrence_duration', true );
555 $args['num_repeat'] = get_post_meta( $ID, $prefix . 'recurrence_duration_num_repeat', true );
556 $args['end_date'] = get_post_meta( $ID, $prefix . 'recurrence_duration_end_date', true );
557 $args['days_of_week'] = get_post_meta( $ID, $prefix . 'weekly_days_of_week_to_repeat', true );
558 if ( $args['freq'] == 0 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'hourly_num_of_hours', true );
559 if ( $args['freq'] == 1 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'daily_num_of_days', true );
560 if ( $args['freq'] == 2 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'weekly_num_of_weeks', true );
561 if ( $args['freq'] == 3 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'monthly_num_of_months', true );
562 if ( $args['freq'] == 4 ) $args['interval_multiplier'] = get_post_meta( $ID, $prefix . 'yearly_num_of_years', true );
563 $args['instance_start'] = get_post_meta( $ID, $prefix . 'instance_start', true );
564 $args['instance_end'] = get_post_meta( $ID, $prefix . 'instance_end', true );
565 $args['monthly_pattern'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month', true );
566 $args['monthly_pattern_ord'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_nth', true );
567 $args['monthly_pattern_day'] = get_post_meta( $ID, $prefix . 'monthly_nth_weekday_of_month_weekday', true );
568 $args['exceptions_dates'] = get_post_meta( $ID, $prefix . 'exceptions_dates', true );
569
570 return $this->__getRulePeriods( $args );
571
572 }
573
574 /**
575 * Wrapper for calling timedContentPlugin::__getRulePeriods() based on the contents of the form fields
576 * of the Add Timed Content Rule and Edit Timed Content Rule screens. Output is sent to output as JSON
577 */
578 function timedContentPluginGetRulePeriodsAjax() {
579 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
580 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
581 $args = array();
582
583 $args['human_readable'] = ( ( ( isset( $_POST[$prefix . 'human_readable'] ) ) && ( $_POST[$prefix . 'human_readable'] == 'true' ) ) ? (bool)$_POST[$prefix . 'human_readable'] : false );
584 $args['freq'] = $_POST[$prefix . 'frequency'];
585 $args['timezone'] = $_POST[$prefix . 'timezone'];
586 $args['recurr_type'] = $_POST[$prefix . 'recurrence_duration'];
587 $args['num_repeat'] = $_POST[$prefix . 'recurrence_duration_num_repeat'];
588 $args['end_date'] = $_POST[$prefix . 'recurrence_duration_end_date'];
589 $args['days_of_week'] = ( isset( $_POST[$prefix . 'weekly_days_of_week_to_repeat'] ) ? $_POST[$prefix . 'weekly_days_of_week_to_repeat'] : array() );
590 $args['interval_multiplier'] = $_POST[$prefix . 'interval_multiplier'];
591 $args['instance_start'] = $_POST[$prefix . 'instance_start'];
592 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
593 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
594 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
595 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
596 $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
597
598 $response = json_encode( $this->__getRulePeriods( $args ) );
599
600 // response output
601 header( "Content-Type: application/json" );
602 echo $response;
603 }
604 die();
605
606 }
607
608 /**
609 * Returns a human-readable description of a Timed Content Rule
610 *
611 * @param $args Array of Timed Content Rule parameters
612 * @return string
613 */
614 function __getScheduleDescription( $args ) {
615 include("lib/Arrays_Definitions.php");
616
617 $interval_multiplier = 1;
618 $desc = "";
619
620 $errors = $this->__validate( $args );
621 if ( $errors ) {
622 $messages = "<div class=\"tcr-warning\">\n";
623 $messages .= "<p class=\"heading\">" . __( "Warning!", 'timed-content' ) . "</p>\n";
624 $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";
625 $messages .= "<ul>\n";
626 foreach ( $errors as $error )
627 $messages .= " <li>" . $error . "</li>\n";
628 $messages .= "</ul>\n";
629 $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";
630 $messages .= "</div>\n";
631 return $messages;
632 }
633
634 if ( $args['action'] )
635 $action = __( "Show the content", 'timed-content' );
636 else
637 $action = __( "Hide the content", 'timed-content' );
638 $freq = $args['freq'];
639 $timezone = $args['timezone'];
640 $recurr_type = $args['recurr_type'];
641 $num_repeat = intval( $args['num_repeat'] );
642 $end_date = $args['end_date'];
643 $days_of_week = $args['days_of_week'];
644 $interval_multiplier = $args['interval_multiplier'];
645 $instance_start_date = $args['instance_start']['date'];
646 $instance_start_time = $args['instance_start']['time'];
647 $instance_end_date = $args['instance_end']['date'];
648 $instance_end_time = $args['instance_end']['time'];
649 $monthly_pattern = $args['monthly_pattern'];
650 $monthly_pattern_ord = $args['monthly_pattern_ord'];
651 $monthly_pattern_day = $args['monthly_pattern_day'];
652 $exceptions_dates = $args['exceptions_dates'];
653
654 $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 );
655
656 if ( $freq == 0 )
657 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every hour.', 'Repeat this action every %d hours.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
658 elseif ( $freq == 1 )
659 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every day.', 'Repeat this action every %d days.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
660 elseif ( $freq == 2 ) {
661 if ( ( $days_of_week ) && ( is_array( $days_of_week ) ) ) {
662 $days = array(); $days_list = "";
663 foreach ( $days_of_week as $v )
664 $days[] = $timed_content_rule_days_array[$v];
665 switch ( count( $days ) ) {
666 case 1: $days_list = sprintf( _x( '%1$s', 'List of one weekday', 'timed-content' ), $days[0] ); break;
667 case 2: $days_list = sprintf( _x( '%1$s and %2$s', 'List of two weekdays', 'timed-content' ), $days[0], $days[1] ); break;
668 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;
669 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;
670 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;
671 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;
672 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;
673 }
674 if ( $interval_multiplier == 1 )
675 $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 );
676 else
677 $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 );
678 } else
679 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every week.', 'Repeat this action every %d weeks.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
680
681 } elseif ( $freq == 3 ) {
682 if ( $monthly_pattern == "yes" ) {
683 if ( $interval_multiplier == 1 )
684 $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] );
685 else
686 $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] );
687 } else
688 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every month.', 'Repeat this action every %d months.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
689 } elseif ( $freq == 4 )
690 $desc .= "&nbsp;" . sprintf( _n( 'Repeat this action every year.', 'Repeat this action every %d years.', $interval_multiplier, 'timed-content' ), $interval_multiplier );
691
692 if ( $recurr_type == "recurrence_duration_num_repeat" )
693 $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 );
694 elseif ( $recurr_type == "recurrence_duration_end_date" )
695 $desc .= "&nbsp;" . sprintf( __( 'This rule will be active until %s.', 'timed-content' ), $end_date );
696
697 if ( ( $exceptions_dates ) && ( is_array( $exceptions_dates ) ) ) {
698 sort( $exceptions_dates, SORT_NUMERIC );
699 $exceptions_dates = array_unique( $exceptions_dates );
700 if ( $exceptions_dates[0] == 0 )
701 array_shift( $exceptions_dates );
702 if ( !empty( $exceptions_dates ) ) {
703 $formatted_dates = array();
704 foreach ( $exceptions_dates as $a_date )
705 $formatted_dates[] = date( _x( "F j, Y" , "Date format for schedule description", 'timed-content' ), $a_date );
706 $desc .= "&nbsp;" . sprintf( __( 'This rule will be inactive on the following dates: %s.', 'timed-content' ), join( ", ", $formatted_dates ) );
707 }
708 }
709
710 $desc .= "&nbsp;" . sprintf( __( 'All times are in the %s timezone.', 'timed-content' ), $timezone );
711 return $desc;
712 }
713
714 /**
715 * Wrapper for calling timedContentPlugin::__getScheduleDescription() by the ID of a Timed Content Rule
716 *
717 * @param int $ID ID of the Timed Content Rule
718 * @return string
719 */
720 function getScheduleDescriptionById( $ID ) {
721 global $timed_content_rule_occurrence_custom_fields,
722 $timed_content_rule_pattern_custom_fields,
723 $timed_content_rule_recurrence_custom_fields,
724 $timed_content_rule_exceptions_custom_fields;
725 $defaults = array();
726
727 foreach ( $timed_content_rule_occurrence_custom_fields as $field ) {
728 $defaults[$field['name']] = $field['default'];
729 }
730 foreach ( $timed_content_rule_pattern_custom_fields as $field ) {
731 $defaults[$field['name']] = $field['default'];
732 }
733 foreach ( $timed_content_rule_recurrence_custom_fields as $field ) {
734 $defaults[$field['name']] = $field['default'];
735 }
736 foreach ( $timed_content_rule_exceptions_custom_fields as $field ) {
737 $defaults[$field['name']] = $field['default'];
738 }
739
740 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
741 $args = array();
742
743 $args['action'] = ( false === get_post_meta( $ID, $prefix . 'action', true ) ? $defaults['action'] : get_post_meta( $ID, $prefix . 'action', true ) );
744 $args['freq'] = ( false === get_post_meta( $ID, $prefix . 'frequency', true ) ? $defaults['frequency'] : get_post_meta( $ID, $prefix . 'frequency', true ) );
745 $args['timezone'] = ( false === get_post_meta( $ID, $prefix . 'timezone', true ) ? $defaults['timezone'] : get_post_meta( $ID, $prefix . 'timezone', true ) );
746 $args['recurr_type'] = ( false === get_post_meta( $ID, $prefix . 'recurrence_duration', true ) ? $defaults['recurrence_duration'] : get_post_meta( $ID, $prefix . 'recurrence_duration', true ) );
747 $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 ) );
748 $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 ) );
749 $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 ) );
750 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 ) );
751 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 ) );
752 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 ) );
753 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 ) );
754 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 ) );
755 $args['instance_start'] = ( false === get_post_meta( $ID, $prefix . 'instance_start', true ) ? $defaults['instance_start'] : get_post_meta( $ID, $prefix . 'instance_start', true ) );
756 $args['instance_end'] = ( false === get_post_meta( $ID, $prefix . 'instance_end', true ) ? $defaults['instance_end'] : get_post_meta( $ID, $prefix . 'instance_end', true ) );
757 $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 ) );
758 $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 ) );
759 $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 ) );
760 $args['exceptions_dates'] = ( false === get_post_meta( $ID, $prefix . 'exceptions_dates', true ) ? $defaults['exceptions_dates'] : get_post_meta( $ID, $prefix . 'exceptions_dates', true ) );
761
762 return $this->__getScheduleDescription( $args );
763
764 }
765
766 /**
767 * Wrapper for calling timedContentPlugin::__getRulePeriods() based on the contents of the form fields
768 * of the Add Timed Content Rule and Edit Timed Content Rule screens. Output is sent to output as plain text
769 */
770 function timedContentPluginGetScheduleDescriptionAjax() {
771 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
772 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
773 $args = array();
774
775 $args['action'] = $_POST[$prefix . 'action'];
776 $args['freq'] = $_POST[$prefix . 'frequency'];
777 $args['timezone'] = $_POST[$prefix . 'timezone'];
778 $args['recurr_type'] = $_POST[$prefix . 'recurrence_duration'];
779 $args['num_repeat'] = $_POST[$prefix . 'recurrence_duration_num_repeat'];
780 $args['end_date'] = $_POST[$prefix . 'recurrence_duration_end_date'];
781 $args['days_of_week'] = ( isset( $_POST[$prefix . 'weekly_days_of_week_to_repeat'] ) ? $_POST[$prefix . 'weekly_days_of_week_to_repeat'] : array() );
782 $args['interval_multiplier'] = $_POST[$prefix . 'interval_multiplier'];
783 $args['instance_start'] = $_POST[$prefix . 'instance_start'];
784 $args['instance_end'] = $_POST[$prefix . 'instance_end'];
785 $args['monthly_pattern'] = $_POST[$prefix . 'monthly_nth_weekday_of_month'];
786 $args['monthly_pattern_ord'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_nth'];
787 $args['monthly_pattern_day'] = $_POST[$prefix . 'monthly_nth_weekday_of_month_weekday'];
788 $args['exceptions_dates'] = ( isset( $_POST[$prefix . 'exceptions_dates'] ) ? $_POST[$prefix . 'exceptions_dates'] : array() );
789
790 $response = $this->__getScheduleDescription( $args );
791
792 // response output
793 header( "Content-Type: text/plain" );
794 echo $response;
795 }
796 die();
797 }
798
799 /**
800 * Processes the [timed-content-client] shortcode.
801 *
802 * @param array $atts
803 * @param null $content
804 * @return string
805 */
806 function clientShowHTML( $atts, $content = null ) {
807 $show_attr = "";
808 $hide_attr = "";
809 extract( shortcode_atts( array( 'show' => '0:00:000' , 'hide' => '0:00:000' , 'display' => 'div' ), $atts ) );
810
811 // Initialize show/hide arguments
812 $s_min = 0; $s_sec = 0; $s_fade = 0;
813 $h_min = 0; $h_sec = 0; $h_fade = 0;
814 @list( $s_min, $s_sec, $s_fade ) = explode( ":", $show );
815 @list( $h_min, $h_sec, $h_fade ) = explode( ":", $hide );
816
817 if ( ( (int)$s_min + (int)$s_sec ) > 0 )
818 $show_attr = "_show_" . $s_min . "_" . $s_sec . "_" . $s_fade;
819 if ( ( (int)$h_min + (int)$h_sec ) > 0 )
820 $hide_attr = "_hide_" . $h_min . "_" . $h_sec . "_" . $h_fade;
821
822 $the_class = TIMED_CONTENT_CLIENT_TAG . $show_attr . $hide_attr ;
823 $the_tag = ( $display == "div" ? "div" : "span" );
824
825 $the_HTML = "<"
826 . $the_tag
827 . " class='"
828 . $the_class
829 . "'"
830 . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">"
831 . apply_filters( "timed_content_filter", $content )
832 . "</" . $the_tag . ">";
833
834 return $the_HTML;
835 }
836
837 /**
838 * Processes the [timed-content-server] shortcode.
839 *
840 * @param array $atts
841 * @param null $content
842 * @return string
843 */
844 function serverShowHTML( $atts, $content = null ) {
845 global $post;
846 extract( shortcode_atts( array( 'show' => TIMED_CONTENT_ZERO_TIME , 'hide' => TIMED_CONTENT_END_TIME, 'debug' => 'false' ), $atts ) );
847 $show_t = strtotime( $this->__datetimeToEnglish( $show ) );
848 $hide_t = strtotime( $this->__datetimeToEnglish( $hide ) );
849 $right_now_t = time();
850 $debug_message = "";
851
852 if ( ( $debug == "true" ) && ( current_user_can( "edit_post", $post->post_id ) ) ) {
853 $temp_tz = date_default_timezone_get();
854 date_default_timezone_set( get_option( 'timezone_string' ) );
855
856 $right_now = date_i18n( TIMED_CONTENT_DT_FORMAT, $right_now_t );
857
858 if ( $show_t > $right_now_t )
859 $show_diff_str = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $show_t, $right_now_t ) );
860 else
861 $show_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $show_t, $right_now_t ) );
862 if ( $hide_t > $right_now_t )
863 $hide_diff_str = sprintf( _x( '%s from now.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) );
864 else
865 $hide_diff_str = sprintf( _x( '%s ago.', 'Human readable time difference', 'timed-content' ), human_time_diff( $hide_t, $right_now_t ) );
866
867 $debug_message = "<div class=\"tcr-warning\">\n";
868 $debug_message .= "<p class=\"heading\">" . _x( "Notice", "Noun", 'timed-content' ) . "</p>\n";
869 $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";
870
871 if ( $show == TIMED_CONTENT_ZERO_TIME )
872 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ), "<code>show</code>" ) . "</p>\n";
873 else
874 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>show</code>" ) . ": " . $show . ",<br />\n "
875 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $show_t )
876 . " (" . $show_diff_str . ")</p>\n";
877
878 if ( $hide == TIMED_CONTENT_END_TIME )
879 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.' , 'timed-content' ), "<code>hide</code>" ) . "</p>\n";
880 else
881 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ), "<code>hide</code>" ) . ": " . $hide . ",<br />\n"
882 . __( 'The Timed Content plugin thinks the intended date/time is', 'timed-content') . ": " . date_i18n( TIMED_CONTENT_DT_FORMAT, $hide_t )
883 . " (" . $hide_diff_str . ").</p>\n";
884
885 $debug_message .= "<p>" . __( 'Current Date/Time:', 'timed-content') . "&nbsp;" . $right_now . "</p>\n";
886 $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content') . "&nbsp;" . $content . "</p>\n";
887
888 $debug_message .= "</div>\n";
889
890 date_default_timezone_set( $temp_tz );
891 }
892
893 if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) )
894 return $debug_message . apply_filters( "timed_content_filter", $content ) . "\n";
895 else
896 return $debug_message . "\n";
897
898 }
899
900 /**
901 * Processes the [timed-content-rule] shortcode.
902 *
903 * @param array $atts
904 * @param null $content
905 * @return string
906 */
907 function rulesShowHTML( $atts, $content = null ) {
908 extract( shortcode_atts( array( 'id' => '0' ), $atts ) );
909 if ( TIMED_CONTENT_RULE_TYPE != get_post_type( $id ) ) return;
910
911 $prefix = TIMED_CONTENT_RULE_POSTMETA_PREFIX;
912 $right_now_t = time();
913 $rule_is_active = false;
914
915 $active_periods = $this->getRulePeriodsById( $id, false );
916 $action_is_show = (bool) get_post_meta( $id, $prefix . 'action', true );
917
918 foreach ( $active_periods as $period ) {
919 if ( ( $period['start'] <= $right_now_t ) && ( $right_now_t <= $period['end'] ) ) {
920 $rule_is_active = true;
921 break;
922 }
923 }
924
925 if ( ( ( $rule_is_active == true ) && ( $action_is_show == true ) ) || ( ( $rule_is_active == false ) && ( $action_is_show == false ) ) )
926 return apply_filters( "timed_content_filter", $content );
927 else
928 return "";
929 }
930
931 /**
932 * Enqueues the JavaScript code necessary for the functionality of the [timed-content-client] shortcode.
933 */
934 function addHeaderCode() {
935 if ( ! is_admin() ) {
936 wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
937 wp_enqueue_script( 'timed-content_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
938 }
939 }
940
941 /**
942 * 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.
943 */
944 function addPostTypeIcons37() {
945 ?>
946 <style type="text/css" media="screen">
947 #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> .wp-menu-image {
948 background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_icon.png) no-repeat 6px 6px !important;
949 }
950 #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 {
951 background-position: -22px 6px !important;
952 }
953 #icon-edit.icon32-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?> {background: url(<?php echo TIMED_CONTENT_PLUGIN_URL; ?>/img/clock_32x32.png) no-repeat;}
954 </style>
955 <?php
956 }
957
958 /**
959 * Enqueues the CSS code necessary for custom icons for the Timed Content Rules management screens
960 * and the TinyMCE editor. Echo'd to output.
961 */
962 function addPostTypeIcons() {
963 wp_enqueue_style( 'ca-aliencyborg-dashicons', TIMED_CONTENT_CSS_DASHICONS, false, TIMED_CONTENT_VERSION );
964 ?>
965 <style type="text/css" media="screen">
966 #adminmenu #menu-posts-<?php echo TIMED_CONTENT_RULE_TYPE; ?>.menu-icon-post div.wp-menu-image:before {
967 font-family: 'ca-aliencyborg-dashicons' !important;
968 content: '\e601';
969 }
970 #dashboard_right_now li.<?php echo TIMED_CONTENT_RULE_TYPE; ?>-count a:before {
971 font-family: 'ca-aliencyborg-dashicons' !important;
972 content: '\e601';
973 }
974 .mce-i-timed_content:before {
975 font: 400 24px/1 'ca-aliencyborg-dashicons' !important;
976 padding: 0;
977 vertical-align: top;
978 margin-left: -2px;
979 padding-right: 2px;
980 content: '\e601';
981 }
982 </style>
983 <?php
984 }
985
986 /**
987 * Enqueues the JavaScript code necessary for the functionality of the Timed Content Rules management screens.
988 */
989 function addAdminHeaderCode() {
990 if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == TIMED_CONTENT_RULE_TYPE )
991 || ( isset( $post_type ) && $post_type == TIMED_CONTENT_RULE_TYPE )
992 || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == TIMED_CONTENT_RULE_TYPE ) ) {
993 wp_enqueue_style( 'timed-content-css', TIMED_CONTENT_CSS, false, TIMED_CONTENT_VERSION );
994 // Enqueue the JavaScript file that manages the meta box UI
995 wp_enqueue_script( 'timed-content-admin_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin.js', array( 'jquery' ), TIMED_CONTENT_VERSION );
996 // Enqueue the JavaScript file that makes AJAX requests
997 wp_enqueue_script( 'timed-content-ajax_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-ajax.js', array( 'jquery', 'jquery-ui-dialog' ), TIMED_CONTENT_VERSION );
998
999 // Set up local variables used in the Admin JavaScript file
1000 wp_localize_script( 'timed-content-admin_js', 'timedContentRuleAdmin', array(
1001 'no_exceptions_label' => __( "- No exceptions set -", 'timed-content' ) ) );
1002
1003 // Set up local variables used in the AJAX JavaScript file
1004 wp_localize_script( 'timed-content-ajax_js', 'timedContentRuleAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1005 'start_label' => _x( 'Start', 'Scheduled Dates/Times dialog - Beginning of active period table header', 'timed-content' ),
1006 'end_label' => _x( 'End', 'Scheduled Dates/Times dialog - End of active period table header', 'timed-content' ),
1007 'dialog_label' => _x( 'Scheduled Dates/Times', 'Scheduled Dates/Times dialog - dialog header', 'timed-content' ),
1008 'dialog_width' => 800,
1009 'dialog_height' => 500,
1010 'close_label' => _x( 'Close', 'Scheduled Dates/Times dialog - Close button HTML label', 'timed-content' ),
1011 'loadingimg' => TIMED_CONTENT_PLUGIN_URL . '/img/wpspin.gif',
1012 'error' => __( "Error", 'timed-content' ),
1013 'error_desc' => __( "Something unexpected has happened along the way. The specific details are below:", 'timed-content' ) ) );
1014 }
1015 }
1016
1017 /**
1018 * Initializes the TinyMCE plugin bundled with this Wordpress plugin
1019 */
1020 function initTinyMCEPlugin() {
1021 if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) )
1022 return;
1023
1024 // Add only in Rich Editor mode
1025 if ( get_user_option( 'rich_editing' ) == 'true' ) {
1026 add_filter( "mce_external_plugins", array( &$this, "addTimedContentTinyMCEPlugin" ) );
1027 add_filter( "mce_buttons", array( &$this, "registerTinyMCEButton" ) );
1028 }
1029 }
1030
1031 /**
1032 * Sets up variables to use in the TinyMCE plugin's plugin.js.
1033 *
1034 */
1035 function setTinyMCEPluginVars() {
1036 global $wp_version;
1037 if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) )
1038 return;
1039
1040 // Add only in Rich Editor mode
1041 if ( get_user_option( 'rich_editing' ) == 'true' ) {
1042 if ( version_compare( $wp_version, "3.8", "<" ) )
1043 $image = "/clock.gif";
1044 else
1045 $image = "";
1046 wp_enqueue_script( 'timed-content-admin_tinymce_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content-admin-tinymce.js', array(), TIMED_CONTENT_VERSION );
1047 wp_localize_script( 'timed-content-admin_tinymce_js',
1048 'timedContentAdminTinyMCEOptionsVars',
1049 array( 'version' => TIMED_CONTENT_VERSION,
1050 'desc' => __( "Add Timed Content shortcodes", 'timed-content' ),
1051 'image' => $image ) );
1052 }
1053 }
1054
1055 /**
1056 * Sets up the button for the associated TinyMCE plugin for use in the editor menubar.
1057 * @param array $buttons Array of menu buttons already registered with TinyMCE
1058 * @return array The array of TinyMCE menu buttons with ours now loaded in as well
1059 */
1060 function registerTinyMCEButton( $buttons ) {
1061 array_push( $buttons, "|", "timed_content" );
1062 return $buttons;
1063 }
1064
1065 /**
1066 * Loads the associated TinyMCE plugin into TinyMCE's plugin array
1067 *
1068 * @param array $plugin_array Array of plugins already registered with TinyMCE
1069 * @return array The array of TinyMCE plugins with ours now loaded in as well
1070 */
1071 function addTimedContentTinyMCEPlugin( $plugin_array ) {
1072 $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/plugin.js";
1073 return $plugin_array;
1074 }
1075
1076 /**
1077 * Generates JavaScript array of objects describing Timed Content Rules. Used in the dialog box created by
1078 * timedContentPlugin::timedContentPluginGetTinyMCEDialog().
1079 *
1080 * @return string
1081 */
1082 function __getRulesJS() {
1083 $the_js = "var rules = [\n";
1084 $args = array( 'post_type' => TIMED_CONTENT_RULE_TYPE, 'posts_per_page' => -1, 'post_status' => 'publish' );
1085 $the_rules = get_posts( $args );
1086 foreach ( $the_rules as $rule ) {
1087 $desc = $this->getScheduleDescriptionById( $rule->ID );
1088 // Only add a rule if there's no errors or warnings
1089 if ( false === strpos( $desc, "tcr-warning" ) )
1090 $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";
1091 }
1092 if ( empty( $the_rules ) )
1093 $the_js .= " { 'ID': -999, 'title': ' ---- ', 'desc': '" . __( 'No Timed Content Rules found', 'timed-content' ) . "' }\n";
1094
1095 $the_js .= "];\n";
1096 return $the_js;
1097 }
1098 /**
1099 * Display a dialog box for this plugin's associated TinyMCE plugin. Called from TinyMCE via AJAX.
1100 *
1101 */
1102 function timedContentPluginGetTinyMCEDialog() {
1103 include( "lib/jquery-ui-datetime-i18n.php" );
1104
1105 wp_enqueue_style( 'timed-content-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS, false, TIMED_CONTENT_VERSION );
1106 wp_enqueue_script( 'jquery-ui-datepicker' );
1107 if( !( wp_script_is( 'timed-content-jquery-ui-datepicker-i18n-js', 'registered' ) ) ) {
1108 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 );
1109 wp_enqueue_script( 'timed-content-jquery-ui-datepicker-i18n-js' );
1110 wp_localize_script( 'timed-content-jquery-ui-datepicker-i18n-js', 'TimedContentJQDatepickerI18n', $jquery_ui_datetime_datepicker_i18n );
1111 }
1112 wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS, array( TIMED_CONTENT_JQUERY_UI_CSS ), TIMED_CONTENT_VERSION );
1113 wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' );
1114 wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array( 'jquery', 'jquery-ui-datepicker' ), TIMED_CONTENT_VERSION );
1115 wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' );
1116 if( !( wp_script_is( 'timed-content-jquery-ui-timepicker-i18n-js', 'registered' ) ) ) {
1117 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 );
1118 wp_enqueue_script( 'timed-content-jquery-ui-timepicker-i18n-js' );
1119 wp_localize_script( 'timed-content-jquery-ui-timepicker-i18n-js', 'TimedContentJQTimepickerI18n', $jquery_ui_datetime_timepicker_i18n );
1120 }
1121
1122 ob_start();
1123 include( "tinymce_plugin/dialog.php" );
1124 $content = ob_get_contents();
1125 ob_end_clean();
1126 echo $content;
1127 die();
1128 }
1129
1130 /**
1131 * Adds support for i18n (internationalization)
1132 *
1133 */
1134 function i18nInit() {
1135 $plugin_dir = basename( dirname( __FILE__ ) ) . "/lang/";
1136 load_plugin_textdomain( 'timed-content', false, $plugin_dir );
1137 }
1138
1139 /**
1140 * Add custom columns to the Timed Content Rules overview page
1141 *
1142 */
1143 function addDescColumnHead( $defaults ) {
1144 unset( $defaults['date'] );
1145 $defaults['description'] = __( 'Description', 'timed-content' );
1146 $defaults['shortcode'] = __( 'Shortcode', 'timed-content' );
1147 return $defaults;
1148 }
1149
1150 /**
1151 * Display content associated with custom columns on the Timed Content Rules overview page
1152 *
1153 * @param $column_name Name of the column to be displayed
1154 * @param $post_ID ID of the Timed Content Rule being listed
1155 */
1156 function addDescColumnContent( $column_name, $post_ID ) {
1157 if ( $column_name == 'shortcode' ) {
1158 echo '<code>[' . TIMED_CONTENT_RULE_TAG . ' id="' . $post_ID . '"]...[/' . TIMED_CONTENT_RULE_TAG . ']</code>';
1159 }
1160 if ( $column_name == 'description' ) {
1161 $desc = $this->getScheduleDescriptionById( $post_ID );
1162 if ( $desc ) {
1163 echo '<em>' . $desc . '</em>';
1164 }
1165 }
1166 }
1167
1168 /**
1169 * Display a count of Timed Content Rules in the Dashboard's Right Now widget for Wordpress versions 3.7.1 and below
1170 *
1171 */
1172 function addRulesCount37() {
1173 if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
1174 return;
1175 }
1176
1177 $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1178 $num = number_format_i18n( $num_posts->publish );
1179 $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1180 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1181 $num = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1182 $text = "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1183 }
1184 echo '<tr>';
1185 echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1186 echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1187 echo '</tr>';
1188
1189 if ( $num_posts->pending > 0 ) {
1190 $num = number_format_i18n( $num_posts->pending );
1191 $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1192 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
1193 $num = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $num . "</a>";
1194 $text = "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>" . $text . "</a>";
1195 }
1196 echo '<tr>';
1197 echo '<td class="first b b-' . TIMED_CONTENT_RULE_TYPE . '">' . $num . '</td>';
1198 echo '<td class="t ' . TIMED_CONTENT_RULE_TYPE . '">' . $text . '</td>';
1199 echo '</tr>';
1200 }
1201 }
1202
1203 /**
1204 * Display a count of Timed Content Rules in the Dashboard's Right Now widget
1205 *
1206 */
1207 function addRulesCount() {
1208 if ( !post_type_exists( TIMED_CONTENT_RULE_TYPE ) ) {
1209 return;
1210 }
1211
1212 $num_posts = wp_count_posts( TIMED_CONTENT_RULE_TYPE );
1213 $num = number_format_i18n( $num_posts->publish );
1214 $text = _n( 'Timed Content Rule', 'Timed Content Rules', intval( $num_posts->publish ), 'timed-content' );
1215 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1216 echo "<a href='edit.php?post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1217 . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1218 . $num
1219 . ' '
1220 . $text
1221 . '</a></li>';
1222
1223 if ( $num_posts->pending > 0 ) {
1224 $num = number_format_i18n( $num_posts->pending );
1225 $text = _n( 'Timed Content Rule Pending', 'Timed Content Rules Pending', intval( $num_posts->pending ), 'timed-content' );
1226 if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) )
1227 echo "<a href='edit.php?post_status=pending&post_type=" . TIMED_CONTENT_RULE_TYPE . "'>"
1228 . '<li class="' . TIMED_CONTENT_RULE_TYPE . '-count">'
1229 . $num
1230 . ' '
1231 . $text
1232 . '</a></li>';
1233 }
1234 }
1235
1236 function setUpCustomFields() {
1237 require_once( "lib/customFields-settings.php" );
1238 require_once( "lib/customFieldsInterface.php" );
1239
1240 $scf = new customFieldsInterface( "timed_content_rule_schedule",
1241 __( 'Rule Description/Schedule', 'timed-content' ),
1242 "<div id=\"schedule_desc\" style=\"font-style: italic;\">"
1243 . ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? $this->getScheduleDescriptionById( intval( $_GET['post'] ) ) : $this->getScheduleDescriptionById( intval( 0 ) ) )
1244 . "</div>"
1245 . "<div style=\"padding-top: 10px;\"><input type=\"button\" class=\"button-primary\" id=\"timed_content_rule_test\" value=\"" . __( 'Show Projected Dates/Times', 'timed-content' ) . "\" /></div>",
1246 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1247 array( TIMED_CONTENT_RULE_TYPE ),
1248 array() );
1249 $ocf = new customFieldsInterface( "timed_content_rule_initial_event",
1250 __( 'Action/Initial Event', 'timed-content' ),
1251 __( 'Set the action to be taken and when it should first run.', 'timed-content' ),
1252 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1253 array( TIMED_CONTENT_RULE_TYPE ),
1254 $timed_content_rule_occurrence_custom_fields );
1255 $pcf = new customFieldsInterface( "timed_content_rule_recurrence",
1256 __( 'Repeating Pattern', 'timed-content' ),
1257 __( 'Set how often the action should repeat.', 'timed-content' ),
1258 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1259 array( TIMED_CONTENT_RULE_TYPE ),
1260 $timed_content_rule_pattern_custom_fields );
1261 $rcf = new customFieldsInterface( "timed_content_rule_stop_condition",
1262 __( 'Stopping Condition', 'timed-content' ),
1263 __( 'Set how long or how many times the action should occur.', 'timed-content' ),
1264 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1265 array( TIMED_CONTENT_RULE_TYPE ),
1266 $timed_content_rule_recurrence_custom_fields );
1267 $ecf = new customFieldsInterface( "timed_content_rule_exceptions",
1268 __( 'Exceptions', 'timed-content' ),
1269 __( 'Set up any exceptions to this Timed Content Rule.', 'timed-content' ),
1270 TIMED_CONTENT_RULE_POSTMETA_PREFIX,
1271 array( TIMED_CONTENT_RULE_TYPE ),
1272 $timed_content_rule_exceptions_custom_fields );
1273
1274 // Initially loaded at the top; defining this constant here means it can get i18n'd
1275 /* translators: date/time format for debugging messages. http://ca2.php.net/manual/en/function.date.php */
1276 define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i A T" , 'timed-content' ) );
1277
1278 }
1279 }
1280
1281 } //End Class timedContentPlugin
1282
1283 // Initialize plugin
1284 if ( class_exists( "timedContentPlugin" ) ) {
1285 $timedContentPluginInstance = new timedContentPlugin();
1286 }
1287
1288 // Actions and Filters
1289 if ( isset( $timedContentPluginInstance ) ) {
1290 add_filter('timed_content_filter', 'wptexturize');
1291 add_filter('timed_content_filter', 'convert_smilies');
1292 add_filter('timed_content_filter', 'convert_chars');
1293 add_filter('timed_content_filter', 'wpautop');
1294 add_filter('timed_content_filter', 'prepend_attachment');
1295 add_filter('timed_content_filter', 'do_shortcode');
1296
1297 add_action( "plugins_loaded", array( &$timedContentPluginInstance, "i18nInit" ), 1 );
1298 add_action( "init", array( &$timedContentPluginInstance, "timedContentRuleTypeInit" ), 2 );
1299 add_action( "init", array( &$timedContentPluginInstance, "setUpCustomFields" ), 2 );
1300 add_action( "wp_head", array( &$timedContentPluginInstance, "addHeaderCode" ), 1 );
1301 add_filter( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_columns", array( &$timedContentPluginInstance, "addDescColumnHead" ) );
1302 add_action( "manage_" . TIMED_CONTENT_RULE_TYPE . "_posts_custom_column", array( &$timedContentPluginInstance, "addDescColumnContent" ), 10, 2);
1303 add_action( "admin_enqueue_scripts", array( &$timedContentPluginInstance, "addAdminHeaderCode" ), 1 );
1304 add_action( "admin_init", array( &$timedContentPluginInstance, "setTinyMCEPluginVars" ), 1 );
1305 add_action( "admin_init", array( &$timedContentPluginInstance, "initTinyMCEPlugin" ), 2 );
1306 add_action( 'wp_ajax_timedContentPluginGetTinyMCEDialog', array( &$timedContentPluginInstance, "timedContentPluginGetTinyMCEDialog" ), 1 );
1307 add_action( 'wp_ajax_timedContentPluginGetRulePeriodsAjax', array( &$timedContentPluginInstance, "timedContentPluginGetRulePeriodsAjax" ), 1 );
1308 add_action( 'wp_ajax_timedContentPluginGetScheduleDescriptionAjax', array( &$timedContentPluginInstance, "timedContentPluginGetScheduleDescriptionAjax" ), 1 );
1309 add_filter( "post_updated_messages", array( &$timedContentPluginInstance, "timedContentRuleUpdatedMessages" ), 1 );
1310 if ( version_compare( $wp_version, "3.8", ">=" ) ) {
1311 add_action( "dashboard_glance_items", array( &$timedContentPluginInstance, "addRulesCount" ) );
1312 add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons" ), 1 );
1313 } else {
1314 add_action( "right_now_content_table_end", array( &$timedContentPluginInstance, "addRulesCount37" ) );
1315 add_action( "admin_head", array( &$timedContentPluginInstance, "addPostTypeIcons37" ), 1 );
1316 }
1317
1318 add_shortcode( TIMED_CONTENT_CLIENT_TAG, array( &$timedContentPluginInstance, "clientShowHTML" ), 1 );
1319 add_shortcode( TIMED_CONTENT_SERVER_TAG, array( &$timedContentPluginInstance, "serverShowHTML" ), 1 );
1320 add_shortcode( TIMED_CONTENT_RULE_TAG, array( &$timedContentPluginInstance, "rulesShowHTML" ), 1 );
1321 }
1322 ?>