Add relative date range selector to calendars and widgets

This commit is contained in:
Brian Miyaji
2017-11-08 16:40:17 +11:00
parent 9d6ecf28bd
commit 04fbbdfc7f
10 changed files with 246 additions and 35 deletions

View File

@@ -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(",");

View File

@@ -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");
});

View File

@@ -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 {
?>
</p>
<p class="sp-date-range">
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="<?php echo $date_from ? $date_from : date_i18n( 'Y-m-d' ); ?>" size="10">
:
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
<p class="sp-date-range-absolute">
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="<?php echo $date_from ? $date_from : date_i18n( 'Y-m-d' ); ?>" size="10">
:
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
</p>
<p class="sp-date-range-relative">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="<?php echo '' !== $date_past ? $date_past : 7; ?>">
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="<?php echo '' !== $date_future ? $date_future : 7; ?>">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label>
<input type="checkbox" name="sp_date_relative" value="1" id="sp_date_relative" <?php checked( $date_relative ); ?>>
<?php _e( 'Relative', 'sportspress' ); ?>
</label>
</p>
</p>
</div>
<div class="sp-event-day-field">
@@ -120,6 +141,9 @@ class SP_Meta_Box_Calendar_Details {
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );
update_post_meta( $post_id, 'sp_date_past', sp_array_value( $_POST, 'sp_date_past', 0 ) );
update_post_meta( $post_id, 'sp_date_future', sp_array_value( $_POST, 'sp_date_future', 0 ) );
update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) );
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null ) );
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', null ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', null ) );

View File

@@ -34,6 +34,15 @@ class SP_Calendar extends SP_Custom_Post {
/** @var string The date to range to. */
public $to;
/** @var string The number of days to query in the past. */
public $past;
/** @var string The number of days to query in the future. */
public $future;
/** @var boolean Determines whether the date range is relative. */
public $relative;
/** @var string The match day. */
public $day;
@@ -88,11 +97,29 @@ class SP_Calendar extends SP_Custom_Post {
if ( ! $this->orderby )
$this->orderby = 'post_date';
if ( ! $this->from )
$this->from = get_post_meta( $this->ID, 'sp_date_from', true );
if ( 'range' == $this->date ) {
if ( ! $this->to )
$this->to = get_post_meta( $this->ID, 'sp_date_to', true );
$this->relative = get_post_meta( $this->ID, 'sp_date_relative', true );
if ( $this->relative ) {
if ( ! $this->past )
$this->past = get_post_meta( $this->ID, 'sp_date_past', true );
if ( ! $this->future )
$this->future = get_post_meta( $this->ID, 'sp_date_future', true );
} else {
if ( ! $this->from )
$this->from = get_post_meta( $this->ID, 'sp_date_from', true );
if ( ! $this->to )
$this->to = get_post_meta( $this->ID, 'sp_date_to', true );
}
}
if ( ! $this->day )
$this->day = get_post_meta( $this->ID, 'sp_day', true );
@@ -133,7 +160,11 @@ class SP_Calendar extends SP_Custom_Post {
$args['day'] = date_i18n('j');
$args['monthnum'] = date_i18n('n');
elseif ( $this->date == 'range' ):
add_filter( 'posts_where', array( $this, 'range' ) );
if ( $this->relative ):
add_filter( 'posts_where', array( $this, 'relative' ) );
else:
add_filter( 'posts_where', array( $this, 'range' ) );
endif;
endif;
endif;
@@ -240,19 +271,19 @@ class SP_Calendar extends SP_Custom_Post {
),
);
}
if ( 'auto' === $this->date && 'any' === $this->status ) {
$args['post_status'] = 'publish';
$args['order'] = 'DESC';
$args['posts_per_page'] = ceil( $this->number / 2 );
$results = get_posts( $args );
$results = array_reverse( $results, true );
$args['post_status'] = 'future';
$args['order'] = 'ASC';
$args['posts_per_page'] = floor( $this->number / 2 );
$fixtures = get_posts( $args );
$events = array_merge_recursive( $results, $fixtures );
} else {
$events = get_posts( $args );
@@ -262,15 +293,33 @@ class SP_Calendar extends SP_Custom_Post {
$events = null;
endif;
// Remove any calendar selection filters
remove_filter( 'posts_where', array( $this, 'range' ) );
remove_filter( 'posts_where', array( $this, 'relative' ) );
return $events;
}
public function range( $where = '' ) {
$to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) );
public function range( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( $this->from, new DateTimeZone( get_option( 'timezone_string' ) ) );
$where .= " AND post_date BETWEEN '" . $from->format( 'Y-m-d' ) . "' AND '" . $to->format( 'Y-m-d' ) . "'";
$to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) );
$to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where;
}
public function relative( $where = '', $format = 'Y-m-d' ) {
$datetimezone = new DateTimeZone( get_option( 'timezone_string' ) );
$from = new DateTime( 'now', $datetimezone );
$to = new DateTime( 'now', $datetimezone );
$from->modify( '-' . abs( (int) $this->past ) . ' day' );
$to->modify( '+' . abs( (int) $this->future ) . ' day' );
$to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where;
}
}

