Add events list widget and close #6
This commit is contained in:
@@ -41,7 +41,7 @@ function sportspress_default_calendar_content( $content ) {
|
||||
$calendar = sportspress_events_list( $id );
|
||||
break;
|
||||
default:
|
||||
$calendar = sportspress_events_calendar( $id, true, false );
|
||||
$calendar = sportspress_events_calendar( $id, false, array( 'caption_tag' => 'h4' ) );
|
||||
break;
|
||||
endswitch;
|
||||
$content = $calendar . $content;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
function sportspress_events_calendar( $id = null, $single = false, $initial = true ) {
|
||||
function sportspress_events_calendar( $id = null, $initial = true, $args = array() ) {
|
||||
|
||||
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
|
||||
|
||||
@@ -8,6 +8,13 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
if ( ! $posts )
|
||||
return;
|
||||
|
||||
$defaults = array(
|
||||
'caption_tag' => 'caption',
|
||||
'show_all_events_link' => false,
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
if ( $id ):
|
||||
$events = sportspress_get_calendar_data( $id );
|
||||
$event_ids = array();
|
||||
@@ -19,7 +26,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
$in = '';
|
||||
endif;
|
||||
|
||||
$caption_tag = ( $single ? 'h4' : 'caption' );
|
||||
$caption_tag = $r['caption_tag'];
|
||||
|
||||
// week_begins = 0 stands for Sunday
|
||||
$week_begins = intval(get_option('start_of_week'));
|
||||
@@ -189,6 +196,9 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
|
||||
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
|
||||
|
||||
if ( $id && $r['show_all_events_link'] )
|
||||
$calendar_output .= '<a class="sp-all-events-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
|
||||
|
||||
return apply_filters( 'sportspress_events_calendar', $calendar_output );
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
function sportspress_events_list( $id = null, $args = '' ) {
|
||||
|
||||
if ( ! $id )
|
||||
$id = get_the_ID();
|
||||
|
||||
$options = get_option( 'sportspress' );
|
||||
$main_result = sportspress_array_value( $options, 'main_result', null );
|
||||
|
||||
$defaults = array(
|
||||
'show_all_events_link' => false,
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
@@ -18,18 +16,21 @@ if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
|
||||
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
|
||||
|
||||
if ( isset( $r['columns'] ) )
|
||||
$usecolumns = $r['columns'];
|
||||
|
||||
$output .= '<th class="column-date">' . __( 'Date', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'event', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
|
||||
$output .= '<th class="column-event">' . __( 'Event', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'teams', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) )
|
||||
$output .= '<th class="column-teams">' . __( 'Teams', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'time', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
|
||||
$output .= '<th class="column-time">' . __( 'Time', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'article', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'article', $usecolumns ) )
|
||||
$output .= '<th class="column-article">' . __( 'Article', 'sportspress' ). '</th>';
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
@@ -44,10 +45,10 @@ if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
|
||||
$output .= '<td class="column-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
|
||||
|
||||
if ( in_array( 'event', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
|
||||
$output .= '<td class="column-event">' . $event->post_title . '</td>';
|
||||
|
||||
if ( in_array( 'teams', $usecolumns ) ):
|
||||
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ):
|
||||
$output .= '<td class="column-teams">';
|
||||
|
||||
$teams = get_post_meta( $event->ID, 'sp_team', false );
|
||||
@@ -84,10 +85,10 @@ if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
$output .= '</td>';
|
||||
endif;
|
||||
|
||||
if ( in_array( 'time', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
|
||||
$output .= '<td class="column-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
|
||||
|
||||
if ( in_array( 'article', $usecolumns ) ):
|
||||
if ( $usecolumns == null || in_array( 'article', $usecolumns ) ):
|
||||
$output .= '<td class="column-article">
|
||||
<a href="' . get_permalink( $event->ID ) . '#sp_articlediv">';
|
||||
|
||||
@@ -113,7 +114,12 @@ if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
$i++;
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>' . '</table>' . '</div>';
|
||||
$output .= '</tbody>' . '</table>';
|
||||
|
||||
if ( $id && $r['show_all_events_link'] )
|
||||
$output .= '<a class="sp-all-events-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return apply_filters( 'sportspress_events_list', $output );
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@ class SportsPress_Widget_Events_Calendar extends WP_Widget {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$id = empty($instance['id']) ? null : $instance['id'];
|
||||
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="calendar_wrap">';
|
||||
echo sportspress_events_calendar( $id );
|
||||
echo sportspress_events_calendar( $id, true, array( 'show_all_events_link' => $show_all_events_link ) );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
@@ -23,14 +24,16 @@ class SportsPress_Widget_Events_Calendar extends WP_Widget {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['id'] = intval($new_instance['id']);
|
||||
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null ) );
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'show_all_events_link' => false ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$show_all_events_link = $instance['show_all_events_link'];
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
|
||||
@@ -44,13 +47,16 @@ class SportsPress_Widget_Events_Calendar extends WP_Widget {
|
||||
'id' => $this->get_field_id('id'),
|
||||
'selected' => $id,
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
'class' => 'sp-events-calendar-select widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_calendar', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><input class="checkbox sp-events-calendar-show-all-toggle" type="checkbox" id="<?php echo $this->get_field_id('show_all_events_link'); ?>" name="<?php echo $this->get_field_name('show_all_events_link'); ?>" value="1" <?php checked( $show_all_events_link, 1 ); ?> <?php disabled( true, ( ! $id ) ); ?>>
|
||||
<label for="<?php echo $this->get_field_id('show_all_events_link'); ?>"><?php _e( 'Display link to view all events', 'sportspress' ); ?></label></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
81
admin/widgets/events-list.php
Normal file
81
admin/widgets/events-list.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
class SportsPress_Widget_Events_List extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_sp_events_list', 'description' => __( 'A list of events.', 'sportspress' ) );
|
||||
parent::__construct('sp_events_list', __( 'SportsPress Events List', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$id = empty($instance['id']) ? null : $instance['id'];
|
||||
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
||||
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo sportspress_events_list( $id, array( 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['id'] = intval($new_instance['id']);
|
||||
$instance['columns'] = (array)$new_instance['columns'];
|
||||
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'columns' => null, 'show_all_events_link' => true ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$columns = $instance['columns'];
|
||||
$show_all_events_link = $instance['show_all_events_link'];
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Calendar', 'sportspress' ) ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_calendar',
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'name' => $this->get_field_name('id'),
|
||||
'id' => $this->get_field_id('id'),
|
||||
'selected' => $id,
|
||||
'values' => 'ID',
|
||||
'class' => 'sp-events-calendar-select widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_calendar', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p class="sp-prefs">
|
||||
<?php _e( 'Columns:', 'sportspress' ); ?><br>
|
||||
<?php
|
||||
$the_columns = array(
|
||||
'event' => __( 'Event', 'sportspress' ),
|
||||
'teams' => __( 'Teams', 'sportspress' ),
|
||||
'time' => __( 'Time', 'sportspress' ),
|
||||
'article' => __( 'Article', 'sportspress' ),
|
||||
);
|
||||
$field_name = $this->get_field_name('columns') . '[]';
|
||||
$field_id = $this->get_field_id('columns');
|
||||
?>
|
||||
<?php foreach ( $the_columns as $key => $label ): ?>
|
||||
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $key; ?>" value="<?php echo $key; ?>" <?php if ( $columns === null || in_array( $key, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $label; ?></label>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
|
||||
<p><input class="checkbox sp-events-calendar-show-all-toggle" type="checkbox" id="<?php echo $this->get_field_id('show_all_events_link'); ?>" name="<?php echo $this->get_field_name('show_all_events_link'); ?>" value="1" <?php checked( $show_all_events_link, 1 ); ?> <?php disabled( true, ( ! $id ) ); ?>>
|
||||
<label for="<?php echo $this->get_field_id('show_all_events_link'); ?>"><?php _e( 'Display link to view all events', 'sportspress' ); ?></label></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Events_List" );' ) );
|
||||
@@ -36,6 +36,11 @@ jQuery(document).ready(function($){
|
||||
$(this).closest(".widget-content").find(".sp-select-order").prop("disabled", $(this).val() == "default");
|
||||
});
|
||||
|
||||
// Calendar affects view all link checkbox in widget options
|
||||
$("body.widgets-php").on("change", ".sp-events-calendar-select", function() {
|
||||
$(this).closest(".widget-content").find(".sp-events-calendar-show-all-toggle").prop("disabled", $(this).val() == 0);
|
||||
});
|
||||
|
||||
// Tab switcher
|
||||
$(".sp-tab-panel").siblings(".sp-tab-bar").find("a").click(function() {
|
||||
$(this).closest("li").removeClass("wp-tab").addClass("wp-tab-active").siblings().removeClass("wp-tab-active").addClass("wp-tab").closest(".wp-tab-bar").siblings($(this).attr("href")).show().siblings(".wp-tab-panel").hide();
|
||||
|
||||
@@ -1494,12 +1494,7 @@ if ( !function_exists( 'sportspress_event_players_sub_filter' ) ) {
|
||||
|
||||
|
||||
if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
|
||||
function sportspress_get_calendar_data( $post_id, $admin = false ) {
|
||||
$leagues = get_the_terms( $post_id, 'sp_league' );
|
||||
$seasons = get_the_terms( $post_id, 'sp_season' );
|
||||
$venues = get_the_terms( $post_id, 'sp_venue' );
|
||||
$team = get_post_meta( $post_id, 'sp_team', true );
|
||||
$usecolumns = get_post_meta( $post_id, 'sp_columns', true );
|
||||
function sportspress_get_calendar_data( $post_id = null, $admin = false ) {
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
@@ -1513,49 +1508,59 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
|
||||
),
|
||||
);
|
||||
|
||||
if ( $leagues ):
|
||||
$league_ids = array();
|
||||
foreach( $leagues as $league ):
|
||||
$league_ids[] = $league->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'field' => 'id',
|
||||
'terms' => $league_ids
|
||||
);
|
||||
endif;
|
||||
if ( $post_id ):
|
||||
$leagues = get_the_terms( $post_id, 'sp_league' );
|
||||
$seasons = get_the_terms( $post_id, 'sp_season' );
|
||||
$venues = get_the_terms( $post_id, 'sp_venue' );
|
||||
$team = get_post_meta( $post_id, 'sp_team', true );
|
||||
$usecolumns = get_post_meta( $post_id, 'sp_columns', true );
|
||||
|
||||
if ( $seasons ):
|
||||
$season_ids = array();
|
||||
foreach( $seasons as $season ):
|
||||
$season_ids[] = $season->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'field' => 'id',
|
||||
'terms' => $season_ids
|
||||
);
|
||||
endif;
|
||||
if ( $leagues ):
|
||||
$league_ids = array();
|
||||
foreach( $leagues as $league ):
|
||||
$league_ids[] = $league->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'field' => 'id',
|
||||
'terms' => $league_ids
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $venues ):
|
||||
$venue_ids = array();
|
||||
foreach( $venues as $venue ):
|
||||
$venue_ids[] = $venue->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_venue',
|
||||
'field' => 'id',
|
||||
'terms' => $venue_ids
|
||||
);
|
||||
endif;
|
||||
if ( $seasons ):
|
||||
$season_ids = array();
|
||||
foreach( $seasons as $season ):
|
||||
$season_ids[] = $season->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'field' => 'id',
|
||||
'terms' => $season_ids
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $team ):
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $team,
|
||||
),
|
||||
);
|
||||
if ( $venues ):
|
||||
$venue_ids = array();
|
||||
foreach( $venues as $venue ):
|
||||
$venue_ids[] = $venue->term_id;
|
||||
endforeach;
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'sp_venue',
|
||||
'field' => 'id',
|
||||
'terms' => $venue_ids
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $team ):
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $team,
|
||||
),
|
||||
);
|
||||
endif;
|
||||
else:
|
||||
$usecolumns = null;
|
||||
endif;
|
||||
|
||||
$events = get_posts( $args );
|
||||
|
||||
@@ -85,6 +85,7 @@ require_once dirname( __FILE__ ) . '/admin/terms/position.php';
|
||||
// Widgets
|
||||
require_once dirname( __FILE__ ) . '/admin/widgets/countdown.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/widgets/events-calendar.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/widgets/events-list.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/widgets/player-list.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/widgets/league-table.php';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user