My Calendar - Version 3.1.13

Version Description

  • Bug fix: If plug-in name is translated, script references were broken.
  • Bug fix: If no holiday category assigned, Today's Events widget will return empty when category limits set.
  • New filter: allow events post type to be made searchable. (Not recommended.)
  • New: Support 'search' parameter in shortcode & URL parameters for main view.
  • Remove option to disable max contrast category names.
Download this release

Release Info

Developer joedolson
Plugin Icon 128x128 My Calendar
Version 3.1.13
Comparing to
See all releases

Code changes from version 3.1.12 to 3.1.13

includes/date-utilities.php CHANGED
@@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
23
function mc_dateclass( $current ) {
24
$now = current_time( 'timestamp' );
25
$dayclass = sanitize_html_class( strtolower( date_i18n( 'l', $current ) ) ) . ' ' . sanitize_html_class( strtolower( date_i18n( 'D', $current ) ) );
26
- if ( date( 'Ymd', $now ) == date( 'Ymd', $current ) ) {
27
$dateclass = 'current-day';
28
} elseif ( my_calendar_date_comp( date( 'Y-m-d', $now ), date( 'Y-m-d', $current ) ) ) {
29
$dateclass = 'future-day';
@@ -103,7 +103,7 @@ function my_calendar_date_equal( $early, $late ) {
103
// convert full datetime to date only.
104
$firstdate = strtotime( date( 'Y-m-d', strtotime( $early ) ) );
105
$lastdate = strtotime( date( 'Y-m-d', strtotime( $late ) ) );
106
- if ( $firstdate == $lastdate ) {
107
108
return true;
109
} else {
@@ -121,7 +121,7 @@ function my_calendar_date_equal( $early, $late ) {
121
* @return int (ternary value)
122
*/
123
function mc_time_cmp( $a, $b ) {
124
- if ( $a->occur_begin == $b->occur_begin ) {
125
126
return 0;
127
}
@@ -140,7 +140,7 @@ function mc_time_cmp( $a, $b ) {
140
function mc_datetime_cmp( $a, $b ) {
141
$event_dt_a = strtotime( $a->occur_begin );
142
$event_dt_b = strtotime( $b->occur_begin );
143
- if ( $event_dt_a == $event_dt_b ) {
144
// this should sub-sort by title if date is the same. But it doesn't seem to.
145
$ta = $a->event_title;
146
$tb = $b->event_title;
@@ -167,7 +167,7 @@ function mc_timediff_cmp( $a, $b ) {
167
$diff_a = mc_date_diff_precise( $event_dt_a );
168
$diff_b = mc_date_diff_precise( $event_dt_b );
169
170
- if ( $diff_a == $diff_b ) {
171
return 0;
172
}
173
@@ -183,7 +183,7 @@ function mc_timediff_cmp( $a, $b ) {
183
* @return absolute time diff
184
*/
185
function mc_date_diff_precise( $start, $end = 'NOW' ) {
186
- if ( 'NOW' == $end ) {
187
$end = strtotime( 'NOW' );
188
}
189
$sdate = $start;
@@ -248,7 +248,7 @@ function mc_checkdate( $date ) {
248
* @return array day and month
249
*/
250
function mc_first_day_of_week( $date = false ) {
251
- $start_of_week = ( get_option( 'start_of_week' ) == 1 || get_option( 'start_of_week' ) == 0 ) ? get_option( 'start_of_week' ) : 0;
252
if ( $date ) {
253
$today = date( 'w', $date );
254
$now = date( 'Y-m-d', $date );
@@ -260,30 +260,30 @@ function mc_first_day_of_week( $date = false ) {
260
$sub = 0; // don't change month.
261
switch ( $today ) {
262
case 1:
263
- $sub = ( 1 == $start_of_week ) ? 0 : 1;
264
break; // mon.
265
case 2:
266
- $sub = ( 1 == $start_of_week ) ? 1 : 2;
267
break; // tues.
268
case 3:
269
- $sub = ( 1 == $start_of_week ) ? 2 : 3;
270
break; // wed.
271
case 4:
272
- $sub = ( 1 == $start_of_week ) ? 3 : 4;
273
break; // thu.
274
case 5:
275
- $sub = ( 1 == $start_of_week ) ? 4 : 5;
276
break; // fri.
277
case 6:
278
- $sub = ( 1 == $start_of_week ) ? 5 : 6;
279
break; // sat.
280
case 0:
281
- $sub = ( 1 == $start_of_week ) ? 6 : 0;
282
break; // sun.
283
}
284
$day = date( 'j', strtotime( $now . ' -' . $sub . ' day' ) );
285
- if ( 0 != $sub ) {
286
- if ( date( 'n', strtotime( $now . ' -' . $sub . ' day' ) ) != date( 'n', strtotime( $now ) ) ) {
287
$month = - 1;
288
} else {
289
$month = 0;
@@ -344,7 +344,7 @@ function mc_name_days( $format ) {
344
'<abbr title="' . date_i18n( 'l', strtotime( 'Friday' ) ) . '" aria-hidden="true">' . date_i18n( 'D', strtotime( 'Friday' ) ) . '</abbr><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Friday' ) ) . '</span>',
345
'<abbr title="' . date_i18n( 'l', strtotime( 'Saturday' ) ) . '" aria-hidden="true">' . date_i18n( 'D', strtotime( 'Saturday' ) ) . '</abbr><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Saturday' ) ) . '</span>',
346
);
347
- if ( 'mini' == $format ) {
348
// PHP doesn't have a single letter abbreviation, so this has to be a translatable.
349
$name_days = array(
350
'<span aria-hidden="true">' . __( '<abbr title="Sunday">S</abbr>', 'my-calendar' ) . '</span><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Sunday' ) ) . '</span>',
@@ -380,10 +380,10 @@ function mc_exit_early( $event, $process_date ) {
380
$end = date( 'Y-m-d', strtotime( $event->occur_end ) );
381
// if event ends at midnight today (e.g., very first thing of the day), exit without re-drawing.
382
// or if event started yesterday & has event_hide_end checked.
383
- $ends_at_midnight = ( '00:00:00' == $event->event_endtime && $end == $process_date && $current != $today ) ? true : false;
384
385
// hides events if hiding end time & not first day.
386
- $hide_day_two = ( $hide_days && ( $today != $current ) ) ? true : false;
387
388
if ( $ends_at_midnight || $hide_day_two ) {
389
return true;
@@ -404,7 +404,7 @@ function mc_exit_early( $event, $process_date ) {
404
* @return boolean
405
*/
406
function mc_private_event( $event ) {
407
- $status = ( 1 == $event->category_private && ! is_user_logged_in() ) ? true : false;
408
// custom filter to grant custom reasons for exiting.
409
// $event may not be an event object; in some cases it's a category object.
410
$status = apply_filters( 'mc_private_event', $status, $event );
23
function mc_dateclass( $current ) {
24
$now = current_time( 'timestamp' );
25
$dayclass = sanitize_html_class( strtolower( date_i18n( 'l', $current ) ) ) . ' ' . sanitize_html_class( strtolower( date_i18n( 'D', $current ) ) );
26
+ if ( date( 'Ymd', $now ) === date( 'Ymd', $current ) ) {
27
$dateclass = 'current-day';
28
} elseif ( my_calendar_date_comp( date( 'Y-m-d', $now ), date( 'Y-m-d', $current ) ) ) {
29
$dateclass = 'future-day';
103
// convert full datetime to date only.
104
$firstdate = strtotime( date( 'Y-m-d', strtotime( $early ) ) );
105
$lastdate = strtotime( date( 'Y-m-d', strtotime( $late ) ) );
106
+ if ( $firstdate === $lastdate ) {
107
108
return true;
109
} else {
121
* @return int (ternary value)
122
*/
123
function mc_time_cmp( $a, $b ) {
124
+ if ( $a->occur_begin === $b->occur_begin ) {
125
126
return 0;
127
}
140
function mc_datetime_cmp( $a, $b ) {
141
$event_dt_a = strtotime( $a->occur_begin );
142
$event_dt_b = strtotime( $b->occur_begin );
143
+ if ( $event_dt_a === $event_dt_b ) {
144
// this should sub-sort by title if date is the same. But it doesn't seem to.
145
$ta = $a->event_title;
146
$tb = $b->event_title;
167
$diff_a = mc_date_diff_precise( $event_dt_a );
168
$diff_b = mc_date_diff_precise( $event_dt_b );
169
170
+ if ( $diff_a === $diff_b ) {
171
return 0;
172
}
173
183
* @return absolute time diff
184
*/
185
function mc_date_diff_precise( $start, $end = 'NOW' ) {
186
+ if ( 'NOW' === $end ) {
187
$end = strtotime( 'NOW' );
188
}
189
$sdate = $start;
248
* @return array day and month
249
*/
250
function mc_first_day_of_week( $date = false ) {
251
+ $start_of_week = ( get_option( 'start_of_week' ) === '1' || get_option( 'start_of_week' ) === '0' ) ? absint( get_option( 'start_of_week' ) ) : 0;
252
if ( $date ) {
253
$today = date( 'w', $date );
254
$now = date( 'Y-m-d', $date );
260
$sub = 0; // don't change month.
261
switch ( $today ) {
262
case 1:
263
+ $sub = ( 1 === $start_of_week ) ? 0 : 1;
264
break; // mon.
265
case 2:
266
+ $sub = ( 1 === $start_of_week ) ? 1 : 2;
267
break; // tues.
268
case 3:
269
+ $sub = ( 1 === $start_of_week ) ? 2 : 3;
270
break; // wed.
271
case 4:
272
+ $sub = ( 1 === $start_of_week ) ? 3 : 4;
273
break; // thu.
274
case 5:
275
+ $sub = ( 1 === $start_of_week ) ? 4 : 5;
276
break; // fri.
277
case 6:
278
+ $sub = ( 1 === $start_of_week ) ? 5 : 6;
279
break; // sat.
280
case 0:
281
+ $sub = ( 1 === $start_of_week ) ? 6 : 0;
282
break; // sun.
283
}
284
$day = date( 'j', strtotime( $now . ' -' . $sub . ' day' ) );
285
+ if ( 0 !== $sub ) {
286
+ if ( date( 'n', strtotime( $now . ' -' . $sub . ' day' ) ) !== date( 'n', strtotime( $now ) ) ) {
287
$month = - 1;
288
} else {
289
$month = 0;
344
'<abbr title="' . date_i18n( 'l', strtotime( 'Friday' ) ) . '" aria-hidden="true">' . date_i18n( 'D', strtotime( 'Friday' ) ) . '</abbr><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Friday' ) ) . '</span>',
345
'<abbr title="' . date_i18n( 'l', strtotime( 'Saturday' ) ) . '" aria-hidden="true">' . date_i18n( 'D', strtotime( 'Saturday' ) ) . '</abbr><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Saturday' ) ) . '</span>',
346
);
347
+ if ( 'mini' === $format ) {
348
// PHP doesn't have a single letter abbreviation, so this has to be a translatable.
349
$name_days = array(
350
'<span aria-hidden="true">' . __( '<abbr title="Sunday">S</abbr>', 'my-calendar' ) . '</span><span class="screen-reader-text">' . date_i18n( 'l', strtotime( 'Sunday' ) ) . '</span>',
380
$end = date( 'Y-m-d', strtotime( $event->occur_end ) );
381
// if event ends at midnight today (e.g., very first thing of the day), exit without re-drawing.
382
// or if event started yesterday & has event_hide_end checked.
383
+ $ends_at_midnight = ( '00:00:00' === $event->event_endtime && $end === $process_date && $current !== $today ) ? true : false;
384
385
// hides events if hiding end time & not first day.
386
+ $hide_day_two = ( $hide_days && ( $today !== $current ) ) ? true : false;
387
388
if ( $ends_at_midnight || $hide_day_two ) {
389
return true;
404
* @return boolean
405
*/
406
function mc_private_event( $event ) {
407
+ $status = ( 1 === absint( $event->category_private ) && ! is_user_logged_in() ) ? true : false;
408
// custom filter to grant custom reasons for exiting.
409
// $event may not be an event object; in some cases it's a category object.
410
$status = apply_filters( 'mc_private_event', $status, $event );
includes/db.php CHANGED
@@ -86,7 +86,7 @@ function my_calendar_select_table( $table = 'my_calendar_events', $site = false
86
$option = (int) get_site_option( 'mc_multisite' );
87
$choice = (int) get_option( 'mc_current_table' );
88
$show = (int) get_site_option( 'mc_multisite_show' ); // 1 == use global instead of local.
89
- if ( 'global' == $site ) {
90
return $wpdb->base_prefix . $table;
91
}
92
if ( false != $site && $site ) {
86
$option = (int) get_site_option( 'mc_multisite' );
87
$choice = (int) get_option( 'mc_current_table' );
88
$show = (int) get_site_option( 'mc_multisite_show' ); // 1 == use global instead of local.
89
+ if ( 'global' === $site ) {
90
return $wpdb->base_prefix . $table;
91
}
92
if ( false != $site && $site ) {
includes/deprecated.php CHANGED
@@ -12,7 +12,7 @@
12
13
// Define the table constants used in My Calendar in case anybody is still using them.
14
// These were eliminated some time ago.
15
- if ( is_multisite() && get_site_option( 'mc_multisite_show' ) == 1 ) {
16
define( 'MY_CALENDAR_TABLE', $wpdb->base_prefix . 'my_calendar' );
17
define( 'MY_CALENDAR_EVENTS_TABLE', $wpdb->base_prefix . 'my_calendar_events' );
18
define( 'MY_CALENDAR_CATEGORIES_TABLE', $wpdb->base_prefix . 'my_calendar_categories' );
@@ -165,7 +165,8 @@ function my_calendar_is_odd( $int ) {
165
* @return string label
166
*/
167
function mc_event_repeats_forever( $recur, $repeats ) {
168
- if ( 'S' != $recur && 0 == $repeats ) {
169
return true;
170
}
171
switch ( $recur ) {
@@ -173,20 +174,20 @@ function mc_event_repeats_forever( $recur, $repeats ) {
173
return false;
174
break;
175
case 'D': // daily.
176
- return ( 500 == $repeats ) ? true : false;
177
break;
178
case 'W': // weekly.
179
- return ( 240 == $repeats ) ? true : false;
180
break;
181
case 'B': // biweekly.
182
- return ( 120 == $repeats ) ? true : false;
183
break;
184
case 'M': // monthly.
185
case 'U':
186
- return ( 60 == $repeats ) ? true : false;
187
break;
188
case 'Y':
189
- return ( 5 == $repeats ) ? true : false;
190
break;
191
default:
192
return false;
@@ -201,10 +202,10 @@ if ( ! function_exists( 'is_ssl' ) ) {
201
*/
202
function is_ssl() {
203
if ( isset( $_SERVER['HTTPS'] ) ) {
204
- if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
205
return true;
206
}
207
- if ( '1' == $_SERVER['HTTPS'] ) {
208
return true;
209
}
210
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
@@ -241,7 +242,7 @@ function jd_draw_template( $array, $template, $type = 'list' ) {
241
* @return boolean
242
*/
243
function mc_dates_consecutive( $current, $last_date ) {
244
- if ( strtotime( $last_date . '+ 1 day' ) == strtotime( $current ) ) {
245
246
return true;
247
} else {
@@ -260,7 +261,7 @@ function mc_dates_consecutive( $current, $last_date ) {
260
function my_calendar_reverse_datetime_cmp( $b, $a ) {
261
$event_dt_a = strtotime( $a->occur_begin );
262
$event_dt_b = strtotime( $b->occur_begin );
263
- if ( $event_dt_a == $event_dt_b ) {
264
return 0;
265
}
266
@@ -302,7 +303,7 @@ function jd_date_diff( $start, $end = 'NOW' ) {
302
*/
303
function get_week_date( $week, $year ) {
304
// Get the target week of the year with reference to the starting day of the year.
305
- $start_of_week = ( get_option( 'start_of_week' ) == 1 || get_option( 'start_of_week' ) == 0 ) ? get_option( 'start_of_week' ) : 0;
306
$target_week = strtotime( "$week week", strtotime( "1 January $year" ) );
307
$date_info = getdate( $target_week );
308
$day_of_week = $date_info['wday'];
12
13
// Define the table constants used in My Calendar in case anybody is still using them.
14
// These were eliminated some time ago.
15
+ if ( is_multisite() && get_site_option( 'mc_multisite_show' ) === '1' ) {
16
define( 'MY_CALENDAR_TABLE', $wpdb->base_prefix . 'my_calendar' );
17
define( 'MY_CALENDAR_EVENTS_TABLE', $wpdb->base_prefix . 'my_calendar_events' );
18
define( 'MY_CALENDAR_CATEGORIES_TABLE', $wpdb->base_prefix . 'my_calendar_categories' );
165
* @return string label
166
*/
167
function mc_event_repeats_forever( $recur, $repeats ) {
168
+ $repeats = absint( $repeats );
169
+ if ( 'S' !== $recur && 0 === $repeats ) {
170
return true;
171
}
172
switch ( $recur ) {
174
return false;
175
break;
176
case 'D': // daily.
177
+ return ( 500 === $repeats ) ? true : false;
178
break;
179
case 'W': // weekly.
180
+ return ( 240 === $repeats ) ? true : false;
181
break;
182
case 'B': // biweekly.
183
+ return ( 120 === $repeats ) ? true : false;
184
break;
185
case 'M': // monthly.
186
case 'U':
187
+ return ( 60 === $repeats ) ? true : false;
188
break;
189
case 'Y':
190
+ return ( 5 === $repeats ) ? true : false;
191
break;
192
default:
193
return false;
202
*/
203
function is_ssl() {
204
if ( isset( $_SERVER['HTTPS'] ) ) {
205
+ if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
206
return true;
207
}
208
+ if ( '1' === $_SERVER['HTTPS'] ) {
209
return true;
210
}
211
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
242
* @return boolean
243
*/
244
function mc_dates_consecutive( $current, $last_date ) {
245
+ if ( strtotime( $last_date . '+ 1 day' ) === strtotime( $current ) ) {
246
247
return true;
248
} else {
261
function my_calendar_reverse_datetime_cmp( $b, $a ) {
262
$event_dt_a = strtotime( $a->occur_begin );
263
$event_dt_b = strtotime( $b->occur_begin );
264
+ if ( $event_dt_a === $event_dt_b ) {
265
return 0;
266
}
267
303
*/
304
function get_week_date( $week, $year ) {
305
// Get the target week of the year with reference to the starting day of the year.
306
+ $start_of_week = ( get_option( 'start_of_week' ) === '1' || get_option( 'start_of_week' ) === '0' ) ? get_option( 'start_of_week' ) : 0;
307
$target_week = strtotime( "$week week", strtotime( "1 January $year" ) );
308
$date_info = getdate( $target_week );
309
$day_of_week = $date_info['wday'];
my-calendar-api.php CHANGED
@@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
18
*/
19
function my_calendar_api() {
20
if ( isset( $_REQUEST['my-calendar-api'] ) ) {
21
- if ( 'true' == get_option( 'mc_api_enabled' ) ) {
22
// use this filter to add custom scripting handling API keys.
23
$api_key = apply_filters( 'mc_api_key', true );
24
if ( $api_key ) {
@@ -273,7 +273,7 @@ function mc_format_rss( $events ) {
273
{guid}
274
</item>' . PHP_EOL;
275
276
- if ( get_option( 'mc_use_rss_template' ) == 1 ) {
277
$template = mc_get_template( 'rss' );
278
}
279
@@ -453,7 +453,7 @@ function mc_api_format_ical( $data ) {
453
}
454
}
455
$output = html_entity_decode( preg_replace( "~(?<!\r)\n~", "\r\n", $templates['head'] . $output . $templates['foot'] ) );
456
- if ( ! ( isset( $_GET['sync'] ) && 'true' == $_GET['sync'] ) ) {
457
$sitename = sanitize_title( get_bloginfo( 'name' ) );
458
header( 'Content-Type: text/calendar; charset=UTF-8' );
459
header( 'Pragma: no-cache' );
@@ -531,8 +531,8 @@ function mc_generate_alert_ical( $alarm ) {
531
$values = array_merge( $defaults, $alarm );
532
$alert = PHP_EOL . 'BEGIN:VALARM' . PHP_EOL;
533
$alert .= "TRIGGER:$values[TRIGGER]\n";
534
- $alert .= ( 0 != $values['REPEAT'] ) ? "REPEAT:$values[REPEAT]\n" : '';
535
- $alert .= ( '' != $values['DURATION'] ) ? "REPEAT:$values[DURATION]\n" : '';
536
$alert .= "ACTION:$values[ACTION]\n";
537
$alert .= "DESCRIPTION:$values[DESCRIPTION]\n";
538
$alert .= 'END:VALARM';
18
*/
19
function my_calendar_api() {
20
if ( isset( $_REQUEST['my-calendar-api'] ) ) {
21
+ if ( 'true' === get_option( 'mc_api_enabled' ) ) {
22
// use this filter to add custom scripting handling API keys.
23
$api_key = apply_filters( 'mc_api_key', true );
24
if ( $api_key ) {
273
{guid}
274
</item>' . PHP_EOL;
275
276
+ if ( get_option( 'mc_use_rss_template' ) === '1' ) {
277
$template = mc_get_template( 'rss' );
278
}
279
453
}
454
}
455
$output = html_entity_decode( preg_replace( "~(?<!\r)\n~", "\r\n", $templates['head'] . $output . $templates['foot'] ) );
456
+ if ( ! ( isset( $_GET['sync'] ) && 'true' === $_GET['sync'] ) ) {
457
$sitename = sanitize_title( get_bloginfo( 'name' ) );
458
header( 'Content-Type: text/calendar; charset=UTF-8' );
459
header( 'Pragma: no-cache' );
531
$values = array_merge( $defaults, $alarm );
532
$alert = PHP_EOL . 'BEGIN:VALARM' . PHP_EOL;
533
$alert .= "TRIGGER:$values[TRIGGER]\n";
534
+ $alert .= ( '0' !== $values['REPEAT'] ) ? "REPEAT:$values[REPEAT]\n" : '';
535
+ $alert .= ( '' !== $values['DURATION'] ) ? "REPEAT:$values[DURATION]\n" : '';
536
$alert .= "ACTION:$values[ACTION]\n";
537
$alert .= "DESCRIPTION:$values[DESCRIPTION]\n";
538
$alert .= 'END:VALARM';
my-calendar-behaviors.php CHANGED
@@ -41,7 +41,7 @@ function my_calendar_behaviors_edit() {
41
update_option( 'mc_ajaxjs', $mc_ajaxjs );
42
}
43
44
- $mc_show_js = ( '' == $_POST['mc_show_js'] ) ? '' : $_POST['mc_show_js'];
45
update_option( 'mc_show_js', $mc_show_js );
46
mc_show_notice( __( 'Behavior Settings saved', 'my-calendar' ) );
47
}
@@ -97,7 +97,7 @@ function my_calendar_behaviors_edit() {
97
<label for="ajax_js"><?php _e( 'Disable AJAX', 'my-calendar' ); ?></label></li>
98
</ul>
99
</div>
100
- <?php if ( get_option( 'mc_use_custom_js' ) == 1 ) { ?>
101
<p>
102
<label for="calendar-js"><?php _e( 'Calendar Behaviors: Grid View', 'my-calendar' ); ?></label><br/><textarea id="calendar-js" name="mc_caljs" rows="12" cols="80"><?php echo esc_textarea( $mc_caljs ); ?></textarea>
103
</p>
41
update_option( 'mc_ajaxjs', $mc_ajaxjs );
42
}
43
44
+ $mc_show_js = ( '' === $_POST['mc_show_js'] ) ? '' : $_POST['mc_show_js'];
45
update_option( 'mc_show_js', $mc_show_js );
46
mc_show_notice( __( 'Behavior Settings saved', 'my-calendar' ) );
47
}
97
<label for="ajax_js"><?php _e( 'Disable AJAX', 'my-calendar' ); ?></label></li>
98
</ul>
99
</div>
100
+ <?php if ( get_option( 'mc_use_custom_js' ) === '1' ) { ?>
101
<p>
102
<label for="calendar-js"><?php _e( 'Calendar Behaviors: Grid View', 'my-calendar' ); ?></label><br/><textarea id="calendar-js" name="mc_caljs" rows="12" cols="80"><?php echo esc_textarea( $mc_caljs ); ?></textarea>
103
</p>
my-calendar-categories.php CHANGED
@@ -481,7 +481,6 @@ function mc_category_settings_update() {
481
if ( isset( $_POST['mc_category_settings'] ) && wp_verify_nonce( $nonce, 'my-calendar-nonce' ) ) {
482
update_option( 'mc_hide_icons', ( ! empty( $_POST['mc_hide_icons'] ) && 'on' == $_POST['mc_hide_icons'] ) ? 'true' : 'false' );
483
update_option( 'mc_apply_color', $_POST['mc_apply_color'] );
484
- update_option( 'mc_inverse_color', ( ! empty( $_POST['mc_inverse_color'] ) && 'on' == $_POST['mc_inverse_color'] ) ? 'true' : 'false' );
485
update_option( 'mc_multiple_categories', ( ! empty( $_POST['mc_multiple_categories'] ) && 'on' == $_POST['mc_multiple_categories'] ) ? 'true' : 'false' );
486
487
$message = mc_show_notice( __( 'My Calendar Category Configuration Updated', 'my-calendar' ), false );
@@ -523,7 +522,6 @@ function mc_category_settings() {
523
</ul>
524
</fieldset>
525
<ul>
526
- <li>' . mc_settings_field( 'mc_inverse_color', __( 'Optimize contrast for category colors.', 'my-calendar' ), '', '', array(), 'checkbox-single', false ) . '
527
<li>' . mc_settings_field( 'mc_hide_icons', __( 'Hide Category icons', 'my-calendar' ), '', '', array(), 'checkbox-single', false ) . '</li>
528
<li>' . mc_settings_field( 'mc_multiple_categories', __( 'Use multiple categories on events', 'my-calendar' ), '', '', array(), 'checkbox-single', false ) . '</li>
529
</ul>
@@ -713,7 +711,7 @@ function mc_profile() {
713
714
if ( user_can( $user_edit, 'mc_manage_events' ) && current_user_can( 'manage_options' ) ) {
715
$permissions = get_user_meta( $user_edit, 'mc_user_permissions', true );
716
- $selected = ( empty( $permissions ) || in_array( 'all', $permissions ) ) ? ' checked="checked"' : '';
717
?>
718
<h3><?php _e( 'My Calendar Editor Permissions', 'my-calendar' ); ?></h3>
719
<table class="form-table">
@@ -827,11 +825,12 @@ function mc_category_select( $data = false, $option = true, $multiple = false, $
827
$selected = ' checked="checked"';
828
}
829
}
830
-
831
if ( $multiple ) {
832
- $c = '<li><input type="checkbox" name="' . esc_attr( $name ) . '" id="mc_cat_' . $cat->category_id . '" value="' . $cat->category_id . '" ' . $selected . ' /><label for="mc_cat_' . $cat->category_id . '">' . strip_tags( stripslashes( $cat->category_name ) ) . '</label></li>';
833
} else {
834
- $c = '<option value="' . $cat->category_id . '" ' . $selected . '>' . strip_tags( stripslashes( $cat->category_name ) ) . '</option>';
835
}
836
if ( get_option( 'mc_default_category' ) != $cat->category_id ) {
837
$list .= $c;
481
if ( isset( $_POST['mc_category_settings'] ) && wp_verify_nonce( $nonce, 'my-calendar-nonce' ) ) {
482
update_option( 'mc_hide_icons', ( ! empty( $_POST['mc_hide_icons'] ) && 'on' == $_POST['mc_hide_icons'] ) ? 'true' : 'false' );
483
update_option( 'mc_apply_color', $_POST['mc_apply_color'] );
484
update_option( 'mc_multiple_categories', ( ! empty( $_POST['mc_multiple_categories'] ) && 'on' == $_POST['mc_multiple_categories'] ) ? 'true' : 'false' );
485
486
$message = mc_show_notice( __( 'My Calendar Category Configuration Updated', 'my-calendar' ), false );
522
</ul>
523
</fieldset>
524
<ul>
525
<li>' . mc_settings_field( 'mc_hide_icons', __( 'Hide Category icons', 'my-calendar' ), '', '', array(), 'checkbox-single', false ) . '</li>
526
<li>' . mc_settings_field( 'mc_multiple_categories', __( 'Use multiple categories on events', 'my-calendar' ), '', '', array(), 'checkbox-single', false ) . '</li>
527
</ul>
711
712
if ( user_can( $user_edit, 'mc_manage_events' ) && current_user_can( 'manage_options' ) ) {
713
$permissions = get_user_meta( $user_edit, 'mc_user_permissions', true );
714
+ $selected = ( empty( $permissions ) || in_array( 'all', $permissions ) || user_can( $user_edit, 'manage_options' ) ) ? ' checked="checked"' : '';
715
?>
716
<h3><?php _e( 'My Calendar Editor Permissions', 'my-calendar' ); ?></h3>
717
<table class="form-table">
825
$selected = ' checked="checked"';
826
}
827
}
828
+ $category_name = strip_tags( stripslashes( trim( $cat->category_name ) ) );
829
+ $category_name = ( '' === $category_name ) ? '(' . __( 'Untitled category', 'my-calendar' ) . ')' : $category_name;
830
if ( $multiple ) {
831
+ $c = '<li><input type="checkbox" name="' . esc_attr( $name ) . '" id="mc_cat_' . $cat->category_id . '" value="' . $cat->category_id . '" ' . $selected . ' /><label for="mc_cat_' . $cat->category_id . '">' . $category_name . '</label></li>';
832
} else {
833
+ $c = '<option value="' . $cat->category_id . '" ' . $selected . '>' . $category_name . '</option>';
834
}
835
if ( get_option( 'mc_default_category' ) != $cat->category_id ) {
836
$list .= $c;
my-calendar-core.php CHANGED
@@ -44,7 +44,7 @@ add_action( 'wp_feed_options', 'mc_cache_feeds' );
44
* @return array updated set of links
45
*/
46
function mc_plugin_action( $links, $file ) {
47
- if ( plugin_basename( dirname( __FILE__ ) . '/my-calendar.php' ) == $file ) {
48
$links[] = '<a href="admin.php?page=my-calendar-config">' . __( 'Settings', 'my-calendar' ) . '</a>';
49
$links[] = '<a href="admin.php?page=my-calendar-help">' . __( 'Help', 'my-calendar' ) . '</a>';
50
if ( ! function_exists( 'mcs_submissions' ) ) {
@@ -67,10 +67,10 @@ function mc_plugin_action( $links, $file ) {
67
function mc_custom_dirs( $type = 'path' ) {
68
$dirs = array();
69
70
- $dirs[] = ( 'path' == $type ) ? plugin_dir_path( __FILE__ ) . 'my-calendar-custom/styles/' : plugin_dir_url( __FILE__ ) . 'my-calendar-custom/styles/';
71
- $dirs[] = ( 'path' == $type ) ? plugin_dir_path( __FILE__ ) . 'my-calendar-custom/' : plugin_dir_url( __FILE__ ) . 'my-calendar-custom/';
72
- $dirs[] = ( 'path' == $type ) ? get_stylesheet_directory() . '/css/' : get_stylesheet_directory_uri() . '/css/';
73
- $dirs[] = ( 'path' == $type ) ? get_stylesheet_directory() . '/' : get_stylesheet_directory_uri() . '/';
74
75
$directories = apply_filters( 'mc_custom_dirs', $dirs, $type );
76
@@ -113,11 +113,11 @@ function mc_get_file( $file, $type = 'path' ) {
113
$file = sanitize_file_name( $file ); // This will remove slashes as well.
114
$dir = plugin_dir_path( __FILE__ );
115
$url = plugin_dir_url( __FILE__ );
116
- $path = ( 'path' == $type ) ? $dir . $file : $url . $file;
117
118
foreach ( mc_custom_dirs() as $key => $dir ) {
119
if ( file_exists( $dir . $file ) ) {
120
- if ( 'path' == $type ) {
121
$path = $dir . $file;
122
} else {
123
$urls = mc_custom_dirs( $type );
@@ -150,14 +150,14 @@ function mc_register_styles() {
150
151
$default = apply_filters( 'mc_display_css_on_archives', true, $wp_query );
152
$id = ( is_object( $this_post ) && isset( $this_post->ID ) ) ? $this_post->ID : false;
153
- $js_array = ( '' != get_option( 'mc_show_js' ) ) ? explode( ',', get_option( 'mc_show_js' ) ) : array();
154
- $css_array = ( '' != get_option( 'mc_show_css' ) ) ? explode( ',', get_option( 'mc_show_css' ) ) : array();
155
156
// check whether any scripts are actually enabled.
157
if ( get_option( 'mc_calendar_javascript' ) != 1 || get_option( 'mc_list_javascript' ) != 1 || get_option( 'mc_mini_javascript' ) != 1 || get_option( 'mc_ajax_javascript' ) != 1 ) {
158
if ( is_array( $js_array ) && in_array( $id, $js_array ) || '' == get_option( 'mc_show_js' ) || is_singular( 'mc-events' ) ) {
159
wp_enqueue_script( 'jquery' );
160
- if ( 'true' == get_option( 'mc_gmap' ) ) {
161
$api_key = get_option( 'mc_gmap_api_key' );
162
if ( $api_key ) {
163
wp_enqueue_script( 'gmaps', "https://maps.googleapis.com/maps/api/js?key=$api_key" );
@@ -167,8 +167,8 @@ function mc_register_styles() {
167
}
168
}
169
// True means styles are disabled.
170
- if ( 'true' != get_option( 'mc_use_styles' ) ) {
171
- if ( ( $default && ! $id ) || ( is_array( $css_array ) && in_array( $id, $css_array ) || get_option( 'mc_show_css' ) == '' ) ) {
172
wp_enqueue_style( 'my-calendar-style' );
173
}
174
}
@@ -192,16 +192,16 @@ function mc_register_styles() {
192
function my_calendar_head() {
193
global $wpdb, $wp_query;
194
$mcdb = $wpdb;
195
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
196
$mcdb = mc_remote_db();
197
}
198
$array = array();
199
200
- if ( get_option( 'mc_use_styles' ) != 'true' ) {
201
$this_post = $wp_query->get_queried_object();
202
$id = ( is_object( $this_post ) && isset( $this_post->ID ) ) ? $this_post->ID : false;
203
- $array = ( '' != get_option( 'mc_show_css' ) ) ? explode( ',', get_option( 'mc_show_css' ) ) : $array;
204
- if ( is_array( $array ) && in_array( $id, $array ) || get_option( 'mc_show_css' ) == '' ) {
205
// generate category colors.
206
$category_styles = '';
207
$inv = '';
@@ -212,20 +212,18 @@ function my_calendar_head() {
212
$class = mc_category_class( $category, 'mc_' );
213
$hex = ( strpos( $category->category_color, '#' ) !== 0 ) ? '#' : '';
214
$color = $hex . $category->category_color;
215
- if ( '#' != $color ) {
216
$hcolor = mc_shift_color( $category->category_color );
217
- if ( 'font' == get_option( 'mc_apply_color' ) ) {
218
$type = 'color';
219
$alt = 'background';
220
- } elseif ( 'background' == get_option( 'mc_apply_color' ) ) {
221
$type = 'background';
222
$alt = 'color';
223
}
224
- if ( 'true' == get_option( 'mc_inverse_color' ) ) {
225
- $inverse = mc_inverse_color( $color );
226
- $inv = "$alt: $inverse;";
227
- }
228
- if ( 'font' == get_option( 'mc_apply_color' ) || 'background' == get_option( 'mc_apply_color' ) ) {
229
// always an anchor as of 1.11.0, apply also to title.
230
$category_styles .= "\n.mc-main .$class .event-title, .mc-main .$class .event-title a { $type: $color; $inv }";
231
$category_styles .= "\n.mc-main .$class .event-title a:hover, .mc-main .$class .event-title a:focus { $type: $hcolor;}";
@@ -240,7 +238,7 @@ function my_calendar_head() {
240
$style_vars .= sanitize_key( $key ) . ': ' . $var . '; ';
241
}
242
}
243
- if ( '' != $style_vars ) {
244
$style_vars = '.mc-main {' . $style_vars . '}';
245
}
246
@@ -284,7 +282,7 @@ function mc_deal_with_deleted_user( $id ) {
284
* @return string New admin body classes
285
*/
286
function mc_admin_body_class( $classes ) {
287
- if ( 'true' == get_option( 'mc_sidebar_footer' ) ) {
288
$classes .= ' mc-sidebar-footer';
289
}
290
@@ -295,14 +293,14 @@ function mc_admin_body_class( $classes ) {
295
* Write custom JS in admin head.
296
*/
297
function my_calendar_write_js() {
298
- if ( isset( $_GET['page'] ) && ( 'my-calendar' == $_GET['page'] || 'my-calendar-locations' == $_GET['page'] ) ) {
299
?>
300
<script>
301
//<![CDATA[
302
jQuery(document).ready(function ($) {
303
$( '#mc-accordion' ).accordion( { collapsible: true, active: false, heightStyle: 'content' } );
304
<?php
305
- if ( function_exists( 'wpt_post_to_twitter' ) && isset( $_GET['page'] ) && 'my-calendar' == $_GET['page'] ) {
306
?>
307
var mc_allowed = $( '#mc_twitter' ).attr( 'data-allowed' );
308
$('#mc_twitter').charCount({
@@ -351,7 +349,7 @@ function mc_footer_js() {
351
return;
352
} else {
353
$pages = array();
354
- if ( get_option( 'mc_show_js' ) != '' ) {
355
$pages = explode( ',', get_option( 'mc_show_js' ) );
356
}
357
if ( is_object( $wp_query ) && isset( $wp_query->post ) ) {
@@ -359,13 +357,13 @@ function mc_footer_js() {
359
} else {
360
$id = false;
361
}
362
- if ( 1 == get_option( 'mc_use_custom_js' ) ) {
363
$top = '';
364
$bottom = '';
365
$inner = '';
366
$list_js = stripcslashes( get_option( 'mc_listjs' ) );
367
$cal_js = stripcslashes( get_option( 'mc_caljs' ) );
368
- if ( 'true' == get_option( 'mc_open_uri' ) ) {
369
// remove sections of javascript if necessary.
370
$replacements = array(
371
'$(this).parent().children().not(".event-title").toggle();',
@@ -375,13 +373,12 @@ function mc_footer_js() {
375
}
376
$mini_js = stripcslashes( get_option( 'mc_minijs' ) );
377
$open_day = get_option( 'mc_open_day_uri' );
378
- if ( 'true' == $open_day || 'listanchor' == $open_day || 'calendaranchor' == $open_day ) {
379
$mini_js = str_replace( 'e.preventDefault();', '', $mini_js );
380
}
381
$ajax_js = stripcslashes( get_option( 'mc_ajaxjs' ) );
382
-
383
- if ( ( is_array( $pages ) && in_array( $id, $pages ) ) || '' == get_option( 'mc_show_js' ) ) {
384
- $inner = '';
385
if ( get_option( 'mc_calendar_javascript' ) != 1 ) {
386
$inner .= "\n" . $cal_js;
387
}
@@ -400,11 +397,11 @@ function mc_footer_js() {
400
</script>';
401
}
402
$inner = apply_filters( 'mc_filter_javascript_footer', $inner );
403
- echo ( '' != $inner ) ? $script . $mcjs : '';
404
} else {
405
$enqueue_mcjs = false;
406
- if ( ( is_array( $pages ) && in_array( $id, $pages ) ) || '' == get_option( 'mc_show_js' ) ) {
407
- if ( 1 != get_option( 'mc_calendar_javascript' ) && 'true' != get_option( 'mc_open_uri' ) ) {
408
$url = apply_filters( 'mc_grid_js', plugins_url( 'js/mc-grid.js', __FILE__ ) );
409
$enqueue_mcjs = true;
410
wp_enqueue_script( 'mc.grid', $url, array( 'jquery' ) );
@@ -416,7 +413,7 @@ function mc_footer_js() {
416
wp_enqueue_script( 'mc.list', $url, array( 'jquery' ) );
417
wp_localize_script( 'mc.list', 'mclist', 'true' );
418
}
419
- if ( 1 != get_option( 'mc_mini_javascript' ) && 'true' != get_option( 'mc_open_day_uri' ) ) {
420
$url = apply_filters( 'mc_mini_js', plugins_url( 'js/mc-mini.js', __FILE__ ) );
421
$enqueue_mcjs = true;
422
wp_enqueue_script( 'mc.mini', $url, array( 'jquery' ) );
@@ -452,7 +449,7 @@ function my_calendar_add_styles() {
452
if ( false !== strpos( $id, 'my-calendar' ) ) {
453
wp_enqueue_style( 'mc-styles', plugins_url( 'css/mc-styles.css', __FILE__ ) );
454
455
- if ( 'toplevel_page_my-calendar' == $id ) {
456
wp_enqueue_style( 'mc-pickadate-default', plugins_url( 'js/pickadate/themes/default.css', __FILE__ ) );
457
wp_enqueue_style( 'mc-pickadate-date', plugins_url( 'js/pickadate/themes/default.date.css', __FILE__ ) );
458
wp_enqueue_style( 'mc-pickadate-time', plugins_url( 'js/pickadate/themes/default.time.css', __FILE__ ) );
@@ -611,7 +608,7 @@ function my_calendar_exists() {
611
$tables = $wpdb->get_results( 'show tables;' );
612
foreach ( $tables as $table ) {
613
foreach ( $table as $value ) {
614
- if ( my_calendar_table() == $value ) {
615
// if the table exists, then My Calendar was already installed.
616
return true;
617
}
@@ -629,13 +626,13 @@ function my_calendar_check() {
629
if ( current_user_can( 'manage_options' ) ) {
630
global $wpdb, $mc_version;
631
mc_if_needs_permissions();
632
- $current_version = ( '' == get_option( 'mc_version' ) ) ? get_option( 'my_calendar_version' ) : get_option( 'mc_version' );
633
if ( version_compare( $current_version, '2.3.12', '>=' ) ) {
634
// if current is a version higher than 2.3.11, they've already seen this notice and handled it.
635
update_option( 'mc_update_notice', 1 );
636
}
637
// If current version matches, don't bother running this.
638
- if ( $current_version == $mc_version ) {
639
640
return true;
641
}
@@ -644,9 +641,9 @@ function my_calendar_check() {
644
$upgrade_path = array();
645
$my_calendar_exists = my_calendar_exists();
646
647
- if ( $my_calendar_exists && '' == $current_version ) {
648
// If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
649
- $current_version = '1.11.3';
650
}
651
652
if ( ! $my_calendar_exists ) {
@@ -654,7 +651,7 @@ function my_calendar_check() {
654
} else {
655
// For each release requiring an upgrade path, add a version compare.
656
// Loop will run every relevant upgrade cycle.
657
- $valid_upgrades = array( '2.0.0', '2.2.10', '2.3.0', '2.3.11', '2.3.15', '2.4.4', '3.0.0' );
658
foreach ( $valid_upgrades as $upgrade ) {
659
if ( version_compare( $current_version, $upgrade, '<' ) ) {
660
$upgrade_path[] = $upgrade;
@@ -664,7 +661,7 @@ function my_calendar_check() {
664
// Having determined upgrade path, assign new version number.
665
update_option( 'mc_version', $mc_version );
666
// Now we've determined what the current install is.
667
- if ( true == $new_install ) {
668
// Add default settings.
669
mc_default_settings();
670
mc_create_category(
@@ -682,7 +679,7 @@ function my_calendar_check() {
682
* If the user has fully uninstalled the plugin but kept the database of events, this will restore default
683
* settings and upgrade db if needed.
684
*/
685
- if ( 'true' == get_option( 'mc_uninstalled' ) ) {
686
mc_default_settings();
687
update_option( 'mc_db_version', $mc_version );
688
delete_option( 'mc_uninstalled' );
@@ -700,6 +697,10 @@ function mc_do_upgrades( $upgrade_path ) {
700
701
foreach ( $upgrade_path as $upgrade ) {
702
switch ( $upgrade ) {
703
case '3.0.0':
704
delete_option( 'mc_event_open' );
705
delete_option( 'mc_widget_defaults' );
@@ -721,7 +722,6 @@ function mc_do_upgrades( $upgrade_path ) {
721
'--highlight-light' => '#efefef',
722
)
723
);
724
- mc_upgrade_db();
725
mc_transition_categories();
726
break;
727
case '2.4.4': // 8-11-2015 (2.4.0).
@@ -743,7 +743,7 @@ function mc_do_upgrades( $upgrade_path ) {
743
case '2.3.0': // 4/10/2014.
744
delete_option( 'mc_location_control' );
745
$user_data = get_option( 'mc_user_settings' );
746
- $loc_type = ( get_option( 'mc_location_type' ) == '' ) ? 'event_state' : get_option( 'mc_location_type' );
747
$locations[ $loc_type ] = $user_data['my_calendar_location_default']['values'];
748
add_option( 'mc_use_permalinks', false );
749
delete_option( 'mc_modified_feeds' );
@@ -759,15 +759,6 @@ function mc_do_upgrades( $upgrade_path ) {
759
delete_option( 'mc_show_rss' );
760
delete_option( 'mc_draggable' );
761
delete_option( 'mc_caching_enabled' ); // remove caching support via options. Filter only.
762
- add_option( 'mc_inverse_color', 'true' );
763
- break;
764
- case '2.0.0': // 11/20/2012 (2.0.12).
765
- mc_migrate_db();
766
- $mc_input = get_option( 'mc_input_options' );
767
- if ( ! isset( $mc_input['event_specials'] ) ) {
768
- $mc_input['event_specials'] = 'on';
769
- update_option( 'mc_input_options', $mc_input );
770
- }
771
break;
772
default:
773
break;
@@ -781,7 +772,7 @@ add_action( 'admin_bar_menu', 'my_calendar_admin_bar', 200 );
781
*/
782
function my_calendar_admin_bar() {
783
global $wp_admin_bar;
784
- if ( current_user_can( 'mc_add_events' ) && 'true' != get_option( 'mc_remote' ) ) {
785
$url = apply_filters( 'mc_add_events_url', admin_url( 'admin.php?page=my-calendar' ) );
786
$args = array(
787
'id' => 'mc-add-event',
@@ -858,14 +849,14 @@ function my_calendar_send_email( $event ) {
858
$details = mc_create_tags( $event );
859
$headers = array();
860
// shift to boolean.
861
- $send_email_option = ( 'true' == get_option( 'mc_event_mail' ) ) ? true : false;
862
$send_email = apply_filters( 'mc_send_notification', $send_email_option, $details );
863
- if ( true == $send_email ) {
864
add_filter( 'wp_mail_content_type', 'mc_html_type' );
865
}
866
- if ( 'true' == get_option( 'mc_event_mail' ) ) {
867
$to = apply_filters( 'mc_event_mail_to', get_option( 'mc_event_mail_to' ), $details );
868
- $from = ( '' == get_option( 'mc_event_mail_from' ) ) ? get_bloginfo( 'admin_email' ) : get_option( 'mc_event_mail_from' );
869
$from = apply_filters( 'mc_event_mail_from', $from, $details );
870
$headers[] = 'From: ' . __( 'Event Notifications', 'my-calendar' ) . " <$from>";
871
$bcc = apply_filters( 'mc_event_mail_bcc', get_option( 'mc_event_mail_bcc' ), $details );
@@ -885,7 +876,7 @@ function my_calendar_send_email( $event ) {
885
$message = mc_draw_template( $details, $body );
886
wp_mail( $to, $subject, $message, $headers );
887
}
888
- if ( 'true' == get_option( 'mc_html_email' ) ) {
889
remove_filter( 'wp_mail_content_type', 'mc_html_type' );
890
}
891
}
@@ -939,7 +930,7 @@ function mc_spam( $event_url = '', $description = '', $post = array() ) {
939
} else {
940
$response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
941
}
942
- if ( 'true' == $response[1] ) {
943
return 1;
944
} else {
945
return 0;
@@ -977,7 +968,8 @@ add_action( 'admin_enqueue_scripts', 'mc_scripts' );
977
*/
978
function mc_scripts() {
979
global $current_screen;
980
- $id = $current_screen->id;
981
982
if ( false !== strpos( $id, 'my-calendar' ) ) {
983
wp_enqueue_script( 'mc.admin', plugins_url( 'js/jquery.admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ) );
@@ -985,11 +977,11 @@ function mc_scripts() {
985
wp_localize_script( 'mc.admin', 'draftText', __( 'Save Draft', 'my-calendar' ) );
986
}
987
988
- if ( 'toplevel_page_my-calendar' == $id || 'my-calendar_page_my-calendar-groups' == $id || 'my-calendar_page_my-calendar-locations' == $id ) {
989
wp_enqueue_script( 'jquery-ui-accordion' );
990
}
991
992
- if ( 'toplevel_page_my-calendar' == $id || 'my-calendar_page_my-calendar-groups' == $id ) {
993
wp_enqueue_script( 'jquery-ui-autocomplete' ); // required for character counting.
994
wp_enqueue_script( 'pickadate', plugins_url( 'js/pickadate/picker.js', __FILE__ ), array( 'jquery' ) );
995
wp_enqueue_script( 'pickadate.date', plugins_url( 'js/pickadate/picker.date.js', __FILE__ ), array( 'pickadate' ) );
@@ -1035,7 +1027,7 @@ function mc_scripts() {
1035
'clear' => addslashes( __( 'Clear', 'my-calendar' ) ),
1036
'close' => addslashes( __( 'Close', 'my-calendar' ) ),
1037
// False-y values = Sunday, truth-y = Monday.
1038
- 'start' => ( 1 == $sweek || 0 == $sweek ) ? $sweek : 0,
1039
),
1040
)
1041
);
@@ -1047,7 +1039,7 @@ function mc_scripts() {
1047
wp_enqueue_media();
1048
}
1049
}
1050
- if ( 'my-calendar_page_my-calendar-locations' == $id || 'toplevel_page_my-calendar' == $id ) {
1051
$api_key = get_option( 'mc_gmap_api_key' );
1052
if ( $api_key ) {
1053
wp_enqueue_script( 'gmaps', "https://maps.googleapis.com/maps/api/js?key=$api_key" );
@@ -1055,10 +1047,10 @@ function mc_scripts() {
1055
}
1056
}
1057
1058
- if ( 'toplevel_page_my-calendar' == $id && function_exists( 'wpt_post_to_twitter' ) ) {
1059
wp_enqueue_script( 'charCount', plugins_url( 'wp-to-twitter/js/jquery.charcount.js' ), array( 'jquery' ) );
1060
}
1061
- if ( 'toplevel_page_my-calendar' == $id ) {
1062
if ( current_user_can( 'mc_manage_events' ) ) {
1063
wp_enqueue_script( 'mc.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ) );
1064
wp_localize_script(
@@ -1073,7 +1065,7 @@ function mc_scripts() {
1073
}
1074
}
1075
1076
- if ( 'my-calendar_page_my-calendar-config' == $id ) {
1077
wp_enqueue_script( 'jquery-ui-autocomplete' );
1078
wp_enqueue_script(
1079
'mc.suggest',
@@ -1086,7 +1078,7 @@ function mc_scripts() {
1086
wp_localize_script( 'mc.suggest', 'mc_ajax_action', 'mc_post_lookup' );
1087
}
1088
1089
- if ( 'my-calendar_page_my-calendar-categories' == $id ) {
1090
wp_enqueue_style( 'wp-color-picker' );
1091
// Switch to wp_add_inline_script when no longer supporting WP 4.4.x.
1092
wp_enqueue_script( 'mc-color-picker', plugins_url( 'js/color-picker.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
@@ -1218,7 +1210,7 @@ function mc_ajax_add_date() {
1218
}
1219
1220
$begin = strtotime( $event_date . ' ' . $event_time );
1221
- $end = ( '' != $event_endtime ) ? strtotime( $event_end . ' ' . $event_endtime ) : strtotime( $event_end . ' ' . $event_time ) + HOUR_IN_SECONDS;
1222
1223
$format = array( '%d', '%s', '%s', '%d' );
1224
$data = array(
@@ -1287,9 +1279,13 @@ function mc_is_tablet() {
1287
/**
1288
* As of version 3.0.0, this only checks for 'my-calendar', to see if this plug-in already exists.
1289
*
1290
- * @return mixed int/boolean
1291
*/
1292
function mc_guess_calendar() {
1293
global $wpdb;
1294
$has_uri = mc_get_uri( 'boolean' );
1295
$current = mc_get_uri();
@@ -1297,9 +1293,9 @@ function mc_guess_calendar() {
1297
if ( $has_uri && esc_url( $current ) ) {
1298
$response = wp_remote_head( $current );
1299
if ( ! is_wp_error( $response ) ) {
1300
- $http = $response['response']['code'];
1301
// Only modify the value if it's explicitly missing. Redirects or secured pages are fine.
1302
- if ( 404 == $http ) {
1303
$current = '';
1304
}
1305
}
@@ -1340,7 +1336,7 @@ function mc_guess_calendar() {
1340
}
1341
}
1342
1343
- return;
1344
}
1345
1346
/**
@@ -1356,9 +1352,9 @@ function mc_get_support_form() {
1356
$mc_css = get_option( 'mc_css_file' );
1357
1358
// Pro license status.
1359
- $license = ( '' != get_option( 'mcs_license_key' ) ) ? get_option( 'mcs_license_key' ) : '';
1360
$license_valid = get_option( 'mcs_license_key_valid' );
1361
- $checked = ( 'valid' == $license_valid ) ? true : false;
1362
1363
if ( $license ) {
1364
$license = "
@@ -1434,12 +1430,12 @@ $plugins_string
1434
wp_die( 'Security check failed' );
1435
}
1436
$request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( $_POST['support_request'] ) : false;
1437
- $has_read_faq = ( 'on' == $_POST['has_read_faq'] ) ? 'Read FAQ' : false;
1438
$subject = 'My Calendar Pro support request.';
1439
$message = $request . "\n\n" . $data;
1440
// Get the site domain and get rid of www. from pluggable.php.
1441
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
1442
- if ( 'www.' == substr( $sitename, 0, 4 ) ) {
1443
$sitename = substr( $sitename, 4 );
1444
}
1445
$from_email = 'wordpress@' . $sitename;
@@ -1452,7 +1448,7 @@ $plugins_string
1452
} else {
1453
$sent = wp_mail( 'plugins@joedolson.com', $subject, $message, $from );
1454
if ( $sent ) {
1455
- if ( 'Donor' == $has_donated || 'Purchaser' == $has_purchased ) {
1456
mc_show_notice( __( 'Thank you for supporting the continuing development of this plug-in! I\'ll get back to you as soon as I can.', 'my-calendar' ) );
1457
} else {
1458
mc_show_notice( __( 'I\'ll get back to you as soon as I can, after dealing with any support requests from plug-in supporters.', 'my-calendar' ) . __( 'You should receive an automatic response to your request when I receive it. If you do not receive this notice, then either I did not receive your message or the email it was sent from was not a valid address.', 'my-calendar' ) );
@@ -1530,7 +1526,7 @@ function mc_load_permalinks() {
1530
* Custom field callback for permalinks settings
1531
*/
1532
function mc_field_callback() {
1533
- $value = ( '' != get_option( 'mc_cpt_base' ) ) ? get_option( 'mc_cpt_base' ) : 'mc-events';
1534
echo '<input type="text" value="' . esc_attr( $value ) . '" name="mc_cpt_base" id="mc_cpt_base" class="regular-text" />';
1535
}
1536
@@ -1541,7 +1537,10 @@ function mc_post_type() {
1541
$arguments = array(
1542
'public' => apply_filters( 'mc_event_posts_public', true ),
1543
'publicly_queryable' => true,
1544
- 'exclude_from_search' => true,
1545
'show_ui' => true,
1546
'show_in_menu' => apply_filters( 'mc_show_custom_posts_in_menu', false ),
1547
'menu_icon' => null,
@@ -1565,7 +1564,7 @@ function mc_post_type() {
1565
function mc_posttypes() {
1566
$types = mc_post_type();
1567
$enabled = array( 'mc-events' );
1568
- $slug = ( '' != get_option( 'mc_cpt_base' ) ) ? get_option( 'mc_cpt_base' ) : 'mc-events';
1569
if ( is_array( $enabled ) ) {
1570
foreach ( $enabled as $key ) {
1571
$value =& $types[ $key ];
@@ -1618,8 +1617,8 @@ function mc_close_comments( $posts ) {
1618
return $posts;
1619
}
1620
1621
- if ( 'mc-events' == get_post_type( $posts[0]->ID ) ) {
1622
- if ( apply_filters( 'mc_autoclose_comments', true ) && 'closed' != $posts[0]->comment_status ) {
1623
$posts[0]->comment_status = 'closed';
1624
$posts[0]->ping_status = 'closed';
1625
wp_update_post( $posts[0] );
@@ -1718,7 +1717,7 @@ add_action( 'admin_init', 'mc_dismiss_notice' );
1718
* Dismiss admin notices
1719
*/
1720
function mc_dismiss_notice() {
1721
- if ( isset( $_GET['dismiss'] ) && 'update' == $_GET['dismiss'] ) {
1722
update_option( 'mc_update_notice', 1 );
1723
}
1724
}
@@ -1735,7 +1734,7 @@ function mc_update_notice() {
1735
echo "<div class='updated'><p>" . sprintf( __( "<strong>Update notice:</strong> if you use custom JS with My Calendar, you need to activate your custom scripts following this update. <a href='%s'>Dismiss Notice</a>", 'my-calendar' ), $dismiss ) . '</p></div>';
1736
}
1737
if ( current_user_can( 'manage_options' ) && isset( $_GET['page'] ) && stripos( $_GET['page'], 'my-calendar' ) !== false ) {
1738
- if ( 'true' == get_option( 'mc_remote' ) ) {
1739
mc_show_notice( __( 'My Calendar is configured to retrieve events from a remote source.', 'my-calendar' ) . ' <a href="' . admin_url( 'admin.php?page=my-calendar-config' ) . '">' . __( 'Update Settings', 'my-calendar' ) . '</a>' );
1740
}
1741
}
@@ -1812,7 +1811,7 @@ function my_calendar_privacy_export( $email_address, $page = 1 ) {
1812
);
1813
}
1814
foreach ( $meta as $mkey => $mvalue ) {
1815
- if ( false !== stripos( $mkey, '_mt_' ) || '_mc_event_data' == $mkey || '_mc_event_desc' == $mkey ) {
1816
continue;
1817
}
1818
// Omit empty values.
@@ -1887,7 +1886,7 @@ function my_calendar_privacy_eraser( $email_address, $page = 1 ) {
1887
// for deletion, if *author*, delete; if *host*, change host.
1888
$calendar = $wpdb->get_results( $wpdb->prepare( 'SELECT event_id, event_host, event_author FROM ' . my_calendar_table() . ' WHERE event_host = %d OR event_author = %d', $user_ID, $user_ID ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1889
foreach ( $calendar as $obj ) {
1890
- if ( $user_ID == $obj->event_host && $obj->event_host != $obj->event_author ) {
1891
$updates[] = array( $obj->event_id, $obj->event_author );
1892
} else {
1893
$deletions[] = $obj->event_id;
44
* @return array updated set of links
45
*/
46
function mc_plugin_action( $links, $file ) {
47
+ if ( plugin_basename( dirname( __FILE__ ) . '/my-calendar.php' ) === $file ) {
48
$links[] = '<a href="admin.php?page=my-calendar-config">' . __( 'Settings', 'my-calendar' ) . '</a>';
49
$links[] = '<a href="admin.php?page=my-calendar-help">' . __( 'Help', 'my-calendar' ) . '</a>';
50
if ( ! function_exists( 'mcs_submissions' ) ) {
67
function mc_custom_dirs( $type = 'path' ) {
68
$dirs = array();
69
70
+ $dirs[] = ( 'path' === $type ) ? plugin_dir_path( __FILE__ ) . 'my-calendar-custom/styles/' : plugin_dir_url( __FILE__ ) . 'my-calendar-custom/styles/';
71
+ $dirs[] = ( 'path' === $type ) ? plugin_dir_path( __FILE__ ) . 'my-calendar-custom/' : plugin_dir_url( __FILE__ ) . 'my-calendar-custom/';
72
+ $dirs[] = ( 'path' === $type ) ? get_stylesheet_directory() . '/css/' : get_stylesheet_directory_uri() . '/css/';
73
+ $dirs[] = ( 'path' === $type ) ? get_stylesheet_directory() . '/' : get_stylesheet_directory_uri() . '/';
74
75
$directories = apply_filters( 'mc_custom_dirs', $dirs, $type );
76
113
$file = sanitize_file_name( $file ); // This will remove slashes as well.
114
$dir = plugin_dir_path( __FILE__ );
115
$url = plugin_dir_url( __FILE__ );
116
+ $path = ( 'path' === $type ) ? $dir . $file : $url . $file;
117
118
foreach ( mc_custom_dirs() as $key => $dir ) {
119
if ( file_exists( $dir . $file ) ) {
120
+ if ( 'path' === $type ) {
121
$path = $dir . $file;
122
} else {
123
$urls = mc_custom_dirs( $type );
150
151
$default = apply_filters( 'mc_display_css_on_archives', true, $wp_query );
152
$id = ( is_object( $this_post ) && isset( $this_post->ID ) ) ? $this_post->ID : false;
153
+ $js_array = ( '' !== get_option( 'mc_show_js', '' ) ) ? explode( ',', get_option( 'mc_show_js' ) ) : array();
154
+ $css_array = ( '' !== get_option( 'mc_show_css', '' ) ) ? explode( ',', get_option( 'mc_show_css' ) ) : array();
155
156
// check whether any scripts are actually enabled.
157
if ( get_option( 'mc_calendar_javascript' ) != 1 || get_option( 'mc_list_javascript' ) != 1 || get_option( 'mc_mini_javascript' ) != 1 || get_option( 'mc_ajax_javascript' ) != 1 ) {
158
if ( is_array( $js_array ) && in_array( $id, $js_array ) || '' == get_option( 'mc_show_js' ) || is_singular( 'mc-events' ) ) {
159
wp_enqueue_script( 'jquery' );
160
+ if ( 'true' === get_option( 'mc_gmap' ) ) {
161
$api_key = get_option( 'mc_gmap_api_key' );
162
if ( $api_key ) {
163
wp_enqueue_script( 'gmaps', "https://maps.googleapis.com/maps/api/js?key=$api_key" );
167
}
168
}
169
// True means styles are disabled.
170
+ if ( 'true' !== get_option( 'mc_use_styles' ) ) {
171
+ if ( ( $default && ! $id ) || ( is_array( $css_array ) && in_array( $id, $css_array ) || get_option( 'mc_show_css', '' ) === '' ) ) {
172
wp_enqueue_style( 'my-calendar-style' );
173
}
174
}
192
function my_calendar_head() {
193
global $wpdb, $wp_query;
194
$mcdb = $wpdb;
195
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
196
$mcdb = mc_remote_db();
197
}
198
$array = array();
199
200
+ if ( get_option( 'mc_use_styles' ) !== 'true' ) {
201
$this_post = $wp_query->get_queried_object();
202
$id = ( is_object( $this_post ) && isset( $this_post->ID ) ) ? $this_post->ID : false;
203
+ $array = ( '' !== get_option( 'mc_show_css', '' ) ) ? explode( ',', get_option( 'mc_show_css' ) ) : $array;
204
+ if ( is_array( $array ) && in_array( $id, $array ) || get_option( 'mc_show_css', '' ) === '' ) {
205
// generate category colors.
206
$category_styles = '';
207
$inv = '';
212
$class = mc_category_class( $category, 'mc_' );
213
$hex = ( strpos( $category->category_color, '#' ) !== 0 ) ? '#' : '';
214
$color = $hex . $category->category_color;
215
+ if ( '#' !== $color ) {
216
$hcolor = mc_shift_color( $category->category_color );
217
+ if ( 'font' === get_option( 'mc_apply_color' ) ) {
218
$type = 'color';
219
$alt = 'background';
220
+ } elseif ( 'background' === get_option( 'mc_apply_color' ) ) {
221
$type = 'background';
222
$alt = 'color';
223
}
224
+ $inverse = mc_inverse_color( $color );
225
+ $inv = "$alt: $inverse;";
226
+ if ( 'font' === get_option( 'mc_apply_color' ) || 'background' === get_option( 'mc_apply_color' ) ) {
227
// always an anchor as of 1.11.0, apply also to title.
228
$category_styles .= "\n.mc-main .$class .event-title, .mc-main .$class .event-title a { $type: $color; $inv }";
229
$category_styles .= "\n.mc-main .$class .event-title a:hover, .mc-main .$class .event-title a:focus { $type: $hcolor;}";
238
$style_vars .= sanitize_key( $key ) . ': ' . $var . '; ';
239
}
240
}
241
+ if ( '' !== $style_vars ) {
242
$style_vars = '.mc-main {' . $style_vars . '}';
243
}
244
282
* @return string New admin body classes
283
*/
284
function mc_admin_body_class( $classes ) {
285
+ if ( 'true' === get_option( 'mc_sidebar_footer' ) ) {
286
$classes .= ' mc-sidebar-footer';
287
}
288
293
* Write custom JS in admin head.
294
*/
295
function my_calendar_write_js() {
296
+ if ( isset( $_GET['page'] ) && ( 'my-calendar' === $_GET['page'] || 'my-calendar-locations' === $_GET['page'] ) ) {
297
?>
298
<script>
299
//<![CDATA[
300
jQuery(document).ready(function ($) {
301
$( '#mc-accordion' ).accordion( { collapsible: true, active: false, heightStyle: 'content' } );
302
<?php
303
+ if ( function_exists( 'wpt_post_to_twitter' ) && isset( $_GET['page'] ) && 'my-calendar' === $_GET['page'] ) {
304
?>
305
var mc_allowed = $( '#mc_twitter' ).attr( 'data-allowed' );
306
$('#mc_twitter').charCount({
349
return;
350
} else {
351
$pages = array();
352
+ if ( get_option( 'mc_show_js', '' ) !== '' ) {
353
$pages = explode( ',', get_option( 'mc_show_js' ) );
354
}
355
if ( is_object( $wp_query ) && isset( $wp_query->post ) ) {
357
} else {
358
$id = false;
359
}
360
+ if ( '1' === get_option( 'mc_use_custom_js' ) ) {
361
$top = '';
362
$bottom = '';
363
$inner = '';
364
$list_js = stripcslashes( get_option( 'mc_listjs' ) );
365
$cal_js = stripcslashes( get_option( 'mc_caljs' ) );
366
+ if ( 'true' === get_option( 'mc_open_uri' ) ) {
367
// remove sections of javascript if necessary.
368
$replacements = array(
369
'$(this).parent().children().not(".event-title").toggle();',
373
}
374
$mini_js = stripcslashes( get_option( 'mc_minijs' ) );
375
$open_day = get_option( 'mc_open_day_uri' );
376
+ if ( 'true' === $open_day || 'listanchor' === $open_day || 'calendaranchor' === $open_day ) {
377
$mini_js = str_replace( 'e.preventDefault();', '', $mini_js );
378
}
379
$ajax_js = stripcslashes( get_option( 'mc_ajaxjs' ) );
380
+ $inner = '';
381
+ if ( ( is_array( $pages ) && in_array( $id, $pages ) ) || '' === get_option( 'mc_show_js', '' ) ) {
382
if ( get_option( 'mc_calendar_javascript' ) != 1 ) {
383
$inner .= "\n" . $cal_js;
384
}
397
</script>';
398
}
399
$inner = apply_filters( 'mc_filter_javascript_footer', $inner );
400
+ echo ( '' !== $inner ) ? $script . $mcjs : '';
401
} else {
402
$enqueue_mcjs = false;
403
+ if ( ( is_array( $pages ) && in_array( $id, $pages ) ) || '' === get_option( 'mc_show_js', '' ) ) {
404
+ if ( 1 != get_option( 'mc_calendar_javascript' ) && 'true' !== get_option( 'mc_open_uri' ) ) {
405
$url = apply_filters( 'mc_grid_js', plugins_url( 'js/mc-grid.js', __FILE__ ) );
406
$enqueue_mcjs = true;
407
wp_enqueue_script( 'mc.grid', $url, array( 'jquery' ) );
413
wp_enqueue_script( 'mc.list', $url, array( 'jquery' ) );
414
wp_localize_script( 'mc.list', 'mclist', 'true' );
415
}
416
+ if ( 1 != get_option( 'mc_mini_javascript' ) && 'true' !== get_option( 'mc_open_day_uri' ) ) {
417
$url = apply_filters( 'mc_mini_js', plugins_url( 'js/mc-mini.js', __FILE__ ) );
418
$enqueue_mcjs = true;
419
wp_enqueue_script( 'mc.mini', $url, array( 'jquery' ) );
449
if ( false !== strpos( $id, 'my-calendar' ) ) {
450
wp_enqueue_style( 'mc-styles', plugins_url( 'css/mc-styles.css', __FILE__ ) );
451
452
+ if ( 'toplevel_page_my-calendar' === $id ) {
453
wp_enqueue_style( 'mc-pickadate-default', plugins_url( 'js/pickadate/themes/default.css', __FILE__ ) );
454
wp_enqueue_style( 'mc-pickadate-date', plugins_url( 'js/pickadate/themes/default.date.css', __FILE__ ) );
455
wp_enqueue_style( 'mc-pickadate-time', plugins_url( 'js/pickadate/themes/default.time.css', __FILE__ ) );
608
$tables = $wpdb->get_results( 'show tables;' );
609
foreach ( $tables as $table ) {
610
foreach ( $table as $value ) {
611
+ if ( my_calendar_table() === $value ) {
612
// if the table exists, then My Calendar was already installed.
613
return true;
614
}
626
if ( current_user_can( 'manage_options' ) ) {
627
global $wpdb, $mc_version;
628
mc_if_needs_permissions();
629
+ $current_version = ( '' === get_option( 'mc_version', '' ) ) ? get_option( 'my_calendar_version' ) : get_option( 'mc_version' );
630
if ( version_compare( $current_version, '2.3.12', '>=' ) ) {
631
// if current is a version higher than 2.3.11, they've already seen this notice and handled it.
632
update_option( 'mc_update_notice', 1 );
633
}
634
// If current version matches, don't bother running this.
635
+ if ( $current_version === $mc_version ) {
636
637
return true;
638
}
641
$upgrade_path = array();
642
$my_calendar_exists = my_calendar_exists();
643
644
+ if ( $my_calendar_exists && '' === $current_version ) {
645
// If the table exists, but I don't know what version it is, I have to run the full cycle of upgrades.
646
+ $current_version = '2.2.9';
647
}
648
649
if ( ! $my_calendar_exists ) {
651
} else {
652
// For each release requiring an upgrade path, add a version compare.
653
// Loop will run every relevant upgrade cycle.
654
+ $valid_upgrades = array( '2.2.10', '2.3.0', '2.3.11', '2.3.15', '2.4.4', '3.0.0', '3.1.13' );
655
foreach ( $valid_upgrades as $upgrade ) {
656
if ( version_compare( $current_version, $upgrade, '<' ) ) {
657
$upgrade_path[] = $upgrade;
661
// Having determined upgrade path, assign new version number.
662
update_option( 'mc_version', $mc_version );
663
// Now we've determined what the current install is.
664
+ if ( true === $new_install ) {
665
// Add default settings.
666
mc_default_settings();
667
mc_create_category(
679
* If the user has fully uninstalled the plugin but kept the database of events, this will restore default
680
* settings and upgrade db if needed.
681
*/
682
+ if ( 'true' === get_option( 'mc_uninstalled' ) ) {
683
mc_default_settings();
684
update_option( 'mc_db_version', $mc_version );
685
delete_option( 'mc_uninstalled' );
697
698
foreach ( $upgrade_path as $upgrade ) {
699
switch ( $upgrade ) {
700
+ case '3.1.13':
701
+ delete_option( 'mc_inverse_color' );
702
+ mc_upgrade_db();
703
+ break;
704
case '3.0.0':
705
delete_option( 'mc_event_open' );
706
delete_option( 'mc_widget_defaults' );
722
'--highlight-light' => '#efefef',
723
)
724
);
725
mc_transition_categories();
726
break;
727
case '2.4.4': // 8-11-2015 (2.4.0).
743
case '2.3.0': // 4/10/2014.
744
delete_option( 'mc_location_control' );
745
$user_data = get_option( 'mc_user_settings' );
746
+ $loc_type = ( get_option( 'mc_location_type', '' ) === '' ) ? 'event_state' : get_option( 'mc_location_type' );
747
$locations[ $loc_type ] = $user_data['my_calendar_location_default']['values'];
748
add_option( 'mc_use_permalinks', false );
749
delete_option( 'mc_modified_feeds' );
759
delete_option( 'mc_show_rss' );
760
delete_option( 'mc_draggable' );
761
delete_option( 'mc_caching_enabled' ); // remove caching support via options. Filter only.
762
break;
763
default:
764
break;
772
*/
773
function my_calendar_admin_bar() {
774
global $wp_admin_bar;
775
+ if ( current_user_can( 'mc_add_events' ) && 'true' !== get_option( 'mc_remote' ) ) {
776
$url = apply_filters( 'mc_add_events_url', admin_url( 'admin.php?page=my-calendar' ) );
777
$args = array(
778
'id' => 'mc-add-event',
849
$details = mc_create_tags( $event );
850
$headers = array();
851
// shift to boolean.
852
+ $send_email_option = ( 'true' === get_option( 'mc_event_mail' ) ) ? true : false;
853
$send_email = apply_filters( 'mc_send_notification', $send_email_option, $details );
854
+ if ( true === $send_email ) {
855
add_filter( 'wp_mail_content_type', 'mc_html_type' );
856
}
857
+ if ( 'true' === get_option( 'mc_event_mail' ) ) {
858
$to = apply_filters( 'mc_event_mail_to', get_option( 'mc_event_mail_to' ), $details );
859
+ $from = ( '' === get_option( 'mc_event_mail_from', '' ) ) ? get_bloginfo( 'admin_email' ) : get_option( 'mc_event_mail_from' );
860
$from = apply_filters( 'mc_event_mail_from', $from, $details );
861
$headers[] = 'From: ' . __( 'Event Notifications', 'my-calendar' ) . " <$from>";
862
$bcc = apply_filters( 'mc_event_mail_bcc', get_option( 'mc_event_mail_bcc' ), $details );
876
$message = mc_draw_template( $details, $body );
877
wp_mail( $to, $subject, $message, $headers );
878
}
879
+ if ( 'true' === get_option( 'mc_html_email' ) ) {
880
remove_filter( 'wp_mail_content_type', 'mc_html_type' );
881
}
882
}
930
} else {
931
$response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
932
}
933
+ if ( 'true' === $response[1] ) {
934
return 1;
935
} else {
936
return 0;
968
*/
969
function mc_scripts() {
970
global $current_screen;
971
+ $id = $current_screen->id;
972
+ $slug = sanitize_title( __( 'My Calendar', 'my-calendar' ) );
973
974
if ( false !== strpos( $id, 'my-calendar' ) ) {
975
wp_enqueue_script( 'mc.admin', plugins_url( 'js/jquery.admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ) );
977
wp_localize_script( 'mc.admin', 'draftText', __( 'Save Draft', 'my-calendar' ) );
978
}
979
980
+ if ( 'toplevel_page_my-calendar' === $id || $slug . '_my-calendar-groups' === $id || $slug . '_page_my-calendar-locations' === $id ) {
981
wp_enqueue_script( 'jquery-ui-accordion' );
982
}
983
984
+ if ( 'toplevel_page_my-calendar' === $id || $slug . '_page_my-calendar-groups' === $id ) {
985
wp_enqueue_script( 'jquery-ui-autocomplete' ); // required for character counting.
986
wp_enqueue_script( 'pickadate', plugins_url( 'js/pickadate/picker.js', __FILE__ ), array( 'jquery' ) );
987
wp_enqueue_script( 'pickadate.date', plugins_url( 'js/pickadate/picker.date.js', __FILE__ ), array( 'pickadate' ) );
1027
'clear' => addslashes( __( 'Clear', 'my-calendar' ) ),
1028
'close' => addslashes( __( 'Close', 'my-calendar' ) ),
1029
// False-y values = Sunday, truth-y = Monday.
1030
+ 'start' => ( 1 === $sweek || 0 === $sweek ) ? $sweek : 0,
1031
),
1032
)
1033
);
1039
wp_enqueue_media();
1040
}
1041
}
1042
+ if ( $slug . '_page_my-calendar-locations' === $id || 'toplevel_page_my-calendar' === $id ) {
1043
$api_key = get_option( 'mc_gmap_api_key' );
1044
if ( $api_key ) {
1045
wp_enqueue_script( 'gmaps', "https://maps.googleapis.com/maps/api/js?key=$api_key" );
1047
}
1048
}
1049
1050
+ if ( 'toplevel_page_my-calendar' === $id && function_exists( 'wpt_post_to_twitter' ) ) {
1051
wp_enqueue_script( 'charCount', plugins_url( 'wp-to-twitter/js/jquery.charcount.js' ), array( 'jquery' ) );
1052
}
1053
+ if ( 'toplevel_page_my-calendar' === $id ) {
1054
if ( current_user_can( 'mc_manage_events' ) ) {
1055
wp_enqueue_script( 'mc.ajax', plugins_url( 'js/ajax.js', __FILE__ ), array( 'jquery' ) );
1056
wp_localize_script(
1065
}
1066
}
1067
1068
+ if ( $slug . '_page_my-calendar-config' === $id ) {
1069
wp_enqueue_script( 'jquery-ui-autocomplete' );
1070
wp_enqueue_script(
1071
'mc.suggest',
1078
wp_localize_script( 'mc.suggest', 'mc_ajax_action', 'mc_post_lookup' );
1079
}
1080
1081
+ if ( $slug . '_page_my-calendar-categories' === $id ) {
1082
wp_enqueue_style( 'wp-color-picker' );
1083
// Switch to wp_add_inline_script when no longer supporting WP 4.4.x.
1084
wp_enqueue_script( 'mc-color-picker', plugins_url( 'js/color-picker.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
1210
}
1211
1212
$begin = strtotime( $event_date . ' ' . $event_time );
1213
+ $end = ( '' !== $event_endtime ) ? strtotime( $event_end . ' ' . $event_endtime ) : strtotime( $event_end . ' ' . $event_time ) + HOUR_IN_SECONDS;
1214
1215
$format = array( '%d', '%s', '%s', '%d' );
1216
$data = array(
1279
/**
1280
* As of version 3.0.0, this only checks for 'my-calendar', to see if this plug-in already exists.
1281
*
1282
+ * @return array
1283
*/
1284
function mc_guess_calendar() {
1285
+ $return = array(
1286
+ 'response' => false,
1287
+ 'message' => __( 'Calendar query was not able to run.', 'my-calendar' ),
1288
+ );
1289
global $wpdb;
1290
$has_uri = mc_get_uri( 'boolean' );
1291
$current = mc_get_uri();
1293
if ( $has_uri && esc_url( $current ) ) {
1294
$response = wp_remote_head( $current );
1295
if ( ! is_wp_error( $response ) ) {
1296
+ $http = (string) $response['response']['code'];
1297
// Only modify the value if it's explicitly missing. Redirects or secured pages are fine.
1298
+ if ( '404' === $http ) {
1299
$current = '';
1300
}
1301
}
1336
}
1337
}
1338
1339
+ return $return;
1340
}
1341
1342
/**
1352
$mc_css = get_option( 'mc_css_file' );
1353
1354
// Pro license status.
1355
+ $license = ( '' !== get_option( 'mcs_license_key', '' ) ) ? get_option( 'mcs_license_key' ) : '';
1356
$license_valid = get_option( 'mcs_license_key_valid' );
1357
+ $checked = ( 'valid' === $license_valid ) ? true : false;
1358
1359
if ( $license ) {
1360
$license = "
1430
wp_die( 'Security check failed' );
1431
}
1432
$request = ( ! empty( $_POST['support_request'] ) ) ? stripslashes( $_POST['support_request'] ) : false;
1433
+ $has_read_faq = ( 'on' === $_POST['has_read_faq'] ) ? 'Read FAQ' : false;
1434
$subject = 'My Calendar Pro support request.';
1435
$message = $request . "\n\n" . $data;
1436
// Get the site domain and get rid of www. from pluggable.php.
1437
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
1438
+ if ( 'www.' === substr( $sitename, 0, 4 ) ) {
1439
$sitename = substr( $sitename, 4 );
1440
}
1441
$from_email = 'wordpress@' . $sitename;
1448
} else {
1449
$sent = wp_mail( 'plugins@joedolson.com', $subject, $message, $from );
1450
if ( $sent ) {
1451
+ if ( 'Donor' === $has_donated || 'Purchaser' === $has_purchased ) {
1452
mc_show_notice( __( 'Thank you for supporting the continuing development of this plug-in! I\'ll get back to you as soon as I can.', 'my-calendar' ) );
1453
} else {
1454
mc_show_notice( __( 'I\'ll get back to you as soon as I can, after dealing with any support requests from plug-in supporters.', 'my-calendar' ) . __( 'You should receive an automatic response to your request when I receive it. If you do not receive this notice, then either I did not receive your message or the email it was sent from was not a valid address.', 'my-calendar' ) );
1526
* Custom field callback for permalinks settings
1527
*/
1528
function mc_field_callback() {
1529
+ $value = ( '' !== get_option( 'mc_cpt_base', '' ) ) ? get_option( 'mc_cpt_base' ) : 'mc-events';
1530
echo '<input type="text" value="' . esc_attr( $value ) . '" name="mc_cpt_base" id="mc_cpt_base" class="regular-text" />';
1531
}
1532
1537
$arguments = array(
1538
'public' => apply_filters( 'mc_event_posts_public', true ),
1539
'publicly_queryable' => true,
1540
+ // WARNING: Allowing the post type to be searchable will not provide a true event search, especially with respect to recurring events.
1541
+ // It will not search recurring events by date, only the post content from each event. Enable only if requirements for search are limited to post content.
1542
+ // Details: https://github.com/joedolson/my-calendar/issues/23.
1543
+ 'exclude_from_search' => apply_filters( 'mc_event_exclude_from_search', true ),
1544
'show_ui' => true,
1545
'show_in_menu' => apply_filters( 'mc_show_custom_posts_in_menu', false ),
1546
'menu_icon' => null,
1564
function mc_posttypes() {
1565
$types = mc_post_type();
1566
$enabled = array( 'mc-events' );
1567
+ $slug = ( '' !== get_option( 'mc_cpt_base', '' ) ) ? get_option( 'mc_cpt_base' ) : 'mc-events';
1568
if ( is_array( $enabled ) ) {
1569
foreach ( $enabled as $key ) {
1570
$value =& $types[ $key ];
1617
return $posts;
1618
}
1619
1620
+ if ( 'mc-events' === get_post_type( $posts[0]->ID ) ) {
1621
+ if ( apply_filters( 'mc_autoclose_comments', true ) && 'closed' !== $posts[0]->comment_status ) {
1622
$posts[0]->comment_status = 'closed';
1623
$posts[0]->ping_status = 'closed';
1624
wp_update_post( $posts[0] );
1717
* Dismiss admin notices
1718
*/
1719
function mc_dismiss_notice() {
1720
+ if ( isset( $_GET['dismiss'] ) && 'update' === $_GET['dismiss'] ) {
1721
update_option( 'mc_update_notice', 1 );
1722
}
1723
}
1734
echo "<div class='updated'><p>" . sprintf( __( "<strong>Update notice:</strong> if you use custom JS with My Calendar, you need to activate your custom scripts following this update. <a href='%s'>Dismiss Notice</a>", 'my-calendar' ), $dismiss ) . '</p></div>';
1735
}
1736
if ( current_user_can( 'manage_options' ) && isset( $_GET['page'] ) && stripos( $_GET['page'], 'my-calendar' ) !== false ) {
1737
+ if ( 'true' === get_option( 'mc_remote' ) ) {
1738
mc_show_notice( __( 'My Calendar is configured to retrieve events from a remote source.', 'my-calendar' ) . ' <a href="' . admin_url( 'admin.php?page=my-calendar-config' ) . '">' . __( 'Update Settings', 'my-calendar' ) . '</a>' );
1739
}
1740
}
1811
);
1812
}
1813
foreach ( $meta as $mkey => $mvalue ) {
1814
+ if ( false !== stripos( $mkey, '_mt_' ) || '_mc_event_data' === $mkey || '_mc_event_desc' === $mkey ) {
1815
continue;
1816
}
1817
// Omit empty values.
1886
// for deletion, if *author*, delete; if *host*, change host.
1887
$calendar = $wpdb->get_results( $wpdb->prepare( 'SELECT event_id, event_host, event_author FROM ' . my_calendar_table() . ' WHERE event_host = %d OR event_author = %d', $user_ID, $user_ID ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1888
foreach ( $calendar as $obj ) {
1889
+ if ( absint( $user_ID ) === absint( $obj->event_host ) && absint( $obj->event_host ) !== absint( $obj->event_author ) ) {
1890
$updates[] = array( $obj->event_id, $obj->event_author );
1891
} else {
1892
$deletions[] = $obj->event_id;
my-calendar-event-manager.php CHANGED
@@ -1690,7 +1690,7 @@ function mc_form_fields( $data, $mode, $event_id ) {
1690
}
1691
if ( mc_show_edit_block( 'event_specials' ) ) {
1692
$hol_checked = ( 'true' == get_option( 'mc_skip_holidays' ) ) ? ' checked="checked"' : '';
1693
- $fifth_checked = ( 'true' == get_option( 'mc_no_fifth_week' ) ) ? ' checked="checked"' : '';
1694
if ( $has_data ) {
1695
$hol_checked = ( '1' == $data->event_holiday ) ? ' checked="checked"' : '';
1696
$fifth_checked = ( '1' == $data->event_fifth_week ) ? ' checked="checked"' : '';
1690
}
1691
if ( mc_show_edit_block( 'event_specials' ) ) {
1692
$hol_checked = ( 'true' == get_option( 'mc_skip_holidays' ) ) ? ' checked="checked"' : '';
1693
+ $fifth_checked = ( 'true' === get_option( 'mc_no_fifth_week' ) ) ? ' checked="checked"' : '';
1694
if ( $has_data ) {
1695
$hol_checked = ( '1' == $data->event_holiday ) ? ' checked="checked"' : '';
1696
$fifth_checked = ( '1' == $data->event_fifth_week ) ? ' checked="checked"' : '';
my-calendar-events.php CHANGED
@@ -79,16 +79,16 @@ function my_calendar_get_events( $args ) {
79
80
global $wpdb;
81
$mcdb = $wpdb;
82
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
83
$mcdb = mc_remote_db();
84
}
85
86
- if ( 'holidays' == $holidays && '' == $category ) {
87
return array();
88
}
89
90
if ( null === $holidays ) {
91
- $ccategory = ( isset( $_GET['mcat'] ) && '' != trim( $_GET['mcat'] ) ) ? $_GET['mcat'] : $category;
92
} else {
93
$ccategory = $category;
94
}
@@ -98,7 +98,7 @@ function my_calendar_get_events( $args ) {
98
$clhost = ( isset( $_GET['mc_host'] ) ) ? $_GET['mc_host'] : $host;
99
100
// If location value is not set, then location type shouldn't be set.
101
- if ( 'all' == $clvalue ) {
102
$cltype = 'all';
103
}
104
@@ -106,11 +106,11 @@ function my_calendar_get_events( $args ) {
106
return array();
107
} // Not valid dates.
108
109
- $cat_limit = ( 'all' != $ccategory ) ? mc_select_category( $ccategory ) : array();
110
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
111
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
112
- $select_author = ( 'all' != $clauth ) ? mc_select_author( $clauth ) : '';
113
- $select_host = ( 'all' != $clhost ) ? mc_select_host( $clhost ) : '';
114
$select_location = mc_select_location( $cltype, $clvalue );
115
$select_access = ( isset( $_GET['access'] ) ) ? mc_access_limit( $_GET['access'] ) : '';
116
$select_published = mc_select_published();
@@ -188,19 +188,19 @@ function mc_get_all_events( $args ) {
188
189
global $wpdb;
190
$mcdb = $wpdb;
191
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
192
$mcdb = mc_remote_db();
193
}
194
195
$exclude_categories = mc_private_categories();
196
- $cat_limit = ( 'default' != $category ) ? mc_select_category( $category ) : array();
197
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
198
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
199
$select_location = mc_select_location( $ltype, $lvalue );
200
$select_access = ( isset( $_GET['access'] ) ) ? mc_access_limit( $_GET['access'] ) : '';
201
$select_published = mc_select_published();
202
- $select_author = ( 'default' != $author ) ? mc_select_author( $author ) : '';
203
- $select_host = ( 'default' != $host ) ? mc_select_host( $host ) : '';
204
$date = date( 'Y-m-d', current_time( 'timestamp' ) );
205
206
$limit = "$select_published $select_category $select_author $select_host $select_location $select_access $search";
@@ -226,7 +226,7 @@ function mc_get_all_events( $args ) {
226
);
227
}
228
// Events happening today.
229
- if ( 'yes' == $today ) {
230
$events3 = $mcdb->get_results(
231
'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end
232
FROM ' . my_calendar_event_table( $site ) . '
@@ -315,7 +315,7 @@ function mc_get_all_holidays( $before, $after, $today ) {
315
function mc_get_rss_events( $cat_id = false ) {
316
global $wpdb;
317
$mcdb = $wpdb;
318
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
319
$mcdb = mc_remote_db();
320
}
321
if ( $cat_id ) {
@@ -372,7 +372,7 @@ function mc_get_search_results( $search ) {
372
global $wpdb;
373
$mcdb = $wpdb;
374
$event_array = array();
375
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
376
$mcdb = mc_remote_db();
377
}
378
$before = apply_filters( 'mc_past_search_results', 0 );
@@ -439,7 +439,7 @@ function mc_get_event_core( $id, $rebuild = false ) {
439
440
global $wpdb;
441
$mcdb = $wpdb;
442
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
443
$mcdb = mc_remote_db();
444
}
445
@@ -463,7 +463,7 @@ function mc_get_event_core( $id, $rebuild = false ) {
463
function mc_get_first_event( $id ) {
464
global $wpdb;
465
$mcdb = $wpdb;
466
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
467
$mcdb = mc_remote_db();
468
}
469
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_event_id=%d', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
@@ -482,7 +482,7 @@ function mc_get_first_event( $id ) {
482
function mc_get_nearest_event( $id ) {
483
global $wpdb;
484
$mcdb = $wpdb;
485
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
486
$mcdb = mc_remote_db();
487
}
488
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_event_id=%d ORDER BY ABS( DATEDIFF( occur_begin, NOW() ) )', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
@@ -506,11 +506,11 @@ function mc_get_event( $id, $type = 'object' ) {
506
507
global $wpdb;
508
$mcdb = $wpdb;
509
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
510
$mcdb = mc_remote_db();
511
}
512
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_id=%d', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
513
- if ( 'object' == $type ) {
514
$event = mc_event_object( $event );
515
return $event;
516
} else {
@@ -535,7 +535,7 @@ function mc_get_event( $id, $type = 'object' ) {
535
function mc_get_data( $field, $id ) {
536
global $wpdb;
537
$mcdb = $wpdb;
538
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
539
$mcdb = mc_remote_db();
540
}
541
$result = $mcdb->get_var( $mcdb->prepare( "SELECT $field FROM " . my_calendar_table() . ' WHERE event_id = %d', $id ) );
@@ -554,15 +554,18 @@ function mc_get_data( $field, $id ) {
554
* @return array Array of event objects with dates as keys.
555
*/
556
function my_calendar_events( $args ) {
557
- $args = apply_filters( 'my_calendar_events_args', $args );
558
- $events = my_calendar_get_events( $args );
559
- $event_array = array();
560
-
561
// Get holidays to filter out.
562
- $args['category'] = get_option( 'mc_skip_holidays_category' );
563
- $args['holidays'] = 'holidays';
564
- $holidays = my_calendar_get_events( $args );
565
- $holiday_array = mc_set_date_array( $holidays );
566
// Get events into an easily parseable set, keyed by date.
567
if ( is_array( $events ) && ! empty( $events ) ) {
568
$event_array = mc_set_date_array( $events );
@@ -585,19 +588,19 @@ function my_calendar_events( $args ) {
585
*/
586
function my_calendar_events_now( $category = 'default', $template = '<strong>{link_title}</strong> {timerange}', $site = false ) {
587
if ( $site ) {
588
- $site = ( 'global' == $site ) ? BLOG_ID_CURRENT_SITE : $site;
589
switch_to_blog( $site );
590
}
591
592
global $wpdb;
593
$mcdb = $wpdb;
594
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
595
$mcdb = mc_remote_db();
596
}
597
598
$arr_events = array();
599
$select_published = mc_select_published();
600
- $cat_limit = ( 'default' != $category ) ? mc_select_category( $category ) : array();
601
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
602
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
603
$exclude_categories = mc_private_categories();
@@ -688,7 +691,7 @@ function mc_get_related( $id ) {
688
* @return boolean
689
*/
690
function mc_is_preview() {
691
- if ( isset( $_GET['preview'] ) && 'true' == $_GET['preview'] && current_user_can( 'mc_manage_events' ) ) {
692
return true;
693
}
694
@@ -730,7 +733,7 @@ function mc_set_date_array( $events ) {
730
foreach ( $events as $event ) {
731
$date = date( 'Y-m-d', strtotime( $event->occur_begin ) );
732
$end = date( 'Y-m-d', strtotime( $event->occur_end ) );
733
- if ( $date != $end ) {
734
$start = strtotime( $date );
735
$end = strtotime( $end );
736
do {
@@ -778,14 +781,14 @@ function mc_get_db_type() {
778
global $wpdb;
779
$mcdb = $wpdb;
780
$db_type = 'MyISAM';
781
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
782
$mcdb = mc_remote_db();
783
}
784
$my_calendar = my_calendar_table();
785
$dbs = $mcdb->get_results( $wpdb->prepare( 'SHOW TABLE STATUS WHERE name=%s', $my_calendar ) );
786
foreach ( $dbs as $db ) {
787
$db = (array) $db;
788
- if ( my_calendar_table() == $db['Name'] ) {
789
$db_type = $db['Engine'];
790
}
791
}
79
80
global $wpdb;
81
$mcdb = $wpdb;
82
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
83
$mcdb = mc_remote_db();
84
}
85
86
+ if ( 'holidays' === $holidays && '' === $category ) {
87
return array();
88
}
89
90
if ( null === $holidays ) {
91
+ $ccategory = ( isset( $_GET['mcat'] ) && '' !== trim( $_GET['mcat'] ) ) ? $_GET['mcat'] : $category;
92
} else {
93
$ccategory = $category;
94
}
98
$clhost = ( isset( $_GET['mc_host'] ) ) ? $_GET['mc_host'] : $host;
99
100
// If location value is not set, then location type shouldn't be set.
101
+ if ( 'all' === $clvalue ) {
102
$cltype = 'all';
103
}
104
106
return array();
107
} // Not valid dates.
108
109
+ $cat_limit = ( 'all' !== $ccategory ) ? mc_select_category( $ccategory ) : array();
110
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
111
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
112
+ $select_author = ( 'all' !== $clauth ) ? mc_select_author( $clauth ) : '';
113
+ $select_host = ( 'all' !== $clhost ) ? mc_select_host( $clhost ) : '';
114
$select_location = mc_select_location( $cltype, $clvalue );
115
$select_access = ( isset( $_GET['access'] ) ) ? mc_access_limit( $_GET['access'] ) : '';
116
$select_published = mc_select_published();
188
189
global $wpdb;
190
$mcdb = $wpdb;
191
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
192
$mcdb = mc_remote_db();
193
}
194
195
$exclude_categories = mc_private_categories();
196
+ $cat_limit = ( 'default' !== $category ) ? mc_select_category( $category ) : array();
197
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
198
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
199
$select_location = mc_select_location( $ltype, $lvalue );
200
$select_access = ( isset( $_GET['access'] ) ) ? mc_access_limit( $_GET['access'] ) : '';
201
$select_published = mc_select_published();
202
+ $select_author = ( 'default' !== $author ) ? mc_select_author( $author ) : '';
203
+ $select_host = ( 'default' !== $host ) ? mc_select_host( $host ) : '';
204
$date = date( 'Y-m-d', current_time( 'timestamp' ) );
205
206
$limit = "$select_published $select_category $select_author $select_host $select_location $select_access $search";
226
);
227
}
228
// Events happening today.
229
+ if ( 'yes' === $today ) {
230
$events3 = $mcdb->get_results(
231
'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end
232
FROM ' . my_calendar_event_table( $site ) . '
315
function mc_get_rss_events( $cat_id = false ) {
316
global $wpdb;
317
$mcdb = $wpdb;
318
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
319
$mcdb = mc_remote_db();
320
}
321
if ( $cat_id ) {
372
global $wpdb;
373
$mcdb = $wpdb;
374
$event_array = array();
375
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
376
$mcdb = mc_remote_db();
377
}
378
$before = apply_filters( 'mc_past_search_results', 0 );
439
440
global $wpdb;
441
$mcdb = $wpdb;
442
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
443
$mcdb = mc_remote_db();
444
}
445
463
function mc_get_first_event( $id ) {
464
global $wpdb;
465
$mcdb = $wpdb;
466
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
467
$mcdb = mc_remote_db();
468
}
469
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_event_id=%d', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
482
function mc_get_nearest_event( $id ) {
483
global $wpdb;
484
$mcdb = $wpdb;
485
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
486
$mcdb = mc_remote_db();
487
}
488
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_event_id=%d ORDER BY ABS( DATEDIFF( occur_begin, NOW() ) )', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
506
507
global $wpdb;
508
$mcdb = $wpdb;
509
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
510
$mcdb = mc_remote_db();
511
}
512
$event = $mcdb->get_row( $wpdb->prepare( 'SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end FROM ' . my_calendar_event_table() . ' JOIN ' . my_calendar_table() . ' ON (event_id=occur_event_id) JOIN ' . my_calendar_categories_table() . ' ON (event_category=category_id) WHERE occur_id=%d', $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
513
+ if ( 'object' === $type ) {
514
$event = mc_event_object( $event );
515
return $event;
516
} else {
535
function mc_get_data( $field, $id ) {
536
global $wpdb;
537
$mcdb = $wpdb;
538
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
539
$mcdb = mc_remote_db();
540
}
541
$result = $mcdb->get_var( $mcdb->prepare( "SELECT $field FROM " . my_calendar_table() . ' WHERE event_id = %d', $id ) );
554
* @return array Array of event objects with dates as keys.
555
*/
556
function my_calendar_events( $args ) {
557
+ $args = apply_filters( 'my_calendar_events_args', $args );
558
+ $events = my_calendar_get_events( $args );
559
+ $event_array = array();
560
+ $holiday_array = array();
561
+ $holidays = array();
562
// Get holidays to filter out.
563
+ if ( get_option( 'mc_skip_holidays_category' ) ) {
564
+ $args['category'] = get_option( 'mc_skip_holidays_category' );
565
+ $args['holidays'] = 'holidays';
566
+ $holidays = my_calendar_get_events( $args );
567
+ $holiday_array = mc_set_date_array( $holidays );
568
+ }
569
// Get events into an easily parseable set, keyed by date.
570
if ( is_array( $events ) && ! empty( $events ) ) {
571
$event_array = mc_set_date_array( $events );
588
*/
589
function my_calendar_events_now( $category = 'default', $template = '<strong>{link_title}</strong> {timerange}', $site = false ) {
590
if ( $site ) {
591
+ $site = ( 'global' === $site ) ? BLOG_ID_CURRENT_SITE : $site;
592
switch_to_blog( $site );
593
}
594
595
global $wpdb;
596
$mcdb = $wpdb;
597
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
598
$mcdb = mc_remote_db();
599
}
600
601
$arr_events = array();
602
$select_published = mc_select_published();
603
+ $cat_limit = ( 'default' !== $category ) ? mc_select_category( $category ) : array();
604
$join = ( isset( $cat_limit[0] ) ) ? $cat_limit[0] : '';
605
$select_category = ( isset( $cat_limit[1] ) ) ? $cat_limit[1] : '';
606
$exclude_categories = mc_private_categories();
691
* @return boolean
692
*/
693
function mc_is_preview() {
694
+ if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] && current_user_can( 'mc_manage_events' ) ) {
695
return true;
696
}
697
733
foreach ( $events as $event ) {
734
$date = date( 'Y-m-d', strtotime( $event->occur_begin ) );
735
$end = date( 'Y-m-d', strtotime( $event->occur_end ) );
736
+ if ( $date !== $end ) {
737
$start = strtotime( $date );
738
$end = strtotime( $end );
739
do {
781
global $wpdb;
782
$mcdb = $wpdb;
783
$db_type = 'MyISAM';
784
+ if ( 'true' === get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
785
$mcdb = mc_remote_db();
786
}
787
$my_calendar = my_calendar_table();
788
$dbs = $mcdb->get_results( $wpdb->prepare( 'SHOW TABLE STATUS WHERE name=%s', $my_calendar ) );
789
foreach ( $dbs as $db ) {
790
$db = (array) $db;
791
+ if ( my_calendar_table() === $db['Name'] ) {
792
$db_type = $db['Engine'];
793
}
794
}
my-calendar-generator.php CHANGED
@@ -241,6 +241,10 @@ function mc_generator( $type ) {
241
<label for="months" id='lmonths'><?php _e( 'Months to show in list view', 'my-calendar' ); ?></label>
242
<input type="number" min="1" max="12" step="1" name="months" id="lmonths" value="" /><br/>
243
</p>
244
<?php
245
}
246
if ( 'upcoming' == $type || 'today' == $type ) {
241
<label for="months" id='lmonths'><?php _e( 'Months to show in list view', 'my-calendar' ); ?></label>
242
<input type="number" min="1" max="12" step="1" name="months" id="lmonths" value="" /><br/>
243
</p>
244
+ <p>
245
+ <label for="search" id='sterm'><?php _e( 'Search keyword', 'my-calendar' ); ?></label>
246
+ <input type="text" name="search" id="sterm" value="" /><br/>
247
+ </p>
248
<?php
249
}
250
if ( 'upcoming' == $type || 'today' == $type ) {
my-calendar-group-manager.php CHANGED
@@ -24,7 +24,7 @@ function my_calendar_group_edit() {
24
$group_id = ! empty( $_POST['group_id'] ) ? $_POST['group_id'] : '';
25
26
if ( isset( $_GET['mode'] ) ) {
27
- if ( 'edit' == $_GET['mode'] ) {
28
$action = 'edit';
29
$event_id = (int) $_GET['event_id'];
30
$group_id = (int) $_GET['group_id'];
@@ -91,7 +91,7 @@ function my_calendar_group_edit() {
91
<div class="wrap my-calendar-admin" id="my-calendar">
92
<?php
93
my_calendar_check_db();
94
- if ( 'edit' == $action ) {
95
echo '<h1>' . __( 'Edit Event Group', 'my-calendar' ) . '</h1>';
96
if ( empty( $event_id ) || empty( $group_id ) ) {
97
mc_show_error( __( 'You must provide an event group id in order to edit it', 'my-calendar' ) );
@@ -146,7 +146,7 @@ function my_calendar_save_group( $action, $output, $event_id = false ) {
146
$proceed = $output[0];
147
$message = '';
148
149
- if ( 'edit' == $action && true == $proceed ) {
150
$event_author = (int) ( $_POST['event_author'] );
151
if ( mc_can_edit_event( $event_id ) ) {
152
$update = $output[2];
@@ -189,7 +189,7 @@ function my_calendar_save_group( $action, $output, $event_id = false ) {
189
function mc_group_data( $event_id = false ) {
190
global $wpdb, $submission;
191
if ( false !== $event_id ) {
192
- if ( intval( $event_id ) != $event_id ) {
193
return mc_show_error( __( 'Sorry! That\'s an invalid event key.', 'my-calendar' ), false );
194
} else {
195
$data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . my_calendar_table() . ' WHERE event_id=%d LIMIT 1', $event_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
@@ -230,7 +230,7 @@ function mc_compare_group_members( $group_id, $field = false ) {
230
$count = count( $results );
231
for ( $i = 0; $i < $count; $i ++ ) {
232
$n = ( ( $i + 1 ) > $count - 1 ) ? 0 : $i + 1;
233
- if ( md5( implode( '', $results[ $i ] ) ) != md5( implode( '', $results[ $n ] ) ) ) {
234
return false;
235
}
236
}
@@ -251,28 +251,28 @@ function mc_group_form( $group_id, $type = 'break' ) {
251
$event_id = (int) $_GET['event_id'];
252
$nonce = wp_create_nonce( 'my-calendar-nonce' );
253
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT event_id, event_begin, event_time FROM ' . my_calendar_table() . ' WHERE event_group_id = %d', $group_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
254
- if ( 'apply' == $type ) {
255
$warning = ( ! mc_compare_group_members( $group_id ) ) ? '<p class="warning">' . __( '<strong>NOTE:</strong> The group editable fields for the events in this group do not match', 'my-calendar' ) . '</p>' : '<p class="matched">' . __( 'The group editable fields for the events in this group match.', 'my-calendar' ) . '</p>';
256
} else {
257
$warning = '';
258
}
259
- $class = ( 'break' == $type ) ? 'break' : 'apply';
260
$group = "<div class='group $class'>";
261
$group .= $warning;
262
- $group .= ( 'apply' == $type ) ? '<fieldset><legend>' . __( 'Apply these changes to:', 'my-calendar' ) . '</legend>' : '';
263
- $group .= ( 'break' == $type ) ? "<form method='post' action='" . admin_url( "admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id=$event_id&amp;group_id=$group_id" ) . "'>
264
<div><input type='hidden' value='" . esc_attr( $group_id ) . "' name='group_id' /><input type='hidden' value='" . esc_attr( $type ) . "' name='event_action' /><input type='hidden' name='_wpnonce' value='$nonce' />
265
</div>" : '';
266
$group .= "<ul class='checkboxes'>";
267
- $checked = ( 'apply' == $type ) ? ' checked="checked"' : '';
268
foreach ( $results as $result ) {
269
$date = date_i18n( 'D, j M, Y', strtotime( $result->event_begin ) );
270
$time = date_i18n( 'g:i a', strtotime( $result->event_time ) );
271
$group .= "<li><input type='checkbox' name='$type" . "[]' value='$result->event_id' id='$type$result->event_id'$checked /> <label for='break$result->event_id'><a href='#event$result->event_id'>#$result->event_id</a>: $date; $time</label></li>\n";
272
}
273
$group .= "<li><input type='checkbox' class='selectall' id='$type'$checked /> <label for='$type'><b>" . __( 'Check/Uncheck all', 'my-calendar' ) . "</b></label></li>\n</ul>";
274
- $group .= ( 'apply' == $type ) ? '</fieldset>' : '';
275
- $group .= ( 'break' == $type ) ? "<p><input type='submit' class='button' value='" . __( 'Remove checked events from this group', 'my-calendar' ) . "' /></p></form>" : '';
276
$group .= '</div>';
277
278
return $group;
@@ -318,7 +318,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
318
$current_user = wp_get_current_user();
319
$has_data = ( empty( $data ) ) ? false : true;
320
$user = get_userdata( $user_ID );
321
- $input_all = ( get_option( 'mc_input_options_administrators' ) == 'true' && current_user_can( 'manage_options' ) ) ? true : false;
322
$mc_input = get_option( 'mc_input_options' );
323
$group_id = ( ! empty( $data->event_group_id ) ) ? $data->event_group_id : mc_group_id();
324
$title = '';
@@ -368,7 +368,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
368
<?php
369
$apply = mc_group_form( $group_id, 'apply' );
370
echo $apply;
371
- if ( 0 == $data->event_repeats && ( 'S1' == $data->event_recur || 'S' == $data->event_recur ) ) {
372
$span_checked = '';
373
if ( ! empty( $data ) && 1 == $data->event_span ) {
374
$span_checked = ' checked="checked"';
@@ -393,7 +393,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
393
<div><input type='hidden' name='event_span' value='<?php echo esc_attr( $data->event_span ); ?>'/></div>
394
<?php
395
}
396
- if ( 'on' == $mc_input['event_desc'] || $input_all ) {
397
?>
398
<div id="group_description">
399
<label for="content">
@@ -408,7 +408,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
408
</div>
409
<?php
410
}
411
- if ( 'on' == $mc_input['event_short'] || $input_all ) {
412
?>
413
<p>
414
<label for="e_short">
@@ -478,20 +478,20 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
478
} elseif ( is_object( $u ) && $u->ID == $user->ID && empty( $data->event_host ) ) {
479
echo ' selected="selected"';
480
}
481
- $display_name = ( '' == $u->display_name ) ? $u->user_nicename : $u->display_name;
482
echo ">$display_name</option>\n";
483
}
484
?>
485
</select>
486
</p>
487
<?php
488
- if ( 'on' == $mc_input['event_category'] || $input_all ) {
489
$match = '';
490
if ( ! mc_compare_group_members( $group_id, 'event_category' ) ) {
491
$match = ' <span class="nomatch">' . __( 'Fields do not match', 'my-calendar' ) . '</span>';
492
}
493
494
- if ( 'true' != get_option( 'mc_multiple_categories' ) ) {
495
$select = mc_category_select( $data, true, false );
496
$return = '<p class="mc_category"><label for="event_category">' . __( 'Category', 'my-calendar-submissions' ) . $match . '</label><select class="widefat" name="event_category" id="e_category">' . $select . '</select></p>';
497
} else {
@@ -506,12 +506,12 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
506
</div>
507
<?php
508
}
509
- if ( 'on' == $mc_input['event_link'] || $input_all ) {
510
if ( ! empty( $data ) && 1 == $data->event_link_expires ) {
511
$exp_checked = ' checked="checked"';
512
} elseif ( ! empty( $data ) && 0 == $data->event_link_expires ) {
513
$exp_checked = '';
514
- } elseif ( 'true' == get_option( 'mc_event_link_expires' ) ) {
515
$exp_checked = ' checked="checked"';
516
}
517
?>
@@ -535,7 +535,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
535
</div>
536
</div>
537
<?php
538
- if ( 'on' == $mc_input['event_open'] || $input_all ) { // Add a "don't change" option here. JCD TODO.
539
?>
540
<div class="ui-sortable meta-box-sortables">
541
<div class="postbox">
@@ -558,7 +558,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
558
</div>
559
<?php
560
}
561
- if ( ( 'on' == $mc_input['event_location'] || 'on' == $mc_input['event_location_dropdown'] ) || $input_all ) {
562
?>
563
<div class="ui-sortable meta-box-sortables">
564
<div class="postbox">
@@ -569,7 +569,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
569
<legend><?php _e( 'Event Location', 'my-calendar' ); ?></legend>
570
<?php
571
}
572
- if ( 'on' == $mc_input['event_location_dropdown'] || $input_all ) {
573
$locations = mc_get_locations( 'group-manager' );
574
if ( ! empty( $locations ) ) {
575
?>
@@ -596,7 +596,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
596
} else {
597
echo '<input type="hidden" name="location_preset" value="none"/>';
598
}
599
- if ( 'on' == $mc_input['event_location'] || $input_all ) {
600
?>
601
<p>
602
<label for="e_label">
@@ -769,7 +769,7 @@ function my_calendar_print_group_fields( $data, $mode, $event_id, $group_id = ''
769
</fieldset>
770
<?php
771
}
772
- if ( ( 'on' == $mc_input['event_location'] || 'on' == $mc_input['event_location_dropdown'] ) || $input_all ) {
773
?>
774
</fieldset>
775
</div>
@@ -806,7 +806,7 @@ function mc_check_group_data( $action, $post ) {
806
return '';
807
}
808
$errors = '';
809
- if ( 'add' == $action || 'edit' == $action || 'copy' == $action ) {
810
$title = ! empty( $post['event_title'] ) ? trim( $post['event_title'] ) : '';
811
$desc = ! empty( $post['content'] ) ? trim( $post['content'] ) : '';
812
$short = ! empty( $post['event_short'] ) ? trim( $post['event_short'] ) : '';
@@ -837,7 +837,7 @@ function mc_check_group_data( $action, $post ) {
837
$event_image = esc_url_raw( $post['event_image'] );
838
$event_span = ! empty( $post['event_span'] ) ? 1 : 0;
839
// Set location.
840
- if ( 'none' != $location_preset ) {
841
$location = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . my_calendar_locations_table() . ' WHERE location_id = %d', $location_preset ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
842
$event_label = $location->location_label;
843
$event_street = $location->location_street;
@@ -916,7 +916,7 @@ function mc_check_group_data( $action, $post ) {
916
917
$submit = array_map( 'mc_kses_post', $submit );
918
919
- if ( 'edit' == $action ) {
920
unset( $submit['event_author'] );
921
}
922
$data = array( $proceed, false, $submit, $errors );
@@ -935,7 +935,7 @@ function mc_list_groups() {
935
936
$sortby = ( isset( $_GET['sort'] ) ) ? (int) $_GET['sort'] : get_option( 'mc_default_sort' );
937
if ( isset( $_GET['order'] ) ) {
938
- $sortdir = ( isset( $_GET['order'] ) && 'ASC' == $_GET['order'] ) ? 'ASC' : 'default';
939
} else {
940
$sortdir = 'default';
941
}
@@ -971,8 +971,8 @@ function mc_list_groups() {
971
$sortbyvalue = 'event_begin';
972
}
973
}
974
- $sortbydirection = ( 'default' == $sortdir ) ? 'DESC' : $sortdir;
975
- $sorting = ( 'DESC' == $sortbydirection ) ? '&amp;order=ASC' : '';
976
977
$current = empty( $_GET['paged'] ) ? 1 : intval( $_GET['paged'] );
978
$screen = get_current_screen();
@@ -1003,13 +1003,13 @@ function mc_list_groups() {
1003
<div class='inside'>
1004
<ul class="links">
1005
<li>
1006
- <a <?php echo ( isset( $_GET['limit'] ) && 'grouped' == $_GET['limit'] ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups&amp;limit=grouped#my-calendar-admin-table' ); ?>"><?php _e( 'Grouped Events', 'my-calendar' ); ?></a>
1007
</li>
1008
<li>
1009
- <a <?php echo ( isset( $_GET['limit'] ) && 'ungrouped' == $_GET['limit'] ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups&amp;limit=ungrouped#my-calendar-admin-table' ); ?>"><?php _e( 'Ungrouped Events', 'my-calendar' ); ?></a>
1010
</li>
1011
<li>
1012
- <a <?php echo ( isset( $_GET['limit'] ) && 'all' == $_GET['limit'] || ! isset( $_GET['limit'] ) ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups#my-calendar-admin-table' ); ?>"><?php _e( 'All', 'my-calendar' ); ?></a>
1013
</li>
1014
</ul>
1015
<p><?php _e( 'Check a set of events to group them for mass editing.', 'my-calendar' ); ?></p>
@@ -1069,7 +1069,7 @@ function mc_list_groups() {
1069
$class = '';
1070
$categories = $wpdb->get_results( 'SELECT * FROM ' . my_calendar_categories_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1071
foreach ( $events as $event ) {
1072
- $class = ( 'alternate' == $class ) ? '' : 'alternate';
1073
$spam = ( 1 == $event->event_flagged ) ? ' spam' : '';
1074
$spam_label = ( 1 == $event->event_flagged ) ? '<strong>Possible spam:</strong> ' : '';
1075
$author = ( 0 != $event->event_author ) ? get_userdata( $event->event_author ) : 'Public Submitter';
@@ -1130,7 +1130,7 @@ function mc_list_groups() {
1130
</td>
1131
<td><?php echo strip_tags( stripslashes( $event->event_label ) ); ?></td>
1132
<?php
1133
- if ( '23:59:59' != $event->event_endtime ) {
1134
$event_time = date_i18n( get_option( 'mc_time_format' ), strtotime( $event->event_time ) );
1135
} else {
1136
$event_time = mc_notime_label( $event );
24
$group_id = ! empty( $_POST['group_id'] ) ? $_POST['group_id'] : '';
25
26
if ( isset( $_GET['mode'] ) ) {
27
+ if ( 'edit' === $_GET['mode'] ) {
28
$action = 'edit';
29
$event_id = (int) $_GET['event_id'];
30
$group_id = (int) $_GET['group_id'];
91
<div class="wrap my-calendar-admin" id="my-calendar">
92
<?php
93
my_calendar_check_db();
94
+ if ( 'edit' === $action ) {
95
echo '<h1>' . __( 'Edit Event Group', 'my-calendar' ) . '</h1>';
96
if ( empty( $event_id ) || empty( $group_id ) ) {
97
mc_show_error( __( 'You must provide an event group id in order to edit it', 'my-calendar' ) );
146
$proceed = $output[0];
147
$message = '';
148
149
+ if ( 'edit' === $action && true == $proceed ) {
150
$event_author = (int) ( $_POST['event_author'] );
151
if ( mc_can_edit_event( $event_id ) ) {
152
$update = $output[2];
189
function mc_group_data( $event_id = false ) {
190
global $wpdb, $submission;
191
if ( false !== $event_id ) {
192
+ if ( intval( $event_id ) !== $event_id ) {
193
return mc_show_error( __( 'Sorry! That\'s an invalid event key.', 'my-calendar' ), false );
194
} else {
195
$data = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . my_calendar_table() . ' WHERE event_id=%d LIMIT 1', $event_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
230
$count = count( $results );
231
for ( $i = 0; $i < $count; $i ++ ) {
232
$n = ( ( $i + 1 ) > $count - 1 ) ? 0 : $i + 1;
233
+ if ( md5( implode( '', $results[ $i ] ) ) !== md5( implode( '', $results[ $n ] ) ) ) {
234
return false;
235
}
236
}
251
$event_id = (int) $_GET['event_id'];
252
$nonce = wp_create_nonce( 'my-calendar-nonce' );
253
$results = $wpdb->get_results( $wpdb->prepare( 'SELECT event_id, event_begin, event_time FROM ' . my_calendar_table() . ' WHERE event_group_id = %d', $group_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
254
+ if ( 'apply' === $type ) {
255
$warning = ( ! mc_compare_group_members( $group_id ) ) ? '<p class="warning">' . __( '<strong>NOTE:</strong> The group editable fields for the events in this group do not match', 'my-calendar' ) . '</p>' : '<p class="matched">' . __( 'The group editable fields for the events in this group match.', 'my-calendar' ) . '</p>';
256
} else {
257
$warning = '';
258
}
259
+ $class = ( 'break' === $type ) ? 'break' : 'apply';
260
$group = "<div class='group $class'>";
261
$group .= $warning;
262
+ $group .= ( 'apply' === $type ) ? '<fieldset><legend>' . __( 'Apply these changes to:', 'my-calendar' ) . '</legend>' : '';
263
+ $group .= ( 'break' === $type ) ? "<form method='post' action='" . admin_url( "admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id=$event_id&amp;group_id=$group_id" ) . "'>
264
<div><input type='hidden' value='" . esc_attr( $group_id ) . "' name='group_id' /><input type='hidden' value='" . esc_attr( $type ) . "' name='event_action' /><input type='hidden' name='_wpnonce' value='$nonce' />
265
</div>" : '';
266
$group .= "<ul class='checkboxes'>";
267
+ $checked = ( 'apply' === $type ) ? ' checked="checked"' : '';
268
foreach ( $results as $result ) {
269
$date = date_i18n( 'D, j M, Y', strtotime( $result->event_begin ) );
270
$time = date_i18n( 'g:i a', strtotime( $result->event_time ) );
271
$group .= "<li><input type='checkbox' name='$type" . "[]' value='$result->event_id' id='$type$result->event_id'$checked /> <label for='break$result->event_id'><a href='#event$result->event_id'>#$result->event_id</a>: $date; $time</label></li>\n";
272
}
273
$group .= "<li><input type='checkbox' class='selectall' id='$type'$checked /> <label for='$type'><b>" . __( 'Check/Uncheck all', 'my-calendar' ) . "</b></label></li>\n</ul>";
274
+ $group .= ( 'apply' === $type ) ? '</fieldset>' : '';
275
+ $group .= ( 'break' === $type ) ? "<p><input type='submit' class='button' value='" . __( 'Remove checked events from this group', 'my-calendar' ) . "' /></p></form>" : '';
276
$group .= '</div>';
277
278
return $group;
318
$current_user = wp_get_current_user();
319
$has_data = ( empty( $data ) ) ? false : true;
320
$user = get_userdata( $user_ID );
321
+ $input_all = ( get_option( 'mc_input_options_administrators' ) === 'true' && current_user_can( 'manage_options' ) ) ? true : false;
322
$mc_input = get_option( 'mc_input_options' );
323
$group_id = ( ! empty( $data->event_group_id ) ) ? $data->event_group_id : mc_group_id();
324
$title = '';
368
<?php
369
$apply = mc_group_form( $group_id, 'apply' );
370
echo $apply;
371
+ if ( 0 == $data->event_repeats && ( 'S1' === $data->event_recur || 'S' === $data->event_recur ) ) {
372
$span_checked = '';
373
if ( ! empty( $data ) && 1 == $data->event_span ) {
374
$span_checked = ' checked="checked"';
393
<div><input type='hidden' name='event_span' value='<?php echo esc_attr( $data->event_span ); ?>'/></div>
394
<?php
395
}
396
+ if ( 'on' === $mc_input['event_desc'] || $input_all ) {
397
?>
398
<div id="group_description">
399
<label for="content">
408
</div>
409
<?php
410
}
411
+ if ( 'on' === $mc_input['event_short'] || $input_all ) {
412
?>
413
<p>
414
<label for="e_short">
478
} elseif ( is_object( $u ) && $u->ID == $user->ID && empty( $data->event_host ) ) {
479
echo ' selected="selected"';
480
}
481
+ $display_name = ( '' === $u->display_name ) ? $u->user_nicename : $u->display_name;
482
echo ">$display_name</option>\n";
483
}
484
?>
485
</select>
486
</p>
487
<?php
488
+ if ( 'on' === $mc_input['event_category'] || $input_all ) {
489
$match = '';
490
if ( ! mc_compare_group_members( $group_id, 'event_category' ) ) {
491
$match = ' <span class="nomatch">' . __( 'Fields do not match', 'my-calendar' ) . '</span>';
492
}
493
494
+ if ( 'true' !== get_option( 'mc_multiple_categories' ) ) {
495
$select = mc_category_select( $data, true, false );
496
$return = '<p class="mc_category"><label for="event_category">' . __( 'Category', 'my-calendar-submissions' ) . $match . '</label><select class="widefat" name="event_category" id="e_category">' . $select . '</select></p>';
497
} else {
506
</div>
507
<?php
508
}
509
+ if ( 'on' === $mc_input['event_link'] || $input_all ) {
510
if ( ! empty( $data ) && 1 == $data->event_link_expires ) {
511
$exp_checked = ' checked="checked"';
512
} elseif ( ! empty( $data ) && 0 == $data->event_link_expires ) {
513
$exp_checked = '';
514
+ } elseif ( 'true' === get_option( 'mc_event_link_expires' ) ) {
515
$exp_checked = ' checked="checked"';
516
}
517
?>
535
</div>
536
</div>
537
<?php
538
+ if ( 'on' === $mc_input['event_open'] || $input_all ) { // Add a "don't change" option here. JCD TODO.
539
?>
540
<div class="ui-sortable meta-box-sortables">
541
<div class="postbox">
558
</div>
559
<?php
560
}
561
+ if ( ( 'on' === $mc_input['event_location'] || 'on' === $mc_input['event_location_dropdown'] ) || $input_all ) {
562
?>
563
<div class="ui-sortable meta-box-sortables">
564
<div class="postbox">
569
<legend><?php _e( 'Event Location', 'my-calendar' ); ?></legend>
570
<?php
571
}
572
+ if ( 'on' === $mc_input['event_location_dropdown'] || $input_all ) {
573
$locations = mc_get_locations( 'group-manager' );
574
if ( ! empty( $locations ) ) {
575
?>
596
} else {
597
echo '<input type="hidden" name="location_preset" value="none"/>';
598
}
599
+ if ( 'on' === $mc_input['event_location'] || $input_all ) {
600
?>
601
<p>
602
<label for="e_label">
769
</fieldset>
770
<?php
771
}
772
+ if ( ( 'on' === $mc_input['event_location'] || 'on' === $mc_input['event_location_dropdown'] ) || $input_all ) {
773
?>
774
</fieldset>
775
</div>
806
return '';
807
}
808
$errors = '';
809
+ if ( 'add' === $action || 'edit' === $action || 'copy' === $action ) {
810
$title = ! empty( $post['event_title'] ) ? trim( $post['event_title'] ) : '';
811
$desc = ! empty( $post['content'] ) ? trim( $post['content'] ) : '';
812
$short = ! empty( $post['event_short'] ) ? trim( $post['event_short'] ) : '';
837
$event_image = esc_url_raw( $post['event_image'] );
838
$event_span = ! empty( $post['event_span'] ) ? 1 : 0;
839
// Set location.
840
+ if ( 'none' !== $location_preset ) {
841
$location = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . my_calendar_locations_table() . ' WHERE location_id = %d', $location_preset ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
842
$event_label = $location->location_label;
843
$event_street = $location->location_street;
916
917
$submit = array_map( 'mc_kses_post', $submit );
918
919
+ if ( 'edit' === $action ) {
920
unset( $submit['event_author'] );
921
}
922
$data = array( $proceed, false, $submit, $errors );
935
936
$sortby = ( isset( $_GET['sort'] ) ) ? (int) $_GET['sort'] : get_option( 'mc_default_sort' );
937
if ( isset( $_GET['order'] ) ) {
938
+ $sortdir = ( isset( $_GET['order'] ) && 'ASC' === $_GET['order'] ) ? 'ASC' : 'default';
939
} else {
940
$sortdir = 'default';
941
}
971
$sortbyvalue = 'event_begin';
972
}
973
}
974
+ $sortbydirection = ( 'default' === $sortdir ) ? 'DESC' : $sortdir;
975
+ $sorting = ( 'DESC' === $sortbydirection ) ? '&amp;order=ASC' : '';
976
977
$current = empty( $_GET['paged'] ) ? 1 : intval( $_GET['paged'] );
978
$screen = get_current_screen();
1003
<div class='inside'>
1004
<ul class="links">
1005
<li>
1006
+ <a <?php echo ( isset( $_GET['limit'] ) && 'grouped' === $_GET['limit'] ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups&amp;limit=grouped#my-calendar-admin-table' ); ?>"><?php _e( 'Grouped Events', 'my-calendar' ); ?></a>
1007
</li>
1008
<li>
1009
+ <a <?php echo ( isset( $_GET['limit'] ) && 'ungrouped' === $_GET['limit'] ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups&amp;limit=ungrouped#my-calendar-admin-table' ); ?>"><?php _e( 'Ungrouped Events', 'my-calendar' ); ?></a>
1010
</li>
1011
<li>
1012
+ <a <?php echo ( isset( $_GET['limit'] ) && 'all' === $_GET['limit'] || ! isset( $_GET['limit'] ) ) ? ' class="active-link"' : ''; ?> href="<?php echo admin_url( 'admin.php?page=my-calendar-groups#my-calendar-admin-table' ); ?>"><?php _e( 'All', 'my-calendar' ); ?></a>
1013
</li>
1014
</ul>
1015
<p><?php _e( 'Check a set of events to group them for mass editing.', 'my-calendar' ); ?></p>
1069
$class = '';
1070
$categories = $wpdb->get_results( 'SELECT * FROM ' . my_calendar_categories_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1071
foreach ( $events as $event ) {
1072
+ $class = ( 'alternate' === $class ) ? '' : 'alternate';
1073
$spam = ( 1 == $event->event_flagged ) ? ' spam' : '';
1074
$spam_label = ( 1 == $event->event_flagged ) ? '<strong>Possible spam:</strong> ' : '';
1075
$author = ( 0 != $event->event_author ) ? get_userdata( $event->event_author ) : 'Public Submitter';
1130
</td>
1131
<td><?php echo strip_tags( stripslashes( $event->event_label ) ); ?></td>
1132
<?php
1133
+ if ( '23:59:59' !== $event->event_endtime ) {
1134
$event_time = date_i18n( get_option( 'mc_time_format' ), strtotime( $event->event_time ) );
1135
} else {
1136
$event_time = mc_notime_label( $event );
my-calendar-install.php CHANGED
@@ -116,7 +116,7 @@ function mc_globals() {
116
);
117
118
$charset_collate = $wpdb->get_charset_collate();
119
- $event_fifth_week = ( get_option( 'mc_no_fifth_week' ) == 'true' ) ? 1 : 0;
120
121
$initial_db = 'CREATE TABLE ' . my_calendar_table() . " (
122
event_id INT(11) NOT NULL AUTO_INCREMENT,
@@ -255,7 +255,6 @@ function mc_default_settings() {
255
add_option( 'mc_multiple_categories', 'true' );
256
add_option( 'mc_event_link_expires', 'false' );
257
add_option( 'mc_apply_color', 'background' );
258
- add_option( 'mc_inverse_color', 'true' );
259
add_option(
260
'mc_input_options',
261
array(
@@ -324,7 +323,7 @@ function mc_default_settings() {
324
update_option( 'mc_update_notice', 1 );
325
mc_add_roles();
326
$has_uri = mc_guess_calendar();
327
- if ( false == $has_uri['response'] ) {
328
// if mc_guess_calendar returns a string, no valid URI was found.
329
$slug = sanitize_title( __( 'My Calendar', 'my-calendar' ) );
330
mc_generate_calendar_page( $slug );
@@ -383,18 +382,18 @@ function mc_migrate_db() {
383
// Step 1) check if early escapement is needed.
384
$count = $wpdb->get_var( 'SELECT count(1) from ' . my_calendar_event_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385
$count2 = $wpdb->get_var( 'SELECT count(1) from ' . my_calendar_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
386
if ( $count2 > 0 && $count > 0 ) {
387
return;
388
}
389
- if ( 0 == $count2 && 0 == $count ) {
390
return; // No events, migration unnecessary.
391
}
392
-
393
// Step 2) migrate events.
394
$events = $wpdb->get_results( 'SELECT event_id, event_begin, event_time, event_end, event_endtime FROM ' . my_calendar_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
395
foreach ( $events as $event ) {
396
// assign endtimes to all events.
397
- if ( '00:00:00' == $event->event_endtime && '00:00:00' != $event->event_time ) {
398
$event->event_endtime = date( 'H:i:s', strtotime( "$event->event_time +1 hour" ) );
399
mc_flag_event( $event->event_id, $event->event_endtime );
400
}
@@ -470,7 +469,7 @@ function mc_check_location_table( $event, $locations ) {
470
* @since 2.3.0
471
*/
472
function mc_transition_db() {
473
- if ( 'true' != get_option( 'mc_remote' ) ) {
474
global $wpdb;
475
$results = $wpdb->get_results( 'SELECT * FROM ' . my_calendar_locations_table(), ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
476
$locations = array();
@@ -502,7 +501,7 @@ function mc_transition_db() {
502
if ( $location ) {
503
mc_update_event( 'event_location', $location, $event['event_id'] );
504
} else {
505
- if ( '' == $event['event_label'] && '' == $event['event_street'] && '' == $event['event_url'] && '' == $event['event_city'] && '' == $event['event_state'] && '' == $event['event_country'] ) {
506
// don't insert the row if location does not have basic data.
507
} else {
508
$add = array(
@@ -534,7 +533,7 @@ function mc_transition_db() {
534
*/
535
function mc_check_imports() {
536
$output = '';
537
- if ( 'true' != get_option( 'ko_calendar_imported' ) ) {
538
if ( function_exists( 'check_calendar' ) ) {
539
$output .= "
540
<div id='message' class='updated'>
@@ -640,7 +639,7 @@ function my_calendar_rmdirr( $dirname ) {
640
* @param array $plugin Current plugin.
641
*/
642
function my_calendar_backup( $process, $plugin ) {
643
- if ( isset( $plugin['plugin'] ) && 'my-calendar/my-calendar.php' == $plugin['plugin'] ) {
644
$to = dirname( __FILE__ ) . '/../styles_backup/';
645
$from = dirname( __FILE__ ) . '/styles/';
646
my_calendar_copyr( $from, $to );
@@ -658,7 +657,7 @@ function my_calendar_backup( $process, $plugin ) {
658
* @param array $plugin Current plugin.
659
*/
660
function my_calendar_recover( $process, $plugin ) {
661
- if ( isset( $plugin['plugin'] ) && 'my-calendar/my-calendar.php' == $plugin['plugin'] ) {
662
$from = dirname( __FILE__ ) . '/../styles_backup/';
663
$to = dirname( __FILE__ ) . '/styles/';
664
my_calendar_copyr( $from, $to );
116
);
117
118
$charset_collate = $wpdb->get_charset_collate();
119
+ $event_fifth_week = ( get_option( 'mc_no_fifth_week' ) === 'true' ) ? 1 : 0;
120
121
$initial_db = 'CREATE TABLE ' . my_calendar_table() . " (
122
event_id INT(11) NOT NULL AUTO_INCREMENT,
255
add_option( 'mc_multiple_categories', 'true' );
256
add_option( 'mc_event_link_expires', 'false' );
257
add_option( 'mc_apply_color', 'background' );
258
add_option(
259
'mc_input_options',
260
array(
323
update_option( 'mc_update_notice', 1 );
324
mc_add_roles();
325
$has_uri = mc_guess_calendar();
326
+ if ( false === $has_uri['response'] ) {
327
// if mc_guess_calendar returns a string, no valid URI was found.
328
$slug = sanitize_title( __( 'My Calendar', 'my-calendar' ) );
329
mc_generate_calendar_page( $slug );
382
// Step 1) check if early escapement is needed.
383
$count = $wpdb->get_var( 'SELECT count(1) from ' . my_calendar_event_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
384
$count2 = $wpdb->get_var( 'SELECT count(1) from ' . my_calendar_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385
+ // If both tables have rows, the drop failed and this should exit.
386
if ( $count2 > 0 && $count > 0 ) {
387
return;
388
}
389
+ if ( 0 === $count2 && 0 === $count ) {
390
return; // No events, migration unnecessary.
391
}
392
// Step 2) migrate events.
393
$events = $wpdb->get_results( 'SELECT event_id, event_begin, event_time, event_end, event_endtime FROM ' . my_calendar_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
394
foreach ( $events as $event ) {
395
// assign endtimes to all events.
396
+ if ( '00:00:00' === $event->event_endtime && '00:00:00' !== $event->event_time ) {
397
$event->event_endtime = date( 'H:i:s', strtotime( "$event->event_time +1 hour" ) );
398
mc_flag_event( $event->event_id, $event->event_endtime );
399
}
469
* @since 2.3.0
470
*/
471
function mc_transition_db() {
472
+ if ( 'true' !== get_option( 'mc_remote' ) ) {
473
global $wpdb;
474
$results = $wpdb->get_results( 'SELECT * FROM ' . my_calendar_locations_table(), ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
475
$locations = array();
501
if ( $location ) {
502
mc_update_event( 'event_location', $location, $event['event_id'] );
503
} else {
504
+ if ( '' === $event['event_label'] && '' === $event['event_street'] && '' === $event['event_url'] && '' === $event['event_city'] && '' === $event['event_state'] && '' === $event['event_country'] ) {
505
// don't insert the row if location does not have basic data.
506
} else {
507
$add = array(
533
*/
534
function mc_check_imports() {
535
$output = '';
536
+ if ( 'true' !== get_option( 'ko_calendar_imported' ) ) {
537
if ( function_exists( 'check_calendar' ) ) {
538
$output .= "
539
<div id='message' class='updated'>
639
* @param array $plugin Current plugin.
640
*/
641
function my_calendar_backup( $process, $plugin ) {
642
+ if ( isset( $plugin['plugin'] ) && 'my-calendar/my-calendar.php' === $plugin['plugin'] ) {
643
$to = dirname( __FILE__ ) . '/../styles_backup/';
644
$from = dirname( __FILE__ ) . '/styles/';
645
my_calendar_copyr( $from, $to );
657
* @param array $plugin Current plugin.
658
*/
659
function my_calendar_recover( $process, $plugin ) {
660
+ if ( isset( $plugin['plugin'] ) && 'my-calendar/my-calendar.php' === $plugin['plugin'] ) {
661
$from = dirname( __FILE__ ) . '/../styles_backup/';
662
$to = dirname( __FILE__ ) . '/styles/';
663
my_calendar_copyr( $from, $to );
my-calendar-location-manager.php CHANGED
@@ -118,8 +118,8 @@ function mc_manage_locations() {
118
if ( isset( $_POST['mcl'] ) ) {
119
$query = $_POST['mcl'];
120
$db_type = mc_get_db_type();
121
- if ( '' != $query ) {
122
- if ( 'MyISAM' == $db_type ) {
123
$query = esc_sql( $query ); // Prepare query.
124
$search = ' WHERE MATCH(' . apply_filters( 'mc_search_fields', 'location_label,location_city,location_state,location_region,location_street,location_street2,location_phone' ) . ") AGAINST ( '$query' IN BOOLEAN MODE ) ";
125
} else {
@@ -225,7 +225,7 @@ function mc_manage_locations() {
225
<?php
226
$class = '';
227
foreach ( $locations as $location ) {
228
- $class = ( 'alternate' == $class ) ? '' : 'alternate';
229
?>
230
<tr class="<?php echo $class; ?>">
231
<th scope="row">
118
if ( isset( $_POST['mcl'] ) ) {
119
$query = $_POST['mcl'];
120
$db_type = mc_get_db_type();
121
+ if ( '' !== $query ) {
122
+ if ( 'MyISAM' === $db_type ) {
123
$query = esc_sql( $query ); // Prepare query.
124
$search = ' WHERE MATCH(' . apply_filters( 'mc_search_fields', 'location_label,location_city,location_state,location_region,location_street,location_street2,location_phone' ) . ") AGAINST ( '$query' IN BOOLEAN MODE ) ";
125
} else {
225
<?php
226
$class = '';
227
foreach ( $locations as $location ) {
228
+ $class = ( 'alternate' === $class ) ? '' : 'alternate';
229
?>
230
<tr class="<?php echo $class; ?>">
231
<th scope="row">
my-calendar-locations.php CHANGED
@@ -34,7 +34,7 @@ function mc_update_location( $field, $data, $location ) {
34
* Update settings for how location inputs are limited.
35
*/
36
function mc_update_location_controls() {
37
- if ( isset( $_POST['mc_locations'] ) && 'true' == $_POST['mc_locations'] ) {
38
$nonce = $_POST['_wpnonce'];
39
if ( ! wp_verify_nonce( $nonce, 'my-calendar-nonce' ) ) {
40
wp_die( 'Invalid nonce' );
@@ -99,7 +99,7 @@ function my_calendar_add_locations() {
99
die( 'Security check failed' );
100
}
101
}
102
- if ( isset( $_POST['mode'] ) && 'add' == $_POST['mode'] ) {
103
$add = array(
104
'location_label' => $_POST['location_label'],
105
'location_street' => $_POST['location_street'],
@@ -125,7 +125,7 @@ function my_calendar_add_locations() {
125
} else {
126
mc_show_error( __( 'Location could not be added to database', 'my-calendar' ) );
127
}
128
- } elseif ( isset( $_GET['location_id'] ) && 'delete' == $_GET['mode'] ) {
129
$results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . my_calendar_locations_table() . ' WHERE location_id=%d', $_GET['location_id'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
130
do_action( 'mc_delete_location', $results, (int) $_GET['location_id'] );
131
if ( $results ) {
@@ -133,10 +133,10 @@ function my_calendar_add_locations() {
133
} else {
134
mc_show_error( __( 'Location could not be deleted', 'my-calendar' ) );
135
}
136
- } elseif ( isset( $_GET['mode'] ) && isset( $_GET['location_id'] ) && 'edit' == $_GET['mode'] && ! isset( $_POST['mode'] ) ) {
137
$cur_loc = (int) $_GET['location_id'];
138
mc_show_location_form( 'edit', $cur_loc );
139
- } elseif ( isset( $_POST['location_id'] ) && isset( $_POST['location_label'] ) && 'edit' == $_POST['mode'] ) {
140
$update = array(
141
'location_label' => $_POST['location_label'],
142
'location_street' => $_POST['location_street'],
@@ -171,7 +171,7 @@ function my_calendar_add_locations() {
171
172
}
173
174
- if ( isset( $_GET['mode'] ) && 'edit' != $_GET['mode'] || isset( $_POST['mode'] ) && 'edit' != $_POST['mode'] || ! isset( $_GET['mode'] ) && ! isset( $_POST['mode'] ) ) {
175
mc_show_location_form( 'add' );
176
}
177
}
@@ -184,11 +184,11 @@ function my_calendar_add_locations() {
184
*/
185
function mc_show_location_form( $view = 'add', $loc_id = '' ) {
186
$cur_loc = false;
187
- if ( '' != $loc_id ) {
188
$cur_loc = mc_get_location( $loc_id );
189
}
190
$has_data = ( empty( $cur_loc ) ) ? false : true;
191
- if ( 'add' == $view ) {
192
?>
193
<h1><?php _e( 'Add New Location', 'my-calendar' ); ?></h1>
194
<?php
@@ -211,7 +211,7 @@ function mc_show_location_form( $view = 'add', $loc_id = '' ) {
211
<form id="my-calendar" method="post" action="<?php echo admin_url( 'admin.php?page=my-calendar-locations' ); ?>">
212
<div><input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'my-calendar-nonce' ); ?>"/></div>
213
<?php
214
- if ( 'add' == $view ) {
215
?>
216
<div>
217
<input type="hidden" name="mode" value="add" />
@@ -229,14 +229,14 @@ function mc_show_location_form( $view = 'add', $loc_id = '' ) {
229
echo mc_locations_fields( $has_data, $cur_loc, 'location' );
230
?>
231
<p>
232
- <input type="submit" name="save" class="button-primary" value="<?php echo ( 'edit' == $view ) ? __( 'Save Changes', 'my-calendar' ) : __( 'Add Location', 'my-calendar' ); ?> &raquo;"/>
233
</p>
234
</form>
235
</div>
236
</div>
237
</div>
238
<?php
239
- if ( 'edit' == $view ) {
240
?>
241
<p>
242
<a href="<?php echo admin_url( 'admin.php?page=my-calendar-locations' ); ?>"><?php _e( 'Add a New Location', 'my-calendar' ); ?> &raquo;</a>
@@ -282,7 +282,7 @@ function mc_controlled_field( $this_field ) {
282
return false;
283
}
284
$controlled = array_keys( $controls );
285
- if ( in_array( 'event_' . $this_field, $controlled ) && ! empty( $controls[ 'event_' . $this_field ] ) ) {
286
return true;
287
} else {
288
return false;
@@ -299,19 +299,19 @@ function mc_controlled_field( $this_field ) {
299
* @return string HTML select element with values
300
*/
301
function mc_location_controller( $fieldname, $selected, $context = 'location' ) {
302
- $field = ( 'location' == $context ) ? 'location_' . $fieldname : 'event_' . $fieldname;
303
$selected = esc_attr( trim( $selected ) );
304
$options = get_option( 'mc_location_controls' );
305
$regions = $options[ 'event_' . $fieldname ];
306
$form = "<select name='$field' id='e_$fieldname'>";
307
$form .= "<option value=''>" . __( 'Select', 'my-calendar' ) . '</option>';
308
- if ( is_admin() && '' != $selected ) {
309
$form .= "<option value='$selected'>$selected :" . __( '(Not a controlled value)', 'my-calendar' ) . '</option>';
310
}
311
foreach ( $regions as $key => $value ) {
312
$key = esc_attr( trim( $key ) );
313
$value = esc_html( trim( $value ) );
314
- $aselected = ( $selected == $key ) ? ' selected="selected"' : '';
315
$form .= "<option value='$key'$aselected>$value</option>\n";
316
}
317
$form .= '</select>';
@@ -355,7 +355,7 @@ function mc_location_controls() {
355
$locations .= stripslashes( "$key,$value" ) . PHP_EOL;
356
}
357
}
358
- if ( '' != trim( $locations ) ) {
359
$class = ' class="active-limit"';
360
$active = ' (' . __( 'active limits', 'my-calendar' ) . ')';
361
}
@@ -384,7 +384,7 @@ function mc_location_controls() {
384
*/
385
function mc_locations_fields( $has_data, $data, $context = 'location' ) {
386
$return = '<div class="mc-locations">';
387
- if ( current_user_can( 'mc_edit_locations' ) && 'event' == $context ) {
388
$return .= '<p class="checkboxes"><input type="checkbox" value="on" name="mc_copy_location" id="mc_copy_location" /> <label for="mc_copy_location">' . __( 'Copy this location into the locations table', 'my-calendar' ) . '</label></p>';
389
}
390
$return .= '
@@ -496,7 +496,7 @@ function mc_locations_fields( $has_data, $data, $context = 'location' ) {
496
$access = apply_filters( 'mc_venue_accessibility', mc_location_access() );
497
$access_list = '';
498
if ( $has_data ) {
499
- if ( 'location' == $context ) {
500
$location_access = unserialize( $data->{$context . '_access'} );
501
} else {
502
if ( property_exists( $data, 'event_location' ) ) {
@@ -514,7 +514,7 @@ function mc_locations_fields( $has_data, $data, $context = 'location' ) {
514
$label = $a;
515
$checked = '';
516
if ( is_array( $location_access ) ) {
517
- $checked = ( in_array( $a, $location_access ) || in_array( $k, $location_access ) ) ? " checked='checked'" : '';
518
}
519
$item = sprintf( '<li><input type="checkbox" id="%1$s" name="' . $context . '_access[]" value="%4$s" class="checkbox" %2$s /> <label for="%1$s">%3$s</label></li>', esc_attr( $id ), $checked, esc_html( $label ), esc_attr( $a ) );
520
$access_list .= $item;
@@ -530,7 +530,7 @@ function mc_locations_fields( $has_data, $data, $context = 'location' ) {
530
$return .= '<h3>' . __( 'Location Map', 'my-calendar' ) . '</h3>';
531
$map = mc_generate_map( $data, $context );
532
533
- $return .= ( '' == $map ) ? __( 'Not enough information to generate a map', 'my-calendar' ) : $map;
534
} else {
535
// Translators: URL to settings page to add key.
536
$return .= sprintf( __( 'Add a <a href="%s">Google Maps API Key</a> to generate a location map.', 'my-calendar' ), admin_url( 'admin.php?page=my-calendar-config#mc-output' ) );
@@ -575,7 +575,7 @@ function mc_location_data( $field, $id ) {
575
if ( $id ) {
576
global $wpdb;
577
$mcdb = $wpdb;
578
- if ( 'true' == get_option( 'mc_remote' ) && function_exists( 'mc_remote_db' ) ) {
579
$mcdb = mc_remote_db();
580
}
581
$field = $field;
@@ -602,7 +602,7 @@ function mc_location_select( $location = false ) {
602
foreach ( $locs as $loc ) {
603
$l = '<option value="' . $loc->location_id . '"';
604
if ( $location ) {
605
- if ( $location == $loc->location_id ) {
606
$l .= ' selected="selected"';
607
}
608
}
@@ -635,12 +635,12 @@ function mc_get_locations( $args ) {
635
$where = '1';
636
$is = '1';
637
}
638
- if ( ! ( 'ASC' == $order || 'DESC' == $order ) ) {
639
// Prevent invalid order parameters.
640
$order = 'ASC';
641
}
642
$valid_args = $wpdb->get_col( 'DESC ' . my_calendar_locations_table() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
643
- if ( ! ( in_array( $orderby, $valid_args ) ) ) {
644
// Prevent invalid order columns.
645
$orderby = 'location_label';
646
}
34
* Update settings for how location inputs are limited.
35
*/
36
function mc_update_location_controls() {
37
+ if ( isset( $_POST['mc_locations'] ) && 'true' === $_POST['mc_locations'] ) {
38
$nonce = $_POST['_wpnonce'];
39
if ( ! wp_verify_nonce( $nonce, 'my-calendar-nonce' ) ) {
40
wp_die( 'Invalid nonce' );
99
die( 'Security check failed' );
100
}
101
}
102
+ if ( isset( $_POST['mode'] ) && 'add' === $_POST['mode'] ) {
103
$add = array(
104
'location_label' => $_POST['location_label'],
105
'location_street' => $_POST['location_street'],
125
} else {
126
mc_show_error( __( 'Location could not be added to database', 'my-calendar' ) );
127
}
128
+ } elseif ( isset( $_GET['location_id'] ) && 'delete' === $_GET['mode'] ) {
129
$results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . my_calendar_locations_table() . ' WHERE location_id=%d', $_GET['location_id'] ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
130
do_action( 'mc_delete_location', $results, (int) $_GET['location_id'] );
131
if ( $results ) {
133
} else {
134
mc_show_error( __( 'Location could not be deleted', 'my-calendar' ) );
135
}
136
+ } elseif ( isset( $_GET['mode'] ) && isset( $_GET['location_id'] ) && 'edit' === $_GET['mode'] && ! isset( $_POST['mode'] ) ) {
137
$cur_loc = (int) $_GET['location_id'];
138
mc_show_location_form( 'edit', $cur_loc );
139
+ } elseif ( isset( $_POST['location_id'] ) && isset( $_POST['location_label'] ) && 'edit' === $_POST['mode'] ) {
140
$update = array(
141
'location_label' => $_POST['location_label'],
142
'location_street' => $_POST['location_street'],
171
172
}
173
174
+ if ( isset( $_GET['mode'] ) && 'edit' !== $_GET['mode'] || isset( $_POST['mode'] ) && 'edit' !== $_POST['mode'] || ! isset( $_GET['mode'] ) && ! isset( $_POST['mode'] ) ) {
175
mc_show_location_form( 'add' );
176
}
177
}
184
*/
185
function mc_show_location_form( $view = 'add', $loc_id = '' ) {
186
$cur_loc = false;
187
+ if ( '' !== $loc_id ) {
188
$cur_loc = mc_get_location( $loc_id );
189
}
190
$has_data = ( empty( $cur_loc ) ) ? false : true;
191
+ if ( 'add' === $view ) {
192
?>
193
<h1><?php _e( 'Add New Location', 'my-calendar' ); ?></h1>
194
<?php
211
<form id="my-calendar" method="post" action="<?php echo admin_url( 'admin.php?page=my-calendar-locations' ); ?>">
212
<div><input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'my-calendar-nonce' ); ?>"/></div>
213
<?php
214
+ if ( 'add' === $view ) {
215
?>
216
<div>
217
<input type="hidden" name="mode" value="add" />
229
echo mc_locations_fields( $has_data, $cur_loc, 'location' );
230
?>
231
<p>
232
+ <input type="submit" name="save" class="button-primary" value="<?php echo ( 'edit' === $view ) ? __( 'Save Changes', 'my-calendar' ) : __( 'Add Location', 'my-calendar' ); ?> &raquo;"/>
233
</p>
234
</form>