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