View File

@@ -21,6 +21,9 @@ class SP_Widget_Event_Blocks 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'];
$order = empty($instance['order']) ? 'default' : $instance['order'];
@@ -35,7 +38,7 @@ class SP_Widget_Event_Blocks extends WP_Widget {
// Action to hook into
do_action( 'sportspress_before_widget_template', $args, $instance, 'event-blocks' );
sp_get_template( 'event-blocks.php', array( 'id' => $id, 'title' => $caption, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'day' => $day, 'number' => $number, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
sp_get_template( 'event-blocks.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, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
// Action to hook into
do_action( 'sportspress_after_widget_template', $args, $instance, 'event-blocks' );
@@ -53,6 +56,9 @@ class SP_Widget_Event_Blocks 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['order'] = strip_tags($new_instance['order']);
@@ -65,7 +71,7 @@ class SP_Widget_Event_Blocks 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, '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, 'order' => 'default', 'show_all_events_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$caption = strip_tags($instance['caption']);
@@ -73,6 +79,9 @@ class SP_Widget_Event_Blocks 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']);
$order = strip_tags($instance['order']);
@@ -130,11 +139,29 @@ class SP_Widget_Event_Blocks extends WP_Widget {
sp_dropdown_dates( $args );
?>
</p>
<p class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<div class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<p class="sp-date-range-absolute<?php if ( $date_relative ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<p class="sp-date-range-relative<?php if ( ! $date_relative ): ?> hidden<?php endif; ?>">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_past' ); ?>" value="<?php echo $date_past; ?>">
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_future' ); ?>" value="<?php echo $date_future; ?>">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label>
<input type="checkbox" name="<?php echo $this->get_field_name( 'date_relative' ); ?>" value="1" id="<?php echo $this->get_field_id( 'date_relative' ); ?>" <?php checked( $date_relative ); ?>>
<?php _e( 'Relative', 'sportspress' ); ?>
</label>
</p>
</div>
</div>
<p><label for="<?php echo $this->get_field_id('day'); ?>"><?php _e( 'Match Day:', 'sportspress' ); ?></label>

View File

@@ -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 );
?>
</p>
<p class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<div class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<p class="sp-date-range-absolute<?php if ( $date_relative ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<p class="sp-date-range-relative<?php if ( ! $date_relative ): ?> hidden<?php endif; ?>">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_past' ); ?>" value="<?php echo $date_past; ?>">
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_future' ); ?>" value="<?php echo $date_future; ?>">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label>
<input type="checkbox" name="<?php echo $this->get_field_name( 'date_relative' ); ?>" value="1" id="<?php echo $this->get_field_id( 'date_relative' ); ?>" <?php checked( $date_relative ); ?>>
<?php _e( 'Relative', 'sportspress' ); ?>
</label>
</p>
</div>
</div>
<p><label for="<?php echo $this->get_field_id('day'); ?>"><?php _e( 'Match Day:', 'sportspress' ); ?></label>

View File

@@ -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 );
?>
</p>
<p class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<div class="sp-date-range<?php if ( 'range' !== $date ): ?> hidden<?php endif; ?>">
<p class="sp-date-range-absolute<?php if ( $date_relative ): ?> hidden<?php endif; ?>">
<input type="text" name="<?php echo $this->get_field_name( 'date_from' ); ?>" value="<?php echo $date_from; ?>" placeholder="yyyy-mm-dd" size="10">
:
<input type="text" name="<?php echo $this->get_field_name( 'date_to' ); ?>" value="<?php echo $date_to; ?>" placeholder="yyyy-mm-dd" size="10">
</p>
<p class="sp-date-range-relative<?php if ( ! $date_relative ): ?> hidden<?php endif; ?>">
<?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_past' ); ?>" value="<?php echo $date_past; ?>">
&rarr;
<?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="<?php echo $this->get_field_name( 'date_future' ); ?>" value="<?php echo $date_future; ?>">
<?php _e( 'days', 'sportspress' ); ?>
</p>
<p class="sp-date-relative">
<label>
<input type="checkbox" name="<?php echo $this->get_field_name( 'date_relative' ); ?>" value="1" id="<?php echo $this->get_field_id( 'date_relative' ); ?>" <?php checked( $date_relative ); ?>>
<?php _e( 'Relative', 'sportspress' ); ?>
</label>
</p>
</div>
</div>
<p><label for="<?php echo $this->get_field_id('day'); ?>"><?php _e( 'Match Day:', 'sportspress' ); ?></label>

View File

@@ -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 )

View File

@@ -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 )

View File

@@ -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 )