diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 7c0b9c64..7f6fa66a 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -604,6 +604,21 @@ jQuery(document).ready(function($){ }); $(".sp-date-selector select").trigger("change"); + // Toggle date range selectors + $(".sp-date-relative input").change(function() { + $relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked")); + $absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked")); + + if ($(this).attr("checked")) { + $relative.show(); + $absolute.hide(); + } else { + $absolute.show(); + $relative.hide(); + } + }); + $(".sp-date-selector input").trigger("change"); + // Apply color scheme $(".sp-color-option").on("click", function() { colors = $(this).find("label").data("sp-colors").split(","); diff --git a/assets/js/admin/widgets.js b/assets/js/admin/widgets.js index ffbf1446..0aba986d 100644 --- a/assets/js/admin/widgets.js +++ b/assets/js/admin/widgets.js @@ -23,4 +23,19 @@ jQuery(document).ready(function($){ } }); $(".sp-date-selector select").trigger("change"); + + // Toggle date range selectors + $("body").on("change", ".sp-date-relative input", function() { + $relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked")); + $absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked")); + + if ($(this).attr("checked")) { + $relative.show(); + $absolute.hide(); + } else { + $absolute.show(); + $relative.hide(); + } + }); + $(".sp-date-selector input").trigger("change"); }); \ No newline at end of file diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php index a28cce7b..081acffc 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php @@ -25,6 +25,9 @@ class SP_Meta_Box_Calendar_Details { $date = get_post_meta( $post->ID, 'sp_date', true ); $date_from = get_post_meta( $post->ID, 'sp_date_from', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true ); + $date_past = get_post_meta( $post->ID, 'sp_date_past', true ); + $date_future = get_post_meta( $post->ID, 'sp_date_future', true ); + $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); $day = get_post_meta( $post->ID, 'sp_day', true ); $teams = get_post_meta( $post->ID, 'sp_team', false ); $table_id = get_post_meta( $post->ID, 'sp_table', true ); @@ -59,9 +62,27 @@ class SP_Meta_Box_Calendar_Details { ?>
- - : - +
+ + : + +
+ ++ + + → + + + +
+ ++ +
diff --git a/includes/widgets/class-sp-widget-event-calendar.php b/includes/widgets/class-sp-widget-event-calendar.php index 369f26b3..995709db 100644 --- a/includes/widgets/class-sp-widget-event-calendar.php +++ b/includes/widgets/class-sp-widget-event-calendar.php @@ -20,6 +20,9 @@ class SP_Widget_Event_Calendar extends WP_Widget { $date = empty($instance['date']) ? 'default' : $instance['date']; $date_from = empty($instance['date_from']) ? 'default' : $instance['date_from']; $date_to = empty($instance['date_to']) ? 'default' : $instance['date_to']; + $date_past = empty($instance['date_past']) ? 'default' : $instance['date_past']; + $date_future = empty($instance['date_future']) ? 'default' : $instance['date_future']; + $date_relative = empty($instance['date_relative']) ? 'default' : $instance['date_relative']; $day = empty($instance['day']) ? 'default' : $instance['day']; $show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link']; @@ -32,7 +35,7 @@ class SP_Widget_Event_Calendar extends WP_Widget { // Action to hook into do_action( 'sportspress_before_widget_template', $args, $instance, 'event-calendar' ); - sp_get_template( 'event-calendar.php', array( 'id' => $id, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'caption_tag' => 'caption', 'day' => $day, 'show_all_events_link' => $show_all_events_link ) ); + sp_get_template( 'event-calendar.php', array( 'id' => $id, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'date_past' => $date_past, 'date_future' => $date_future, 'date_relative' => $date_relative, 'caption_tag' => 'caption', 'day' => $day, 'show_all_events_link' => $show_all_events_link ) ); // Action to hook into do_action( 'sportspress_after_widget_template', $args, $instance, 'event-calendar' ); @@ -49,6 +52,9 @@ class SP_Widget_Event_Calendar extends WP_Widget { $instance['date'] = $new_instance['date']; $instance['date_from'] = $new_instance['date_from']; $instance['date_to'] = $new_instance['date_to']; + $instance['date_past'] = $new_instance['date_past']; + $instance['date_future'] = $new_instance['date_future']; + $instance['date_relative'] = $new_instance['date_relative']; $instance['day'] = $new_instance['day']; $instance['show_all_events_link'] = $new_instance['show_all_events_link']; @@ -59,13 +65,16 @@ class SP_Widget_Event_Calendar extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'day' => '', 'show_all_events_link' => false ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'date_past' => 7, 'date_future' => 7, 'date_relative' => false, 'day' => '', 'show_all_events_link' => false ) ); $title = strip_tags($instance['title']); $id = intval($instance['id']); $status = $instance['status']; $date = $instance['date']; $date_from = $instance['date_from']; $date_to = $instance['date_to']; + $date_past = $instance['date_past']; + $date_future = $instance['date_future']; + $date_relative = $instance['date_relative']; $day = $instance['day']; $show_all_events_link = $instance['show_all_events_link']; @@ -118,11 +127,29 @@ class SP_Widget_Event_Calendar extends WP_Widget { sp_dropdown_dates( $args ); ?>
- +diff --git a/includes/widgets/class-sp-widget-event-list.php b/includes/widgets/class-sp-widget-event-list.php index 0e9c7e61..4c646af9 100644 --- a/includes/widgets/class-sp-widget-event-list.php +++ b/includes/widgets/class-sp-widget-event-list.php @@ -21,6 +21,9 @@ class SP_Widget_Event_List extends WP_Widget { $date = empty($instance['date']) ? 'default' : $instance['date']; $date_from = empty($instance['date_from']) ? 'default' : $instance['date_from']; $date_to = empty($instance['date_to']) ? 'default' : $instance['date_to']; + $date_past = empty($instance['date_past']) ? 'default' : $instance['date_past']; + $date_future = empty($instance['date_future']) ? 'default' : $instance['date_future']; + $date_relative = empty($instance['date_relative']) ? 'default' : $instance['date_relative']; $day = empty($instance['day']) ? 'default' : $instance['day']; $number = empty($instance['number']) ? null : $instance['number']; $columns = empty($instance['columns']) ? null : $instance['columns']; @@ -36,7 +39,7 @@ class SP_Widget_Event_List extends WP_Widget { // Action to hook into do_action( 'sportspress_before_widget_template', $args, $instance, 'event-list' ); - sp_get_template( 'event-list.php', array( 'id' => $id, 'title' => $caption, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'day' => $day, 'number' => $number, 'columns' => $columns, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) ); + sp_get_template( 'event-list.php', array( 'id' => $id, 'title' => $caption, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'date_past' => $date_past, 'date_future' => $date_future, 'date_relative' => $date_relative, 'day' => $day, 'number' => $number, 'columns' => $columns, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) ); // Action to hook into do_action( 'sportspress_after_widget_template', $args, $instance, 'event-list' ); @@ -54,6 +57,9 @@ class SP_Widget_Event_List extends WP_Widget { $instance['date'] = $new_instance['date']; $instance['date_from'] = $new_instance['date_from']; $instance['date_to'] = $new_instance['date_to']; + $instance['date_past'] = $new_instance['date_past']; + $instance['date_future'] = $new_instance['date_future']; + $instance['date_relative'] = $new_instance['date_relative']; $instance['day'] = $new_instance['day']; $instance['number'] = intval($new_instance['number']); $instance['columns'] = (array)$new_instance['columns']; @@ -67,7 +73,7 @@ class SP_Widget_Event_List extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'caption' => '', 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'day' => '', 'number' => 5, 'columns' => null, 'order' => 'default', 'show_all_events_link' => true ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'caption' => '', 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'date_past' => 7, 'date_future' => 7, 'date_relative' => false, 'day' => '', 'number' => 5, 'columns' => null, 'order' => 'default', 'show_all_events_link' => true ) ); $title = strip_tags($instance['title']); $id = intval($instance['id']); $caption = strip_tags($instance['caption']); @@ -75,6 +81,9 @@ class SP_Widget_Event_List extends WP_Widget { $date = $instance['date']; $date_from = $instance['date_from']; $date_to = $instance['date_to']; + $date_past = $instance['date_past']; + $date_future = $instance['date_future']; + $date_relative = $instance['date_relative']; $day = $instance['day']; $number = intval($instance['number']); $columns = $instance['columns']; @@ -135,11 +144,29 @@ class SP_Widget_Event_List extends WP_Widget { sp_dropdown_dates( $args ); ?>
- +diff --git a/templates/event-blocks.php b/templates/event-blocks.php index 5c5a12d1..232fe701 100644 --- a/templates/event-blocks.php +++ b/templates/event-blocks.php @@ -16,6 +16,9 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'date_past' => 'default', + 'date_future' => 'default', + 'date_relative' => 'default', 'day' => 'default', 'league' => null, 'season' => null, @@ -49,6 +52,12 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $date_past != 'default' ) + $calendar->past = $date_past; +if ( $date_future != 'default' ) + $calendar->future = $date_future; +if ( $date_relative != 'default' ) + $calendar->relative = $date_relative; if ( $league ) $calendar->league = $league; if ( $season ) diff --git a/templates/event-calendar.php b/templates/event-calendar.php index 5230e7e8..2a764652 100644 --- a/templates/event-calendar.php +++ b/templates/event-calendar.php @@ -17,6 +17,9 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'date_past' => 'default', + 'date_future' => 'default', + 'date_relative' => 'default', 'day' => 'default', 'league' => null, 'season' => null, @@ -40,6 +43,12 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $date_past != 'default' ) + $calendar->past = $date_past; +if ( $date_future != 'default' ) + $calendar->future = $date_future; +if ( $date_relative != 'default' ) + $calendar->relative = $date_relative; if ( $day != 'default' ) $calendar->day = $day; if ( $league ) diff --git a/templates/event-list.php b/templates/event-list.php index 964f77ff..ee86d556 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -16,6 +16,9 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'date_past' => 'default', + 'date_future' => 'default', + 'date_relative' => 'default', 'day' => 'default', 'league' => null, 'season' => null, @@ -51,6 +54,12 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $date_past != 'default' ) + $calendar->past = $date_past; +if ( $date_future != 'default' ) + $calendar->future = $date_future; +if ( $date_relative != 'default' ) + $calendar->relative = $date_relative; if ( $league ) $calendar->league = $league; if ( $season )