| 1 |
<?php |
| 2 |
require_once("Arrays_Definitions.php"); |
| 3 |
global $post, |
| 4 |
$timed_content_rule_occurrence_custom_fields, |
| 5 |
$timed_content_rule_pattern_custom_fields, |
| 6 |
$timed_content_rule_recurrence_custom_fields, |
| 7 |
$timed_content_rule_exceptions_custom_fields; |
| 8 |
$now_t = current_time( "timestamp" ); |
| 9 |
$post_id = ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? intval( $_GET['post'] ) : intval( 0 ) ); |
| 10 |
$timed_content_rules_exceptions_dates = ( "" === get_post_meta( $post_id, TIMED_CONTENT_RULE_POSTMETA_PREFIX . "exceptions_dates", true ) ? array() : get_post_meta( $post_id, TIMED_CONTENT_RULE_POSTMETA_PREFIX . "exceptions_dates", true ) ); |
| 11 |
if ( empty( $timed_content_rules_exceptions_dates ) ) |
| 12 |
$timed_content_rules_exceptions_dates_array = array( "0" => __( "- No exceptions set -", 'timed-content' ) ); |
| 13 |
else { |
| 14 |
sort( $timed_content_rules_exceptions_dates, SORT_NUMERIC ); |
| 15 |
$timed_content_rules_exceptions_dates = array_unique( $timed_content_rules_exceptions_dates ); |
| 16 |
$formatted_dates = array(); |
| 17 |
foreach ( $timed_content_rules_exceptions_dates as $a_date ) { |
| 18 |
$a_date_idx = $a_date * 1000; |
| 19 |
$formatted_dates[$a_date_idx] = date(_x("F j, Y", "Date format for schedule description", 'timed-content'), $a_date); |
| 20 |
} |
| 21 |
$timed_content_rules_exceptions_dates_array = array_combine($timed_content_rules_exceptions_dates, $formatted_dates); |
| 22 |
} |
| 23 |
|
| 24 |
$timed_content_rule_occurrence_custom_fields = array( |
| 25 |
array( |
| 26 |
"name" => "action", |
| 27 |
"display" => "block", |
| 28 |
"title" => __( "Action", 'timed-content' ), |
| 29 |
"description" => __( "Sets the action to be performed when the rule is active.", 'timed-content' ), |
| 30 |
"type" => "radio", |
| 31 |
"values" => array( 1 => __( "Show the content", 'timed-content' ), |
| 32 |
0 => __( "Hide the content", 'timed-content' ) ), |
| 33 |
"default" => 1, |
| 34 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 35 |
"capability" => "edit_posts" |
| 36 |
), |
| 37 |
array( |
| 38 |
"name" => "instance_start", |
| 39 |
"display" => "block", |
| 40 |
"title" => __( "Starting Date/Time", 'timed-content' ), |
| 41 |
"description" => __( "Sets the date and time for the beginning of the first active period for this rule.", 'timed-content' ), |
| 42 |
"type" => "datetime", |
| 43 |
"default" => array( "date" => date_i18n( _x( "F jS, Y", "Starting Date/Time date format (http://ca2.php.net/manual/en/function.date.php)", 'timed-content'), strtotime( "+1 hour", $now_t ) ), |
| 44 |
"time" => date_i18n( _x( "g:i A", "Starting Date/Time time format (http://ca2.php.net/manual/en/function.date.php)", 'timed-content'), strtotime( "+1 hour", $now_t ) ) ), |
| 45 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 46 |
"capability" => "edit_posts" |
| 47 |
), |
| 48 |
array( |
| 49 |
"name" => "instance_end", |
| 50 |
"display" => "block", |
| 51 |
"title" => __( "Ending Date/Time", 'timed-content' ), |
| 52 |
"description" => __( "Sets the date and time for the end of the first active period for this rule.", 'timed-content' ), |
| 53 |
"type" => "datetime", |
| 54 |
"default" => array( "date" => date_i18n( _x( "F jS, Y", "Ending Date/Time date format (http://ca2.php.net/manual/en/function.date.php)", 'timed-content'), strtotime( "+2 hour", $now_t ) ), |
| 55 |
"time" => date_i18n( _x( "g:i A", "Ending Date/Time time format (http://ca2.php.net/manual/en/function.date.php)", 'timed-content'), strtotime( "+2 hour", $now_t ) ) ), |
| 56 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 57 |
"capability" => "edit_posts" |
| 58 |
), |
| 59 |
array( |
| 60 |
"name" => "timezone", |
| 61 |
"display" => "block", |
| 62 |
"title" => __( "Timezone:", 'timed-content' ), |
| 63 |
"description" => __( "Select a city in the timezone you wish to use for this rule.", 'timed-content' ), |
| 64 |
"type" => "timezone-list", |
| 65 |
"default" => get_option( 'timezone_string' ), |
| 66 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 67 |
"capability" => "edit_posts" |
| 68 |
) |
| 69 |
); |
| 70 |
$timed_content_rule_pattern_custom_fields = array( |
| 71 |
array( |
| 72 |
"name" => "frequency", |
| 73 |
"display" => "block", |
| 74 |
"title" => __( "Frequency:", 'timed-content' ), |
| 75 |
"description" => __( "Sets the frequency at which the action should be repeated.", 'timed-content' ), |
| 76 |
"type" => "list", |
| 77 |
"default" => "1", |
| 78 |
"values" => $timed_content_rule_freq_array, |
| 79 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 80 |
"capability" => "edit_posts" |
| 81 |
), |
| 82 |
array( |
| 83 |
"name" => "hourly_num_of_hours", |
| 84 |
"display" => "none", |
| 85 |
"title" => __( "Repeat How Often?", 'timed-content' ), |
| 86 |
"description" => __( "If the frequency is set to Hourly, repeat this action every X hours.", 'timed-content' ), |
| 87 |
"type" => "number", |
| 88 |
"default" => "1", |
| 89 |
"min" => "1", |
| 90 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 91 |
"capability" => "edit_posts" |
| 92 |
), |
| 93 |
array( |
| 94 |
"name" => "daily_num_of_days", |
| 95 |
"display" => "none", |
| 96 |
"title" => __( "Repeat How Often?", 'timed-content' ), |
| 97 |
"description" => __( "If the frequency is set to Daily, repeat this action every X days.", 'timed-content' ), |
| 98 |
"type" => "number", |
| 99 |
"default" => "1", |
| 100 |
"min" => "1", |
| 101 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 102 |
"capability" => "edit_posts" |
| 103 |
), |
| 104 |
array( |
| 105 |
"name" => "weekly_num_of_weeks", |
| 106 |
"display" => "none", |
| 107 |
"title" => __( "Repeat How Often?", 'timed-content' ), |
| 108 |
"description" => __( "If the frequency is set to Weekly, repeat this action every X weeks.", 'timed-content' ), |
| 109 |
"type" => "number", |
| 110 |
"default" => "1", |
| 111 |
"min" => "1", |
| 112 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 113 |
"capability" => "edit_posts" |
| 114 |
), |
| 115 |
array( |
| 116 |
"name" => "weekly_days_of_week_to_repeat", |
| 117 |
"display" => "none", |
| 118 |
"title" => __( "Repeat On The Following Days", 'timed-content' ), |
| 119 |
"description" => __( "If the frequency is set to Weekly, repeat this action on these days of the week INSTEAD of the day of week the Starting Date/Time falls on.", 'timed-content' ), |
| 120 |
"type" => "checkbox-list", |
| 121 |
"default" => array(), |
| 122 |
"values" => $timed_content_rule_days_array, |
| 123 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 124 |
"capability" => "edit_posts" |
| 125 |
), |
| 126 |
array( |
| 127 |
"name" => "monthly_num_of_months", |
| 128 |
"display" => "none", |
| 129 |
"title" => __( "Repeat How Often?", 'timed-content' ), |
| 130 |
"description" => __( "If the frequency is set to Monthly, repeat this action every X months.", 'timed-content' ), |
| 131 |
"type" => "number", |
| 132 |
"default" => "1", |
| 133 |
"min" => "1", |
| 134 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 135 |
"capability" => "edit_posts" |
| 136 |
), |
| 137 |
array( |
| 138 |
"name" => "monthly_nth_weekday_of_month", |
| 139 |
"display" => "none", |
| 140 |
"title" => __( "Repeat On The Nth Weekday Of The Month?", 'timed-content' ), |
| 141 |
"description" => __( "If the frequency is set to Monthly, repeat this action on the Nth weekday of the month (for example, 'every third Tuesday'). Check this box to select a pattern below.", 'timed-content' ), |
| 142 |
"type" => "checkbox", |
| 143 |
"default" => "no", |
| 144 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 145 |
"capability" => "edit_posts" |
| 146 |
), |
| 147 |
array( |
| 148 |
"name" => "monthly_nth_weekday_of_month_nth", |
| 149 |
"display" => "none", |
| 150 |
"title" => __( "Nth Weekday Ordinal:", 'timed-content' ), |
| 151 |
"description" => __( "Select a value for the Nth (for example 'first', 'second', etc.) week of the month.", 'timed-content' ), |
| 152 |
"type" => "list", |
| 153 |
"default" => 0, |
| 154 |
"values" => $timed_content_rule_ordinal_array, |
| 155 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 156 |
"capability" => "edit_posts" |
| 157 |
), |
| 158 |
array( |
| 159 |
"name" => "monthly_nth_weekday_of_month_weekday", |
| 160 |
"display" => "none", |
| 161 |
"title" => __( "Nth Weekday Day Of Week:", 'timed-content' ), |
| 162 |
"description" => __( "Select the day of week to repeat on.", 'timed-content' ), |
| 163 |
"type" => "list", |
| 164 |
"default" => 0, |
| 165 |
"values" => $timed_content_rule_ordinal_days_array, |
| 166 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 167 |
"capability" => "edit_posts" |
| 168 |
), |
| 169 |
array( |
| 170 |
"name" => "yearly_num_of_years", |
| 171 |
"display" => "none", |
| 172 |
"title" => __( "Repeat How Often?", 'timed-content' ), |
| 173 |
"description" => __( "If the frequency is set to Yearly, repeat this action every X years.", 'timed-content' ), |
| 174 |
"type" => "number", |
| 175 |
"default" => "1", |
| 176 |
"min" => "1", |
| 177 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 178 |
"capability" => "edit_posts" |
| 179 |
) |
| 180 |
); |
| 181 |
$timed_content_rule_recurrence_custom_fields = array( |
| 182 |
array( |
| 183 |
"name" => "recurrence_duration", |
| 184 |
"display" => "block", |
| 185 |
"title" => __( "How Often To Repeat This Action?", 'timed-content' ), |
| 186 |
"description" => "", |
| 187 |
"type" => "radio", |
| 188 |
"values" => array( "recurrence_duration_end_date" => __( "Keep repeating until a given date", 'timed-content' ), |
| 189 |
"recurrence_duration_num_repeat" => __( "Repeat a set number of times", 'timed-content' ) ), |
| 190 |
"default" => "recurrence_duration_end_date", |
| 191 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 192 |
"capability" => "edit_posts" |
| 193 |
), |
| 194 |
array( |
| 195 |
"name" => "recurrence_duration_end_date", |
| 196 |
"display" => "none", |
| 197 |
"title" => __( "End Date:", 'timed-content' ), |
| 198 |
"description" => __( "Using the settings above, repeat this action until this date.", 'timed-content' ), |
| 199 |
"type" => "date", |
| 200 |
"default" => date_i18n( _x( "F jS, Y", "End Date date format (http://ca2.php.net/manual/en/function.date.php)", 'timed-content'), strtotime( "+1 year", $now_t ) ), |
| 201 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 202 |
"capability" => "edit_posts" |
| 203 |
), |
| 204 |
array( |
| 205 |
"name" => "recurrence_duration_num_repeat", |
| 206 |
"display" => "none", |
| 207 |
"title" => __( "Repeat How Many Times?", 'timed-content' ), |
| 208 |
"description" => __( "Using the settings above, repeat this action this many times.", 'timed-content' ), |
| 209 |
"type" => "number", |
| 210 |
"default" => "1", |
| 211 |
"min" => "1", |
| 212 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 213 |
"capability" => "edit_posts" |
| 214 |
) |
| 215 |
); |
| 216 |
$exceptions_dates_picker_on_select = <<<FUNC |
| 217 |
onSelect: function (dateText, inst) { |
| 218 |
//alert(dateText); |
| 219 |
jQuery("#timed_content_rule_exceptions_dates option[value='0']" ).remove(); |
| 220 |
jQuery("#timed_content_rule_exceptions_dates").append( '<option value="' + parseInt(Date.parse(dateText) / 1000) + '">' + dateText + '</option>' ); |
| 221 |
jQuery(this).val(""); |
| 222 |
jQuery(this).trigger("change"); |
| 223 |
}, |
| 224 |
FUNC; |
| 225 |
|
| 226 |
$timed_content_rule_exceptions_custom_fields = array( |
| 227 |
array( |
| 228 |
"name" => "exceptions_dates_picker", |
| 229 |
"display" => "block", |
| 230 |
"title" => __( "Add Exception Date:", 'timed-content' ), |
| 231 |
"description" => __( "Select a date to add to the Exception Dates List.", 'timed-content' ), |
| 232 |
"type" => "date", |
| 233 |
"default" => "", |
| 234 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 235 |
"capability" => "edit_posts", |
| 236 |
"custom_functions" => $exceptions_dates_picker_on_select |
| 237 |
), |
| 238 |
array( |
| 239 |
"name" => "exceptions_dates", |
| 240 |
"display" => "block", |
| 241 |
"title" => __( "Exception Dates List", 'timed-content' ), |
| 242 |
"description" => __( "Dates that this Timed Content Rule will not be active. Double-click on a date to remove it from the list.", 'timed-content' ), |
| 243 |
"type" => "menu", |
| 244 |
"values" => $timed_content_rules_exceptions_dates_array, |
| 245 |
"size" => "10", |
| 246 |
"default" => array(), |
| 247 |
"scope" => array( TIMED_CONTENT_RULE_TYPE ), |
| 248 |
"capability" => "edit_posts" |
| 249 |
) |
| 250 |
); |
| 251 |
|
| 252 |
?> |